Split out SetupFooComponent (#1106)
* Split out adding HTTP routes from making internal APIs for clarity * Split out more components * Split out more things * Finish converting * internal mux for internal routesmain
parent
cdb9a11571
commit
4f171c56a8
|
@ -21,6 +21,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
||||||
"github.com/matrix-org/dendrite/appservice/consumers"
|
"github.com/matrix-org/dendrite/appservice/consumers"
|
||||||
"github.com/matrix-org/dendrite/appservice/inthttp"
|
"github.com/matrix-org/dendrite/appservice/inthttp"
|
||||||
|
@ -40,15 +41,28 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetupAppServiceAPIComponent sets up and registers HTTP handlers for the AppServices
|
// AddPublicRoutes registers HTTP handlers for CS API calls
|
||||||
// component.
|
func AddPublicRoutes(router *mux.Router, cfg *config.Dendrite, rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||||
func SetupAppServiceAPIComponent(
|
accountsDB accounts.Database, federation *gomatrixserverlib.FederationClient, txnCache *transactions.Cache) {
|
||||||
|
|
||||||
|
routing.Setup(
|
||||||
|
router, cfg, rsAPI,
|
||||||
|
accountsDB, federation, txnCache,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddInternalRoutes registers HTTP handlers for internal API calls
|
||||||
|
func AddInternalRoutes(router *mux.Router, queryAPI appserviceAPI.AppServiceQueryAPI) {
|
||||||
|
inthttp.AddRoutes(queryAPI, router)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewInternalAPI returns a concerete implementation of the internal API. Callers
|
||||||
|
// can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes.
|
||||||
|
func NewInternalAPI(
|
||||||
base *basecomponent.BaseDendrite,
|
base *basecomponent.BaseDendrite,
|
||||||
accountsDB accounts.Database,
|
accountsDB accounts.Database,
|
||||||
deviceDB devices.Database,
|
deviceDB devices.Database,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||||
transactionsCache *transactions.Cache,
|
|
||||||
) appserviceAPI.AppServiceQueryAPI {
|
) appserviceAPI.AppServiceQueryAPI {
|
||||||
// Create a connection to the appservice postgres DB
|
// Create a connection to the appservice postgres DB
|
||||||
appserviceDB, err := storage.NewDatabase(string(base.Cfg.Database.AppService), base.Cfg.DbProperties())
|
appserviceDB, err := storage.NewDatabase(string(base.Cfg.Database.AppService), base.Cfg.DbProperties())
|
||||||
|
@ -85,8 +99,6 @@ func SetupAppServiceAPIComponent(
|
||||||
Cfg: base.Cfg,
|
Cfg: base.Cfg,
|
||||||
}
|
}
|
||||||
|
|
||||||
inthttp.AddRoutes(appserviceQueryAPI, base.InternalAPIMux)
|
|
||||||
|
|
||||||
consumer := consumers.NewOutputRoomEventConsumer(
|
consumer := consumers.NewOutputRoomEventConsumer(
|
||||||
base.Cfg, base.KafkaConsumer, accountsDB, appserviceDB,
|
base.Cfg, base.KafkaConsumer, accountsDB, appserviceDB,
|
||||||
rsAPI, workerStates,
|
rsAPI, workerStates,
|
||||||
|
@ -99,13 +111,6 @@ func SetupAppServiceAPIComponent(
|
||||||
if err := workers.SetupTransactionWorkers(appserviceDB, workerStates); err != nil {
|
if err := workers.SetupTransactionWorkers(appserviceDB, workerStates); err != nil {
|
||||||
logrus.WithError(err).Panicf("failed to start app service transaction workers")
|
logrus.WithError(err).Panicf("failed to start app service transaction workers")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up HTTP Endpoints
|
|
||||||
routing.Setup(
|
|
||||||
base.PublicAPIMux, base.Cfg, rsAPI,
|
|
||||||
accountsDB, federation, transactionsCache,
|
|
||||||
)
|
|
||||||
|
|
||||||
return appserviceQueryAPI
|
return appserviceQueryAPI
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
package clientapi
|
package clientapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/gorilla/mux"
|
||||||
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
||||||
|
@ -30,9 +31,9 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetupClientAPIComponent sets up and registers HTTP handlers for the ClientAPI
|
// AddPublicRoutes sets up and registers HTTP handlers for the ClientAPI component.
|
||||||
// component.
|
func AddPublicRoutes(
|
||||||
func SetupClientAPIComponent(
|
router *mux.Router,
|
||||||
base *basecomponent.BaseDendrite,
|
base *basecomponent.BaseDendrite,
|
||||||
deviceDB devices.Database,
|
deviceDB devices.Database,
|
||||||
accountsDB accounts.Database,
|
accountsDB accounts.Database,
|
||||||
|
@ -65,7 +66,7 @@ func SetupClientAPIComponent(
|
||||||
}
|
}
|
||||||
|
|
||||||
routing.Setup(
|
routing.Setup(
|
||||||
base.PublicAPIMux, base.Cfg, roomserverProducer, rsAPI, asAPI,
|
router, base.Cfg, roomserverProducer, rsAPI, asAPI,
|
||||||
accountsDB, deviceDB, federation, *keyRing, userUpdateProducer,
|
accountsDB, deviceDB, federation, *keyRing, userUpdateProducer,
|
||||||
syncProducer, eduProducer, transactionsCache, fsAPI,
|
syncProducer, eduProducer, transactionsCache, fsAPI,
|
||||||
)
|
)
|
||||||
|
|
|
@ -31,9 +31,9 @@ func main() {
|
||||||
rsAPI := base.RoomserverHTTPClient()
|
rsAPI := base.RoomserverHTTPClient()
|
||||||
cache := transactions.New()
|
cache := transactions.New()
|
||||||
|
|
||||||
appservice.SetupAppServiceAPIComponent(
|
intAPI := appservice.NewInternalAPI(base, accountDB, deviceDB, rsAPI)
|
||||||
base, accountDB, deviceDB, federation, rsAPI, cache,
|
appservice.AddInternalRoutes(base.InternalAPIMux, intAPI)
|
||||||
)
|
appservice.AddPublicRoutes(base.PublicAPIMux, base.Cfg, rsAPI, accountDB, federation, cache)
|
||||||
|
|
||||||
base.SetupAndServeHTTP(string(base.Cfg.Bind.AppServiceAPI), string(base.Cfg.Listen.AppServiceAPI))
|
base.SetupAndServeHTTP(string(base.Cfg.Bind.AppServiceAPI), string(base.Cfg.Listen.AppServiceAPI))
|
||||||
|
|
||||||
|
|
|
@ -38,8 +38,8 @@ func main() {
|
||||||
fsAPI := base.FederationSenderHTTPClient()
|
fsAPI := base.FederationSenderHTTPClient()
|
||||||
eduInputAPI := base.EDUServerClient()
|
eduInputAPI := base.EDUServerClient()
|
||||||
|
|
||||||
clientapi.SetupClientAPIComponent(
|
clientapi.AddPublicRoutes(
|
||||||
base, deviceDB, accountDB, federation, keyRing,
|
base.PublicAPIMux, base, deviceDB, accountDB, federation, keyRing,
|
||||||
rsAPI, eduInputAPI, asQuery, transactions.New(), fsAPI,
|
rsAPI, eduInputAPI, asQuery, transactions.New(), fsAPI,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -136,42 +136,41 @@ func main() {
|
||||||
deviceDB := base.Base.CreateDeviceDB()
|
deviceDB := base.Base.CreateDeviceDB()
|
||||||
federation := createFederationClient(base)
|
federation := createFederationClient(base)
|
||||||
|
|
||||||
serverKeyAPI := serverkeyapi.SetupServerKeyAPIComponent(
|
serverKeyAPI := serverkeyapi.NewInternalAPI(
|
||||||
&base.Base, federation,
|
base.Base.Cfg, federation, base.Base.Caches,
|
||||||
)
|
)
|
||||||
keyRing := serverKeyAPI.KeyRing()
|
keyRing := serverKeyAPI.KeyRing()
|
||||||
createKeyDB(
|
createKeyDB(
|
||||||
base, serverKeyAPI,
|
base, serverKeyAPI,
|
||||||
)
|
)
|
||||||
|
|
||||||
rsAPI := roomserver.SetupRoomServerComponent(
|
rsAPI := roomserver.NewInternalAPI(
|
||||||
&base.Base, keyRing, federation,
|
&base.Base, keyRing, federation,
|
||||||
)
|
)
|
||||||
eduInputAPI := eduserver.SetupEDUServerComponent(
|
eduInputAPI := eduserver.NewInternalAPI(
|
||||||
&base.Base, cache.New(), deviceDB,
|
&base.Base, cache.New(), deviceDB,
|
||||||
)
|
)
|
||||||
asAPI := appservice.SetupAppServiceAPIComponent(
|
asAPI := appservice.NewInternalAPI(&base.Base, accountDB, deviceDB, rsAPI)
|
||||||
&base.Base, accountDB, deviceDB, federation, rsAPI, transactions.New(),
|
appservice.AddPublicRoutes(base.Base.PublicAPIMux, &cfg, rsAPI, accountDB, federation, transactions.New())
|
||||||
)
|
fsAPI := federationsender.NewInternalAPI(
|
||||||
fsAPI := federationsender.SetupFederationSenderComponent(
|
|
||||||
&base.Base, federation, rsAPI, keyRing,
|
&base.Base, federation, rsAPI, keyRing,
|
||||||
)
|
)
|
||||||
rsAPI.SetFederationSenderAPI(fsAPI)
|
rsAPI.SetFederationSenderAPI(fsAPI)
|
||||||
|
|
||||||
clientapi.SetupClientAPIComponent(
|
clientapi.AddPublicRoutes(
|
||||||
&base.Base, deviceDB, accountDB,
|
base.Base.PublicAPIMux, &base.Base, deviceDB, accountDB,
|
||||||
federation, keyRing, rsAPI,
|
federation, keyRing, rsAPI,
|
||||||
eduInputAPI, asAPI, transactions.New(), fsAPI,
|
eduInputAPI, asAPI, transactions.New(), fsAPI,
|
||||||
)
|
)
|
||||||
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
||||||
federationapi.SetupFederationAPIComponent(&base.Base, accountDB, deviceDB, federation, keyRing, rsAPI, asAPI, fsAPI, eduProducer)
|
federationapi.AddPublicRoutes(base.Base.PublicAPIMux, base.Base.Cfg, accountDB, deviceDB, federation, keyRing, rsAPI, asAPI, fsAPI, eduProducer)
|
||||||
mediaapi.SetupMediaAPIComponent(&base.Base, deviceDB)
|
mediaapi.AddPublicRoutes(base.Base.PublicAPIMux, base.Base.Cfg, deviceDB)
|
||||||
publicRoomsDB, err := storage.NewPublicRoomsServerDatabaseWithPubSub(string(base.Base.Cfg.Database.PublicRoomsAPI), base.LibP2PPubsub, cfg.Matrix.ServerName)
|
publicRoomsDB, err := storage.NewPublicRoomsServerDatabaseWithPubSub(string(base.Base.Cfg.Database.PublicRoomsAPI), base.LibP2PPubsub, cfg.Matrix.ServerName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
||||||
}
|
}
|
||||||
publicroomsapi.SetupPublicRoomsAPIComponent(&base.Base, deviceDB, publicRoomsDB, rsAPI, federation, nil) // Check this later
|
publicroomsapi.AddPublicRoutes(base.Base.PublicAPIMux, &base.Base, deviceDB, publicRoomsDB, rsAPI, federation, nil) // Check this later
|
||||||
syncapi.SetupSyncAPIComponent(&base.Base, deviceDB, accountDB, rsAPI, federation, &cfg)
|
syncapi.AddPublicRoutes(base.Base.PublicAPIMux, &base.Base, deviceDB, accountDB, rsAPI, federation, &cfg)
|
||||||
|
|
||||||
internal.SetupHTTPAPI(
|
internal.SetupHTTPAPI(
|
||||||
http.DefaultServeMux,
|
http.DefaultServeMux,
|
||||||
|
|
|
@ -31,7 +31,8 @@ func main() {
|
||||||
}()
|
}()
|
||||||
deviceDB := base.CreateDeviceDB()
|
deviceDB := base.CreateDeviceDB()
|
||||||
|
|
||||||
eduserver.SetupEDUServerComponent(base, cache.New(), deviceDB)
|
intAPI := eduserver.NewInternalAPI(base, cache.New(), deviceDB)
|
||||||
|
eduserver.AddInternalRoutes(base.InternalAPIMux, intAPI)
|
||||||
|
|
||||||
base.SetupAndServeHTTP(string(base.Cfg.Bind.EDUServer), string(base.Cfg.Listen.EDUServer))
|
base.SetupAndServeHTTP(string(base.Cfg.Bind.EDUServer), string(base.Cfg.Listen.EDUServer))
|
||||||
|
|
||||||
|
|
|
@ -36,8 +36,8 @@ func main() {
|
||||||
// TODO: this isn't a producer
|
// TODO: this isn't a producer
|
||||||
eduProducer := producers.NewEDUServerProducer(base.EDUServerClient())
|
eduProducer := producers.NewEDUServerProducer(base.EDUServerClient())
|
||||||
|
|
||||||
federationapi.SetupFederationAPIComponent(
|
federationapi.AddPublicRoutes(
|
||||||
base, accountDB, deviceDB, federation, keyRing,
|
base.PublicAPIMux, base.Cfg, accountDB, deviceDB, federation, keyRing,
|
||||||
rsAPI, asAPI, fsAPI, eduProducer,
|
rsAPI, asAPI, fsAPI, eduProducer,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -30,9 +30,10 @@ func main() {
|
||||||
keyRing := serverKeyAPI.KeyRing()
|
keyRing := serverKeyAPI.KeyRing()
|
||||||
|
|
||||||
rsAPI := base.RoomserverHTTPClient()
|
rsAPI := base.RoomserverHTTPClient()
|
||||||
federationsender.SetupFederationSenderComponent(
|
fsAPI := federationsender.NewInternalAPI(
|
||||||
base, federation, rsAPI, keyRing,
|
base, federation, rsAPI, keyRing,
|
||||||
)
|
)
|
||||||
|
federationsender.AddInternalRoutes(base.InternalAPIMux, fsAPI)
|
||||||
|
|
||||||
base.SetupAndServeHTTP(string(base.Cfg.Bind.FederationSender), string(base.Cfg.Listen.FederationSender))
|
base.SetupAndServeHTTP(string(base.Cfg.Bind.FederationSender), string(base.Cfg.Listen.FederationSender))
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ func main() {
|
||||||
accountDB := base.CreateAccountsDB()
|
accountDB := base.CreateAccountsDB()
|
||||||
deviceDB := base.CreateDeviceDB()
|
deviceDB := base.CreateDeviceDB()
|
||||||
|
|
||||||
keyserver.SetupKeyServerComponent(base, deviceDB, accountDB)
|
keyserver.AddPublicRoutes(base.PublicAPIMux, base.Cfg, deviceDB, accountDB)
|
||||||
|
|
||||||
base.SetupAndServeHTTP(string(base.Cfg.Bind.KeyServer), string(base.Cfg.Listen.KeyServer))
|
base.SetupAndServeHTTP(string(base.Cfg.Bind.KeyServer), string(base.Cfg.Listen.KeyServer))
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ func main() {
|
||||||
|
|
||||||
deviceDB := base.CreateDeviceDB()
|
deviceDB := base.CreateDeviceDB()
|
||||||
|
|
||||||
mediaapi.SetupMediaAPIComponent(base, deviceDB)
|
mediaapi.AddPublicRoutes(base.PublicAPIMux, base.Cfg, deviceDB)
|
||||||
|
|
||||||
base.SetupAndServeHTTP(string(base.Cfg.Bind.MediaAPI), string(base.Cfg.Listen.MediaAPI))
|
base.SetupAndServeHTTP(string(base.Cfg.Bind.MediaAPI), string(base.Cfg.Listen.MediaAPI))
|
||||||
|
|
||||||
|
|
|
@ -70,62 +70,66 @@ func main() {
|
||||||
deviceDB := base.CreateDeviceDB()
|
deviceDB := base.CreateDeviceDB()
|
||||||
federation := base.CreateFederationClient()
|
federation := base.CreateFederationClient()
|
||||||
|
|
||||||
serverKeyAPI := serverkeyapi.SetupServerKeyAPIComponent(
|
serverKeyAPI := serverkeyapi.NewInternalAPI(
|
||||||
base, federation,
|
base.Cfg, federation, base.Caches,
|
||||||
)
|
)
|
||||||
if base.UseHTTPAPIs {
|
if base.UseHTTPAPIs {
|
||||||
|
serverkeyapi.AddInternalRoutes(base.InternalAPIMux, serverKeyAPI, base.Caches)
|
||||||
serverKeyAPI = base.ServerKeyAPIClient()
|
serverKeyAPI = base.ServerKeyAPIClient()
|
||||||
}
|
}
|
||||||
keyRing := serverKeyAPI.KeyRing()
|
keyRing := serverKeyAPI.KeyRing()
|
||||||
|
|
||||||
rsComponent := roomserver.SetupRoomServerComponent(
|
rsComponent := roomserver.NewInternalAPI(
|
||||||
base, keyRing, federation,
|
base, keyRing, federation,
|
||||||
)
|
)
|
||||||
rsAPI := rsComponent
|
rsAPI := rsComponent
|
||||||
if base.UseHTTPAPIs {
|
if base.UseHTTPAPIs {
|
||||||
|
roomserver.AddInternalRoutes(base.InternalAPIMux, rsAPI)
|
||||||
rsAPI = base.RoomserverHTTPClient()
|
rsAPI = base.RoomserverHTTPClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
eduInputAPI := eduserver.SetupEDUServerComponent(
|
eduInputAPI := eduserver.NewInternalAPI(
|
||||||
base, cache.New(), deviceDB,
|
base, cache.New(), deviceDB,
|
||||||
)
|
)
|
||||||
if base.UseHTTPAPIs {
|
if base.UseHTTPAPIs {
|
||||||
|
eduserver.AddInternalRoutes(base.InternalAPIMux, eduInputAPI)
|
||||||
eduInputAPI = base.EDUServerClient()
|
eduInputAPI = base.EDUServerClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
asAPI := appservice.SetupAppServiceAPIComponent(
|
asAPI := appservice.NewInternalAPI(base, accountDB, deviceDB, rsAPI)
|
||||||
base, accountDB, deviceDB, federation, rsAPI, transactions.New(),
|
appservice.AddPublicRoutes(base.PublicAPIMux, cfg, rsAPI, accountDB, federation, transactions.New())
|
||||||
)
|
|
||||||
if base.UseHTTPAPIs {
|
if base.UseHTTPAPIs {
|
||||||
|
appservice.AddInternalRoutes(base.InternalAPIMux, asAPI)
|
||||||
asAPI = base.AppserviceHTTPClient()
|
asAPI = base.AppserviceHTTPClient()
|
||||||
}
|
}
|
||||||
|
|
||||||
fsAPI := federationsender.SetupFederationSenderComponent(
|
fsAPI := federationsender.NewInternalAPI(
|
||||||
base, federation, rsAPI, keyRing,
|
base, federation, rsAPI, keyRing,
|
||||||
)
|
)
|
||||||
if base.UseHTTPAPIs {
|
if base.UseHTTPAPIs {
|
||||||
|
federationsender.AddInternalRoutes(base.InternalAPIMux, fsAPI)
|
||||||
fsAPI = base.FederationSenderHTTPClient()
|
fsAPI = base.FederationSenderHTTPClient()
|
||||||
}
|
}
|
||||||
rsComponent.SetFederationSenderAPI(fsAPI)
|
rsComponent.SetFederationSenderAPI(fsAPI)
|
||||||
|
|
||||||
clientapi.SetupClientAPIComponent(
|
clientapi.AddPublicRoutes(
|
||||||
base, deviceDB, accountDB,
|
base.PublicAPIMux, base, deviceDB, accountDB,
|
||||||
federation, keyRing, rsAPI,
|
federation, keyRing, rsAPI,
|
||||||
eduInputAPI, asAPI, transactions.New(), fsAPI,
|
eduInputAPI, asAPI, transactions.New(), fsAPI,
|
||||||
)
|
)
|
||||||
|
|
||||||
keyserver.SetupKeyServerComponent(
|
keyserver.AddPublicRoutes(
|
||||||
base, deviceDB, accountDB,
|
base.PublicAPIMux, base.Cfg, deviceDB, accountDB,
|
||||||
)
|
)
|
||||||
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
||||||
federationapi.SetupFederationAPIComponent(base, accountDB, deviceDB, federation, keyRing, rsAPI, asAPI, fsAPI, eduProducer)
|
federationapi.AddPublicRoutes(base.PublicAPIMux, base.Cfg, accountDB, deviceDB, federation, keyRing, rsAPI, asAPI, fsAPI, eduProducer)
|
||||||
mediaapi.SetupMediaAPIComponent(base, deviceDB)
|
mediaapi.AddPublicRoutes(base.PublicAPIMux, base.Cfg, deviceDB)
|
||||||
publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI), base.Cfg.DbProperties(), cfg.Matrix.ServerName)
|
publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI), base.Cfg.DbProperties(), cfg.Matrix.ServerName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
||||||
}
|
}
|
||||||
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, nil)
|
publicroomsapi.AddPublicRoutes(base.PublicAPIMux, base, deviceDB, publicRoomsDB, rsAPI, federation, nil)
|
||||||
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg)
|
syncapi.AddPublicRoutes(base.PublicAPIMux, base, deviceDB, accountDB, rsAPI, federation, cfg)
|
||||||
|
|
||||||
internal.SetupHTTPAPI(
|
internal.SetupHTTPAPI(
|
||||||
http.DefaultServeMux,
|
http.DefaultServeMux,
|
||||||
|
|
|
@ -34,7 +34,7 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
||||||
}
|
}
|
||||||
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, nil, nil)
|
publicroomsapi.AddPublicRoutes(base.PublicAPIMux, base, deviceDB, publicRoomsDB, rsAPI, nil, nil)
|
||||||
|
|
||||||
base.SetupAndServeHTTP(string(base.Cfg.Bind.PublicRoomsAPI), string(base.Cfg.Listen.PublicRoomsAPI))
|
base.SetupAndServeHTTP(string(base.Cfg.Bind.PublicRoomsAPI), string(base.Cfg.Listen.PublicRoomsAPI))
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,9 @@ func main() {
|
||||||
keyRing := serverKeyAPI.KeyRing()
|
keyRing := serverKeyAPI.KeyRing()
|
||||||
|
|
||||||
fsAPI := base.FederationSenderHTTPClient()
|
fsAPI := base.FederationSenderHTTPClient()
|
||||||
rsAPI := roomserver.SetupRoomServerComponent(base, keyRing, federation)
|
rsAPI := roomserver.NewInternalAPI(base, keyRing, federation)
|
||||||
rsAPI.SetFederationSenderAPI(fsAPI)
|
rsAPI.SetFederationSenderAPI(fsAPI)
|
||||||
|
roomserver.AddInternalRoutes(base.InternalAPIMux, rsAPI)
|
||||||
|
|
||||||
base.SetupAndServeHTTP(string(base.Cfg.Bind.RoomServer), string(base.Cfg.Listen.RoomServer))
|
base.SetupAndServeHTTP(string(base.Cfg.Bind.RoomServer), string(base.Cfg.Listen.RoomServer))
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,8 @@ func main() {
|
||||||
|
|
||||||
federation := base.CreateFederationClient()
|
federation := base.CreateFederationClient()
|
||||||
|
|
||||||
serverkeyapi.SetupServerKeyAPIComponent(base, federation)
|
intAPI := serverkeyapi.NewInternalAPI(base.Cfg, federation, base.Caches)
|
||||||
|
serverkeyapi.AddInternalRoutes(base.InternalAPIMux, intAPI, base.Caches)
|
||||||
|
|
||||||
base.SetupAndServeHTTP(string(base.Cfg.Bind.ServerKeyAPI), string(base.Cfg.Listen.ServerKeyAPI))
|
base.SetupAndServeHTTP(string(base.Cfg.Bind.ServerKeyAPI), string(base.Cfg.Listen.ServerKeyAPI))
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ func main() {
|
||||||
|
|
||||||
rsAPI := base.RoomserverHTTPClient()
|
rsAPI := base.RoomserverHTTPClient()
|
||||||
|
|
||||||
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg)
|
syncapi.AddPublicRoutes(base.PublicAPIMux, base, deviceDB, accountDB, rsAPI, federation, cfg)
|
||||||
|
|
||||||
base.SetupAndServeHTTP(string(base.Cfg.Bind.SyncAPI), string(base.Cfg.Listen.SyncAPI))
|
base.SetupAndServeHTTP(string(base.Cfg.Bind.SyncAPI), string(base.Cfg.Listen.SyncAPI))
|
||||||
|
|
||||||
|
|
|
@ -206,29 +206,29 @@ func main() {
|
||||||
KeyDatabase: fetcher,
|
KeyDatabase: fetcher,
|
||||||
}
|
}
|
||||||
|
|
||||||
rsAPI := roomserver.SetupRoomServerComponent(base, keyRing, federation)
|
rsAPI := roomserver.NewInternalAPI(base, keyRing, federation)
|
||||||
eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New(), deviceDB)
|
eduInputAPI := eduserver.NewInternalAPI(base, cache.New(), deviceDB)
|
||||||
asQuery := appservice.SetupAppServiceAPIComponent(
|
asQuery := appservice.NewInternalAPI(
|
||||||
base, accountDB, deviceDB, federation, rsAPI, transactions.New(),
|
base, accountDB, deviceDB, rsAPI,
|
||||||
)
|
)
|
||||||
fedSenderAPI := federationsender.SetupFederationSenderComponent(base, federation, rsAPI, &keyRing)
|
fedSenderAPI := federationsender.NewInternalAPI(base, federation, rsAPI, &keyRing)
|
||||||
rsAPI.SetFederationSenderAPI(fedSenderAPI)
|
rsAPI.SetFederationSenderAPI(fedSenderAPI)
|
||||||
p2pPublicRoomProvider := NewLibP2PPublicRoomsProvider(node, fedSenderAPI)
|
p2pPublicRoomProvider := NewLibP2PPublicRoomsProvider(node, fedSenderAPI)
|
||||||
|
|
||||||
clientapi.SetupClientAPIComponent(
|
clientapi.AddPublicRoutes(
|
||||||
base, deviceDB, accountDB,
|
base.PublicAPIMux, base, deviceDB, accountDB,
|
||||||
federation, &keyRing, rsAPI,
|
federation, &keyRing, rsAPI,
|
||||||
eduInputAPI, asQuery, transactions.New(), fedSenderAPI,
|
eduInputAPI, asQuery, transactions.New(), fedSenderAPI,
|
||||||
)
|
)
|
||||||
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
||||||
federationapi.SetupFederationAPIComponent(base, accountDB, deviceDB, federation, &keyRing, rsAPI, asQuery, fedSenderAPI, eduProducer)
|
federationapi.AddPublicRoutes(base.PublicAPIMux, base.Cfg, accountDB, deviceDB, federation, &keyRing, rsAPI, asQuery, fedSenderAPI, eduProducer)
|
||||||
mediaapi.SetupMediaAPIComponent(base, deviceDB)
|
mediaapi.AddPublicRoutes(base.PublicAPIMux, base.Cfg, deviceDB)
|
||||||
publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI), cfg.Matrix.ServerName)
|
publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI), cfg.Matrix.ServerName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
||||||
}
|
}
|
||||||
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, p2pPublicRoomProvider)
|
publicroomsapi.AddPublicRoutes(base.PublicAPIMux, base, deviceDB, publicRoomsDB, rsAPI, federation, p2pPublicRoomProvider)
|
||||||
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg)
|
syncapi.AddPublicRoutes(base.PublicAPIMux, base, deviceDB, accountDB, rsAPI, federation, cfg)
|
||||||
|
|
||||||
internal.SetupHTTPAPI(
|
internal.SetupHTTPAPI(
|
||||||
http.DefaultServeMux,
|
http.DefaultServeMux,
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package eduserver
|
package eduserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
||||||
"github.com/matrix-org/dendrite/eduserver/api"
|
"github.com/matrix-org/dendrite/eduserver/api"
|
||||||
"github.com/matrix-org/dendrite/eduserver/cache"
|
"github.com/matrix-org/dendrite/eduserver/cache"
|
||||||
|
@ -25,16 +26,20 @@ import (
|
||||||
"github.com/matrix-org/dendrite/internal/basecomponent"
|
"github.com/matrix-org/dendrite/internal/basecomponent"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetupEDUServerComponent sets up and registers HTTP handlers for the
|
// AddInternalRoutes registers HTTP handlers for the internal API. Invokes functions
|
||||||
// EDUServer component. Returns instances of the various roomserver APIs,
|
// on the given input API.
|
||||||
// allowing other components running in the same process to hit the query the
|
func AddInternalRoutes(internalMux *mux.Router, inputAPI api.EDUServerInputAPI) {
|
||||||
// APIs directly instead of having to use HTTP.
|
inthttp.AddRoutes(inputAPI, internalMux)
|
||||||
func SetupEDUServerComponent(
|
}
|
||||||
|
|
||||||
|
// NewInternalAPI returns a concerete implementation of the internal API. Callers
|
||||||
|
// can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes.
|
||||||
|
func NewInternalAPI(
|
||||||
base *basecomponent.BaseDendrite,
|
base *basecomponent.BaseDendrite,
|
||||||
eduCache *cache.EDUCache,
|
eduCache *cache.EDUCache,
|
||||||
deviceDB devices.Database,
|
deviceDB devices.Database,
|
||||||
) api.EDUServerInputAPI {
|
) api.EDUServerInputAPI {
|
||||||
inputAPI := &input.EDUServerInputAPI{
|
return &input.EDUServerInputAPI{
|
||||||
Cache: eduCache,
|
Cache: eduCache,
|
||||||
DeviceDB: deviceDB,
|
DeviceDB: deviceDB,
|
||||||
Producer: base.KafkaProducer,
|
Producer: base.KafkaProducer,
|
||||||
|
@ -42,8 +47,4 @@ func SetupEDUServerComponent(
|
||||||
OutputSendToDeviceEventTopic: string(base.Cfg.Kafka.Topics.OutputSendToDeviceEvent),
|
OutputSendToDeviceEventTopic: string(base.Cfg.Kafka.Topics.OutputSendToDeviceEvent),
|
||||||
ServerName: base.Cfg.Matrix.ServerName,
|
ServerName: base.Cfg.Matrix.ServerName,
|
||||||
}
|
}
|
||||||
|
|
||||||
inthttp.AddRoutes(inputAPI, base.InternalAPIMux)
|
|
||||||
|
|
||||||
return inputAPI
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,11 +15,12 @@
|
||||||
package federationapi
|
package federationapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/gorilla/mux"
|
||||||
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
||||||
federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api"
|
federationSenderAPI "github.com/matrix-org/dendrite/federationsender/api"
|
||||||
"github.com/matrix-org/dendrite/internal/basecomponent"
|
"github.com/matrix-org/dendrite/internal/config"
|
||||||
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
||||||
|
|
||||||
// TODO: Are we really wanting to pull in the producer from clientapi
|
// TODO: Are we really wanting to pull in the producer from clientapi
|
||||||
|
@ -28,10 +29,10 @@ import (
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetupFederationAPIComponent sets up and registers HTTP handlers for the
|
// AddPublicRoutes sets up and registers HTTP handlers on the base API muxes for the FederationAPI component.
|
||||||
// FederationAPI component.
|
func AddPublicRoutes(
|
||||||
func SetupFederationAPIComponent(
|
router *mux.Router,
|
||||||
base *basecomponent.BaseDendrite,
|
cfg *config.Dendrite,
|
||||||
accountsDB accounts.Database,
|
accountsDB accounts.Database,
|
||||||
deviceDB devices.Database,
|
deviceDB devices.Database,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *gomatrixserverlib.FederationClient,
|
||||||
|
@ -44,7 +45,7 @@ func SetupFederationAPIComponent(
|
||||||
roomserverProducer := producers.NewRoomserverProducer(rsAPI)
|
roomserverProducer := producers.NewRoomserverProducer(rsAPI)
|
||||||
|
|
||||||
routing.Setup(
|
routing.Setup(
|
||||||
base.PublicAPIMux, base.Cfg, rsAPI, asAPI, roomserverProducer,
|
router, cfg, rsAPI, asAPI, roomserverProducer,
|
||||||
eduProducer, federationSenderAPI, *keyRing,
|
eduProducer, federationSenderAPI, *keyRing,
|
||||||
federation, accountsDB, deviceDB,
|
federation, accountsDB, deviceDB,
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
package federationsender
|
package federationsender
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/federationsender/api"
|
"github.com/matrix-org/dendrite/federationsender/api"
|
||||||
"github.com/matrix-org/dendrite/federationsender/consumers"
|
"github.com/matrix-org/dendrite/federationsender/consumers"
|
||||||
"github.com/matrix-org/dendrite/federationsender/internal"
|
"github.com/matrix-org/dendrite/federationsender/internal"
|
||||||
|
@ -29,9 +30,15 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetupFederationSenderComponent sets up and registers HTTP handlers for the
|
// AddInternalRoutes registers HTTP handlers for the internal API. Invokes functions
|
||||||
// FederationSender component.
|
// on the given input API.
|
||||||
func SetupFederationSenderComponent(
|
func AddInternalRoutes(router *mux.Router, intAPI api.FederationSenderInternalAPI) {
|
||||||
|
inthttp.AddRoutes(intAPI, router)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewInternalAPI returns a concerete implementation of the internal API. Callers
|
||||||
|
// can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes.
|
||||||
|
func NewInternalAPI(
|
||||||
base *basecomponent.BaseDendrite,
|
base *basecomponent.BaseDendrite,
|
||||||
federation *gomatrixserverlib.FederationClient,
|
federation *gomatrixserverlib.FederationClient,
|
||||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||||
|
@ -66,8 +73,5 @@ func SetupFederationSenderComponent(
|
||||||
logrus.WithError(err).Panic("failed to start typing server consumer")
|
logrus.WithError(err).Panic("failed to start typing server consumer")
|
||||||
}
|
}
|
||||||
|
|
||||||
queryAPI := internal.NewFederationSenderInternalAPI(federationSenderDB, base.Cfg, roomserverProducer, federation, keyRing, statistics, queues)
|
return internal.NewFederationSenderInternalAPI(federationSenderDB, base.Cfg, roomserverProducer, federation, keyRing, statistics, queues)
|
||||||
inthttp.AddRoutes(queryAPI, base.InternalAPIMux)
|
|
||||||
|
|
||||||
return queryAPI
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,18 +15,18 @@
|
||||||
package keyserver
|
package keyserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
||||||
"github.com/matrix-org/dendrite/internal/basecomponent"
|
"github.com/matrix-org/dendrite/internal/config"
|
||||||
"github.com/matrix-org/dendrite/keyserver/routing"
|
"github.com/matrix-org/dendrite/keyserver/routing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetupFederationSenderComponent sets up and registers HTTP handlers for the
|
// AddPublicRoutes registers HTTP handlers for CS API calls
|
||||||
// FederationSender component.
|
func AddPublicRoutes(
|
||||||
func SetupKeyServerComponent(
|
router *mux.Router, cfg *config.Dendrite,
|
||||||
base *basecomponent.BaseDendrite,
|
|
||||||
deviceDB devices.Database,
|
deviceDB devices.Database,
|
||||||
accountsDB accounts.Database,
|
accountsDB accounts.Database,
|
||||||
) {
|
) {
|
||||||
routing.Setup(base.PublicAPIMux, base.Cfg, accountsDB, deviceDB)
|
routing.Setup(router, cfg, accountsDB, deviceDB)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,26 +15,26 @@
|
||||||
package mediaapi
|
package mediaapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
||||||
"github.com/matrix-org/dendrite/internal/basecomponent"
|
"github.com/matrix-org/dendrite/internal/config"
|
||||||
"github.com/matrix-org/dendrite/mediaapi/routing"
|
"github.com/matrix-org/dendrite/mediaapi/routing"
|
||||||
"github.com/matrix-org/dendrite/mediaapi/storage"
|
"github.com/matrix-org/dendrite/mediaapi/storage"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetupMediaAPIComponent sets up and registers HTTP handlers for the MediaAPI
|
// AddPublicRoutes sets up and registers HTTP handlers for the MediaAPI component.
|
||||||
// component.
|
func AddPublicRoutes(
|
||||||
func SetupMediaAPIComponent(
|
router *mux.Router, cfg *config.Dendrite,
|
||||||
base *basecomponent.BaseDendrite,
|
|
||||||
deviceDB devices.Database,
|
deviceDB devices.Database,
|
||||||
) {
|
) {
|
||||||
mediaDB, err := storage.Open(string(base.Cfg.Database.MediaAPI), base.Cfg.DbProperties())
|
mediaDB, err := storage.Open(string(cfg.Database.MediaAPI), cfg.DbProperties())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Panicf("failed to connect to media db")
|
logrus.WithError(err).Panicf("failed to connect to media db")
|
||||||
}
|
}
|
||||||
|
|
||||||
routing.Setup(
|
routing.Setup(
|
||||||
base.PublicAPIMux, base.Cfg, mediaDB, deviceDB, gomatrixserverlib.NewClient(),
|
router, cfg, mediaDB, deviceDB, gomatrixserverlib.NewClient(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
package publicroomsapi
|
package publicroomsapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
||||||
"github.com/matrix-org/dendrite/internal/basecomponent"
|
"github.com/matrix-org/dendrite/internal/basecomponent"
|
||||||
"github.com/matrix-org/dendrite/publicroomsapi/consumers"
|
"github.com/matrix-org/dendrite/publicroomsapi/consumers"
|
||||||
|
@ -26,9 +27,10 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetupPublicRoomsAPIComponent sets up and registers HTTP handlers for the PublicRoomsAPI
|
// AddPublicRoutes sets up and registers HTTP handlers for the PublicRoomsAPI
|
||||||
// component.
|
// component.
|
||||||
func SetupPublicRoomsAPIComponent(
|
func AddPublicRoutes(
|
||||||
|
router *mux.Router,
|
||||||
base *basecomponent.BaseDendrite,
|
base *basecomponent.BaseDendrite,
|
||||||
deviceDB devices.Database,
|
deviceDB devices.Database,
|
||||||
publicRoomsDB storage.Database,
|
publicRoomsDB storage.Database,
|
||||||
|
@ -43,5 +45,5 @@ func SetupPublicRoomsAPIComponent(
|
||||||
logrus.WithError(err).Panic("failed to start public rooms server consumer")
|
logrus.WithError(err).Panic("failed to start public rooms server consumer")
|
||||||
}
|
}
|
||||||
|
|
||||||
routing.Setup(base.PublicAPIMux, deviceDB, publicRoomsDB, rsAPI, fedClient, extRoomsProvider)
|
routing.Setup(router, deviceDB, publicRoomsDB, rsAPI, fedClient, extRoomsProvider)
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
package roomserver
|
package roomserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"github.com/matrix-org/dendrite/roomserver/api"
|
"github.com/matrix-org/dendrite/roomserver/api"
|
||||||
"github.com/matrix-org/dendrite/roomserver/inthttp"
|
"github.com/matrix-org/dendrite/roomserver/inthttp"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
@ -25,11 +26,15 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetupRoomServerComponent sets up and registers HTTP handlers for the
|
// AddInternalRoutes registers HTTP handlers for the internal API. Invokes functions
|
||||||
// RoomServer component. Returns instances of the various roomserver APIs,
|
// on the given input API.
|
||||||
// allowing other components running in the same process to hit the query the
|
func AddInternalRoutes(router *mux.Router, intAPI api.RoomserverInternalAPI) {
|
||||||
// APIs directly instead of having to use HTTP.
|
inthttp.AddRoutes(intAPI, router)
|
||||||
func SetupRoomServerComponent(
|
}
|
||||||
|
|
||||||
|
// NewInternalAPI returns a concerete implementation of the internal API. Callers
|
||||||
|
// can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes.
|
||||||
|
func NewInternalAPI(
|
||||||
base *basecomponent.BaseDendrite,
|
base *basecomponent.BaseDendrite,
|
||||||
keyRing gomatrixserverlib.JSONVerifier,
|
keyRing gomatrixserverlib.JSONVerifier,
|
||||||
fedClient *gomatrixserverlib.FederationClient,
|
fedClient *gomatrixserverlib.FederationClient,
|
||||||
|
@ -39,7 +44,7 @@ func SetupRoomServerComponent(
|
||||||
logrus.WithError(err).Panicf("failed to connect to room server db")
|
logrus.WithError(err).Panicf("failed to connect to room server db")
|
||||||
}
|
}
|
||||||
|
|
||||||
internalAPI := &internal.RoomserverInternalAPI{
|
return &internal.RoomserverInternalAPI{
|
||||||
DB: roomserverDB,
|
DB: roomserverDB,
|
||||||
Cfg: base.Cfg,
|
Cfg: base.Cfg,
|
||||||
Producer: base.KafkaProducer,
|
Producer: base.KafkaProducer,
|
||||||
|
@ -49,8 +54,4 @@ func SetupRoomServerComponent(
|
||||||
FedClient: fedClient,
|
FedClient: fedClient,
|
||||||
KeyRing: keyRing,
|
KeyRing: keyRing,
|
||||||
}
|
}
|
||||||
|
|
||||||
inthttp.AddRoutes(internalAPI, base.InternalAPIMux)
|
|
||||||
|
|
||||||
return internalAPI
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,9 @@ import (
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/internal/basecomponent"
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/matrix-org/dendrite/internal/caching"
|
||||||
|
"github.com/matrix-org/dendrite/internal/config"
|
||||||
"github.com/matrix-org/dendrite/serverkeyapi/api"
|
"github.com/matrix-org/dendrite/serverkeyapi/api"
|
||||||
"github.com/matrix-org/dendrite/serverkeyapi/internal"
|
"github.com/matrix-org/dendrite/serverkeyapi/internal"
|
||||||
"github.com/matrix-org/dendrite/serverkeyapi/inthttp"
|
"github.com/matrix-org/dendrite/serverkeyapi/inthttp"
|
||||||
|
@ -14,22 +16,31 @@ import (
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetupServerKeyAPIComponent(
|
// AddInternalRoutes registers HTTP handlers for the internal API. Invokes functions
|
||||||
base *basecomponent.BaseDendrite,
|
// on the given input API.
|
||||||
|
func AddInternalRoutes(router *mux.Router, intAPI api.ServerKeyInternalAPI, caches *caching.Caches) {
|
||||||
|
inthttp.AddRoutes(intAPI, router, caches)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewInternalAPI returns a concerete implementation of the internal API. Callers
|
||||||
|
// can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes.
|
||||||
|
func NewInternalAPI(
|
||||||
|
cfg *config.Dendrite,
|
||||||
fedClient *gomatrixserverlib.FederationClient,
|
fedClient *gomatrixserverlib.FederationClient,
|
||||||
|
caches *caching.Caches,
|
||||||
) api.ServerKeyInternalAPI {
|
) api.ServerKeyInternalAPI {
|
||||||
innerDB, err := storage.NewDatabase(
|
innerDB, err := storage.NewDatabase(
|
||||||
string(base.Cfg.Database.ServerKey),
|
string(cfg.Database.ServerKey),
|
||||||
base.Cfg.DbProperties(),
|
cfg.DbProperties(),
|
||||||
base.Cfg.Matrix.ServerName,
|
cfg.Matrix.ServerName,
|
||||||
base.Cfg.Matrix.PrivateKey.Public().(ed25519.PublicKey),
|
cfg.Matrix.PrivateKey.Public().(ed25519.PublicKey),
|
||||||
base.Cfg.Matrix.KeyID,
|
cfg.Matrix.KeyID,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Panicf("failed to connect to server key database")
|
logrus.WithError(err).Panicf("failed to connect to server key database")
|
||||||
}
|
}
|
||||||
|
|
||||||
serverKeyDB, err := cache.NewKeyDatabase(innerDB, base.Caches)
|
serverKeyDB, err := cache.NewKeyDatabase(innerDB, caches)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithError(err).Panicf("failed to set up caching wrapper for server key database")
|
logrus.WithError(err).Panicf("failed to set up caching wrapper for server key database")
|
||||||
}
|
}
|
||||||
|
@ -47,7 +58,7 @@ func SetupServerKeyAPIComponent(
|
||||||
}
|
}
|
||||||
|
|
||||||
var b64e = base64.StdEncoding.WithPadding(base64.NoPadding)
|
var b64e = base64.StdEncoding.WithPadding(base64.NoPadding)
|
||||||
for _, ps := range base.Cfg.Matrix.KeyPerspectives {
|
for _, ps := range cfg.Matrix.KeyPerspectives {
|
||||||
perspective := &gomatrixserverlib.PerspectiveKeyFetcher{
|
perspective := &gomatrixserverlib.PerspectiveKeyFetcher{
|
||||||
PerspectiveServerName: ps.ServerName,
|
PerspectiveServerName: ps.ServerName,
|
||||||
PerspectiveServerKeys: map[gomatrixserverlib.KeyID]ed25519.PublicKey{},
|
PerspectiveServerKeys: map[gomatrixserverlib.KeyID]ed25519.PublicKey{},
|
||||||
|
@ -77,7 +88,5 @@ func SetupServerKeyAPIComponent(
|
||||||
}).Info("Enabled perspective key fetcher")
|
}).Info("Enabled perspective key fetcher")
|
||||||
}
|
}
|
||||||
|
|
||||||
inthttp.AddRoutes(&internalAPI, base.InternalAPIMux, base.Caches)
|
|
||||||
|
|
||||||
return &internalAPI
|
return &internalAPI
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ package syncapi
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||||
|
@ -32,9 +33,10 @@ import (
|
||||||
"github.com/matrix-org/dendrite/syncapi/sync"
|
"github.com/matrix-org/dendrite/syncapi/sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SetupSyncAPIComponent sets up and registers HTTP handlers for the SyncAPI
|
// AddPublicRoutes sets up and registers HTTP handlers for the SyncAPI
|
||||||
// component.
|
// component.
|
||||||
func SetupSyncAPIComponent(
|
func AddPublicRoutes(
|
||||||
|
router *mux.Router,
|
||||||
base *basecomponent.BaseDendrite,
|
base *basecomponent.BaseDendrite,
|
||||||
deviceDB devices.Database,
|
deviceDB devices.Database,
|
||||||
accountsDB accounts.Database,
|
accountsDB accounts.Database,
|
||||||
|
@ -88,5 +90,5 @@ func SetupSyncAPIComponent(
|
||||||
logrus.WithError(err).Panicf("failed to start send-to-device consumer")
|
logrus.WithError(err).Panicf("failed to start send-to-device consumer")
|
||||||
}
|
}
|
||||||
|
|
||||||
routing.Setup(base.PublicAPIMux, requestPool, syncDB, deviceDB, federation, rsAPI, cfg)
|
routing.Setup(router, requestPool, syncDB, deviceDB, federation, rsAPI, cfg)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue