forked from quic-go/quic-go
1
integrationtests/drop.go
Normal file
1
integrationtests/drop.go
Normal file
@@ -0,0 +1 @@
|
|||||||
|
package integrationtests
|
||||||
94
integrationtests/drop_test.go
Normal file
94
integrationtests/drop_test.go
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
package integrationtests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
_ "github.com/lucas-clemente/quic-clients" // download clients
|
||||||
|
"github.com/lucas-clemente/quic-go/protocol"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
|
. "github.com/onsi/gomega/gexec"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ = Describe("Drop Proxy", func() {
|
||||||
|
var proxy *UDPProxy
|
||||||
|
clientPath := fmt.Sprintf(
|
||||||
|
"%s/src/github.com/lucas-clemente/quic-clients/client-%s-debug",
|
||||||
|
os.Getenv("GOPATH"),
|
||||||
|
runtime.GOOS,
|
||||||
|
)
|
||||||
|
proxyPort := 10001
|
||||||
|
|
||||||
|
AfterEach(func() {
|
||||||
|
proxy.Stop()
|
||||||
|
time.Sleep(time.Millisecond)
|
||||||
|
})
|
||||||
|
|
||||||
|
for i := range protocol.SupportedVersions {
|
||||||
|
version := protocol.SupportedVersions[i]
|
||||||
|
|
||||||
|
Context(fmt.Sprintf("with quic version %d", version), func() {
|
||||||
|
It("gets a file when many outgoing packets are dropped", func() {
|
||||||
|
dropper := func(p PacketNumber) bool {
|
||||||
|
if p <= 5 { // don't interfere with the crypto handshake
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return p%4 == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
iPort, _ := strconv.Atoi(port)
|
||||||
|
var err error
|
||||||
|
proxy, err = NewUDPProxy(proxyPort, "localhost", iPort, nil, dropper)
|
||||||
|
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())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("gets a file when many incoming packets are dropped", func() {
|
||||||
|
dropper := func(p PacketNumber) bool {
|
||||||
|
if p <= 5 { // don't interfere with the crypto handshake
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return p%4 == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
iPort, _ := strconv.Atoi(port)
|
||||||
|
var err error
|
||||||
|
proxy, err = NewUDPProxy(proxyPort, "localhost", iPort, dropper, nil)
|
||||||
|
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())
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -54,6 +54,7 @@ var _ = AfterSuite(func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
func setupHTTPHandlers() {
|
func setupHTTPHandlers() {
|
||||||
|
defer GinkgoRecover()
|
||||||
data = make([]byte, dataLen)
|
data = make([]byte, dataLen)
|
||||||
_, err := rand.Read(data)
|
_, err := rand.Read(data)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ type connection struct {
|
|||||||
ClientAddr *net.UDPAddr // Address of the client
|
ClientAddr *net.UDPAddr // Address of the client
|
||||||
ServerConn *net.UDPConn // UDP connection to server
|
ServerConn *net.UDPConn // UDP connection to server
|
||||||
|
|
||||||
incomingPacketCounter packetNumber
|
incomingPacketCounter PacketNumber
|
||||||
outgoingPacketCounter packetNumber
|
outgoingPacketCounter PacketNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
type packetNumber uint64
|
type PacketNumber uint64
|
||||||
type dropCallback func(packetNumber) bool
|
type dropCallback func(PacketNumber) bool
|
||||||
|
|
||||||
// UDPProxy is a UDP proxy
|
// UDPProxy is a UDP proxy
|
||||||
type UDPProxy struct {
|
type UDPProxy struct {
|
||||||
@@ -33,7 +33,7 @@ type UDPProxy struct {
|
|||||||
|
|
||||||
// NewUDPProxy creates a new UDP proxy
|
// NewUDPProxy creates a new UDP proxy
|
||||||
func NewUDPProxy(proxyPort int, serverAddress string, serverPort int, dropIncomingPacket, dropOutgoingPacket dropCallback) (*UDPProxy, error) {
|
func NewUDPProxy(proxyPort int, serverAddress string, serverPort int, dropIncomingPacket, dropOutgoingPacket dropCallback) (*UDPProxy, error) {
|
||||||
dontDrop := func(p packetNumber) bool {
|
dontDrop := func(p PacketNumber) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -114,13 +114,13 @@ var _ = Describe("Integrationtests", func() {
|
|||||||
var key string
|
var key string
|
||||||
var conn *connection
|
var conn *connection
|
||||||
for key, conn = range proxy.clientDict {
|
for key, conn = range proxy.clientDict {
|
||||||
Expect(conn.incomingPacketCounter).To(Equal(packetNumber(1)))
|
Expect(conn.incomingPacketCounter).To(Equal(PacketNumber(1)))
|
||||||
}
|
}
|
||||||
_, err = clientConn.Write([]byte("decafbad"))
|
_, err = clientConn.Write([]byte("decafbad"))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
time.Sleep(time.Millisecond)
|
time.Sleep(time.Millisecond)
|
||||||
Expect(proxy.clientDict).To(HaveLen(1))
|
Expect(proxy.clientDict).To(HaveLen(1))
|
||||||
Expect(proxy.clientDict[key].incomingPacketCounter).To(Equal(packetNumber(2)))
|
Expect(proxy.clientDict[key].incomingPacketCounter).To(Equal(PacketNumber(2)))
|
||||||
Expect(serverReceivedPackets).To(HaveLen(2))
|
Expect(serverReceivedPackets).To(HaveLen(2))
|
||||||
Expect(serverReceivedPackets[0]).To(Equal(packetData("foobar")))
|
Expect(serverReceivedPackets[0]).To(Equal(packetData("foobar")))
|
||||||
Expect(serverReceivedPackets[1]).To(Equal(packetData("decafbad")))
|
Expect(serverReceivedPackets[1]).To(Equal(packetData("decafbad")))
|
||||||
@@ -134,13 +134,13 @@ var _ = Describe("Integrationtests", func() {
|
|||||||
var key string
|
var key string
|
||||||
var conn *connection
|
var conn *connection
|
||||||
for key, conn = range proxy.clientDict {
|
for key, conn = range proxy.clientDict {
|
||||||
Expect(conn.outgoingPacketCounter).To(Equal(packetNumber(1)))
|
Expect(conn.outgoingPacketCounter).To(Equal(PacketNumber(1)))
|
||||||
}
|
}
|
||||||
_, err = clientConn.Write([]byte("decafbad"))
|
_, err = clientConn.Write([]byte("decafbad"))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
time.Sleep(time.Millisecond)
|
time.Sleep(time.Millisecond)
|
||||||
Expect(proxy.clientDict).To(HaveLen(1))
|
Expect(proxy.clientDict).To(HaveLen(1))
|
||||||
Expect(proxy.clientDict[key].outgoingPacketCounter).To(Equal(packetNumber(2)))
|
Expect(proxy.clientDict[key].outgoingPacketCounter).To(Equal(PacketNumber(2)))
|
||||||
|
|
||||||
var clientReceivedPackets []packetData
|
var clientReceivedPackets []packetData
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ var _ = Describe("Integrationtests", func() {
|
|||||||
|
|
||||||
Context("Drop Callbacks", func() {
|
Context("Drop Callbacks", func() {
|
||||||
It("drops incoming packets", func() {
|
It("drops incoming packets", func() {
|
||||||
dropper := func(p packetNumber) bool {
|
dropper := func(p PacketNumber) bool {
|
||||||
return p%2 == 0
|
return p%2 == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ var _ = Describe("Integrationtests", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("drops outgoing packets", func() {
|
It("drops outgoing packets", func() {
|
||||||
dropper := func(p packetNumber) bool {
|
dropper := func(p PacketNumber) bool {
|
||||||
return p%2 == 0
|
return p%2 == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user