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

Commit

Permalink
providers: don't add every connected node as a provider
Browse files Browse the repository at this point in the history
We now do exactly what the comment is warning about: track peers providing keys.
  • Loading branch information
Stebalien authored and hannahhoward committed Feb 5, 2019
1 parent 5b807cb commit 586a5c0
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions network/ipfs_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,7 @@ func (bsnet *impl) ConnectTo(ctx context.Context, p peer.ID) error {

// FindProvidersAsync returns a channel of providers for the given key.
func (bsnet *impl) FindProvidersAsync(ctx context.Context, k cid.Cid, max int) <-chan peer.ID {

// Since routing queries are expensive, give bitswap the peers to which we
// have open connections. Note that this may cause issues if bitswap starts
// precisely tracking which peers provide certain keys. This optimization
// would be misleading. In the long run, this may not be the most
// appropriate place for this optimization, but it won't cause any harm in
// the short term.
connectedPeers := bsnet.host.Network().Peers()
out := make(chan peer.ID, len(connectedPeers)) // just enough buffer for these connectedPeers
for _, id := range connectedPeers {
if id == bsnet.host.ID() {
continue // ignore self as provider
}
out <- id
}

out := make(chan peer.ID, max)
go func() {
defer close(out)
providers := bsnet.routing.FindProvidersAsync(ctx, k, max)
Expand Down

0 comments on commit 586a5c0

Please sign in to comment.