mirror of
https://github.com/pion/ice.git
synced 2025-10-24 16:00:39 +08:00
Update CI configs to v0.7.2
Update lint scripts and CI configs.
This commit is contained in:
2
.github/workflows/lint.yaml
vendored
2
.github/workflows/lint.yaml
vendored
@@ -47,5 +47,5 @@ jobs:
|
|||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v3
|
uses: golangci/golangci-lint-action@v3
|
||||||
with:
|
with:
|
||||||
version: v1.31
|
version: v1.45.2
|
||||||
args: $GOLANGCI_LINT_EXRA_ARGS
|
args: $GOLANGCI_LINT_EXRA_ARGS
|
||||||
|
|||||||
@@ -15,14 +15,22 @@ linters-settings:
|
|||||||
linters:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
|
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
|
||||||
|
- bidichk # Checks for dangerous unicode character sequences
|
||||||
- bodyclose # checks whether HTTP response body is closed successfully
|
- bodyclose # checks whether HTTP response body is closed successfully
|
||||||
|
- contextcheck # check the function whether use a non-inherited context
|
||||||
- deadcode # Finds unused code
|
- deadcode # Finds unused code
|
||||||
|
- decorder # check declaration order and count of types, constants, variables and functions
|
||||||
- depguard # Go linter that checks if package imports are in a list of acceptable packages
|
- depguard # Go linter that checks if package imports are in a list of acceptable packages
|
||||||
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
|
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
|
||||||
- dupl # Tool for code clone detection
|
- dupl # Tool for code clone detection
|
||||||
|
- durationcheck # check for two durations multiplied together
|
||||||
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
|
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
|
||||||
|
- 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.
|
||||||
|
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.
|
||||||
|
- 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.
|
||||||
- exhaustive # check exhaustiveness of enum switch statements
|
- exhaustive # check exhaustiveness of enum switch statements
|
||||||
- exportloopref # checks for pointers to enclosing loop variables
|
- exportloopref # checks for pointers to enclosing loop variables
|
||||||
|
- forcetypeassert # finds forced type assertions
|
||||||
- gci # Gci control golang package import order and make it always deterministic.
|
- gci # Gci control golang package import order and make it always deterministic.
|
||||||
- gochecknoglobals # Checks that no globals are present in Go code
|
- gochecknoglobals # Checks that no globals are present in Go code
|
||||||
- gochecknoinits # Checks that no init functions are present in Go code
|
- gochecknoinits # Checks that no init functions are present in Go code
|
||||||
@@ -35,40 +43,62 @@ linters:
|
|||||||
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
|
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
|
||||||
- goheader # Checks is file header matches to pattern
|
- goheader # Checks is file header matches to pattern
|
||||||
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
|
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
|
||||||
- golint # Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes
|
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
|
||||||
- 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.
|
- 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.
|
||||||
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
|
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
|
||||||
- gosec # Inspects source code for security problems
|
- gosec # Inspects source code for security problems
|
||||||
- gosimple # Linter for Go source code that specializes in simplifying a code
|
- gosimple # Linter for Go source code that specializes in simplifying a code
|
||||||
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
|
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
|
||||||
|
- grouper # An analyzer to analyze expression groups.
|
||||||
|
- importas # Enforces consistent import aliases
|
||||||
- ineffassign # Detects when assignments to existing variables are not used
|
- ineffassign # Detects when assignments to existing variables are not used
|
||||||
- misspell # Finds commonly misspelled English words in comments
|
- misspell # Finds commonly misspelled English words in comments
|
||||||
- nakedret # Finds naked returns in functions greater than a specified function length
|
- nakedret # Finds naked returns in functions greater than a specified function length
|
||||||
|
- nilerr # Finds the code that returns nil even if it checks that the error is not nil.
|
||||||
|
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value.
|
||||||
- noctx # noctx finds sending http request without context.Context
|
- noctx # noctx finds sending http request without context.Context
|
||||||
- scopelint # Scopelint checks for unpinned variables in go programs
|
- predeclared # find code that shadows one of Go's predeclared identifiers
|
||||||
|
- revive # golint replacement, finds style mistakes
|
||||||
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
|
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
|
||||||
- structcheck # Finds unused struct fields
|
- structcheck # Finds unused struct fields
|
||||||
- stylecheck # Stylecheck is a replacement for golint
|
- stylecheck # Stylecheck is a replacement for golint
|
||||||
|
- tagliatelle # Checks the struct tags.
|
||||||
|
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
|
||||||
|
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
|
||||||
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
|
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
|
||||||
- unconvert # Remove unnecessary type conversions
|
- unconvert # Remove unnecessary type conversions
|
||||||
- unparam # Reports unused function parameters
|
- unparam # Reports unused function parameters
|
||||||
- unused # Checks Go code for unused constants, variables, functions and types
|
- unused # Checks Go code for unused constants, variables, functions and types
|
||||||
- varcheck # Finds unused global variables and constants
|
- varcheck # Finds unused global variables and constants
|
||||||
|
- wastedassign # wastedassign finds wasted assignment statements
|
||||||
- whitespace # Tool for detection of leading and trailing whitespace
|
- whitespace # Tool for detection of leading and trailing whitespace
|
||||||
disable:
|
disable:
|
||||||
|
- containedctx # containedctx is a linter that detects struct contained context.Context field
|
||||||
|
- cyclop # checks function and package cyclomatic complexity
|
||||||
|
- exhaustivestruct # Checks if all struct's fields are initialized
|
||||||
|
- forbidigo # Forbids identifiers
|
||||||
- funlen # Tool for detection of long functions
|
- funlen # Tool for detection of long functions
|
||||||
- gocyclo # Computes and checks the cyclomatic complexity of functions
|
- gocyclo # Computes and checks the cyclomatic complexity of functions
|
||||||
- godot # Check if comments end in a period
|
- godot # Check if comments end in a period
|
||||||
- gomnd # An analyzer to detect magic numbers.
|
- gomnd # An analyzer to detect magic numbers.
|
||||||
|
- ifshort # Checks that your code uses short syntax for if-statements whenever possible
|
||||||
|
- ireturn # Accept Interfaces, Return Concrete Types
|
||||||
- lll # Reports long lines
|
- lll # Reports long lines
|
||||||
|
- maintidx # maintidx measures the maintainability index of each function.
|
||||||
|
- makezero # Finds slice declarations with non-zero initial length
|
||||||
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted
|
- maligned # Tool to detect Go structs that would take less memory if their fields were sorted
|
||||||
- nestif # Reports deeply nested if statements
|
- nestif # Reports deeply nested if statements
|
||||||
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
|
- nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity
|
||||||
- nolintlint # Reports ill-formed or insufficient nolint directives
|
- nolintlint # Reports ill-formed or insufficient nolint directives
|
||||||
|
- paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test
|
||||||
- prealloc # Finds slice declarations that could potentially be preallocated
|
- prealloc # Finds slice declarations that could potentially be preallocated
|
||||||
|
- promlinter # Check Prometheus metrics naming via promlint
|
||||||
- rowserrcheck # checks whether Err of rows is checked successfully
|
- rowserrcheck # checks whether Err of rows is checked successfully
|
||||||
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
|
- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed.
|
||||||
- testpackage # linter that makes you use a separate _test package
|
- testpackage # linter that makes you use a separate _test package
|
||||||
|
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers
|
||||||
|
- varnamelen # checks that the length of a variable's name matches its scope
|
||||||
|
- wrapcheck # Checks that errors returned from external packages are wrapped
|
||||||
- wsl # Whitespace Linter - Forces you to use empty lines!
|
- wsl # Whitespace Linter - Forces you to use empty lines!
|
||||||
|
|
||||||
issues:
|
issues:
|
||||||
|
|||||||
13
agent.go
13
agent.go
@@ -450,7 +450,7 @@ func (a *Agent) startConnectivityChecks(isControlling bool, remoteUfrag, remoteP
|
|||||||
return ErrMultipleStart
|
return ErrMultipleStart
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
if err := a.SetRemoteCredentials(remoteUfrag, remotePwd); err != nil {
|
if err := a.SetRemoteCredentials(remoteUfrag, remotePwd); err != nil { //nolint:contextcheck
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -477,7 +477,7 @@ func (a *Agent) startConnectivityChecks(isControlling bool, remoteUfrag, remoteP
|
|||||||
agent.updateConnectionState(ConnectionStateChecking)
|
agent.updateConnectionState(ConnectionStateChecking)
|
||||||
|
|
||||||
a.requestConnectivityCheck()
|
a.requestConnectivityCheck()
|
||||||
go a.connectivityChecks()
|
go a.connectivityChecks() //nolint:contextcheck
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1143,7 +1143,7 @@ func (a *Agent) validateNonSTUNTraffic(local Candidate, remote net.Addr) bool {
|
|||||||
func (a *Agent) GetSelectedCandidatePair() (*CandidatePair, error) {
|
func (a *Agent) GetSelectedCandidatePair() (*CandidatePair, error) {
|
||||||
selectedPair := a.getSelectedPair()
|
selectedPair := a.getSelectedPair()
|
||||||
if selectedPair == nil {
|
if selectedPair == nil {
|
||||||
return nil, nil
|
return nil, nil //nolint:nilnil
|
||||||
}
|
}
|
||||||
|
|
||||||
local, err := selectedPair.Local.copy()
|
local, err := selectedPair.Local.copy()
|
||||||
@@ -1160,12 +1160,11 @@ func (a *Agent) GetSelectedCandidatePair() (*CandidatePair, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) getSelectedPair() *CandidatePair {
|
func (a *Agent) getSelectedPair() *CandidatePair {
|
||||||
selectedPair := a.selectedPair.Load()
|
if selectedPair, ok := a.selectedPair.Load().(*CandidatePair); ok {
|
||||||
if selectedPair == nil {
|
return selectedPair
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return selectedPair.(*CandidatePair)
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) closeMulticastConn() {
|
func (a *Agent) closeMulticastConn() {
|
||||||
|
|||||||
@@ -60,7 +60,9 @@ func (a *Agent) GetLocalCandidatesStats() []CandidateStats {
|
|||||||
for _, c := range localCandidates {
|
for _, c := range localCandidates {
|
||||||
relayProtocol := ""
|
relayProtocol := ""
|
||||||
if c.Type() == CandidateTypeRelay {
|
if c.Type() == CandidateTypeRelay {
|
||||||
relayProtocol = c.(*CandidateRelay).RelayProtocol()
|
if cRelay, ok := c.(*CandidateRelay); ok {
|
||||||
|
relayProtocol = cRelay.RelayProtocol()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
stat := CandidateStats{
|
stat := CandidateStats{
|
||||||
Timestamp: time.Now(),
|
Timestamp: time.Now(),
|
||||||
|
|||||||
@@ -433,14 +433,14 @@ func TestConnectivityOnStartup(t *testing.T) {
|
|||||||
|
|
||||||
origHdlr := aAgent.onConnectionStateChangeHdlr.Load()
|
origHdlr := aAgent.onConnectionStateChangeHdlr.Load()
|
||||||
if origHdlr != nil {
|
if origHdlr != nil {
|
||||||
defer check(aAgent.OnConnectionStateChange(origHdlr.(func(ConnectionState))))
|
defer check(aAgent.OnConnectionStateChange(origHdlr.(func(ConnectionState)))) //nolint:forcetypeassert
|
||||||
}
|
}
|
||||||
check(aAgent.OnConnectionStateChange(func(s ConnectionState) {
|
check(aAgent.OnConnectionStateChange(func(s ConnectionState) {
|
||||||
if s == ConnectionStateChecking {
|
if s == ConnectionStateChecking {
|
||||||
close(accepting)
|
close(accepting)
|
||||||
}
|
}
|
||||||
if origHdlr != nil {
|
if origHdlr != nil {
|
||||||
origHdlr.(func(ConnectionState))(s)
|
origHdlr.(func(ConnectionState))(s) //nolint:forcetypeassert
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|
||||||
@@ -1862,7 +1862,7 @@ func TestAcceptAggressiveNomination(t *testing.T) {
|
|||||||
for _, candidates := range aAgent.remoteCandidates {
|
for _, candidates := range aAgent.remoteCandidates {
|
||||||
for _, candidate := range candidates {
|
for _, candidate := range candidates {
|
||||||
if candidate.Equal(c) {
|
if candidate.Equal(c) {
|
||||||
candidate.(*CandidateHost).priorityOverride += 1000
|
candidate.(*CandidateHost).priorityOverride += 1000 //nolint:forcetypeassert
|
||||||
break incr_priority
|
break incr_priority
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -249,7 +249,7 @@ func handleInboundCandidateMsg(ctx context.Context, c Candidate, buffer []byte,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.agent().validateNonSTUNTraffic(c, srcAddr) {
|
if !c.agent().validateNonSTUNTraffic(c, srcAddr) { //nolint:contextcheck
|
||||||
log.Warnf("Discarded message from %s, not a valid remote candidate", c.addr())
|
log.Warnf("Discarded message from %s, not a valid remote candidate", c.addr())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -342,11 +342,10 @@ func (c *candidateBase) String() string {
|
|||||||
// LastReceived returns a time.Time indicating the last time
|
// LastReceived returns a time.Time indicating the last time
|
||||||
// this candidate was received
|
// this candidate was received
|
||||||
func (c *candidateBase) LastReceived() time.Time {
|
func (c *candidateBase) LastReceived() time.Time {
|
||||||
lastReceived := c.lastReceived.Load()
|
if lastReceived, ok := c.lastReceived.Load().(time.Time); ok {
|
||||||
if lastReceived == nil {
|
return lastReceived
|
||||||
return time.Time{}
|
|
||||||
}
|
}
|
||||||
return lastReceived.(time.Time)
|
return time.Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *candidateBase) setLastReceived(t time.Time) {
|
func (c *candidateBase) setLastReceived(t time.Time) {
|
||||||
@@ -356,11 +355,10 @@ func (c *candidateBase) setLastReceived(t time.Time) {
|
|||||||
// LastSent returns a time.Time indicating the last time
|
// LastSent returns a time.Time indicating the last time
|
||||||
// this candidate was sent
|
// this candidate was sent
|
||||||
func (c *candidateBase) LastSent() time.Time {
|
func (c *candidateBase) LastSent() time.Time {
|
||||||
lastSent := c.lastSent.Load()
|
if lastSent, ok := c.lastSent.Load().(time.Time); ok {
|
||||||
if lastSent == nil {
|
return lastSent
|
||||||
return time.Time{}
|
|
||||||
}
|
}
|
||||||
return lastSent.(time.Time)
|
return time.Time{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *candidateBase) setLastSent(t time.Time) {
|
func (c *candidateBase) setLastSent(t time.Time) {
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ type externalIPMapper struct {
|
|||||||
|
|
||||||
func newExternalIPMapper(candidateType CandidateType, ips []string) (*externalIPMapper, error) { //nolint:gocognit
|
func newExternalIPMapper(candidateType CandidateType, ips []string) (*externalIPMapper, error) { //nolint:gocognit
|
||||||
if len(ips) == 0 {
|
if len(ips) == 0 {
|
||||||
return nil, nil
|
return nil, nil //nolint:nilnil
|
||||||
}
|
}
|
||||||
if candidateType == CandidateTypeUnspecified {
|
if candidateType == CandidateTypeUnspecified {
|
||||||
candidateType = CandidateTypeHost // defaults to host
|
candidateType = CandidateTypeHost // defaults to host
|
||||||
|
|||||||
80
gather.go
80
gather.go
@@ -82,7 +82,7 @@ func (a *Agent) GatherCandidates() error {
|
|||||||
|
|
||||||
func (a *Agent) gatherCandidates(ctx context.Context) {
|
func (a *Agent) gatherCandidates(ctx context.Context) {
|
||||||
defer close(a.gatherCandidateDone)
|
defer close(a.gatherCandidateDone)
|
||||||
if err := a.setGatheringState(GatheringStateGathering); err != nil {
|
if err := a.setGatheringState(GatheringStateGathering); err != nil { //nolint:contextcheck
|
||||||
a.log.Warnf("failed to set gatheringState to GatheringStateGathering: %v", err)
|
a.log.Warnf("failed to set gatheringState to GatheringStateGathering: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -126,7 +126,7 @@ func (a *Agent) gatherCandidates(ctx context.Context) {
|
|||||||
// Block until all STUN and TURN URLs have been gathered (or timed out)
|
// Block until all STUN and TURN URLs have been gathered (or timed out)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
if err := a.setGatheringState(GatheringStateComplete); err != nil {
|
if err := a.setGatheringState(GatheringStateComplete); err != nil { //nolint:contextcheck
|
||||||
a.log.Warnf("failed to set gatheringState to GatheringStateComplete: %v", err)
|
a.log.Warnf("failed to set gatheringState to GatheringStateComplete: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -171,10 +171,12 @@ func (a *Agent) gatherCandidatesLocal(ctx context.Context, networkTypes []Networ
|
|||||||
}
|
}
|
||||||
|
|
||||||
for network := range networks {
|
for network := range networks {
|
||||||
var port int
|
var (
|
||||||
var conn net.PacketConn
|
port int
|
||||||
var err error
|
conn net.PacketConn
|
||||||
var tcpType TCPType
|
err error
|
||||||
|
tcpType TCPType
|
||||||
|
)
|
||||||
|
|
||||||
switch network {
|
switch network {
|
||||||
case tcp:
|
case tcp:
|
||||||
@@ -187,7 +189,13 @@ func (a *Agent) gatherCandidatesLocal(ctx context.Context, networkTypes []Networ
|
|||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
port = conn.LocalAddr().(*net.TCPAddr).Port
|
|
||||||
|
if tcpConn, ok := conn.LocalAddr().(*net.TCPAddr); ok {
|
||||||
|
port = tcpConn.Port
|
||||||
|
} else {
|
||||||
|
a.log.Warnf("failed to get port of conn from TCPMux: %s %s %s\n", network, ip, a.localUfrag)
|
||||||
|
continue
|
||||||
|
}
|
||||||
tcpType = TCPTypePassive
|
tcpType = TCPTypePassive
|
||||||
// is there a way to verify that the listen address is even
|
// is there a way to verify that the listen address is even
|
||||||
// accessible from the current interface.
|
// accessible from the current interface.
|
||||||
@@ -198,7 +206,12 @@ func (a *Agent) gatherCandidatesLocal(ctx context.Context, networkTypes []Networ
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
port = conn.LocalAddr().(*net.UDPAddr).Port
|
if udpConn, ok := conn.LocalAddr().(*net.UDPAddr); ok {
|
||||||
|
port = udpConn.Port
|
||||||
|
} else {
|
||||||
|
a.log.Warnf("failed to get port of UDPAddr from ListenUDPInPortRange: %s %s %s\n", network, ip, a.localUfrag)
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
hostConfig := CandidateHostConfig{
|
hostConfig := CandidateHostConfig{
|
||||||
Network: network,
|
Network: network,
|
||||||
@@ -258,18 +271,23 @@ func (a *Agent) gatherCandidatesLocalUDPMux(ctx context.Context) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
port := conn.LocalAddr().(*net.UDPAddr).Port
|
|
||||||
|
udpAddr, ok := conn.LocalAddr().(*net.UDPAddr)
|
||||||
|
if !ok {
|
||||||
|
closeConnAndLog(conn, a.log, fmt.Sprintf("Failed to create host mux candidate: %s failed to cast\n", candidateIP))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
hostConfig := CandidateHostConfig{
|
hostConfig := CandidateHostConfig{
|
||||||
Network: udp,
|
Network: udp,
|
||||||
Address: candidateIP.String(),
|
Address: candidateIP.String(),
|
||||||
Port: port,
|
Port: udpAddr.Port,
|
||||||
Component: ComponentRTP,
|
Component: ComponentRTP,
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := NewCandidateHost(&hostConfig)
|
c, err := NewCandidateHost(&hostConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
closeConnAndLog(conn, a.log, fmt.Sprintf("Failed to create host mux candidate: %s %d: %v\n", candidateIP, port, err))
|
closeConnAndLog(conn, a.log, fmt.Sprintf("Failed to create host mux candidate: %s %d: %v\n", candidateIP, udpAddr.Port, err))
|
||||||
// already logged error
|
// already logged error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -305,7 +323,12 @@ func (a *Agent) gatherCandidatesSrflxMapped(ctx context.Context, networkTypes []
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
laddr := conn.LocalAddr().(*net.UDPAddr)
|
laddr, ok := conn.LocalAddr().(*net.UDPAddr)
|
||||||
|
if !ok {
|
||||||
|
closeConnAndLog(conn, a.log, "1:1 NAT mapping is enabled but LocalAddr is not a UDPAddr\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
mappedIP, err := a.extIPMapper.findExternalIP(laddr.IP.String())
|
mappedIP, err := a.extIPMapper.findExternalIP(laddr.IP.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
closeConnAndLog(conn, a.log, fmt.Sprintf("1:1 NAT mapping is enabled but no external IP is found for %s\n", laddr.IP.String()))
|
closeConnAndLog(conn, a.log, fmt.Sprintf("1:1 NAT mapping is enabled but no external IP is found for %s\n", laddr.IP.String()))
|
||||||
@@ -340,7 +363,7 @@ func (a *Agent) gatherCandidatesSrflxMapped(ctx context.Context, networkTypes []
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *Agent) gatherCandidatesSrflxUDPMux(ctx context.Context, urls []*URL, networkTypes []NetworkType) {
|
func (a *Agent) gatherCandidatesSrflxUDPMux(ctx context.Context, urls []*URL, networkTypes []NetworkType) { //nolint:gocognit
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
defer wg.Wait()
|
defer wg.Wait()
|
||||||
|
|
||||||
@@ -376,7 +399,12 @@ func (a *Agent) gatherCandidatesSrflxUDPMux(ctx context.Context, urls []*URL, ne
|
|||||||
ip := xoraddr.IP
|
ip := xoraddr.IP
|
||||||
port := xoraddr.Port
|
port := xoraddr.Port
|
||||||
|
|
||||||
laddr := conn.LocalAddr().(*net.UDPAddr)
|
laddr, ok := conn.LocalAddr().(*net.UDPAddr)
|
||||||
|
if !ok {
|
||||||
|
closeConnAndLog(conn, a.log, fmt.Sprintf("Failed to create server reflexive candidate: %s %s %d: cast failed\n", network, ip, port))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
srflxConfig := CandidateServerReflexiveConfig{
|
srflxConfig := CandidateServerReflexiveConfig{
|
||||||
Network: network,
|
Network: network,
|
||||||
Address: ip.String(),
|
Address: ip.String(),
|
||||||
@@ -450,7 +478,7 @@ func (a *Agent) gatherCandidatesSrflx(ctx context.Context, urls []*URL, networkT
|
|||||||
ip := xoraddr.IP
|
ip := xoraddr.IP
|
||||||
port := xoraddr.Port
|
port := xoraddr.Port
|
||||||
|
|
||||||
laddr := conn.LocalAddr().(*net.UDPAddr)
|
laddr := conn.LocalAddr().(*net.UDPAddr) //nolint:forcetypeassert
|
||||||
srflxConfig := CandidateServerReflexiveConfig{
|
srflxConfig := CandidateServerReflexiveConfig{
|
||||||
Network: network,
|
Network: network,
|
||||||
Address: ip.String(),
|
Address: ip.String(),
|
||||||
@@ -512,8 +540,8 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
RelAddr = locConn.LocalAddr().(*net.UDPAddr).IP.String()
|
RelAddr = locConn.LocalAddr().(*net.UDPAddr).IP.String() //nolint:forcetypeassert
|
||||||
RelPort = locConn.LocalAddr().(*net.UDPAddr).Port
|
RelPort = locConn.LocalAddr().(*net.UDPAddr).Port //nolint:forcetypeassert
|
||||||
relayProtocol = udp
|
relayProtocol = udp
|
||||||
case a.proxyDialer != nil && url.Proto == ProtoTypeTCP &&
|
case a.proxyDialer != nil && url.Proto == ProtoTypeTCP &&
|
||||||
(url.Scheme == SchemeTypeTURN || url.Scheme == SchemeTypeTURNS):
|
(url.Scheme == SchemeTypeTURN || url.Scheme == SchemeTypeTURNS):
|
||||||
@@ -523,8 +551,8 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
RelAddr = conn.LocalAddr().(*net.TCPAddr).IP.String()
|
RelAddr = conn.LocalAddr().(*net.TCPAddr).IP.String() //nolint:forcetypeassert
|
||||||
RelPort = conn.LocalAddr().(*net.TCPAddr).Port
|
RelPort = conn.LocalAddr().(*net.TCPAddr).Port //nolint:forcetypeassert
|
||||||
if url.Scheme == SchemeTypeTURN {
|
if url.Scheme == SchemeTypeTURN {
|
||||||
relayProtocol = tcp
|
relayProtocol = tcp
|
||||||
} else if url.Scheme == SchemeTypeTURNS {
|
} else if url.Scheme == SchemeTypeTURNS {
|
||||||
@@ -545,8 +573,8 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
RelAddr = conn.LocalAddr().(*net.TCPAddr).IP.String()
|
RelAddr = conn.LocalAddr().(*net.TCPAddr).IP.String() //nolint:forcetypeassert
|
||||||
RelPort = conn.LocalAddr().(*net.TCPAddr).Port
|
RelPort = conn.LocalAddr().(*net.TCPAddr).Port //nolint:forcetypeassert
|
||||||
relayProtocol = tcp
|
relayProtocol = tcp
|
||||||
locConn = turn.NewSTUNConn(conn)
|
locConn = turn.NewSTUNConn(conn)
|
||||||
case url.Proto == ProtoTypeUDP && url.Scheme == SchemeTypeTURNS:
|
case url.Proto == ProtoTypeUDP && url.Scheme == SchemeTypeTURNS:
|
||||||
@@ -565,8 +593,8 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
RelAddr = conn.LocalAddr().(*net.UDPAddr).IP.String()
|
RelAddr = conn.LocalAddr().(*net.UDPAddr).IP.String() //nolint:forcetypeassert
|
||||||
RelPort = conn.LocalAddr().(*net.UDPAddr).Port
|
RelPort = conn.LocalAddr().(*net.UDPAddr).Port //nolint:forcetypeassert
|
||||||
relayProtocol = "dtls"
|
relayProtocol = "dtls"
|
||||||
locConn = &fakePacketConn{conn}
|
locConn = &fakePacketConn{conn}
|
||||||
case url.Proto == ProtoTypeTCP && url.Scheme == SchemeTypeTURNS:
|
case url.Proto == ProtoTypeTCP && url.Scheme == SchemeTypeTURNS:
|
||||||
@@ -577,8 +605,8 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
|
|||||||
a.log.Warnf("Failed to Dial TLS Addr %s: %v\n", TURNServerAddr, connectErr)
|
a.log.Warnf("Failed to Dial TLS Addr %s: %v\n", TURNServerAddr, connectErr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
RelAddr = conn.LocalAddr().(*net.TCPAddr).IP.String()
|
RelAddr = conn.LocalAddr().(*net.TCPAddr).IP.String() //nolint:forcetypeassert
|
||||||
RelPort = conn.LocalAddr().(*net.TCPAddr).Port
|
RelPort = conn.LocalAddr().(*net.TCPAddr).Port //nolint:forcetypeassert
|
||||||
relayProtocol = "tls"
|
relayProtocol = "tls"
|
||||||
locConn = turn.NewSTUNConn(conn)
|
locConn = turn.NewSTUNConn(conn)
|
||||||
default:
|
default:
|
||||||
@@ -612,7 +640,7 @@ func (a *Agent) gatherCandidatesRelay(ctx context.Context, urls []*URL) { //noli
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
raddr := relayConn.LocalAddr().(*net.UDPAddr)
|
raddr := relayConn.LocalAddr().(*net.UDPAddr) //nolint:forcetypeassert
|
||||||
relayConfig := CandidateRelayConfig{
|
relayConfig := CandidateRelayConfig{
|
||||||
Network: network,
|
Network: network,
|
||||||
Component: ComponentRTP,
|
Component: ComponentRTP,
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ func TestVNetGatherWithNAT1To1(t *testing.T) {
|
|||||||
|
|
||||||
laddr := [2]*net.UDPAddr{nil, nil}
|
laddr := [2]*net.UDPAddr{nil, nil}
|
||||||
for i, candi := range candidates {
|
for i, candi := range candidates {
|
||||||
laddr[i] = candi.(*CandidateHost).conn.LocalAddr().(*net.UDPAddr)
|
laddr[i] = candi.(*CandidateHost).conn.LocalAddr().(*net.UDPAddr) //nolint:forcetypeassert
|
||||||
if candi.Port() != laddr[i].Port {
|
if candi.Port() != laddr[i].Port {
|
||||||
t.Fatalf("Unexpected candidate port: %d", candi.Port())
|
t.Fatalf("Unexpected candidate port: %d", candi.Port())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func (a *Agent) connect(ctx context.Context, isControlling bool, remoteUfrag, re
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = a.startConnectivityChecks(isControlling, remoteUfrag, remotePwd)
|
err = a.startConnectivityChecks(isControlling, remoteUfrag, remotePwd) //nolint:contextcheck
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,16 +75,16 @@ func TestRemoteLocalAddr(t *testing.T) {
|
|||||||
|
|
||||||
// Assert addresses
|
// Assert addresses
|
||||||
assert.Equal(t, aLAddr.String(),
|
assert.Equal(t, aLAddr.String(),
|
||||||
fmt.Sprintf("%s:%d", vnetLocalIPA, bRAddr.(*net.UDPAddr).Port),
|
fmt.Sprintf("%s:%d", vnetLocalIPA, bRAddr.(*net.UDPAddr).Port), //nolint:forcetypeassert
|
||||||
)
|
)
|
||||||
assert.Equal(t, bLAddr.String(),
|
assert.Equal(t, bLAddr.String(),
|
||||||
fmt.Sprintf("%s:%d", vnetLocalIPB, aRAddr.(*net.UDPAddr).Port),
|
fmt.Sprintf("%s:%d", vnetLocalIPB, aRAddr.(*net.UDPAddr).Port), //nolint:forcetypeassert
|
||||||
)
|
)
|
||||||
assert.Equal(t, aRAddr.String(),
|
assert.Equal(t, aRAddr.String(),
|
||||||
fmt.Sprintf("%s:%d", vnetGlobalIPB, bLAddr.(*net.UDPAddr).Port),
|
fmt.Sprintf("%s:%d", vnetGlobalIPB, bLAddr.(*net.UDPAddr).Port), //nolint:forcetypeassert
|
||||||
)
|
)
|
||||||
assert.Equal(t, bRAddr.String(),
|
assert.Equal(t, bRAddr.String(),
|
||||||
fmt.Sprintf("%s:%d", vnetGlobalIPA, aLAddr.(*net.UDPAddr).Port),
|
fmt.Sprintf("%s:%d", vnetGlobalIPA, aLAddr.(*net.UDPAddr).Port), //nolint:forcetypeassert
|
||||||
)
|
)
|
||||||
|
|
||||||
// Close
|
// Close
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package ice
|
package ice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
@@ -242,7 +243,7 @@ func (m *UDPMuxDefault) connWorker() {
|
|||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
if os.IsTimeout(err) {
|
if os.IsTimeout(err) {
|
||||||
continue
|
continue
|
||||||
} else if err != io.EOF {
|
} else if !errors.Is(err, io.EOF) {
|
||||||
logger.Errorf("could not read udp packet: %v", err)
|
logger.Errorf("could not read udp packet: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func newUDPMuxedConn(params *udpMuxedConnParams) *udpMuxedConn {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *udpMuxedConn) ReadFrom(b []byte) (n int, raddr net.Addr, err error) {
|
func (c *udpMuxedConn) ReadFrom(b []byte) (n int, raddr net.Addr, err error) {
|
||||||
buf := c.params.AddrPool.Get().(*bufferHolder)
|
buf := c.params.AddrPool.Get().(*bufferHolder) //nolint:forcetypeassert
|
||||||
defer c.params.AddrPool.Put(buf)
|
defer c.params.AddrPool.Put(buf)
|
||||||
|
|
||||||
// read address
|
// read address
|
||||||
@@ -171,7 +171,7 @@ func (c *udpMuxedConn) containsAddress(addr string) bool {
|
|||||||
|
|
||||||
func (c *udpMuxedConn) writePacket(data []byte, addr *net.UDPAddr) error {
|
func (c *udpMuxedConn) writePacket(data []byte, addr *net.UDPAddr) error {
|
||||||
// write two packets, address and data
|
// write two packets, address and data
|
||||||
buf := c.params.AddrPool.Get().(*bufferHolder)
|
buf := c.params.AddrPool.Get().(*bufferHolder) //nolint:forcetypeassert
|
||||||
defer c.params.AddrPool.Put(buf)
|
defer c.params.AddrPool.Put(buf)
|
||||||
|
|
||||||
// format of buffer | data len | data bytes | addr len | addr bytes |
|
// format of buffer | data len | data bytes | addr len | addr bytes |
|
||||||
@@ -189,7 +189,7 @@ func (c *udpMuxedConn) writePacket(data []byte, addr *net.UDPAddr) error {
|
|||||||
// write address first, leaving room for its length
|
// write address first, leaving room for its length
|
||||||
n, err := encodeUDPAddr(addr, buf.buffer[offset+2:])
|
n, err := encodeUDPAddr(addr, buf.buffer[offset+2:])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
total := offset + n + 2
|
total := offset + n + 2
|
||||||
|
|
||||||
|
|||||||
4
url.go
4
url.go
@@ -1,6 +1,7 @@
|
|||||||
package ice
|
package ice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -122,7 +123,8 @@ func ParseURL(raw string) (*URL, error) { //nolint:gocognit
|
|||||||
|
|
||||||
var rawPort string
|
var rawPort string
|
||||||
if u.Host, rawPort, err = net.SplitHostPort(rawParts.Opaque); err != nil {
|
if u.Host, rawPort, err = net.SplitHostPort(rawParts.Opaque); err != nil {
|
||||||
if e, ok := err.(*net.AddrError); ok {
|
var e *net.AddrError
|
||||||
|
if errors.As(err, &e) {
|
||||||
if e.Err == "missing port in address" {
|
if e.Err == "missing port in address" {
|
||||||
nextRawURL := u.Scheme.String() + ":" + rawParts.Opaque
|
nextRawURL := u.Scheme.String() + ":" + rawParts.Opaque
|
||||||
switch {
|
switch {
|
||||||
|
|||||||
15
url_test.go
15
url_test.go
@@ -1,6 +1,7 @@
|
|||||||
package ice
|
package ice
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -67,11 +68,15 @@ func TestParseURL(t *testing.T) {
|
|||||||
|
|
||||||
for i, testCase := range testCases {
|
for i, testCase := range testCases {
|
||||||
_, err := ParseURL(testCase.rawURL)
|
_, err := ParseURL(testCase.rawURL)
|
||||||
switch e := err.(type) {
|
var (
|
||||||
case *url.Error:
|
urlError *url.Error
|
||||||
err = e.Err
|
addrError *net.AddrError
|
||||||
case *net.AddrError:
|
)
|
||||||
err = fmt.Errorf(e.Err) //nolint:goerr113
|
switch {
|
||||||
|
case errors.As(err, &urlError):
|
||||||
|
err = urlError.Err
|
||||||
|
case errors.As(err, &addrError):
|
||||||
|
err = fmt.Errorf(addrError.Err) //nolint:goerr113
|
||||||
}
|
}
|
||||||
assert.EqualError(t, err, testCase.expectedErr.Error(), "testCase: %d %v", i, testCase)
|
assert.EqualError(t, err, testCase.expectedErr.Error(), "testCase: %d %v", i, testCase)
|
||||||
}
|
}
|
||||||
|
|||||||
2
util.go
2
util.go
@@ -218,7 +218,7 @@ func listenUDPInPortRange(vnet *vnet.Net, log logging.LeveledLogger, portMax, po
|
|||||||
laddr = &net.UDPAddr{IP: laddr.IP, Port: portCurrent}
|
laddr = &net.UDPAddr{IP: laddr.IP, Port: portCurrent}
|
||||||
c, e := vnet.ListenUDP(network, laddr)
|
c, e := vnet.ListenUDP(network, laddr)
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return c, e
|
return c, e //nolint:nilerr
|
||||||
}
|
}
|
||||||
log.Debugf("failed to listen %s: %v", laddr.String(), e)
|
log.Debugf("failed to listen %s: %v", laddr.String(), e)
|
||||||
portCurrent++
|
portCurrent++
|
||||||
|
|||||||
Reference in New Issue
Block a user