Skip to content

Commit

Permalink
Merge pull request #586 from libp2p/fix/obsaddr-panic
Browse files Browse the repository at this point in the history
fix panic in observed address activation check
  • Loading branch information
vyzo authored Apr 9, 2019
2 parents 7ae0fda + a4776e6 commit 202655c
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions p2p/protocol/identify/obsaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ type ObservedAddr struct {
}

func (oa *ObservedAddr) activated(ttl time.Duration) bool {
// cleanup SeenBy set
now := time.Now()

for k, ob := range oa.SeenBy {
if now.Sub(ob.seenTime) > ttl*ActivationThresh {
delete(oa.SeenBy, k)
}
}

// We only activate if in the TTL other peers observed the same address
// of ours at least 4 times.
return len(oa.SeenBy) >= ActivationThresh
Expand Down Expand Up @@ -154,7 +145,15 @@ func (oas *ObservedAddrSet) gc() {
for local, observedAddrs := range oas.addrs {
// TODO we can do this without allocating by compacting the array in place
filteredAddrs := make([]*ObservedAddr, 0, len(observedAddrs))

for _, a := range observedAddrs {
// clean up SeenBy set
for k, ob := range a.SeenBy {
if now.Sub(ob.seenTime) > oas.ttl*ActivationThresh {
delete(a.SeenBy, k)
}
}

// leave only alive observed addresses
if now.Sub(a.LastSeen) <= oas.ttl {
filteredAddrs = append(filteredAddrs, a)
Expand Down

0 comments on commit 202655c

Please sign in to comment.