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-bitswap
Commits
694d2f81
Unverified
Commit
694d2f81
authored
Mar 16, 2020
by
Steven Allen
Committed by
GitHub
Mar 16, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #300 from ipfs/feat/full-wantlist
feat: expose the full wantlist through GetWantlist
parents
bced0f31
808f5a08
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
2 deletions
+38
-2
bitswap.go
bitswap.go
+7
-1
internal/peermanager/peermanager.go
internal/peermanager/peermanager.go
+9
-1
internal/peermanager/peerwantmanager.go
internal/peermanager/peerwantmanager.go
+22
-0
No files found.
bitswap.go
View file @
694d2f81
...
@@ -503,11 +503,17 @@ func (bs *Bitswap) Close() error {
...
@@ -503,11 +503,17 @@ func (bs *Bitswap) Close() error {
return
bs
.
process
.
Close
()
return
bs
.
process
.
Close
()
}
}
// GetWantlist returns the current local wantlist.
// GetWantlist returns the current local wantlist (both want-blocks and
// want-haves).
func
(
bs
*
Bitswap
)
GetWantlist
()
[]
cid
.
Cid
{
func
(
bs
*
Bitswap
)
GetWantlist
()
[]
cid
.
Cid
{
return
bs
.
pm
.
CurrentWants
()
return
bs
.
pm
.
CurrentWants
()
}
}
// GetWantBlocks returns the current list of want-blocks.
func
(
bs
*
Bitswap
)
GetWantBlocks
()
[]
cid
.
Cid
{
return
bs
.
pm
.
CurrentWantBlocks
()
}
// GetWanthaves returns the current list of want-haves.
// GetWanthaves returns the current list of want-haves.
func
(
bs
*
Bitswap
)
GetWantHaves
()
[]
cid
.
Cid
{
func
(
bs
*
Bitswap
)
GetWantHaves
()
[]
cid
.
Cid
{
return
bs
.
pm
.
CurrentWantHaves
()
return
bs
.
pm
.
CurrentWantHaves
()
...
...
internal/peermanager/peermanager.go
View file @
694d2f81
...
@@ -170,11 +170,19 @@ func (pm *PeerManager) SendCancels(ctx context.Context, cancelKs []cid.Cid) {
...
@@ -170,11 +170,19 @@ func (pm *PeerManager) SendCancels(ctx context.Context, cancelKs []cid.Cid) {
}
}
}
}
// CurrentWants returns the list of pending want-blocks
// CurrentWants returns the list of pending
wants (both want-haves and
want-blocks
).
func
(
pm
*
PeerManager
)
CurrentWants
()
[]
cid
.
Cid
{
func
(
pm
*
PeerManager
)
CurrentWants
()
[]
cid
.
Cid
{
pm
.
pqLk
.
RLock
()
pm
.
pqLk
.
RLock
()
defer
pm
.
pqLk
.
RUnlock
()
defer
pm
.
pqLk
.
RUnlock
()
return
pm
.
pwm
.
GetWants
()
}
// CurrentWantBlocks returns the list of pending want-blocks
func
(
pm
*
PeerManager
)
CurrentWantBlocks
()
[]
cid
.
Cid
{
pm
.
pqLk
.
RLock
()
defer
pm
.
pqLk
.
RUnlock
()
return
pm
.
pwm
.
GetWantBlocks
()
return
pm
.
pwm
.
GetWantBlocks
()
}
}
...
...
internal/peermanager/peerwantmanager.go
View file @
694d2f81
...
@@ -189,6 +189,28 @@ func (pwm *peerWantManager) GetWantHaves() []cid.Cid {
...
@@ -189,6 +189,28 @@ func (pwm *peerWantManager) GetWantHaves() []cid.Cid {
return
res
.
Keys
()
return
res
.
Keys
()
}
}
// GetWants returns the set of all wants (both want-blocks and want-haves).
func
(
pwm
*
peerWantManager
)
GetWants
()
[]
cid
.
Cid
{
res
:=
cid
.
NewSet
()
// Iterate over all known peers
for
_
,
pws
:=
range
pwm
.
peerWants
{
// Iterate over all want-blocks
for
_
,
c
:=
range
pws
.
wantBlocks
.
Keys
()
{
// Add the CID to the results
res
.
Add
(
c
)
}
// Iterate over all want-haves
for
_
,
c
:=
range
pws
.
wantHaves
.
Keys
()
{
// Add the CID to the results
res
.
Add
(
c
)
}
}
return
res
.
Keys
()
}
func
(
pwm
*
peerWantManager
)
String
()
string
{
func
(
pwm
*
peerWantManager
)
String
()
string
{
var
b
bytes
.
Buffer
var
b
bytes
.
Buffer
for
p
,
ws
:=
range
pwm
.
peerWants
{
for
p
,
ws
:=
range
pwm
.
peerWants
{
...
...
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