提交 559a2415 作者: Jeromy

implement a simple wantlist command to allow the user to view their wantlist

上级 5d7a3dfe
......@@ -98,6 +98,7 @@ var rootSubcommands = map[string]*cmds.Command{
"swarm": SwarmCmd,
"update": UpdateCmd,
"version": VersionCmd,
"wantlist": WantlistCmd,
}
func init() {
......
package commands
import cmds "github.com/jbenet/go-ipfs/commands"
var WantlistCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "A set of commands to work with the bitswap wantlist",
ShortDescription: ``,
},
Subcommands: map[string]*cmds.Command{
"show": showWantlistCmd,
},
}
var showWantlistCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Show blocks currently on the wantlist",
ShortDescription: `
Print out all blocks currently on the bitswap wantlist for the local peer`,
},
Type: KeyList{},
Run: func(req cmds.Request, res cmds.Response) {
nd, err := req.Context().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
res.SetOutput(&KeyList{nd.Exchange.GetWantlist()})
},
Marshalers: cmds.MarshalerMap{
cmds.Text: KeyListTextMarshaler,
},
}
......@@ -402,3 +402,11 @@ func (bs *bitswap) send(ctx context.Context, p peer.ID, m bsmsg.BitSwapMessage)
func (bs *bitswap) Close() error {
return bs.process.Close()
}
func (bs *bitswap) GetWantlist() []u.Key {
var out []u.Key
for _, e := range bs.wantlist.Entries() {
out = append(out, e.Key)
}
return out
}
......@@ -21,5 +21,7 @@ type Interface interface {
// available on the network?
HasBlock(context.Context, *blocks.Block) error
GetWantlist() []u.Key
io.Closer
}
......@@ -66,3 +66,8 @@ func (e *offlineExchange) GetBlocks(ctx context.Context, ks []u.Key) (<-chan *bl
}()
return out, nil
}
// implement Exchange
func (e *offlineExchange) GetWantlist() []u.Key {
return nil
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论