-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
99 lines (88 loc) · 2.22 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"crypto/tls"
"fmt"
"log"
"net"
"net/http"
"os"
"github.com/zzzz-26/quic-go"
"github.com/zzzz-26/quic-go/http3"
"github.com/zzzz-26/quic-go/interop/http09"
"github.com/zzzz-26/quic-go/interop/utils"
"github.com/zzzz-26/quic-go/qlog"
)
var tlsConf *tls.Config
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)
keyLog, err := utils.GetSSLKeyLog()
if err != nil {
fmt.Printf("Could not create key log: %s\n", err.Error())
os.Exit(1)
}
if keyLog != nil {
defer keyLog.Close()
}
testcase := os.Getenv("TESTCASE")
getLogWriter, err := utils.GetQLOGWriter()
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
// a quic.Config that doesn't do a Retry
quicConf := &quic.Config{
RequireAddressValidation: func(net.Addr) bool { return testcase == "retry" },
Tracer: qlog.NewTracer(getLogWriter),
}
cert, err := tls.LoadX509KeyPair("/certs/cert.pem", "/certs/priv.key")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
tlsConf = &tls.Config{
Certificates: []tls.Certificate{cert},
KeyLogWriter: keyLog,
}
switch testcase {
case "versionnegotiation", "handshake", "retry", "transfer", "resumption", "zerortt", "multiconnect":
err = runHTTP09Server(quicConf)
case "chacha20":
tlsConf.CipherSuites = []uint16{tls.TLS_CHACHA20_POLY1305_SHA256}
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: ":443",
TLSConfig: tlsConf,
},
QuicConfig: quicConf,
}
http.DefaultServeMux.Handle("/", http.FileServer(http.Dir("/www")))
return server.ListenAndServe()
}
func runHTTP3Server(quicConf *quic.Config) error {
server := http3.Server{
Addr: ":443",
TLSConfig: tlsConf,
QuicConfig: quicConf,
}
http.DefaultServeMux.Handle("/", http.FileServer(http.Dir("/www")))
return server.ListenAndServe()
}