diff --git a/integrationtests/gquic/drop_test.go b/integrationtests/gquic/drop_test.go index a72d0b5d..66937df1 100644 --- a/integrationtests/gquic/drop_test.go +++ b/integrationtests/gquic/drop_test.go @@ -21,7 +21,7 @@ var _ = Describe("Drop tests", func() { runDropTest := func(dropCallback quicproxy.DropCallback, version protocol.VersionNumber) { var err error - proxy, err = quicproxy.NewQuicProxy("localhost:0", version, quicproxy.Opts{ + proxy, err = quicproxy.NewQuicProxy("localhost:0", version, &quicproxy.Opts{ RemoteAddr: "localhost:" + testserver.Port(), DropPacket: dropCallback, }) diff --git a/integrationtests/gquic/random_rtt_test.go b/integrationtests/gquic/random_rtt_test.go index 052917d6..3a7354f9 100644 --- a/integrationtests/gquic/random_rtt_test.go +++ b/integrationtests/gquic/random_rtt_test.go @@ -56,7 +56,7 @@ var _ = Describe("Random RTT", func() { runRTTTest := func(minRtt, maxRtt time.Duration, version protocol.VersionNumber) { rand.Seed(time.Now().UnixNano()) var err error - proxy, err = quicproxy.NewQuicProxy("localhost:", version, quicproxy.Opts{ + proxy, err = quicproxy.NewQuicProxy("localhost:", version, &quicproxy.Opts{ RemoteAddr: "localhost:" + testserver.Port(), DelayPacket: func(_ quicproxy.Direction, _ protocol.PacketNumber) time.Duration { return getRandomDuration(minRtt, maxRtt) diff --git a/integrationtests/gquic/rtt_test.go b/integrationtests/gquic/rtt_test.go index 29e6a1b2..31f40c1a 100644 --- a/integrationtests/gquic/rtt_test.go +++ b/integrationtests/gquic/rtt_test.go @@ -22,7 +22,7 @@ var _ = Describe("non-zero RTT", func() { runRTTTest := func(rtt time.Duration, version protocol.VersionNumber) { var err error - proxy, err = quicproxy.NewQuicProxy("localhost:", version, quicproxy.Opts{ + proxy, err = quicproxy.NewQuicProxy("localhost:", version, &quicproxy.Opts{ RemoteAddr: "localhost:" + testserver.Port(), DelayPacket: func(_ quicproxy.Direction, _ protocol.PacketNumber) time.Duration { return rtt / 2 diff --git a/integrationtests/self/handshake_rtt_test.go b/integrationtests/self/handshake_rtt_test.go index a56bba55..008359ec 100644 --- a/integrationtests/self/handshake_rtt_test.go +++ b/integrationtests/self/handshake_rtt_test.go @@ -45,7 +45,7 @@ var _ = Describe("Handshake RTT tests", func() { server, err = quic.ListenAddr("localhost:0", testdata.GetTLSConfig(), serverConfig) Expect(err).ToNot(HaveOccurred()) // start the proxy - proxy, err = quicproxy.NewQuicProxy("localhost:0", protocol.VersionWhatever, quicproxy.Opts{ + 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 }, }) diff --git a/integrationtests/tools/proxy/proxy.go b/integrationtests/tools/proxy/proxy.go index b68ac604..46c53231 100644 --- a/integrationtests/tools/proxy/proxy.go +++ b/integrationtests/tools/proxy/proxy.go @@ -75,7 +75,10 @@ type QuicProxy struct { } // NewQuicProxy creates a new UDP proxy -func NewQuicProxy(local string, version protocol.VersionNumber, opts Opts) (*QuicProxy, error) { +func NewQuicProxy(local string, version protocol.VersionNumber, opts *Opts) (*QuicProxy, error) { + if opts == nil { + opts = &Opts{} + } laddr, err := net.ResolveUDPAddr("udp", local) if err != nil { return nil, err diff --git a/integrationtests/tools/proxy/proxy_test.go b/integrationtests/tools/proxy/proxy_test.go index c0074158..a152129d 100644 --- a/integrationtests/tools/proxy/proxy_test.go +++ b/integrationtests/tools/proxy/proxy_test.go @@ -18,8 +18,6 @@ import ( type packetData []byte var _ = Describe("QUIC Proxy", func() { - var serverAddr string - makePacket := func(p protocol.PacketNumber, payload []byte) []byte { b := &bytes.Buffer{} hdr := wire.PublicHeader{ @@ -34,13 +32,9 @@ var _ = Describe("QUIC Proxy", func() { return raw } - BeforeEach(func() { - serverAddr = "localhost:7331" - }) - Context("Proxy setup and teardown", func() { It("sets up the UDPProxy", func() { - proxy, err := NewQuicProxy("localhost:0", protocol.VersionWhatever, Opts{RemoteAddr: serverAddr}) + proxy, err := NewQuicProxy("localhost:0", protocol.VersionWhatever, nil) Expect(err).ToNot(HaveOccurred()) Expect(proxy.clientDict).To(HaveLen(0)) @@ -53,7 +47,7 @@ var _ = Describe("QUIC Proxy", func() { }) It("stops the UDPProxy", func() { - proxy, err := NewQuicProxy("localhost:0", protocol.VersionWhatever, Opts{RemoteAddr: serverAddr}) + proxy, err := NewQuicProxy("localhost:0", protocol.VersionWhatever, nil) Expect(err).ToNot(HaveOccurred()) port := proxy.LocalPort() err = proxy.Close() @@ -71,7 +65,7 @@ var _ = Describe("QUIC Proxy", func() { }) It("has the correct LocalAddr and LocalPort", func() { - proxy, err := NewQuicProxy("localhost:0", protocol.VersionWhatever, Opts{RemoteAddr: serverAddr}) + proxy, err := NewQuicProxy("localhost:0", protocol.VersionWhatever, nil) Expect(err).ToNot(HaveOccurred()) Expect(proxy.LocalAddr().String()).To(Equal("127.0.0.1:" + strconv.Itoa(proxy.LocalPort()))) @@ -90,7 +84,7 @@ var _ = Describe("QUIC Proxy", func() { proxy *QuicProxy ) - startProxy := func(opts Opts) { + startProxy := func(opts *Opts) { var err error proxy, err = NewQuicProxy("localhost:0", protocol.VersionWhatever, opts) Expect(err).ToNot(HaveOccurred()) @@ -113,9 +107,9 @@ var _ = Describe("QUIC Proxy", func() { serverReceivedPackets = make(chan packetData, 100) atomic.StoreInt32(&serverNumPacketsSent, 0) - // setup a dump UDP server on port 7331 + // setup a dump UDP server // in production this would be a QUIC server - raddr, err := net.ResolveUDPAddr("udp", serverAddr) + raddr, err := net.ResolveUDPAddr("udp", "127.0.0.1:0") Expect(err).ToNot(HaveOccurred()) serverConn, err = net.ListenUDP("udp", raddr) Expect(err).ToNot(HaveOccurred()) @@ -149,7 +143,7 @@ var _ = Describe("QUIC Proxy", func() { Context("no packet drop", func() { It("relays packets from the client to the server", func() { - startProxy(Opts{RemoteAddr: serverAddr}) + startProxy(&Opts{RemoteAddr: serverConn.LocalAddr().String()}) // send the first packet _, err := clientConn.Write(makePacket(1, []byte("foobar"))) Expect(err).ToNot(HaveOccurred()) @@ -171,7 +165,7 @@ var _ = Describe("QUIC Proxy", func() { }) It("relays packets from the server to the client", func() { - startProxy(Opts{RemoteAddr: serverAddr}) + startProxy(&Opts{RemoteAddr: serverConn.LocalAddr().String()}) // send the first packet _, err := clientConn.Write(makePacket(1, []byte("foobar"))) Expect(err).ToNot(HaveOccurred()) @@ -218,8 +212,8 @@ var _ = Describe("QUIC Proxy", func() { Context("Drop Callbacks", func() { It("drops incoming packets", func() { - opts := Opts{ - RemoteAddr: serverAddr, + opts := &Opts{ + RemoteAddr: serverConn.LocalAddr().String(), DropPacket: func(d Direction, p protocol.PacketNumber) bool { return d == DirectionIncoming && p%2 == 0 }, @@ -236,8 +230,8 @@ var _ = Describe("QUIC Proxy", func() { It("drops outgoing packets", func() { const numPackets = 6 - opts := Opts{ - RemoteAddr: serverAddr, + opts := &Opts{ + RemoteAddr: serverConn.LocalAddr().String(), DropPacket: func(d Direction, p protocol.PacketNumber) bool { return d == DirectionOutgoing && p%2 == 0 }, @@ -280,8 +274,8 @@ var _ = Describe("QUIC Proxy", func() { It("delays incoming packets", func() { delay := 300 * time.Millisecond - opts := Opts{ - RemoteAddr: serverAddr, + opts := &Opts{ + RemoteAddr: serverConn.LocalAddr().String(), // delay packet 1 by 200 ms // delay packet 2 by 400 ms // ... @@ -311,8 +305,8 @@ var _ = Describe("QUIC Proxy", func() { It("delays outgoing packets", func() { const numPackets = 3 delay := 300 * time.Millisecond - opts := Opts{ - RemoteAddr: serverAddr, + opts := &Opts{ + RemoteAddr: serverConn.LocalAddr().String(), // delay packet 1 by 200 ms // delay packet 2 by 400 ms // ...