Skip to content

Commit

Permalink
identify: fix sorting of observed addresses (libp2p#2476)
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Aug 14, 2023
1 parent 646af49 commit e083078
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions p2p/protocol/identify/obsaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,13 @@ func (oas *ObservedAddrManager) filter(observedAddrs []*observedAddr) []ma.Multi
for pat := range pmap {
s := pmap[pat]

// We prefer inbound connection observations over outbound.
// For ties, we prefer the ones with more votes.
slices.SortFunc(s, func(first, second *observedAddr) int {
if first.numInbound > second.numInbound || len(first.seenBy) > len(second.seenBy) {
// We prefer inbound connection observations over outbound.
if first.numInbound > second.numInbound {
return -1
}
// For ties, we prefer the ones with more votes.
if first.numInbound == second.numInbound && len(first.seenBy) > len(second.seenBy) {
return -1
}
return 1
Expand Down

0 comments on commit e083078

Please sign in to comment.