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

This commit is contained in:
Jeromy 2015-02-02 02:48:12 +00:00
parent 5d7a3dfec2
commit 559a241566
5 changed files with 50 additions and 0 deletions

View File

@ -98,6 +98,7 @@ var rootSubcommands = map[string]*cmds.Command{
"swarm": SwarmCmd,
"update": UpdateCmd,
"version": VersionCmd,
"wantlist": WantlistCmd,
}
func init() {

34
core/commands/wantlist.go Normal file
View File

@ -0,0 +1,34 @@
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,
},
}

View File

@ -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
}

View File

@ -21,5 +21,7 @@ type Interface interface {
// available on the network?
HasBlock(context.Context, *blocks.Block) error
GetWantlist() []u.Key
io.Closer
}

View File

@ -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
}