Browse Source
quic: fix race condition when generating random holepunch packet (#2263)
pull/2266/head
Marten Seemann
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with
7 additions and
2 deletions
-
p2p/transport/quic/transport.go
|
@ -45,6 +45,8 @@ type transport struct { |
|
|
|
|
|
|
|
|
holePunchingMx sync.Mutex |
|
|
holePunchingMx sync.Mutex |
|
|
holePunching map[holePunchKey]*activeHolePunch |
|
|
holePunching map[holePunchKey]*activeHolePunch |
|
|
|
|
|
|
|
|
|
|
|
rndMx sync.Mutex |
|
|
rnd rand.Rand |
|
|
rnd rand.Rand |
|
|
|
|
|
|
|
|
connMx sync.Mutex |
|
|
connMx sync.Mutex |
|
@ -218,7 +220,10 @@ func (t *transport) holePunch(ctx context.Context, raddr ma.Multiaddr, p peer.ID |
|
|
var punchErr error |
|
|
var punchErr error |
|
|
loop: |
|
|
loop: |
|
|
for i := 0; ; i++ { |
|
|
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 |
|
|
punchErr = err |
|
|
break |
|
|
break |
|
|
} |
|
|
} |
|
|