mirror of
https://github.com/pion/stun.git
synced 2025-10-07 00:32:59 +08:00
Update CI configs to v0.4.5
Update lint scripts and CI configs. Excluding codecov.yml.
This commit is contained in:
37
.github/workflows/lint.yaml
vendored
Normal file
37
.github/workflows/lint.yaml
vendored
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
name: Lint
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
types:
|
||||||
|
- opened
|
||||||
|
- edited
|
||||||
|
- synchronize
|
||||||
|
jobs:
|
||||||
|
lint-commit-message:
|
||||||
|
name: Metadata
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Commit Message
|
||||||
|
run: .github/lint-commit-message.sh
|
||||||
|
|
||||||
|
- name: File names
|
||||||
|
run: .github/lint-filename.sh
|
||||||
|
|
||||||
|
- name: Contributors
|
||||||
|
run: .github/assert-contributors.sh
|
||||||
|
|
||||||
|
- name: Functions
|
||||||
|
run: .github/lint-disallowed-functions-in-library.sh
|
||||||
|
|
||||||
|
lint-go:
|
||||||
|
name: Go
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: golangci-lint
|
||||||
|
uses: golangci/golangci-lint-action@v1
|
||||||
|
with:
|
||||||
|
version: v1.31
|
||||||
|
args: $GOLANGCI_LINT_EXRA_ARGS
|
132
.github/workflows/test.yaml
vendored
Normal file
132
.github/workflows/test.yaml
vendored
Normal file
@@ -0,0 +1,132 @@
|
|||||||
|
name: Test
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
go: ["1.14", "1.15"]
|
||||||
|
name: Go ${{ matrix.go }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Go
|
||||||
|
uses: actions/setup-go@v1
|
||||||
|
with:
|
||||||
|
go-version: ${{ matrix.go }}
|
||||||
|
|
||||||
|
- name: Set test packages
|
||||||
|
run: echo ::set-env name=TEST_PACKAGES::$(go list ./... | grep -v examples)
|
||||||
|
|
||||||
|
- name: Run test
|
||||||
|
run: |
|
||||||
|
go test \
|
||||||
|
-coverprofile=cover.out -covermode=atomic \
|
||||||
|
${TEST_EXTRA_ARGS:-} \
|
||||||
|
-v -race ${TEST_PACKAGES}
|
||||||
|
|
||||||
|
- uses: codecov/codecov-action@v1
|
||||||
|
with:
|
||||||
|
file: ./cover.out
|
||||||
|
name: codecov-umbrella
|
||||||
|
fail_ci_if_error: true
|
||||||
|
flags: go
|
||||||
|
|
||||||
|
test-i386:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
go: ["1.14", "1.15"]
|
||||||
|
name: Go i386 ${{ matrix.go }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/go/pkg/mod
|
||||||
|
~/.cache
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
|
||||||
|
- name: Set test packages
|
||||||
|
run: echo ::set-env name=TEST_PACKAGES::$(go list ./... | grep -v examples)
|
||||||
|
|
||||||
|
- name: Run test
|
||||||
|
run: |
|
||||||
|
docker run \
|
||||||
|
-u $(id -u):$(id -g) \
|
||||||
|
-e "GO111MODULE=on" \
|
||||||
|
-e "CGO_ENABLED=0" \
|
||||||
|
-v $GITHUB_WORKSPACE:/go/src/github.com/pion/$(basename $GITHUB_WORKSPACE) \
|
||||||
|
-v $HOME/go/pkg/mod:/go/pkg/mod \
|
||||||
|
-v $HOME/.cache:/.cache \
|
||||||
|
-w /go/src/github.com/pion/$(basename $GITHUB_WORKSPACE) \
|
||||||
|
i386/golang:${{matrix.go}}-alpine \
|
||||||
|
/usr/local/go/bin/go test \
|
||||||
|
${TEST_EXTRA_ARGS:-} \
|
||||||
|
-v ${TEST_PACKAGES}
|
||||||
|
|
||||||
|
test-wasm:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: WASM
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Use Node.js
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: '12.x'
|
||||||
|
|
||||||
|
- uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/go/pkg/mod
|
||||||
|
~/.cache
|
||||||
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: |
|
||||||
|
${{ runner.os }}-go-
|
||||||
|
|
||||||
|
- name: Set test packages
|
||||||
|
run: echo ::set-env name=TEST_PACKAGES::$(go list ./... | grep -v examples)
|
||||||
|
|
||||||
|
- name: Download Go
|
||||||
|
run: curl -sSfL https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz | tar -C ~ -xzf -
|
||||||
|
env:
|
||||||
|
GO_VERSION: 1.15
|
||||||
|
|
||||||
|
- name: Set Go Root
|
||||||
|
run: echo ::set-env name=GOROOT::${HOME}/go
|
||||||
|
|
||||||
|
- name: Set Go Path
|
||||||
|
run: echo ::set-env name=GOPATH::${HOME}/go
|
||||||
|
|
||||||
|
- name: Update Path
|
||||||
|
run: echo ::set-env name=PATH::${GOROOT}/bin:${PATH}
|
||||||
|
|
||||||
|
- name: Set Go WASM Exec
|
||||||
|
run: echo ::set-env name=GO_JS_WASM_EXEC::${GOROOT}/misc/wasm/go_js_wasm_exec
|
||||||
|
|
||||||
|
- name: Insall NPM modules
|
||||||
|
run: yarn install
|
||||||
|
|
||||||
|
- name: Run Tests
|
||||||
|
run: |
|
||||||
|
GOOS=js GOARCH=wasm go test \
|
||||||
|
-coverprofile=cover.out -covermode=atomic \
|
||||||
|
-exec="${GO_JS_WASM_EXEC}" \
|
||||||
|
-v ${TEST_PACKAGES}
|
||||||
|
|
||||||
|
- uses: codecov/codecov-action@v1
|
||||||
|
with:
|
||||||
|
file: ./cover.out
|
||||||
|
name: codecov-umbrella
|
||||||
|
fail_ci_if_error: true
|
||||||
|
flags: wasm
|
@@ -1,93 +1,8 @@
|
|||||||
linters-settings:
|
linters-settings:
|
||||||
govet:
|
govet:
|
||||||
check-shadowing: true
|
check-shadowing: true
|
||||||
golint:
|
|
||||||
min-confidence: 0
|
|
||||||
gocyclo:
|
|
||||||
min-complexity: 15
|
|
||||||
maligned:
|
|
||||||
suggest-new: true
|
|
||||||
dupl:
|
|
||||||
threshold: 100
|
|
||||||
goconst:
|
|
||||||
min-len: 2
|
|
||||||
min-occurrences: 2
|
|
||||||
misspell:
|
misspell:
|
||||||
locale: US
|
locale: US
|
||||||
lll:
|
|
||||||
line-length: 140
|
|
||||||
goimports:
|
|
||||||
local-prefixes: github.com/pion
|
|
||||||
gocritic:
|
|
||||||
enabled-tags:
|
|
||||||
- performance
|
|
||||||
- style
|
|
||||||
- experimental
|
|
||||||
disabled-checks:
|
|
||||||
- commentedOutCode
|
|
||||||
- sloppyReassign
|
|
||||||
|
|
||||||
issues:
|
|
||||||
exclude:
|
|
||||||
- "`assertHMACSize` - `blocksize` always receives `64`"
|
|
||||||
exclude-rules:
|
|
||||||
- text: "string `<nil>`"
|
|
||||||
linters:
|
|
||||||
- goconst
|
|
||||||
|
|
||||||
# Exclude some linters from running on tests files.
|
|
||||||
- path: _test\.go
|
|
||||||
linters:
|
|
||||||
- gocyclo
|
|
||||||
- errcheck
|
|
||||||
- dupl
|
|
||||||
- gosec
|
|
||||||
- goconst
|
|
||||||
|
|
||||||
# Ease some gocritic warnings on test files.
|
|
||||||
- path: _test\.go
|
|
||||||
text: "(unnamedResult|exitAfterDefer|unlambda)"
|
|
||||||
linters:
|
|
||||||
- gocritic
|
|
||||||
|
|
||||||
# Exclude known linters from partially hard-vendored code,
|
|
||||||
# which is impossible to exclude via "nolint" comments.
|
|
||||||
- path: internal/hmac/
|
|
||||||
text: "weak cryptographic primitive"
|
|
||||||
linters:
|
|
||||||
- gosec
|
|
||||||
- path: internal/hmac/
|
|
||||||
text: "Write\\` is not checked"
|
|
||||||
linters:
|
|
||||||
- errcheck
|
|
||||||
|
|
||||||
# Ease linting on benchmarking code.
|
|
||||||
- path: cmd/stun-bench/
|
|
||||||
linters:
|
|
||||||
- gosec
|
|
||||||
- errcheck
|
|
||||||
- unparam
|
|
||||||
|
|
||||||
- path: ^cmd/
|
|
||||||
linters:
|
|
||||||
- gocyclo
|
|
||||||
- path: ^cmd/
|
|
||||||
text: "(unnamedResult|exitAfterDefer)"
|
|
||||||
linters:
|
|
||||||
- gocritic
|
|
||||||
|
|
||||||
linters:
|
|
||||||
enable-all: true
|
|
||||||
disable:
|
|
||||||
- funlen
|
|
||||||
- gochecknoglobals
|
|
||||||
- godox
|
|
||||||
- prealloc
|
|
||||||
- scopelint
|
|
||||||
|
|
||||||
run:
|
run:
|
||||||
skip-dirs:
|
skip-dirs-use-default: false
|
||||||
- e2e
|
|
||||||
- fuzz
|
|
||||||
- testdata
|
|
||||||
- api
|
|
||||||
|
142
.travis.yml
142
.travis.yml
@@ -1,142 +0,0 @@
|
|||||||
#
|
|
||||||
# DO NOT EDIT THIS FILE
|
|
||||||
#
|
|
||||||
# It is automatically copied from https://github.com/pion/.goassets repository.
|
|
||||||
# If this repository should have package specific CI config,
|
|
||||||
# remove the repository name from .goassets/.github/workflows/assets-sync.yml.
|
|
||||||
#
|
|
||||||
# If you want to update the shared CI config, send a PR to
|
|
||||||
# https://github.com/pion/.goassets instead of this repository.
|
|
||||||
#
|
|
||||||
|
|
||||||
dist: bionic
|
|
||||||
language: go
|
|
||||||
|
|
||||||
|
|
||||||
branches:
|
|
||||||
only:
|
|
||||||
- master
|
|
||||||
|
|
||||||
env:
|
|
||||||
global:
|
|
||||||
- GO111MODULE=on
|
|
||||||
- GOLANGCI_LINT_VERSION=1.19.1
|
|
||||||
|
|
||||||
cache:
|
|
||||||
directories:
|
|
||||||
- ${HOME}/.cache/go-build
|
|
||||||
- ${GOPATH}/pkg/mod
|
|
||||||
npm: true
|
|
||||||
yarn: true
|
|
||||||
|
|
||||||
_lint_job: &lint_job
|
|
||||||
env: CACHE_NAME=lint
|
|
||||||
before_install:
|
|
||||||
- if [ -f .github/.ci.conf ]; then . .github/.ci.conf; fi
|
|
||||||
install: skip
|
|
||||||
before_script:
|
|
||||||
- |
|
|
||||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh \
|
|
||||||
| bash -s - -b $GOPATH/bin v${GOLANGCI_LINT_VERSION}
|
|
||||||
script:
|
|
||||||
- bash .github/assert-contributors.sh
|
|
||||||
- bash .github/lint-disallowed-functions-in-library.sh
|
|
||||||
- bash .github/lint-commit-message.sh
|
|
||||||
- bash .github/lint-filename.sh
|
|
||||||
- golangci-lint run ${GOLANGCI_LINT_EXRA_ARGS:-} ./...
|
|
||||||
_test_job: &test_job
|
|
||||||
env: CACHE_NAME=test
|
|
||||||
before_install:
|
|
||||||
- if [ -f .github/.ci.conf ]; then . .github/.ci.conf; fi
|
|
||||||
- go mod download
|
|
||||||
install:
|
|
||||||
- go build ./...
|
|
||||||
script:
|
|
||||||
# If you want to specify repository specific test packages rule,
|
|
||||||
# add `TEST_PACKAGES=$(command to list test target packages)` to .github/.ci.conf
|
|
||||||
- testpkgs=${TEST_PACKAGES:-$(go list ./... | grep -v examples)}
|
|
||||||
- coverpkgs=$(echo "${testpkgs}" | paste -s -d ',')
|
|
||||||
- |
|
|
||||||
go test \
|
|
||||||
-coverpkg=${coverpkgs} -coverprofile=cover.out -covermode=atomic \
|
|
||||||
${TEST_EXTRA_ARGS:-} \
|
|
||||||
-v -race ${testpkgs}
|
|
||||||
- if [ -n "${TEST_HOOK}" ]; then ${TEST_HOOK}; fi
|
|
||||||
after_success:
|
|
||||||
- travis_retry bash <(curl -s https://codecov.io/bash) -c -F go
|
|
||||||
_test_i386_job: &test_i386_job
|
|
||||||
env: CACHE_NAME=test386
|
|
||||||
services: docker
|
|
||||||
before_install:
|
|
||||||
- if [ -f .github/.ci.conf ]; then . .github/.ci.conf; fi
|
|
||||||
script:
|
|
||||||
- testpkgs=${TEST_PACKAGES:-$(go list ./... | grep -v examples)}
|
|
||||||
- |
|
|
||||||
docker run \
|
|
||||||
-u $(id -u):$(id -g) \
|
|
||||||
-e "GO111MODULE=on" \
|
|
||||||
-e "CGO_ENABLED=0" \
|
|
||||||
-v ${PWD}:/go/src/github.com/pion/$(basename ${PWD}) \
|
|
||||||
-v ${HOME}/gopath/pkg/mod:/go/pkg/mod \
|
|
||||||
-v ${HOME}/.cache/go-build:/.cache/go-build \
|
|
||||||
-w /go/src/github.com/pion/$(basename ${PWD}) \
|
|
||||||
-it i386/golang:${GO_VERSION}-alpine \
|
|
||||||
/usr/local/go/bin/go test \
|
|
||||||
${TEST_EXTRA_ARGS:-} \
|
|
||||||
-v ${testpkgs}
|
|
||||||
_test_wasm_job: &test_wasm_job
|
|
||||||
env: CACHE_NAME=wasm
|
|
||||||
language: node_js
|
|
||||||
node_js: 12
|
|
||||||
before_install:
|
|
||||||
- if [ -f .github/.ci.conf ]; then . .github/.ci.conf; fi
|
|
||||||
- if ${SKIP_WASM_TEST:-false}; then exit 0; fi
|
|
||||||
install:
|
|
||||||
# Manually download and install Go instead of using gimme.
|
|
||||||
# It looks like gimme Go causes some errors on go-test for Wasm.
|
|
||||||
- curl -sSfL https://dl.google.com/go/go${GO_VERSION}.linux-amd64.tar.gz | tar -C ~ -xzf -
|
|
||||||
- export GOROOT=${HOME}/go
|
|
||||||
- export PATH=${GOROOT}/bin:${PATH}
|
|
||||||
- yarn install
|
|
||||||
- export GO_JS_WASM_EXEC=${GO_JS_WASM_EXEC:-${GOROOT}/misc/wasm/go_js_wasm_exec}
|
|
||||||
script:
|
|
||||||
- testpkgs=${TEST_PACKAGES:-$(go list ./... | grep -v examples)}
|
|
||||||
- coverpkgs=$(echo "${testpkgs}" | paste -s -d ',')
|
|
||||||
- |
|
|
||||||
GOOS=js GOARCH=wasm go test \
|
|
||||||
-coverpkg=${coverpkgs} -coverprofile=cover.out -covermode=atomic \
|
|
||||||
-exec="${GO_JS_WASM_EXEC}" \
|
|
||||||
-v ${testpkgs}
|
|
||||||
after_success:
|
|
||||||
- travis_retry bash <(curl -s https://codecov.io/bash) -c -F wasm
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
include:
|
|
||||||
- <<: *lint_job
|
|
||||||
name: Lint 1.15
|
|
||||||
go: 1.15
|
|
||||||
- <<: *test_job
|
|
||||||
name: Test 1.14
|
|
||||||
go: 1.14
|
|
||||||
- <<: *test_job
|
|
||||||
name: Test 1.15
|
|
||||||
go: 1.15
|
|
||||||
- <<: *test_i386_job
|
|
||||||
name: Test i386 1.14
|
|
||||||
env: GO_VERSION=1.14
|
|
||||||
go: 1.15 # Go version for host environment only for `go list`.
|
|
||||||
# All tests are done on the version specified by GO_VERSION.
|
|
||||||
- <<: *test_i386_job
|
|
||||||
name: Test i386 1.15
|
|
||||||
env: GO_VERSION=1.15
|
|
||||||
go: 1.15 # Go version for host environment only for `go list`.
|
|
||||||
# All tests are done on the version specified by GO_VERSION.
|
|
||||||
- <<: *test_wasm_job
|
|
||||||
name: Test WASM 1.14
|
|
||||||
env: GO_VERSION=1.14
|
|
||||||
- <<: *test_wasm_job
|
|
||||||
name: Test WASM 1.15
|
|
||||||
env: GO_VERSION=1.15
|
|
||||||
|
|
||||||
notifications:
|
|
||||||
email: false
|
|
@@ -129,7 +129,7 @@ func TestAgent_GC(t *testing.T) {
|
|||||||
)
|
)
|
||||||
gcDeadline := deadline.Add(-time.Second)
|
gcDeadline := deadline.Add(-time.Second)
|
||||||
deadlineNotGC := gcDeadline.AddDate(0, 0, -1)
|
deadlineNotGC := gcDeadline.AddDate(0, 0, -1)
|
||||||
a.SetHandler(func(e Event) {
|
a.SetHandler(func(e Event) { //nolint: errcheck
|
||||||
id := e.TransactionID
|
id := e.TransactionID
|
||||||
shouldTimeOut, found := shouldTimeOutID[id]
|
shouldTimeOut, found := shouldTimeOutID[id]
|
||||||
if !found {
|
if !found {
|
||||||
|
@@ -9,7 +9,7 @@ func BenchmarkMessage_GetNotFound(b *testing.B) {
|
|||||||
m := New()
|
m := New()
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
m.Get(AttrRealm)
|
m.Get(AttrRealm) //nolint: errcheck
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ func BenchmarkMessage_Get(b *testing.B) {
|
|||||||
m.Add(AttrUsername, []byte{1, 2, 3, 4, 5, 6, 7})
|
m.Add(AttrUsername, []byte{1, 2, 3, 4, 5, 6, 7})
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
m.Get(AttrUsername)
|
m.Get(AttrUsername) //nolint: errcheck
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,12 +42,12 @@ func TestRawAttribute_AddTo(t *testing.T) {
|
|||||||
|
|
||||||
func TestMessage_GetNoAllocs(t *testing.T) {
|
func TestMessage_GetNoAllocs(t *testing.T) {
|
||||||
m := New()
|
m := New()
|
||||||
NewSoftware("c").AddTo(m)
|
NewSoftware("c").AddTo(m) //nolint: errcheck
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
|
|
||||||
t.Run("Default", func(t *testing.T) {
|
t.Run("Default", func(t *testing.T) {
|
||||||
allocs := testing.AllocsPerRun(10, func() {
|
allocs := testing.AllocsPerRun(10, func() {
|
||||||
m.Get(AttrSoftware)
|
m.Get(AttrSoftware) //nolint: errcheck
|
||||||
})
|
})
|
||||||
if allocs > 0 {
|
if allocs > 0 {
|
||||||
t.Error("allocated memory, but should not")
|
t.Error("allocated memory, but should not")
|
||||||
@@ -55,7 +55,7 @@ func TestMessage_GetNoAllocs(t *testing.T) {
|
|||||||
})
|
})
|
||||||
t.Run("Not found", func(t *testing.T) {
|
t.Run("Not found", func(t *testing.T) {
|
||||||
allocs := testing.AllocsPerRun(10, func() {
|
allocs := testing.AllocsPerRun(10, func() {
|
||||||
m.Get(AttrOrigin)
|
m.Get(AttrOrigin) //nolint: errcheck
|
||||||
})
|
})
|
||||||
if allocs > 0 {
|
if allocs > 0 {
|
||||||
t.Error("allocated memory, but should not")
|
t.Error("allocated memory, but should not")
|
||||||
|
@@ -83,7 +83,7 @@ func BenchmarkClient_Do(b *testing.B) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
m := New()
|
m := New()
|
||||||
m.NewTransactionID()
|
m.NewTransactionID() //nolint: errcheck
|
||||||
m.Encode()
|
m.Encode()
|
||||||
for pb.Next() {
|
for pb.Next() {
|
||||||
if err := client.Do(m, noopF); err != nil {
|
if err := client.Do(m, noopF); err != nil {
|
||||||
@@ -1426,7 +1426,7 @@ func TestClientImmediateTimeout(t *testing.T) {
|
|||||||
}
|
}
|
||||||
gotReads <- struct{}{}
|
gotReads <- struct{}{}
|
||||||
}()
|
}()
|
||||||
c.Start(MustBuild(response, BindingRequest), func(e Event) {
|
c.Start(MustBuild(response, BindingRequest), func(e Event) { //nolint: errcheck
|
||||||
if e.Error == ErrTransactionTimeOut {
|
if e.Error == ErrTransactionTimeOut {
|
||||||
t.Error("unexpected error")
|
t.Error("unexpected error")
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,7 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
workers = flag.Int("w", runtime.GOMAXPROCS(0), "concurrent workers")
|
workers = flag.Int("w", runtime.GOMAXPROCS(0), "concurrent workers")
|
||||||
addr = flag.String("addr", fmt.Sprintf("localhost"), "target address")
|
addr = flag.String("addr", "localhost", "target address")
|
||||||
port = flag.Int("port", stun.DefaultPort, "target port")
|
port = flag.Int("port", stun.DefaultPort, "target port")
|
||||||
duration = flag.Duration("d", time.Minute, "benchmark duration")
|
duration = flag.Duration("d", time.Minute, "benchmark duration")
|
||||||
network = flag.String("net", "udp", "protocol to use (udp, tcp)")
|
network = flag.String("net", "udp", "protocol to use (udp, tcp)")
|
||||||
@@ -95,7 +95,9 @@ func main() {
|
|||||||
req := stun.New()
|
req := stun.New()
|
||||||
for {
|
for {
|
||||||
if *realRand {
|
if *realRand {
|
||||||
rand.Read(req.TransactionID[:])
|
if _, err := rand.Read(req.TransactionID[:]); err != nil {
|
||||||
|
log.Fatal("rand.Read failed:", err)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mathRand.Read(req.TransactionID[:])
|
mathRand.Read(req.TransactionID[:])
|
||||||
}
|
}
|
||||||
|
@@ -14,7 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
server = flag.String("server", fmt.Sprintf("pion.ly:3478"), "Stun server address")
|
server = flag.String("server", "pion.ly:3478", "Stun server address")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@@ -12,7 +12,7 @@ func BenchmarkErrorCode_AddTo(b *testing.B) {
|
|||||||
m := New()
|
m := New()
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
CodeStaleNonce.AddTo(m)
|
CodeStaleNonce.AddTo(m) //nolint: errcheck
|
||||||
m.Reset()
|
m.Reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -25,7 +25,7 @@ func BenchmarkErrorCodeAttribute_AddTo(b *testing.B) {
|
|||||||
Reason: []byte("not found!"),
|
Reason: []byte("not found!"),
|
||||||
}
|
}
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
a.AddTo(m)
|
a.AddTo(m) //nolint: errcheck
|
||||||
m.Reset()
|
m.Reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,9 +37,9 @@ func BenchmarkErrorCodeAttribute_GetFrom(b *testing.B) {
|
|||||||
Code: 404,
|
Code: 404,
|
||||||
Reason: []byte("not found!"),
|
Reason: []byte("not found!"),
|
||||||
}
|
}
|
||||||
a.AddTo(m)
|
a.AddTo(m) //nolint: errcheck
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
a.GetFrom(m)
|
a.GetFrom(m) //nolint: errcheck
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ func TestMessage_AddErrorCode(t *testing.T) {
|
|||||||
copy(m.TransactionID[:], transactionID)
|
copy(m.TransactionID[:], transactionID)
|
||||||
expectedCode := ErrorCode(438)
|
expectedCode := ErrorCode(438)
|
||||||
expectedReason := "Stale Nonce"
|
expectedReason := "Stale Nonce"
|
||||||
CodeStaleNonce.AddTo(m)
|
CodeStaleNonce.AddTo(m) //nolint: errcheck
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
|
|
||||||
mRes := New()
|
mRes := New()
|
||||||
|
@@ -18,7 +18,7 @@ func BenchmarkFingerprint_AddTo(b *testing.B) {
|
|||||||
addAttr(b, m, s)
|
addAttr(b, m, s)
|
||||||
b.SetBytes(int64(len(m.Raw)))
|
b.SetBytes(int64(len(m.Raw)))
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
Fingerprint.AddTo(m)
|
Fingerprint.AddTo(m) //nolint: errcheck
|
||||||
m.WriteLength()
|
m.WriteLength()
|
||||||
m.Length -= attributeHeaderSize + fingerprintSize
|
m.Length -= attributeHeaderSize + fingerprintSize
|
||||||
m.Raw = m.Raw[:m.Length+messageHeaderSize]
|
m.Raw = m.Raw[:m.Length+messageHeaderSize]
|
||||||
@@ -30,7 +30,7 @@ func TestFingerprint_Check(t *testing.T) {
|
|||||||
m := new(Message)
|
m := new(Message)
|
||||||
addAttr(t, m, NewSoftware("software"))
|
addAttr(t, m, NewSoftware("software"))
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
Fingerprint.AddTo(m)
|
Fingerprint.AddTo(m) //nolint: errcheck
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
if err := Fingerprint.Check(m); err != nil {
|
if err := Fingerprint.Check(m); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
@@ -64,7 +64,7 @@ func BenchmarkFingerprint_Check(b *testing.B) {
|
|||||||
addAttr(b, m, addr)
|
addAttr(b, m, addr)
|
||||||
addAttr(b, m, s)
|
addAttr(b, m, s)
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
Fingerprint.AddTo(m)
|
Fingerprint.AddTo(m) //nolint: errcheck
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
b.SetBytes(int64(len(m.Raw)))
|
b.SetBytes(int64(len(m.Raw)))
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
|
@@ -19,14 +19,14 @@ func BenchmarkBuildOverhead(b *testing.B) {
|
|||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
m := new(Message)
|
m := new(Message)
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
m.Build(&t, &username, &nonce, &realm, &Fingerprint)
|
m.Build(&t, &username, &nonce, &realm, &Fingerprint) //nolint: errcheck
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
b.Run("BuildNonPointer", func(b *testing.B) {
|
b.Run("BuildNonPointer", func(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
m := new(Message)
|
m := new(Message)
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
m.Build(t, username, nonce, realm, Fingerprint)
|
m.Build(t, username, nonce, realm, Fingerprint) //nolint: errcheck //nolint: errcheck
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
b.Run("Raw", func(b *testing.B) {
|
b.Run("Raw", func(b *testing.B) {
|
||||||
@@ -36,10 +36,10 @@ func BenchmarkBuildOverhead(b *testing.B) {
|
|||||||
m.Reset()
|
m.Reset()
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
m.SetType(t)
|
m.SetType(t)
|
||||||
username.AddTo(m)
|
username.AddTo(m) //nolint: errcheck
|
||||||
nonce.AddTo(m)
|
nonce.AddTo(m) //nolint: errcheck
|
||||||
realm.AddTo(m)
|
realm.AddTo(m) //nolint: errcheck
|
||||||
Fingerprint.AddTo(m)
|
Fingerprint.AddTo(m) //nolint: errcheck
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@@ -21,7 +21,7 @@ func TestMessageIntegrity_AddTo_Simple(t *testing.T) {
|
|||||||
if err := i.AddTo(m); err != nil {
|
if err := i.AddTo(m); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
NewSoftware("software").AddTo(m)
|
NewSoftware("software").AddTo(m) //nolint: errcheck
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
dM := new(Message)
|
dM := new(Message)
|
||||||
dM.Raw = m.Raw
|
dM.Raw = m.Raw
|
||||||
@@ -42,7 +42,7 @@ func TestMessageIntegrityWithFingerprint(t *testing.T) {
|
|||||||
m := new(Message)
|
m := new(Message)
|
||||||
m.TransactionID = [TransactionIDSize]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
|
m.TransactionID = [TransactionIDSize]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
NewSoftware("software").AddTo(m)
|
NewSoftware("software").AddTo(m) //nolint: errcheck
|
||||||
i := NewShortTermIntegrity("pwd")
|
i := NewShortTermIntegrity("pwd")
|
||||||
if i.String() != "KEY: 0x707764" {
|
if i.String() != "KEY: 0x707764" {
|
||||||
t.Error("bad string", i)
|
t.Error("bad string", i)
|
||||||
@@ -81,7 +81,7 @@ func TestMessageIntegrity(t *testing.T) {
|
|||||||
func TestMessageIntegrityBeforeFingerprint(t *testing.T) {
|
func TestMessageIntegrityBeforeFingerprint(t *testing.T) {
|
||||||
m := new(Message)
|
m := new(Message)
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
Fingerprint.AddTo(m)
|
Fingerprint.AddTo(m) //nolint: errcheck
|
||||||
i := NewShortTermIntegrity("password")
|
i := NewShortTermIntegrity("password")
|
||||||
if err := i.AddTo(m); err == nil {
|
if err := i.AddTo(m); err == nil {
|
||||||
t.Error("should error")
|
t.Error("should error")
|
||||||
@@ -106,7 +106,7 @@ func BenchmarkMessageIntegrity_Check(b *testing.B) {
|
|||||||
m := new(Message)
|
m := new(Message)
|
||||||
// TODO: Find a way to make this test zero-alloc without excessive pre-alloc.
|
// TODO: Find a way to make this test zero-alloc without excessive pre-alloc.
|
||||||
m.Raw = make([]byte, 0, 1024)
|
m.Raw = make([]byte, 0, 1024)
|
||||||
NewSoftware("software").AddTo(m)
|
NewSoftware("software").AddTo(m) //nolint: errcheck
|
||||||
integrity := NewShortTermIntegrity("password")
|
integrity := NewShortTermIntegrity("password")
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
|
@@ -45,8 +45,8 @@ func (h *hmac) Sum(in []byte) []byte {
|
|||||||
origLen := len(in)
|
origLen := len(in)
|
||||||
in = h.inner.Sum(in)
|
in = h.inner.Sum(in)
|
||||||
h.outer.Reset()
|
h.outer.Reset()
|
||||||
h.outer.Write(h.opad)
|
h.outer.Write(h.opad) //nolint: errcheck
|
||||||
h.outer.Write(in[origLen:])
|
h.outer.Write(in[origLen:]) //nolint: errcheck
|
||||||
return h.outer.Sum(in[:origLen])
|
return h.outer.Sum(in[:origLen])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ func (h *hmac) BlockSize() int { return h.blocksize }
|
|||||||
|
|
||||||
func (h *hmac) Reset() {
|
func (h *hmac) Reset() {
|
||||||
h.inner.Reset()
|
h.inner.Reset()
|
||||||
h.inner.Write(h.ipad)
|
h.inner.Write(h.ipad) //nolint: errcheck
|
||||||
}
|
}
|
||||||
|
|
||||||
// New returns a new HMAC hash using the given hash.Hash type and key.
|
// New returns a new HMAC hash using the given hash.Hash type and key.
|
||||||
@@ -77,7 +77,7 @@ func New(h func() hash.Hash, key []byte) hash.Hash {
|
|||||||
hm.opad = make([]byte, hm.blocksize)
|
hm.opad = make([]byte, hm.blocksize)
|
||||||
if len(key) > hm.blocksize {
|
if len(key) > hm.blocksize {
|
||||||
// If key is too big, hash it.
|
// If key is too big, hash it.
|
||||||
hm.outer.Write(key)
|
hm.outer.Write(key) //nolint: errcheck
|
||||||
key = hm.outer.Sum(nil)
|
key = hm.outer.Sum(nil)
|
||||||
}
|
}
|
||||||
copy(hm.ipad, key)
|
copy(hm.ipad, key)
|
||||||
@@ -88,7 +88,7 @@ func New(h func() hash.Hash, key []byte) hash.Hash {
|
|||||||
for i := range hm.opad {
|
for i := range hm.opad {
|
||||||
hm.opad[i] ^= 0x5c
|
hm.opad[i] ^= 0x5c
|
||||||
}
|
}
|
||||||
hm.inner.Write(hm.ipad)
|
hm.inner.Write(hm.ipad) //nolint: errcheck
|
||||||
return hm
|
return hm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -575,7 +575,7 @@ func BenchmarkHMACSHA256_1K(b *testing.B) {
|
|||||||
h := New(sha256.New, key)
|
h := New(sha256.New, key)
|
||||||
b.SetBytes(int64(len(buf)))
|
b.SetBytes(int64(len(buf)))
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
h.Write(buf)
|
h.Write(buf) //nolint: errcheck
|
||||||
h.Reset()
|
h.Reset()
|
||||||
mac := h.Sum(nil)
|
mac := h.Sum(nil)
|
||||||
buf[0] = mac[0]
|
buf[0] = mac[0]
|
||||||
@@ -588,7 +588,7 @@ func BenchmarkHMACSHA256_32(b *testing.B) {
|
|||||||
h := New(sha256.New, key)
|
h := New(sha256.New, key)
|
||||||
b.SetBytes(int64(len(buf)))
|
b.SetBytes(int64(len(buf)))
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
h.Write(buf)
|
h.Write(buf) //nolint: errcheck
|
||||||
h.Reset()
|
h.Reset()
|
||||||
mac := h.Sum(nil)
|
mac := h.Sum(nil)
|
||||||
buf[0] = mac[0]
|
buf[0] = mac[0]
|
||||||
|
@@ -23,7 +23,7 @@ func (h *hmac) resetTo(key []byte) {
|
|||||||
setZeroes(h.opad)
|
setZeroes(h.opad)
|
||||||
if len(key) > h.blocksize {
|
if len(key) > h.blocksize {
|
||||||
// If key is too big, hash it.
|
// If key is too big, hash it.
|
||||||
h.outer.Write(key)
|
h.outer.Write(key) //nolint: errcheck
|
||||||
key = h.outer.Sum(nil)
|
key = h.outer.Sum(nil)
|
||||||
}
|
}
|
||||||
copy(h.ipad, key)
|
copy(h.ipad, key)
|
||||||
@@ -34,7 +34,7 @@ func (h *hmac) resetTo(key []byte) {
|
|||||||
for i := range h.opad {
|
for i := range h.opad {
|
||||||
h.opad[i] ^= 0x5c
|
h.opad[i] ^= 0x5c
|
||||||
}
|
}
|
||||||
h.inner.Write(h.ipad)
|
h.inner.Write(h.ipad) //nolint: errcheck
|
||||||
}
|
}
|
||||||
|
|
||||||
var hmacSHA1Pool = &sync.Pool{
|
var hmacSHA1Pool = &sync.Pool{
|
||||||
|
@@ -14,7 +14,7 @@ func BenchmarkHMACSHA1_512(b *testing.B) {
|
|||||||
h := AcquireSHA1(key)
|
h := AcquireSHA1(key)
|
||||||
b.SetBytes(int64(len(buf)))
|
b.SetBytes(int64(len(buf)))
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
h.Write(buf)
|
h.Write(buf) //nolint: errcheck
|
||||||
h.Reset()
|
h.Reset()
|
||||||
mac := h.Sum(nil)
|
mac := h.Sum(nil)
|
||||||
buf[0] = mac[0]
|
buf[0] = mac[0]
|
||||||
@@ -29,7 +29,7 @@ func BenchmarkHMACSHA1_512_Pool(b *testing.B) {
|
|||||||
b.SetBytes(int64(len(buf)))
|
b.SetBytes(int64(len(buf)))
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
h := AcquireSHA1(key)
|
h := AcquireSHA1(key)
|
||||||
h.Write(buf)
|
h.Write(buf) //nolint: errcheck
|
||||||
h.Reset()
|
h.Reset()
|
||||||
mac := h.Sum(tBuf)
|
mac := h.Sum(tBuf)
|
||||||
buf[0] = mac[0]
|
buf[0] = mac[0]
|
||||||
|
@@ -263,7 +263,7 @@ func BenchmarkMessage_WriteTo(b *testing.B) {
|
|||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
m.WriteTo(buf)
|
m.WriteTo(buf) //nolint: errcheck
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -499,7 +499,7 @@ func TestMessage_String(t *testing.T) {
|
|||||||
|
|
||||||
func TestIsMessage(t *testing.T) {
|
func TestIsMessage(t *testing.T) {
|
||||||
m := New()
|
m := New()
|
||||||
NewSoftware("software").AddTo(m)
|
NewSoftware("software").AddTo(m) //nolint: errcheck
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
|
|
||||||
var tt = [...]struct {
|
var tt = [...]struct {
|
||||||
@@ -526,7 +526,7 @@ func BenchmarkIsMessage(b *testing.B) {
|
|||||||
m := New()
|
m := New()
|
||||||
m.Type = MessageType{Method: MethodBinding, Class: ClassRequest}
|
m.Type = MessageType{Method: MethodBinding, Class: ClassRequest}
|
||||||
m.TransactionID = NewTransactionID()
|
m.TransactionID = NewTransactionID()
|
||||||
NewSoftware("cydev/stun test").AddTo(m)
|
NewSoftware("cydev/stun test").AddTo(m) //nolint: errcheck
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
|
|
||||||
b.SetBytes(int64(messageHeaderSize))
|
b.SetBytes(int64(messageHeaderSize))
|
||||||
@@ -625,7 +625,7 @@ func BenchmarkMessageFull(b *testing.B) {
|
|||||||
addAttr(b, m, &s)
|
addAttr(b, m, &s)
|
||||||
m.WriteAttributes()
|
m.WriteAttributes()
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
Fingerprint.AddTo(m)
|
Fingerprint.AddTo(m) //nolint: errcheck
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
m.Reset()
|
m.Reset()
|
||||||
}
|
}
|
||||||
@@ -679,7 +679,7 @@ func TestMessage_Contains(t *testing.T) {
|
|||||||
func ExampleMessage() {
|
func ExampleMessage() {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
m := new(Message)
|
m := new(Message)
|
||||||
m.Build(BindingRequest,
|
m.Build(BindingRequest, //nolint: errcheck
|
||||||
NewTransactionIDSetter([TransactionIDSize]byte{
|
NewTransactionIDSetter([TransactionIDSize]byte{
|
||||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
|
1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1,
|
||||||
}),
|
}),
|
||||||
@@ -705,11 +705,11 @@ func ExampleMessage() {
|
|||||||
decoded.Raw = make([]byte, 0, 1024) // for ReadFrom that reuses m.Raw
|
decoded.Raw = make([]byte, 0, 1024) // for ReadFrom that reuses m.Raw
|
||||||
// ReadFrom does not allocate internal buffer for reading from io.Reader,
|
// ReadFrom does not allocate internal buffer for reading from io.Reader,
|
||||||
// instead it uses m.Raw, expanding it length to capacity.
|
// instead it uses m.Raw, expanding it length to capacity.
|
||||||
decoded.ReadFrom(buf)
|
decoded.ReadFrom(buf) //nolint: errcheck
|
||||||
fmt.Println("has software:", decoded.Contains(AttrSoftware))
|
fmt.Println("has software:", decoded.Contains(AttrSoftware))
|
||||||
fmt.Println("has nonce:", decoded.Contains(AttrNonce))
|
fmt.Println("has nonce:", decoded.Contains(AttrNonce))
|
||||||
var software Software
|
var software Software
|
||||||
decoded.Parse(&software) // or software.GetFrom(decoded)
|
decoded.Parse(&software) //nolint: errcheck
|
||||||
// Rule for Parse method is same as for Build.
|
// Rule for Parse method is same as for Build.
|
||||||
fmt.Println("software:", software)
|
fmt.Println("software:", software)
|
||||||
if err := Fingerprint.Check(decoded); err == nil {
|
if err := Fingerprint.Check(decoded); err == nil {
|
||||||
@@ -888,7 +888,7 @@ func BenchmarkMessage_CloneTo(b *testing.B) {
|
|||||||
}
|
}
|
||||||
b.SetBytes(int64(len(m.Raw)))
|
b.SetBytes(int64(len(m.Raw)))
|
||||||
a := new(Message)
|
a := new(Message)
|
||||||
m.CloneTo(a)
|
m.CloneTo(a) //nolint: errcheck
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if err := m.CloneTo(a); err != nil {
|
if err := m.CloneTo(a); err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
@@ -917,7 +917,7 @@ func TestMessage_AddTo(t *testing.T) {
|
|||||||
if b.Equal(m) {
|
if b.Equal(m) {
|
||||||
t.Fatal("should not be equal")
|
t.Fatal("should not be equal")
|
||||||
}
|
}
|
||||||
m.AddTo(b)
|
m.AddTo(b) //nolint: errcheck
|
||||||
if !b.Equal(m) {
|
if !b.Equal(m) {
|
||||||
t.Fatal("should be equal")
|
t.Fatal("should be equal")
|
||||||
}
|
}
|
||||||
@@ -935,7 +935,7 @@ func BenchmarkMessage_AddTo(b *testing.B) {
|
|||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
}
|
}
|
||||||
a := new(Message)
|
a := new(Message)
|
||||||
m.CloneTo(a)
|
m.CloneTo(a) //nolint: errcheck
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
if err := m.AddTo(a); err != nil {
|
if err := m.AddTo(a); err != nil {
|
||||||
b.Fatal(err)
|
b.Fatal(err)
|
||||||
|
@@ -72,7 +72,7 @@ func BenchmarkUsername_AddTo(b *testing.B) {
|
|||||||
func BenchmarkUsername_GetFrom(b *testing.B) {
|
func BenchmarkUsername_GetFrom(b *testing.B) {
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
m := new(Message)
|
m := new(Message)
|
||||||
Username("test").AddTo(m)
|
Username("test").AddTo(m) //nolint: errcheck
|
||||||
var u Username
|
var u Username
|
||||||
b.ResetTimer()
|
b.ResetTimer()
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
@@ -258,8 +258,8 @@ func BenchmarkNonce_GetFrom(b *testing.B) {
|
|||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
m := New()
|
m := New()
|
||||||
n := NewNonce("nonce")
|
n := NewNonce("nonce")
|
||||||
n.AddTo(m)
|
n.AddTo(m) //nolint: errcheck
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
n.GetFrom(m)
|
n.GetFrom(m) //nolint: errcheck
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,7 +18,7 @@ func BenchmarkXORMappedAddress_AddTo(b *testing.B) {
|
|||||||
ip := net.ParseIP("192.168.1.32")
|
ip := net.ParseIP("192.168.1.32")
|
||||||
for i := 0; i < b.N; i++ {
|
for i := 0; i < b.N; i++ {
|
||||||
addr := &XORMappedAddress{IP: ip, Port: 3654}
|
addr := &XORMappedAddress{IP: ip, Port: 3654}
|
||||||
addr.AddTo(m)
|
addr.AddTo(m) //nolint: errcheck
|
||||||
m.Reset()
|
m.Reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ func TestXORMappedAddress_GetFrom_Invalid(t *testing.T) {
|
|||||||
|
|
||||||
addr.IP = expectedIP
|
addr.IP = expectedIP
|
||||||
addr.Port = expectedPort
|
addr.Port = expectedPort
|
||||||
addr.AddTo(m)
|
addr.AddTo(m) //nolint: errcheck
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
|
|
||||||
mRes := New()
|
mRes := New()
|
||||||
@@ -163,7 +163,7 @@ func TestXORMappedAddress_AddTo_IPv6(t *testing.T) {
|
|||||||
IP: net.ParseIP("fe80::dc2b:44ff:fe20:6009"),
|
IP: net.ParseIP("fe80::dc2b:44ff:fe20:6009"),
|
||||||
Port: 21254,
|
Port: 21254,
|
||||||
}
|
}
|
||||||
addr.AddTo(m)
|
addr.AddTo(m) //nolint: errcheck
|
||||||
m.WriteHeader()
|
m.WriteHeader()
|
||||||
|
|
||||||
mRes := New()
|
mRes := New()
|
||||||
|
Reference in New Issue
Block a user