mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-21 22:03:10 -06:00
Break apart client/federation/key/media muxes
This commit is contained in:
parent
8382a9dcc2
commit
89ab97be74
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/appservice"
|
"github.com/matrix-org/dendrite/appservice"
|
||||||
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/signing"
|
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/signing"
|
||||||
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/yggconn"
|
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/yggconn"
|
||||||
|
|
@ -18,6 +19,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/federationsender"
|
"github.com/matrix-org/dendrite/federationsender"
|
||||||
"github.com/matrix-org/dendrite/federationsender/api"
|
"github.com/matrix-org/dendrite/federationsender/api"
|
||||||
"github.com/matrix-org/dendrite/internal/config"
|
"github.com/matrix-org/dendrite/internal/config"
|
||||||
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/matrix-org/dendrite/internal/setup"
|
"github.com/matrix-org/dendrite/internal/setup"
|
||||||
"github.com/matrix-org/dendrite/keyserver"
|
"github.com/matrix-org/dendrite/keyserver"
|
||||||
"github.com/matrix-org/dendrite/roomserver"
|
"github.com/matrix-org/dendrite/roomserver"
|
||||||
|
|
@ -169,7 +171,21 @@ func (m *DendriteMonolith) Start() {
|
||||||
ygg, fsAPI, federation,
|
ygg, fsAPI, federation,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
monolith.AddAllPublicRoutes(base.PublicAPIMux)
|
monolith.AddAllPublicRoutes(
|
||||||
|
base.ExternalClientAPIMux,
|
||||||
|
base.ExternalFederationAPIMux,
|
||||||
|
base.ExternalKeyAPIMux,
|
||||||
|
base.ExternalMediaAPIMux,
|
||||||
|
)
|
||||||
|
|
||||||
|
httpRouter := mux.NewRouter()
|
||||||
|
httpRouter.PathPrefix(httputil.InternalPathPrefix).Handler(base.InternalAPIMux)
|
||||||
|
httpRouter.PathPrefix(httputil.ExternalClientPathPrefix).Handler(base.ExternalClientAPIMux)
|
||||||
|
httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.ExternalMediaAPIMux)
|
||||||
|
|
||||||
|
yggRouter := mux.NewRouter()
|
||||||
|
httpRouter.PathPrefix(httputil.ExternalFederationPathPrefix).Handler(base.ExternalClientAPIMux)
|
||||||
|
httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.ExternalMediaAPIMux)
|
||||||
|
|
||||||
// Build both ends of a HTTP multiplex.
|
// Build both ends of a HTTP multiplex.
|
||||||
m.httpServer = &http.Server{
|
m.httpServer = &http.Server{
|
||||||
|
|
@ -181,7 +197,7 @@ func (m *DendriteMonolith) Start() {
|
||||||
BaseContext: func(_ net.Listener) context.Context {
|
BaseContext: func(_ net.Listener) context.Context {
|
||||||
return context.Background()
|
return context.Background()
|
||||||
},
|
},
|
||||||
Handler: base.PublicAPIMux,
|
Handler: yggRouter,
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
|
@ -189,8 +205,8 @@ func (m *DendriteMonolith) Start() {
|
||||||
m.logger.Fatal(m.httpServer.Serve(ygg))
|
m.logger.Fatal(m.httpServer.Serve(ygg))
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
m.logger.Info("Listening on ", m.BaseURL())
|
logrus.Info("Listening on ", m.listener.Addr())
|
||||||
m.logger.Fatal(m.httpServer.Serve(m.listener))
|
logrus.Fatal(http.Serve(m.listener, httpRouter))
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
logrus.Info("Sending wake-up message to known nodes")
|
logrus.Info("Sending wake-up message to known nodes")
|
||||||
|
|
|
||||||
|
|
@ -40,9 +40,9 @@ import (
|
||||||
"github.com/matrix-org/util"
|
"github.com/matrix-org/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
const pathPrefixV1 = "/client/api/v1"
|
const pathPrefixV1 = "/api/v1"
|
||||||
const pathPrefixR0 = "/client/r0"
|
const pathPrefixR0 = "/r0"
|
||||||
const pathPrefixUnstable = "/client/unstable"
|
const pathPrefixUnstable = "/unstable"
|
||||||
|
|
||||||
// Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
|
// Setup registers HTTP handlers with the given ServeMux. It also supplies the given http.Client
|
||||||
// to clients which need to make outbound HTTP requests.
|
// to clients which need to make outbound HTTP requests.
|
||||||
|
|
@ -68,7 +68,7 @@ func Setup(
|
||||||
) {
|
) {
|
||||||
userInteractiveAuth := auth.NewUserInteractive(accountDB.GetAccountByPassword, cfg)
|
userInteractiveAuth := auth.NewUserInteractive(accountDB.GetAccountByPassword, cfg)
|
||||||
|
|
||||||
publicAPIMux.Handle("/client/versions",
|
publicAPIMux.Handle("/versions",
|
||||||
httputil.MakeExternalAPI("versions", func(req *http.Request) util.JSONResponse {
|
httputil.MakeExternalAPI("versions", func(req *http.Request) util.JSONResponse {
|
||||||
return util.JSONResponse{
|
return util.JSONResponse{
|
||||||
Code: http.StatusOK,
|
Code: http.StatusOK,
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ func main() {
|
||||||
keyAPI := base.KeyServerHTTPClient()
|
keyAPI := base.KeyServerHTTPClient()
|
||||||
|
|
||||||
clientapi.AddPublicRoutes(
|
clientapi.AddPublicRoutes(
|
||||||
base.PublicAPIMux, &base.Cfg.ClientAPI, base.KafkaProducer, deviceDB, accountDB, federation,
|
base.ExternalClientAPIMux, &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,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
gostream "github.com/libp2p/go-libp2p-gostream"
|
gostream "github.com/libp2p/go-libp2p-gostream"
|
||||||
p2phttp "github.com/libp2p/go-libp2p-http"
|
p2phttp "github.com/libp2p/go-libp2p-http"
|
||||||
p2pdisc "github.com/libp2p/go-libp2p/p2p/discovery"
|
p2pdisc "github.com/libp2p/go-libp2p/p2p/discovery"
|
||||||
|
|
@ -31,6 +32,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/eduserver"
|
"github.com/matrix-org/dendrite/eduserver"
|
||||||
"github.com/matrix-org/dendrite/federationsender"
|
"github.com/matrix-org/dendrite/federationsender"
|
||||||
"github.com/matrix-org/dendrite/internal/config"
|
"github.com/matrix-org/dendrite/internal/config"
|
||||||
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/matrix-org/dendrite/internal/setup"
|
"github.com/matrix-org/dendrite/internal/setup"
|
||||||
"github.com/matrix-org/dendrite/keyserver"
|
"github.com/matrix-org/dendrite/keyserver"
|
||||||
"github.com/matrix-org/dendrite/roomserver"
|
"github.com/matrix-org/dendrite/roomserver"
|
||||||
|
|
@ -189,13 +191,28 @@ func main() {
|
||||||
KeyAPI: keyAPI,
|
KeyAPI: keyAPI,
|
||||||
ExtPublicRoomsProvider: provider,
|
ExtPublicRoomsProvider: provider,
|
||||||
}
|
}
|
||||||
monolith.AddAllPublicRoutes(base.Base.PublicAPIMux)
|
monolith.AddAllPublicRoutes(
|
||||||
|
base.Base.ExternalClientAPIMux,
|
||||||
|
base.Base.ExternalFederationAPIMux,
|
||||||
|
base.Base.ExternalKeyAPIMux,
|
||||||
|
base.Base.ExternalMediaAPIMux,
|
||||||
|
)
|
||||||
|
|
||||||
|
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)
|
||||||
|
|
||||||
|
libp2pRouter := mux.NewRouter()
|
||||||
|
httpRouter.PathPrefix(httputil.ExternalFederationPathPrefix).Handler(base.Base.ExternalClientAPIMux)
|
||||||
|
httpRouter.PathPrefix(httputil.ExternalKeyPathPrefix).Handler(base.Base.ExternalClientAPIMux)
|
||||||
|
httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.Base.ExternalMediaAPIMux)
|
||||||
|
|
||||||
// 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() {
|
||||||
httpBindAddr := fmt.Sprintf(":%d", *instancePort)
|
httpBindAddr := fmt.Sprintf(":%d", *instancePort)
|
||||||
logrus.Info("Listening on ", httpBindAddr)
|
logrus.Info("Listening on ", httpBindAddr)
|
||||||
logrus.Fatal(http.ListenAndServe(httpBindAddr, base.Base.PublicAPIMux))
|
logrus.Fatal(http.ListenAndServe(httpBindAddr, httpRouter))
|
||||||
}()
|
}()
|
||||||
// Expose the matrix APIs also via libp2p
|
// Expose the matrix APIs also via libp2p
|
||||||
if base.LibP2P != nil {
|
if base.LibP2P != nil {
|
||||||
|
|
@ -208,7 +225,7 @@ func main() {
|
||||||
defer func() {
|
defer func() {
|
||||||
logrus.Fatal(listener.Close())
|
logrus.Fatal(listener.Close())
|
||||||
}()
|
}()
|
||||||
logrus.Fatal(http.Serve(listener, base.Base.PublicAPIMux))
|
logrus.Fatal(http.Serve(listener, libp2pRouter))
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/appservice"
|
"github.com/matrix-org/dendrite/appservice"
|
||||||
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/embed"
|
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/embed"
|
||||||
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/signing"
|
"github.com/matrix-org/dendrite/cmd/dendrite-demo-yggdrasil/signing"
|
||||||
|
|
@ -35,6 +36,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/federationsender/api"
|
"github.com/matrix-org/dendrite/federationsender/api"
|
||||||
"github.com/matrix-org/dendrite/internal"
|
"github.com/matrix-org/dendrite/internal"
|
||||||
"github.com/matrix-org/dendrite/internal/config"
|
"github.com/matrix-org/dendrite/internal/config"
|
||||||
|
"github.com/matrix-org/dendrite/internal/httputil"
|
||||||
"github.com/matrix-org/dendrite/internal/setup"
|
"github.com/matrix-org/dendrite/internal/setup"
|
||||||
"github.com/matrix-org/dendrite/keyserver"
|
"github.com/matrix-org/dendrite/keyserver"
|
||||||
"github.com/matrix-org/dendrite/roomserver"
|
"github.com/matrix-org/dendrite/roomserver"
|
||||||
|
|
@ -131,7 +133,7 @@ func main() {
|
||||||
|
|
||||||
rsComponent.SetFederationSenderAPI(fsAPI)
|
rsComponent.SetFederationSenderAPI(fsAPI)
|
||||||
|
|
||||||
embed.Embed(base.PublicAPIMux, *instancePort, "Yggdrasil Demo")
|
embed.Embed(base.ExternalClientAPIMux, *instancePort, "Yggdrasil Demo")
|
||||||
|
|
||||||
monolith := setup.Monolith{
|
monolith := setup.Monolith{
|
||||||
Config: base.Cfg,
|
Config: base.Cfg,
|
||||||
|
|
@ -154,7 +156,21 @@ func main() {
|
||||||
ygg, fsAPI, federation,
|
ygg, fsAPI, federation,
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
monolith.AddAllPublicRoutes(base.PublicAPIMux)
|
monolith.AddAllPublicRoutes(
|
||||||
|
base.ExternalClientAPIMux,
|
||||||
|
base.ExternalFederationAPIMux,
|
||||||
|
base.ExternalKeyAPIMux,
|
||||||
|
base.ExternalMediaAPIMux,
|
||||||
|
)
|
||||||
|
|
||||||
|
httpRouter := mux.NewRouter()
|
||||||
|
httpRouter.PathPrefix(httputil.InternalPathPrefix).Handler(base.InternalAPIMux)
|
||||||
|
httpRouter.PathPrefix(httputil.ExternalClientPathPrefix).Handler(base.ExternalClientAPIMux)
|
||||||
|
httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.ExternalMediaAPIMux)
|
||||||
|
|
||||||
|
yggRouter := mux.NewRouter()
|
||||||
|
httpRouter.PathPrefix(httputil.ExternalFederationPathPrefix).Handler(base.ExternalClientAPIMux)
|
||||||
|
httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.ExternalMediaAPIMux)
|
||||||
|
|
||||||
// Build both ends of a HTTP multiplex.
|
// Build both ends of a HTTP multiplex.
|
||||||
httpServer := &http.Server{
|
httpServer := &http.Server{
|
||||||
|
|
@ -166,7 +182,7 @@ func main() {
|
||||||
BaseContext: func(_ net.Listener) context.Context {
|
BaseContext: func(_ net.Listener) context.Context {
|
||||||
return context.Background()
|
return context.Background()
|
||||||
},
|
},
|
||||||
Handler: base.PublicAPIMux,
|
Handler: yggRouter,
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
|
@ -176,7 +192,7 @@ func main() {
|
||||||
go func() {
|
go func() {
|
||||||
httpBindAddr := fmt.Sprintf(":%d", *instancePort)
|
httpBindAddr := fmt.Sprintf(":%d", *instancePort)
|
||||||
logrus.Info("Listening on ", httpBindAddr)
|
logrus.Info("Listening on ", httpBindAddr)
|
||||||
logrus.Fatal(http.ListenAndServe(httpBindAddr, base.PublicAPIMux))
|
logrus.Fatal(http.ListenAndServe(httpBindAddr, httpRouter))
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
logrus.Info("Sending wake-up message to known nodes")
|
logrus.Info("Sending wake-up message to known nodes")
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,8 @@ func main() {
|
||||||
keyAPI := base.KeyServerHTTPClient()
|
keyAPI := base.KeyServerHTTPClient()
|
||||||
|
|
||||||
federationapi.AddPublicRoutes(
|
federationapi.AddPublicRoutes(
|
||||||
base.PublicAPIMux, &base.Cfg.FederationAPI, userAPI, federation, keyRing,
|
base.ExternalFederationAPIMux, base.ExternalKeyAPIMux,
|
||||||
|
&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.PublicAPIMux, &base.Cfg.MediaAPI, userAPI, client)
|
mediaapi.AddPublicRoutes(base.ExternalMediaAPIMux, &base.Cfg.MediaAPI, userAPI, client)
|
||||||
|
|
||||||
base.SetupAndServeHTTP(
|
base.SetupAndServeHTTP(
|
||||||
base.Cfg.MediaAPI.InternalAPI.Listen,
|
base.Cfg.MediaAPI.InternalAPI.Listen,
|
||||||
|
|
|
||||||
|
|
@ -145,7 +145,12 @@ func main() {
|
||||||
UserAPI: userAPI,
|
UserAPI: userAPI,
|
||||||
KeyAPI: keyAPI,
|
KeyAPI: keyAPI,
|
||||||
}
|
}
|
||||||
monolith.AddAllPublicRoutes(base.PublicAPIMux)
|
monolith.AddAllPublicRoutes(
|
||||||
|
base.ExternalClientAPIMux,
|
||||||
|
base.ExternalFederationAPIMux,
|
||||||
|
base.ExternalKeyAPIMux,
|
||||||
|
base.ExternalMediaAPIMux,
|
||||||
|
)
|
||||||
|
|
||||||
// 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() {
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,10 @@ func main() {
|
||||||
rsAPI := base.RoomserverHTTPClient()
|
rsAPI := base.RoomserverHTTPClient()
|
||||||
|
|
||||||
syncapi.AddPublicRoutes(
|
syncapi.AddPublicRoutes(
|
||||||
base.PublicAPIMux, base.KafkaConsumer, userAPI, rsAPI, base.KeyServerHTTPClient(), base.CurrentStateAPIClient(),
|
base.ExternalClientAPIMux, base.KafkaConsumer, userAPI, rsAPI,
|
||||||
federation, &cfg.SyncAPI)
|
base.KeyServerHTTPClient(), base.CurrentStateAPIClient(),
|
||||||
|
federation, &cfg.SyncAPI,
|
||||||
|
)
|
||||||
|
|
||||||
base.SetupAndServeHTTP(
|
base.SetupAndServeHTTP(
|
||||||
base.Cfg.SyncAPI.InternalAPI.Listen,
|
base.Cfg.SyncAPI.InternalAPI.Listen,
|
||||||
|
|
|
||||||
|
|
@ -235,18 +235,28 @@ func main() {
|
||||||
//ServerKeyAPI: serverKeyAPI,
|
//ServerKeyAPI: serverKeyAPI,
|
||||||
ExtPublicRoomsProvider: p2pPublicRoomProvider,
|
ExtPublicRoomsProvider: p2pPublicRoomProvider,
|
||||||
}
|
}
|
||||||
monolith.AddAllPublicRoutes(base.PublicAPIMux)
|
monolith.AddAllPublicRoutes(
|
||||||
|
base.ExternalClientAPIMux,
|
||||||
|
base.ExternalFederationAPIMux,
|
||||||
|
base.ExternalKeyAPIMux,
|
||||||
|
base.ExternalMediaAPIMux,
|
||||||
|
)
|
||||||
|
|
||||||
router := mux.NewRouter()
|
httpRouter := mux.NewRouter()
|
||||||
router.PathPrefix(httputil.InternalPathPrefix).Handler(base.InternalAPIMux)
|
httpRouter.PathPrefix(httputil.InternalPathPrefix).Handler(base.InternalAPIMux)
|
||||||
router.PathPrefix(httputil.PublicPathPrefix).Handler(base.PublicAPIMux)
|
httpRouter.PathPrefix(httputil.ExternalClientPathPrefix).Handler(base.ExternalClientAPIMux)
|
||||||
|
httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.ExternalMediaAPIMux)
|
||||||
|
|
||||||
|
libp2pRouter := mux.NewRouter()
|
||||||
|
httpRouter.PathPrefix(httputil.ExternalFederationPathPrefix).Handler(base.ExternalClientAPIMux)
|
||||||
|
httpRouter.PathPrefix(httputil.ExternalMediaPathPrefix).Handler(base.ExternalMediaAPIMux)
|
||||||
|
|
||||||
// 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 {
|
||||||
go func() {
|
go func() {
|
||||||
logrus.Info("Listening on libp2p-js host ID ", node.Id)
|
logrus.Info("Listening on libp2p-js host ID ", node.Id)
|
||||||
s := JSServer{
|
s := JSServer{
|
||||||
Mux: base.PublicAPIMux,
|
Mux: libp2pRouter,
|
||||||
}
|
}
|
||||||
s.ListenAndServe("p2p")
|
s.ListenAndServe("p2p")
|
||||||
}()
|
}()
|
||||||
|
|
@ -256,7 +266,7 @@ func main() {
|
||||||
go func() {
|
go func() {
|
||||||
logrus.Info("Listening for service-worker fetch traffic")
|
logrus.Info("Listening for service-worker fetch traffic")
|
||||||
s := JSServer{
|
s := JSServer{
|
||||||
Mux: router,
|
Mux: httpRouter,
|
||||||
}
|
}
|
||||||
s.ListenAndServe("fetch")
|
s.ListenAndServe("fetch")
|
||||||
}()
|
}()
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import (
|
||||||
|
|
||||||
// AddPublicRoutes sets up and registers HTTP handlers on the base API muxes for the FederationAPI component.
|
// AddPublicRoutes sets up and registers HTTP handlers on the base API muxes for the FederationAPI component.
|
||||||
func AddPublicRoutes(
|
func AddPublicRoutes(
|
||||||
router *mux.Router,
|
fedRouter, keyRouter *mux.Router,
|
||||||
cfg *config.FederationAPI,
|
cfg *config.FederationAPI,
|
||||||
userAPI userapi.UserInternalAPI,
|
userAPI userapi.UserInternalAPI,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *gomatrixserverlib.FederationClient,
|
||||||
|
|
@ -42,7 +42,7 @@ func AddPublicRoutes(
|
||||||
keyAPI keyserverAPI.KeyInternalAPI,
|
keyAPI keyserverAPI.KeyInternalAPI,
|
||||||
) {
|
) {
|
||||||
routing.Setup(
|
routing.Setup(
|
||||||
router, cfg, rsAPI,
|
fedRouter, keyRouter, cfg, rsAPI,
|
||||||
eduAPI, federationSenderAPI, keyRing,
|
eduAPI, federationSenderAPI, keyRing,
|
||||||
federation, userAPI, stateAPI, keyAPI,
|
federation, userAPI, stateAPI, keyAPI,
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,8 @@ func TestRoomsV3URLEscapeDoNot404(t *testing.T) {
|
||||||
fsAPI := base.FederationSenderHTTPClient()
|
fsAPI := base.FederationSenderHTTPClient()
|
||||||
// TODO: This is pretty fragile, as if anything calls anything on these nils this test will break.
|
// TODO: This is pretty fragile, as if anything calls anything on these nils this test will break.
|
||||||
// Unfortunately, it makes little sense to instantiate these dependencies when we just want to test routing.
|
// Unfortunately, it makes little sense to instantiate these dependencies when we just want to test routing.
|
||||||
federationapi.AddPublicRoutes(base.PublicAPIMux, &cfg.FederationAPI, nil, nil, keyRing, nil, fsAPI, nil, nil, nil)
|
federationapi.AddPublicRoutes(base.ExternalFederationAPIMux, base.ExternalKeyAPIMux, &cfg.FederationAPI, nil, nil, keyRing, nil, fsAPI, nil, nil, nil)
|
||||||
baseURL, cancel := test.ListenAndServe(t, base.PublicAPIMux, true)
|
baseURL, cancel := test.ListenAndServe(t, base.ExternalFederationAPIMux, true)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
serverName := gomatrixserverlib.ServerName(strings.TrimPrefix(baseURL, "https://"))
|
serverName := gomatrixserverlib.ServerName(strings.TrimPrefix(baseURL, "https://"))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,9 +32,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
pathPrefixV2Keys = "/key/v2"
|
pathPrefixV2Keys = "/v2"
|
||||||
pathPrefixV1Federation = "/federation/v1"
|
pathPrefixV1Federation = "/v1"
|
||||||
pathPrefixV2Federation = "/federation/v2"
|
pathPrefixV2Federation = "/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Setup registers HTTP handlers with the given ServeMux.
|
// Setup registers HTTP handlers with the given ServeMux.
|
||||||
|
|
@ -46,7 +46,7 @@ const (
|
||||||
// applied:
|
// applied:
|
||||||
// nolint: gocyclo
|
// nolint: gocyclo
|
||||||
func Setup(
|
func Setup(
|
||||||
publicAPIMux *mux.Router,
|
fedMux, keyMux *mux.Router,
|
||||||
cfg *config.FederationAPI,
|
cfg *config.FederationAPI,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||||
eduAPI eduserverAPI.EDUServerInputAPI,
|
eduAPI eduserverAPI.EDUServerInputAPI,
|
||||||
|
|
@ -57,9 +57,9 @@ func Setup(
|
||||||
stateAPI currentstateAPI.CurrentStateInternalAPI,
|
stateAPI currentstateAPI.CurrentStateInternalAPI,
|
||||||
keyAPI keyserverAPI.KeyInternalAPI,
|
keyAPI keyserverAPI.KeyInternalAPI,
|
||||||
) {
|
) {
|
||||||
v2keysmux := publicAPIMux.PathPrefix(pathPrefixV2Keys).Subrouter()
|
v2keysmux := keyMux.PathPrefix(pathPrefixV2Keys).Subrouter()
|
||||||
v1fedmux := publicAPIMux.PathPrefix(pathPrefixV1Federation).Subrouter()
|
v1fedmux := fedMux.PathPrefix(pathPrefixV1Federation).Subrouter()
|
||||||
v2fedmux := publicAPIMux.PathPrefix(pathPrefixV2Federation).Subrouter()
|
v2fedmux := fedMux.PathPrefix(pathPrefixV2Federation).Subrouter()
|
||||||
|
|
||||||
wakeup := &httputil.FederationWakeups{
|
wakeup := &httputil.FederationWakeups{
|
||||||
FsAPI: fsAPI,
|
FsAPI: fsAPI,
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@
|
||||||
package httputil
|
package httputil
|
||||||
|
|
||||||
const (
|
const (
|
||||||
PublicPathPrefix = "/_matrix/"
|
ExternalClientPathPrefix = "/_matrix/client/"
|
||||||
InternalPathPrefix = "/api/"
|
ExternalFederationPathPrefix = "/_matrix/federation/"
|
||||||
|
ExternalKeyPathPrefix = "/_matrix/key/"
|
||||||
|
ExternalMediaPathPrefix = "/_matrix/media/"
|
||||||
|
InternalPathPrefix = "/api/"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -62,18 +62,19 @@ import (
|
||||||
// should only be used during start up.
|
// should only be used during start up.
|
||||||
// Must be closed when shutting down.
|
// Must be closed when shutting down.
|
||||||
type BaseDendrite struct {
|
type BaseDendrite struct {
|
||||||
componentName string
|
componentName string
|
||||||
tracerCloser io.Closer
|
tracerCloser io.Closer
|
||||||
|
ExternalClientAPIMux *mux.Router
|
||||||
// PublicAPIMux should be used to register new public matrix api endpoints
|
ExternalFederationAPIMux *mux.Router
|
||||||
PublicAPIMux *mux.Router
|
ExternalKeyAPIMux *mux.Router
|
||||||
InternalAPIMux *mux.Router
|
ExternalMediaAPIMux *mux.Router
|
||||||
UseHTTPAPIs bool
|
InternalAPIMux *mux.Router
|
||||||
httpClient *http.Client
|
UseHTTPAPIs bool
|
||||||
Cfg *config.Dendrite
|
httpClient *http.Client
|
||||||
Caches *caching.Caches
|
Cfg *config.Dendrite
|
||||||
KafkaConsumer sarama.Consumer
|
Caches *caching.Caches
|
||||||
KafkaProducer sarama.SyncProducer
|
KafkaConsumer sarama.Consumer
|
||||||
|
KafkaProducer sarama.SyncProducer
|
||||||
}
|
}
|
||||||
|
|
||||||
const HTTPServerTimeout = time.Minute * 5
|
const HTTPServerTimeout = time.Minute * 5
|
||||||
|
|
@ -136,16 +137,19 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, useHTTPAPIs boo
|
||||||
// are not inadvertently reading paths without cleaning, else this could introduce a
|
// are not inadvertently reading paths without cleaning, else this could introduce a
|
||||||
// directory traversal attack e.g /../../../etc/passwd
|
// directory traversal attack e.g /../../../etc/passwd
|
||||||
return &BaseDendrite{
|
return &BaseDendrite{
|
||||||
componentName: componentName,
|
componentName: componentName,
|
||||||
UseHTTPAPIs: useHTTPAPIs,
|
UseHTTPAPIs: useHTTPAPIs,
|
||||||
tracerCloser: closer,
|
tracerCloser: closer,
|
||||||
Cfg: cfg,
|
Cfg: cfg,
|
||||||
Caches: cache,
|
Caches: cache,
|
||||||
PublicAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicPathPrefix).Subrouter().UseEncodedPath(),
|
ExternalClientAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.ExternalClientPathPrefix).Subrouter().UseEncodedPath(),
|
||||||
InternalAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.InternalPathPrefix).Subrouter().UseEncodedPath(),
|
ExternalFederationAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.ExternalFederationPathPrefix).Subrouter().UseEncodedPath(),
|
||||||
httpClient: &client,
|
ExternalKeyAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.ExternalKeyPathPrefix).Subrouter().UseEncodedPath(),
|
||||||
KafkaConsumer: kafkaConsumer,
|
ExternalMediaAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.ExternalMediaPathPrefix).Subrouter().UseEncodedPath(),
|
||||||
KafkaProducer: kafkaProducer,
|
InternalAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.InternalPathPrefix).Subrouter().UseEncodedPath(),
|
||||||
|
httpClient: &client,
|
||||||
|
KafkaConsumer: kafkaConsumer,
|
||||||
|
KafkaProducer: kafkaProducer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -293,7 +297,11 @@ func (b *BaseDendrite) SetupAndServeHTTP(
|
||||||
}
|
}
|
||||||
|
|
||||||
internalRouter.PathPrefix(httputil.InternalPathPrefix).Handler(b.InternalAPIMux)
|
internalRouter.PathPrefix(httputil.InternalPathPrefix).Handler(b.InternalAPIMux)
|
||||||
externalRouter.PathPrefix(httputil.PublicPathPrefix).Handler(b.PublicAPIMux)
|
|
||||||
|
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)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer close(block)
|
defer close(block)
|
||||||
|
|
|
||||||
|
|
@ -63,21 +63,21 @@ type Monolith struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddAllPublicRoutes attaches all public paths to the given router
|
// AddAllPublicRoutes attaches all public paths to the given router
|
||||||
func (m *Monolith) AddAllPublicRoutes(publicMux *mux.Router) {
|
func (m *Monolith) AddAllPublicRoutes(csMux, ssMux, keyMux, mediaMux *mux.Router) {
|
||||||
clientapi.AddPublicRoutes(
|
clientapi.AddPublicRoutes(
|
||||||
publicMux, &m.Config.ClientAPI, m.KafkaProducer, m.DeviceDB, m.AccountDB,
|
csMux, &m.Config.ClientAPI, m.KafkaProducer, m.DeviceDB, m.AccountDB,
|
||||||
m.FedClient, m.RoomserverAPI,
|
m.FedClient, m.RoomserverAPI,
|
||||||
m.EDUInternalAPI, m.AppserviceAPI, m.StateAPI, transactions.New(),
|
m.EDUInternalAPI, m.AppserviceAPI, m.StateAPI, transactions.New(),
|
||||||
m.FederationSenderAPI, m.UserAPI, m.KeyAPI, m.ExtPublicRoomsProvider,
|
m.FederationSenderAPI, m.UserAPI, m.KeyAPI, m.ExtPublicRoomsProvider,
|
||||||
)
|
)
|
||||||
federationapi.AddPublicRoutes(
|
federationapi.AddPublicRoutes(
|
||||||
publicMux, &m.Config.FederationAPI, m.UserAPI, m.FedClient,
|
ssMux, keyMux, &m.Config.FederationAPI, m.UserAPI, m.FedClient,
|
||||||
m.KeyRing, m.RoomserverAPI, m.FederationSenderAPI,
|
m.KeyRing, m.RoomserverAPI, m.FederationSenderAPI,
|
||||||
m.EDUInternalAPI, m.StateAPI, m.KeyAPI,
|
m.EDUInternalAPI, m.StateAPI, m.KeyAPI,
|
||||||
)
|
)
|
||||||
mediaapi.AddPublicRoutes(publicMux, &m.Config.MediaAPI, m.UserAPI, m.Client)
|
mediaapi.AddPublicRoutes(mediaMux, &m.Config.MediaAPI, m.UserAPI, m.Client)
|
||||||
syncapi.AddPublicRoutes(
|
syncapi.AddPublicRoutes(
|
||||||
publicMux, m.KafkaConsumer, m.UserAPI, m.RoomserverAPI,
|
csMux, m.KafkaConsumer, m.UserAPI, m.RoomserverAPI,
|
||||||
m.KeyAPI, m.StateAPI, m.FedClient, &m.Config.SyncAPI,
|
m.KeyAPI, m.StateAPI, m.FedClient, &m.Config.SyncAPI,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue