Skip to content

Commit

Permalink
Harmonize capitalization of logging messages
Browse files Browse the repository at this point in the history
  • Loading branch information
stv0g committed Jun 24, 2023
1 parent f45f69e commit 6e9e94a
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 56 deletions.
32 changes: 16 additions & 16 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ func (c *Client) Listen() error {
for {
n, from, err := c.conn.ReadFrom(buf)
if err != nil {
c.log.Debugf("exiting read loop: %s", err.Error())
c.log.Debugf("Failed to read: %s. Exiting loop", err)
break
}

_, err = c.HandleInbound(buf[:n], from)
if err != nil {
c.log.Debugf("exiting read loop: %s", err.Error())
c.log.Debugf("Failed to handle inbound message: %s. Exiting loop", err)
break
}
}
Expand Down Expand Up @@ -404,7 +404,7 @@ func (c *Client) PerformTransaction(msg *stun.Message, to net.Addr, ignoreResult

c.trMap.Insert(trKey, tr)

c.log.Tracef("start %s transaction %s to %s", msg.Type, trKey, tr.To.String())
c.log.Tracef("Start %s transaction %s to %s", msg.Type, trKey, tr.To.String())
_, err := c.conn.WriteTo(tr.Raw, to)
if err != nil {
return client.TransactionResult{}, err
Expand Down Expand Up @@ -467,7 +467,7 @@ func (c *Client) HandleInbound(data []byte, from net.Addr) (bool, error) {
return true, errNonSTUNMessage
default:
// Assume, this is an application data
c.log.Tracef("non-STUN/TURN packet, unhandled")
c.log.Tracef("Ignoring non-STUN/TURN packet")
}

return false, nil
Expand Down Expand Up @@ -503,11 +503,11 @@ func (c *Client) handleSTUNMessage(data []byte, from net.Addr) error {
return err
}

c.log.Tracef("data indication received from %s", from.String())
c.log.Tracef("Data indication received from %s", from.String())

relayedConn := c.relayedUDPConn()
if relayedConn == nil {
c.log.Debug("no relayed conn allocated")
c.log.Debug("No relayed conn allocated")
return nil // Silently discard
}
relayedConn.HandleInbound(data, from)
Expand All @@ -527,17 +527,17 @@ func (c *Client) handleSTUNMessage(data []byte, from net.Addr) error {
return err
}

c.log.Debugf("connection attempt from %s", addr.String())
c.log.Debugf("Connection attempt from %s", addr.String())

allocation := c.getTCPAllocation()
if allocation == nil {
c.log.Debug("no TCP allocation exists")
c.log.Debug("No TCP allocation exists")
return nil // Silently discard
}

allocation.HandleConnectionAttempt(addr, cid)
default:
c.log.Debug("received unsupported STUN method")
c.log.Debug("Received unsupported STUN method")
}
return nil
}
Expand All @@ -554,7 +554,7 @@ func (c *Client) handleSTUNMessage(data []byte, from net.Addr) error {
if !ok {
c.mutexTrMap.Unlock()
// Silently discard
c.log.Debugf("no transaction for %s", msg.String())
c.log.Debugf("No transaction for %s", msg.String())
return nil
}

Expand All @@ -568,7 +568,7 @@ func (c *Client) handleSTUNMessage(data []byte, from net.Addr) error {
From: from,
Retries: tr.Retries(),
}) {
c.log.Debugf("no listener for %s", msg.String())
c.log.Debugf("No listener for %s", msg.String())
}

return nil
Expand All @@ -585,7 +585,7 @@ func (c *Client) handleChannelData(data []byte) error {

relayedConn := c.relayedUDPConn()
if relayedConn == nil {
c.log.Debug("no relayed conn allocated")
c.log.Debug("No relayed conn allocated")
return nil // Silently discard
}

Expand All @@ -594,7 +594,7 @@ func (c *Client) handleChannelData(data []byte) error {
return fmt.Errorf("%w: %d", errChannelBindNotFound, int(chData.Number))
}

c.log.Tracef("channel data received from %s (ch=%d)", addr.String(), int(chData.Number))
c.log.Tracef("Channel data received from %s (ch=%d)", addr.String(), int(chData.Number))

relayedConn.HandleInbound(chData.Data, addr)
return nil
Expand All @@ -615,20 +615,20 @@ func (c *Client) onRtxTimeout(trKey string, nRtx int) {
if !tr.WriteResult(client.TransactionResult{
Err: fmt.Errorf("%w %s", errAllRetransmissionsFailed, trKey),
}) {
c.log.Debug("no listener for transaction")
c.log.Debug("No listener for transaction")
}
return
}

c.log.Tracef("retransmitting transaction %s to %s (nRtx=%d)",
c.log.Tracef("Retransmitting transaction %s to %s (nRtx=%d)",
trKey, tr.To.String(), nRtx)
_, err := c.conn.WriteTo(tr.Raw, tr.To)
if err != nil {
c.trMap.Delete(trKey)
if !tr.WriteResult(client.TransactionResult{
Err: fmt.Errorf("%w %s", errFailedToRetransmitTransaction, trKey),
}) {
c.log.Debug("no listener for transaction")
c.log.Debug("No listener for transaction")
}
return
}
Expand Down
4 changes: 2 additions & 2 deletions examples/turn-client/tcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ func main() {
flag.Parse()

if len(*host) == 0 {
log.Fatalf("'host' is required")
log.Fatalf("Parameter 'host' is required")
}

if len(*user) == 0 {
log.Fatalf("'user' is required")
log.Fatalf("Parameter 'user' is required")
}

// Dial TURN Server
Expand Down
4 changes: 2 additions & 2 deletions internal/allocation/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (a *Allocation) packetHandler(m *Manager) {
return
}

a.log.Debugf("relay socket %s received %d bytes from %s",
a.log.Debugf("Relay socket %s received %d bytes from %s",
a.RelaySocket.LocalAddr().String(),
n,
srcAddr.String())
Expand Down Expand Up @@ -273,7 +273,7 @@ func (a *Allocation) packetHandler(m *Manager) {
a.log.Errorf("Failed to send DataIndication from allocation %v %v", srcAddr, err)
return
}
a.log.Debugf("relaying message from %s to client at %s",
a.log.Debugf("Relaying message from %s to client at %s",
srcAddr.String(),
a.fiveTuple.SrcAddr.String())
if _, err = a.TurnSocket.WriteTo(msg.Raw, a.fiveTuple.SrcAddr); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/allocation/allocation_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (m *Manager) CreateAllocation(fiveTuple *FiveTuple, turnSocket net.PacketCo
a.RelaySocket = conn
a.RelayAddr = relayAddr

m.log.Debugf("listening on relay addr: %s", a.RelayAddr.String())
m.log.Debugf("Listening on relay address: %s", a.RelayAddr.String())

a.lifetimeTimer = time.AfterFunc(lifetime, func() {
m.DeleteAllocation(a.fiveTuple)
Expand Down
26 changes: 13 additions & 13 deletions internal/client/allocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ func (a *allocation) setNonceFromMsg(msg *stun.Message) {
var nonce stun.Nonce
if err := nonce.GetFrom(msg); err == nil {
a.setNonce(nonce)
a.log.Debug("refresh allocation: 438, got new nonce.")
a.log.Debug("Refresh allocation: 438, got new nonce.")
} else {
a.log.Warn("refresh allocation: 438 but no nonce.")
a.log.Warn("Refresh allocation: 438 but no nonce.")
}
}

Expand All @@ -74,18 +74,18 @@ func (a *allocation) refreshAllocation(lifetime time.Duration, dontWait bool) er
return fmt.Errorf("%w: %s", errFailedToBuildRefreshRequest, err.Error())
}

a.log.Debugf("send refresh request (dontWait=%v)", dontWait)
a.log.Debugf("Send refresh request (dontWait=%v)", dontWait)
trRes, err := a.client.PerformTransaction(msg, a.serverAddr, dontWait)
if err != nil {
return fmt.Errorf("%w: %s", errFailedToRefreshAllocation, err.Error())
}

if dontWait {
a.log.Debug("refresh request sent")
a.log.Debug("Refresh request sent")
return nil
}

a.log.Debug("refresh request sent, and waiting response")
a.log.Debug("Refresh request sent, and waiting response")

res := trRes.Msg
if res.Type.Class == stun.ClassErrorResponse {
Expand All @@ -107,29 +107,29 @@ func (a *allocation) refreshAllocation(lifetime time.Duration, dontWait bool) er
}

a.setLifetime(updatedLifetime.Duration)
a.log.Debugf("updated lifetime: %d seconds", int(a.lifetime().Seconds()))
a.log.Debugf("Updated lifetime: %d seconds", int(a.lifetime().Seconds()))
return nil
}

func (a *allocation) refreshPermissions() error {
addrs := a.permMap.addrs()
if len(addrs) == 0 {
a.log.Debug("no permission to refresh")
a.log.Debug("No permission to refresh")
return nil
}
if err := a.CreatePermissions(addrs...); err != nil {
if errors.Is(err, errTryAgain) {
return errTryAgain
}
a.log.Errorf("fail to refresh permissions: %s", err.Error())
a.log.Errorf("Fail to refresh permissions: %s", err)
return err
}
a.log.Debug("refresh permissions successful")
a.log.Debug("Refresh permissions successful")
return nil
}

func (a *allocation) onRefreshTimers(id int) {
a.log.Debugf("refresh timer %d expired", id)
a.log.Debugf("Refresh timer %d expired", id)
switch id {
case timerIDRefreshAlloc:
var err error
Expand All @@ -143,7 +143,7 @@ func (a *allocation) onRefreshTimers(id int) {
}
}
if err != nil {
a.log.Warnf("refresh allocation failed")
a.log.Warnf("Failed to refresh allocation: %s", err)
}
case timerIDRefreshPerms:
var err error
Expand All @@ -154,7 +154,7 @@ func (a *allocation) onRefreshTimers(id int) {
}
}
if err != nil {
a.log.Warnf("refresh permissions failed")
a.log.Warnf("Failed to refresh permissions: %s", err)
}
}
}
Expand All @@ -170,7 +170,7 @@ func (a *allocation) setNonce(nonce stun.Nonce) {
a.mutex.Lock()
defer a.mutex.Unlock()

a.log.Debugf("set new nonce with %d bytes", len(nonce))
a.log.Debugf("Set new nonce with %d bytes", len(nonce))
a._nonce = nonce
}

Expand Down
14 changes: 7 additions & 7 deletions internal/client/udp_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewUDPConn(config *AllocationConfig) *UDPConn {
},
}

c.log.Debugf("initial lifetime: %d seconds", int(c.lifetime().Seconds()))
c.log.Debugf("Initial lifetime: %d seconds", int(c.lifetime().Seconds()))

c.refreshAllocTimer = NewPeriodicTimer(
timerIDRefreshAlloc,
Expand All @@ -78,10 +78,10 @@ func NewUDPConn(config *AllocationConfig) *UDPConn {
)

if c.refreshAllocTimer.Start() {
c.log.Debugf("refreshAllocTimer started")
c.log.Debugf("Started refresh allocation timer")
}
if c.refreshPermsTimer.Start() {
c.log.Debugf("refreshPermsTimer started")
c.log.Debugf("Started refresh permission timer")
}

return c
Expand Down Expand Up @@ -197,7 +197,7 @@ func (c *UDPConn) WriteTo(p []byte, addr net.Addr) (int, error) { //nolint: goco
go func() {
err2 := c.bind(b)
if err2 != nil {
c.log.Warnf("bind() failed: %s", err2.Error())
c.log.Warnf("Failed to bind bind(): %s", err2)
b.setState(bindingStateFailed)
// Keep going...
} else {
Expand Down Expand Up @@ -238,7 +238,7 @@ func (c *UDPConn) WriteTo(p []byte, addr net.Addr) (int, error) { //nolint: goco
go func() {
err = c.bind(b)
if err != nil {
c.log.Warnf("bind() for refresh failed: %s", err.Error())
c.log.Warnf("Failed to bind() for refresh: %s", err)
b.setState(bindingStateFailed)
// Keep going...
} else {
Expand Down Expand Up @@ -391,7 +391,7 @@ func (c *UDPConn) HandleInbound(data []byte, from net.Addr) {
select {
case c.readCh <- &inboundData{data: copied, from: from}:
default:
c.log.Warnf("receive buffer full")
c.log.Warnf("Receive buffer full")
}
}

Expand Down Expand Up @@ -435,7 +435,7 @@ func (c *UDPConn) bind(b *binding) error {
return fmt.Errorf("unexpected response type %s", res.Type) //nolint:goerr113
}

c.log.Debugf("channel binding successful: %s %d", b.addr.String(), b.number)
c.log.Debugf("Channel binding successful: %s %d", b.addr.String(), b.number)

// Success.
return nil
Expand Down
6 changes: 3 additions & 3 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type Request struct {

// HandleRequest processes the give Request
func HandleRequest(r Request) error {
r.Log.Debugf("received %d bytes of udp from %s on %s", len(r.Buff), r.SrcAddr.String(), r.Conn.LocalAddr().String())
r.Log.Debugf("Received %d bytes of udp from %s on %s", len(r.Buff), r.SrcAddr.String(), r.Conn.LocalAddr().String())

if proto.IsChannelData(r.Buff) {
return handleDataPacket(r)
Expand All @@ -46,7 +46,7 @@ func HandleRequest(r Request) error {
}

func handleDataPacket(r Request) error {
r.Log.Debugf("received DataPacket from %s", r.SrcAddr.String())
r.Log.Debugf("Received DataPacket from %s", r.SrcAddr.String())
c := proto.ChannelData{Raw: r.Buff}
if err := c.Decode(); err != nil {
return fmt.Errorf("%w: %v", errFailedToCreateChannelData, err) //nolint:errorlint
Expand All @@ -61,7 +61,7 @@ func handleDataPacket(r Request) error {
}

func handleTURNPacket(r Request) error {
r.Log.Debug("handleTURNPacket")
r.Log.Debug("Handling TURN packet")
m := &stun.Message{Raw: append([]byte{}, r.Buff...)}
if err := m.Decode(); err != nil {
return fmt.Errorf("%w: %v", errFailedToCreateSTUNPacket, err) //nolint:errorlint
Expand Down
2 changes: 1 addition & 1 deletion internal/server/stun.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func handleBindingRequest(r Request, m *stun.Message) error {
r.Log.Debugf("received BindingRequest from %s", r.SrcAddr.String())
r.Log.Debugf("Received BindingRequest from %s", r.SrcAddr.String())

ip, port, err := ipnet.AddrIPPort(r.SrcAddr)
if err != nil {
Expand Down
Loading

0 comments on commit 6e9e94a

Please sign in to comment.