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
ea2375e8
Commit
ea2375e8
authored
9 years ago
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
let wantlist command show other peers wantlists
parent
ff1e58a4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
2 deletions
+39
-2
core/commands/bitswap.go
core/commands/bitswap.go
+21
-2
exchange/bitswap/bitswap.go
exchange/bitswap/bitswap.go
+8
-0
exchange/bitswap/decision/engine.go
exchange/bitswap/decision/engine.go
+10
-0
No files found.
core/commands/bitswap.go
View file @
ea2375e8
...
...
@@ -3,10 +3,12 @@ package commands
import
(
"bytes"
"fmt"
"io"
cmds
"github.com/ipfs/go-ipfs/commands"
bitswap
"github.com/ipfs/go-ipfs/exchange/bitswap"
peer
"github.com/ipfs/go-ipfs/p2p/peer"
u
"github.com/ipfs/go-ipfs/util"
"io"
)
var
BitswapCmd
=
&
cmds
.
Command
{
...
...
@@ -26,6 +28,9 @@ var showWantlistCmd = &cmds.Command{
ShortDescription
:
`
Print out all blocks currently on the bitswap wantlist for the local peer`
,
},
Options
:
[]
cmds
.
Option
{
cmds
.
StringOption
(
"peer"
,
"p"
,
"specify which peer to show wantlist for (default self)"
),
},
Type
:
KeyList
{},
Run
:
func
(
req
cmds
.
Request
,
res
cmds
.
Response
)
{
nd
,
err
:=
req
.
Context
()
.
GetNode
()
...
...
@@ -39,7 +44,21 @@ Print out all blocks currently on the bitswap wantlist for the local peer`,
return
}
res
.
SetOutput
(
&
KeyList
{
bs
.
GetWantlist
()})
pstr
,
found
,
err
:=
req
.
Option
(
"peer"
)
.
String
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
if
found
{
pid
,
err
:=
peer
.
IDB58Decode
(
pstr
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
res
.
SetOutput
(
&
KeyList
{
bs
.
WantlistForPeer
(
pid
)})
}
else
{
res
.
SetOutput
(
&
KeyList
{
bs
.
GetWantlist
()})
}
},
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
KeyListTextMarshaler
,
...
...
This diff is collapsed.
Click to expand it.
exchange/bitswap/bitswap.go
View file @
ea2375e8
...
...
@@ -175,6 +175,14 @@ func (bs *Bitswap) GetBlock(parent context.Context, k u.Key) (*blocks.Block, err
}
}
func
(
bs
*
Bitswap
)
WantlistForPeer
(
p
peer
.
ID
)
[]
u
.
Key
{
var
out
[]
u
.
Key
for
_
,
e
:=
range
bs
.
engine
.
WantlistForPeer
(
p
)
{
out
=
append
(
out
,
e
.
Key
)
}
return
out
}
// GetBlocks returns a channel where the caller may receive blocks that
// correspond to the provided |keys|. Returns an error if BitSwap is unable to
// begin this request within the deadline enforced by the context.
...
...
This diff is collapsed.
Click to expand it.
exchange/bitswap/decision/engine.go
View file @
ea2375e8
...
...
@@ -96,6 +96,16 @@ func NewEngine(ctx context.Context, bs bstore.Blockstore) *Engine {
return
e
}
func
(
e
*
Engine
)
WantlistForPeer
(
p
peer
.
ID
)
(
out
[]
wl
.
Entry
)
{
e
.
lock
.
Lock
()
partner
,
ok
:=
e
.
ledgerMap
[
p
]
if
ok
{
out
=
partner
.
wantList
.
SortedEntries
()
}
e
.
lock
.
Unlock
()
return
out
}
func
(
e
*
Engine
)
taskWorker
(
ctx
context
.
Context
)
{
defer
close
(
e
.
outbox
)
// because taskWorker uses the channel exclusively
for
{
...
...
This diff is collapsed.
Click to expand it.
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