Skip to content

Commit ba90276

Browse files
committed
fix unlimited growing of addrs in peer info
1 parent 694f4b4 commit ba90276

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

p2p/discovery.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"encoding/json"
66
"io"
7+
"slices"
78
"sync"
89
"time"
910

@@ -83,7 +84,11 @@ func (pd *PeerDiscovery) addPeer(pinfo peer.AddrInfo) {
8384
}
8485
oldPinfo, ok := pd.knownPeers[pinfo.ID]
8586
if ok {
86-
oldPinfo.Addrs = append(oldPinfo.Addrs, pinfo.Addrs...)
87+
for _, addr := range pinfo.Addrs {
88+
if !slices.Contains(oldPinfo.Addrs, addr) {
89+
oldPinfo.Addrs = append(oldPinfo.Addrs, addr)
90+
}
91+
}
8792
} else {
8893
oldPinfo = pinfo
8994
}

0 commit comments

Comments
 (0)