Skip to content

Commit

Permalink
Misc cleanups after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
stv0g committed May 10, 2023
1 parent de0b89a commit 58cf167
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 29 deletions.
2 changes: 1 addition & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

// Package main implements a TURN client with support for TCP
package main

Expand Down
26 changes: 14 additions & 12 deletions internal/client/allocation.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package client

import (
Expand All @@ -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
}
4 changes: 4 additions & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

// Package client implements the API for a TURN client
package client

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/client/tcp_alloc.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package client

import (
Expand Down
4 changes: 3 additions & 1 deletion internal/client/tcp_conn.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// Package client implements the API for a TURN client
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package client

import (
Expand Down
3 changes: 3 additions & 0 deletions internal/client/tcp_conn_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package client

import (
Expand Down
12 changes: 6 additions & 6 deletions internal/client/udp_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion internal/ipnet/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
14 changes: 7 additions & 7 deletions internal/proto/fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
})
}
Expand Down
3 changes: 2 additions & 1 deletion internal/server/turn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-
Expand Down

0 comments on commit 58cf167

Please sign in to comment.