mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-20 05:13:11 -06:00
Finish converting
This commit is contained in:
parent
7c5f89979f
commit
0a8e122ad0
|
|
@ -136,15 +136,15 @@ func main() {
|
|||
deviceDB := base.Base.CreateDeviceDB()
|
||||
federation := createFederationClient(base)
|
||||
|
||||
serverKeyAPI := serverkeyapi.SetupServerKeyAPIComponent(
|
||||
&base.Base, federation,
|
||||
serverKeyAPI := serverkeyapi.NewInternalAPI(
|
||||
base.Base.Cfg, federation, base.Base.Caches,
|
||||
)
|
||||
keyRing := serverKeyAPI.KeyRing()
|
||||
createKeyDB(
|
||||
base, serverKeyAPI,
|
||||
)
|
||||
|
||||
rsAPI := roomserver.SetupRoomServerComponent(
|
||||
rsAPI := roomserver.NewInternalAPI(
|
||||
&base.Base, keyRing, federation,
|
||||
)
|
||||
eduInputAPI := eduserver.NewInternalAPI(
|
||||
|
|
@ -169,8 +169,8 @@ func main() {
|
|||
if err != nil {
|
||||
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
||||
}
|
||||
publicroomsapi.SetupPublicRoomsAPIComponent(&base.Base, deviceDB, publicRoomsDB, rsAPI, federation, nil) // Check this later
|
||||
syncapi.SetupSyncAPIComponent(&base.Base, deviceDB, accountDB, rsAPI, federation, &cfg)
|
||||
publicroomsapi.AddPublicRoutes(base.Base.PublicAPIMux, &base.Base, deviceDB, publicRoomsDB, rsAPI, federation, nil) // Check this later
|
||||
syncapi.AddPublicRoutes(base.Base.PublicAPIMux, &base.Base, deviceDB, accountDB, rsAPI, federation, &cfg)
|
||||
|
||||
internal.SetupHTTPAPI(
|
||||
http.DefaultServeMux,
|
||||
|
|
|
|||
|
|
@ -70,19 +70,21 @@ func main() {
|
|||
deviceDB := base.CreateDeviceDB()
|
||||
federation := base.CreateFederationClient()
|
||||
|
||||
serverKeyAPI := serverkeyapi.SetupServerKeyAPIComponent(
|
||||
base, federation,
|
||||
serverKeyAPI := serverkeyapi.NewInternalAPI(
|
||||
base.Cfg, federation, base.Caches,
|
||||
)
|
||||
if base.UseHTTPAPIs {
|
||||
serverkeyapi.AddInternalRoutes(base.InternalAPIMux, serverKeyAPI, base.Caches)
|
||||
serverKeyAPI = base.ServerKeyAPIClient()
|
||||
}
|
||||
keyRing := serverKeyAPI.KeyRing()
|
||||
|
||||
rsComponent := roomserver.SetupRoomServerComponent(
|
||||
rsComponent := roomserver.NewInternalAPI(
|
||||
base, keyRing, federation,
|
||||
)
|
||||
rsAPI := rsComponent
|
||||
if base.UseHTTPAPIs {
|
||||
roomserver.AddInternalRoutes(base.InternalAPIMux, rsAPI)
|
||||
rsAPI = base.RoomserverHTTPClient()
|
||||
}
|
||||
|
||||
|
|
@ -126,8 +128,8 @@ func main() {
|
|||
if err != nil {
|
||||
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
||||
}
|
||||
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, nil)
|
||||
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg)
|
||||
publicroomsapi.AddPublicRoutes(base.PublicAPIMux, base, deviceDB, publicRoomsDB, rsAPI, federation, nil)
|
||||
syncapi.AddPublicRoutes(base.PublicAPIMux, base, deviceDB, accountDB, rsAPI, federation, cfg)
|
||||
|
||||
internal.SetupHTTPAPI(
|
||||
http.DefaultServeMux,
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ func main() {
|
|||
if err != nil {
|
||||
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))
|
||||
|
||||
|
|
|
|||
|
|
@ -29,8 +29,9 @@ func main() {
|
|||
keyRing := serverKeyAPI.KeyRing()
|
||||
|
||||
fsAPI := base.FederationSenderHTTPClient()
|
||||
rsAPI := roomserver.SetupRoomServerComponent(base, keyRing, federation)
|
||||
rsAPI := roomserver.NewInternalAPI(base, keyRing, federation)
|
||||
rsAPI.SetFederationSenderAPI(fsAPI)
|
||||
roomserver.AddInternalRoutes(base.PublicAPIMux, rsAPI)
|
||||
|
||||
base.SetupAndServeHTTP(string(base.Cfg.Bind.RoomServer), string(base.Cfg.Listen.RoomServer))
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,8 @@ func main() {
|
|||
|
||||
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))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ func main() {
|
|||
|
||||
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))
|
||||
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ func main() {
|
|||
KeyDatabase: fetcher,
|
||||
}
|
||||
|
||||
rsAPI := roomserver.SetupRoomServerComponent(base, keyRing, federation)
|
||||
rsAPI := roomserver.NewInternalAPI(base, keyRing, federation)
|
||||
eduInputAPI := eduserver.NewInternalAPI(base, cache.New(), deviceDB)
|
||||
asQuery := appservice.NewInternalAPI(
|
||||
base, accountDB, deviceDB, rsAPI,
|
||||
|
|
@ -227,8 +227,8 @@ func main() {
|
|||
if err != nil {
|
||||
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
||||
}
|
||||
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, p2pPublicRoomProvider)
|
||||
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg)
|
||||
publicroomsapi.AddPublicRoutes(base.PublicAPIMux, base, deviceDB, publicRoomsDB, rsAPI, federation, p2pPublicRoomProvider)
|
||||
syncapi.AddPublicRoutes(base.PublicAPIMux, base, deviceDB, accountDB, rsAPI, federation, cfg)
|
||||
|
||||
internal.SetupHTTPAPI(
|
||||
http.DefaultServeMux,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
package publicroomsapi
|
||||
|
||||
import (
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
|
||||
"github.com/matrix-org/dendrite/internal/basecomponent"
|
||||
"github.com/matrix-org/dendrite/publicroomsapi/consumers"
|
||||
|
|
@ -26,9 +27,10 @@ import (
|
|||
"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.
|
||||
func SetupPublicRoomsAPIComponent(
|
||||
func AddPublicRoutes(
|
||||
router *mux.Router,
|
||||
base *basecomponent.BaseDendrite,
|
||||
deviceDB devices.Database,
|
||||
publicRoomsDB storage.Database,
|
||||
|
|
@ -43,5 +45,5 @@ func SetupPublicRoomsAPIComponent(
|
|||
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
|
||||
|
||||
import (
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/roomserver/inthttp"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
|
@ -25,11 +26,15 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// SetupRoomServerComponent sets up and registers HTTP handlers for the
|
||||
// RoomServer component. Returns instances of the various roomserver APIs,
|
||||
// allowing other components running in the same process to hit the query the
|
||||
// APIs directly instead of having to use HTTP.
|
||||
func SetupRoomServerComponent(
|
||||
// AddInternalRoutes registers HTTP handlers for the internal API. Invokes functions
|
||||
// on the given input API.
|
||||
func AddInternalRoutes(router *mux.Router, intAPI api.RoomserverInternalAPI) {
|
||||
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,
|
||||
keyRing gomatrixserverlib.JSONVerifier,
|
||||
fedClient *gomatrixserverlib.FederationClient,
|
||||
|
|
@ -39,7 +44,7 @@ func SetupRoomServerComponent(
|
|||
logrus.WithError(err).Panicf("failed to connect to room server db")
|
||||
}
|
||||
|
||||
internalAPI := &internal.RoomserverInternalAPI{
|
||||
return &internal.RoomserverInternalAPI{
|
||||
DB: roomserverDB,
|
||||
Cfg: base.Cfg,
|
||||
Producer: base.KafkaProducer,
|
||||
|
|
@ -49,8 +54,4 @@ func SetupRoomServerComponent(
|
|||
FedClient: fedClient,
|
||||
KeyRing: keyRing,
|
||||
}
|
||||
|
||||
inthttp.AddRoutes(internalAPI, base.InternalAPIMux)
|
||||
|
||||
return internalAPI
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ import (
|
|||
"crypto/ed25519"
|
||||
"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/internal"
|
||||
"github.com/matrix-org/dendrite/serverkeyapi/inthttp"
|
||||
|
|
@ -14,22 +16,31 @@ import (
|
|||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func SetupServerKeyAPIComponent(
|
||||
base *basecomponent.BaseDendrite,
|
||||
// AddInternalRoutes registers HTTP handlers for the internal API. Invokes functions
|
||||
// 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,
|
||||
caches *caching.Caches,
|
||||
) api.ServerKeyInternalAPI {
|
||||
innerDB, err := storage.NewDatabase(
|
||||
string(base.Cfg.Database.ServerKey),
|
||||
base.Cfg.DbProperties(),
|
||||
base.Cfg.Matrix.ServerName,
|
||||
base.Cfg.Matrix.PrivateKey.Public().(ed25519.PublicKey),
|
||||
base.Cfg.Matrix.KeyID,
|
||||
string(cfg.Database.ServerKey),
|
||||
cfg.DbProperties(),
|
||||
cfg.Matrix.ServerName,
|
||||
cfg.Matrix.PrivateKey.Public().(ed25519.PublicKey),
|
||||
cfg.Matrix.KeyID,
|
||||
)
|
||||
if err != nil {
|
||||
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 {
|
||||
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)
|
||||
for _, ps := range base.Cfg.Matrix.KeyPerspectives {
|
||||
for _, ps := range cfg.Matrix.KeyPerspectives {
|
||||
perspective := &gomatrixserverlib.PerspectiveKeyFetcher{
|
||||
PerspectiveServerName: ps.ServerName,
|
||||
PerspectiveServerKeys: map[gomatrixserverlib.KeyID]ed25519.PublicKey{},
|
||||
|
|
@ -77,7 +88,5 @@ func SetupServerKeyAPIComponent(
|
|||
}).Info("Enabled perspective key fetcher")
|
||||
}
|
||||
|
||||
inthttp.AddRoutes(&internalAPI, base.InternalAPIMux, base.Caches)
|
||||
|
||||
return &internalAPI
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ package syncapi
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/matrix-org/dendrite/clientapi/auth/storage/accounts"
|
||||
|
|
@ -32,9 +33,10 @@ import (
|
|||
"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.
|
||||
func SetupSyncAPIComponent(
|
||||
func AddPublicRoutes(
|
||||
router *mux.Router,
|
||||
base *basecomponent.BaseDendrite,
|
||||
deviceDB devices.Database,
|
||||
accountsDB accounts.Database,
|
||||
|
|
@ -88,5 +90,5 @@ func SetupSyncAPIComponent(
|
|||
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 a new issue