Skip to content

Commit f4976e6

Browse files
committed
cmds/bitswap: sort wantlist
License: MIT Signed-off-by: Overbool <[email protected]>
1 parent 085217e commit f4976e6

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

core/commands/bitswap.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
bitswap "gx/ipfs/QmXRphxBT4BH2GqGHUSbqULm7wNsxnpA2NrbNaY3DU1Y5K/go-bitswap"
1212
decision "gx/ipfs/QmXRphxBT4BH2GqGHUSbqULm7wNsxnpA2NrbNaY3DU1Y5K/go-bitswap/decision"
1313
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
14+
cidutil "gx/ipfs/QmbfKu17LbMWyGUxHEUns9Wf5Dkm8PT6be4uPhTkk4YvaV/go-cidutil"
1415
peer "gx/ipfs/QmcqU6QUDSXprb1518vYDGczrTJTyGwLG9eUa5iNX4xUtS/go-libp2p-peer"
1516
cmdkit "gx/ipfs/Qmde5VP1qUkyQXKCfmEUA7bP64V2HAptbJ7phuPp7jXWwg/go-ipfs-cmdkit"
1617
)
@@ -64,18 +65,19 @@ Print out all blocks currently on the bitswap wantlist for the local peer.`,
6465
if err != nil {
6566
return err
6667
}
67-
if pid == nd.Identity {
68-
return cmds.EmitOnce(res, &KeyList{bs.GetWantlist()})
68+
if pid != nd.Identity {
69+
return cmds.EmitOnce(res, &KeyList{bs.WantlistForPeer(pid)})
6970
}
70-
71-
return cmds.EmitOnce(res, &KeyList{bs.WantlistForPeer(pid)})
7271
}
72+
7373
return cmds.EmitOnce(res, &KeyList{bs.GetWantlist()})
7474
},
7575
Encoders: cmds.EncoderMap{
7676
cmds.Text: cmds.MakeTypedEncoder(func(req *cmds.Request, w io.Writer, out *KeyList) error {
77+
// sort the keys first
78+
cidutil.Sort(out.Keys)
7779
for _, key := range out.Keys {
78-
fmt.Fprintln(w, key.String())
80+
fmt.Fprintln(w, key)
7981
}
8082

8183
return nil

0 commit comments

Comments
 (0)