diff --git a/integrationtests/self/close_test.go b/integrationtests/self/close_test.go index 292a1563..8f06723b 100644 --- a/integrationtests/self/close_test.go +++ b/integrationtests/self/close_test.go @@ -30,10 +30,10 @@ func TestConnectionCloseRetransmission(t *testing.T) { proxy := &quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: server.Addr().(*net.UDPAddr), - DelayPacket: func(_ quicproxy.Direction, _ []byte) time.Duration { + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return 5 * time.Millisecond // 10ms RTT }, - DropPacket: func(dir quicproxy.Direction, b []byte) bool { + DropPacket: func(dir quicproxy.Direction, _, _ net.Addr, b []byte) bool { if drop := drop.Load(); drop && dir == quicproxy.DirectionOutgoing { dropped <- b return true diff --git a/integrationtests/self/datagram_test.go b/integrationtests/self/datagram_test.go index 11ae654d..5c2cdd12 100644 --- a/integrationtests/self/datagram_test.go +++ b/integrationtests/self/datagram_test.go @@ -140,7 +140,7 @@ func TestDatagramLoss(t *testing.T) { proxy := &quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: server.Addr().(*net.UDPAddr), - DropPacket: func(dir quicproxy.Direction, packet []byte) bool { + DropPacket: func(dir quicproxy.Direction, _, _ net.Addr, packet []byte) bool { if wire.IsLongHeaderPacket(packet[0]) { // don't drop Long Header packets return false } @@ -159,7 +159,7 @@ func TestDatagramLoss(t *testing.T) { } return false }, - DelayPacket: func(_ quicproxy.Direction, _ []byte) time.Duration { return rtt / 2 }, + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return rtt / 2 }, } require.NoError(t, proxy.Start()) defer proxy.Close() diff --git a/integrationtests/self/drop_test.go b/integrationtests/self/drop_test.go index d4e58273..f7336d74 100644 --- a/integrationtests/self/drop_test.go +++ b/integrationtests/self/drop_test.go @@ -36,8 +36,8 @@ func TestDropTests(t *testing.T) { proxy := &quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: ln.Addr().(*net.UDPAddr), - DelayPacket: func(quicproxy.Direction, []byte) time.Duration { return rtt / 2 }, - DropPacket: func(d quicproxy.Direction, b []byte) bool { + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return rtt / 2 }, + DropPacket: func(d quicproxy.Direction, _, _ net.Addr, b []byte) bool { if !d.Is(direction) { return false } diff --git a/integrationtests/self/early_data_test.go b/integrationtests/self/early_data_test.go index 9e30409f..3611bf45 100644 --- a/integrationtests/self/early_data_test.go +++ b/integrationtests/self/early_data_test.go @@ -22,7 +22,7 @@ func TestEarlyData(t *testing.T) { proxy := &quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: ln.Addr().(*net.UDPAddr), - DelayPacket: func(quicproxy.Direction, []byte) time.Duration { return rtt / 2 }, + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return rtt / 2 }, } require.NoError(t, proxy.Start()) defer proxy.Close() diff --git a/integrationtests/self/handshake_drop_test.go b/integrationtests/self/handshake_drop_test.go index bf7feb76..962c62ce 100644 --- a/integrationtests/self/handshake_drop_test.go +++ b/integrationtests/self/handshake_drop_test.go @@ -47,7 +47,7 @@ func startDropTestListenerAndProxy(t *testing.T, rtt, timeout time.Duration, dro Conn: newUPDConnLocalhost(t), ServerAddr: ln.Addr().(*net.UDPAddr), DropPacket: dropCallback, - DelayPacket: func(quicproxy.Direction, []byte) time.Duration { return rtt / 2 }, + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return rtt / 2 }, } require.NoError(t, proxy.Start()) t.Cleanup(func() { proxy.Close() }) @@ -172,7 +172,7 @@ func dropTestProtocolNobodySpeaks(t *testing.T, ln *quic.Listener, addr net.Addr func dropCallbackDropNthPacket(direction quicproxy.Direction, n int) quicproxy.DropCallback { var incoming, outgoing atomic.Int32 - return func(d quicproxy.Direction, packet []byte) bool { + return func(d quicproxy.Direction, _, _ net.Addr, packet []byte) bool { var p int32 switch d { case quicproxy.DirectionIncoming: @@ -188,7 +188,7 @@ func dropCallbackDropOneThird(direction quicproxy.Direction) quicproxy.DropCallb const maxSequentiallyDropped = 10 var mx sync.Mutex var incoming, outgoing int - return func(d quicproxy.Direction, _ []byte) bool { + return func(d quicproxy.Direction, _, _ net.Addr, _ []byte) bool { drop := mrand.Int63n(int64(3)) == 0 mx.Lock() diff --git a/integrationtests/self/handshake_rtt_test.go b/integrationtests/self/handshake_rtt_test.go index 992a19c6..20186ecd 100644 --- a/integrationtests/self/handshake_rtt_test.go +++ b/integrationtests/self/handshake_rtt_test.go @@ -20,7 +20,7 @@ func handshakeWithRTT(t *testing.T, serverAddr net.Addr, tlsConf *tls.Config, qu proxy := quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: serverAddr.(*net.UDPAddr), - DelayPacket: func(quicproxy.Direction, []byte) time.Duration { return rtt / 2 }, + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return rtt / 2 }, } require.NoError(t, proxy.Start()) t.Cleanup(func() { proxy.Close() }) diff --git a/integrationtests/self/handshake_test.go b/integrationtests/self/handshake_test.go index 3bb81ef8..6b307e47 100644 --- a/integrationtests/self/handshake_test.go +++ b/integrationtests/self/handshake_test.go @@ -362,7 +362,7 @@ func TestHandshakingConnectionsClosedOnServerShutdown(t *testing.T) { proxy := quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: ln.Addr().(*net.UDPAddr), - DelayPacket: func(quicproxy.Direction, []byte) time.Duration { return rtt / 2 }, + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return rtt / 2 }, } require.NoError(t, proxy.Start()) defer proxy.Close() @@ -553,7 +553,7 @@ func TestInvalidToken(t *testing.T) { proxy := quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: server.Addr().(*net.UDPAddr), - DelayPacket: func(quicproxy.Direction, []byte) time.Duration { return rtt / 2 }, + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return rtt / 2 }, } require.NoError(t, proxy.Start()) defer proxy.Close() diff --git a/integrationtests/self/http_test.go b/integrationtests/self/http_test.go index bf4a0bd5..808acb06 100644 --- a/integrationtests/self/http_test.go +++ b/integrationtests/self/http_test.go @@ -851,7 +851,7 @@ func TestHTTP0RTT(t *testing.T) { proxy := quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: port}, - DelayPacket: func(_ quicproxy.Direction, data []byte) time.Duration { + DelayPacket: func(_ quicproxy.Direction, _, _ net.Addr, data []byte) time.Duration { if contains0RTTPacket(data) { num0RTTPackets.Add(1) } diff --git a/integrationtests/self/mitm_test.go b/integrationtests/self/mitm_test.go index bca522a2..46f9c0d0 100644 --- a/integrationtests/self/mitm_test.go +++ b/integrationtests/self/mitm_test.go @@ -121,7 +121,7 @@ func testMITMInjectRandomPackets(t *testing.T, direction quicproxy.Direction) { rtt := scaleDuration(10 * time.Millisecond) serverTransport, clientTransport := getTransportsForMITMTest(t) - dropCallback := func(dir quicproxy.Direction, b []byte) bool { + dropCallback := func(dir quicproxy.Direction, _, _ net.Addr, b []byte) bool { if dir != direction { return false } @@ -148,7 +148,7 @@ func testMITMDuplicatePackets(t *testing.T, direction quicproxy.Direction) { serverTransport, clientTransport := getTransportsForMITMTest(t) rtt := scaleDuration(10 * time.Millisecond) - dropCallback := func(dir quicproxy.Direction, b []byte) bool { + dropCallback := func(dir quicproxy.Direction, _, _ net.Addr, b []byte) bool { if dir != direction { return false } @@ -169,7 +169,7 @@ func testMITMCorruptPackets(t *testing.T, direction quicproxy.Direction) { rtt := scaleDuration(5 * time.Millisecond) var numCorrupted atomic.Int32 - dropCallback := func(dir quicproxy.Direction, b []byte) bool { + dropCallback := func(dir quicproxy.Direction, _, _ net.Addr, b []byte) bool { if dir != direction { return false } @@ -206,7 +206,7 @@ func runMITMTest(t *testing.T, serverTr, clientTr *quic.Transport, rtt time.Dura proxy := quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: ln.Addr().(*net.UDPAddr), - DelayPacket: func(_ quicproxy.Direction, b []byte) time.Duration { return rtt / 2 }, + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return rtt / 2 }, DropPacket: dropCb, } require.NoError(t, proxy.Start()) @@ -269,7 +269,7 @@ func TestMITMForgedVersionNegotiationPacket(t *testing.T) { const supportedVersion protocol.Version = 42 var once sync.Once - delayCb := func(dir quicproxy.Direction, raw []byte) time.Duration { + delayCb := func(dir quicproxy.Direction, _, _ net.Addr, raw []byte) time.Duration { if dir != quicproxy.DirectionIncoming { return rtt / 2 } @@ -306,7 +306,7 @@ func TestMITMForgedRetryPacket(t *testing.T) { rtt := scaleDuration(10 * time.Millisecond) var once sync.Once - delayCb := func(dir quicproxy.Direction, raw []byte) time.Duration { + delayCb := func(dir quicproxy.Direction, _, _ net.Addr, raw []byte) time.Duration { hdr, _, _, err := wire.ParsePacket(raw) if err != nil { panic("failed to parse packet: " + err.Error()) @@ -333,7 +333,7 @@ func TestMITMForgedInitialPacket(t *testing.T) { rtt := scaleDuration(10 * time.Millisecond) var once sync.Once - delayCb := func(dir quicproxy.Direction, raw []byte) time.Duration { + delayCb := func(dir quicproxy.Direction, _, _ net.Addr, raw []byte) time.Duration { if dir == quicproxy.DirectionIncoming { hdr, _, _, err := wire.ParsePacket(raw) if err != nil { @@ -370,7 +370,7 @@ func TestMITMForgedInitialPacketWithAck(t *testing.T) { rtt := scaleDuration(10 * time.Millisecond) var once sync.Once - delayCb := func(dir quicproxy.Direction, raw []byte) time.Duration { + delayCb := func(dir quicproxy.Direction, _, _ net.Addr, raw []byte) time.Duration { if dir == quicproxy.DirectionIncoming { hdr, _, _, err := wire.ParsePacket(raw) if err != nil { diff --git a/integrationtests/self/mtu_test.go b/integrationtests/self/mtu_test.go index fb45ea49..be72fd58 100644 --- a/integrationtests/self/mtu_test.go +++ b/integrationtests/self/mtu_test.go @@ -82,8 +82,8 @@ func TestPathMTUDiscovery(t *testing.T) { proxy := &quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: ln.Addr().(*net.UDPAddr), - DelayPacket: func(_ quicproxy.Direction, _ []byte) time.Duration { return rtt / 2 }, - DropPacket: func(dir quicproxy.Direction, packet []byte) bool { + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return rtt / 2 }, + DropPacket: func(dir quicproxy.Direction, _, _ net.Addr, packet []byte) bool { if len(packet) > mtu { return true } diff --git a/integrationtests/self/nat_rebinding_test.go b/integrationtests/self/nat_rebinding_test.go index 342c07ac..bcd7acde 100644 --- a/integrationtests/self/nat_rebinding_test.go +++ b/integrationtests/self/nat_rebinding_test.go @@ -44,7 +44,7 @@ func TestNATRebinding(t *testing.T) { var mx sync.Mutex var switchedPath bool var dataTransferred int - proxy.DelayPacket = func(dir quicproxy.Direction, b []byte) time.Duration { + proxy.DelayPacket = func(dir quicproxy.Direction, _, _ net.Addr, b []byte) time.Duration { mx.Lock() defer mx.Unlock() diff --git a/integrationtests/self/packetization_test.go b/integrationtests/self/packetization_test.go index 86a30f59..c76214e7 100644 --- a/integrationtests/self/packetization_test.go +++ b/integrationtests/self/packetization_test.go @@ -37,7 +37,7 @@ func TestACKBundling(t *testing.T) { proxy := quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: server.Addr().(*net.UDPAddr), - DelayPacket: func(_ quicproxy.Direction, _ []byte) time.Duration { + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return 5 * time.Millisecond }, } @@ -166,7 +166,7 @@ func testConnAndStreamDataBlocked(t *testing.T, limitStream, limitConn bool) { proxy := quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: ln.Addr().(*net.UDPAddr), - DelayPacket: func(_ quicproxy.Direction, _ []byte) time.Duration { + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return rtt / 2 }, } diff --git a/integrationtests/self/rtt_test.go b/integrationtests/self/rtt_test.go index 64c95848..b9aec524 100644 --- a/integrationtests/self/rtt_test.go +++ b/integrationtests/self/rtt_test.go @@ -68,7 +68,7 @@ func TestDownloadWithFixedRTT(t *testing.T) { proxy := quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: addr.(*net.UDPAddr).Port}, - DelayPacket: func(_ quicproxy.Direction, _ []byte) time.Duration { return rtt / 2 }, + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return rtt / 2 }, } require.NoError(t, proxy.Start()) t.Cleanup(func() { proxy.Close() }) @@ -113,7 +113,7 @@ func TestDownloadWithReordering(t *testing.T) { proxy := quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: addr.(*net.UDPAddr).Port}, - DelayPacket: func(_ quicproxy.Direction, _ []byte) time.Duration { + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return randomDuration(rtt/2, rtt*3/2) / 2 }, } diff --git a/integrationtests/self/stateless_reset_test.go b/integrationtests/self/stateless_reset_test.go index ce573063..ba45565c 100644 --- a/integrationtests/self/stateless_reset_test.go +++ b/integrationtests/self/stateless_reset_test.go @@ -60,7 +60,7 @@ func testStatelessReset(t *testing.T, connIDLen int) { proxy := quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: ln.Addr().(*net.UDPAddr), - DropPacket: func(quicproxy.Direction, []byte) bool { return drop.Load() }, + DropPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) bool { return drop.Load() }, } require.NoError(t, proxy.Start()) defer proxy.Close() diff --git a/integrationtests/self/timeout_test.go b/integrationtests/self/timeout_test.go index 6f83f6df..9aaa5e6a 100644 --- a/integrationtests/self/timeout_test.go +++ b/integrationtests/self/timeout_test.go @@ -114,7 +114,7 @@ func TestIdleTimeout(t *testing.T) { proxy := quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: server.Addr().(*net.UDPAddr), - DropPacket: func(_ quicproxy.Direction, _ []byte) bool { return drop.Load() }, + DropPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) bool { return drop.Load() }, } require.NoError(t, proxy.Start()) defer proxy.Close() @@ -181,7 +181,7 @@ func TestKeepAlive(t *testing.T) { proxy := quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: server.Addr().(*net.UDPAddr), - DropPacket: func(_ quicproxy.Direction, _ []byte) bool { return drop.Load() }, + DropPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) bool { return drop.Load() }, } require.NoError(t, proxy.Start()) defer proxy.Close() @@ -323,7 +323,7 @@ func TestTimeoutAfterSendingPacket(t *testing.T) { proxy := quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: server.Addr().(*net.UDPAddr), - DropPacket: func(_ quicproxy.Direction, _ []byte) bool { return drop.Load() }, + DropPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) bool { return drop.Load() }, } require.NoError(t, proxy.Start()) defer proxy.Close() diff --git a/integrationtests/self/zero_rtt_test.go b/integrationtests/self/zero_rtt_test.go index 220cad9e..cfff31ca 100644 --- a/integrationtests/self/zero_rtt_test.go +++ b/integrationtests/self/zero_rtt_test.go @@ -27,7 +27,7 @@ func runCountingProxyAndCount0RTTPackets(t *testing.T, serverPort int, rtt time. proxy := &quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: &net.UDPAddr{IP: net.IPv4(127, 0, 0, 1), Port: serverPort}, - DelayPacket: func(_ quicproxy.Direction, data []byte) time.Duration { + DelayPacket: func(_ quicproxy.Direction, _, _ net.Addr, data []byte) time.Duration { if contains0RTTPacket(data) { num0RTTPackets.Add(1) } @@ -55,7 +55,7 @@ func dialAndReceiveTicket( proxy := &quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: ln.Addr().(*net.UDPAddr), - DelayPacket: func(_ quicproxy.Direction, _ []byte) time.Duration { return rtt / 2 }, + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return rtt / 2 }, } require.NoError(t, proxy.Start()) defer proxy.Close() @@ -366,8 +366,8 @@ func Test0RTTDataLoss(t *testing.T) { proxy := quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: ln.Addr().(*net.UDPAddr), - DelayPacket: func(_ quicproxy.Direction, data []byte) time.Duration { return rtt / 2 }, - DropPacket: func(_ quicproxy.Direction, data []byte) bool { + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return rtt / 2 }, + DropPacket: func(_ quicproxy.Direction, _, _ net.Addr, data []byte) bool { if !wire.IsLongHeaderPacket(data[0]) { return false } @@ -436,7 +436,7 @@ func Test0RTTRetransmitOnRetry(t *testing.T) { proxy := quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: ln.Addr().(*net.UDPAddr), - DelayPacket: func(dir quicproxy.Direction, data []byte) time.Duration { + DelayPacket: func(dir quicproxy.Direction, _, _ net.Addr, data []byte) time.Duration { connID, err := wire.ParseConnectionID(data, 0) if err != nil { panic("failed to parse connection ID") @@ -912,7 +912,7 @@ func Test0RTTPacketQueueing(t *testing.T) { proxy := quicproxy.Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: ln.Addr().(*net.UDPAddr), - DelayPacket: func(dir quicproxy.Direction, data []byte) time.Duration { + DelayPacket: func(dir quicproxy.Direction, _, _ net.Addr, data []byte) time.Duration { // delay the client's Initial by 1 RTT if dir == quicproxy.DirectionIncoming && wire.IsLongHeaderPacket(data[0]) && data[0]&0x30>>4 == 0 { return rtt * 3 / 2 diff --git a/integrationtests/tools/proxy/proxy.go b/integrationtests/tools/proxy/proxy.go index 86e71fa5..be3176e3 100644 --- a/integrationtests/tools/proxy/proxy.go +++ b/integrationtests/tools/proxy/proxy.go @@ -139,10 +139,10 @@ func (d Direction) Is(dir Direction) bool { } // DropCallback is a callback that determines which packet gets dropped. -type DropCallback func(dir Direction, packet []byte) bool +type DropCallback func(dir Direction, from, to net.Addr, packet []byte) bool // DelayCallback is a callback that determines how much delay to apply to a packet. -type DelayCallback func(dir Direction, packet []byte) time.Duration +type DelayCallback func(dir Direction, from, to net.Addr, packet []byte) time.Duration // Proxy is a QUIC proxy that can drop and delay packets. type Proxy struct { @@ -267,7 +267,7 @@ func (p *Proxy) runProxy() error { } p.mutex.Unlock() - if p.DropPacket != nil && p.DropPacket(DirectionIncoming, raw) { + if p.DropPacket != nil && p.DropPacket(DirectionIncoming, cliaddr, conn.ServerAddr, raw) { if p.logger.Debug() { p.logger.Debugf("dropping incoming packet(%d bytes)", n) } @@ -276,7 +276,7 @@ func (p *Proxy) runProxy() error { var delay time.Duration if p.DelayPacket != nil { - delay = p.DelayPacket(DirectionIncoming, raw) + delay = p.DelayPacket(DirectionIncoming, cliaddr, conn.ServerAddr, raw) } if delay == 0 { if p.logger.Debug() { @@ -301,7 +301,7 @@ func (p *Proxy) runOutgoingConnection(conn *connection) error { go func() { for { buffer := make([]byte, protocol.MaxPacketBufferSize) - n, err := conn.GetServerConn().Read(buffer) + n, addr, err := conn.GetServerConn().ReadFrom(buffer) if err != nil { // when the connection is switched out, we set a deadline on the old connection, // in order to return it immediately @@ -312,7 +312,7 @@ func (p *Proxy) runOutgoingConnection(conn *connection) error { } raw := buffer[0:n] - if p.DropPacket != nil && p.DropPacket(DirectionOutgoing, raw) { + if p.DropPacket != nil && p.DropPacket(DirectionOutgoing, addr, conn.ClientAddr, raw) { if p.logger.Debug() { p.logger.Debugf("dropping outgoing packet(%d bytes)", n) } @@ -321,7 +321,7 @@ func (p *Proxy) runOutgoingConnection(conn *connection) error { var delay time.Duration if p.DelayPacket != nil { - delay = p.DelayPacket(DirectionOutgoing, raw) + delay = p.DelayPacket(DirectionOutgoing, addr, conn.ClientAddr, raw) } if delay == 0 { if p.logger.Debug() { diff --git a/integrationtests/tools/proxy/proxy_test.go b/integrationtests/tools/proxy/proxy_test.go index d2e15e17..b53a214b 100644 --- a/integrationtests/tools/proxy/proxy_test.go +++ b/integrationtests/tools/proxy/proxy_test.go @@ -142,13 +142,16 @@ func TestDropIncomingPackets(t *testing.T) { const numPackets = 6 serverAddr, serverReceivedPackets := runServer(t) var counter atomic.Int32 + var fromAddr, toAddr atomic.Pointer[net.Addr] proxy := Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: serverAddr, - DropPacket: func(d Direction, _ []byte) bool { + DropPacket: func(d Direction, from, to net.Addr, _ []byte) bool { if d != DirectionIncoming { return false } + fromAddr.Store(&from) + toAddr.Store(&to) return counter.Add(1)%2 == 1 }, } @@ -174,19 +177,25 @@ func TestDropIncomingPackets(t *testing.T) { t.Fatalf("received unexpected packet") case <-time.After(100 * time.Millisecond): } + + require.Equal(t, *fromAddr.Load(), clientConn.LocalAddr()) + require.Equal(t, *toAddr.Load(), serverAddr) } func TestDropOutgoingPackets(t *testing.T) { const numPackets = 6 serverAddr, serverReceivedPackets := runServer(t) var counter atomic.Int32 + var fromAddr, toAddr atomic.Pointer[net.Addr] proxy := Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: serverAddr, - DropPacket: func(d Direction, _ []byte) bool { + DropPacket: func(d Direction, from, to net.Addr, _ []byte) bool { if d != DirectionOutgoing { return false } + fromAddr.Store(&from) + toAddr.Store(&to) return counter.Add(1)%2 == 1 }, } @@ -225,6 +234,9 @@ func TestDropOutgoingPackets(t *testing.T) { case <-time.After(100 * time.Millisecond): } require.Len(t, serverReceivedPackets, numPackets) + + require.Equal(t, *fromAddr.Load(), serverAddr) + require.Equal(t, *toAddr.Load(), clientConn.LocalAddr()) } func TestDelayIncomingPackets(t *testing.T) { @@ -235,7 +247,7 @@ func TestDelayIncomingPackets(t *testing.T) { proxy := Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: serverAddr, - DelayPacket: func(d Direction, _ []byte) time.Duration { + DelayPacket: func(d Direction, _, _ net.Addr, _ []byte) time.Duration { // delay packet 1 by 200 ms // delay packet 2 by 400 ms // ... @@ -282,7 +294,7 @@ func TestPacketReordering(t *testing.T) { proxy := Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: serverAddr, - DelayPacket: func(d Direction, _ []byte) time.Duration { + DelayPacket: func(d Direction, _, _ net.Addr, _ []byte) time.Duration { // delay packet 1 by 600 ms // delay packet 2 by 400 ms // delay packet 3 by 200 ms @@ -321,7 +333,7 @@ func TestConstantDelay(t *testing.T) { // no reordering expected here proxy := Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: serverAddr, - DelayPacket: func(d Direction, _ []byte) time.Duration { + DelayPacket: func(d Direction, _, _ net.Addr, _ []byte) time.Duration { if d == DirectionOutgoing { return 0 } @@ -359,7 +371,7 @@ func TestDelayOutgoingPackets(t *testing.T) { proxy := Proxy{ Conn: newUPDConnLocalhost(t), ServerAddr: serverAddr, - DelayPacket: func(d Direction, _ []byte) time.Duration { + DelayPacket: func(d Direction, _, _ net.Addr, _ []byte) time.Duration { // delay packet 1 by 200 ms // delay packet 2 by 400 ms // ... diff --git a/integrationtests/versionnegotiation/rtt_test.go b/integrationtests/versionnegotiation/rtt_test.go index 35f99e38..b2ca13c8 100644 --- a/integrationtests/versionnegotiation/rtt_test.go +++ b/integrationtests/versionnegotiation/rtt_test.go @@ -40,7 +40,7 @@ func TestVersionNegotiationFailure(t *testing.T) { proxy := quicproxy.Proxy{ Conn: proxyConn, ServerAddr: ln.Addr().(*net.UDPAddr), - DelayPacket: func(quicproxy.Direction, []byte) time.Duration { return rtt / 2 }, + DelayPacket: func(quicproxy.Direction, net.Addr, net.Addr, []byte) time.Duration { return rtt / 2 }, } require.NoError(t, proxy.Start()) defer proxy.Close()