forked from quic-go/quic-go
add some debug logging for the proxy
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lucas-clemente/quic-go/internal/protocol"
|
"github.com/lucas-clemente/quic-go/internal/protocol"
|
||||||
|
"github.com/lucas-clemente/quic-go/internal/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Connection is a UDP connection
|
// Connection is a UDP connection
|
||||||
@@ -131,6 +132,7 @@ func NewQuicProxy(local string, version protocol.VersionNumber, opts *Opts) (*Qu
|
|||||||
version: version,
|
version: version,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
utils.Debugf("Starting UDP Proxy %s <-> %s", conn.LocalAddr(), raddr)
|
||||||
go p.runProxy()
|
go p.runProxy()
|
||||||
return &p, nil
|
return &p, nil
|
||||||
}
|
}
|
||||||
@@ -189,19 +191,27 @@ func (p *QuicProxy) runProxy() error {
|
|||||||
packetCount := atomic.AddUint64(&conn.incomingPacketCounter, 1)
|
packetCount := atomic.AddUint64(&conn.incomingPacketCounter, 1)
|
||||||
|
|
||||||
if p.dropPacket(DirectionIncoming, packetCount) {
|
if p.dropPacket(DirectionIncoming, packetCount) {
|
||||||
|
if utils.Debug() {
|
||||||
|
utils.Debugf("dropping incoming packet %d (%d bytes)", packetCount, n)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the packet to the server
|
// Send the packet to the server
|
||||||
delay := p.delayPacket(DirectionIncoming, packetCount)
|
delay := p.delayPacket(DirectionIncoming, packetCount)
|
||||||
if delay != 0 {
|
if delay != 0 {
|
||||||
|
if utils.Debug() {
|
||||||
|
utils.Debugf("delaying incoming packet %d (%d bytes) to %s by %s", packetCount, n, conn.ServerConn.RemoteAddr(), delay)
|
||||||
|
}
|
||||||
time.AfterFunc(delay, func() {
|
time.AfterFunc(delay, func() {
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
_, _ = conn.ServerConn.Write(raw)
|
_, _ = conn.ServerConn.Write(raw)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
_, err := conn.ServerConn.Write(raw)
|
if utils.Debug() {
|
||||||
if err != nil {
|
utils.Debugf("forwarding incoming packet %d (%d bytes) to %s", packetCount, n, conn.ServerConn.RemoteAddr())
|
||||||
|
}
|
||||||
|
if _, err := conn.ServerConn.Write(raw); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -221,18 +231,27 @@ func (p *QuicProxy) runConnection(conn *connection) error {
|
|||||||
packetCount := atomic.AddUint64(&conn.outgoingPacketCounter, 1)
|
packetCount := atomic.AddUint64(&conn.outgoingPacketCounter, 1)
|
||||||
|
|
||||||
if p.dropPacket(DirectionOutgoing, packetCount) {
|
if p.dropPacket(DirectionOutgoing, packetCount) {
|
||||||
|
if utils.Debug() {
|
||||||
|
utils.Debugf("dropping outgoing packet %d (%d bytes)", packetCount, n)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
utils.Debugf("forwarding outgoing packet %d (%d bytes) to %s", packetCount, n, conn.ClientAddr)
|
||||||
|
|
||||||
delay := p.delayPacket(DirectionOutgoing, packetCount)
|
delay := p.delayPacket(DirectionOutgoing, packetCount)
|
||||||
if delay != 0 {
|
if delay != 0 {
|
||||||
|
if utils.Debug() {
|
||||||
|
utils.Debugf("delaying outgoing packet %d (%d bytes) to %s by %s", packetCount, n, conn.ClientAddr, delay)
|
||||||
|
}
|
||||||
time.AfterFunc(delay, func() {
|
time.AfterFunc(delay, func() {
|
||||||
// TODO: handle error
|
// TODO: handle error
|
||||||
_, _ = p.conn.WriteToUDP(raw, conn.ClientAddr)
|
_, _ = p.conn.WriteToUDP(raw, conn.ClientAddr)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
_, err := p.conn.WriteToUDP(raw, conn.ClientAddr)
|
if utils.Debug() {
|
||||||
if err != nil {
|
utils.Debugf("forwarding outgoing packet %d (%d bytes) to %s", packetCount, n, conn.ClientAddr)
|
||||||
|
}
|
||||||
|
if _, err := p.conn.WriteToUDP(raw, conn.ClientAddr); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user