Skip to content

Commit

Permalink
remove bitswap unwant
Browse files Browse the repository at this point in the history
This command messes with internal state and doesn't even work at the moment. If
you don't want a block, you should cancel the request that's trying to fetch it.

fixes #5295

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
  • Loading branch information
Stebalien committed Aug 16, 2018
1 parent afda4ca commit 86b94dd
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 60 deletions.
48 changes: 0 additions & 48 deletions core/commands/bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
cmdkit "gx/ipfs/QmPVqQHEfLpqK7JLCsUkyam7rhuV3MAeZ9gueQQCrBwCta/go-ipfs-cmdkit"
cmds "gx/ipfs/QmUQb3xtNzkQCgTj2NjaqcJZNv2nfSSub2QAdy9DtQMRBT/go-ipfs-cmds"
cid "gx/ipfs/QmYjnkEL7i731PirfVH1sis89evN7jt4otSHw5D2xXXwUV/go-cid"
peer "gx/ipfs/QmcZSzKEM5yDfpZbeEEZaVmaZ1zXm6JWTbrQZSB8hCVPzk/go-libp2p-peer"
)

Expand All @@ -27,58 +26,11 @@ var BitswapCmd = &cmds.Command{
Subcommands: map[string]*cmds.Command{
"stat": bitswapStatCmd,
"wantlist": lgc.NewCommand(showWantlistCmd),
"unwant": lgc.NewCommand(unwantCmd),
"ledger": lgc.NewCommand(ledgerCmd),
"reprovide": lgc.NewCommand(reprovideCmd),
},
}

var unwantCmd = &oldcmds.Command{
Helptext: cmdkit.HelpText{
Tagline: "Remove a given block from your wantlist.",
},
Arguments: []cmdkit.Argument{
cmdkit.StringArg("key", true, true, "Key(s) to remove from your wantlist.").EnableStdin(),
},
Run: func(req oldcmds.Request, res oldcmds.Response) {
nd, err := req.InvocContext().GetNode()
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
}

if !nd.OnlineMode() {
res.SetError(errNotOnline, cmdkit.ErrClient)
return
}

bs, ok := nd.Exchange.(*bitswap.Bitswap)
if !ok {
res.SetError(e.TypeErr(bs, nd.Exchange), cmdkit.ErrNormal)
return
}

var ks []*cid.Cid
for _, arg := range req.Arguments() {
c, err := cid.Decode(arg)
if err != nil {
res.SetError(err, cmdkit.ErrNormal)
return
}

ks = append(ks, c)
}

// TODO: This should maybe find *all* sessions for this request and cancel them?
// (why): in reality, i think this command should be removed. Its
// messing with the internal state of bitswap. You should cancel wants
// by killing the command that caused the want.
bs.CancelWants(ks, 0)

res.SetOutput(nil)
},
}

var showWantlistCmd = &oldcmds.Command{
Helptext: cmdkit.HelpText{
Tagline: "Show blocks currently on the wantlist.",
Expand Down
1 change: 0 additions & 1 deletion core/commands/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func TestCommands(t *testing.T) {
"/bitswap/ledger",
"/bitswap/reprovide",
"/bitswap/stat",
"/bitswap/unwant",
"/bitswap/wantlist",
"/block",
"/block/get",
Expand Down
12 changes: 1 addition & 11 deletions misc/completion/ipfs-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ _ipfs_add()

_ipfs_bitswap()
{
ipfs_comp "ledger stat unwant wantlist --help"
ipfs_comp "ledger stat wantlist --help"
}

_ipfs_bitswap_ledger()
Expand All @@ -40,21 +40,11 @@ _ipfs_bitswap_stat()
_ipfs_help_only
}

_ipfs_bitswap_unwant()
{
_ipfs_help_only
}

_ipfs_bitswap_wantlist()
{
ipfs_comp "--peer= --help"
}

_ipfs_bitswap_unwant()
{
_ipfs_help_only
}

_ipfs_block()
{
_ipfs_comp "get put rm stat --help"
Expand Down

0 comments on commit 86b94dd

Please # to comment.