mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-24 20:51:42 +00:00
Consolidate pinecone demo http server variations
This commit is contained in:
parent
048e35026c
commit
a666c06da1
@ -342,12 +342,10 @@ func (m *DendriteMonolith) Start() {
|
|||||||
cfg.Global.JetStream.InMemory = false
|
cfg.Global.JetStream.InMemory = false
|
||||||
|
|
||||||
enableRelaying := false
|
enableRelaying := false
|
||||||
enableMetrics := true
|
enableMetrics := false
|
||||||
enableWebsockets := true
|
enableWebsockets := false
|
||||||
m.p2pMonolith.SetupDendrite(cfg, 65432, enableRelaying, enableMetrics, enableWebsockets)
|
m.p2pMonolith.SetupDendrite(cfg, 65432, enableRelaying, enableMetrics, enableWebsockets)
|
||||||
|
m.p2pMonolith.StartMonolith()
|
||||||
useTCPListener := false
|
|
||||||
m.p2pMonolith.StartMonolith(useTCPListener)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *DendriteMonolith) Stop() {
|
func (m *DendriteMonolith) Stop() {
|
||||||
|
@ -90,9 +90,7 @@ func main() {
|
|||||||
enableMetrics := true
|
enableMetrics := true
|
||||||
enableWebsockets := true
|
enableWebsockets := true
|
||||||
p2pMonolith.SetupDendrite(cfg, *instancePort, *instanceRelayingEnabled, enableMetrics, enableWebsockets)
|
p2pMonolith.SetupDendrite(cfg, *instancePort, *instanceRelayingEnabled, enableMetrics, enableWebsockets)
|
||||||
|
p2pMonolith.StartMonolith()
|
||||||
useTCPListener := false
|
|
||||||
p2pMonolith.StartMonolith(useTCPListener)
|
|
||||||
p2pMonolith.WaitForShutdown()
|
p2pMonolith.WaitForShutdown()
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
@ -50,8 +50,6 @@ import (
|
|||||||
userAPI "github.com/matrix-org/dendrite/userapi/api"
|
userAPI "github.com/matrix-org/dendrite/userapi/api"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/net/http2"
|
|
||||||
"golang.org/x/net/http2/h2c"
|
|
||||||
|
|
||||||
pineconeConnections "github.com/matrix-org/pinecone/connections"
|
pineconeConnections "github.com/matrix-org/pinecone/connections"
|
||||||
pineconeMulticast "github.com/matrix-org/pinecone/multicast"
|
pineconeMulticast "github.com/matrix-org/pinecone/multicast"
|
||||||
@ -199,8 +197,8 @@ func (p *P2PMonolith) GetUserAPI() userAPI.UserInternalAPI {
|
|||||||
return p.dendrite.UserAPI
|
return p.dendrite.UserAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *P2PMonolith) StartMonolith(useTCPListener bool) {
|
func (p *P2PMonolith) StartMonolith() {
|
||||||
p.startHTTPServers(useTCPListener)
|
p.startHTTPServers()
|
||||||
p.startEventHandler()
|
p.startEventHandler()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,26 +282,7 @@ func (p *P2PMonolith) setupHttpServers(userProvider *users.PineconeUserProvider,
|
|||||||
pHTTP.Mux().Handle(httputil.PublicMediaPathPrefix, p.pineconeMux)
|
pHTTP.Mux().Handle(httputil.PublicMediaPathPrefix, p.pineconeMux)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *P2PMonolith) startHTTPServers(useTCPListener bool) {
|
func (p *P2PMonolith) startHTTPServers() {
|
||||||
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) }
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
// Build both ends of a HTTP multiplex.
|
// Build both ends of a HTTP multiplex.
|
||||||
httpServer := &http.Server{
|
httpServer := &http.Server{
|
||||||
@ -315,7 +294,7 @@ func (p *P2PMonolith) startHTTPServers(useTCPListener bool) {
|
|||||||
BaseContext: func(_ net.Listener) context.Context {
|
BaseContext: func(_ net.Listener) context.Context {
|
||||||
return context.Background()
|
return context.Background()
|
||||||
},
|
},
|
||||||
Handler: handler,
|
Handler: p.pineconeMux,
|
||||||
}
|
}
|
||||||
|
|
||||||
pubkey := p.Router.PublicKey()
|
pubkey := p.Router.PublicKey()
|
||||||
@ -330,9 +309,10 @@ func (p *P2PMonolith) startHTTPServers(useTCPListener bool) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
p.httpListenAddr = fmt.Sprintf(":%d", p.port)
|
||||||
go func() {
|
go func() {
|
||||||
logrus.Info("Listening on ", p.httpListenAddr)
|
logrus.Info("Listening on ", p.httpListenAddr)
|
||||||
switch httpServeFunc() {
|
switch http.ListenAndServe(p.httpListenAddr, p.httpMux) {
|
||||||
case net.ErrClosed, http.ErrServerClosed:
|
case net.ErrClosed, http.ErrServerClosed:
|
||||||
logrus.Info("Stopped listening on ", p.httpListenAddr)
|
logrus.Info("Stopped listening on ", p.httpListenAddr)
|
||||||
default:
|
default:
|
||||||
|
Loading…
Reference in New Issue
Block a user