github.com/tumi8/quic-go@v0.37.4-tum/interop/server/main.go (about) 1 package main 2 3 import ( 4 "crypto/tls" 5 "fmt" 6 "log" 7 "net" 8 "net/http" 9 "os" 10 11 "github.com/tumi8/quic-go" 12 "github.com/tumi8/quic-go/http3" 13 "github.com/tumi8/quic-go/noninternal/qtls" 14 "github.com/tumi8/quic-go/interop/http09" 15 "github.com/tumi8/quic-go/interop/utils" 16 ) 17 18 var tlsConf *tls.Config 19 20 func main() { 21 logFile, err := os.Create("/logs/log.txt") 22 if err != nil { 23 fmt.Printf("Could not create log file: %s\n", err.Error()) 24 os.Exit(1) 25 } 26 defer logFile.Close() 27 log.SetOutput(logFile) 28 29 keyLog, err := utils.GetSSLKeyLog() 30 if err != nil { 31 fmt.Printf("Could not create key log: %s\n", err.Error()) 32 os.Exit(1) 33 } 34 if keyLog != nil { 35 defer keyLog.Close() 36 } 37 38 testcase := os.Getenv("TESTCASE") 39 40 quicConf := &quic.Config{ 41 RequireAddressValidation: func(net.Addr) bool { return testcase == "retry" }, 42 Allow0RTT: testcase == "zerortt", 43 Tracer: utils.NewQLOGConnectionTracer, 44 } 45 cert, err := tls.LoadX509KeyPair("/certs/cert.pem", "/certs/priv.key") 46 if err != nil { 47 fmt.Println(err) 48 os.Exit(1) 49 } 50 tlsConf = &tls.Config{ 51 Certificates: []tls.Certificate{cert}, 52 KeyLogWriter: keyLog, 53 } 54 55 switch testcase { 56 case "versionnegotiation", "handshake", "retry", "transfer", "resumption", "multiconnect", "zerortt": 57 err = runHTTP09Server(quicConf) 58 case "chacha20": 59 reset := qtls.SetCipherSuite(tls.TLS_CHACHA20_POLY1305_SHA256) 60 defer reset() 61 err = runHTTP09Server(quicConf) 62 case "http3": 63 err = runHTTP3Server(quicConf) 64 default: 65 fmt.Printf("unsupported test case: %s\n", testcase) 66 os.Exit(127) 67 } 68 69 if err != nil { 70 fmt.Printf("Error running server: %s\n", err.Error()) 71 os.Exit(1) 72 } 73 } 74 75 func runHTTP09Server(quicConf *quic.Config) error { 76 server := http09.Server{ 77 Server: &http.Server{ 78 Addr: ":443", 79 TLSConfig: tlsConf, 80 }, 81 QuicConfig: quicConf, 82 } 83 http.DefaultServeMux.Handle("/", http.FileServer(http.Dir("/www"))) 84 return server.ListenAndServe() 85 } 86 87 func runHTTP3Server(quicConf *quic.Config) error { 88 server := http3.Server{ 89 Addr: ":443", 90 TLSConfig: tlsConf, 91 QuicConfig: quicConf, 92 } 93 http.DefaultServeMux.Handle("/", http.FileServer(http.Dir("/www"))) 94 return server.ListenAndServe() 95 }