Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
df861afc
Commit
df861afc
authored
Sep 15, 2015
by
Juan Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1672 from ipfs/feat/unwant
implement unwant command to remove blocks from wantlist
parents
ae1e4523
6c02259a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
79 additions
and
0 deletions
+79
-0
core/commands/bitswap.go
core/commands/bitswap.go
+42
-0
exchange/bitswap/bitswap.go
exchange/bitswap/bitswap.go
+5
-0
test/sharness/t0220-bitswap.sh
test/sharness/t0220-bitswap.sh
+32
-0
No files found.
core/commands/bitswap.go
View file @
df861afc
...
...
@@ -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
)
},
}
...
...
exchange/bitswap/bitswap.go
View file @
df861afc
...
...
@@ -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
{
...
...
test/sharness/t0220-bitswap.sh
0 → 100755
View file @
df861afc
#!/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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment