mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-21 18:37:45 +08:00
implement a simple wantlist command to allow the user to view their wantlist
This commit is contained in:
parent
5d7a3dfec2
commit
559a241566
@ -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
34
core/commands/wantlist.go
Normal 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,
|
||||
},
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user