Skip to content

Commit

Permalink
nit: cleanup contains check
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoPolo committed Oct 16, 2024
1 parent a76c6d8 commit 9cb382c
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions p2p/host/autonat/autonat.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package autonat
import (
"context"
"math/rand"
"slices"
"sync/atomic"
"time"

Expand Down Expand Up @@ -245,15 +246,10 @@ func (as *AmbientAutoNAT) background() {

func (as *AmbientAutoNAT) checkAddrs() (hasNewAddr bool) {
currentAddrs := as.addressFunc()
for _, a := range currentAddrs {
if !manet.IsPublicAddr(a) {
continue
}
if _, ok := as.ourAddrs[string(a.Bytes())]; !ok {
hasNewAddr = true
break
}
}
hasNewAddr = slices.ContainsFunc(currentAddrs, func(a ma.Multiaddr) bool {
_, ok := as.ourAddrs[string(a.Bytes())]
return !ok
})
clear(as.ourAddrs)
for _, a := range currentAddrs {
if !manet.IsPublicAddr(a) {
Expand Down

0 comments on commit 9cb382c

Please sign in to comment.