From 58cf167a087977a93e65f776906bfe1d8c91838c Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Wed, 10 May 2023 18:10:45 +0200 Subject: [PATCH] Misc cleanups after rebase --- client.go | 2 +- .../{tcp_alloc => tcp-alloc}/main.go | 3 +++ internal/client/allocation.go | 26 ++++++++++--------- internal/client/client.go | 4 +++ internal/client/tcp_alloc.go | 3 +++ internal/client/tcp_conn.go | 4 ++- internal/client/tcp_conn_test.go | 3 +++ internal/client/udp_conn.go | 12 ++++----- internal/ipnet/util.go | 2 +- internal/proto/fuzz_test.go | 14 +++++----- internal/server/turn.go | 3 ++- 11 files changed, 47 insertions(+), 29 deletions(-) rename examples/turn-client/{tcp_alloc => tcp-alloc}/main.go (97%) diff --git a/client.go b/client.go index 49271fca..fbbebec7 100644 --- a/client.go +++ b/client.go @@ -511,7 +511,7 @@ func (c *Client) handleSTUNMessage(data []byte, from net.Addr) error { allocation := c.getTCPAllocation() if allocation == nil { c.log.Debug("no TCP allocation exists") - return nil // silently discard + return nil // Silently discard } allocation.HandleConnectionAttempt(addr, cid) diff --git a/examples/turn-client/tcp_alloc/main.go b/examples/turn-client/tcp-alloc/main.go similarity index 97% rename from examples/turn-client/tcp_alloc/main.go rename to examples/turn-client/tcp-alloc/main.go index ed3c14e7..e201d4ca 100644 --- a/examples/turn-client/tcp_alloc/main.go +++ b/examples/turn-client/tcp-alloc/main.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2023 The Pion community +// SPDX-License-Identifier: MIT + // Package main implements a TURN client with support for TCP package main diff --git a/internal/client/allocation.go b/internal/client/allocation.go index 5c44c6f4..774b6f29 100644 --- a/internal/client/allocation.go +++ b/internal/client/allocation.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2023 The Pion community +// SPDX-License-Identifier: MIT + package client import ( @@ -20,16 +23,15 @@ type AllocationConfig struct { } type Allocation struct { - client Client // read-only - relayedAddr net.Addr // read-only - permMap *permissionMap // thread-safe - bindingMgr *bindingManager // Thread-safe - integrity stun.MessageIntegrity // read-only - _nonce stun.Nonce // needs mutex x - _lifetime time.Duration // needs mutex x - refreshAllocTimer *PeriodicTimer // thread-safe - refreshPermsTimer *PeriodicTimer // thread-safe - readTimer *time.Timer // thread-safe - mutex sync.RWMutex // thread-safe - log logging.LeveledLogger // read-only + client Client // Read-only + relayedAddr net.Addr // Read-only + permMap *permissionMap // Thread-safe + integrity stun.MessageIntegrity // Read-only + _nonce stun.Nonce // Needs mutex x + _lifetime time.Duration // Needs mutex x + refreshAllocTimer *PeriodicTimer // Thread-safe + refreshPermsTimer *PeriodicTimer // Thread-safe + readTimer *time.Timer // Thread-safe + mutex sync.RWMutex // Thread-safe + log logging.LeveledLogger // Read-only } diff --git a/internal/client/client.go b/internal/client/client.go index dbdaf95d..44558a4f 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -1,3 +1,7 @@ +// SPDX-FileCopyrightText: 2023 The Pion community +// SPDX-License-Identifier: MIT + +// Package client implements the API for a TURN client package client import ( diff --git a/internal/client/tcp_alloc.go b/internal/client/tcp_alloc.go index 71c97702..fa3231e5 100644 --- a/internal/client/tcp_alloc.go +++ b/internal/client/tcp_alloc.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2023 The Pion community +// SPDX-License-Identifier: MIT + package client import ( diff --git a/internal/client/tcp_conn.go b/internal/client/tcp_conn.go index 492d87ba..a01d28f6 100644 --- a/internal/client/tcp_conn.go +++ b/internal/client/tcp_conn.go @@ -1,4 +1,6 @@ -// Package client implements the API for a TURN client +// SPDX-FileCopyrightText: 2023 The Pion community +// SPDX-License-Identifier: MIT + package client import ( diff --git a/internal/client/tcp_conn_test.go b/internal/client/tcp_conn_test.go index 0f8456fe..87969d1f 100644 --- a/internal/client/tcp_conn_test.go +++ b/internal/client/tcp_conn_test.go @@ -1,3 +1,6 @@ +// SPDX-FileCopyrightText: 2023 The Pion community +// SPDX-License-Identifier: MIT + package client import ( diff --git a/internal/client/udp_conn.go b/internal/client/udp_conn.go index 097ba206..7da04e69 100644 --- a/internal/client/udp_conn.go +++ b/internal/client/udp_conn.go @@ -33,11 +33,11 @@ type inboundData struct { } // UDPConn is the implementation of the Conn and PacketConn interfaces for UDP network connections. -// comatible with net.PacketConn and net.Conn +// compatible with net.PacketConn and net.Conn type UDPConn struct { - bindingMgr *bindingManager // thread-safe - readCh chan *inboundData // thread-safe - closeCh chan struct{} // thread-safe + bindingMgr *bindingManager // Thread-safe + readCh chan *inboundData // Thread-safe + closeCh chan struct{} // Thread-safe Allocation } @@ -203,7 +203,7 @@ func (c *UDPConn) WriteTo(p []byte, addr net.Addr) (int, error) { //nolint: goco } }() - // send data using SendIndication + // Send data using SendIndication peerAddr := addr2PeerAddress(addr) var msg *stun.Message msg, err = stun.Build( @@ -381,7 +381,7 @@ func (c *Allocation) CreatePermissions(addrs ...net.Addr) error { // HandleInbound passes inbound data in UDPConn func (c *UDPConn) HandleInbound(data []byte, from net.Addr) { - // copy data + // Copy data copied := make([]byte, len(data)) copy(copied, data) diff --git a/internal/ipnet/util.go b/internal/ipnet/util.go index 3bcbc79e..1cc7f135 100644 --- a/internal/ipnet/util.go +++ b/internal/ipnet/util.go @@ -49,5 +49,5 @@ func FingerprintAddr(addr net.Addr) string { case *net.TCPAddr: // Do we really need this case? return a.IP.String() } - return "" // should never happen + return "" // Should never happen } diff --git a/internal/proto/fuzz_test.go b/internal/proto/fuzz_test.go index f49faed6..1bedc5e8 100644 --- a/internal/proto/fuzz_test.go +++ b/internal/proto/fuzz_test.go @@ -63,28 +63,28 @@ func FuzzSetters(f *testing.F) { m1.Add(attr.t, value) if err := attr.g.GetFrom(m1); err != nil { if errors.Is(err, stun.ErrAttributeNotFound) { - fmt.Println("unexpected 404") // nolint - panic(err) // nolint + fmt.Println("unexpected 404") //nolint + panic(err) //nolint } return } m2.WriteHeader() if err := attr.g.AddTo(m2); err != nil { - fmt.Println("failed to add attribute to m2") // nolint - panic(err) // nolint + fmt.Println("failed to add attribute to m2") //nolint + panic(err) //nolint } m3.WriteHeader() v, err := m2.Get(attr.t) if err != nil { - panic(err) // nolint + panic(err) //nolint } m3.Add(attr.t, v) if !m2.Equal(m3) { - fmt.Println(m2, "not equal", m3) // nolint - panic("not equal") // nolint + fmt.Println(m2, "not equal", m3) //nolint + panic("not equal") //nolint } }) } diff --git a/internal/server/turn.go b/internal/server/turn.go index d77b1850..11a73d8f 100644 --- a/internal/server/turn.go +++ b/internal/server/turn.go @@ -131,7 +131,8 @@ func handleAllocateRequest(r Request, m *stun.Message) error { } // Once the allocation is created, the server replies with a success - // response. The success response contains: + // response. + // The success response contains: // * An XOR-RELAYED-ADDRESS attribute containing the relayed transport // address. // * A LIFETIME attribute containing the current value of the time-to-