cmds/bitswap: sort wantlist

License: MIT
Signed-off-by: Overbool <overbool.xu@gmail.com>
This commit is contained in:
Overbool 2018-11-10 10:22:53 +08:00
parent 085217eb5e
commit f4976e6b4e

View File

@ -11,6 +11,7 @@ import (
bitswap "gx/ipfs/QmXRphxBT4BH2GqGHUSbqULm7wNsxnpA2NrbNaY3DU1Y5K/go-bitswap"
decision "gx/ipfs/QmXRphxBT4BH2GqGHUSbqULm7wNsxnpA2NrbNaY3DU1Y5K/go-bitswap/decision"
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
cidutil "gx/ipfs/QmbfKu17LbMWyGUxHEUns9Wf5Dkm8PT6be4uPhTkk4YvaV/go-cidutil"
peer "gx/ipfs/QmcqU6QUDSXprb1518vYDGczrTJTyGwLG9eUa5iNX4xUtS/go-libp2p-peer"
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
)
@ -64,18 +65,19 @@ Print out all blocks currently on the bitswap wantlist for the local peer.`,
if err != nil {
return err
}
if pid == nd.Identity {
return cmds.EmitOnce(res, &KeyList{bs.GetWantlist()})
if pid != nd.Identity {
return cmds.EmitOnce(res, &KeyList{bs.WantlistForPeer(pid)})
}
return cmds.EmitOnce(res, &KeyList{bs.WantlistForPeer(pid)})
}
return cmds.EmitOnce(res, &KeyList{bs.GetWantlist()})
},
Encoders: cmds.EncoderMap{
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *KeyList) error {
// sort the keys first
cidutil.Sort(out.Keys)
for _, key := range out.Keys {
fmt.Fprintln(w, key.String())
fmt.Fprintln(w, key)
}
return nil