diff --git a/integrationtests/drop_test.go b/integrationtests/drop_test.go index 8312f73c3..f8d22da41 100644 --- a/integrationtests/drop_test.go +++ b/integrationtests/drop_test.go @@ -10,6 +10,7 @@ import ( "time" _ "github.com/lucas-clemente/quic-clients" // download clients + "github.com/lucas-clemente/quic-go/integrationtests/proxy" "github.com/lucas-clemente/quic-go/protocol" . "github.com/onsi/ginkgo" @@ -17,40 +18,40 @@ import ( . "github.com/onsi/gomega/gexec" ) -var proxy *UDPProxy - -func runDropTest(incomingPacketDropper, outgoingPacketDropper dropCallback, version protocol.VersionNumber) { - proxyPort := 12345 - - clientPath := fmt.Sprintf( - "%s/src/github.com/lucas-clemente/quic-clients/client-%s-debug", - os.Getenv("GOPATH"), - runtime.GOOS, - ) - - iPort, _ := strconv.Atoi(port) - var err error - proxy, err = NewUDPProxy(proxyPort, "localhost", iPort, incomingPacketDropper, outgoingPacketDropper, 0) - Expect(err).ToNot(HaveOccurred()) - - command := exec.Command( - clientPath, - "--quic-version="+strconv.Itoa(int(version)), - "--host=127.0.0.1", - "--port="+strconv.Itoa(proxyPort), - "https://quic.clemente.io/data", - ) - - session, err := Start(command, nil, GinkgoWriter) - Expect(err).NotTo(HaveOccurred()) - defer session.Kill() - Eventually(session, 4).Should(Exit(0)) - Expect(bytes.Contains(session.Out.Contents(), data)).To(BeTrue()) -} - var _ = Describe("Drop Proxy", func() { + var dropproxy *proxy.UDPProxy + + runDropTest := func(incomingPacketDropper, outgoingPacketDropper proxy.DropCallback, version protocol.VersionNumber) { + proxyPort := 12345 + + clientPath := fmt.Sprintf( + "%s/src/github.com/lucas-clemente/quic-clients/client-%s-debug", + os.Getenv("GOPATH"), + runtime.GOOS, + ) + + iPort, _ := strconv.Atoi(port) + var err error + dropproxy, err = proxy.NewUDPProxy(proxyPort, "localhost", iPort, incomingPacketDropper, outgoingPacketDropper, 0) + Expect(err).ToNot(HaveOccurred()) + + command := exec.Command( + clientPath, + "--quic-version="+strconv.Itoa(int(version)), + "--host=127.0.0.1", + "--port="+strconv.Itoa(proxyPort), + "https://quic.clemente.io/data", + ) + + session, err := Start(command, nil, GinkgoWriter) + Expect(err).NotTo(HaveOccurred()) + defer session.Kill() + Eventually(session, 4).Should(Exit(0)) + Expect(bytes.Contains(session.Out.Contents(), data)).To(BeTrue()) + } + AfterEach(func() { - proxy.Stop() + dropproxy.Stop() time.Sleep(time.Millisecond) }) @@ -59,7 +60,7 @@ var _ = Describe("Drop Proxy", func() { Context(fmt.Sprintf("with quic version %d", version), func() { Context("dropping every 4th packet after the crypto handshake", func() { - dropper := func(p PacketNumber) bool { + dropper := func(p proxy.PacketNumber) bool { if p <= 5 { // don't interfere with the crypto handshake return false } diff --git a/integrationtests/udp_proxy.go b/integrationtests/proxy/udp_proxy.go similarity index 88% rename from integrationtests/udp_proxy.go rename to integrationtests/proxy/udp_proxy.go index 6c83867f8..7b7f18232 100644 --- a/integrationtests/udp_proxy.go +++ b/integrationtests/proxy/udp_proxy.go @@ -1,4 +1,4 @@ -package integrationtests +package proxy import ( "net" @@ -16,8 +16,12 @@ type connection struct { outgoingPacketCounter PacketNumber } +// A PacketNumber is a packet number for the UDP Proxy +// note that this does not necessarily correspond to the QUIC packet number type PacketNumber uint64 -type dropCallback func(PacketNumber) bool + +// DropCallback is a callback that determines which packet gets dropped +type DropCallback func(PacketNumber) bool // UDPProxy is a UDP proxy type UDPProxy struct { @@ -25,8 +29,8 @@ type UDPProxy struct { mutex sync.Mutex proxyConn *net.UDPConn - dropIncomingPacket dropCallback - dropOutgoingPacket dropCallback + dropIncomingPacket DropCallback + dropOutgoingPacket DropCallback rtt time.Duration // Mapping from client addresses (as host:port) to connection @@ -34,7 +38,7 @@ type UDPProxy struct { } // NewUDPProxy creates a new UDP proxy -func NewUDPProxy(proxyPort int, serverAddress string, serverPort int, dropIncomingPacket, dropOutgoingPacket dropCallback, rtt time.Duration) (*UDPProxy, error) { +func NewUDPProxy(proxyPort int, serverAddress string, serverPort int, dropIncomingPacket, dropOutgoingPacket DropCallback, rtt time.Duration) (*UDPProxy, error) { dontDrop := func(p PacketNumber) bool { return false } diff --git a/integrationtests/udp_proxy_test.go b/integrationtests/proxy/udp_proxy_test.go similarity index 98% rename from integrationtests/udp_proxy_test.go rename to integrationtests/proxy/udp_proxy_test.go index 0c78d8ce4..4c9397123 100644 --- a/integrationtests/udp_proxy_test.go +++ b/integrationtests/proxy/udp_proxy_test.go @@ -1,4 +1,4 @@ -package integrationtests +package proxy import ( "net" @@ -11,7 +11,7 @@ import ( type packetData []byte -var _ = Describe("Integrationtests", func() { +var _ = Describe("UDP Proxy", func() { var serverPort int BeforeEach(func() { diff --git a/integrationtests/proxy/udpproxy_suite_test.go b/integrationtests/proxy/udpproxy_suite_test.go new file mode 100644 index 000000000..00e58c139 --- /dev/null +++ b/integrationtests/proxy/udpproxy_suite_test.go @@ -0,0 +1,13 @@ +package proxy + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + + "testing" +) + +func TestQuicGo(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "UDP Proxy") +} diff --git a/integrationtests/rtt_test.go b/integrationtests/rtt_test.go index 49e3a48b3..4366deec1 100644 --- a/integrationtests/rtt_test.go +++ b/integrationtests/rtt_test.go @@ -10,6 +10,7 @@ import ( "time" _ "github.com/lucas-clemente/quic-clients" // download clients + "github.com/lucas-clemente/quic-go/integrationtests/proxy" "github.com/lucas-clemente/quic-go/protocol" . "github.com/onsi/ginkgo" @@ -18,7 +19,7 @@ import ( ) var _ = Describe("RTT", func() { - var rttProxy *UDPProxy + var rttProxy *proxy.UDPProxy runRTTTest := func(rtt time.Duration, version protocol.VersionNumber) { proxyPort := 12345 @@ -31,7 +32,7 @@ var _ = Describe("RTT", func() { iPort, _ := strconv.Atoi(port) var err error - rttProxy, err = NewUDPProxy(proxyPort, "localhost", iPort, nil, nil, rtt) + rttProxy, err = proxy.NewUDPProxy(proxyPort, "localhost", iPort, nil, nil, rtt) Expect(err).ToNot(HaveOccurred()) command := exec.Command(