mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-22 14:23:09 -06:00
Review comments @Kegsay
This commit is contained in:
parent
6afd1daeb8
commit
9c51aa365f
|
|
@ -39,7 +39,7 @@ func main() {
|
||||||
keyAPI := base.KeyServerHTTPClient()
|
keyAPI := base.KeyServerHTTPClient()
|
||||||
|
|
||||||
clientapi.AddPublicRoutes(
|
clientapi.AddPublicRoutes(
|
||||||
base.ExternalClientAPIMux, &base.Cfg.ClientAPI, base.KafkaProducer, deviceDB, accountDB, federation,
|
base.PublicClientAPIMux, &base.Cfg.ClientAPI, base.KafkaProducer, deviceDB, accountDB, federation,
|
||||||
rsAPI, eduInputAPI, asQuery, stateAPI, transactions.New(), fsAPI, userAPI, keyAPI, nil,
|
rsAPI, eduInputAPI, asQuery, stateAPI, transactions.New(), fsAPI, userAPI, keyAPI, nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -192,21 +192,21 @@ func main() {
|
||||||
ExtPublicRoomsProvider: provider,
|
ExtPublicRoomsProvider: provider,
|
||||||
}
|
}
|
||||||
monolith.AddAllPublicRoutes(
|
monolith.AddAllPublicRoutes(
|
||||||
base.Base.ExternalClientAPIMux,
|
base.Base.PublicClientAPIMux,
|
||||||
base.Base.ExternalFederationAPIMux,
|
base.Base.PublicFederationAPIMux,
|
||||||
base.Base.ExternalKeyAPIMux,
|
base.Base.PublicKeyAPIMux,
|
||||||
base.Base.ExternalMediaAPIMux,
|
base.Base.PublicMediaAPIMux,
|
||||||
)
|
)
|
||||||
|
|
||||||
httpRouter := mux.NewRouter()
|
httpRouter := mux.NewRouter()
|
||||||
httpRouter.PathPrefix(httputil.InternalPathPrefix).Handler(base.Base.InternalAPIMux)
|
httpRouter.PathPrefix(httputil.InternalPathPrefix).Handler(base.Base.InternalAPIMux)
|
||||||
httpRouter.PathPrefix(httputil.ExternalClientPathPrefix).Handler(base.Base.ExternalClientAPIMux)
|
httpRouter.PathPrefix(httputil.PublicClientPathPrefix).Handler(base.Base.PublicClientAPIMux)
|
||||||
httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.Base.ExternalMediaAPIMux)
|
httpRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(base.Base.PublicMediaAPIMux)
|
||||||
|
|
||||||
libp2pRouter := mux.NewRouter()
|
libp2pRouter := mux.NewRouter()
|
||||||
libp2pRouter.PathPrefix(httputil.ExternalFederationPathPrefix).Handler(base.Base.ExternalFederationAPIMux)
|
libp2pRouter.PathPrefix(httputil.PublicFederationPathPrefix).Handler(base.Base.PublicFederationAPIMux)
|
||||||
libp2pRouter.PathPrefix(httputil.ExternalKeyPathPrefix).Handler(base.Base.ExternalKeyAPIMux)
|
libp2pRouter.PathPrefix(httputil.PublicKeyPathPrefix).Handler(base.Base.PublicKeyAPIMux)
|
||||||
libp2pRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.Base.ExternalMediaAPIMux)
|
libp2pRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(base.Base.PublicMediaAPIMux)
|
||||||
|
|
||||||
// Expose the matrix APIs directly rather than putting them under a /api path.
|
// Expose the matrix APIs directly rather than putting them under a /api path.
|
||||||
go func() {
|
go func() {
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ func main() {
|
||||||
|
|
||||||
rsComponent.SetFederationSenderAPI(fsAPI)
|
rsComponent.SetFederationSenderAPI(fsAPI)
|
||||||
|
|
||||||
embed.Embed(base.ExternalClientAPIMux, *instancePort, "Yggdrasil Demo")
|
embed.Embed(base.PublicClientAPIMux, *instancePort, "Yggdrasil Demo")
|
||||||
|
|
||||||
monolith := setup.Monolith{
|
monolith := setup.Monolith{
|
||||||
Config: base.Cfg,
|
Config: base.Cfg,
|
||||||
|
|
@ -157,20 +157,20 @@ func main() {
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
monolith.AddAllPublicRoutes(
|
monolith.AddAllPublicRoutes(
|
||||||
base.ExternalClientAPIMux,
|
base.PublicClientAPIMux,
|
||||||
base.ExternalFederationAPIMux,
|
base.PublicFederationAPIMux,
|
||||||
base.ExternalKeyAPIMux,
|
base.PublicKeyAPIMux,
|
||||||
base.ExternalMediaAPIMux,
|
base.PublicMediaAPIMux,
|
||||||
)
|
)
|
||||||
|
|
||||||
httpRouter := mux.NewRouter()
|
httpRouter := mux.NewRouter()
|
||||||
httpRouter.PathPrefix(httputil.InternalPathPrefix).Handler(base.InternalAPIMux)
|
httpRouter.PathPrefix(httputil.InternalPathPrefix).Handler(base.InternalAPIMux)
|
||||||
httpRouter.PathPrefix(httputil.ExternalClientPathPrefix).Handler(base.ExternalClientAPIMux)
|
httpRouter.PathPrefix(httputil.PublicClientPathPrefix).Handler(base.PublicClientAPIMux)
|
||||||
httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.ExternalMediaAPIMux)
|
httpRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(base.PublicMediaAPIMux)
|
||||||
|
|
||||||
yggRouter := mux.NewRouter()
|
yggRouter := mux.NewRouter()
|
||||||
yggRouter.PathPrefix(httputil.ExternalFederationPathPrefix).Handler(base.ExternalFederationAPIMux)
|
yggRouter.PathPrefix(httputil.PublicFederationPathPrefix).Handler(base.PublicFederationAPIMux)
|
||||||
yggRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.ExternalMediaAPIMux)
|
yggRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(base.PublicMediaAPIMux)
|
||||||
|
|
||||||
// Build both ends of a HTTP multiplex.
|
// Build both ends of a HTTP multiplex.
|
||||||
httpServer := &http.Server{
|
httpServer := &http.Server{
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ func main() {
|
||||||
keyAPI := base.KeyServerHTTPClient()
|
keyAPI := base.KeyServerHTTPClient()
|
||||||
|
|
||||||
federationapi.AddPublicRoutes(
|
federationapi.AddPublicRoutes(
|
||||||
base.ExternalFederationAPIMux, base.ExternalKeyAPIMux,
|
base.PublicFederationAPIMux, base.PublicKeyAPIMux,
|
||||||
&base.Cfg.FederationAPI, userAPI, federation, keyRing,
|
&base.Cfg.FederationAPI, userAPI, federation, keyRing,
|
||||||
rsAPI, fsAPI, base.EDUServerClient(), base.CurrentStateAPIClient(), keyAPI,
|
rsAPI, fsAPI, base.EDUServerClient(), base.CurrentStateAPIClient(), keyAPI,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ func main() {
|
||||||
userAPI := base.UserAPIClient()
|
userAPI := base.UserAPIClient()
|
||||||
client := gomatrixserverlib.NewClient(cfg.FederationSender.DisableTLSValidation)
|
client := gomatrixserverlib.NewClient(cfg.FederationSender.DisableTLSValidation)
|
||||||
|
|
||||||
mediaapi.AddPublicRoutes(base.ExternalMediaAPIMux, &base.Cfg.MediaAPI, userAPI, client)
|
mediaapi.AddPublicRoutes(base.PublicMediaAPIMux, &base.Cfg.MediaAPI, userAPI, client)
|
||||||
|
|
||||||
base.SetupAndServeHTTP(
|
base.SetupAndServeHTTP(
|
||||||
base.Cfg.MediaAPI.InternalAPI.Listen,
|
base.Cfg.MediaAPI.InternalAPI.Listen,
|
||||||
|
|
|
||||||
|
|
@ -146,10 +146,10 @@ func main() {
|
||||||
KeyAPI: keyAPI,
|
KeyAPI: keyAPI,
|
||||||
}
|
}
|
||||||
monolith.AddAllPublicRoutes(
|
monolith.AddAllPublicRoutes(
|
||||||
base.ExternalClientAPIMux,
|
base.PublicClientAPIMux,
|
||||||
base.ExternalFederationAPIMux,
|
base.PublicFederationAPIMux,
|
||||||
base.ExternalKeyAPIMux,
|
base.PublicKeyAPIMux,
|
||||||
base.ExternalMediaAPIMux,
|
base.PublicMediaAPIMux,
|
||||||
)
|
)
|
||||||
|
|
||||||
// Expose the matrix APIs directly rather than putting them under a /api path.
|
// Expose the matrix APIs directly rather than putting them under a /api path.
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ func main() {
|
||||||
rsAPI := base.RoomserverHTTPClient()
|
rsAPI := base.RoomserverHTTPClient()
|
||||||
|
|
||||||
syncapi.AddPublicRoutes(
|
syncapi.AddPublicRoutes(
|
||||||
base.ExternalClientAPIMux, base.KafkaConsumer, userAPI, rsAPI,
|
base.PublicClientAPIMux, base.KafkaConsumer, userAPI, rsAPI,
|
||||||
base.KeyServerHTTPClient(), base.CurrentStateAPIClient(),
|
base.KeyServerHTTPClient(), base.CurrentStateAPIClient(),
|
||||||
federation, &cfg.SyncAPI,
|
federation, &cfg.SyncAPI,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -236,20 +236,20 @@ func main() {
|
||||||
ExtPublicRoomsProvider: p2pPublicRoomProvider,
|
ExtPublicRoomsProvider: p2pPublicRoomProvider,
|
||||||
}
|
}
|
||||||
monolith.AddAllPublicRoutes(
|
monolith.AddAllPublicRoutes(
|
||||||
base.ExternalClientAPIMux,
|
base.PublicClientAPIMux,
|
||||||
base.ExternalFederationAPIMux,
|
base.PublicFederationAPIMux,
|
||||||
base.ExternalKeyAPIMux,
|
base.PublicKeyAPIMux,
|
||||||
base.ExternalMediaAPIMux,
|
base.PublicMediaAPIMux,
|
||||||
)
|
)
|
||||||
|
|
||||||
httpRouter := mux.NewRouter()
|
httpRouter := mux.NewRouter()
|
||||||
httpRouter.PathPrefix(httputil.InternalPathPrefix).Handler(base.InternalAPIMux)
|
httpRouter.PathPrefix(httputil.InternalPathPrefix).Handler(base.InternalAPIMux)
|
||||||
httpRouter.PathPrefix(httputil.ExternalClientPathPrefix).Handler(base.ExternalClientAPIMux)
|
httpRouter.PathPrefix(httputil.PublicClientPathPrefix).Handler(base.PublicClientAPIMux)
|
||||||
httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.ExternalMediaAPIMux)
|
httpRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(base.PublicMediaAPIMux)
|
||||||
|
|
||||||
libp2pRouter := mux.NewRouter()
|
libp2pRouter := mux.NewRouter()
|
||||||
libp2pRouter.PathPrefix(httputil.ExternalFederationPathPrefix).Handler(base.ExternalFederationAPIMux)
|
libp2pRouter.PathPrefix(httputil.PublicFederationPathPrefix).Handler(base.PublicFederationAPIMux)
|
||||||
libp2pRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.ExternalMediaAPIMux)
|
libp2pRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(base.PublicMediaAPIMux)
|
||||||
|
|
||||||
// Expose the matrix APIs via libp2p-js - for federation traffic
|
// Expose the matrix APIs via libp2p-js - for federation traffic
|
||||||
if node != nil {
|
if node != nil {
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,9 @@
|
||||||
package httputil
|
package httputil
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ExternalClientPathPrefix = "/_matrix/client/"
|
PublicClientPathPrefix = "/_matrix/client/"
|
||||||
ExternalFederationPathPrefix = "/_matrix/federation/"
|
PublicFederationPathPrefix = "/_matrix/federation/"
|
||||||
ExternalKeyPathPrefix = "/_matrix/key/"
|
PublicKeyPathPrefix = "/_matrix/key/"
|
||||||
ExternalMediaPathPrefix = "/_matrix/media/"
|
PublicMediaPathPrefix = "/_matrix/media/"
|
||||||
InternalPathPrefix = "/api/"
|
InternalPathPrefix = "/api/"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/internal/sqlutil"
|
"github.com/matrix-org/dendrite/internal/sqlutil"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/matrix-org/naffka"
|
"github.com/matrix-org/naffka"
|
||||||
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
"github.com/matrix-org/dendrite/userapi/storage/accounts"
|
"github.com/matrix-org/dendrite/userapi/storage/accounts"
|
||||||
|
|
@ -64,10 +65,10 @@ import (
|
||||||
type BaseDendrite struct {
|
type BaseDendrite struct {
|
||||||
componentName string
|
componentName string
|
||||||
tracerCloser io.Closer
|
tracerCloser io.Closer
|
||||||
ExternalClientAPIMux *mux.Router
|
PublicClientAPIMux *mux.Router
|
||||||
ExternalFederationAPIMux *mux.Router
|
PublicFederationAPIMux *mux.Router
|
||||||
ExternalKeyAPIMux *mux.Router
|
PublicKeyAPIMux *mux.Router
|
||||||
ExternalMediaAPIMux *mux.Router
|
PublicMediaAPIMux *mux.Router
|
||||||
InternalAPIMux *mux.Router
|
InternalAPIMux *mux.Router
|
||||||
UseHTTPAPIs bool
|
UseHTTPAPIs bool
|
||||||
httpClient *http.Client
|
httpClient *http.Client
|
||||||
|
|
@ -142,10 +143,10 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, useHTTPAPIs boo
|
||||||
tracerCloser: closer,
|
tracerCloser: closer,
|
||||||
Cfg: cfg,
|
Cfg: cfg,
|
||||||
Caches: cache,
|
Caches: cache,
|
||||||
ExternalClientAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.ExternalClientPathPrefix).Subrouter().UseEncodedPath(),
|
PublicClientAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicClientPathPrefix).Subrouter().UseEncodedPath(),
|
||||||
ExternalFederationAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.ExternalFederationPathPrefix).Subrouter().UseEncodedPath(),
|
PublicFederationAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicFederationPathPrefix).Subrouter().UseEncodedPath(),
|
||||||
ExternalKeyAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.ExternalKeyPathPrefix).Subrouter().UseEncodedPath(),
|
PublicKeyAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicKeyPathPrefix).Subrouter().UseEncodedPath(),
|
||||||
ExternalMediaAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.ExternalMediaPathPrefix).Subrouter().UseEncodedPath(),
|
PublicMediaAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicMediaPathPrefix).Subrouter().UseEncodedPath(),
|
||||||
InternalAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.InternalPathPrefix).Subrouter().UseEncodedPath(),
|
InternalAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.InternalPathPrefix).Subrouter().UseEncodedPath(),
|
||||||
httpClient: &client,
|
httpClient: &client,
|
||||||
KafkaConsumer: kafkaConsumer,
|
KafkaConsumer: kafkaConsumer,
|
||||||
|
|
@ -272,8 +273,6 @@ func (b *BaseDendrite) SetupAndServeHTTP(
|
||||||
internalHTTPAddr, externalHTTPAddr config.HTTPAddress,
|
internalHTTPAddr, externalHTTPAddr config.HTTPAddress,
|
||||||
certFile, keyFile *string,
|
certFile, keyFile *string,
|
||||||
) {
|
) {
|
||||||
block := make(chan struct{})
|
|
||||||
|
|
||||||
internalAddr, _ := internalHTTPAddr.Address()
|
internalAddr, _ := internalHTTPAddr.Address()
|
||||||
externalAddr, _ := externalHTTPAddr.Address()
|
externalAddr, _ := externalHTTPAddr.Address()
|
||||||
|
|
||||||
|
|
@ -297,14 +296,16 @@ func (b *BaseDendrite) SetupAndServeHTTP(
|
||||||
}
|
}
|
||||||
|
|
||||||
internalRouter.PathPrefix(httputil.InternalPathPrefix).Handler(b.InternalAPIMux)
|
internalRouter.PathPrefix(httputil.InternalPathPrefix).Handler(b.InternalAPIMux)
|
||||||
|
if b.Cfg.Global.Metrics.Enabled {
|
||||||
|
internalRouter.Handle("/metrics", httputil.WrapHandlerInBasicAuth(promhttp.Handler(), b.Cfg.Global.Metrics.BasicAuth))
|
||||||
|
}
|
||||||
|
|
||||||
externalRouter.PathPrefix(httputil.ExternalClientPathPrefix).Handler(b.ExternalClientAPIMux)
|
externalRouter.PathPrefix(httputil.PublicClientPathPrefix).Handler(b.PublicClientAPIMux)
|
||||||
externalRouter.PathPrefix(httputil.ExternalKeyPathPrefix).Handler(b.ExternalKeyAPIMux)
|
externalRouter.PathPrefix(httputil.PublicKeyPathPrefix).Handler(b.PublicKeyAPIMux)
|
||||||
externalRouter.PathPrefix(httputil.ExternalFederationPathPrefix).Handler(b.ExternalFederationAPIMux)
|
externalRouter.PathPrefix(httputil.PublicFederationPathPrefix).Handler(b.PublicFederationAPIMux)
|
||||||
externalRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(b.ExternalMediaAPIMux)
|
externalRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(b.PublicMediaAPIMux)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer close(block)
|
|
||||||
logrus.Infof("Starting %s listener on %s", b.componentName, externalServ.Addr)
|
logrus.Infof("Starting %s listener on %s", b.componentName, externalServ.Addr)
|
||||||
if certFile != nil && keyFile != nil {
|
if certFile != nil && keyFile != nil {
|
||||||
if err := externalServ.ListenAndServeTLS(*certFile, *keyFile); err != nil {
|
if err := externalServ.ListenAndServeTLS(*certFile, *keyFile); err != nil {
|
||||||
|
|
@ -320,7 +321,6 @@ func (b *BaseDendrite) SetupAndServeHTTP(
|
||||||
|
|
||||||
if internalAddr != "" && internalAddr != externalAddr {
|
if internalAddr != "" && internalAddr != externalAddr {
|
||||||
go func() {
|
go func() {
|
||||||
defer close(block)
|
|
||||||
logrus.Infof("Starting %s listener on %s", b.componentName, internalServ.Addr)
|
logrus.Infof("Starting %s listener on %s", b.componentName, internalServ.Addr)
|
||||||
if certFile != nil && keyFile != nil {
|
if certFile != nil && keyFile != nil {
|
||||||
if err := internalServ.ListenAndServeTLS(*certFile, *keyFile); err != nil {
|
if err := internalServ.ListenAndServeTLS(*certFile, *keyFile); err != nil {
|
||||||
|
|
@ -335,7 +335,7 @@ func (b *BaseDendrite) SetupAndServeHTTP(
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
<-block
|
select {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// setupKafka creates kafka consumer/producer pair from the config.
|
// setupKafka creates kafka consumer/producer pair from the config.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue