forked from quic-go/quic-go
add a client and server implementation for the interop test runner
This commit is contained in:
24
interop/Dockerfile
Normal file
24
interop/Dockerfile
Normal file
@@ -0,0 +1,24 @@
|
||||
FROM martenseemann/quic-network-simulator-endpoint:latest
|
||||
|
||||
RUN apt-get update && apt-get install -y wget tar git vim python
|
||||
|
||||
RUN wget https://dl.google.com/go/go1.13.3.linux-amd64.tar.gz && \
|
||||
tar xfz go1.13.3.linux-amd64.tar.gz && \
|
||||
rm go1.13.3.linux-amd64.tar.gz
|
||||
|
||||
ENV PATH="/go/bin:${PATH}"
|
||||
|
||||
# build with --build-arg CACHEBUST=$(date +%s)
|
||||
ARG CACHEBUST=1
|
||||
|
||||
RUN git clone https://github.com/lucas-clemente/quic-go && \
|
||||
cd quic-go && \
|
||||
git checkout interop && \
|
||||
go get ./...
|
||||
|
||||
WORKDIR /quic-go
|
||||
|
||||
COPY run_endpoint.sh .
|
||||
RUN chmod +x run_endpoint.sh
|
||||
|
||||
ENTRYPOINT [ "./run_endpoint.sh" ]
|
||||
87
interop/client/main.go
Normal file
87
interop/client/main.go
Normal file
@@ -0,0 +1,87 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/http3"
|
||||
"github.com/lucas-clemente/quic-go/interop/http09"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logFile, err := os.Create("/logs/log.txt")
|
||||
if err != nil {
|
||||
fmt.Printf("Could not create log file: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
defer logFile.Close()
|
||||
log.SetOutput(logFile)
|
||||
|
||||
flag.Parse()
|
||||
urls := flag.Args()
|
||||
|
||||
testcase := os.Getenv("TESTCASE")
|
||||
|
||||
var useH3 bool
|
||||
switch testcase {
|
||||
case "handshake", "transfer", "retry":
|
||||
case "http3":
|
||||
useH3 = true
|
||||
default:
|
||||
fmt.Printf("unsupported test case: %s\n", testcase)
|
||||
os.Exit(127)
|
||||
}
|
||||
|
||||
var roundTripper http.RoundTripper
|
||||
if useH3 {
|
||||
r := &http3.RoundTripper{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
defer r.Close()
|
||||
roundTripper = r
|
||||
} else {
|
||||
r := &http09.RoundTripper{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
defer r.Close()
|
||||
roundTripper = r
|
||||
}
|
||||
|
||||
var g errgroup.Group
|
||||
for _, u := range urls {
|
||||
url := u
|
||||
g.Go(func() error {
|
||||
return downloadFile(roundTripper, url)
|
||||
})
|
||||
}
|
||||
if err := g.Wait(); err != nil {
|
||||
fmt.Printf("Downloading files failed: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func downloadFile(cl http.RoundTripper, url string) error {
|
||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
rsp, err := cl.RoundTrip(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rsp.Body.Close()
|
||||
|
||||
file, err := os.Create("/downloads" + req.URL.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
_, err = io.Copy(file, rsp.Body)
|
||||
return err
|
||||
}
|
||||
17
interop/run_endpoint.sh
Normal file
17
interop/run_endpoint.sh
Normal file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# Set up the routing needed for the simulation.
|
||||
/setup.sh
|
||||
|
||||
if [ "$ROLE" == "client" ]; then
|
||||
# Wait for the simulator to start up.
|
||||
/wait-for-it.sh sim:57832 -s -t 10
|
||||
echo "Starting QUIC client..."
|
||||
echo "Client params: $CLIENT_PARAMS"
|
||||
echo "Test case: $TESTCASE"
|
||||
QUIC_GO_LOG_LEVEL=debug go run interop/client/main.go $CLIENT_PARAMS $REQUESTS
|
||||
else
|
||||
echo "Running QUIC server."
|
||||
QUIC_GO_LOG_LEVEL=debug go run interop/server/main.go "$@"
|
||||
fi
|
||||
74
interop/server/main.go
Normal file
74
interop/server/main.go
Normal file
@@ -0,0 +1,74 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
"github.com/lucas-clemente/quic-go/http3"
|
||||
"github.com/lucas-clemente/quic-go/internal/testdata"
|
||||
"github.com/lucas-clemente/quic-go/interop/http09"
|
||||
)
|
||||
|
||||
func main() {
|
||||
logFile, err := os.Create("/logs/log.txt")
|
||||
if err != nil {
|
||||
fmt.Printf("Could not create log file: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
defer logFile.Close()
|
||||
log.SetOutput(logFile)
|
||||
|
||||
testcase := os.Getenv("TESTCASE")
|
||||
|
||||
// a quic.Config that doesn't do a Retry
|
||||
quicConf := &quic.Config{
|
||||
AcceptToken: func(_ net.Addr, _ *quic.Token) bool { return true },
|
||||
}
|
||||
|
||||
switch testcase {
|
||||
case "handshake", "transfer":
|
||||
err = runHTTP09Server(quicConf)
|
||||
case "retry":
|
||||
// By default, quic-go performs a Retry on every incoming connection.
|
||||
quicConf.AcceptToken = nil
|
||||
err = runHTTP09Server(quicConf)
|
||||
case "http3":
|
||||
err = runHTTP3Server(quicConf)
|
||||
default:
|
||||
fmt.Printf("unsupported test case: %s\n", testcase)
|
||||
os.Exit(127)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Error running server: %s\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func runHTTP09Server(quicConf *quic.Config) error {
|
||||
server := http09.Server{
|
||||
Server: &http.Server{
|
||||
Addr: "0.0.0.0:443",
|
||||
TLSConfig: testdata.GetTLSConfig(),
|
||||
},
|
||||
QuicConfig: quicConf,
|
||||
}
|
||||
http.DefaultServeMux.Handle("/", http.FileServer(http.Dir("/www")))
|
||||
return server.ListenAndServe()
|
||||
}
|
||||
|
||||
func runHTTP3Server(quicConf *quic.Config) error {
|
||||
server := http3.Server{
|
||||
Server: &http.Server{
|
||||
Addr: "0.0.0.0:443",
|
||||
TLSConfig: testdata.GetTLSConfig(),
|
||||
},
|
||||
QuicConfig: quicConf,
|
||||
}
|
||||
http.DefaultServeMux.Handle("/", http.FileServer(http.Dir("/www")))
|
||||
return server.ListenAndServe()
|
||||
}
|
||||
Reference in New Issue
Block a user