Commit df861afc authored by Juan Benet's avatar Juan Benet

Merge pull request #1672 from ipfs/feat/unwant

implement unwant command to remove blocks from wantlist
parents ae1e4523 6c02259a
......@@ -5,6 +5,7 @@ import (
"fmt"
"io"
key "github.com/ipfs/go-ipfs/blocks/key"
cmds "github.com/ipfs/go-ipfs/commands"
bitswap "github.com/ipfs/go-ipfs/exchange/bitswap"
peer "github.com/ipfs/go-ipfs/p2p/peer"
......@@ -19,6 +20,47 @@ var BitswapCmd = &cmds.Command{
Subcommands: map[string]*cmds.Command{
"wantlist": showWantlistCmd,
"stat": bitswapStatCmd,
"unwant": unwantCmd,
},
}
var unwantCmd = &cmds.Command{
Helptext: cmds.HelpText{
Tagline: "Remove a given block from your wantlist",
},
Arguments: []cmds.Argument{
cmds.StringArg("key", true, true, "key to remove from your wantlist").EnableStdin(),
},
Run: func(req cmds.Request, res cmds.Response) {
nd, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
if !nd.OnlineMode() {
res.SetError(errNotOnline, cmds.ErrClient)
return
}
bs, ok := nd.Exchange.(*bitswap.Bitswap)
if !ok {
res.SetError(u.ErrCast(), cmds.ErrNormal)
return
}
var ks []key.Key
for _, arg := range req.Arguments() {
dec := key.B58KeyDecode(arg)
if dec == "" {
res.SetError(fmt.Errorf("incorrectly formatted key: %s", arg), cmds.ErrNormal)
return
}
ks = append(ks, dec)
}
bs.CancelWants(ks)
},
}
......
......@@ -221,6 +221,11 @@ func (bs *Bitswap) GetBlocks(ctx context.Context, keys []key.Key) (<-chan *block
}
}
// CancelWant removes a given key from the wantlist
func (bs *Bitswap) CancelWants(ks []key.Key) {
bs.wm.CancelWants(ks)
}
// HasBlock announces the existance of a block to this bitswap service. The
// service will potentially notify its peers.
func (bs *Bitswap) HasBlock(ctx context.Context, blk *blocks.Block) error {
......
#!/bin/sh
#
# Copyright (c) 2015 Jeromy Johnson
# MIT Licensed; see the LICENSE file in this repository.
#
test_description="test bitswap commands"
. lib/test-lib.sh
test_init_ipfs
test_launch_ipfs_daemon
test_expect_success "'ipfs block get' adds hash to wantlist" '
export NONEXIST=QmeXxaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&
test_expect_code 1 ipfs block get $NONEXIST --timeout=10ms &&
ipfs bitswap wantlist | grep $NONEXIST
'
test_expect_success "'ipfs bitswap unwant' succeeds" '
ipfs bitswap unwant $NONEXIST
'
test_expect_success "hash was removed from wantlist" '
ipfs bitswap wantlist > wantlist_out &&
printf "" > wantlist_exp &&
test_cmp wantlist_out wantlist_exp
'
test_kill_ipfs_daemon
test_done
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment