go-ethereum/p2p/nat
cuiweixie 42c013f2af p2p/nat: return exactly n random STUN servers on every call
randomServers drew indices with rand.Intn into a dedup map, bounded by
len(serverList)*2 iterations. When n approaches the number of configured
servers, repeated random collisions can exhaust the iteration budget
before n unique servers are collected, so the function sometimes returns
fewer servers than requested even though enough exist.

For example, with 2 configured servers and requestLimit==3 (capped to 2),
the four allowed draws can collide and yield only a single server. If
that server is down, ExternalIP fails without ever trying the other.

Replace the sampling loop with rand.Perm, which produces a uniform
permutation of all indices in one pass. Slicing the first n entries
always yields exactly min(n, len(serverList)) distinct servers, with no
probabilistic shortfall.
2026-06-11 20:00:00 +08:00
..
nat.go all: use fmt.Appendf instead of fmt.Sprintf where possible (#31301) 2025-03-25 14:53:02 +01:00
nat_test.go p2p/nat: server list contains IPv6 servers (#35084) 2026-06-02 17:13:36 +02:00
natpmp.go p2p/nat: remove forceful port mapping in upnp (#30265) 2025-04-04 10:56:55 +02:00
natupnp.go p2p/nat: fix err shadowing in UPnP addAnyPortMapping (#33355) 2025-12-08 15:02:24 +01:00
natupnp_test.go all: replace strings.Replace with string.ReplaceAll (#24835) 2022-05-09 13:13:23 +03:00
stun-list-update.sh p2p/nat: add stun protocol (#31064) 2025-01-24 16:16:02 +01:00
stun-list.txt p2p/nat: add stun protocol (#31064) 2025-01-24 16:16:02 +01:00
stun.go p2p/nat: return exactly n random STUN servers on every call 2026-06-11 20:00:00 +08:00
stun_test.go p2p/nat: remove test with default servers (#31225) 2025-02-21 10:42:54 +08:00