TUN-6308: Add debug logs to see if packets are sent/received from edge

This commit is contained in:
cthuang 2022-05-30 13:38:15 +01:00
parent 08a8101308
commit baed5f4eea
4 changed files with 26 additions and 15 deletions

View File

@ -58,7 +58,7 @@ func NewQUICConnection(
return nil, fmt.Errorf("failed to dial to edge: %w", err)
}
datagramMuxer, err := quicpogs.NewDatagramMuxer(session)
datagramMuxer, err := quicpogs.NewDatagramMuxer(session, logger)
if err != nil {
return nil, err
}
@ -217,7 +217,7 @@ func (q *QUICConnection) RegisterUdpSession(ctx context.Context, sessionID uuid.
go q.serveUDPSession(session, closeAfterIdleHint)
q.logger.Debug().Msgf("Registered session %v, %v, %v", sessionID, dstIP, dstPort)
q.logger.Debug().Str("sessionID", sessionID.String()).Str("src", originProxy.LocalAddr().String()).Str("dst", fmt.Sprintf("%s:%d", dstIP, dstPort)).Msgf("Registered session")
return nil
}

View File

@ -6,11 +6,16 @@ import (
"net"
)
type UDPProxy struct {
type UDPProxy interface {
io.ReadWriteCloser
LocalAddr() net.Addr
}
func DialUDP(dstIP net.IP, dstPort uint16) (*UDPProxy, error) {
type udpProxy struct {
*net.UDPConn
}
func DialUDP(dstIP net.IP, dstPort uint16) (UDPProxy, error) {
dstAddr := &net.UDPAddr{
IP: dstIP,
Port: int(dstPort),
@ -23,5 +28,5 @@ func DialUDP(dstIP net.IP, dstPort uint16) (*UDPProxy, error) {
return nil, fmt.Errorf("unable to create UDP proxy to origin (%v:%v): %w", dstIP, dstPort, err)
}
return &UDPProxy{udpConn}, nil
return &udpProxy{udpConn}, nil
}

View File

@ -6,6 +6,7 @@ import (
"github.com/google/uuid"
"github.com/lucas-clemente/quic-go"
"github.com/pkg/errors"
"github.com/rs/zerolog"
)
const (
@ -13,18 +14,14 @@ const (
)
type DatagramMuxer struct {
ID uuid.UUID
session quic.Session
logger *zerolog.Logger
}
func NewDatagramMuxer(quicSession quic.Session) (*DatagramMuxer, error) {
muxerID, err := uuid.NewRandom()
if err != nil {
return nil, err
}
func NewDatagramMuxer(quicSession quic.Session, logger *zerolog.Logger) (*DatagramMuxer, error) {
return &DatagramMuxer{
ID: muxerID,
session: quicSession,
logger: logger,
}, nil
}
@ -42,6 +39,7 @@ func (dm *DatagramMuxer) SendTo(sessionID uuid.UUID, payload []byte) error {
if err := dm.session.SendMessage(msgWithID); err != nil {
return errors.Wrap(err, "Failed to send datagram back to edge")
}
dm.logger.Debug().Str("sessionID", sessionID.String()).Int("bytes", len(payload)).Msg("Send datagram back to edge")
return nil
}
@ -53,7 +51,12 @@ func (dm *DatagramMuxer) ReceiveFrom() (uuid.UUID, []byte, error) {
if err != nil {
return uuid.Nil, nil, err
}
return extractSessionID(msg)
sessionID, payload, err := extractSessionID(msg)
if err != nil {
return uuid.Nil, nil, err
}
dm.logger.Debug().Str("sessionID", sessionID.String()).Int("bytes", len(payload)).Msg("Received datagram from edge")
return sessionID, payload, nil
}
// Maximum application payload to send to / receive from QUIC datagram frame

View File

@ -14,6 +14,7 @@ import (
"github.com/google/uuid"
"github.com/lucas-clemente/quic-go"
"github.com/rs/zerolog"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
)
@ -71,7 +72,8 @@ func TestMaxDatagramPayload(t *testing.T) {
return err
}
muxer, err := NewDatagramMuxer(quicSession)
logger := zerolog.Nop()
muxer, err := NewDatagramMuxer(quicSession, &logger)
if err != nil {
return err
}
@ -96,7 +98,8 @@ func TestMaxDatagramPayload(t *testing.T) {
quicSession, err := quic.DialAddrEarly(quicListener.Addr().String(), tlsClientConfig, quicConfig)
require.NoError(t, err)
muxer, err := NewDatagramMuxer(quicSession)
logger := zerolog.Nop()
muxer, err := NewDatagramMuxer(quicSession, &logger)
if err != nil {
return err
}