2024-10-17 16:16:37 +01:00
|
|
|
// Copyright 2024 New Vector Ltd.
|
2020-06-12 14:55:57 +01:00
|
|
|
// Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
//
|
2024-10-18 15:14:08 +01:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
|
|
|
// Please see LICENSE files in the repository root for full details.
|
2020-06-12 14:55:57 +01:00
|
|
|
|
2020-06-09 12:07:33 +01:00
|
|
|
package setup
|
|
|
|
|
|
|
|
import (
|
2024-10-17 16:33:45 +01:00
|
|
|
appserviceAPI "github.com/element-hq/dendrite/appservice/api"
|
|
|
|
"github.com/element-hq/dendrite/clientapi"
|
|
|
|
"github.com/element-hq/dendrite/clientapi/api"
|
|
|
|
"github.com/element-hq/dendrite/federationapi"
|
|
|
|
federationAPI "github.com/element-hq/dendrite/federationapi/api"
|
|
|
|
"github.com/element-hq/dendrite/internal/caching"
|
|
|
|
"github.com/element-hq/dendrite/internal/httputil"
|
|
|
|
"github.com/element-hq/dendrite/internal/sqlutil"
|
|
|
|
"github.com/element-hq/dendrite/internal/transactions"
|
|
|
|
"github.com/element-hq/dendrite/mediaapi"
|
|
|
|
"github.com/element-hq/dendrite/relayapi"
|
|
|
|
relayAPI "github.com/element-hq/dendrite/relayapi/api"
|
|
|
|
roomserverAPI "github.com/element-hq/dendrite/roomserver/api"
|
|
|
|
"github.com/element-hq/dendrite/setup/config"
|
|
|
|
"github.com/element-hq/dendrite/setup/jetstream"
|
|
|
|
"github.com/element-hq/dendrite/setup/process"
|
|
|
|
"github.com/element-hq/dendrite/syncapi"
|
|
|
|
userapi "github.com/element-hq/dendrite/userapi/api"
|
2020-06-09 12:07:33 +01:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2023-04-06 09:55:01 +01:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
2020-06-09 12:07:33 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Monolith represents an instantiation of all dependencies required to build
|
|
|
|
// all components of Dendrite, for use in monolith mode.
|
|
|
|
type Monolith struct {
|
2020-10-15 13:27:13 +01:00
|
|
|
Config *config.Dendrite
|
|
|
|
KeyRing *gomatrixserverlib.KeyRing
|
2023-04-06 09:55:01 +01:00
|
|
|
Client *fclient.Client
|
2023-04-24 17:23:25 +01:00
|
|
|
FedClient fclient.FederationClient
|
2020-06-09 12:07:33 +01:00
|
|
|
|
2022-05-06 12:39:26 +01:00
|
|
|
AppserviceAPI appserviceAPI.AppServiceInternalAPI
|
2022-03-29 13:14:35 +01:00
|
|
|
FederationAPI federationAPI.FederationInternalAPI
|
|
|
|
RoomserverAPI roomserverAPI.RoomserverInternalAPI
|
|
|
|
UserAPI userapi.UserInternalAPI
|
2023-01-23 17:55:12 +00:00
|
|
|
RelayAPI relayAPI.RelayInternalAPI
|
2020-06-09 12:07:33 +01:00
|
|
|
|
|
|
|
// Optional
|
2022-03-28 16:25:26 +01:00
|
|
|
ExtPublicRoomsProvider api.ExtraPublicRoomsProvider
|
2022-05-05 19:30:38 +01:00
|
|
|
ExtUserDirectoryProvider userapi.QuerySearchProfilesAPI
|
2020-06-09 12:07:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// AddAllPublicRoutes attaches all public paths to the given router
|
2023-03-22 08:21:32 +00:00
|
|
|
func (m *Monolith) AddAllPublicRoutes(
|
|
|
|
processCtx *process.ProcessContext,
|
|
|
|
cfg *config.Dendrite,
|
|
|
|
routers httputil.Routers,
|
2023-07-19 12:37:04 +01:00
|
|
|
cm *sqlutil.Connections,
|
2023-03-22 08:21:32 +00:00
|
|
|
natsInstance *jetstream.NATSInstance,
|
|
|
|
caches *caching.Caches,
|
|
|
|
enableMetrics bool,
|
|
|
|
) {
|
2022-03-28 16:25:26 +01:00
|
|
|
userDirectoryProvider := m.ExtUserDirectoryProvider
|
|
|
|
if userDirectoryProvider == nil {
|
|
|
|
userDirectoryProvider = m.UserAPI
|
|
|
|
}
|
2020-06-09 12:07:33 +01:00
|
|
|
clientapi.AddPublicRoutes(
|
2023-03-22 08:21:32 +00:00
|
|
|
processCtx, routers, cfg, natsInstance, m.FedClient, m.RoomserverAPI, m.AppserviceAPI, transactions.New(),
|
2023-02-20 13:58:03 +00:00
|
|
|
m.FederationAPI, m.UserAPI, userDirectoryProvider,
|
2023-03-22 08:21:32 +00:00
|
|
|
m.ExtPublicRoomsProvider, enableMetrics,
|
2020-06-09 12:07:33 +01:00
|
|
|
)
|
|
|
|
federationapi.AddPublicRoutes(
|
2023-05-03 10:21:27 +01:00
|
|
|
processCtx, routers, cfg, natsInstance, m.UserAPI, m.FedClient, m.KeyRing, m.RoomserverAPI, m.FederationAPI, enableMetrics,
|
2020-06-09 12:07:33 +01:00
|
|
|
)
|
2024-08-16 11:37:59 +01:00
|
|
|
mediaapi.AddPublicRoutes(routers, cm, cfg, m.UserAPI, m.Client, m.FedClient, m.KeyRing)
|
2023-03-22 08:21:32 +00:00
|
|
|
syncapi.AddPublicRoutes(processCtx, routers, cfg, cm, natsInstance, m.UserAPI, m.RoomserverAPI, caches, enableMetrics)
|
2023-01-23 17:55:12 +00:00
|
|
|
|
|
|
|
if m.RelayAPI != nil {
|
2023-03-22 08:21:32 +00:00
|
|
|
relayapi.AddPublicRoutes(routers, cfg, m.KeyRing, m.RelayAPI)
|
2023-01-23 17:55:12 +00:00
|
|
|
}
|
2020-06-09 12:07:33 +01:00
|
|
|
}
|