mirror of
https://github.com/libp2p/go-libp2p.git
synced 2025-12-24 13:29:35 +08:00
quic: fix race condition when generating random holepunch packet (#2263)
This commit is contained in:
@@ -45,7 +45,9 @@ type transport struct {
|
||||
|
||||
holePunchingMx sync.Mutex
|
||||
holePunching map[holePunchKey]*activeHolePunch
|
||||
rnd rand.Rand
|
||||
|
||||
rndMx sync.Mutex
|
||||
rnd rand.Rand
|
||||
|
||||
connMx sync.Mutex
|
||||
conns map[quic.Connection]*conn
|
||||
@@ -218,7 +220,10 @@ func (t *transport) holePunch(ctx context.Context, raddr ma.Multiaddr, p peer.ID
|
||||
var punchErr error
|
||||
loop:
|
||||
for i := 0; ; i++ {
|
||||
if _, err := t.rnd.Read(payload); err != nil {
|
||||
t.rndMx.Lock()
|
||||
_, err := t.rnd.Read(payload)
|
||||
t.rndMx.Unlock()
|
||||
if err != nil {
|
||||
punchErr = err
|
||||
break
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user