Use HTTP/2

This commit is contained in:
Neil Alexander 2021-03-15 15:09:50 +00:00
parent 346510c557
commit 3be9f6d5d6
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
3 changed files with 16 additions and 24 deletions

View file

@ -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

View file

@ -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,
},
},
)

View file

@ -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() {