Skip to content

Commit 74d6899

Browse files
pionbotSean-Der
authored andcommitted
Update CI configs to v0.7.2
Update lint scripts and CI configs.
1 parent a456c99 commit 74d6899

17 files changed

+76
-17
lines changed

.github/workflows/lint.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ jobs:
4747
- name: golangci-lint
4848
uses: golangci/golangci-lint-action@v3
4949
with:
50-
version: v1.31
50+
version: v1.45.2
5151
args: $GOLANGCI_LINT_EXRA_ARGS

.golangci.yml

+32-2
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,22 @@ linters-settings:
1515
linters:
1616
enable:
1717
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
18+
- bidichk # Checks for dangerous unicode character sequences
1819
- bodyclose # checks whether HTTP response body is closed successfully
20+
- contextcheck # check the function whether use a non-inherited context
1921
- deadcode # Finds unused code
22+
- decorder # check declaration order and count of types, constants, variables and functions
2023
- depguard # Go linter that checks if package imports are in a list of acceptable packages
2124
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
2225
- dupl # Tool for code clone detection
26+
- durationcheck # check for two durations multiplied together
2327
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
28+
- errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occations, where the check for the returned error can be omitted.
29+
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.
30+
- errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
2431
- exhaustive # check exhaustiveness of enum switch statements
2532
- exportloopref # checks for pointers to enclosing loop variables
33+
- forcetypeassert # finds forced type assertions
2634
- gci # Gci control golang package import order and make it always deterministic.
2735
- gochecknoglobals # Checks that no globals are present in Go code
2836
- gochecknoinits # Checks that no init functions are present in Go code
@@ -35,40 +43,62 @@ linters:
3543
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
3644
- goheader # Checks is file header matches to pattern
3745
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
38-
- golint # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
46+
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
3947
- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations.
4048
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
4149
- gosec # Inspects source code for security problems
4250
- gosimple # Linter for Go source code that specializes in simplifying a code
4351
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
52+
- grouper # An analyzer to analyze expression groups.
53+
- importas # Enforces consistent import aliases
4454
- ineffassign # Detects when assignments to existing variables are not used
4555
- misspell # Finds commonly misspelled English words in comments
4656
- nakedret # Finds naked returns in functions greater than a specified function length
57+
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
58+
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value.
4759
- noctx # noctx finds sending http request without context.Context
48-
- scopelint # Scopelint checks for unpinned variables in go programs
60+
- predeclared # find code that shadows one of Go's predeclared identifiers
61+
- revive # golint replacement, finds style mistakes
4962
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
5063
- structcheck # Finds unused struct fields
5164
- stylecheck # Stylecheck is a replacement for golint
65+
- tagliatelle # Checks the struct tags.
66+
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
67+
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
5268
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
5369
- unconvert # Remove unnecessary type conversions
5470
- unparam # Reports unused function parameters
5571
- unused # Checks Go code for unused constants, variables, functions and types
5672
- varcheck # Finds unused global variables and constants
73+
- wastedassign # wastedassign finds wasted assignment statements
5774
- whitespace # Tool for detection of leading and trailing whitespace
5875
disable:
76+
- containedctx # containedctx is a linter that detects struct contained context.Context field
77+
- cyclop # checks function and package cyclomatic complexity
78+
- exhaustivestruct # Checks if all struct's fields are initialized
79+
- forbidigo # Forbids identifiers
5980
- funlen # Tool for detection of long functions
6081
- gocyclo # Computes and checks the cyclomatic complexity of functions
6182
- godot # Check if comments end in a period
6283
- gomnd # An analyzer to detect magic numbers.
84+
- ifshort # Checks that your code uses short syntax for if-statements whenever possible
85+
- ireturn # Accept Interfaces, Return Concrete Types
6386
- lll # Reports long lines
87+
- maintidx # maintidx measures the maintainability index of each function.
88+
- makezero # Finds slice declarations with non-zero initial length
6489
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted
6590
- nestif # Reports deeply nested if statements
6691
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
6792
- nolintlint # Reports ill-formed or insufficient nolint directives
93+
- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
6894
- prealloc # Finds slice declarations that could potentially be preallocated
95+
- promlinter # Check Prometheus metrics naming via promlint
6996
- rowserrcheck # checks whether Err of rows is checked successfully
7097
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
7198
- testpackage # linter that makes you use a separate _test package
99+
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
100+
- varnamelen # checks that the length of a variable's name matches its scope
101+
- wrapcheck # Checks that errors returned from external packages are wrapped
72102
- wsl # Whitespace Linter - Forces you to use empty lines!
73103

74104
issues:

client.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ func (c *Client) CreatePermission(addrs ...net.Addr) error {
341341

342342
// PerformTransaction performs STUN transaction
343343
func (c *Client) PerformTransaction(msg *stun.Message, to net.Addr, ignoreResult bool) (client.TransactionResult,
344-
error) {
344+
error,
345+
) {
345346
trKey := b64.StdEncoding.EncodeToString(msg.TransactionID[:])
346347

347348
raw := make([]byte, len(msg.Raw))

client_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package turn

internal/allocation/allocation.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ func (a *Allocation) SetResponseCache(transactionID [stun.TransactionIDSize]byte
186186

187187
// GetResponseCache return response cache for retransmit allocation request
188188
func (a *Allocation) GetResponseCache() (id [stun.TransactionIDSize]byte, attrs []stun.Setter) {
189-
if r := a.responseCache.Load(); r != nil {
190-
res := r.(*allocationResponse)
189+
if res, ok := a.responseCache.Load().(*allocationResponse); ok && res != nil {
191190
id, attrs = res.transactionID, res.responseAttrs
192191
}
193192
return
@@ -267,13 +266,19 @@ func (a *Allocation) packetHandler(m *Manager) {
267266
a.log.Errorf("Failed to send ChannelData from allocation %v %v", srcAddr, err)
268267
}
269268
} else if p := a.GetPermission(srcAddr); p != nil {
270-
udpAddr := srcAddr.(*net.UDPAddr)
269+
udpAddr, ok := srcAddr.(*net.UDPAddr)
270+
if !ok {
271+
a.log.Errorf("Failed to send DataIndication from allocation %v %v", srcAddr, err)
272+
return
273+
}
274+
271275
peerAddressAttr := proto.PeerAddress{IP: udpAddr.IP, Port: udpAddr.Port}
272276
dataAttr := proto.Data(buffer[:n])
273277

274278
msg, err := stun.Build(stun.TransactionID, stun.NewType(stun.MethodData, stun.ClassIndication), peerAddressAttr, dataAttr)
275279
if err != nil {
276280
a.log.Errorf("Failed to send DataIndication from allocation %v %v", srcAddr, err)
281+
return
277282
}
278283
a.log.Debugf("relaying message from %s to client at %s",
279284
srcAddr.String(),

internal/allocation/allocation_manager_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package allocation

internal/allocation/allocation_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package allocation

internal/client/conn_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ func TestUDPConn(t *testing.T) {
5353
t.Run("bind()", func(t *testing.T) {
5454
obs := &dummyUDPConnObserver{
5555
_performTransaction: func(msg *stun.Message, to net.Addr, dontWait bool) (TransactionResult, error) {
56-
return TransactionResult{}, errFakeErr
56+
return TransactionResult{}, errFake
5757
},
5858
}
5959

internal/client/errors.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
)
66

77
var (
8-
errFakeErr = errors.New("fake error")
8+
errFake = errors.New("fake error")
99
errTryAgain = errors.New("try again")
1010
errClosed = errors.New("use of closed network connection")
1111
errUDPAddrCast = errors.New("addr is not a net.UDPAddr")

internal/server/turn.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func handleAllocateRequest(r Request, m *stun.Message) error {
9797
// error.
9898
var evenPort proto.EvenPort
9999
if err = evenPort.GetFrom(m); err == nil {
100-
randomPort := 0
100+
var randomPort int
101101
randomPort, err = r.AllocationManager.GetRandomEvenPort()
102102
if err != nil {
103103
return buildAndSendErr(r.Conn, r.SrcAddr, err, insufficentCapacityMsg...)

internal/server/turn_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package server

internal/server/util.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,13 @@ func authenticateRequest(r Request, m *stun.Message, callingMethod stun.Method)
9595
}
9696

9797
// Assert Nonce exists and is not expired
98-
nonceCreationTime, ok := r.Nonces.Load(string(*nonceAttr))
99-
if !ok || time.Since(nonceCreationTime.(time.Time)) >= nonceLifetime {
98+
nonceCreationTime, nonceFound := r.Nonces.Load(string(*nonceAttr))
99+
if !nonceFound {
100+
r.Nonces.Delete(nonceAttr)
101+
return respondWithNonce(stun.CodeStaleNonce)
102+
}
103+
104+
if timeValue, ok := nonceCreationTime.(time.Time); !ok || time.Since(timeValue) >= nonceLifetime {
100105
r.Nonces.Delete(nonceAttr)
101106
return respondWithNonce(stun.CodeStaleNonce)
102107
}

lt_cred_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build !js
12
// +build !js
23

34
package turn

relay_address_generator_range.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ func (r *RelayAddressGeneratorPortRange) AllocatePacketConn(network string, requ
6666
if err != nil {
6767
return nil, nil, err
6868
}
69-
relayAddr := conn.LocalAddr().(*net.UDPAddr)
69+
relayAddr, ok := conn.LocalAddr().(*net.UDPAddr)
70+
if !ok {
71+
return nil, nil, errNilConn
72+
}
73+
7074
relayAddr.IP = r.RelayAddress
7175
return conn, relayAddr, nil
7276
}
@@ -78,7 +82,11 @@ func (r *RelayAddressGeneratorPortRange) AllocatePacketConn(network string, requ
7882
continue
7983
}
8084

81-
relayAddr := conn.LocalAddr().(*net.UDPAddr)
85+
relayAddr, ok := conn.LocalAddr().(*net.UDPAddr)
86+
if !ok {
87+
return nil, nil, errNilConn
88+
}
89+
8290
relayAddr.IP = r.RelayAddress
8391
return conn, relayAddr, nil
8492
}

relay_address_generator_static.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ func (r *RelayAddressGeneratorStatic) AllocatePacketConn(network string, request
4343
}
4444

4545
// Replace actual listening IP with the user requested one of RelayAddressGeneratorStatic
46-
relayAddr := conn.LocalAddr().(*net.UDPAddr)
46+
relayAddr, ok := conn.LocalAddr().(*net.UDPAddr)
47+
if !ok {
48+
return nil, nil, errNilConn
49+
}
50+
4751
relayAddr.IP = r.RelayAddress
4852

4953
return conn, relayAddr, nil

server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (s *Server) Close() error {
152152

153153
err := errFailedToClose
154154
for _, e := range errors {
155-
err = fmt.Errorf("%s; Close error (%v) ", err.Error(), e) //nolint:goerr113
155+
err = fmt.Errorf("%s; Close error (%w) ", err.Error(), e)
156156
}
157157

158158
return err

server_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,8 @@ func TestServerVNet(t *testing.T) {
281281
reflAddr, err := client.SendBindingRequest()
282282
assert.NoError(t, err)
283283
log.Debugf("mapped-address: %v", reflAddr.String())
284-
udpAddr := reflAddr.(*net.UDPAddr)
284+
udpAddr, ok := reflAddr.(*net.UDPAddr)
285+
assert.True(t, ok)
285286

286287
// The mapped-address should have IP address that was assigned
287288
// to the LAN router.

0 commit comments

Comments
 (0)