Skip to content

Commit 6b8fe86

Browse files
committed
remove exp/rand
1 parent 6fce89f commit 6b8fe86

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

Diff for: go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ require (
6262
go.uber.org/mock v0.5.0
6363
go.uber.org/zap v1.27.0
6464
golang.org/x/crypto v0.33.0
65-
golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac
6665
golang.org/x/sync v0.11.0
6766
golang.org/x/sys v0.30.0
6867
golang.org/x/tools v0.30.0
@@ -127,6 +126,7 @@ require (
127126
github.com/wlynxg/anet v0.0.5 // indirect
128127
go.uber.org/dig v1.18.0 // indirect
129128
go.uber.org/multierr v1.11.0 // indirect
129+
golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac // indirect
130130
golang.org/x/mod v0.23.0 // indirect
131131
golang.org/x/net v0.35.0 // indirect
132132
golang.org/x/text v0.22.0 // indirect

Diff for: p2p/protocol/autonatv2/autonat.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"sync"
99
"time"
1010

11+
"math/rand/v2"
12+
1113
logging "github.com/ipfs/go-log/v2"
1214
"github.com/libp2p/go-libp2p/core/event"
1315
"github.com/libp2p/go-libp2p/core/host"
@@ -16,7 +18,6 @@ import (
1618
"github.com/libp2p/go-libp2p/p2p/protocol/autonatv2/pb"
1719
ma "github.com/multiformats/go-multiaddr"
1820
manet "github.com/multiformats/go-multiaddr/net"
19-
"golang.org/x/exp/rand"
2021
)
2122

2223
const (
@@ -211,7 +212,7 @@ func (p *peersMap) GetRand() peer.ID {
211212
if len(p.peers) == 0 {
212213
return ""
213214
}
214-
return p.peers[rand.Intn(len(p.peers))]
215+
return p.peers[rand.IntN(len(p.peers))]
215216
}
216217

217218
func (p *peersMap) Put(pid peer.ID) {

Diff for: p2p/protocol/autonatv2/client.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ import (
88
"sync"
99
"time"
1010

11+
"math/rand/v2"
12+
1113
"github.com/libp2p/go-libp2p/core/host"
1214
"github.com/libp2p/go-libp2p/core/network"
1315
"github.com/libp2p/go-libp2p/core/peer"
1416
"github.com/libp2p/go-libp2p/p2p/protocol/autonatv2/pb"
1517
"github.com/libp2p/go-msgio/pbio"
1618
ma "github.com/multiformats/go-multiaddr"
17-
"golang.org/x/exp/rand"
1819
)
1920

2021
// client implements the client for making dial requests for AutoNAT v2. It verifies successful

Diff for: p2p/transport/webrtc/transport.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import (
99
"crypto/elliptic"
1010
"crypto/rand"
1111
"crypto/x509"
12-
"encoding/binary"
1312
"errors"
1413
"fmt"
1514
"net"
1615
"time"
1716

18-
mrand "golang.org/x/exp/rand"
17+
mrand "math/rand/v2"
18+
1919
"google.golang.org/protobuf/proto"
2020

2121
"github.com/libp2p/go-libp2p/core/connmgr"
@@ -420,15 +420,15 @@ func genUfrag() string {
420420
uFragLength = len(uFragPrefix) + uFragIdLength
421421
)
422422

423-
seed := [8]byte{}
423+
seed := [32]byte{}
424424
rand.Read(seed[:])
425-
r := mrand.New(mrand.NewSource(binary.BigEndian.Uint64(seed[:])))
425+
r := mrand.New(mrand.New(mrand.NewChaCha8(seed)))
426426
b := make([]byte, uFragLength)
427427
for i := 0; i < len(uFragPrefix); i++ {
428428
b[i] = uFragPrefix[i]
429429
}
430430
for i := len(uFragPrefix); i < uFragLength; i++ {
431-
b[i] = uFragAlphabet[r.Intn(len(uFragAlphabet))]
431+
b[i] = uFragAlphabet[r.IntN(len(uFragAlphabet))]
432432
}
433433
return string(b)
434434
}

0 commit comments

Comments
 (0)