Skip to content

Commit

Permalink
Fix linter errors
Browse files Browse the repository at this point in the history
golangci-lint upgrade to v1.56.2 added more checks

Relates to pion/.goassets#201
  • Loading branch information
Sean-Der committed Mar 16, 2024
1 parent cb8a47a commit 2d7ced1
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 58 deletions.
28 changes: 14 additions & 14 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}()
Expand Down Expand Up @@ -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
})
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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...)
Expand All @@ -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...)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
})
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions agent_on_selected_candidate_pair_change_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions agent_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
14 changes: 8 additions & 6 deletions agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/stretchr/testify/require"
)

const localhostIPStr = "127.0.0.1"

type BadAddr struct{}

func (ba *BadAddr) Network() string {
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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),
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion candidate_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions candidate_relay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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 + ""},
},
},
})
Expand All @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions candidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},

Expand Down
2 changes: 1 addition & 1 deletion connectivity_vnet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion gather.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2d7ced1

Please sign in to comment.