Skip to content

Commit

Permalink
fix: addr can be nill for UDP debug
Browse files Browse the repository at this point in the history
  • Loading branch information
emiago committed Oct 16, 2023
1 parent 0a8342d commit 98e2e48
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions transport/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,10 @@ func (l *Layer) Close() error {

func IsReliable(network string) bool {
switch network {
case "tcp", "tls", "ws", "wss", "TCP", "TLS", "WS", "WSS":
return true
default:
case "udp", "UDP":
return false
default:
return true
}
}

Expand Down
2 changes: 1 addition & 1 deletion transport/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (t *TCPTransport) createConnection(ctx context.Context, laddr *net.TCPAddr,
d := net.Dialer{
LocalAddr: laddr,
}
conn, err := d.DialContext(ctx, "tcp", raddr.String())
conn, err := d.DialContext(ctx, "tcp", addr)
if err != nil {
return nil, fmt.Errorf("%s dial err=%w", t, err)
}
Expand Down
6 changes: 4 additions & 2 deletions transport/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ func (c *UDPConnection) Write(b []byte) (n int, err error) {
func (c *UDPConnection) ReadFrom(b []byte) (n int, addr net.Addr, err error) {
// Some debug hook. TODO move to proper way
n, addr, err = c.PacketConn.ReadFrom(b)
if SIPDebug {
if SIPDebug && err == nil {
// addr is nil on error
log.Debug().Msgf("UDP read from %s <- %s:\n%s", c.PacketConn.LocalAddr().String(), addr.String(), string(b[:n]))
}
return n, addr, err
Expand All @@ -347,7 +348,8 @@ func (c *UDPConnection) ReadFrom(b []byte) (n int, addr net.Addr, err error) {
func (c *UDPConnection) WriteTo(b []byte, addr net.Addr) (n int, err error) {
// Some debug hook. TODO move to proper way
n, err = c.PacketConn.WriteTo(b, addr)
if SIPDebug {
if SIPDebug && err == nil {
// addr is nil on error
log.Debug().Msgf("UDP write to %s -> %s:\n%s", c.PacketConn.LocalAddr().String(), addr.String(), string(b[:n]))
}
return n, err
Expand Down

0 comments on commit 98e2e48

Please sign in to comment.