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