From 9e4efcc2d4f7c1df2d98a906b80b71c7b8977ef5 Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Sat, 16 Mar 2024 20:58:51 -0400 Subject: [PATCH] Fix linter errors golangci-lint upgrade to v1.56.2 added more checks Relates to pion/.goassets#201 --- client_test.go | 4 ++-- examples/turn-server/add-software-attribute/main.go | 2 +- examples/turn-server/log/main.go | 2 +- examples/turn-server/perm-filter/main.go | 2 +- examples/turn-server/port-range/main.go | 2 +- examples/turn-server/simple-multithreaded/main.go | 4 ++-- examples/turn-server/simple/main.go | 2 +- examples/turn-server/tcp/main.go | 2 +- examples/turn-server/tls/main.go | 2 +- internal/allocation/allocation_manager_test.go | 6 +++--- internal/client/tcp_conn_test.go | 6 +++--- internal/client/udp_conn_test.go | 6 +++--- internal/proto/fuzz_test.go | 6 +++--- internal/server/turn_test.go | 6 +++--- server_test.go | 12 ++++++------ 15 files changed, 32 insertions(+), 32 deletions(-) diff --git a/client_test.go b/client_test.go index 2e7e9346..cc011df1 100644 --- a/client_test.go +++ b/client_test.go @@ -142,7 +142,7 @@ func TestClientNonceExpiration(t *testing.T) { assert.NoError(t, err) server, err := NewServer(ServerConfig{ - AuthHandler: func(username, realm string, srcAddr net.Addr) (key []byte, ok bool) { + AuthHandler: func(username, realm string, _ net.Addr) (key []byte, ok bool) { return GenerateAuthKey(username, realm, "pass"), true }, PacketConnConfigs: []PacketConnConfig{ @@ -193,7 +193,7 @@ func TestTCPClient(t *testing.T) { require.NoError(t, err) server, err := NewServer(ServerConfig{ - AuthHandler: func(username, realm string, srcAddr net.Addr) (key []byte, ok bool) { + AuthHandler: func(username, realm string, _ net.Addr) (key []byte, ok bool) { return GenerateAuthKey(username, realm, "pass"), true }, ListenerConfigs: []ListenerConfig{ diff --git a/examples/turn-server/add-software-attribute/main.go b/examples/turn-server/add-software-attribute/main.go index 2deb3cb3..1e47058e 100644 --- a/examples/turn-server/add-software-attribute/main.go +++ b/examples/turn-server/add-software-attribute/main.go @@ -76,7 +76,7 @@ func main() { // Set AuthHandler callback // This is called every time a user tries to authenticate with the TURN server // Return the key for that user, or false when no user is found - AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { + AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { // nolint: revive if key, ok := usersMap[username]; ok { return key, true } diff --git a/examples/turn-server/log/main.go b/examples/turn-server/log/main.go index 40a75346..2298abc7 100644 --- a/examples/turn-server/log/main.go +++ b/examples/turn-server/log/main.go @@ -84,7 +84,7 @@ func main() { // Set AuthHandler callback // This is called every time a user tries to authenticate with the TURN server // Return the key for that user, or false when no user is found - AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { + AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { // nolint: revive if key, ok := usersMap[username]; ok { return key, true } diff --git a/examples/turn-server/perm-filter/main.go b/examples/turn-server/perm-filter/main.go index 44fe8f55..11139029 100644 --- a/examples/turn-server/perm-filter/main.go +++ b/examples/turn-server/perm-filter/main.go @@ -54,7 +54,7 @@ func main() { // Set AuthHandler callback // This is called every time a user tries to authenticate with the TURN server // Return the key for that user, or false when no user is found - AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { + AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { // nolint: revive if key, ok := usersMap[username]; ok { return key, true } diff --git a/examples/turn-server/port-range/main.go b/examples/turn-server/port-range/main.go index 562deb81..5d89e994 100644 --- a/examples/turn-server/port-range/main.go +++ b/examples/turn-server/port-range/main.go @@ -51,7 +51,7 @@ func main() { // Set AuthHandler callback // This is called every time a user tries to authenticate with the TURN server // Return the key for that user, or false when no user is found - AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { + AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { // nolint: revive if key, ok := usersMap[username]; ok { return key, true } diff --git a/examples/turn-server/simple-multithreaded/main.go b/examples/turn-server/simple-multithreaded/main.go index d50028e9..acae7e59 100644 --- a/examples/turn-server/simple-multithreaded/main.go +++ b/examples/turn-server/simple-multithreaded/main.go @@ -53,7 +53,7 @@ func main() { // UDP listeners share the same local address:port with setting SO_REUSEPORT and the kernel // will load-balance received packets per the IP 5-tuple listenerConfig := &net.ListenConfig{ - Control: func(network, address string, conn syscall.RawConn) error { + Control: func(network, address string, conn syscall.RawConn) error { // nolint: revive var operr error if err = conn.Control(func(fd uintptr) { operr = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, unix.SO_REUSEPORT, 1) @@ -90,7 +90,7 @@ func main() { // Set AuthHandler callback // This is called every time a user tries to authenticate with the TURN server // Return the key for that user, or false when no user is found - AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { + AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { // nolint: revive if key, ok := usersMap[username]; ok { return key, true } diff --git a/examples/turn-server/simple/main.go b/examples/turn-server/simple/main.go index 32c76674..d2ba7d7c 100644 --- a/examples/turn-server/simple/main.go +++ b/examples/turn-server/simple/main.go @@ -50,7 +50,7 @@ func main() { // Set AuthHandler callback // This is called every time a user tries to authenticate with the TURN server // Return the key for that user, or false when no user is found - AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { + AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { // nolint: revive if key, ok := usersMap[username]; ok { return key, true } diff --git a/examples/turn-server/tcp/main.go b/examples/turn-server/tcp/main.go index de617298..9a6ab47b 100644 --- a/examples/turn-server/tcp/main.go +++ b/examples/turn-server/tcp/main.go @@ -50,7 +50,7 @@ func main() { // Set AuthHandler callback // This is called every time a user tries to authenticate with the TURN server // Return the key for that user, or false when no user is found - AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { + AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { // nolint: revive if key, ok := usersMap[username]; ok { return key, true } diff --git a/examples/turn-server/tls/main.go b/examples/turn-server/tls/main.go index 094ab9c5..61823086 100644 --- a/examples/turn-server/tls/main.go +++ b/examples/turn-server/tls/main.go @@ -63,7 +63,7 @@ func main() { // Set AuthHandler callback // This is called every time a user tries to authenticate with the TURN server // Return the key for that user, or false when no user is found - AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { + AuthHandler: func(username string, realm string, srcAddr net.Addr) ([]byte, bool) { // nolint: revive if key, ok := usersMap[username]; ok { return key, true } diff --git a/internal/allocation/allocation_manager_test.go b/internal/allocation/allocation_manager_test.go index e33c2c8d..5ebfe68b 100644 --- a/internal/allocation/allocation_manager_test.go +++ b/internal/allocation/allocation_manager_test.go @@ -167,7 +167,7 @@ func subTestManagerClose(t *testing.T, turnSocket net.PacketConn) { } func randomFiveTuple() *FiveTuple { - /* #nosec */ + // nolint return &FiveTuple{ SrcAddr: &net.UDPAddr{IP: nil, Port: rand.Int()}, DstAddr: &net.UDPAddr{IP: nil, Port: rand.Int()}, @@ -179,7 +179,7 @@ func newTestManager() (*Manager, error) { config := ManagerConfig{ LeveledLogger: loggerFactory.NewLogger("test"), - AllocatePacketConn: func(network string, requestedPort int) (net.PacketConn, net.Addr, error) { + AllocatePacketConn: func(string, int) (net.PacketConn, net.Addr, error) { conn, err := net.ListenPacket("udp4", "0.0.0.0:0") if err != nil { return nil, nil, err @@ -187,7 +187,7 @@ func newTestManager() (*Manager, error) { return conn, conn.LocalAddr(), nil }, - AllocateConn: func(network string, requestedPort int) (net.Conn, net.Addr, error) { return nil, nil, nil }, + AllocateConn: func(string, int) (net.Conn, net.Addr, error) { return nil, nil, nil }, } return NewManager(config) } diff --git a/internal/client/tcp_conn_test.go b/internal/client/tcp_conn_test.go index 69fdaa9e..e0f2777d 100644 --- a/internal/client/tcp_conn_test.go +++ b/internal/client/tcp_conn_test.go @@ -44,7 +44,7 @@ func TestTCPConn(t *testing.T) { t.Run("Connect()", func(t *testing.T) { var cid proto.ConnectionID = 5 client := &mockClient{ - performTransaction: func(msg *stun.Message, to net.Addr, dontWait bool) (TransactionResult, error) { + performTransaction: func(msg *stun.Message, _ net.Addr, _ bool) (TransactionResult, error) { if msg.Type.Class == stun.ClassRequest && msg.Type.Method == stun.MethodConnect { msg, err := stun.Build( stun.TransactionID, @@ -83,7 +83,7 @@ func TestTCPConn(t *testing.T) { assert.Equal(t, cid, actualCid) client = &mockClient{ - performTransaction: func(msg *stun.Message, to net.Addr, dontWait bool) (TransactionResult, error) { + performTransaction: func(msg *stun.Message, _ net.Addr, _ bool) (TransactionResult, error) { if msg.Type.Class == stun.ClassRequest && msg.Type.Method == stun.MethodConnect { msg, err = stun.Build( stun.TransactionID, @@ -159,7 +159,7 @@ func TestTCPConn(t *testing.T) { var cid proto.ConnectionID = 5 loggerFactory := logging.NewDefaultLoggerFactory() client := &mockClient{ - performTransaction: func(msg *stun.Message, to net.Addr, dontWait bool) (TransactionResult, error) { + performTransaction: func(msg *stun.Message, _ net.Addr, _ bool) (TransactionResult, error) { typ := stun.NewType(stun.MethodConnect, stun.ClassSuccessResponse) if msg.Type.Method == stun.MethodCreatePermission { typ = stun.NewType(stun.MethodCreatePermission, stun.ClassSuccessResponse) diff --git a/internal/client/udp_conn_test.go b/internal/client/udp_conn_test.go index 0671a847..ee7ef7fc 100644 --- a/internal/client/udp_conn_test.go +++ b/internal/client/udp_conn_test.go @@ -14,7 +14,7 @@ import ( func TestUDPConn(t *testing.T) { t.Run("bind()", func(t *testing.T) { client := &mockClient{ - performTransaction: func(msg *stun.Message, to net.Addr, dontWait bool) (TransactionResult, error) { + performTransaction: func(*stun.Message, net.Addr, bool) (TransactionResult, error) { return TransactionResult{}, errFake }, } @@ -40,10 +40,10 @@ func TestUDPConn(t *testing.T) { t.Run("WriteTo()", func(t *testing.T) { client := &mockClient{ - performTransaction: func(msg *stun.Message, to net.Addr, dontWait bool) (TransactionResult, error) { + performTransaction: func(*stun.Message, net.Addr, bool) (TransactionResult, error) { return TransactionResult{}, errFake }, - writeTo: func(data []byte, to net.Addr) (int, error) { + writeTo: func(data []byte, _ net.Addr) (int, error) { return len(data), nil }, } diff --git a/internal/proto/fuzz_test.go b/internal/proto/fuzz_test.go index be1bfcd7..2534e1a3 100644 --- a/internal/proto/fuzz_test.go +++ b/internal/proto/fuzz_test.go @@ -31,7 +31,7 @@ func (a attrs) pick(v byte) struct { } func FuzzSetters(f *testing.F) { - f.Fuzz(func(t *testing.T, attrType byte, value []byte) { + f.Fuzz(func(_ *testing.T, attrType byte, value []byte) { var ( m1 = &stun.Message{ Raw: make([]byte, 0, 2048), @@ -92,7 +92,7 @@ func FuzzSetters(f *testing.F) { func FuzzChannelData(f *testing.F) { d := &ChannelData{} - f.Fuzz(func(t *testing.T, data []byte) { + f.Fuzz(func(_ *testing.T, data []byte) { d.Reset() if len(data) > channelDataHeaderSize { @@ -123,7 +123,7 @@ func FuzzChannelData(f *testing.F) { } func FuzzIsChannelData(f *testing.F) { - f.Fuzz(func(t *testing.T, data []byte) { + f.Fuzz(func(_ *testing.T, data []byte) { IsChannelData(data) }) } diff --git a/internal/server/turn_test.go b/internal/server/turn_test.go index b188facb..2590ab6e 100644 --- a/internal/server/turn_test.go +++ b/internal/server/turn_test.go @@ -64,7 +64,7 @@ func TestAllocationLifeTime(t *testing.T) { logger := logging.NewDefaultLoggerFactory().NewLogger("turn") allocationManager, err := allocation.NewManager(allocation.ManagerConfig{ - AllocatePacketConn: func(network string, requestedPort int) (net.PacketConn, net.Addr, error) { + AllocatePacketConn: func(network string, _ int) (net.PacketConn, net.Addr, error) { conn, listenErr := net.ListenPacket(network, "0.0.0.0:0") if err != nil { return nil, nil, listenErr @@ -72,7 +72,7 @@ func TestAllocationLifeTime(t *testing.T) { return conn, conn.LocalAddr(), nil }, - AllocateConn: func(network string, requestedPort int) (net.Conn, net.Addr, error) { + AllocateConn: func(string, int) (net.Conn, net.Addr, error) { return nil, nil, nil }, LeveledLogger: logger, @@ -90,7 +90,7 @@ func TestAllocationLifeTime(t *testing.T) { Conn: l, SrcAddr: &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5000}, Log: logger, - AuthHandler: func(username string, realm string, srcAddr net.Addr) (key []byte, ok bool) { + AuthHandler: func(string, string, net.Addr) (key []byte, ok bool) { return []byte(staticKey), true }, } diff --git a/server_test.go b/server_test.go index 13f755b2..ceeca8e5 100644 --- a/server_test.go +++ b/server_test.go @@ -39,7 +39,7 @@ func TestServer(t *testing.T) { assert.NoError(t, err) server, err := NewServer(ServerConfig{ - AuthHandler: func(username, realm string, srcAddr net.Addr) (key []byte, ok bool) { + AuthHandler: func(username, _ string, _ net.Addr) (key []byte, ok bool) { if pw, ok := credMap[username]; ok { return pw, true } @@ -128,7 +128,7 @@ func TestServer(t *testing.T) { assert.NoError(t, err) server, err := NewServer(ServerConfig{ - AuthHandler: func(username, realm string, srcAddr net.Addr) (key []byte, ok bool) { + AuthHandler: func(username, _ string, _ net.Addr) (key []byte, ok bool) { if pw, ok := credMap[username]; ok { return pw, true } @@ -150,7 +150,7 @@ func TestServer(t *testing.T) { // make sure we can reuse the client port dialer := &net.Dialer{ - Control: func(network, address string, conn syscall.RawConn) error { + Control: func(_, _ string, conn syscall.RawConn) error { return conn.Control(func(descriptor uintptr) { _ = syscall.SetsockoptInt(int(descriptor), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1) }) @@ -213,7 +213,7 @@ func TestServer(t *testing.T) { assert.NoError(t, err) server, err := NewServer(ServerConfig{ - AuthHandler: func(username, realm string, srcAddr net.Addr) (key []byte, ok bool) { + AuthHandler: func(username, _ string, _ net.Addr) (key []byte, ok bool) { if pw, ok := credMap[username]; ok { return pw, true } @@ -453,7 +453,7 @@ func buildVNet() (*VNet, error) { } server, err := NewServer(ServerConfig{ - AuthHandler: func(username, realm string, srcAddr net.Addr) (key []byte, ok bool) { + AuthHandler: func(username, _ string, _ net.Addr) (key []byte, ok bool) { if pw, ok := credMap[username]; ok { return pw, true } @@ -591,7 +591,7 @@ func RunBenchmarkServer(b *testing.B, clientNum int) { defer serverConn.Close() //nolint:errcheck server, err := NewServer(ServerConfig{ - AuthHandler: func(username, realm string, srcAddr net.Addr) (key []byte, ok bool) { + AuthHandler: func(username, _ string, _ net.Addr) (key []byte, ok bool) { if pw, ok := credMap[username]; ok { return pw, true }