Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

feat: expose the full wantlist through GetWantlist #300

Merged
merged 1 commit into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,11 +503,17 @@ func (bs *Bitswap) Close() error {
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 {
return bs.pm.CurrentWants()
Stebalien marked this conversation as resolved.
Show resolved Hide resolved
}

// 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.
func (bs *Bitswap) GetWantHaves() []cid.Cid {
return bs.pm.CurrentWantHaves()
Expand Down
10 changes: 9 additions & 1 deletion internal/peermanager/peermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
pm.pqLk.RLock()
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()
}

Expand Down
22 changes: 22 additions & 0 deletions internal/peermanager/peerwantmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@ func (pwm *peerWantManager) GetWantHaves() []cid.Cid {
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 {
var b bytes.Buffer
for p, ws := range pwm.peerWants {
Expand Down