diff --git a/integrationtests/gquic/drop_test.go b/integrationtests/gquic/drop_test.go index 66937df1..2d471261 100644 --- a/integrationtests/gquic/drop_test.go +++ b/integrationtests/gquic/drop_test.go @@ -60,12 +60,12 @@ var _ = Describe("Drop tests", func() { func dropTests( context string, - interval protocol.PacketNumber, - dropInARow protocol.PacketNumber, + interval uint64, + dropInARow uint64, runDropTest func(dropCallback quicproxy.DropCallback, version protocol.VersionNumber), version protocol.VersionNumber) { Context(context, func() { - dropper := func(p protocol.PacketNumber) bool { + dropper := func(p uint64) bool { if p <= 10 { // don't interfere with the crypto handshake return false } @@ -73,13 +73,13 @@ func dropTests( } It("gets a file when many outgoing packets are dropped", func() { - runDropTest(func(d quicproxy.Direction, p protocol.PacketNumber) bool { + runDropTest(func(d quicproxy.Direction, p uint64) bool { return d == quicproxy.DirectionOutgoing && dropper(p) }, version) }) It("gets a file when many incoming packets are dropped", func() { - runDropTest(func(d quicproxy.Direction, p protocol.PacketNumber) bool { + runDropTest(func(d quicproxy.Direction, p uint64) bool { return d == quicproxy.DirectionIncoming && dropper(p) }, version) }) diff --git a/integrationtests/gquic/random_rtt_test.go b/integrationtests/gquic/random_rtt_test.go index 3a7354f9..fdb406e7 100644 --- a/integrationtests/gquic/random_rtt_test.go +++ b/integrationtests/gquic/random_rtt_test.go @@ -58,7 +58,7 @@ var _ = Describe("Random RTT", func() { var err error proxy, err = quicproxy.NewQuicProxy("localhost:", version, &quicproxy.Opts{ RemoteAddr: "localhost:" + testserver.Port(), - DelayPacket: func(_ quicproxy.Direction, _ protocol.PacketNumber) time.Duration { + DelayPacket: func(_ quicproxy.Direction, _ uint64) time.Duration { return getRandomDuration(minRtt, maxRtt) }, }) diff --git a/integrationtests/gquic/rtt_test.go b/integrationtests/gquic/rtt_test.go index 31f40c1a..89419f54 100644 --- a/integrationtests/gquic/rtt_test.go +++ b/integrationtests/gquic/rtt_test.go @@ -24,7 +24,7 @@ var _ = Describe("non-zero RTT", func() { var err error proxy, err = quicproxy.NewQuicProxy("localhost:", version, &quicproxy.Opts{ RemoteAddr: "localhost:" + testserver.Port(), - DelayPacket: func(_ quicproxy.Direction, _ protocol.PacketNumber) time.Duration { + DelayPacket: func(_ quicproxy.Direction, _ uint64) time.Duration { return rtt / 2 }, }) diff --git a/integrationtests/self/handshake_rtt_test.go b/integrationtests/self/handshake_rtt_test.go index 008359ec..421e790f 100644 --- a/integrationtests/self/handshake_rtt_test.go +++ b/integrationtests/self/handshake_rtt_test.go @@ -47,7 +47,7 @@ var _ = Describe("Handshake RTT tests", func() { // start the proxy proxy, err = quicproxy.NewQuicProxy("localhost:0", protocol.VersionWhatever, &quicproxy.Opts{ RemoteAddr: server.Addr().String(), - DelayPacket: func(_ quicproxy.Direction, _ protocol.PacketNumber) time.Duration { return rtt / 2 }, + DelayPacket: func(_ quicproxy.Direction, _ uint64) time.Duration { return rtt / 2 }, }) Expect(err).ToNot(HaveOccurred()) diff --git a/integrationtests/tools/proxy/proxy.go b/integrationtests/tools/proxy/proxy.go index 46c53231..b8f2cf6b 100644 --- a/integrationtests/tools/proxy/proxy.go +++ b/integrationtests/tools/proxy/proxy.go @@ -1,14 +1,12 @@ package quicproxy import ( - "bytes" "net" "sync" "sync/atomic" "time" "github.com/lucas-clemente/quic-go/internal/protocol" - "github.com/lucas-clemente/quic-go/internal/wire" ) // Connection is a UDP connection @@ -31,18 +29,18 @@ const ( ) // DropCallback is a callback that determines which packet gets dropped. -type DropCallback func(Direction, protocol.PacketNumber) bool +type DropCallback func(dir Direction, packetCount uint64) bool // NoDropper doesn't drop packets. -var NoDropper DropCallback = func(Direction, protocol.PacketNumber) bool { +var NoDropper DropCallback = func(Direction, uint64) bool { return false } // DelayCallback is a callback that determines how much delay to apply to a packet. -type DelayCallback func(Direction, protocol.PacketNumber) time.Duration +type DelayCallback func(dir Direction, packetCount uint64) time.Duration // NoDelay doesn't apply a delay. -var NoDelay DelayCallback = func(Direction, protocol.PacketNumber) time.Duration { +var NoDelay DelayCallback = func(Direction, uint64) time.Duration { return 0 } @@ -125,6 +123,7 @@ func (p *QuicProxy) LocalAddr() net.Addr { return p.conn.LocalAddr() } +// LocalPort is the UDP port number the proxy is listening on. func (p *QuicProxy) LocalPort() int { return p.conn.LocalAddr().(*net.UDPAddr).Port } @@ -165,20 +164,14 @@ func (p *QuicProxy) runProxy() error { } p.mutex.Unlock() - atomic.AddUint64(&conn.incomingPacketCounter, 1) + packetCount := atomic.AddUint64(&conn.incomingPacketCounter, 1) - r := bytes.NewReader(raw) - hdr, err := wire.ParsePublicHeader(r, protocol.PerspectiveClient, p.version) - if err != nil { - return err - } - - if p.dropPacket(DirectionIncoming, hdr.PacketNumber) { + if p.dropPacket(DirectionIncoming, packetCount) { continue } // Send the packet to the server - delay := p.delayPacket(DirectionIncoming, hdr.PacketNumber) + delay := p.delayPacket(DirectionIncoming, packetCount) if delay != 0 { time.AfterFunc(delay, func() { // TODO: handle error @@ -203,21 +196,13 @@ func (p *QuicProxy) runConnection(conn *connection) error { } raw := buffer[0:n] - // TODO: Switch back to using the public header once Chrome properly sets the type byte. - // r := bytes.NewReader(raw) - // , err := wire.ParsePublicHeader(r, protocol.PerspectiveServer) - // if err != nil { - // return err - // } + packetCount := atomic.AddUint64(&conn.outgoingPacketCounter, 1) - v := atomic.AddUint64(&conn.outgoingPacketCounter, 1) - - packetNumber := protocol.PacketNumber(v) - if p.dropPacket(DirectionOutgoing, packetNumber) { + if p.dropPacket(DirectionOutgoing, packetCount) { continue } - delay := p.delayPacket(DirectionOutgoing, packetNumber) + delay := p.delayPacket(DirectionOutgoing, packetCount) if delay != 0 { time.AfterFunc(delay, func() { // TODO: handle error diff --git a/integrationtests/tools/proxy/proxy_test.go b/integrationtests/tools/proxy/proxy_test.go index a152129d..c1574ba6 100644 --- a/integrationtests/tools/proxy/proxy_test.go +++ b/integrationtests/tools/proxy/proxy_test.go @@ -214,7 +214,7 @@ var _ = Describe("QUIC Proxy", func() { It("drops incoming packets", func() { opts := &Opts{ RemoteAddr: serverConn.LocalAddr().String(), - DropPacket: func(d Direction, p protocol.PacketNumber) bool { + DropPacket: func(d Direction, p uint64) bool { return d == DirectionIncoming && p%2 == 0 }, } @@ -232,7 +232,7 @@ var _ = Describe("QUIC Proxy", func() { const numPackets = 6 opts := &Opts{ RemoteAddr: serverConn.LocalAddr().String(), - DropPacket: func(d Direction, p protocol.PacketNumber) bool { + DropPacket: func(d Direction, p uint64) bool { return d == DirectionOutgoing && p%2 == 0 }, } @@ -279,7 +279,7 @@ var _ = Describe("QUIC Proxy", func() { // delay packet 1 by 200 ms // delay packet 2 by 400 ms // ... - DelayPacket: func(d Direction, p protocol.PacketNumber) time.Duration { + DelayPacket: func(d Direction, p uint64) time.Duration { if d == DirectionOutgoing { return 0 } @@ -310,7 +310,7 @@ var _ = Describe("QUIC Proxy", func() { // delay packet 1 by 200 ms // delay packet 2 by 400 ms // ... - DelayPacket: func(d Direction, p protocol.PacketNumber) time.Duration { + DelayPacket: func(d Direction, p uint64) time.Duration { if d == DirectionIncoming { return 0 }