Finish converting

This commit is contained in:
Kegan Dougal 2020-06-08 15:04:08 +01:00
parent 7c5f89979f
commit 0a8e122ad0
11 changed files with 63 additions and 45 deletions

View file

@ -136,15 +136,15 @@ 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.NewInternalAPI( eduInputAPI := eduserver.NewInternalAPI(
@ -169,8 +169,8 @@ 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.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,

View file

@ -70,19 +70,21 @@ 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()
} }
@ -126,8 +128,8 @@ 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, 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,

View file

@ -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))

View file

@ -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.PublicAPIMux, 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))

View file

@ -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))
} }

View file

@ -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))

View file

@ -206,7 +206,7 @@ func main() {
KeyDatabase: fetcher, KeyDatabase: fetcher,
} }
rsAPI := roomserver.SetupRoomServerComponent(base, keyRing, federation) rsAPI := roomserver.NewInternalAPI(base, keyRing, federation)
eduInputAPI := eduserver.NewInternalAPI(base, cache.New(), deviceDB) eduInputAPI := eduserver.NewInternalAPI(base, cache.New(), deviceDB)
asQuery := appservice.NewInternalAPI( asQuery := appservice.NewInternalAPI(
base, accountDB, deviceDB, rsAPI, base, accountDB, deviceDB, rsAPI,
@ -227,8 +227,8 @@ 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, 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,

View file

@ -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)
} }

View file

@ -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
} }

View file

@ -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
} }

View file

@ -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)
} }