Fix linter errors

golangci-lint upgrade to v1.56.2 added more checks

Relates to pion/.goassets#201
This commit is contained in:
Sean DuBois
2024-03-15 22:25:46 -04:00
parent cb8a47ac37
commit 2d7ced1d49
13 changed files with 60 additions and 58 deletions
+14 -14
View File
@@ -396,7 +396,7 @@ func (a *Agent) startConnectivityChecks(isControlling bool, remoteUfrag, remoteP
a.log.Debugf("Started agent: isControlling? %t, remoteUfrag: %q, remotePwd: %q", isControlling, remoteUfrag, remotePwd)
return a.run(a.context(), func(ctx context.Context, agent *Agent) {
return a.run(a.context(), func(_ context.Context, agent *Agent) {
agent.isControlling = isControlling
agent.remoteUfrag = remoteUfrag
agent.remotePwd = remotePwd
@@ -426,7 +426,7 @@ func (a *Agent) connectivityChecks() {
checkingDuration := time.Time{}
contact := func() {
if err := a.run(a.context(), func(ctx context.Context, a *Agent) {
if err := a.run(a.context(), func(_ context.Context, a *Agent) {
defer func() {
lastConnectionState = a.connectionState
}()
@@ -506,7 +506,7 @@ func (a *Agent) updateConnectionState(newState ConnectionState) {
// Call handler after finishing current task since we may be holding the agent lock
// and the handler may also require it
a.afterRun(func(ctx context.Context) {
a.afterRun(func(_ context.Context) {
a.chanState <- newState
})
}
@@ -685,7 +685,7 @@ func (a *Agent) AddRemoteCandidate(c Candidate) error {
}
go func() {
if err := a.run(a.context(), func(ctx context.Context, agent *Agent) {
if err := a.run(a.context(), func(_ context.Context, agent *Agent) {
// nolint: contextcheck
agent.addRemoteCandidate(c)
}); err != nil {
@@ -717,7 +717,7 @@ func (a *Agent) resolveAndAddMulticastCandidate(c *CandidateHost) {
return
}
if err = a.run(a.context(), func(ctx context.Context, agent *Agent) {
if err = a.run(a.context(), func(_ context.Context, agent *Agent) {
// nolint: contextcheck
agent.addRemoteCandidate(c)
}); err != nil {
@@ -810,7 +810,7 @@ func (a *Agent) addRemoteCandidate(c Candidate) {
}
func (a *Agent) addCandidate(ctx context.Context, c Candidate, candidateConn net.PacketConn) error {
return a.run(ctx, func(ctx context.Context, agent *Agent) {
return a.run(ctx, func(context.Context, *Agent) {
set := a.localCandidates[c.NetworkType()]
for _, candidate := range set {
if candidate.Equal(c) {
@@ -846,7 +846,7 @@ func (a *Agent) addCandidate(ctx context.Context, c Candidate, candidateConn net
func (a *Agent) GetRemoteCandidates() ([]Candidate, error) {
var res []Candidate
err := a.run(a.context(), func(ctx context.Context, agent *Agent) {
err := a.run(a.context(), func(_ context.Context, agent *Agent) {
var candidates []Candidate
for _, set := range agent.remoteCandidates {
candidates = append(candidates, set...)
@@ -864,7 +864,7 @@ func (a *Agent) GetRemoteCandidates() ([]Candidate, error) {
func (a *Agent) GetLocalCandidates() ([]Candidate, error) {
var res []Candidate
err := a.run(a.context(), func(ctx context.Context, agent *Agent) {
err := a.run(a.context(), func(_ context.Context, agent *Agent) {
var candidates []Candidate
for _, set := range agent.localCandidates {
candidates = append(candidates, set...)
@@ -881,7 +881,7 @@ func (a *Agent) GetLocalCandidates() ([]Candidate, error) {
// GetLocalUserCredentials returns the local user credentials
func (a *Agent) GetLocalUserCredentials() (frag string, pwd string, err error) {
valSet := make(chan struct{})
err = a.run(a.context(), func(ctx context.Context, agent *Agent) {
err = a.run(a.context(), func(_ context.Context, agent *Agent) {
frag = agent.localUfrag
pwd = agent.localPwd
close(valSet)
@@ -896,7 +896,7 @@ func (a *Agent) GetLocalUserCredentials() (frag string, pwd string, err error) {
// GetRemoteUserCredentials returns the remote user credentials
func (a *Agent) GetRemoteUserCredentials() (frag string, pwd string, err error) {
valSet := make(chan struct{})
err = a.run(a.context(), func(ctx context.Context, agent *Agent) {
err = a.run(a.context(), func(_ context.Context, agent *Agent) {
frag = agent.remoteUfrag
pwd = agent.remotePwd
close(valSet)
@@ -1145,7 +1145,7 @@ func (a *Agent) handleInbound(m *stun.Message, local Candidate, remote net.Addr)
// and returns true if it is an actual remote candidate
func (a *Agent) validateNonSTUNTraffic(local Candidate, remote net.Addr) (Candidate, bool) {
var remoteCandidate Candidate
if err := a.run(local.context(), func(ctx context.Context, agent *Agent) {
if err := a.run(local.context(), func(context.Context, *Agent) {
remoteCandidate = a.findRemoteCandidate(local.NetworkType(), remote)
if remoteCandidate != nil {
remoteCandidate.seen(false)
@@ -1202,7 +1202,7 @@ func (a *Agent) SetRemoteCredentials(remoteUfrag, remotePwd string) error {
return ErrRemotePwdEmpty
}
return a.run(a.context(), func(ctx context.Context, agent *Agent) {
return a.run(a.context(), func(_ context.Context, agent *Agent) {
agent.remoteUfrag = remoteUfrag
agent.remotePwd = remotePwd
})
@@ -1239,7 +1239,7 @@ func (a *Agent) Restart(ufrag, pwd string) error {
}
var err error
if runErr := a.run(a.context(), func(ctx context.Context, agent *Agent) {
if runErr := a.run(a.context(), func(_ context.Context, agent *Agent) {
if agent.gatheringState == GatheringStateGathering {
agent.gatherCandidateCancel()
}
@@ -1272,7 +1272,7 @@ func (a *Agent) Restart(ufrag, pwd string) error {
func (a *Agent) setGatheringState(newState GatheringState) error {
done := make(chan struct{})
if err := a.run(a.context(), func(ctx context.Context, agent *Agent) {
if err := a.run(a.context(), func(context.Context, *Agent) {
if a.gatheringState != newState && newState == GatheringStateComplete {
a.chanCandidate <- nil
}
@@ -17,12 +17,12 @@ func TestOnSelectedCandidatePairChange(t *testing.T) {
agent, candidatePair := fixtureTestOnSelectedCandidatePairChange(t)
callbackCalled := make(chan struct{}, 1)
err := agent.OnSelectedCandidatePairChange(func(local, remote Candidate) {
err := agent.OnSelectedCandidatePairChange(func(_, _ Candidate) {
close(callbackCalled)
})
require.NoError(t, err)
err = agent.run(context.Background(), func(ctx context.Context, agent *Agent) {
err = agent.run(context.Background(), func(_ context.Context, agent *Agent) {
agent.setSelectedPair(candidatePair)
})
require.NoError(t, err)
+3 -3
View File
@@ -11,7 +11,7 @@ import (
// GetCandidatePairsStats returns a list of candidate pair stats
func (a *Agent) GetCandidatePairsStats() []CandidatePairStats {
var res []CandidatePairStats
err := a.run(a.context(), func(ctx context.Context, agent *Agent) {
err := a.run(a.context(), func(_ context.Context, agent *Agent) {
result := make([]CandidatePairStats, 0, len(agent.checklist))
for _, cp := range agent.checklist {
stat := CandidatePairStats{
@@ -57,7 +57,7 @@ func (a *Agent) GetCandidatePairsStats() []CandidatePairStats {
// GetLocalCandidatesStats returns a list of local candidates stats
func (a *Agent) GetLocalCandidatesStats() []CandidateStats {
var res []CandidateStats
err := a.run(a.context(), func(ctx context.Context, agent *Agent) {
err := a.run(a.context(), func(_ context.Context, agent *Agent) {
result := make([]CandidateStats, 0, len(agent.localCandidates))
for networkType, localCandidates := range agent.localCandidates {
for _, c := range localCandidates {
@@ -94,7 +94,7 @@ func (a *Agent) GetLocalCandidatesStats() []CandidateStats {
// GetRemoteCandidatesStats returns a list of remote candidates stats
func (a *Agent) GetRemoteCandidatesStats() []CandidateStats {
var res []CandidateStats
err := a.run(a.context(), func(ctx context.Context, agent *Agent) {
err := a.run(a.context(), func(_ context.Context, agent *Agent) {
result := make([]CandidateStats, 0, len(agent.remoteCandidates))
for networkType, remoteCandidates := range agent.remoteCandidates {
for _, c := range remoteCandidates {
+8 -6
View File
@@ -24,6 +24,8 @@ import (
"github.com/stretchr/testify/require"
)
const localhostIPStr = "127.0.0.1"
type BadAddr struct{}
func (ba *BadAddr) Network() string {
@@ -57,7 +59,7 @@ func TestHandlePeerReflexive(t *testing.T) {
t.Run("UDP prflx candidate from handleInbound()", func(t *testing.T) {
var config AgentConfig
runAgentTest(t, &config, func(ctx context.Context, a *Agent) {
runAgentTest(t, &config, func(_ context.Context, a *Agent) {
a.selector = &controllingSelector{agent: a, log: a.log}
hostConfig := CandidateHostConfig{
@@ -118,7 +120,7 @@ func TestHandlePeerReflexive(t *testing.T) {
t.Run("Bad network type with handleInbound()", func(t *testing.T) {
var config AgentConfig
runAgentTest(t, &config, func(ctx context.Context, a *Agent) {
runAgentTest(t, &config, func(_ context.Context, a *Agent) {
a.selector = &controllingSelector{agent: a, log: a.log}
hostConfig := CandidateHostConfig{
@@ -145,7 +147,7 @@ func TestHandlePeerReflexive(t *testing.T) {
t.Run("Success from unknown remote, prflx candidate MUST only be created via Binding Request", func(t *testing.T) {
var config AgentConfig
runAgentTest(t, &config, func(ctx context.Context, a *Agent) {
runAgentTest(t, &config, func(_ context.Context, a *Agent) {
a.selector = &controllingSelector{agent: a, log: a.log}
tID := [stun.TransactionIDSize]byte{}
copy(tID[:], "ABC")
@@ -440,7 +442,7 @@ func TestInboundValidity(t *testing.T) {
t.Fatalf("Error constructing ice.Agent")
}
err = a.run(context.Background(), func(ctx context.Context, a *Agent) {
err = a.run(context.Background(), func(_ context.Context, a *Agent) {
a.selector = &controllingSelector{agent: a, log: a.log}
// nolint: contextcheck
a.handleInbound(buildMsg(stun.ClassRequest, a.localUfrag+":"+a.remoteUfrag, a.localPwd), local, remote)
@@ -455,7 +457,7 @@ func TestInboundValidity(t *testing.T) {
t.Run("Valid bind without fingerprint", func(t *testing.T) {
var config AgentConfig
runAgentTest(t, &config, func(ctx context.Context, a *Agent) {
runAgentTest(t, &config, func(_ context.Context, a *Agent) {
a.selector = &controllingSelector{agent: a, log: a.log}
msg, err := stun.Build(stun.BindingRequest, stun.TransactionID,
stun.NewUsername(a.localUfrag+":"+a.remoteUfrag),
@@ -1120,7 +1122,7 @@ func TestConnectionStateFailedDeleteAllCandidates(t *testing.T) {
<-isFailed
done := make(chan struct{})
assert.NoError(t, aAgent.run(context.Background(), func(ctx context.Context, agent *Agent) {
assert.NoError(t, aAgent.run(context.Background(), func(context.Context, *Agent) {
assert.Equal(t, len(aAgent.remoteCandidates), 0)
assert.Equal(t, len(aAgent.localCandidates), 0)
close(done)
+1 -1
View File
@@ -267,7 +267,7 @@ func (c *candidateBase) handleInboundPacket(buf []byte, srcAddr net.Addr) {
return
}
if err := a.run(c, func(ctx context.Context, a *Agent) {
if err := a.run(c, func(_ context.Context, a *Agent) {
// nolint: contextcheck
a.handleInbound(m, c, srcAddr)
}); err != nil {
+3 -3
View File
@@ -31,7 +31,7 @@ func TestRelayOnlyConnection(t *testing.T) {
defer report()
serverPort := randomPort(t)
serverListener, err := net.ListenPacket("udp", "127.0.0.1:"+strconv.Itoa(serverPort))
serverListener, err := net.ListenPacket("udp", localhostIPStr+":"+strconv.Itoa(serverPort))
assert.NoError(t, err)
server, err := turn.NewServer(turn.ServerConfig{
@@ -40,7 +40,7 @@ func TestRelayOnlyConnection(t *testing.T) {
PacketConnConfigs: []turn.PacketConnConfig{
{
PacketConn: serverListener,
RelayAddressGenerator: &turn.RelayAddressGeneratorNone{Address: "127.0.0.1"},
RelayAddressGenerator: &turn.RelayAddressGeneratorNone{Address: localhostIPStr + ""},
},
},
})
@@ -51,7 +51,7 @@ func TestRelayOnlyConnection(t *testing.T) {
Urls: []*stun.URI{
{
Scheme: stun.SchemeTypeTURN,
Host: "127.0.0.1",
Host: localhostIPStr + "",
Username: "username",
Password: "password",
Port: serverPort,
+2 -2
View File
@@ -358,14 +358,14 @@ func TestCandidateMarshal(t *testing.T) {
candidateBase{
networkType: NetworkTypeUDP4,
candidateType: CandidateTypeHost,
address: "127.0.0.1",
address: localhostIPStr,
port: 80,
priorityOverride: 500,
foundationOverride: " ",
},
"",
},
" 1 udp 500 127.0.0.1 80 typ host",
" 1 udp 500 " + localhostIPStr + " 80 typ host",
false,
},
+1 -1
View File
@@ -171,7 +171,7 @@ func addVNetSTUN(wanNet *vnet.Net, loggerFactory logging.LoggerFactory) (*turn.S
return nil, err
}
server, err := turn.NewServer(turn.ServerConfig{
AuthHandler: func(username, realm string, srcAddr net.Addr) (key []byte, ok bool) {
AuthHandler: func(username, realm string, _ net.Addr) (key []byte, ok bool) {
if pw, ok := credMap[username]; ok {
return turn.GenerateAuthKey(username, realm, pw), true
}
+1 -1
View File
@@ -42,7 +42,7 @@ func closeConnAndLog(c io.Closer, log logging.LeveledLogger, msg string, args ..
func (a *Agent) GatherCandidates() error {
var gatherErr error
if runErr := a.run(a.context(), func(ctx context.Context, agent *Agent) {
if runErr := a.run(a.context(), func(ctx context.Context, _ *Agent) {
if a.gatheringState != GatheringStateNew {
gatherErr = ErrMultipleGatherAttempted
return
+22 -22
View File
@@ -104,7 +104,7 @@ func TestGatherConcurrency(t *testing.T) {
assert.NoError(t, err)
candidateGathered, candidateGatheredFunc := context.WithCancel(context.Background())
assert.NoError(t, a.OnCandidate(func(c Candidate) {
assert.NoError(t, a.OnCandidate(func(Candidate) {
candidateGatheredFunc()
}))
@@ -209,7 +209,7 @@ func TestSTUNConcurrency(t *testing.T) {
defer lim.Stop()
serverPort := randomPort(t)
serverListener, err := net.ListenPacket("udp4", "127.0.0.1:"+strconv.Itoa(serverPort))
serverListener, err := net.ListenPacket("udp4", localhostIPStr+":"+strconv.Itoa(serverPort))
assert.NoError(t, err)
server, err := turn.NewServer(turn.ServerConfig{
@@ -218,7 +218,7 @@ func TestSTUNConcurrency(t *testing.T) {
PacketConnConfigs: []turn.PacketConnConfig{
{
PacketConn: serverListener,
RelayAddressGenerator: &turn.RelayAddressGeneratorNone{Address: "127.0.0.1"},
RelayAddressGenerator: &turn.RelayAddressGeneratorNone{Address: localhostIPStr},
},
},
})
@@ -228,13 +228,13 @@ func TestSTUNConcurrency(t *testing.T) {
for i := 0; i <= 10; i++ {
urls = append(urls, &stun.URI{
Scheme: stun.SchemeTypeSTUN,
Host: "127.0.0.1",
Host: localhostIPStr,
Port: serverPort + 1,
})
}
urls = append(urls, &stun.URI{
Scheme: stun.SchemeTypeSTUN,
Host: "127.0.0.1",
Host: localhostIPStr,
Port: serverPort,
})
@@ -289,7 +289,7 @@ func TestTURNConcurrency(t *testing.T) {
if packetConn != nil {
packetConnConfigs = append(packetConnConfigs, turn.PacketConnConfig{
PacketConn: packetConn,
RelayAddressGenerator: &turn.RelayAddressGeneratorNone{Address: "127.0.0.1"},
RelayAddressGenerator: &turn.RelayAddressGeneratorNone{Address: localhostIPStr},
})
}
@@ -297,7 +297,7 @@ func TestTURNConcurrency(t *testing.T) {
if listener != nil {
listenerConfigs = append(listenerConfigs, turn.ListenerConfig{
Listener: listener,
RelayAddressGenerator: &turn.RelayAddressGeneratorNone{Address: "127.0.0.1"},
RelayAddressGenerator: &turn.RelayAddressGeneratorNone{Address: localhostIPStr},
})
}
@@ -313,7 +313,7 @@ func TestTURNConcurrency(t *testing.T) {
for i := 0; i <= 10; i++ {
urls = append(urls, &stun.URI{
Scheme: scheme,
Host: "127.0.0.1",
Host: localhostIPStr,
Username: "username",
Password: "password",
Proto: protocol,
@@ -322,7 +322,7 @@ func TestTURNConcurrency(t *testing.T) {
}
urls = append(urls, &stun.URI{
Scheme: scheme,
Host: "127.0.0.1",
Host: localhostIPStr,
Username: "username",
Password: "password",
Proto: protocol,
@@ -353,7 +353,7 @@ func TestTURNConcurrency(t *testing.T) {
t.Run("UDP Relay", func(t *testing.T) {
serverPort := randomPort(t)
serverListener, err := net.ListenPacket("udp", "127.0.0.1:"+strconv.Itoa(serverPort))
serverListener, err := net.ListenPacket("udp", localhostIPStr+":"+strconv.Itoa(serverPort))
assert.NoError(t, err)
runTest(stun.ProtoTypeUDP, stun.SchemeTypeTURN, serverListener, nil, serverPort)
@@ -361,7 +361,7 @@ func TestTURNConcurrency(t *testing.T) {
t.Run("TCP Relay", func(t *testing.T) {
serverPort := randomPort(t)
serverListener, err := net.Listen("tcp", "127.0.0.1:"+strconv.Itoa(serverPort))
serverListener, err := net.Listen("tcp", localhostIPStr+":"+strconv.Itoa(serverPort))
assert.NoError(t, err)
runTest(stun.ProtoTypeTCP, stun.SchemeTypeTURN, nil, serverListener, serverPort)
@@ -372,7 +372,7 @@ func TestTURNConcurrency(t *testing.T) {
assert.NoError(t, genErr)
serverPort := randomPort(t)
serverListener, err := tls.Listen("tcp", "127.0.0.1:"+strconv.Itoa(serverPort), &tls.Config{ //nolint:gosec
serverListener, err := tls.Listen("tcp", localhostIPStr+":"+strconv.Itoa(serverPort), &tls.Config{ //nolint:gosec
Certificates: []tls.Certificate{certificate},
})
assert.NoError(t, err)
@@ -385,7 +385,7 @@ func TestTURNConcurrency(t *testing.T) {
assert.NoError(t, genErr)
serverPort := randomPort(t)
serverListener, err := dtls.Listen("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: serverPort}, &dtls.Config{
serverListener, err := dtls.Listen("udp", &net.UDPAddr{IP: net.ParseIP(localhostIPStr), Port: serverPort}, &dtls.Config{
Certificates: []tls.Certificate{certificate},
})
assert.NoError(t, err)
@@ -403,7 +403,7 @@ func TestSTUNTURNConcurrency(t *testing.T) {
defer lim.Stop()
serverPort := randomPort(t)
serverListener, err := net.ListenPacket("udp4", "127.0.0.1:"+strconv.Itoa(serverPort))
serverListener, err := net.ListenPacket("udp4", localhostIPStr+":"+strconv.Itoa(serverPort))
assert.NoError(t, err)
server, err := turn.NewServer(turn.ServerConfig{
@@ -412,7 +412,7 @@ func TestSTUNTURNConcurrency(t *testing.T) {
PacketConnConfigs: []turn.PacketConnConfig{
{
PacketConn: serverListener,
RelayAddressGenerator: &turn.RelayAddressGeneratorNone{Address: "127.0.0.1"},
RelayAddressGenerator: &turn.RelayAddressGeneratorNone{Address: localhostIPStr},
},
},
})
@@ -422,14 +422,14 @@ func TestSTUNTURNConcurrency(t *testing.T) {
for i := 0; i <= 10; i++ {
urls = append(urls, &stun.URI{
Scheme: stun.SchemeTypeSTUN,
Host: "127.0.0.1",
Host: localhostIPStr,
Port: serverPort + 1,
})
}
urls = append(urls, &stun.URI{
Scheme: stun.SchemeTypeTURN,
Proto: stun.ProtoTypeUDP,
Host: "127.0.0.1",
Host: localhostIPStr,
Port: serverPort,
Username: "username",
Password: "password",
@@ -475,7 +475,7 @@ func TestTURNSrflx(t *testing.T) {
defer lim.Stop()
serverPort := randomPort(t)
serverListener, err := net.ListenPacket("udp4", "127.0.0.1:"+strconv.Itoa(serverPort))
serverListener, err := net.ListenPacket("udp4", localhostIPStr+":"+strconv.Itoa(serverPort))
assert.NoError(t, err)
server, err := turn.NewServer(turn.ServerConfig{
@@ -484,7 +484,7 @@ func TestTURNSrflx(t *testing.T) {
PacketConnConfigs: []turn.PacketConnConfig{
{
PacketConn: serverListener,
RelayAddressGenerator: &turn.RelayAddressGeneratorNone{Address: "127.0.0.1"},
RelayAddressGenerator: &turn.RelayAddressGeneratorNone{Address: localhostIPStr},
},
},
})
@@ -493,7 +493,7 @@ func TestTURNSrflx(t *testing.T) {
urls := []*stun.URI{{
Scheme: stun.SchemeTypeTURN,
Proto: stun.ProtoTypeUDP,
Host: "127.0.0.1",
Host: localhostIPStr,
Port: serverPort,
Username: "username",
Password: "password",
@@ -577,7 +577,7 @@ func TestTURNProxyDialer(t *testing.T) {
Urls: []*stun.URI{
{
Scheme: stun.SchemeTypeTURN,
Host: "127.0.0.1",
Host: localhostIPStr,
Username: "username",
Password: "password",
Proto: stun.ProtoTypeTCP,
@@ -787,7 +787,7 @@ func TestUniversalUDPMuxUsage(t *testing.T) {
for i := 0; i < numSTUNS; i++ {
urls = append(urls, &stun.URI{
Scheme: SchemeTypeSTUN,
Host: "127.0.0.1",
Host: localhostIPStr,
Port: 3478 + i,
})
}
+1 -1
View File
@@ -15,7 +15,7 @@ func TestRandomGeneratorCollision(t *testing.T) {
gen func(t *testing.T) string
}{
"CandidateID": {
gen: func(t *testing.T) string {
gen: func(*testing.T) string {
return candidateIDGen.Generate()
},
},
+1 -1
View File
@@ -91,7 +91,7 @@ func (c *Conn) Write(p []byte) (int, error) {
pair := c.agent.getSelectedPair()
if pair == nil {
if err = c.agent.run(c.agent.context(), func(ctx context.Context, a *Agent) {
if err = c.agent.run(c.agent.context(), func(_ context.Context, a *Agent) {
pair = a.getBestValidCandidatePair()
}); err != nil {
return 0, err
+1 -1
View File
@@ -49,7 +49,7 @@ func testTimeout(t *testing.T, c *Conn, timeout time.Duration) {
var cs ConnectionState
err := c.agent.run(context.Background(), func(ctx context.Context, agent *Agent) {
err := c.agent.run(context.Background(), func(_ context.Context, agent *Agent) {
cs = agent.connectionState
})
if err != nil {