Skip to content

Commit

Permalink
addr-explosion mitigated adding
Browse files Browse the repository at this point in the history
mitigated adding our own addresses where received
from peers

see ipfs#573
  • Loading branch information
jbenet committed Jan 16, 2015
1 parent 52de86a commit 38c3e88
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ func (dht *IpfsDHT) handleAddProvider(ctx context.Context, p peer.ID, pmes *pb.M
}

log.Infof("received provider %s for %s (addrs: %s)", p, key, pi.Addrs)
for _, maddr := range pi.Addrs {
if pi.ID != dht.self { // dont add own addrs.
// add the received addresses to our peerstore.
dht.peerstore.AddAddress(p, maddr)
dht.peerstore.AddPeerInfo(pi)
}
dht.providers.AddProvider(key, p)
}
Expand Down
5 changes: 5 additions & 0 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ func (r *dhtQueryRunner) queryPeer(cg ctxgroup.ContextGroup, p peer.ID) {
} else if len(res.closerPeers) > 0 {
log.Debugf("PEERS CLOSER -- worker for: %v (%d closer peers)", p, len(res.closerPeers))
for _, next := range res.closerPeers {
if next.ID == r.query.dht.self { // dont add self.
log.Debugf("PEERS CLOSER -- worker for: %v found self", p)
continue
}

// add their addresses to the dialer's peerstore
r.query.dht.peerstore.AddPeerInfo(next)
r.addPeerToQuery(cg.Context(), next.ID)
Expand Down
6 changes: 4 additions & 2 deletions routing.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ func (dht *IpfsDHT) closerPeersSingle(ctx context.Context, key u.Key, p peer.ID)
var out []peer.ID
for _, pbp := range pmes.GetCloserPeers() {
pid := peer.ID(pbp.GetId())
dht.peerstore.AddAddresses(pid, pbp.Addresses())
out = append(out, pid)
if pid != dht.self { // dont add self
dht.peerstore.AddAddresses(pid, pbp.Addresses())
out = append(out, pid)
}
}
return out, nil
}
Expand Down

0 comments on commit 38c3e88

Please sign in to comment.