aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorDevon Hudson <devonhudson@librem.one>2023-02-01 14:11:48 -0700
committerDevon Hudson <devonhudson@librem.one>2023-02-01 14:11:48 -0700
commita666c06da1274ed98bfbcc4862fc58deb8448ec9 (patch)
treeac6698813e9ad83cfabe96f39cda8f7cd04feb25 /cmd
parent048e35026c5396594d26cef6a2412c00ffe6f35f (diff)
Consolidate pinecone demo http server variations
Diffstat (limited to 'cmd')
-rw-r--r--cmd/dendrite-demo-pinecone/main.go4
-rw-r--r--cmd/dendrite-demo-pinecone/monolith/monolith.go32
2 files changed, 7 insertions, 29 deletions
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: