Skip to content

Commit

Permalink
fix unlimited growing of addrs in peer info
Browse files Browse the repository at this point in the history
  • Loading branch information
brewmaster012 committed Oct 29, 2024
1 parent 694f4b4 commit ba90276
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion p2p/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"io"
"slices"

Check failure on line 7 in p2p/discovery.go

View workflow job for this annotation

GitHub Actions / test go 1.20

package slices is not in GOROOT (/opt/hostedtoolcache/go/1.20.14/x64/src/slices)
"sync"
"time"

Expand Down Expand Up @@ -83,7 +84,11 @@ func (pd *PeerDiscovery) addPeer(pinfo peer.AddrInfo) {
}
oldPinfo, ok := pd.knownPeers[pinfo.ID]
if ok {
oldPinfo.Addrs = append(oldPinfo.Addrs, pinfo.Addrs...)
for _, addr := range pinfo.Addrs {
if !slices.Contains(oldPinfo.Addrs, addr) {
oldPinfo.Addrs = append(oldPinfo.Addrs, addr)
}
}
} else {
oldPinfo = pinfo
}
Expand Down

0 comments on commit ba90276

Please sign in to comment.