diff options
author | Devon Hudson <devonhudson@librem.one> | 2023-02-01 14:11:48 -0700 |
---|---|---|
committer | Devon Hudson <devonhudson@librem.one> | 2023-02-01 14:11:48 -0700 |
commit | a666c06da1274ed98bfbcc4862fc58deb8448ec9 (patch) | |
tree | ac6698813e9ad83cfabe96f39cda8f7cd04feb25 | |
parent | 048e35026c5396594d26cef6a2412c00ffe6f35f (diff) |
Consolidate pinecone demo http server variations
-rw-r--r-- | build/gobind-pinecone/monolith.go | 8 | ||||
-rw-r--r-- | cmd/dendrite-demo-pinecone/main.go | 4 | ||||
-rw-r--r-- | cmd/dendrite-demo-pinecone/monolith/monolith.go | 32 |
3 files changed, 10 insertions, 34 deletions
diff --git a/build/gobind-pinecone/monolith.go b/build/gobind-pinecone/monolith.go index 597c9135..e8b22c06 100644 --- a/build/gobind-pinecone/monolith.go +++ b/build/gobind-pinecone/monolith.go @@ -342,12 +342,10 @@ func (m *DendriteMonolith) Start() { cfg.Global.JetStream.InMemory = false enableRelaying := false - enableMetrics := true - enableWebsockets := true + enableMetrics := false + enableWebsockets := false m.p2pMonolith.SetupDendrite(cfg, 65432, enableRelaying, enableMetrics, enableWebsockets) - - useTCPListener := false - m.p2pMonolith.StartMonolith(useTCPListener) + m.p2pMonolith.StartMonolith() } func (m *DendriteMonolith) Stop() { diff --git a/cmd/dendrite-demo-pinecone/main.go b/cmd/dendrite-demo-pinecone/main.go index 0b76188b..7706a73f 100644 --- a/cmd/dendrite-demo-pinecone/main.go +++ b/cmd/dendrite-demo-pinecone/main.go @@ -90,9 +90,7 @@ func main() { enableMetrics := true enableWebsockets := true p2pMonolith.SetupDendrite(cfg, *instancePort, *instanceRelayingEnabled, enableMetrics, enableWebsockets) - - useTCPListener := false - p2pMonolith.StartMonolith(useTCPListener) + p2pMonolith.StartMonolith() p2pMonolith.WaitForShutdown() go func() { diff --git a/cmd/dendrite-demo-pinecone/monolith/monolith.go b/cmd/dendrite-demo-pinecone/monolith/monolith.go index 61e71e87..6f1c69a7 100644 --- a/cmd/dendrite-demo-pinecone/monolith/monolith.go +++ b/cmd/dendrite-demo-pinecone/monolith/monolith.go @@ -50,8 +50,6 @@ import ( userAPI "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" pineconeConnections "github.com/matrix-org/pinecone/connections" pineconeMulticast "github.com/matrix-org/pinecone/multicast" @@ -199,8 +197,8 @@ func (p *P2PMonolith) GetUserAPI() userAPI.UserInternalAPI { return p.dendrite.UserAPI } -func (p *P2PMonolith) StartMonolith(useTCPListener bool) { - p.startHTTPServers(useTCPListener) +func (p *P2PMonolith) StartMonolith() { + p.startHTTPServers() p.startEventHandler() } @@ -284,26 +282,7 @@ func (p *P2PMonolith) setupHttpServers(userProvider *users.PineconeUserProvider, pHTTP.Mux().Handle(httputil.PublicMediaPathPrefix, p.pineconeMux) } -func (p *P2PMonolith) startHTTPServers(useTCPListener bool) { - var handler http.Handler - var httpServeFunc func() error - if useTCPListener { - var err error - p.httpListenAddr = "localhost:" + fmt.Sprint(p.port) - p.listener, err = net.Listen("tcp", p.httpListenAddr) - if err != nil { - panic(err) - } - - h2s := &http2.Server{} - handler = h2c.NewHandler(p.pineconeMux, h2s) - httpServeFunc = func() error { return http.Serve(p.listener, p.httpMux) } - } else { - handler = p.pineconeMux - p.httpListenAddr = fmt.Sprintf(":%d", p.port) - httpServeFunc = func() error { return http.ListenAndServe(p.httpListenAddr, p.httpMux) } - } - +func (p *P2PMonolith) startHTTPServers() { go func() { // Build both ends of a HTTP multiplex. httpServer := &http.Server{ @@ -315,7 +294,7 @@ func (p *P2PMonolith) startHTTPServers(useTCPListener bool) { BaseContext: func(_ net.Listener) context.Context { return context.Background() }, - Handler: handler, + Handler: p.pineconeMux, } pubkey := p.Router.PublicKey() @@ -330,9 +309,10 @@ func (p *P2PMonolith) startHTTPServers(useTCPListener bool) { } }() + p.httpListenAddr = fmt.Sprintf(":%d", p.port) go func() { logrus.Info("Listening on ", p.httpListenAddr) - switch httpServeFunc() { + switch http.ListenAndServe(p.httpListenAddr, p.httpMux) { case net.ErrClosed, http.ErrServerClosed: logrus.Info("Stopped listening on ", p.httpListenAddr) default: |