Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release v0.35.1 #2834

Merged
merged 8 commits into from
Jun 12, 2024
Prev Previous commit
Next Next commit
webrtc: fix ufrag prefix for dialing (#2832)
sukunrt committed Jun 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit c5e2b33ee1eb4949b946bb0b96242f5c9ab760ed
8 changes: 5 additions & 3 deletions p2p/transport/webrtc/transport.go
Original file line number Diff line number Diff line change
@@ -415,15 +415,17 @@ func genUfrag() string {
uFragAlphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
uFragPrefix = "libp2p+webrtc+v1/"
uFragIdLength = 32
uFragIdOffset = len(uFragPrefix)
uFragLength = uFragIdOffset + uFragIdLength
uFragLength = len(uFragPrefix) + uFragIdLength
)

seed := [8]byte{}
rand.Read(seed[:])
r := mrand.New(mrand.NewSource(binary.BigEndian.Uint64(seed[:])))
b := make([]byte, uFragLength)
for i := uFragIdOffset; i < uFragLength; i++ {
for i := 0; i < len(uFragPrefix); i++ {
b[i] = uFragPrefix[i]
}
for i := len(uFragPrefix); i < uFragLength; i++ {
b[i] = uFragAlphabet[r.Intn(len(uFragAlphabet))]
}
return string(b)
7 changes: 7 additions & 0 deletions p2p/transport/webrtc/transport_test.go
Original file line number Diff line number Diff line change
@@ -860,3 +860,10 @@ func TestMaxInFlightRequests(t *testing.T) {
require.Equal(t, count, int(success.Load()), "expected exactly 3 dial successes")
require.Equal(t, 1, int(fails.Load()), "expected exactly 1 dial failure")
}

func TestGenUfrag(t *testing.T) {
for i := 0; i < 10; i++ {
s := genUfrag()
require.True(t, strings.HasPrefix(s, "libp2p+webrtc+v1/"))
}
}