diff --git a/transport/layer.go b/transport/layer.go index 1078eda..bcd0d78 100644 --- a/transport/layer.go +++ b/transport/layer.go @@ -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 } } diff --git a/transport/tcp.go b/transport/tcp.go index 0258cb4..e13adff 100644 --- a/transport/tcp.go +++ b/transport/tcp.go @@ -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) } diff --git a/transport/udp.go b/transport/udp.go index f017f9e..6803ca9 100644 --- a/transport/udp.go +++ b/transport/udp.go @@ -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 @@ -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