Skip to content

Commit

Permalink
cmds/bitswap: sort wantlist
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Overbool <overbool.xu@gmail.com>
  • Loading branch information
overbool committed Nov 10, 2018
1 parent 085217e commit f02c099
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions core/commands/bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"fmt"
"io"
"sort"

cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
e "github.com/ipfs/go-ipfs/core/commands/e"
Expand Down Expand Up @@ -64,18 +65,24 @@ 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
keys := make([]string, 0, len(out.Keys))
for _, key := range out.Keys {
fmt.Fprintln(w, key.String())
keys = append(keys, key.String())
}
sort.Sort(sort.StringSlice(keys))

for _, key := range keys {
fmt.Fprintln(w, key)
}

return nil
Expand Down

0 comments on commit f02c099

Please sign in to comment.