From 3be9f6d5d689c40a2990abadefdd888543c29cea Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 15 Mar 2021 15:09:50 +0000 Subject: [PATCH] Use HTTP/2 --- build/gobind-pinecone/monolith.go | 5 +++- cmd/dendrite-demo-pinecone/conn/client.go | 30 ++++++----------------- cmd/dendrite-demo-pinecone/main.go | 5 +++- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/build/gobind-pinecone/monolith.go b/build/gobind-pinecone/monolith.go index 12139c136..f014b5515 100644 --- a/build/gobind-pinecone/monolith.go +++ b/build/gobind-pinecone/monolith.go @@ -38,6 +38,8 @@ import ( userapiAPI "github.com/matrix-org/dendrite/userapi/api" "github.com/matrix-org/gomatrixserverlib" "github.com/sirupsen/logrus" + "golang.org/x/net/http2" + "golang.org/x/net/http2/h2c" pineconeMulticast "github.com/matrix-org/pinecone/multicast" pineconeRouter "github.com/matrix-org/pinecone/router" @@ -339,6 +341,7 @@ func (m *DendriteMonolith) Start() { m.PineconeQUIC.Mux().Handle(httputil.PublicMediaPathPrefix, pMux) // Build both ends of a HTTP multiplex. + h2s := &http2.Server{} m.httpServer = &http.Server{ Addr: ":0", TLSNextProto: map[string]func(*http.Server, *tls.Conn, http.Handler){}, @@ -348,7 +351,7 @@ func (m *DendriteMonolith) Start() { BaseContext: func(_ net.Listener) context.Context { return context.Background() }, - Handler: pMux, + Handler: h2c.NewHandler(pMux, h2s), } m.processContext = base.ProcessContext diff --git a/cmd/dendrite-demo-pinecone/conn/client.go b/cmd/dendrite-demo-pinecone/conn/client.go index 63ddd7f22..5570c787f 100644 --- a/cmd/dendrite-demo-pinecone/conn/client.go +++ b/cmd/dendrite-demo-pinecone/conn/client.go @@ -4,12 +4,12 @@ import ( "net" "net/http" "strings" - "time" "github.com/gorilla/websocket" "github.com/matrix-org/dendrite/setup" "github.com/matrix-org/gomatrixserverlib" "github.com/sirupsen/logrus" + "golang.org/x/net/http2" pineconeRouter "github.com/matrix-org/pinecone/router" pineconeSessions "github.com/matrix-org/pinecone/sessions" @@ -41,7 +41,7 @@ func ConnectToPeer(pRouter *pineconeRouter.Router, peer string) { } type RoundTripper struct { - inner *http.Transport + inner *http2.Transport } func (y *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { @@ -55,16 +55,9 @@ func CreateClient( tr := &http.Transport{} tr.RegisterProtocol( "matrix", &RoundTripper{ - inner: &http.Transport{ - //MaxIdleConnsPerHost: -1, - DisableKeepAlives: true, - TLSHandshakeTimeout: 10 * time.Second, - ResponseHeaderTimeout: 10 * time.Second, - IdleConnTimeout: 60 * time.Second, - Dial: s.Dial, - DialContext: s.DialContext, - DialTLS: s.DialTLS, - DialTLSContext: s.DialTLSContext, + inner: &http2.Transport{ + AllowHTTP: true, + DialTLS: s.DialTLSForH2C, }, }, ) @@ -79,16 +72,9 @@ func CreateFederationClient( tr := &http.Transport{} tr.RegisterProtocol( "matrix", &RoundTripper{ - inner: &http.Transport{ - //MaxIdleConnsPerHost: -1, - DisableKeepAlives: true, - TLSHandshakeTimeout: 10 * time.Second, - ResponseHeaderTimeout: 10 * time.Second, - IdleConnTimeout: 60 * time.Second, - Dial: s.Dial, - DialContext: s.DialContext, - DialTLS: s.DialTLS, - DialTLSContext: s.DialTLSContext, + inner: &http2.Transport{ + AllowHTTP: true, + DialTLS: s.DialTLSForH2C, }, }, ) diff --git a/cmd/dendrite-demo-pinecone/main.go b/cmd/dendrite-demo-pinecone/main.go index 9555e7116..978748bd5 100644 --- a/cmd/dendrite-demo-pinecone/main.go +++ b/cmd/dendrite-demo-pinecone/main.go @@ -47,6 +47,8 @@ import ( "github.com/matrix-org/dendrite/setup/config" "github.com/matrix-org/dendrite/userapi" "github.com/matrix-org/gomatrixserverlib" + "golang.org/x/net/http2" + "golang.org/x/net/http2/h2c" pineconeMulticast "github.com/matrix-org/pinecone/multicast" pineconeRouter "github.com/matrix-org/pinecone/router" @@ -222,6 +224,7 @@ func main() { pQUIC.Mux().Handle(httputil.PublicMediaPathPrefix, pMux) // Build both ends of a HTTP multiplex. + h2s := &http2.Server{} httpServer := &http.Server{ Addr: ":0", TLSNextProto: map[string]func(*http.Server, *tls.Conn, http.Handler){}, @@ -231,7 +234,7 @@ func main() { BaseContext: func(_ net.Listener) context.Context { return context.Background() }, - Handler: pMux, + Handler: h2c.NewHandler(pMux, h2s), } go func() {