Skip to content

Commit 4c00345

Browse files
committed
Remove pessimistic String calls for low level logs
1 parent c8be609 commit 4c00345

File tree

9 files changed

+26
-30
lines changed

9 files changed

+26
-30
lines changed

client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ func (c *Client) PerformTransaction(msg *stun.Message, to net.Addr, ignoreResult
425425

426426
c.trMap.Insert(trKey, tr)
427427

428-
c.log.Tracef("Start %s transaction %s to %s", msg.Type, trKey, tr.To.String())
428+
c.log.Tracef("Start %s transaction %s to %s", msg.Type, trKey, tr.To)
429429
_, err := c.conn.WriteTo(tr.Raw, to)
430430
if err != nil {
431431
return client.TransactionResult{}, err
@@ -524,7 +524,7 @@ func (c *Client) handleSTUNMessage(data []byte, from net.Addr) error {
524524
return err
525525
}
526526

527-
c.log.Tracef("Data indication received from %s", from.String())
527+
c.log.Tracef("Data indication received from %s", from)
528528

529529
relayedConn := c.relayedUDPConn()
530530
if relayedConn == nil {
@@ -548,7 +548,7 @@ func (c *Client) handleSTUNMessage(data []byte, from net.Addr) error {
548548
return err
549549
}
550550

551-
c.log.Debugf("Connection attempt from %s", addr.String())
551+
c.log.Debugf("Connection attempt from %s", addr)
552552

553553
allocation := c.getTCPAllocation()
554554
if allocation == nil {
@@ -575,7 +575,7 @@ func (c *Client) handleSTUNMessage(data []byte, from net.Addr) error {
575575
if !ok {
576576
c.mutexTrMap.Unlock()
577577
// Silently discard
578-
c.log.Debugf("No transaction for %s", msg.String())
578+
c.log.Debugf("No transaction for %s", msg)
579579
return nil
580580
}
581581

@@ -589,7 +589,7 @@ func (c *Client) handleSTUNMessage(data []byte, from net.Addr) error {
589589
From: from,
590590
Retries: tr.Retries(),
591591
}) {
592-
c.log.Debugf("No listener for %s", msg.String())
592+
c.log.Debugf("No listener for %s", msg)
593593
}
594594

595595
return nil

client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestClientWithSTUN(t *testing.T) {
6767

6868
resp, err := c.SendBindingRequest()
6969
assert.NoError(t, err, "should succeed")
70-
log.Debugf("mapped-addr: %s", resp.String())
70+
log.Debugf("mapped-addr: %s", resp)
7171
assert.Equal(t, 0, c.trMap.Size(), "should be no transaction left")
7272
assert.NoError(t, pc.Close())
7373
})

internal/allocation/allocation.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,9 @@ func (a *Allocation) packetHandler(m *Manager) {
244244
}
245245

246246
a.log.Debugf("Relay socket %s received %d bytes from %s",
247-
a.RelaySocket.LocalAddr().String(),
247+
a.RelaySocket.LocalAddr(),
248248
n,
249-
srcAddr.String())
249+
srcAddr)
250250

251251
if channel := a.GetChannelByAddr(srcAddr); channel != nil {
252252
channelData := &proto.ChannelData{
@@ -274,13 +274,13 @@ func (a *Allocation) packetHandler(m *Manager) {
274274
return
275275
}
276276
a.log.Debugf("Relaying message from %s to client at %s",
277-
srcAddr.String(),
278-
a.fiveTuple.SrcAddr.String())
277+
srcAddr,
278+
a.fiveTuple.SrcAddr)
279279
if _, err = a.TurnSocket.WriteTo(msg.Raw, a.fiveTuple.SrcAddr); err != nil {
280280
a.log.Errorf("Failed to send DataIndication from allocation %v %v", srcAddr, err)
281281
}
282282
} else {
283-
a.log.Infof("No Permission or Channel exists for %v on allocation %v", srcAddr, a.RelayAddr.String())
283+
a.log.Infof("No Permission or Channel exists for %v on allocation %v", srcAddr, a.RelayAddr)
284284
}
285285
}
286286
}

internal/allocation/allocation_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func (m *Manager) CreateAllocation(fiveTuple *FiveTuple, turnSocket net.PacketCo
113113
a.RelaySocket = conn
114114
a.RelayAddr = relayAddr
115115

116-
m.log.Debugf("Listening on relay address: %s", a.RelayAddr.String())
116+
m.log.Debugf("Listening on relay address: %s", a.RelayAddr)
117117

118118
a.lifetimeTimer = time.AfterFunc(lifetime, func() {
119119
m.DeleteAllocation(a.fiveTuple)

internal/client/udp_conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ func (c *UDPConn) bind(b *binding) error {
435435
return fmt.Errorf("unexpected response type %s", res.Type) //nolint:goerr113
436436
}
437437

438-
c.log.Debugf("Channel binding successful: %s %d", b.addr.String(), b.number)
438+
c.log.Debugf("Channel binding successful: %s %d", b.addr, b.number)
439439

440440
// Success.
441441
return nil

internal/server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type Request struct {
3535

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

4040
if proto.IsChannelData(r.Buff) {
4141
return handleDataPacket(r)

internal/server/stun.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

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

1414
ip, port, err := ipnet.AddrIPPort(r.SrcAddr)
1515
if err != nil {

internal/server/turn.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
// See: https://tools.ietf.org/html/rfc5766#section-6.2
1717
func handleAllocateRequest(r Request, m *stun.Message) error {
18-
r.Log.Debugf("Received AllocateRequest from %s", r.SrcAddr.String())
18+
r.Log.Debugf("Received AllocateRequest from %s", r.SrcAddr)
1919

2020
// 1. The server MUST require that the request be authenticated. This
2121
// authentication MUST be done using the long-term credential
@@ -177,7 +177,7 @@ func handleAllocateRequest(r Request, m *stun.Message) error {
177177
}
178178

179179
func handleRefreshRequest(r Request, m *stun.Message) error {
180-
r.Log.Debugf("Received RefreshRequest from %s", r.SrcAddr.String())
180+
r.Log.Debugf("Received RefreshRequest from %s", r.SrcAddr)
181181

182182
messageIntegrity, hasAuth, err := authenticateRequest(r, m, stun.MethodRefresh)
183183
if !hasAuth {
@@ -211,7 +211,7 @@ func handleRefreshRequest(r Request, m *stun.Message) error {
211211
}
212212

213213
func handleCreatePermissionRequest(r Request, m *stun.Message) error {
214-
r.Log.Debugf("Received CreatePermission from %s", r.SrcAddr.String())
214+
r.Log.Debugf("Received CreatePermission from %s", r.SrcAddr)
215215

216216
a := r.AllocationManager.GetAllocation(&allocation.FiveTuple{
217217
SrcAddr: r.SrcAddr,
@@ -236,13 +236,12 @@ func handleCreatePermissionRequest(r Request, m *stun.Message) error {
236236
}
237237

238238
if err := r.AllocationManager.GrantPermission(r.SrcAddr, peerAddress.IP); err != nil {
239-
r.Log.Infof("permission denied for client %s to peer %s", r.SrcAddr.String(),
240-
peerAddress.IP.String())
239+
r.Log.Infof("permission denied for client %s to peer %s", r.SrcAddr, peerAddress.IP)
241240
return err
242241
}
243242

244243
r.Log.Debugf("Adding permission for %s", fmt.Sprintf("%s:%d",
245-
peerAddress.IP.String(), peerAddress.Port))
244+
peerAddress.IP, peerAddress.Port))
246245

247246
a.AddPermission(allocation.NewPermission(
248247
&net.UDPAddr{
@@ -266,7 +265,7 @@ func handleCreatePermissionRequest(r Request, m *stun.Message) error {
266265
}
267266

268267
func handleSendIndication(r Request, m *stun.Message) error {
269-
r.Log.Debugf("Received SendIndication from %s", r.SrcAddr.String())
268+
r.Log.Debugf("Received SendIndication from %s", r.SrcAddr)
270269
a := r.AllocationManager.GetAllocation(&allocation.FiveTuple{
271270
SrcAddr: r.SrcAddr,
272271
DstAddr: r.Conn.LocalAddr(),
@@ -299,7 +298,7 @@ func handleSendIndication(r Request, m *stun.Message) error {
299298
}
300299

301300
func handleChannelBindRequest(r Request, m *stun.Message) error {
302-
r.Log.Debugf("Received ChannelBindRequest from %s", r.SrcAddr.String())
301+
r.Log.Debugf("Received ChannelBindRequest from %s", r.SrcAddr)
303302

304303
a := r.AllocationManager.GetAllocation(&allocation.FiveTuple{
305304
SrcAddr: r.SrcAddr,
@@ -328,18 +327,15 @@ func handleChannelBindRequest(r Request, m *stun.Message) error {
328327
}
329328

330329
if err = r.AllocationManager.GrantPermission(r.SrcAddr, peerAddr.IP); err != nil {
331-
r.Log.Infof("permission denied for client %s to peer %s", r.SrcAddr.String(),
332-
peerAddr.IP.String())
330+
r.Log.Infof("permission denied for client %s to peer %s", r.SrcAddr, peerAddr.IP)
333331

334332
unauthorizedRequestMsg := buildMsg(m.TransactionID,
335333
stun.NewType(stun.MethodChannelBind, stun.ClassErrorResponse),
336334
&stun.ErrorCodeAttribute{Code: stun.CodeUnauthorized})
337335
return buildAndSendErr(r.Conn, r.SrcAddr, err, unauthorizedRequestMsg...)
338336
}
339337

340-
r.Log.Debugf("Binding channel %d to %s",
341-
channel,
342-
fmt.Sprintf("%s:%d", peerAddr.IP.String(), peerAddr.Port))
338+
r.Log.Debugf("Binding channel %d to %s", channel, peerAddr)
343339
err = a.AddChannelBind(allocation.NewChannelBind(
344340
channel,
345341
&net.UDPAddr{IP: peerAddr.IP, Port: peerAddr.Port},
@@ -353,7 +349,7 @@ func handleChannelBindRequest(r Request, m *stun.Message) error {
353349
}
354350

355351
func handleChannelData(r Request, c *proto.ChannelData) error {
356-
r.Log.Debugf("Received ChannelData from %s", r.SrcAddr.String())
352+
r.Log.Debugf("Received ChannelData from %s", r.SrcAddr)
357353

358354
a := r.AllocationManager.GetAllocation(&allocation.FiveTuple{
359355
SrcAddr: r.SrcAddr,

server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ func TestServerVNet(t *testing.T) {
447447
log.Debug("sending a binding request.")
448448
reflAddr, err := client.SendBindingRequest()
449449
assert.NoError(t, err)
450-
log.Debugf("mapped-address: %v", reflAddr.String())
450+
log.Debugf("mapped-address: %s", reflAddr)
451451
udpAddr, ok := reflAddr.(*net.UDPAddr)
452452
assert.True(t, ok)
453453

0 commit comments

Comments
 (0)