mirror of
https://github.com/libp2p/go-libp2p.git
synced 2025-10-23 16:13:23 +08:00
sync: update CI config files (#2073)
* bump go.mod to Go 1.19 and run go fix * stop using the deprecated io/ioutil package * bump go.mod to Go 1.19 and run go fix * bump go.mod to Go 1.19 and run go fix * bump go.mod to Go 1.19 and run go fix * stop using the deprecated io/ioutil package * bump go.mod to Go 1.19 and run go fix * stop using the deprecated io/ioutil package * update .github/workflows/go-test.yml * update .github/workflows/go-check.yml * update .github/workflows/release-check.yml * various fixes * stop using deprecated math/rand.Read --------- Co-authored-by: web3-bot <web3-bot@users.noreply.github.com> Co-authored-by: Marten Seemann <martenseemann@gmail.com>
This commit is contained in:
24
.github/workflows/go-check.yml
vendored
24
.github/workflows/go-check.yml
vendored
@@ -8,26 +8,20 @@ jobs:
|
|||||||
unit:
|
unit:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: All
|
name: All
|
||||||
env:
|
|
||||||
RUNGOGENERATE: false
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
- id: config
|
||||||
|
uses: protocol/.github/.github/actions/read-config@master
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: "1.19.x"
|
go-version: 1.20.x
|
||||||
- name: Run repo-specific setup
|
- name: Run repo-specific setup
|
||||||
uses: ./.github/actions/go-check-setup
|
uses: ./.github/actions/go-check-setup
|
||||||
if: hashFiles('./.github/actions/go-check-setup') != ''
|
if: hashFiles('./.github/actions/go-check-setup') != ''
|
||||||
- name: Read config
|
|
||||||
if: hashFiles('./.github/workflows/go-check-config.json') != ''
|
|
||||||
run: |
|
|
||||||
if jq -re .gogenerate ./.github/workflows/go-check-config.json; then
|
|
||||||
echo "RUNGOGENERATE=true" >> $GITHUB_ENV
|
|
||||||
fi
|
|
||||||
- name: Install staticcheck
|
- name: Install staticcheck
|
||||||
run: go install honnef.co/go/tools/cmd/staticcheck@376210a89477dedbe6fdc4484b233998650d7b3c # 2022.1.3 (v0.3.3)
|
run: go install honnef.co/go/tools/cmd/staticcheck@4970552d932f48b71485287748246cf3237cebdf # 2023.1 (v0.4.0)
|
||||||
- name: Check that go.mod is tidy
|
- name: Check that go.mod is tidy
|
||||||
uses: protocol/multiple-go-modules@v1.2
|
uses: protocol/multiple-go-modules@v1.2
|
||||||
with:
|
with:
|
||||||
@@ -39,7 +33,7 @@ jobs:
|
|||||||
fi
|
fi
|
||||||
git diff --exit-code -- go.sum go.mod
|
git diff --exit-code -- go.sum go.mod
|
||||||
- name: gofmt
|
- name: gofmt
|
||||||
if: ${{ success() || failure() }} # run this step even if the previous one failed
|
if: success() || failure() # run this step even if the previous one failed
|
||||||
run: |
|
run: |
|
||||||
out=$(gofmt -s -l .)
|
out=$(gofmt -s -l .)
|
||||||
if [[ -n "$out" ]]; then
|
if [[ -n "$out" ]]; then
|
||||||
@@ -47,12 +41,12 @@ jobs:
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
- name: go vet
|
- name: go vet
|
||||||
if: ${{ success() || failure() }} # run this step even if the previous one failed
|
if: success() || failure() # run this step even if the previous one failed
|
||||||
uses: protocol/multiple-go-modules@v1.2
|
uses: protocol/multiple-go-modules@v1.2
|
||||||
with:
|
with:
|
||||||
run: go vet ./...
|
run: go vet ./...
|
||||||
- name: staticcheck
|
- name: staticcheck
|
||||||
if: ${{ success() || failure() }} # run this step even if the previous one failed
|
if: success() || failure() # run this step even if the previous one failed
|
||||||
uses: protocol/multiple-go-modules@v1.2
|
uses: protocol/multiple-go-modules@v1.2
|
||||||
with:
|
with:
|
||||||
run: |
|
run: |
|
||||||
@@ -60,11 +54,11 @@ jobs:
|
|||||||
staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g'
|
staticcheck ./... | sed -e 's@\(.*\)\.go@./\1.go@g'
|
||||||
- name: go generate
|
- name: go generate
|
||||||
uses: protocol/multiple-go-modules@v1.2
|
uses: protocol/multiple-go-modules@v1.2
|
||||||
if: (success() || failure()) && env.RUNGOGENERATE == 'true'
|
if: (success() || failure()) && fromJSON(steps.config.outputs.json).gogenerate == true
|
||||||
with:
|
with:
|
||||||
run: |
|
run: |
|
||||||
git clean -fd # make sure there aren't untracked files / directories
|
git clean -fd # make sure there aren't untracked files / directories
|
||||||
go generate ./...
|
go generate -x ./...
|
||||||
# check if go generate modified or added any files
|
# check if go generate modified or added any files
|
||||||
if ! $(git add . && git diff-index HEAD --exit-code --quiet); then
|
if ! $(git add . && git diff-index HEAD --exit-code --quiet); then
|
||||||
echo "go generated caused changes to the repository:"
|
echo "go generated caused changes to the repository:"
|
||||||
|
22
.github/workflows/go-test.yml
vendored
22
.github/workflows/go-test.yml
vendored
@@ -10,15 +10,17 @@ jobs:
|
|||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
os: [ "ubuntu", "windows", "macos" ]
|
os: [ "ubuntu", "windows", "macos" ]
|
||||||
go: [ "1.18.x", "1.19.x" ]
|
go: ["1.19.x","1.20.x"]
|
||||||
env:
|
env:
|
||||||
COVERAGES: ""
|
COVERAGES: ""
|
||||||
runs-on: ${{ format('{0}-latest', matrix.os) }}
|
runs-on: ${{ fromJSON(vars[format('UCI_GO_TEST_RUNNER_{0}', matrix.os)] || format('"{0}-latest"', matrix.os)) }}
|
||||||
name: ${{ matrix.os }} (go ${{ matrix.go }})
|
name: ${{ matrix.os }} (go ${{ matrix.go }})
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
- id: config
|
||||||
|
uses: protocol/.github/.github/actions/read-config@master
|
||||||
- uses: actions/setup-go@v3
|
- uses: actions/setup-go@v3
|
||||||
with:
|
with:
|
||||||
go-version: ${{ matrix.go }}
|
go-version: ${{ matrix.go }}
|
||||||
@@ -27,7 +29,7 @@ jobs:
|
|||||||
go version
|
go version
|
||||||
go env
|
go env
|
||||||
- name: Use msys2 on windows
|
- name: Use msys2 on windows
|
||||||
if: ${{ matrix.os == 'windows' }}
|
if: matrix.os == 'windows'
|
||||||
shell: bash
|
shell: bash
|
||||||
# The executable for msys2 is also called bash.cmd
|
# The executable for msys2 is also called bash.cmd
|
||||||
# https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md#shells
|
# https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md#shells
|
||||||
@@ -38,6 +40,7 @@ jobs:
|
|||||||
uses: ./.github/actions/go-test-setup
|
uses: ./.github/actions/go-test-setup
|
||||||
if: hashFiles('./.github/actions/go-test-setup') != ''
|
if: hashFiles('./.github/actions/go-test-setup') != ''
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
|
if: contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false
|
||||||
uses: protocol/multiple-go-modules@v1.2
|
uses: protocol/multiple-go-modules@v1.2
|
||||||
with:
|
with:
|
||||||
# Use -coverpkg=./..., so that we include cross-package coverage.
|
# Use -coverpkg=./..., so that we include cross-package coverage.
|
||||||
@@ -45,16 +48,21 @@ jobs:
|
|||||||
# this means ./B's coverage will be significantly higher than 0%.
|
# this means ./B's coverage will be significantly higher than 0%.
|
||||||
run: go test -v -shuffle=on -coverprofile=module-coverage.txt -coverpkg=./... ./...
|
run: go test -v -shuffle=on -coverprofile=module-coverage.txt -coverpkg=./... ./...
|
||||||
- name: Run tests (32 bit)
|
- name: Run tests (32 bit)
|
||||||
if: ${{ matrix.os != 'macos' }} # can't run 32 bit tests on OSX.
|
# can't run 32 bit tests on OSX.
|
||||||
|
if: matrix.os != 'macos' &&
|
||||||
|
fromJSON(steps.config.outputs.json).skip32bit != true &&
|
||||||
|
contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false
|
||||||
uses: protocol/multiple-go-modules@v1.2
|
uses: protocol/multiple-go-modules@v1.2
|
||||||
env:
|
env:
|
||||||
GOARCH: 386
|
GOARCH: 386
|
||||||
with:
|
with:
|
||||||
run: |
|
run: |
|
||||||
export "PATH=${{ env.PATH_386 }}:$PATH"
|
export "PATH=$PATH_386:$PATH"
|
||||||
go test -v -shuffle=on ./...
|
go test -v -shuffle=on ./...
|
||||||
- name: Run tests with race detector
|
- name: Run tests with race detector
|
||||||
if: ${{ matrix.os == 'ubuntu' }} # speed things up. Windows and OSX VMs are slow
|
# speed things up. Windows and OSX VMs are slow
|
||||||
|
if: matrix.os == 'ubuntu' &&
|
||||||
|
contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false
|
||||||
uses: protocol/multiple-go-modules@v1.2
|
uses: protocol/multiple-go-modules@v1.2
|
||||||
with:
|
with:
|
||||||
run: go test -v -race ./...
|
run: go test -v -race ./...
|
||||||
@@ -62,7 +70,7 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV
|
run: echo "COVERAGES=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_ENV
|
||||||
- name: Upload coverage to Codecov
|
- name: Upload coverage to Codecov
|
||||||
uses: codecov/codecov-action@81cd2dc8148241f03f5839d295e000b8f761e378 # v3.1.0
|
uses: codecov/codecov-action@d9f34f8cd5cb3b3eb79b3e4b5dae3a16df499a70 # v3.1.1
|
||||||
with:
|
with:
|
||||||
files: '${{ env.COVERAGES }}'
|
files: '${{ env.COVERAGES }}'
|
||||||
env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }}
|
env_vars: OS=${{ matrix.os }}, GO=${{ matrix.go }}
|
||||||
|
4
.github/workflows/release-check.yml
vendored
4
.github/workflows/release-check.yml
vendored
@@ -3,9 +3,11 @@
|
|||||||
|
|
||||||
name: Release Checker
|
name: Release Checker
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request_target:
|
||||||
paths: [ 'version.json' ]
|
paths: [ 'version.json' ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
release-check:
|
release-check:
|
||||||
uses: protocol/.github/.github/workflows/release-check.yml@master
|
uses: protocol/.github/.github/workflows/release-check.yml@master
|
||||||
|
with:
|
||||||
|
go-version: 1.20.x
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
package test
|
package test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"crypto/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/libp2p/go-libp2p/core/peer"
|
"github.com/libp2p/go-libp2p/core/peer"
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
module github.com/libp2p/go-libp2p/examples
|
module github.com/libp2p/go-libp2p/examples
|
||||||
|
|
||||||
go 1.18
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gogo/protobuf v1.3.2
|
github.com/gogo/protobuf v1.3.2
|
||||||
|
@@ -5,8 +5,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
fmt "fmt"
|
fmt "fmt"
|
||||||
proto "github.com/gogo/protobuf/proto"
|
|
||||||
math "math"
|
math "math"
|
||||||
|
|
||||||
|
proto "github.com/gogo/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
@@ -5,8 +5,9 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
fmt "fmt"
|
fmt "fmt"
|
||||||
proto "github.com/gogo/protobuf/proto"
|
|
||||||
math "math"
|
math "math"
|
||||||
|
|
||||||
|
proto "github.com/gogo/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
module github.com/libp2p/go-libp2p/examples/ipfs-camp-2019
|
module github.com/libp2p/go-libp2p/examples/ipfs-camp-2019
|
||||||
|
|
||||||
go 1.18
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gogo/protobuf v1.3.2
|
github.com/gogo/protobuf v1.3.2
|
||||||
|
@@ -13,9 +13,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
rnd := rand.New(rand.NewSource(666))
|
||||||
// Choose random ports between 10000-10100
|
// Choose random ports between 10000-10100
|
||||||
rand.Seed(666)
|
port1 := rnd.Intn(100) + 10000
|
||||||
port1 := rand.Intn(100) + 10000
|
|
||||||
port2 := port1 + 1
|
port2 := port1 + 1
|
||||||
|
|
||||||
done := make(chan bool, 1)
|
done := make(chan bool, 1)
|
||||||
|
@@ -3,9 +3,13 @@
|
|||||||
|
|
||||||
package protocols_p2p
|
package protocols_p2p
|
||||||
|
|
||||||
import proto "github.com/gogo/protobuf/proto"
|
import (
|
||||||
import fmt "fmt"
|
fmt "fmt"
|
||||||
import math "math"
|
|
||||||
|
proto "github.com/gogo/protobuf/proto"
|
||||||
|
|
||||||
|
math "math"
|
||||||
|
)
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
var _ = proto.Marshal
|
var _ = proto.Marshal
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
module github.com/libp2p/go-libp2p/examples/pubsub/chat
|
module github.com/libp2p/go-libp2p/examples/pubsub/chat
|
||||||
|
|
||||||
go 1.18
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/libp2p/go-libp2p v0.25.1
|
github.com/libp2p/go-libp2p v0.25.1
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
module github.com/libp2p/go-libp2p/examples/pubsub/chat
|
module github.com/libp2p/go-libp2p/examples/pubsub/chat
|
||||||
|
|
||||||
go 1.18
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gdamore/tcell/v2 v2.5.2
|
github.com/gdamore/tcell/v2 v2.5.2
|
||||||
|
2
go.mod
2
go.mod
@@ -1,6 +1,6 @@
|
|||||||
module github.com/libp2p/go-libp2p
|
module github.com/libp2p/go-libp2p
|
||||||
|
|
||||||
go 1.18
|
go 1.19
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/benbjohnson/clock v1.3.0
|
github.com/benbjohnson/clock v1.3.0
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
//go:build linux || darwin
|
//go:build linux || darwin
|
||||||
// +build linux darwin
|
|
||||||
|
|
||||||
package rcmgr
|
package rcmgr
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ package pnet
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"math/rand"
|
"crypto/rand"
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@@ -62,8 +62,7 @@ func TestPSKFragmentation(t *testing.T) {
|
|||||||
psk1, psk2 := setupPSKConns(ctx, t)
|
psk1, psk2 := setupPSKConns(ctx, t)
|
||||||
|
|
||||||
in := make([]byte, 1000)
|
in := make([]byte, 1000)
|
||||||
_, err := rand.Read(in)
|
if _, err := rand.Read(in); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,8 +84,7 @@ func TestPSKFragmentation(t *testing.T) {
|
|||||||
in = in[100:]
|
in = in[100:]
|
||||||
}
|
}
|
||||||
|
|
||||||
err = <-wch
|
if err := <-wch; err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,9 +3,9 @@ package relay_test
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"math/rand"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -325,8 +325,7 @@ func TestRelayLimitData(t *testing.T) {
|
|||||||
|
|
||||||
buf := make([]byte, 1024)
|
buf := make([]byte, 1024)
|
||||||
for i := 0; i < 3; i++ {
|
for i := 0; i < 3; i++ {
|
||||||
_, err = rand.Read(buf)
|
if _, err := rand.Read(buf); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,8 +344,7 @@ func TestRelayLimitData(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
buf = make([]byte, 4096)
|
buf = make([]byte, 4096)
|
||||||
_, err = rand.Read(buf)
|
if _, err := rand.Read(buf); err != nil {
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -271,12 +271,6 @@ func TestPeerIDOutboundNoCheck(t *testing.T) {
|
|||||||
require.NoError(t, initErr)
|
require.NoError(t, initErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeLargePlaintext(size int) []byte {
|
|
||||||
buf := make([]byte, size)
|
|
||||||
rand.Read(buf)
|
|
||||||
return buf
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLargePayloads(t *testing.T) {
|
func TestLargePayloads(t *testing.T) {
|
||||||
initTransport := newTestTransport(t, crypto.Ed25519, 2048)
|
initTransport := newTestTransport(t, crypto.Ed25519, 2048)
|
||||||
respTransport := newTestTransport(t, crypto.Ed25519, 2048)
|
respTransport := newTestTransport(t, crypto.Ed25519, 2048)
|
||||||
@@ -287,11 +281,12 @@ func TestLargePayloads(t *testing.T) {
|
|||||||
|
|
||||||
// enough to require a couple Noise messages, with a size that
|
// enough to require a couple Noise messages, with a size that
|
||||||
// isn't a neat multiple of Noise message size, just in case
|
// isn't a neat multiple of Noise message size, just in case
|
||||||
size := 100000
|
rnd := rand.New(rand.NewSource(1234))
|
||||||
|
const size = 100000
|
||||||
|
before := make([]byte, size)
|
||||||
|
rnd.Read(before)
|
||||||
|
|
||||||
before := makeLargePlaintext(size)
|
if _, err := initConn.Write(before); err != nil {
|
||||||
_, err := initConn.Write(before)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -71,6 +71,7 @@ func runRound(t *testing.T, hosts []host.Host) {
|
|||||||
numStreams = 5
|
numStreams = 5
|
||||||
maxDataLen = 64 << 10
|
maxDataLen = 64 << 10
|
||||||
)
|
)
|
||||||
|
rnd := rand.New(rand.NewSource(12345))
|
||||||
// exchange some data
|
// exchange some data
|
||||||
for _, h1 := range hosts {
|
for _, h1 := range hosts {
|
||||||
for _, h2 := range hosts {
|
for _, h2 := range hosts {
|
||||||
@@ -80,10 +81,10 @@ func runRound(t *testing.T, hosts []host.Host) {
|
|||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(numStreams)
|
wg.Add(numStreams)
|
||||||
for i := 0; i < numStreams; i++ {
|
for i := 0; i < numStreams; i++ {
|
||||||
|
data := make([]byte, rand.Intn(maxDataLen)+1)
|
||||||
|
rnd.Read(data)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
data := make([]byte, rand.Intn(maxDataLen)+1)
|
|
||||||
rand.Read(data)
|
|
||||||
str, err := h1.NewStream(context.Background(), h2.ID(), protocol.TestingID)
|
str, err := h1.NewStream(context.Background(), h2.ID(), protocol.TestingID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer str.Close()
|
defer str.Close()
|
||||||
|
@@ -45,6 +45,7 @@ type transport struct {
|
|||||||
|
|
||||||
holePunchingMx sync.Mutex
|
holePunchingMx sync.Mutex
|
||||||
holePunching map[holePunchKey]*activeHolePunch
|
holePunching map[holePunchKey]*activeHolePunch
|
||||||
|
rnd rand.Rand
|
||||||
|
|
||||||
connMx sync.Mutex
|
connMx sync.Mutex
|
||||||
conns map[quic.Connection]*conn
|
conns map[quic.Connection]*conn
|
||||||
@@ -94,6 +95,7 @@ func NewTransport(key ic.PrivKey, connManager *quicreuse.ConnManager, psk pnet.P
|
|||||||
rcmgr: rcmgr,
|
rcmgr: rcmgr,
|
||||||
conns: make(map[quic.Connection]*conn),
|
conns: make(map[quic.Connection]*conn),
|
||||||
holePunching: make(map[holePunchKey]*activeHolePunch),
|
holePunching: make(map[holePunchKey]*activeHolePunch),
|
||||||
|
rnd: *rand.New(rand.NewSource(time.Now().UnixNano())),
|
||||||
|
|
||||||
listeners: make(map[string][]*virtualListener),
|
listeners: make(map[string][]*virtualListener),
|
||||||
}, nil
|
}, nil
|
||||||
@@ -217,7 +219,7 @@ 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 := rand.Read(payload); err != nil {
|
if _, err := t.rnd.Read(payload); err != nil {
|
||||||
punchErr = err
|
punchErr = err
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user