Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix panic in observed address activation check #586

Merged
merged 1 commit into from
Apr 9, 2019
Merged
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
17 changes: 8 additions & 9 deletions p2p/protocol/identify/obsaddr.go
Original file line number Diff line number Diff line change
@@ -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
@@ -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)