Consolidation of roomserver APIs (#994)

* Consolidation of roomserver APIs

* Comment out alias tests for now, they are broken

* Wire AS API into roomserver again

* Roomserver didn't take asAPI param before so return to that

* Prevent roomserver asking AS API for alias info

* Rename some files

* Remove alias_test, incoherent tests and unwanted appservice integration

* Remove FS API inject on syncapi component
This commit is contained in:
Neil Alexander 2020-05-01 10:48:17 +01:00 committed by GitHub
parent ebbfc12592
commit e15f6676ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
72 changed files with 894 additions and 1170 deletions

View File

@ -44,8 +44,7 @@ func SetupAppServiceAPIComponent(
accountsDB accounts.Database, accountsDB accounts.Database,
deviceDB devices.Database, deviceDB devices.Database,
federation *gomatrixserverlib.FederationClient, federation *gomatrixserverlib.FederationClient,
roomserverAliasAPI roomserverAPI.RoomserverAliasAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
roomserverQueryAPI roomserverAPI.RoomserverQueryAPI,
transactionsCache *transactions.Cache, transactionsCache *transactions.Cache,
) appserviceAPI.AppServiceQueryAPI { ) appserviceAPI.AppServiceQueryAPI {
// Create a connection to the appservice postgres DB // Create a connection to the appservice postgres DB
@ -87,7 +86,7 @@ func SetupAppServiceAPIComponent(
consumer := consumers.NewOutputRoomEventConsumer( consumer := consumers.NewOutputRoomEventConsumer(
base.Cfg, base.KafkaConsumer, accountsDB, appserviceDB, base.Cfg, base.KafkaConsumer, accountsDB, appserviceDB,
roomserverQueryAPI, roomserverAliasAPI, workerStates, rsAPI, workerStates,
) )
if err := consumer.Start(); err != nil { if err := consumer.Start(); err != nil {
logrus.WithError(err).Panicf("failed to start appservice roomserver consumer") logrus.WithError(err).Panicf("failed to start appservice roomserver consumer")
@ -100,7 +99,7 @@ func SetupAppServiceAPIComponent(
// Set up HTTP Endpoints // Set up HTTP Endpoints
routing.Setup( routing.Setup(
base.APIMux, base.Cfg, roomserverQueryAPI, roomserverAliasAPI, base.APIMux, base.Cfg, rsAPI,
accountsDB, federation, transactionsCache, accountsDB, federation, transactionsCache,
) )

View File

@ -35,8 +35,7 @@ type OutputRoomEventConsumer struct {
roomServerConsumer *common.ContinualConsumer roomServerConsumer *common.ContinualConsumer
db accounts.Database db accounts.Database
asDB storage.Database asDB storage.Database
query api.RoomserverQueryAPI rsAPI api.RoomserverInternalAPI
alias api.RoomserverAliasAPI
serverName string serverName string
workerStates []types.ApplicationServiceWorkerState workerStates []types.ApplicationServiceWorkerState
} }
@ -48,8 +47,7 @@ func NewOutputRoomEventConsumer(
kafkaConsumer sarama.Consumer, kafkaConsumer sarama.Consumer,
store accounts.Database, store accounts.Database,
appserviceDB storage.Database, appserviceDB storage.Database,
queryAPI api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
aliasAPI api.RoomserverAliasAPI,
workerStates []types.ApplicationServiceWorkerState, workerStates []types.ApplicationServiceWorkerState,
) *OutputRoomEventConsumer { ) *OutputRoomEventConsumer {
consumer := common.ContinualConsumer{ consumer := common.ContinualConsumer{
@ -61,8 +59,7 @@ func NewOutputRoomEventConsumer(
roomServerConsumer: &consumer, roomServerConsumer: &consumer,
db: store, db: store,
asDB: appserviceDB, asDB: appserviceDB,
query: queryAPI, rsAPI: rsAPI,
alias: aliasAPI,
serverName: string(cfg.Matrix.ServerName), serverName: string(cfg.Matrix.ServerName),
workerStates: workerStates, workerStates: workerStates,
} }
@ -139,7 +136,7 @@ func (s *OutputRoomEventConsumer) lookupMissingStateEvents(
// Request the missing events from the roomserver // Request the missing events from the roomserver
eventReq := api.QueryEventsByIDRequest{EventIDs: missing} eventReq := api.QueryEventsByIDRequest{EventIDs: missing}
var eventResp api.QueryEventsByIDResponse var eventResp api.QueryEventsByIDResponse
if err := s.query.QueryEventsByID(context.TODO(), &eventReq, &eventResp); err != nil { if err := s.rsAPI.QueryEventsByID(context.TODO(), &eventReq, &eventResp); err != nil {
return nil, err return nil, err
} }
@ -200,7 +197,7 @@ func (s *OutputRoomEventConsumer) appserviceIsInterestedInEvent(ctx context.Cont
// Check all known room aliases of the room the event came from // Check all known room aliases of the room the event came from
queryReq := api.GetAliasesForRoomIDRequest{RoomID: event.RoomID()} queryReq := api.GetAliasesForRoomIDRequest{RoomID: event.RoomID()}
var queryRes api.GetAliasesForRoomIDResponse var queryRes api.GetAliasesForRoomIDResponse
if err := s.alias.GetAliasesForRoomID(ctx, &queryReq, &queryRes); err == nil { if err := s.rsAPI.GetAliasesForRoomID(ctx, &queryReq, &queryRes); err == nil {
for _, alias := range queryRes.Aliases { for _, alias := range queryRes.Aliases {
if appservice.IsInterestedInRoomAlias(alias) { if appservice.IsInterestedInRoomAlias(alias) {
return true return true

View File

@ -37,7 +37,7 @@ const pathPrefixApp = "/_matrix/app/v1"
// nolint: gocyclo // nolint: gocyclo
func Setup( func Setup(
apiMux *mux.Router, cfg *config.Dendrite, // nolint: unparam apiMux *mux.Router, cfg *config.Dendrite, // nolint: unparam
queryAPI api.RoomserverQueryAPI, aliasAPI api.RoomserverAliasAPI, // nolint: unparam rsAPI api.RoomserverInternalAPI, // nolint: unparam
accountDB accounts.Database, // nolint: unparam accountDB accounts.Database, // nolint: unparam
federation *gomatrixserverlib.FederationClient, // nolint: unparam federation *gomatrixserverlib.FederationClient, // nolint: unparam
transactionsCache *transactions.Cache, // nolint: unparam transactionsCache *transactions.Cache, // nolint: unparam

View File

@ -38,15 +38,13 @@ func SetupClientAPIComponent(
accountsDB accounts.Database, accountsDB accounts.Database,
federation *gomatrixserverlib.FederationClient, federation *gomatrixserverlib.FederationClient,
keyRing *gomatrixserverlib.KeyRing, keyRing *gomatrixserverlib.KeyRing,
aliasAPI roomserverAPI.RoomserverAliasAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
inputAPI roomserverAPI.RoomserverInputAPI,
queryAPI roomserverAPI.RoomserverQueryAPI,
eduInputAPI eduServerAPI.EDUServerInputAPI, eduInputAPI eduServerAPI.EDUServerInputAPI,
asAPI appserviceAPI.AppServiceQueryAPI, asAPI appserviceAPI.AppServiceQueryAPI,
transactionsCache *transactions.Cache, transactionsCache *transactions.Cache,
fsAPI federationSenderAPI.FederationSenderInternalAPI, fsAPI federationSenderAPI.FederationSenderInternalAPI,
) { ) {
roomserverProducer := producers.NewRoomserverProducer(inputAPI, queryAPI) roomserverProducer := producers.NewRoomserverProducer(rsAPI)
eduProducer := producers.NewEDUServerProducer(eduInputAPI) eduProducer := producers.NewEDUServerProducer(eduInputAPI)
userUpdateProducer := &producers.UserUpdateProducer{ userUpdateProducer := &producers.UserUpdateProducer{
@ -60,14 +58,14 @@ func SetupClientAPIComponent(
} }
consumer := consumers.NewOutputRoomEventConsumer( consumer := consumers.NewOutputRoomEventConsumer(
base.Cfg, base.KafkaConsumer, accountsDB, queryAPI, base.Cfg, base.KafkaConsumer, accountsDB, rsAPI,
) )
if err := consumer.Start(); err != nil { if err := consumer.Start(); err != nil {
logrus.WithError(err).Panicf("failed to start room server consumer") logrus.WithError(err).Panicf("failed to start room server consumer")
} }
routing.Setup( routing.Setup(
base.APIMux, base.Cfg, roomserverProducer, queryAPI, aliasAPI, asAPI, base.APIMux, base.Cfg, roomserverProducer, rsAPI, asAPI,
accountsDB, deviceDB, federation, *keyRing, userUpdateProducer, accountsDB, deviceDB, federation, *keyRing, userUpdateProducer,
syncProducer, eduProducer, transactionsCache, fsAPI, syncProducer, eduProducer, transactionsCache, fsAPI,
) )

View File

@ -30,10 +30,10 @@ import (
// OutputRoomEventConsumer consumes events that originated in the room server. // OutputRoomEventConsumer consumes events that originated in the room server.
type OutputRoomEventConsumer struct { type OutputRoomEventConsumer struct {
roomServerConsumer *common.ContinualConsumer rsAPI api.RoomserverInternalAPI
db accounts.Database rsConsumer *common.ContinualConsumer
query api.RoomserverQueryAPI db accounts.Database
serverName string serverName string
} }
// NewOutputRoomEventConsumer creates a new OutputRoomEventConsumer. Call Start() to begin consuming from room servers. // NewOutputRoomEventConsumer creates a new OutputRoomEventConsumer. Call Start() to begin consuming from room servers.
@ -41,7 +41,7 @@ func NewOutputRoomEventConsumer(
cfg *config.Dendrite, cfg *config.Dendrite,
kafkaConsumer sarama.Consumer, kafkaConsumer sarama.Consumer,
store accounts.Database, store accounts.Database,
queryAPI api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
) *OutputRoomEventConsumer { ) *OutputRoomEventConsumer {
consumer := common.ContinualConsumer{ consumer := common.ContinualConsumer{
@ -50,10 +50,10 @@ func NewOutputRoomEventConsumer(
PartitionStore: store, PartitionStore: store,
} }
s := &OutputRoomEventConsumer{ s := &OutputRoomEventConsumer{
roomServerConsumer: &consumer, rsConsumer: &consumer,
db: store, db: store,
query: queryAPI, rsAPI: rsAPI,
serverName: string(cfg.Matrix.ServerName), serverName: string(cfg.Matrix.ServerName),
} }
consumer.ProcessMessage = s.onMessage consumer.ProcessMessage = s.onMessage
@ -62,7 +62,7 @@ func NewOutputRoomEventConsumer(
// Start consuming from room servers // Start consuming from room servers
func (s *OutputRoomEventConsumer) Start() error { func (s *OutputRoomEventConsumer) Start() error {
return s.roomServerConsumer.Start() return s.rsConsumer.Start()
} }
// onMessage is called when the sync server receives a new event from the room server output log. // onMessage is called when the sync server receives a new event from the room server output log.
@ -134,7 +134,7 @@ func (s *OutputRoomEventConsumer) lookupStateEvents(
// Request the missing events from the roomserver // Request the missing events from the roomserver
eventReq := api.QueryEventsByIDRequest{EventIDs: missing} eventReq := api.QueryEventsByIDRequest{EventIDs: missing}
var eventResp api.QueryEventsByIDResponse var eventResp api.QueryEventsByIDResponse
if err := s.query.QueryEventsByID(context.TODO(), &eventReq, &eventResp); err != nil { if err := s.rsAPI.QueryEventsByID(context.TODO(), &eventReq, &eventResp); err != nil {
return nil, err return nil, err
} }

View File

@ -23,15 +23,13 @@ import (
// RoomserverProducer produces events for the roomserver to consume. // RoomserverProducer produces events for the roomserver to consume.
type RoomserverProducer struct { type RoomserverProducer struct {
InputAPI api.RoomserverInputAPI RsAPI api.RoomserverInternalAPI
QueryAPI api.RoomserverQueryAPI
} }
// NewRoomserverProducer creates a new RoomserverProducer // NewRoomserverProducer creates a new RoomserverProducer
func NewRoomserverProducer(inputAPI api.RoomserverInputAPI, queryAPI api.RoomserverQueryAPI) *RoomserverProducer { func NewRoomserverProducer(rsAPI api.RoomserverInternalAPI) *RoomserverProducer {
return &RoomserverProducer{ return &RoomserverProducer{
InputAPI: inputAPI, RsAPI: rsAPI,
QueryAPI: queryAPI,
} }
} }
@ -95,7 +93,7 @@ func (c *RoomserverProducer) SendInputRoomEvents(
) (eventID string, err error) { ) (eventID string, err error) {
request := api.InputRoomEventsRequest{InputRoomEvents: ires} request := api.InputRoomEventsRequest{InputRoomEvents: ires}
var response api.InputRoomEventsResponse var response api.InputRoomEventsResponse
err = c.InputAPI.InputRoomEvents(ctx, &request, &response) err = c.RsAPI.InputRoomEvents(ctx, &request, &response)
eventID = response.EventID eventID = response.EventID
return return
} }
@ -118,5 +116,5 @@ func (c *RoomserverProducer) SendInvite(
}}, }},
} }
var response api.InputRoomEventsResponse var response api.InputRoomEventsResponse
return c.InputAPI.InputRoomEvents(ctx, &request, &response) return c.RsAPI.InputRoomEvents(ctx, &request, &response)
} }

View File

@ -26,11 +26,11 @@ import (
// SendMembership implements PUT /rooms/{roomID}/(join|kick|ban|unban|leave|invite) // SendMembership implements PUT /rooms/{roomID}/(join|kick|ban|unban|leave|invite)
// by building a m.room.member event then sending it to the room server // by building a m.room.member event then sending it to the room server
func GetCapabilities( func GetCapabilities(
req *http.Request, queryAPI roomserverAPI.RoomserverQueryAPI, req *http.Request, rsAPI roomserverAPI.RoomserverInternalAPI,
) util.JSONResponse { ) util.JSONResponse {
roomVersionsQueryReq := roomserverAPI.QueryRoomVersionCapabilitiesRequest{} roomVersionsQueryReq := roomserverAPI.QueryRoomVersionCapabilitiesRequest{}
roomVersionsQueryRes := roomserverAPI.QueryRoomVersionCapabilitiesResponse{} roomVersionsQueryRes := roomserverAPI.QueryRoomVersionCapabilitiesResponse{}
if err := queryAPI.QueryRoomVersionCapabilities( if err := rsAPI.QueryRoomVersionCapabilities(
req.Context(), req.Context(),
&roomVersionsQueryReq, &roomVersionsQueryReq,
&roomVersionsQueryRes, &roomVersionsQueryRes,

View File

@ -137,13 +137,13 @@ type fledglingEvent struct {
func CreateRoom( func CreateRoom(
req *http.Request, device *authtypes.Device, req *http.Request, device *authtypes.Device,
cfg *config.Dendrite, producer *producers.RoomserverProducer, cfg *config.Dendrite, producer *producers.RoomserverProducer,
accountDB accounts.Database, aliasAPI roomserverAPI.RoomserverAliasAPI, accountDB accounts.Database, rsAPI roomserverAPI.RoomserverInternalAPI,
asAPI appserviceAPI.AppServiceQueryAPI, asAPI appserviceAPI.AppServiceQueryAPI,
) util.JSONResponse { ) util.JSONResponse {
// TODO (#267): Check room ID doesn't clash with an existing one, and we // TODO (#267): Check room ID doesn't clash with an existing one, and we
// probably shouldn't be using pseudo-random strings, maybe GUIDs? // probably shouldn't be using pseudo-random strings, maybe GUIDs?
roomID := fmt.Sprintf("!%s:%s", util.RandomString(16), cfg.Matrix.ServerName) roomID := fmt.Sprintf("!%s:%s", util.RandomString(16), cfg.Matrix.ServerName)
return createRoom(req, device, cfg, roomID, producer, accountDB, aliasAPI, asAPI) return createRoom(req, device, cfg, roomID, producer, accountDB, rsAPI, asAPI)
} }
// createRoom implements /createRoom // createRoom implements /createRoom
@ -151,7 +151,7 @@ func CreateRoom(
func createRoom( func createRoom(
req *http.Request, device *authtypes.Device, req *http.Request, device *authtypes.Device,
cfg *config.Dendrite, roomID string, producer *producers.RoomserverProducer, cfg *config.Dendrite, roomID string, producer *producers.RoomserverProducer,
accountDB accounts.Database, aliasAPI roomserverAPI.RoomserverAliasAPI, accountDB accounts.Database, rsAPI roomserverAPI.RoomserverInternalAPI,
asAPI appserviceAPI.AppServiceQueryAPI, asAPI appserviceAPI.AppServiceQueryAPI,
) util.JSONResponse { ) util.JSONResponse {
logger := util.GetLogger(req.Context()) logger := util.GetLogger(req.Context())
@ -340,7 +340,7 @@ func createRoom(
} }
var aliasResp roomserverAPI.SetRoomAliasResponse var aliasResp roomserverAPI.SetRoomAliasResponse
err = aliasAPI.SetRoomAlias(req.Context(), &aliasReq, &aliasResp) err = rsAPI.SetRoomAlias(req.Context(), &aliasReq, &aliasResp)
if err != nil { if err != nil {
util.GetLogger(req.Context()).WithError(err).Error("aliasAPI.SetRoomAlias failed") util.GetLogger(req.Context()).WithError(err).Error("aliasAPI.SetRoomAlias failed")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()

View File

@ -46,7 +46,7 @@ func DirectoryRoom(
roomAlias string, roomAlias string,
federation *gomatrixserverlib.FederationClient, federation *gomatrixserverlib.FederationClient,
cfg *config.Dendrite, cfg *config.Dendrite,
rsAPI roomserverAPI.RoomserverAliasAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
fedSenderAPI federationSenderAPI.FederationSenderInternalAPI, fedSenderAPI federationSenderAPI.FederationSenderInternalAPI,
) util.JSONResponse { ) util.JSONResponse {
_, domain, err := gomatrixserverlib.SplitID('#', roomAlias) _, domain, err := gomatrixserverlib.SplitID('#', roomAlias)
@ -115,7 +115,7 @@ func SetLocalAlias(
device *authtypes.Device, device *authtypes.Device,
alias string, alias string,
cfg *config.Dendrite, cfg *config.Dendrite,
aliasAPI roomserverAPI.RoomserverAliasAPI, aliasAPI roomserverAPI.RoomserverInternalAPI,
) util.JSONResponse { ) util.JSONResponse {
_, domain, err := gomatrixserverlib.SplitID('#', alias) _, domain, err := gomatrixserverlib.SplitID('#', alias)
if err != nil { if err != nil {
@ -190,7 +190,7 @@ func RemoveLocalAlias(
req *http.Request, req *http.Request,
device *authtypes.Device, device *authtypes.Device,
alias string, alias string,
aliasAPI roomserverAPI.RoomserverAliasAPI, aliasAPI roomserverAPI.RoomserverInternalAPI,
) util.JSONResponse { ) util.JSONResponse {
creatorQueryReq := roomserverAPI.GetCreatorIDForAliasRequest{ creatorQueryReq := roomserverAPI.GetCreatorIDForAliasRequest{

View File

@ -44,7 +44,7 @@ func GetEvent(
roomID string, roomID string,
eventID string, eventID string,
cfg *config.Dendrite, cfg *config.Dendrite,
queryAPI api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
federation *gomatrixserverlib.FederationClient, federation *gomatrixserverlib.FederationClient,
keyRing gomatrixserverlib.KeyRing, keyRing gomatrixserverlib.KeyRing,
) util.JSONResponse { ) util.JSONResponse {
@ -52,7 +52,7 @@ func GetEvent(
EventIDs: []string{eventID}, EventIDs: []string{eventID},
} }
var eventsResp api.QueryEventsByIDResponse var eventsResp api.QueryEventsByIDResponse
err := queryAPI.QueryEventsByID(req.Context(), &eventsReq, &eventsResp) err := rsAPI.QueryEventsByID(req.Context(), &eventsReq, &eventsResp)
if err != nil { if err != nil {
util.GetLogger(req.Context()).WithError(err).Error("queryAPI.QueryEventsByID failed") util.GetLogger(req.Context()).WithError(err).Error("queryAPI.QueryEventsByID failed")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
@ -88,7 +88,7 @@ func GetEvent(
}}, }},
} }
var stateResp api.QueryStateAfterEventsResponse var stateResp api.QueryStateAfterEventsResponse
if err := queryAPI.QueryStateAfterEvents(req.Context(), &stateReq, &stateResp); err != nil { if err := rsAPI.QueryStateAfterEvents(req.Context(), &stateReq, &stateResp); err != nil {
util.GetLogger(req.Context()).WithError(err).Error("queryAPI.QueryStateAfterEvents failed") util.GetLogger(req.Context()).WithError(err).Error("queryAPI.QueryStateAfterEvents failed")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
} }

View File

@ -43,8 +43,7 @@ func JoinRoomByIDOrAlias(
cfg *config.Dendrite, cfg *config.Dendrite,
federation *gomatrixserverlib.FederationClient, federation *gomatrixserverlib.FederationClient,
producer *producers.RoomserverProducer, producer *producers.RoomserverProducer,
queryAPI roomserverAPI.RoomserverQueryAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
aliasAPI roomserverAPI.RoomserverAliasAPI,
fsAPI federationSenderAPI.FederationSenderInternalAPI, fsAPI federationSenderAPI.FederationSenderInternalAPI,
keyRing gomatrixserverlib.KeyRing, keyRing gomatrixserverlib.KeyRing,
accountDB accounts.Database, accountDB accounts.Database,
@ -80,7 +79,7 @@ func JoinRoomByIDOrAlias(
r := joinRoomReq{ r := joinRoomReq{
req, evTime, content, device.UserID, cfg, federation, producer, req, evTime, content, device.UserID, cfg, federation, producer,
queryAPI, aliasAPI, fsAPI, keyRing, rsAPI, fsAPI, keyRing,
} }
if strings.HasPrefix(roomIDOrAlias, "!") { if strings.HasPrefix(roomIDOrAlias, "!") {
@ -106,8 +105,7 @@ type joinRoomReq struct {
cfg *config.Dendrite cfg *config.Dendrite
federation *gomatrixserverlib.FederationClient federation *gomatrixserverlib.FederationClient
producer *producers.RoomserverProducer producer *producers.RoomserverProducer
queryAPI roomserverAPI.RoomserverQueryAPI rsAPI roomserverAPI.RoomserverInternalAPI
aliasAPI roomserverAPI.RoomserverAliasAPI
fsAPI federationSenderAPI.FederationSenderInternalAPI fsAPI federationSenderAPI.FederationSenderInternalAPI
keyRing gomatrixserverlib.KeyRing keyRing gomatrixserverlib.KeyRing
} }
@ -124,7 +122,7 @@ func (r joinRoomReq) joinRoomByID(roomID string) util.JSONResponse {
RoomID: roomID, TargetUserID: r.userID, RoomID: roomID, TargetUserID: r.userID,
} }
var queryRes roomserverAPI.QueryInvitesForUserResponse var queryRes roomserverAPI.QueryInvitesForUserResponse
if err := r.queryAPI.QueryInvitesForUser(r.req.Context(), &queryReq, &queryRes); err != nil { if err := r.rsAPI.QueryInvitesForUser(r.req.Context(), &queryReq, &queryRes); err != nil {
util.GetLogger(r.req.Context()).WithError(err).Error("r.queryAPI.QueryInvitesForUser failed") util.GetLogger(r.req.Context()).WithError(err).Error("r.queryAPI.QueryInvitesForUser failed")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
} }
@ -172,7 +170,7 @@ func (r joinRoomReq) joinRoomByAlias(roomAlias string) util.JSONResponse {
if domain == r.cfg.Matrix.ServerName { if domain == r.cfg.Matrix.ServerName {
queryReq := roomserverAPI.GetRoomIDForAliasRequest{Alias: roomAlias} queryReq := roomserverAPI.GetRoomIDForAliasRequest{Alias: roomAlias}
var queryRes roomserverAPI.GetRoomIDForAliasResponse var queryRes roomserverAPI.GetRoomIDForAliasResponse
if err = r.aliasAPI.GetRoomIDForAlias(r.req.Context(), &queryReq, &queryRes); err != nil { if err = r.rsAPI.GetRoomIDForAlias(r.req.Context(), &queryReq, &queryRes); err != nil {
util.GetLogger(r.req.Context()).WithError(err).Error("r.aliasAPI.GetRoomIDForAlias failed") util.GetLogger(r.req.Context()).WithError(err).Error("r.aliasAPI.GetRoomIDForAlias failed")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
} }
@ -243,7 +241,7 @@ func (r joinRoomReq) joinRoomUsingServers(
} }
queryRes := roomserverAPI.QueryLatestEventsAndStateResponse{} queryRes := roomserverAPI.QueryLatestEventsAndStateResponse{}
event, err := common.BuildEvent(r.req.Context(), &eb, r.cfg, r.evTime, r.queryAPI, &queryRes) event, err := common.BuildEvent(r.req.Context(), &eb, r.cfg, r.evTime, r.rsAPI, &queryRes)
if err == nil { if err == nil {
// If we have successfully built an event at this point then we can // If we have successfully built an event at this point then we can
// assert that the room is a local room, as BuildEvent was able to // assert that the room is a local room, as BuildEvent was able to

View File

@ -45,12 +45,12 @@ var errMissingUserID = errors.New("'user_id' must be supplied")
func SendMembership( func SendMembership(
req *http.Request, accountDB accounts.Database, device *authtypes.Device, req *http.Request, accountDB accounts.Database, device *authtypes.Device,
roomID string, membership string, cfg *config.Dendrite, roomID string, membership string, cfg *config.Dendrite,
queryAPI roomserverAPI.RoomserverQueryAPI, asAPI appserviceAPI.AppServiceQueryAPI, rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI,
producer *producers.RoomserverProducer, producer *producers.RoomserverProducer,
) util.JSONResponse { ) util.JSONResponse {
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID} verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
verRes := api.QueryRoomVersionForRoomResponse{} verRes := api.QueryRoomVersionForRoomResponse{}
if err := queryAPI.QueryRoomVersionForRoom(req.Context(), &verReq, &verRes); err != nil { if err := rsAPI.QueryRoomVersionForRoom(req.Context(), &verReq, &verRes); err != nil {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
JSON: jsonerror.UnsupportedRoomVersion(err.Error()), JSON: jsonerror.UnsupportedRoomVersion(err.Error()),
@ -71,7 +71,7 @@ func SendMembership(
} }
inviteStored, jsonErrResp := checkAndProcessThreepid( inviteStored, jsonErrResp := checkAndProcessThreepid(
req, device, &body, cfg, queryAPI, accountDB, producer, req, device, &body, cfg, rsAPI, accountDB, producer,
membership, roomID, evTime, membership, roomID, evTime,
) )
if jsonErrResp != nil { if jsonErrResp != nil {
@ -89,7 +89,7 @@ func SendMembership(
} }
event, err := buildMembershipEvent( event, err := buildMembershipEvent(
req.Context(), body, accountDB, device, membership, roomID, cfg, evTime, queryAPI, asAPI, req.Context(), body, accountDB, device, membership, roomID, cfg, evTime, rsAPI, asAPI,
) )
if err == errMissingUserID { if err == errMissingUserID {
return util.JSONResponse{ return util.JSONResponse{
@ -153,7 +153,7 @@ func buildMembershipEvent(
device *authtypes.Device, device *authtypes.Device,
membership, roomID string, membership, roomID string,
cfg *config.Dendrite, evTime time.Time, cfg *config.Dendrite, evTime time.Time,
queryAPI roomserverAPI.RoomserverQueryAPI, asAPI appserviceAPI.AppServiceQueryAPI, rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI,
) (*gomatrixserverlib.Event, error) { ) (*gomatrixserverlib.Event, error) {
stateKey, reason, err := getMembershipStateKey(body, device, membership) stateKey, reason, err := getMembershipStateKey(body, device, membership)
if err != nil { if err != nil {
@ -188,7 +188,7 @@ func buildMembershipEvent(
return nil, err return nil, err
} }
return common.BuildEvent(ctx, &builder, cfg, evTime, queryAPI, nil) return common.BuildEvent(ctx, &builder, cfg, evTime, rsAPI, nil)
} }
// loadProfile lookups the profile of a given user from the database and returns // loadProfile lookups the profile of a given user from the database and returns
@ -248,7 +248,7 @@ func checkAndProcessThreepid(
device *authtypes.Device, device *authtypes.Device,
body *threepid.MembershipRequest, body *threepid.MembershipRequest,
cfg *config.Dendrite, cfg *config.Dendrite,
queryAPI roomserverAPI.RoomserverQueryAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
accountDB accounts.Database, accountDB accounts.Database,
producer *producers.RoomserverProducer, producer *producers.RoomserverProducer,
membership, roomID string, membership, roomID string,
@ -256,7 +256,7 @@ func checkAndProcessThreepid(
) (inviteStored bool, errRes *util.JSONResponse) { ) (inviteStored bool, errRes *util.JSONResponse) {
inviteStored, err := threepid.CheckAndProcessInvite( inviteStored, err := threepid.CheckAndProcessInvite(
req.Context(), device, body, cfg, queryAPI, accountDB, producer, req.Context(), device, body, cfg, rsAPI, accountDB, producer,
membership, roomID, evTime, membership, roomID, evTime,
) )
if err == threepid.ErrMissingParameter { if err == threepid.ErrMissingParameter {

View File

@ -39,7 +39,7 @@ type getJoinedRoomsResponse struct {
func GetMemberships( func GetMemberships(
req *http.Request, device *authtypes.Device, roomID string, joinedOnly bool, req *http.Request, device *authtypes.Device, roomID string, joinedOnly bool,
_ *config.Dendrite, _ *config.Dendrite,
queryAPI api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
) util.JSONResponse { ) util.JSONResponse {
queryReq := api.QueryMembershipsForRoomRequest{ queryReq := api.QueryMembershipsForRoomRequest{
JoinedOnly: joinedOnly, JoinedOnly: joinedOnly,
@ -47,8 +47,8 @@ func GetMemberships(
Sender: device.UserID, Sender: device.UserID,
} }
var queryRes api.QueryMembershipsForRoomResponse var queryRes api.QueryMembershipsForRoomResponse
if err := queryAPI.QueryMembershipsForRoom(req.Context(), &queryReq, &queryRes); err != nil { if err := rsAPI.QueryMembershipsForRoom(req.Context(), &queryReq, &queryRes); err != nil {
util.GetLogger(req.Context()).WithError(err).Error("queryAPI.QueryMembershipsForRoom failed") util.GetLogger(req.Context()).WithError(err).Error("rsAPI.QueryMembershipsForRoom failed")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
} }

View File

@ -94,7 +94,7 @@ func GetAvatarURL(
func SetAvatarURL( func SetAvatarURL(
req *http.Request, accountDB accounts.Database, device *authtypes.Device, req *http.Request, accountDB accounts.Database, device *authtypes.Device,
userID string, producer *producers.UserUpdateProducer, cfg *config.Dendrite, userID string, producer *producers.UserUpdateProducer, cfg *config.Dendrite,
rsProducer *producers.RoomserverProducer, queryAPI api.RoomserverQueryAPI, rsProducer *producers.RoomserverProducer, rsAPI api.RoomserverInternalAPI,
) util.JSONResponse { ) util.JSONResponse {
if userID != device.UserID { if userID != device.UserID {
return util.JSONResponse{ return util.JSONResponse{
@ -154,7 +154,7 @@ func SetAvatarURL(
} }
events, err := buildMembershipEvents( events, err := buildMembershipEvents(
req.Context(), memberships, newProfile, userID, cfg, evTime, queryAPI, req.Context(), memberships, newProfile, userID, cfg, evTime, rsAPI,
) )
if err != nil { if err != nil {
util.GetLogger(req.Context()).WithError(err).Error("buildMembershipEvents failed") util.GetLogger(req.Context()).WithError(err).Error("buildMembershipEvents failed")
@ -208,7 +208,7 @@ func GetDisplayName(
func SetDisplayName( func SetDisplayName(
req *http.Request, accountDB accounts.Database, device *authtypes.Device, req *http.Request, accountDB accounts.Database, device *authtypes.Device,
userID string, producer *producers.UserUpdateProducer, cfg *config.Dendrite, userID string, producer *producers.UserUpdateProducer, cfg *config.Dendrite,
rsProducer *producers.RoomserverProducer, queryAPI api.RoomserverQueryAPI, rsProducer *producers.RoomserverProducer, rsAPI api.RoomserverInternalAPI,
) util.JSONResponse { ) util.JSONResponse {
if userID != device.UserID { if userID != device.UserID {
return util.JSONResponse{ return util.JSONResponse{
@ -268,7 +268,7 @@ func SetDisplayName(
} }
events, err := buildMembershipEvents( events, err := buildMembershipEvents(
req.Context(), memberships, newProfile, userID, cfg, evTime, queryAPI, req.Context(), memberships, newProfile, userID, cfg, evTime, rsAPI,
) )
if err != nil { if err != nil {
util.GetLogger(req.Context()).WithError(err).Error("buildMembershipEvents failed") util.GetLogger(req.Context()).WithError(err).Error("buildMembershipEvents failed")
@ -337,14 +337,14 @@ func buildMembershipEvents(
ctx context.Context, ctx context.Context,
memberships []authtypes.Membership, memberships []authtypes.Membership,
newProfile authtypes.Profile, userID string, cfg *config.Dendrite, newProfile authtypes.Profile, userID string, cfg *config.Dendrite,
evTime time.Time, queryAPI api.RoomserverQueryAPI, evTime time.Time, rsAPI api.RoomserverInternalAPI,
) ([]gomatrixserverlib.HeaderedEvent, error) { ) ([]gomatrixserverlib.HeaderedEvent, error) {
evs := []gomatrixserverlib.HeaderedEvent{} evs := []gomatrixserverlib.HeaderedEvent{}
for _, membership := range memberships { for _, membership := range memberships {
verReq := api.QueryRoomVersionForRoomRequest{RoomID: membership.RoomID} verReq := api.QueryRoomVersionForRoomRequest{RoomID: membership.RoomID}
verRes := api.QueryRoomVersionForRoomResponse{} verRes := api.QueryRoomVersionForRoomResponse{}
if err := queryAPI.QueryRoomVersionForRoom(ctx, &verReq, &verRes); err != nil { if err := rsAPI.QueryRoomVersionForRoom(ctx, &verReq, &verRes); err != nil {
return []gomatrixserverlib.HeaderedEvent{}, err return []gomatrixserverlib.HeaderedEvent{}, err
} }
@ -366,7 +366,7 @@ func buildMembershipEvents(
return nil, err return nil, err
} }
event, err := common.BuildEvent(ctx, &builder, cfg, evTime, queryAPI, nil) event, err := common.BuildEvent(ctx, &builder, cfg, evTime, rsAPI, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -49,8 +49,7 @@ const pathPrefixUnstable = "/_matrix/client/unstable"
func Setup( func Setup(
apiMux *mux.Router, cfg *config.Dendrite, apiMux *mux.Router, cfg *config.Dendrite,
producer *producers.RoomserverProducer, producer *producers.RoomserverProducer,
queryAPI roomserverAPI.RoomserverQueryAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
aliasAPI roomserverAPI.RoomserverAliasAPI,
asAPI appserviceAPI.AppServiceQueryAPI, asAPI appserviceAPI.AppServiceQueryAPI,
accountDB accounts.Database, accountDB accounts.Database,
deviceDB devices.Database, deviceDB devices.Database,
@ -91,7 +90,7 @@ func Setup(
r0mux.Handle("/createRoom", r0mux.Handle("/createRoom",
common.MakeAuthAPI("createRoom", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { common.MakeAuthAPI("createRoom", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
return CreateRoom(req, device, cfg, producer, accountDB, aliasAPI, asAPI) return CreateRoom(req, device, cfg, producer, accountDB, rsAPI, asAPI)
}), }),
).Methods(http.MethodPost, http.MethodOptions) ).Methods(http.MethodPost, http.MethodOptions)
r0mux.Handle("/join/{roomIDOrAlias}", r0mux.Handle("/join/{roomIDOrAlias}",
@ -102,7 +101,7 @@ func Setup(
} }
return JoinRoomByIDOrAlias( return JoinRoomByIDOrAlias(
req, device, vars["roomIDOrAlias"], cfg, federation, producer, req, device, vars["roomIDOrAlias"], cfg, federation, producer,
queryAPI, aliasAPI, federationSender, keyRing, accountDB, rsAPI, federationSender, keyRing, accountDB,
) )
}), }),
).Methods(http.MethodPost, http.MethodOptions) ).Methods(http.MethodPost, http.MethodOptions)
@ -118,7 +117,7 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return SendMembership(req, accountDB, device, vars["roomID"], vars["membership"], cfg, queryAPI, asAPI, producer) return SendMembership(req, accountDB, device, vars["roomID"], vars["membership"], cfg, rsAPI, asAPI, producer)
}), }),
).Methods(http.MethodPost, http.MethodOptions) ).Methods(http.MethodPost, http.MethodOptions)
r0mux.Handle("/rooms/{roomID}/send/{eventType}", r0mux.Handle("/rooms/{roomID}/send/{eventType}",
@ -127,7 +126,7 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, nil, cfg, queryAPI, producer, nil) return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, nil, cfg, rsAPI, producer, nil)
}), }),
).Methods(http.MethodPost, http.MethodOptions) ).Methods(http.MethodPost, http.MethodOptions)
r0mux.Handle("/rooms/{roomID}/send/{eventType}/{txnID}", r0mux.Handle("/rooms/{roomID}/send/{eventType}/{txnID}",
@ -138,7 +137,7 @@ func Setup(
} }
txnID := vars["txnID"] txnID := vars["txnID"]
return SendEvent(req, device, vars["roomID"], vars["eventType"], &txnID, return SendEvent(req, device, vars["roomID"], vars["eventType"], &txnID,
nil, cfg, queryAPI, producer, transactionsCache) nil, cfg, rsAPI, producer, transactionsCache)
}), }),
).Methods(http.MethodPut, http.MethodOptions) ).Methods(http.MethodPut, http.MethodOptions)
r0mux.Handle("/rooms/{roomID}/event/{eventID}", r0mux.Handle("/rooms/{roomID}/event/{eventID}",
@ -147,7 +146,7 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return GetEvent(req, device, vars["roomID"], vars["eventID"], cfg, queryAPI, federation, keyRing) return GetEvent(req, device, vars["roomID"], vars["eventID"], cfg, rsAPI, federation, keyRing)
}), }),
).Methods(http.MethodGet, http.MethodOptions) ).Methods(http.MethodGet, http.MethodOptions)
@ -156,7 +155,7 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return OnIncomingStateRequest(req.Context(), queryAPI, vars["roomID"]) return OnIncomingStateRequest(req.Context(), rsAPI, vars["roomID"])
})).Methods(http.MethodGet, http.MethodOptions) })).Methods(http.MethodGet, http.MethodOptions)
r0mux.Handle("/rooms/{roomID}/state/{type}", common.MakeAuthAPI("room_state", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { r0mux.Handle("/rooms/{roomID}/state/{type}", common.MakeAuthAPI("room_state", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
@ -164,7 +163,7 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return OnIncomingStateTypeRequest(req.Context(), queryAPI, vars["roomID"], vars["type"], "") return OnIncomingStateTypeRequest(req.Context(), rsAPI, vars["roomID"], vars["type"], "")
})).Methods(http.MethodGet, http.MethodOptions) })).Methods(http.MethodGet, http.MethodOptions)
r0mux.Handle("/rooms/{roomID}/state/{type}/{stateKey}", common.MakeAuthAPI("room_state", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { r0mux.Handle("/rooms/{roomID}/state/{type}/{stateKey}", common.MakeAuthAPI("room_state", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
@ -172,7 +171,7 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return OnIncomingStateTypeRequest(req.Context(), queryAPI, vars["roomID"], vars["type"], vars["stateKey"]) return OnIncomingStateTypeRequest(req.Context(), rsAPI, vars["roomID"], vars["type"], vars["stateKey"])
})).Methods(http.MethodGet, http.MethodOptions) })).Methods(http.MethodGet, http.MethodOptions)
r0mux.Handle("/rooms/{roomID}/state/{eventType:[^/]+/?}", r0mux.Handle("/rooms/{roomID}/state/{eventType:[^/]+/?}",
@ -187,7 +186,7 @@ func Setup(
if strings.HasSuffix(eventType, "/") { if strings.HasSuffix(eventType, "/") {
eventType = eventType[:len(eventType)-1] eventType = eventType[:len(eventType)-1]
} }
return SendEvent(req, device, vars["roomID"], eventType, nil, &emptyString, cfg, queryAPI, producer, nil) return SendEvent(req, device, vars["roomID"], eventType, nil, &emptyString, cfg, rsAPI, producer, nil)
}), }),
).Methods(http.MethodPut, http.MethodOptions) ).Methods(http.MethodPut, http.MethodOptions)
@ -198,7 +197,7 @@ func Setup(
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
stateKey := vars["stateKey"] stateKey := vars["stateKey"]
return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, &stateKey, cfg, queryAPI, producer, nil) return SendEvent(req, device, vars["roomID"], vars["eventType"], nil, &stateKey, cfg, rsAPI, producer, nil)
}), }),
).Methods(http.MethodPut, http.MethodOptions) ).Methods(http.MethodPut, http.MethodOptions)
@ -220,7 +219,7 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return DirectoryRoom(req, vars["roomAlias"], federation, cfg, aliasAPI, federationSender) return DirectoryRoom(req, vars["roomAlias"], federation, cfg, rsAPI, federationSender)
}), }),
).Methods(http.MethodGet, http.MethodOptions) ).Methods(http.MethodGet, http.MethodOptions)
@ -230,7 +229,7 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return SetLocalAlias(req, device, vars["roomAlias"], cfg, aliasAPI) return SetLocalAlias(req, device, vars["roomAlias"], cfg, rsAPI)
}), }),
).Methods(http.MethodPut, http.MethodOptions) ).Methods(http.MethodPut, http.MethodOptions)
@ -240,7 +239,7 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return RemoveLocalAlias(req, device, vars["roomAlias"], aliasAPI) return RemoveLocalAlias(req, device, vars["roomAlias"], rsAPI)
}), }),
).Methods(http.MethodDelete, http.MethodOptions) ).Methods(http.MethodDelete, http.MethodOptions)
@ -354,7 +353,7 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return SetAvatarURL(req, accountDB, device, vars["userID"], userUpdateProducer, cfg, producer, queryAPI) return SetAvatarURL(req, accountDB, device, vars["userID"], userUpdateProducer, cfg, producer, rsAPI)
}), }),
).Methods(http.MethodPut, http.MethodOptions) ).Methods(http.MethodPut, http.MethodOptions)
// Browsers use the OPTIONS HTTP method to check if the CORS policy allows // Browsers use the OPTIONS HTTP method to check if the CORS policy allows
@ -376,7 +375,7 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return SetDisplayName(req, accountDB, device, vars["userID"], userUpdateProducer, cfg, producer, queryAPI) return SetDisplayName(req, accountDB, device, vars["userID"], userUpdateProducer, cfg, producer, rsAPI)
}), }),
).Methods(http.MethodPut, http.MethodOptions) ).Methods(http.MethodPut, http.MethodOptions)
// Browsers use the OPTIONS HTTP method to check if the CORS policy allows // Browsers use the OPTIONS HTTP method to check if the CORS policy allows
@ -489,7 +488,7 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return GetMemberships(req, device, vars["roomID"], false, cfg, queryAPI) return GetMemberships(req, device, vars["roomID"], false, cfg, rsAPI)
}), }),
).Methods(http.MethodGet, http.MethodOptions) ).Methods(http.MethodGet, http.MethodOptions)
@ -499,7 +498,7 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return GetMemberships(req, device, vars["roomID"], true, cfg, queryAPI) return GetMemberships(req, device, vars["roomID"], true, cfg, rsAPI)
}), }),
).Methods(http.MethodGet, http.MethodOptions) ).Methods(http.MethodGet, http.MethodOptions)
@ -603,7 +602,7 @@ func Setup(
r0mux.Handle("/capabilities", r0mux.Handle("/capabilities",
common.MakeAuthAPI("capabilities", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { common.MakeAuthAPI("capabilities", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
return GetCapabilities(req, queryAPI) return GetCapabilities(req, rsAPI)
}), }),
).Methods(http.MethodGet) ).Methods(http.MethodGet)
} }

View File

@ -45,13 +45,13 @@ func SendEvent(
device *authtypes.Device, device *authtypes.Device,
roomID, eventType string, txnID, stateKey *string, roomID, eventType string, txnID, stateKey *string,
cfg *config.Dendrite, cfg *config.Dendrite,
queryAPI api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
producer *producers.RoomserverProducer, producer *producers.RoomserverProducer,
txnCache *transactions.Cache, txnCache *transactions.Cache,
) util.JSONResponse { ) util.JSONResponse {
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID} verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
verRes := api.QueryRoomVersionForRoomResponse{} verRes := api.QueryRoomVersionForRoomResponse{}
if err := queryAPI.QueryRoomVersionForRoom(req.Context(), &verReq, &verRes); err != nil { if err := rsAPI.QueryRoomVersionForRoom(req.Context(), &verReq, &verRes); err != nil {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
JSON: jsonerror.UnsupportedRoomVersion(err.Error()), JSON: jsonerror.UnsupportedRoomVersion(err.Error()),
@ -65,7 +65,7 @@ func SendEvent(
} }
} }
e, resErr := generateSendEvent(req, device, roomID, eventType, stateKey, cfg, queryAPI) e, resErr := generateSendEvent(req, device, roomID, eventType, stateKey, cfg, rsAPI)
if resErr != nil { if resErr != nil {
return *resErr return *resErr
} }
@ -115,7 +115,7 @@ func generateSendEvent(
device *authtypes.Device, device *authtypes.Device,
roomID, eventType string, stateKey *string, roomID, eventType string, stateKey *string,
cfg *config.Dendrite, cfg *config.Dendrite,
queryAPI api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
) (*gomatrixserverlib.Event, *util.JSONResponse) { ) (*gomatrixserverlib.Event, *util.JSONResponse) {
// parse the incoming http request // parse the incoming http request
userID := device.UserID userID := device.UserID
@ -148,7 +148,7 @@ func generateSendEvent(
} }
var queryRes api.QueryLatestEventsAndStateResponse var queryRes api.QueryLatestEventsAndStateResponse
e, err := common.BuildEvent(req.Context(), &builder, cfg, evTime, queryAPI, &queryRes) e, err := common.BuildEvent(req.Context(), &builder, cfg, evTime, rsAPI, &queryRes)
if err == common.ErrRoomNoExists { if err == common.ErrRoomNoExists {
return nil, &util.JSONResponse{ return nil, &util.JSONResponse{
Code: http.StatusNotFound, Code: http.StatusNotFound,

View File

@ -40,7 +40,7 @@ type stateEventInStateResp struct {
// TODO: Check if the user is in the room. If not, check if the room's history // TODO: Check if the user is in the room. If not, check if the room's history
// is publicly visible. Current behaviour is returning an empty array if the // is publicly visible. Current behaviour is returning an empty array if the
// user cannot see the room's history. // user cannot see the room's history.
func OnIncomingStateRequest(ctx context.Context, queryAPI api.RoomserverQueryAPI, roomID string) util.JSONResponse { func OnIncomingStateRequest(ctx context.Context, rsAPI api.RoomserverInternalAPI, roomID string) util.JSONResponse {
// TODO(#287): Auth request and handle the case where the user has left (where // TODO(#287): Auth request and handle the case where the user has left (where
// we should return the state at the poin they left) // we should return the state at the poin they left)
stateReq := api.QueryLatestEventsAndStateRequest{ stateReq := api.QueryLatestEventsAndStateRequest{
@ -48,7 +48,7 @@ func OnIncomingStateRequest(ctx context.Context, queryAPI api.RoomserverQueryAPI
} }
stateRes := api.QueryLatestEventsAndStateResponse{} stateRes := api.QueryLatestEventsAndStateResponse{}
if err := queryAPI.QueryLatestEventsAndState(ctx, &stateReq, &stateRes); err != nil { if err := rsAPI.QueryLatestEventsAndState(ctx, &stateReq, &stateRes); err != nil {
util.GetLogger(ctx).WithError(err).Error("queryAPI.QueryLatestEventsAndState failed") util.GetLogger(ctx).WithError(err).Error("queryAPI.QueryLatestEventsAndState failed")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
} }
@ -98,7 +98,7 @@ func OnIncomingStateRequest(ctx context.Context, queryAPI api.RoomserverQueryAPI
// /rooms/{roomID}/state/{type}/{statekey} request. It will look in current // /rooms/{roomID}/state/{type}/{statekey} request. It will look in current
// state to see if there is an event with that type and state key, if there // state to see if there is an event with that type and state key, if there
// is then (by default) we return the content, otherwise a 404. // is then (by default) we return the content, otherwise a 404.
func OnIncomingStateTypeRequest(ctx context.Context, queryAPI api.RoomserverQueryAPI, roomID string, evType, stateKey string) util.JSONResponse { func OnIncomingStateTypeRequest(ctx context.Context, rsAPI api.RoomserverInternalAPI, roomID string, evType, stateKey string) util.JSONResponse {
// TODO(#287): Auth request and handle the case where the user has left (where // TODO(#287): Auth request and handle the case where the user has left (where
// we should return the state at the poin they left) // we should return the state at the poin they left)
util.GetLogger(ctx).WithFields(log.Fields{ util.GetLogger(ctx).WithFields(log.Fields{
@ -118,7 +118,7 @@ func OnIncomingStateTypeRequest(ctx context.Context, queryAPI api.RoomserverQuer
} }
stateRes := api.QueryLatestEventsAndStateResponse{} stateRes := api.QueryLatestEventsAndStateResponse{}
if err := queryAPI.QueryLatestEventsAndState(ctx, &stateReq, &stateRes); err != nil { if err := rsAPI.QueryLatestEventsAndState(ctx, &stateReq, &stateRes); err != nil {
util.GetLogger(ctx).WithError(err).Error("queryAPI.QueryLatestEventsAndState failed") util.GetLogger(ctx).WithError(err).Error("queryAPI.QueryLatestEventsAndState failed")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
} }

View File

@ -87,7 +87,7 @@ var (
func CheckAndProcessInvite( func CheckAndProcessInvite(
ctx context.Context, ctx context.Context,
device *authtypes.Device, body *MembershipRequest, cfg *config.Dendrite, device *authtypes.Device, body *MembershipRequest, cfg *config.Dendrite,
queryAPI api.RoomserverQueryAPI, db accounts.Database, rsAPI api.RoomserverInternalAPI, db accounts.Database,
producer *producers.RoomserverProducer, membership string, roomID string, producer *producers.RoomserverProducer, membership string, roomID string,
evTime time.Time, evTime time.Time,
) (inviteStoredOnIDServer bool, err error) { ) (inviteStoredOnIDServer bool, err error) {
@ -112,7 +112,7 @@ func CheckAndProcessInvite(
// "m.room.third_party_invite" have to be emitted from the data in // "m.room.third_party_invite" have to be emitted from the data in
// storeInviteRes. // storeInviteRes.
err = emit3PIDInviteEvent( err = emit3PIDInviteEvent(
ctx, body, storeInviteRes, device, roomID, cfg, queryAPI, producer, evTime, ctx, body, storeInviteRes, device, roomID, cfg, rsAPI, producer, evTime,
) )
inviteStoredOnIDServer = err == nil inviteStoredOnIDServer = err == nil
@ -331,7 +331,7 @@ func emit3PIDInviteEvent(
ctx context.Context, ctx context.Context,
body *MembershipRequest, res *idServerStoreInviteResponse, body *MembershipRequest, res *idServerStoreInviteResponse,
device *authtypes.Device, roomID string, cfg *config.Dendrite, device *authtypes.Device, roomID string, cfg *config.Dendrite,
queryAPI api.RoomserverQueryAPI, producer *producers.RoomserverProducer, rsAPI api.RoomserverInternalAPI, producer *producers.RoomserverProducer,
evTime time.Time, evTime time.Time,
) error { ) error {
builder := &gomatrixserverlib.EventBuilder{ builder := &gomatrixserverlib.EventBuilder{
@ -354,7 +354,7 @@ func emit3PIDInviteEvent(
} }
queryRes := api.QueryLatestEventsAndStateResponse{} queryRes := api.QueryLatestEventsAndStateResponse{}
event, err := common.BuildEvent(ctx, builder, cfg, evTime, queryAPI, &queryRes) event, err := common.BuildEvent(ctx, builder, cfg, evTime, rsAPI, &queryRes)
if err != nil { if err != nil {
return err return err
} }

View File

@ -28,11 +28,11 @@ func main() {
accountDB := base.CreateAccountsDB() accountDB := base.CreateAccountsDB()
deviceDB := base.CreateDeviceDB() deviceDB := base.CreateDeviceDB()
federation := base.CreateFederationClient() federation := base.CreateFederationClient()
alias, _, query := base.CreateHTTPRoomserverAPIs() rsAPI := base.CreateHTTPRoomserverAPIs()
cache := transactions.New() cache := transactions.New()
appservice.SetupAppServiceAPIComponent( appservice.SetupAppServiceAPIComponent(
base, accountDB, deviceDB, federation, alias, query, cache, base, accountDB, deviceDB, federation, rsAPI, 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))

View File

@ -36,13 +36,14 @@ func main() {
keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives) keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives)
asQuery := base.CreateHTTPAppServiceAPIs() asQuery := base.CreateHTTPAppServiceAPIs()
alias, input, query := base.CreateHTTPRoomserverAPIs() rsAPI := base.CreateHTTPRoomserverAPIs()
fsAPI := base.CreateHTTPFederationSenderAPIs() fsAPI := base.CreateHTTPFederationSenderAPIs()
rsAPI.SetFederationSenderAPI(fsAPI)
eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New()) eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New())
clientapi.SetupClientAPIComponent( clientapi.SetupClientAPIComponent(
base, deviceDB, accountDB, federation, &keyRing, base, deviceDB, accountDB, federation, &keyRing,
alias, input, query, eduInputAPI, asQuery, transactions.New(), fsAPI, rsAPI, eduInputAPI, asQuery, transactions.New(), fsAPI,
) )
base.SetupAndServeHTTP(string(base.Cfg.Bind.ClientAPI), string(base.Cfg.Listen.ClientAPI)) base.SetupAndServeHTTP(string(base.Cfg.Bind.ClientAPI), string(base.Cfg.Listen.ClientAPI))

View File

@ -148,27 +148,34 @@ func main() {
federation := createFederationClient(base) federation := createFederationClient(base)
keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives) keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives)
alias, input, query := roomserver.SetupRoomServerComponent(&base.Base, keyRing, federation) rsAPI := roomserver.SetupRoomServerComponent(
eduInputAPI := eduserver.SetupEDUServerComponent(&base.Base, cache.New()) &base.Base, keyRing, federation,
asQuery := appservice.SetupAppServiceAPIComponent(
&base.Base, accountDB, deviceDB, federation, alias, query, transactions.New(),
) )
fsAPI := federationsender.SetupFederationSenderComponent(&base.Base, federation, query, input, &keyRing) eduInputAPI := eduserver.SetupEDUServerComponent(
&base.Base, cache.New(),
)
asAPI := appservice.SetupAppServiceAPIComponent(
&base.Base, accountDB, deviceDB, federation, rsAPI, transactions.New(),
)
fsAPI := federationsender.SetupFederationSenderComponent(
&base.Base, federation, rsAPI, &keyRing,
)
rsAPI.SetFederationSenderAPI(fsAPI)
clientapi.SetupClientAPIComponent( clientapi.SetupClientAPIComponent(
&base.Base, deviceDB, accountDB, &base.Base, deviceDB, accountDB,
federation, &keyRing, alias, input, query, federation, &keyRing, rsAPI,
eduInputAPI, asQuery, transactions.New(), fsAPI, eduInputAPI, asAPI, transactions.New(), fsAPI,
) )
eduProducer := producers.NewEDUServerProducer(eduInputAPI) eduProducer := producers.NewEDUServerProducer(eduInputAPI)
federationapi.SetupFederationAPIComponent(&base.Base, accountDB, deviceDB, federation, &keyRing, alias, input, query, asQuery, fsAPI, eduProducer) federationapi.SetupFederationAPIComponent(&base.Base, accountDB, deviceDB, federation, &keyRing, rsAPI, asAPI, fsAPI, eduProducer)
mediaapi.SetupMediaAPIComponent(&base.Base, deviceDB) mediaapi.SetupMediaAPIComponent(&base.Base, deviceDB)
publicRoomsDB, err := storage.NewPublicRoomsServerDatabaseWithPubSub(string(base.Base.Cfg.Database.PublicRoomsAPI), base.LibP2PPubsub) publicRoomsDB, err := storage.NewPublicRoomsServerDatabaseWithPubSub(string(base.Base.Cfg.Database.PublicRoomsAPI), base.LibP2PPubsub)
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, query, federation, nil) // Check this later publicroomsapi.SetupPublicRoomsAPIComponent(&base.Base, deviceDB, publicRoomsDB, rsAPI, federation, nil) // Check this later
syncapi.SetupSyncAPIComponent(&base.Base, deviceDB, accountDB, query, federation, &cfg) syncapi.SetupSyncAPIComponent(&base.Base, deviceDB, accountDB, rsAPI, federation, &cfg)
httpHandler := common.WrapHandlerInCORS(base.Base.APIMux) httpHandler := common.WrapHandlerInCORS(base.Base.APIMux)

View File

@ -35,14 +35,15 @@ func main() {
fsAPI := base.CreateHTTPFederationSenderAPIs() fsAPI := base.CreateHTTPFederationSenderAPIs()
keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives) keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives)
alias, input, query := base.CreateHTTPRoomserverAPIs() rsAPI := base.CreateHTTPRoomserverAPIs()
asQuery := base.CreateHTTPAppServiceAPIs() asAPI := base.CreateHTTPAppServiceAPIs()
rsAPI.SetFederationSenderAPI(fsAPI)
eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New()) eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New())
eduProducer := producers.NewEDUServerProducer(eduInputAPI) eduProducer := producers.NewEDUServerProducer(eduInputAPI)
federationapi.SetupFederationAPIComponent( federationapi.SetupFederationAPIComponent(
base, accountDB, deviceDB, federation, &keyRing, base, accountDB, deviceDB, federation, &keyRing,
alias, input, query, asQuery, fsAPI, eduProducer, rsAPI, asAPI, fsAPI, eduProducer,
) )
base.SetupAndServeHTTP(string(base.Cfg.Bind.FederationAPI), string(base.Cfg.Listen.FederationAPI)) base.SetupAndServeHTTP(string(base.Cfg.Bind.FederationAPI), string(base.Cfg.Listen.FederationAPI))

View File

@ -28,12 +28,11 @@ func main() {
federation := base.CreateFederationClient() federation := base.CreateFederationClient()
keyDB := base.CreateKeyDB() keyDB := base.CreateKeyDB()
keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives) keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives)
rsAPI := base.CreateHTTPRoomserverAPIs()
_, input, query := base.CreateHTTPRoomserverAPIs() fsAPI := federationsender.SetupFederationSenderComponent(
base, federation, rsAPI, &keyRing,
federationsender.SetupFederationSenderComponent(
base, federation, query, input, &keyRing,
) )
rsAPI.SetFederationSenderAPI(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))

View File

@ -57,28 +57,34 @@ func main() {
federation := base.CreateFederationClient() federation := base.CreateFederationClient()
keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives) keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives)
alias, input, query := roomserver.SetupRoomServerComponent(base, keyRing, federation) rsAPI := roomserver.SetupRoomServerComponent(
eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New()) base, keyRing, federation,
asQuery := appservice.SetupAppServiceAPIComponent(
base, accountDB, deviceDB, federation, alias, query, transactions.New(),
) )
fsAPI := federationsender.SetupFederationSenderComponent(base, federation, query, input, &keyRing) eduInputAPI := eduserver.SetupEDUServerComponent(
input.SetFederationSenderAPI(fsAPI) base, cache.New(),
)
asAPI := appservice.SetupAppServiceAPIComponent(
base, accountDB, deviceDB, federation, rsAPI, transactions.New(),
)
fsAPI := federationsender.SetupFederationSenderComponent(
base, federation, rsAPI, &keyRing,
)
rsAPI.SetFederationSenderAPI(fsAPI)
clientapi.SetupClientAPIComponent( clientapi.SetupClientAPIComponent(
base, deviceDB, accountDB, base, deviceDB, accountDB,
federation, &keyRing, alias, input, query, federation, &keyRing, rsAPI,
eduInputAPI, asQuery, transactions.New(), fsAPI, eduInputAPI, asAPI, transactions.New(), fsAPI,
) )
eduProducer := producers.NewEDUServerProducer(eduInputAPI) eduProducer := producers.NewEDUServerProducer(eduInputAPI)
federationapi.SetupFederationAPIComponent(base, accountDB, deviceDB, federation, &keyRing, alias, input, query, asQuery, fsAPI, eduProducer) federationapi.SetupFederationAPIComponent(base, accountDB, deviceDB, federation, &keyRing, rsAPI, asAPI, fsAPI, eduProducer)
mediaapi.SetupMediaAPIComponent(base, deviceDB) mediaapi.SetupMediaAPIComponent(base, deviceDB)
publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI)) publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI))
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, query, federation, nil) publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, nil)
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, query, federation, cfg) syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg)
httpHandler := common.WrapHandlerInCORS(base.APIMux) httpHandler := common.WrapHandlerInCORS(base.APIMux)

View File

@ -28,12 +28,15 @@ func main() {
deviceDB := base.CreateDeviceDB() deviceDB := base.CreateDeviceDB()
_, _, query := base.CreateHTTPRoomserverAPIs() fsAPI := base.CreateHTTPFederationSenderAPIs()
rsAPI := base.CreateHTTPRoomserverAPIs()
rsAPI.SetFederationSenderAPI(fsAPI)
publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI)) publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI))
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, query, nil, nil) publicroomsapi.SetupPublicRoomsAPIComponent(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

@ -31,8 +31,8 @@ func main() {
keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives) keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives)
fsAPI := base.CreateHTTPFederationSenderAPIs() fsAPI := base.CreateHTTPFederationSenderAPIs()
_, input, _ := roomserver.SetupRoomServerComponent(base, keyRing, federation) rsAPI := roomserver.SetupRoomServerComponent(base, keyRing, federation)
input.SetFederationSenderAPI(fsAPI) rsAPI.SetFederationSenderAPI(fsAPI)
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

@ -28,9 +28,9 @@ func main() {
accountDB := base.CreateAccountsDB() accountDB := base.CreateAccountsDB()
federation := base.CreateFederationClient() federation := base.CreateFederationClient()
_, _, query := base.CreateHTTPRoomserverAPIs() rsAPI := base.CreateHTTPRoomserverAPIs()
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, query, federation, cfg) syncapi.SetupSyncAPIComponent(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

@ -123,28 +123,28 @@ func main() {
} }
p2pPublicRoomProvider := NewLibP2PPublicRoomsProvider(node) p2pPublicRoomProvider := NewLibP2PPublicRoomsProvider(node)
alias, input, query := roomserver.SetupRoomServerComponent(base, keyRing, federation) rsAPI := roomserver.SetupRoomServerComponent(base, keyRing, federation)
eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New()) eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New())
asQuery := appservice.SetupAppServiceAPIComponent( asQuery := appservice.SetupAppServiceAPIComponent(
base, accountDB, deviceDB, federation, alias, query, transactions.New(), base, accountDB, deviceDB, federation, rsAPI, transactions.New(),
) )
fedSenderAPI := federationsender.SetupFederationSenderComponent(base, federation, query, input, &keyRing) fedSenderAPI := federationsender.SetupFederationSenderComponent(base, federation, rsAPI, &keyRing)
input.SetFederationSenderAPI(fedSenderAPI) rsAPI.SetFederationSenderAPI(fedSenderAPI)
clientapi.SetupClientAPIComponent( clientapi.SetupClientAPIComponent(
base, deviceDB, accountDB, base, deviceDB, accountDB,
federation, &keyRing, alias, input, query, 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, alias, input, query, asQuery, fedSenderAPI, eduProducer) federationapi.SetupFederationAPIComponent(base, accountDB, deviceDB, federation, &keyRing, rsAPI, asQuery, fedSenderAPI, eduProducer)
mediaapi.SetupMediaAPIComponent(base, deviceDB) mediaapi.SetupMediaAPIComponent(base, deviceDB)
publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI)) publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI))
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, query, federation, p2pPublicRoomProvider) publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, p2pPublicRoomProvider)
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, query, federation, cfg) syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg)
httpHandler := common.WrapHandlerInCORS(base.APIMux) httpHandler := common.WrapHandlerInCORS(base.APIMux)

View File

@ -209,7 +209,7 @@ func writeToRoomServer(input []string, roomserverURL string) error {
return err return err
} }
} }
x, err := api.NewRoomserverInputAPIHTTP(roomserverURL, &http.Client{Timeout: timeoutHTTP}) x, err := api.NewRoomserverInternalAPIHTTP(roomserverURL, &http.Client{Timeout: timeoutHTTP}, nil)
if err != nil { if err != nil {
return err return err
} }
@ -225,7 +225,7 @@ func writeToRoomServer(input []string, roomserverURL string) error {
// Once those messages have been written it runs the checkQueries function passing // Once those messages have been written it runs the checkQueries function passing
// a api.RoomserverQueryAPI client. The caller can use this function to check the // a api.RoomserverQueryAPI client. The caller can use this function to check the
// behaviour of the query API. // behaviour of the query API.
func testRoomserver(input []string, wantOutput []string, checkQueries func(api.RoomserverQueryAPI)) { func testRoomserver(input []string, wantOutput []string, checkQueries func(api.RoomserverInternalAPI)) {
dir, err := ioutil.TempDir("", "room-server-test") dir, err := ioutil.TempDir("", "room-server-test")
if err != nil { if err != nil {
panic(err) panic(err)
@ -276,7 +276,7 @@ func testRoomserver(input []string, wantOutput []string, checkQueries func(api.R
cmd.Args = []string{"dendrite-room-server", "--config", filepath.Join(dir, test.ConfigFile)} cmd.Args = []string{"dendrite-room-server", "--config", filepath.Join(dir, test.ConfigFile)}
gotOutput, err := runAndReadFromTopic(cmd, cfg.RoomServerURL()+"/metrics", doInput, outputTopic, len(wantOutput), func() { gotOutput, err := runAndReadFromTopic(cmd, cfg.RoomServerURL()+"/metrics", doInput, outputTopic, len(wantOutput), func() {
queryAPI, _ := api.NewRoomserverQueryAPIHTTP("http://"+string(cfg.Listen.RoomServer), &http.Client{Timeout: timeoutHTTP}, cache) queryAPI, _ := api.NewRoomserverInternalAPIHTTP("http://"+string(cfg.Listen.RoomServer), &http.Client{Timeout: timeoutHTTP}, cache)
checkQueries(queryAPI) checkQueries(queryAPI)
}) })
if err != nil { if err != nil {
@ -410,7 +410,7 @@ func main() {
}}`, }}`,
} }
testRoomserver(input, want, func(q api.RoomserverQueryAPI) { testRoomserver(input, want, func(q api.RoomserverInternalAPI) {
var response api.QueryLatestEventsAndStateResponse var response api.QueryLatestEventsAndStateResponse
if err := q.QueryLatestEventsAndState( if err := q.QueryLatestEventsAndState(
context.Background(), context.Background(),

View File

@ -119,24 +119,12 @@ func (b *BaseDendrite) CreateHTTPAppServiceAPIs() appserviceAPI.AppServiceQueryA
// CreateHTTPRoomserverAPIs returns the AliasAPI, InputAPI and QueryAPI for hitting // CreateHTTPRoomserverAPIs returns the AliasAPI, InputAPI and QueryAPI for hitting
// the roomserver over HTTP. // the roomserver over HTTP.
func (b *BaseDendrite) CreateHTTPRoomserverAPIs() ( func (b *BaseDendrite) CreateHTTPRoomserverAPIs() roomserverAPI.RoomserverInternalAPI {
roomserverAPI.RoomserverAliasAPI, rsAPI, err := roomserverAPI.NewRoomserverInternalAPIHTTP(b.Cfg.RoomServerURL(), b.httpClient, b.ImmutableCache)
roomserverAPI.RoomserverInputAPI,
roomserverAPI.RoomserverQueryAPI,
) {
alias, err := roomserverAPI.NewRoomserverAliasAPIHTTP(b.Cfg.RoomServerURL(), b.httpClient)
if err != nil { if err != nil {
logrus.WithError(err).Panic("NewRoomserverAliasAPIHTTP failed") logrus.WithError(err).Panic("NewRoomserverInternalAPIHTTP failed", b.httpClient)
} }
input, err := roomserverAPI.NewRoomserverInputAPIHTTP(b.Cfg.RoomServerURL(), b.httpClient) return rsAPI
if err != nil {
logrus.WithError(err).Panic("NewRoomserverInputAPIHTTP failed", b.httpClient)
}
query, err := roomserverAPI.NewRoomserverQueryAPIHTTP(b.Cfg.RoomServerURL(), b.httpClient, b.ImmutableCache)
if err != nil {
logrus.WithError(err).Panic("NewRoomserverQueryAPIHTTP failed", b.httpClient)
}
return alias, input, query
} }
// CreateHTTPEDUServerAPIs returns eduInputAPI for hitting the EDU // CreateHTTPEDUServerAPIs returns eduInputAPI for hitting the EDU

View File

@ -39,13 +39,13 @@ var ErrRoomNoExists = errors.New("Room does not exist")
func BuildEvent( func BuildEvent(
ctx context.Context, ctx context.Context,
builder *gomatrixserverlib.EventBuilder, cfg *config.Dendrite, evTime time.Time, builder *gomatrixserverlib.EventBuilder, cfg *config.Dendrite, evTime time.Time,
queryAPI api.RoomserverQueryAPI, queryRes *api.QueryLatestEventsAndStateResponse, rsAPI api.RoomserverInternalAPI, queryRes *api.QueryLatestEventsAndStateResponse,
) (*gomatrixserverlib.Event, error) { ) (*gomatrixserverlib.Event, error) {
if queryRes == nil { if queryRes == nil {
queryRes = &api.QueryLatestEventsAndStateResponse{} queryRes = &api.QueryLatestEventsAndStateResponse{}
} }
err := AddPrevEventsToEvent(ctx, builder, queryAPI, queryRes) err := AddPrevEventsToEvent(ctx, builder, rsAPI, queryRes)
if err != nil { if err != nil {
// This can pass through a ErrRoomNoExists to the caller // This can pass through a ErrRoomNoExists to the caller
return nil, err return nil, err
@ -66,7 +66,7 @@ func BuildEvent(
func AddPrevEventsToEvent( func AddPrevEventsToEvent(
ctx context.Context, ctx context.Context,
builder *gomatrixserverlib.EventBuilder, builder *gomatrixserverlib.EventBuilder,
queryAPI api.RoomserverQueryAPI, queryRes *api.QueryLatestEventsAndStateResponse, rsAPI api.RoomserverInternalAPI, queryRes *api.QueryLatestEventsAndStateResponse,
) error { ) error {
eventsNeeded, err := gomatrixserverlib.StateNeededForEventBuilder(builder) eventsNeeded, err := gomatrixserverlib.StateNeededForEventBuilder(builder)
if err != nil { if err != nil {
@ -82,8 +82,8 @@ func AddPrevEventsToEvent(
RoomID: builder.RoomID, RoomID: builder.RoomID,
StateToFetch: eventsNeeded.Tuples(), StateToFetch: eventsNeeded.Tuples(),
} }
if err = queryAPI.QueryLatestEventsAndState(ctx, &queryReq, queryRes); err != nil { if err = rsAPI.QueryLatestEventsAndState(ctx, &queryReq, queryRes); err != nil {
return fmt.Errorf("queryAPI.QueryLatestEventsAndState: %w", err) return fmt.Errorf("rsAPI.QueryLatestEventsAndState: %w", err)
} }
if !queryRes.RoomExists { if !queryRes.RoomExists {

View File

@ -36,18 +36,16 @@ func SetupFederationAPIComponent(
deviceDB devices.Database, deviceDB devices.Database,
federation *gomatrixserverlib.FederationClient, federation *gomatrixserverlib.FederationClient,
keyRing *gomatrixserverlib.KeyRing, keyRing *gomatrixserverlib.KeyRing,
aliasAPI roomserverAPI.RoomserverAliasAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
inputAPI roomserverAPI.RoomserverInputAPI,
queryAPI roomserverAPI.RoomserverQueryAPI,
asAPI appserviceAPI.AppServiceQueryAPI, asAPI appserviceAPI.AppServiceQueryAPI,
federationSenderAPI federationSenderAPI.FederationSenderInternalAPI, federationSenderAPI federationSenderAPI.FederationSenderInternalAPI,
eduProducer *producers.EDUServerProducer, eduProducer *producers.EDUServerProducer,
) { ) {
roomserverProducer := producers.NewRoomserverProducer(inputAPI, queryAPI) roomserverProducer := producers.NewRoomserverProducer(rsAPI)
routing.Setup( routing.Setup(
base.APIMux, base.Cfg, queryAPI, aliasAPI, asAPI, base.APIMux, base.Cfg, rsAPI, asAPI, roomserverProducer,
roomserverProducer, eduProducer, federationSenderAPI, *keyRing, eduProducer, federationSenderAPI, *keyRing,
federation, accountsDB, deviceDB, federation, accountsDB, deviceDB,
) )
} }

View File

@ -33,7 +33,7 @@ import (
func Backfill( func Backfill(
httpReq *http.Request, httpReq *http.Request,
request *gomatrixserverlib.FederationRequest, request *gomatrixserverlib.FederationRequest,
query api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
roomID string, roomID string,
cfg *config.Dendrite, cfg *config.Dendrite,
) util.JSONResponse { ) util.JSONResponse {
@ -82,7 +82,7 @@ func Backfill(
} }
// Query the roomserver. // Query the roomserver.
if err = query.QueryBackfill(httpReq.Context(), &req, &res); err != nil { if err = rsAPI.QueryBackfill(httpReq.Context(), &req, &res); err != nil {
util.GetLogger(httpReq.Context()).WithError(err).Error("query.QueryBackfill failed") util.GetLogger(httpReq.Context()).WithError(err).Error("query.QueryBackfill failed")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
} }

View File

@ -25,13 +25,13 @@ import (
func GetEventAuth( func GetEventAuth(
ctx context.Context, ctx context.Context,
request *gomatrixserverlib.FederationRequest, request *gomatrixserverlib.FederationRequest,
query api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
roomID string, roomID string,
eventID string, eventID string,
) util.JSONResponse { ) util.JSONResponse {
// TODO: Optimisation: we shouldn't be querying all the room state // TODO: Optimisation: we shouldn't be querying all the room state
// that is in state.StateEvents - we just ignore it. // that is in state.StateEvents - we just ignore it.
state, err := getState(ctx, request, query, roomID, eventID) state, err := getState(ctx, request, rsAPI, roomID, eventID)
if err != nil { if err != nil {
return *err return *err
} }

View File

@ -29,11 +29,11 @@ import (
func GetEvent( func GetEvent(
ctx context.Context, ctx context.Context,
request *gomatrixserverlib.FederationRequest, request *gomatrixserverlib.FederationRequest,
query api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
eventID string, eventID string,
origin gomatrixserverlib.ServerName, origin gomatrixserverlib.ServerName,
) util.JSONResponse { ) util.JSONResponse {
event, err := getEvent(ctx, request, query, eventID) event, err := getEvent(ctx, request, rsAPI, eventID)
if err != nil { if err != nil {
return *err return *err
} }
@ -52,11 +52,11 @@ func GetEvent(
func getEvent( func getEvent(
ctx context.Context, ctx context.Context,
request *gomatrixserverlib.FederationRequest, request *gomatrixserverlib.FederationRequest,
query api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
eventID string, eventID string,
) (*gomatrixserverlib.Event, *util.JSONResponse) { ) (*gomatrixserverlib.Event, *util.JSONResponse) {
var authResponse api.QueryServerAllowedToSeeEventResponse var authResponse api.QueryServerAllowedToSeeEventResponse
err := query.QueryServerAllowedToSeeEvent( err := rsAPI.QueryServerAllowedToSeeEvent(
ctx, ctx,
&api.QueryServerAllowedToSeeEventRequest{ &api.QueryServerAllowedToSeeEventRequest{
EventID: eventID, EventID: eventID,
@ -75,7 +75,7 @@ func getEvent(
} }
var eventsResponse api.QueryEventsByIDResponse var eventsResponse api.QueryEventsByIDResponse
err = query.QueryEventsByID( err = rsAPI.QueryEventsByID(
ctx, ctx,
&api.QueryEventsByIDRequest{EventIDs: []string{eventID}}, &api.QueryEventsByIDRequest{EventIDs: []string{eventID}},
&eventsResponse, &eventsResponse,

View File

@ -33,13 +33,13 @@ func MakeJoin(
httpReq *http.Request, httpReq *http.Request,
request *gomatrixserverlib.FederationRequest, request *gomatrixserverlib.FederationRequest,
cfg *config.Dendrite, cfg *config.Dendrite,
query api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
roomID, userID string, roomID, userID string,
remoteVersions []gomatrixserverlib.RoomVersion, remoteVersions []gomatrixserverlib.RoomVersion,
) util.JSONResponse { ) util.JSONResponse {
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID} verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
verRes := api.QueryRoomVersionForRoomResponse{} verRes := api.QueryRoomVersionForRoomResponse{}
if err := query.QueryRoomVersionForRoom(httpReq.Context(), &verReq, &verRes); err != nil { if err := rsAPI.QueryRoomVersionForRoom(httpReq.Context(), &verReq, &verRes); err != nil {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusInternalServerError, Code: http.StatusInternalServerError,
JSON: jsonerror.InternalServerError(), JSON: jsonerror.InternalServerError(),
@ -97,7 +97,7 @@ func MakeJoin(
queryRes := api.QueryLatestEventsAndStateResponse{ queryRes := api.QueryLatestEventsAndStateResponse{
RoomVersion: verRes.RoomVersion, RoomVersion: verRes.RoomVersion,
} }
event, err := common.BuildEvent(httpReq.Context(), &builder, cfg, time.Now(), query, &queryRes) event, err := common.BuildEvent(httpReq.Context(), &builder, cfg, time.Now(), rsAPI, &queryRes)
if err == common.ErrRoomNoExists { if err == common.ErrRoomNoExists {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusNotFound, Code: http.StatusNotFound,
@ -136,15 +136,15 @@ func SendJoin(
httpReq *http.Request, httpReq *http.Request,
request *gomatrixserverlib.FederationRequest, request *gomatrixserverlib.FederationRequest,
cfg *config.Dendrite, cfg *config.Dendrite,
query api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
producer *producers.RoomserverProducer, producer *producers.RoomserverProducer,
keys gomatrixserverlib.KeyRing, keys gomatrixserverlib.KeyRing,
roomID, eventID string, roomID, eventID string,
) util.JSONResponse { ) util.JSONResponse {
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID} verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
verRes := api.QueryRoomVersionForRoomResponse{} verRes := api.QueryRoomVersionForRoomResponse{}
if err := query.QueryRoomVersionForRoom(httpReq.Context(), &verReq, &verRes); err != nil { if err := rsAPI.QueryRoomVersionForRoom(httpReq.Context(), &verReq, &verRes); err != nil {
util.GetLogger(httpReq.Context()).WithError(err).Error("query.QueryRoomVersionForRoom failed") util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryRoomVersionForRoom failed")
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusInternalServerError, Code: http.StatusInternalServerError,
JSON: jsonerror.InternalServerError(), JSON: jsonerror.InternalServerError(),
@ -216,14 +216,14 @@ func SendJoin(
// Fetch the state and auth chain. We do this before we send the events // Fetch the state and auth chain. We do this before we send the events
// on, in case this fails. // on, in case this fails.
var stateAndAuthChainResponse api.QueryStateAndAuthChainResponse var stateAndAuthChainResponse api.QueryStateAndAuthChainResponse
err = query.QueryStateAndAuthChain(httpReq.Context(), &api.QueryStateAndAuthChainRequest{ err = rsAPI.QueryStateAndAuthChain(httpReq.Context(), &api.QueryStateAndAuthChainRequest{
PrevEventIDs: event.PrevEventIDs(), PrevEventIDs: event.PrevEventIDs(),
AuthEventIDs: event.AuthEventIDs(), AuthEventIDs: event.AuthEventIDs(),
RoomID: roomID, RoomID: roomID,
ResolveState: true, ResolveState: true,
}, &stateAndAuthChainResponse) }, &stateAndAuthChainResponse)
if err != nil { if err != nil {
util.GetLogger(httpReq.Context()).WithError(err).Error("query.QueryStateAndAuthChain failed") util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryStateAndAuthChain failed")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
} }

View File

@ -30,7 +30,7 @@ func MakeLeave(
httpReq *http.Request, httpReq *http.Request,
request *gomatrixserverlib.FederationRequest, request *gomatrixserverlib.FederationRequest,
cfg *config.Dendrite, cfg *config.Dendrite,
query api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
roomID, userID string, roomID, userID string,
) util.JSONResponse { ) util.JSONResponse {
_, domain, err := gomatrixserverlib.SplitID('@', userID) _, domain, err := gomatrixserverlib.SplitID('@', userID)
@ -61,7 +61,7 @@ func MakeLeave(
} }
var queryRes api.QueryLatestEventsAndStateResponse var queryRes api.QueryLatestEventsAndStateResponse
event, err := common.BuildEvent(httpReq.Context(), &builder, cfg, time.Now(), query, &queryRes) event, err := common.BuildEvent(httpReq.Context(), &builder, cfg, time.Now(), rsAPI, &queryRes)
if err == common.ErrRoomNoExists { if err == common.ErrRoomNoExists {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusNotFound, Code: http.StatusNotFound,
@ -102,7 +102,7 @@ func SendLeave(
) util.JSONResponse { ) util.JSONResponse {
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID} verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
verRes := api.QueryRoomVersionForRoomResponse{} verRes := api.QueryRoomVersionForRoomResponse{}
if err := producer.QueryAPI.QueryRoomVersionForRoom(httpReq.Context(), &verReq, &verRes); err != nil { if err := producer.RsAPI.QueryRoomVersionForRoom(httpReq.Context(), &verReq, &verRes); err != nil {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
JSON: jsonerror.UnsupportedRoomVersion(err.Error()), JSON: jsonerror.UnsupportedRoomVersion(err.Error()),

View File

@ -34,7 +34,7 @@ type getMissingEventRequest struct {
func GetMissingEvents( func GetMissingEvents(
httpReq *http.Request, httpReq *http.Request,
request *gomatrixserverlib.FederationRequest, request *gomatrixserverlib.FederationRequest,
query api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
roomID string, roomID string,
) util.JSONResponse { ) util.JSONResponse {
var gme getMissingEventRequest var gme getMissingEventRequest
@ -46,7 +46,7 @@ func GetMissingEvents(
} }
var eventsResponse api.QueryMissingEventsResponse var eventsResponse api.QueryMissingEventsResponse
if err := query.QueryMissingEvents( if err := rsAPI.QueryMissingEvents(
httpReq.Context(), &api.QueryMissingEventsRequest{ httpReq.Context(), &api.QueryMissingEventsRequest{
EarliestEvents: gme.EarliestEvents, EarliestEvents: gme.EarliestEvents,
LatestEvents: gme.LatestEvents, LatestEvents: gme.LatestEvents,

View File

@ -32,7 +32,7 @@ func RoomAliasToID(
httpReq *http.Request, httpReq *http.Request,
federation *gomatrixserverlib.FederationClient, federation *gomatrixserverlib.FederationClient,
cfg *config.Dendrite, cfg *config.Dendrite,
aliasAPI roomserverAPI.RoomserverAliasAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
senderAPI federationSenderAPI.FederationSenderInternalAPI, senderAPI federationSenderAPI.FederationSenderInternalAPI,
) util.JSONResponse { ) util.JSONResponse {
roomAlias := httpReq.FormValue("room_alias") roomAlias := httpReq.FormValue("room_alias")
@ -55,7 +55,7 @@ func RoomAliasToID(
if domain == cfg.Matrix.ServerName { if domain == cfg.Matrix.ServerName {
queryReq := roomserverAPI.GetRoomIDForAliasRequest{Alias: roomAlias} queryReq := roomserverAPI.GetRoomIDForAliasRequest{Alias: roomAlias}
var queryRes roomserverAPI.GetRoomIDForAliasResponse var queryRes roomserverAPI.GetRoomIDForAliasResponse
if err = aliasAPI.GetRoomIDForAlias(httpReq.Context(), &queryReq, &queryRes); err != nil { if err = rsAPI.GetRoomIDForAlias(httpReq.Context(), &queryReq, &queryRes); err != nil {
util.GetLogger(httpReq.Context()).WithError(err).Error("aliasAPI.GetRoomIDForAlias failed") util.GetLogger(httpReq.Context()).WithError(err).Error("aliasAPI.GetRoomIDForAlias failed")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
} }

View File

@ -44,8 +44,7 @@ const (
func Setup( func Setup(
apiMux *mux.Router, apiMux *mux.Router,
cfg *config.Dendrite, cfg *config.Dendrite,
query roomserverAPI.RoomserverQueryAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
aliasAPI roomserverAPI.RoomserverAliasAPI,
asAPI appserviceAPI.AppServiceQueryAPI, asAPI appserviceAPI.AppServiceQueryAPI,
producer *producers.RoomserverProducer, producer *producers.RoomserverProducer,
eduProducer *producers.EDUServerProducer, eduProducer *producers.EDUServerProducer,
@ -80,7 +79,7 @@ func Setup(
} }
return Send( return Send(
httpReq, request, gomatrixserverlib.TransactionID(vars["txnID"]), httpReq, request, gomatrixserverlib.TransactionID(vars["txnID"]),
cfg, query, producer, eduProducer, keys, federation, cfg, rsAPI, producer, eduProducer, keys, federation,
) )
}, },
)).Methods(http.MethodPut, http.MethodOptions) )).Methods(http.MethodPut, http.MethodOptions)
@ -101,7 +100,7 @@ func Setup(
v1fedmux.Handle("/3pid/onbind", common.MakeExternalAPI("3pid_onbind", v1fedmux.Handle("/3pid/onbind", common.MakeExternalAPI("3pid_onbind",
func(req *http.Request) util.JSONResponse { func(req *http.Request) util.JSONResponse {
return CreateInvitesFrom3PIDInvites(req, query, asAPI, cfg, producer, federation, accountDB) return CreateInvitesFrom3PIDInvites(req, rsAPI, asAPI, cfg, producer, federation, accountDB)
}, },
)).Methods(http.MethodPost, http.MethodOptions) )).Methods(http.MethodPost, http.MethodOptions)
@ -113,7 +112,7 @@ func Setup(
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return ExchangeThirdPartyInvite( return ExchangeThirdPartyInvite(
httpReq, request, vars["roomID"], query, cfg, federation, producer, httpReq, request, vars["roomID"], rsAPI, cfg, federation, producer,
) )
}, },
)).Methods(http.MethodPut, http.MethodOptions) )).Methods(http.MethodPut, http.MethodOptions)
@ -126,7 +125,7 @@ func Setup(
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return GetEvent( return GetEvent(
httpReq.Context(), request, query, vars["eventID"], cfg.Matrix.ServerName, httpReq.Context(), request, rsAPI, vars["eventID"], cfg.Matrix.ServerName,
) )
}, },
)).Methods(http.MethodGet) )).Methods(http.MethodGet)
@ -139,7 +138,7 @@ func Setup(
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return GetState( return GetState(
httpReq.Context(), request, query, vars["roomID"], httpReq.Context(), request, rsAPI, vars["roomID"],
) )
}, },
)).Methods(http.MethodGet) )).Methods(http.MethodGet)
@ -152,7 +151,7 @@ func Setup(
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return GetStateIDs( return GetStateIDs(
httpReq.Context(), request, query, vars["roomID"], httpReq.Context(), request, rsAPI, vars["roomID"],
) )
}, },
)).Methods(http.MethodGet) )).Methods(http.MethodGet)
@ -162,7 +161,7 @@ func Setup(
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
vars := mux.Vars(httpReq) vars := mux.Vars(httpReq)
return GetEventAuth( return GetEventAuth(
httpReq.Context(), request, query, vars["roomID"], vars["eventID"], httpReq.Context(), request, rsAPI, vars["roomID"], vars["eventID"],
) )
}, },
)).Methods(http.MethodGet) )).Methods(http.MethodGet)
@ -171,7 +170,7 @@ func Setup(
"federation_query_room_alias", cfg.Matrix.ServerName, keys, "federation_query_room_alias", cfg.Matrix.ServerName, keys,
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse { func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
return RoomAliasToID( return RoomAliasToID(
httpReq, federation, cfg, aliasAPI, federationSenderAPI, httpReq, federation, cfg, rsAPI, federationSenderAPI,
) )
}, },
)).Methods(http.MethodGet) )).Methods(http.MethodGet)
@ -222,7 +221,7 @@ func Setup(
remoteVersions = append(remoteVersions, gomatrixserverlib.RoomVersionV1) remoteVersions = append(remoteVersions, gomatrixserverlib.RoomVersionV1)
} }
return MakeJoin( return MakeJoin(
httpReq, request, cfg, query, roomID, eventID, remoteVersions, httpReq, request, cfg, rsAPI, roomID, eventID, remoteVersions,
) )
}, },
)).Methods(http.MethodGet) )).Methods(http.MethodGet)
@ -237,7 +236,7 @@ func Setup(
roomID := vars["roomID"] roomID := vars["roomID"]
eventID := vars["eventID"] eventID := vars["eventID"]
return SendJoin( return SendJoin(
httpReq, request, cfg, query, producer, keys, roomID, eventID, httpReq, request, cfg, rsAPI, producer, keys, roomID, eventID,
) )
}, },
)).Methods(http.MethodPut) )).Methods(http.MethodPut)
@ -252,7 +251,7 @@ func Setup(
roomID := vars["roomID"] roomID := vars["roomID"]
eventID := vars["eventID"] eventID := vars["eventID"]
return MakeLeave( return MakeLeave(
httpReq, request, cfg, query, roomID, eventID, httpReq, request, cfg, rsAPI, roomID, eventID,
) )
}, },
)).Methods(http.MethodGet) )).Methods(http.MethodGet)
@ -286,7 +285,7 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return GetMissingEvents(httpReq, request, query, vars["roomID"]) return GetMissingEvents(httpReq, request, rsAPI, vars["roomID"])
}, },
)).Methods(http.MethodPost) )).Methods(http.MethodPost)
@ -297,7 +296,7 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return Backfill(httpReq, request, query, vars["roomID"], cfg) return Backfill(httpReq, request, rsAPI, vars["roomID"], cfg)
}, },
)).Methods(http.MethodGet) )).Methods(http.MethodGet)
} }

View File

@ -34,7 +34,7 @@ func Send(
request *gomatrixserverlib.FederationRequest, request *gomatrixserverlib.FederationRequest,
txnID gomatrixserverlib.TransactionID, txnID gomatrixserverlib.TransactionID,
cfg *config.Dendrite, cfg *config.Dendrite,
query api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
producer *producers.RoomserverProducer, producer *producers.RoomserverProducer,
eduProducer *producers.EDUServerProducer, eduProducer *producers.EDUServerProducer,
keys gomatrixserverlib.KeyRing, keys gomatrixserverlib.KeyRing,
@ -42,7 +42,7 @@ func Send(
) util.JSONResponse { ) util.JSONResponse {
t := txnReq{ t := txnReq{
context: httpReq.Context(), context: httpReq.Context(),
query: query, rsAPI: rsAPI,
producer: producer, producer: producer,
eduProducer: eduProducer, eduProducer: eduProducer,
keys: keys, keys: keys,
@ -99,7 +99,7 @@ func Send(
type txnReq struct { type txnReq struct {
gomatrixserverlib.Transaction gomatrixserverlib.Transaction
context context.Context context context.Context
query api.RoomserverQueryAPI rsAPI api.RoomserverInternalAPI
producer *producers.RoomserverProducer producer *producers.RoomserverProducer
eduProducer *producers.EDUServerProducer eduProducer *producers.EDUServerProducer
keys gomatrixserverlib.KeyRing keys gomatrixserverlib.KeyRing
@ -120,7 +120,7 @@ func (t *txnReq) processTransaction() (*gomatrixserverlib.RespSend, error) {
} }
verReq := api.QueryRoomVersionForRoomRequest{RoomID: header.RoomID} verReq := api.QueryRoomVersionForRoomRequest{RoomID: header.RoomID}
verRes := api.QueryRoomVersionForRoomResponse{} verRes := api.QueryRoomVersionForRoomResponse{}
if err := t.query.QueryRoomVersionForRoom(t.context, &verReq, &verRes); err != nil { if err := t.rsAPI.QueryRoomVersionForRoom(t.context, &verReq, &verRes); err != nil {
util.GetLogger(t.context).WithError(err).Warn("Transaction: Failed to query room version for room", verReq.RoomID) util.GetLogger(t.context).WithError(err).Warn("Transaction: Failed to query room version for room", verReq.RoomID)
return nil, roomNotFoundError{verReq.RoomID} return nil, roomNotFoundError{verReq.RoomID}
} }
@ -228,7 +228,7 @@ func (t *txnReq) processEvent(e gomatrixserverlib.Event) error {
StateToFetch: needed.Tuples(), StateToFetch: needed.Tuples(),
} }
var stateResp api.QueryStateAfterEventsResponse var stateResp api.QueryStateAfterEventsResponse
if err := t.query.QueryStateAfterEvents(t.context, &stateReq, &stateResp); err != nil { if err := t.rsAPI.QueryStateAfterEvents(t.context, &stateReq, &stateResp); err != nil {
return err return err
} }

View File

@ -27,7 +27,7 @@ import (
func GetState( func GetState(
ctx context.Context, ctx context.Context,
request *gomatrixserverlib.FederationRequest, request *gomatrixserverlib.FederationRequest,
query api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
roomID string, roomID string,
) util.JSONResponse { ) util.JSONResponse {
eventID, err := parseEventIDParam(request) eventID, err := parseEventIDParam(request)
@ -35,7 +35,7 @@ func GetState(
return *err return *err
} }
state, err := getState(ctx, request, query, roomID, eventID) state, err := getState(ctx, request, rsAPI, roomID, eventID)
if err != nil { if err != nil {
return *err return *err
} }
@ -47,7 +47,7 @@ func GetState(
func GetStateIDs( func GetStateIDs(
ctx context.Context, ctx context.Context,
request *gomatrixserverlib.FederationRequest, request *gomatrixserverlib.FederationRequest,
query api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
roomID string, roomID string,
) util.JSONResponse { ) util.JSONResponse {
eventID, err := parseEventIDParam(request) eventID, err := parseEventIDParam(request)
@ -55,7 +55,7 @@ func GetStateIDs(
return *err return *err
} }
state, err := getState(ctx, request, query, roomID, eventID) state, err := getState(ctx, request, rsAPI, roomID, eventID)
if err != nil { if err != nil {
return *err return *err
} }
@ -94,11 +94,11 @@ func parseEventIDParam(
func getState( func getState(
ctx context.Context, ctx context.Context,
request *gomatrixserverlib.FederationRequest, request *gomatrixserverlib.FederationRequest,
query api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
roomID string, roomID string,
eventID string, eventID string,
) (*gomatrixserverlib.RespState, *util.JSONResponse) { ) (*gomatrixserverlib.RespState, *util.JSONResponse) {
event, resErr := getEvent(ctx, request, query, eventID) event, resErr := getEvent(ctx, request, rsAPI, eventID)
if resErr != nil { if resErr != nil {
return nil, resErr return nil, resErr
} }
@ -110,7 +110,7 @@ func getState(
authEventIDs := getIDsFromEventRef(event.AuthEvents()) authEventIDs := getIDsFromEventRef(event.AuthEvents())
var response api.QueryStateAndAuthChainResponse var response api.QueryStateAndAuthChainResponse
err := query.QueryStateAndAuthChain( err := rsAPI.QueryStateAndAuthChain(
ctx, ctx,
&api.QueryStateAndAuthChainRequest{ &api.QueryStateAndAuthChainRequest{
RoomID: roomID, RoomID: roomID,

View File

@ -58,7 +58,7 @@ var (
// CreateInvitesFrom3PIDInvites implements POST /_matrix/federation/v1/3pid/onbind // CreateInvitesFrom3PIDInvites implements POST /_matrix/federation/v1/3pid/onbind
func CreateInvitesFrom3PIDInvites( func CreateInvitesFrom3PIDInvites(
req *http.Request, queryAPI roomserverAPI.RoomserverQueryAPI, req *http.Request, rsAPI roomserverAPI.RoomserverInternalAPI,
asAPI appserviceAPI.AppServiceQueryAPI, cfg *config.Dendrite, asAPI appserviceAPI.AppServiceQueryAPI, cfg *config.Dendrite,
producer *producers.RoomserverProducer, federation *gomatrixserverlib.FederationClient, producer *producers.RoomserverProducer, federation *gomatrixserverlib.FederationClient,
accountDB accounts.Database, accountDB accounts.Database,
@ -72,7 +72,7 @@ func CreateInvitesFrom3PIDInvites(
for _, inv := range body.Invites { for _, inv := range body.Invites {
verReq := api.QueryRoomVersionForRoomRequest{RoomID: inv.RoomID} verReq := api.QueryRoomVersionForRoomRequest{RoomID: inv.RoomID}
verRes := api.QueryRoomVersionForRoomResponse{} verRes := api.QueryRoomVersionForRoomResponse{}
if err := queryAPI.QueryRoomVersionForRoom(req.Context(), &verReq, &verRes); err != nil { if err := rsAPI.QueryRoomVersionForRoom(req.Context(), &verReq, &verRes); err != nil {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
JSON: jsonerror.UnsupportedRoomVersion(err.Error()), JSON: jsonerror.UnsupportedRoomVersion(err.Error()),
@ -80,7 +80,7 @@ func CreateInvitesFrom3PIDInvites(
} }
event, err := createInviteFrom3PIDInvite( event, err := createInviteFrom3PIDInvite(
req.Context(), queryAPI, asAPI, cfg, inv, federation, accountDB, req.Context(), rsAPI, asAPI, cfg, inv, federation, accountDB,
) )
if err != nil { if err != nil {
util.GetLogger(req.Context()).WithError(err).Error("createInviteFrom3PIDInvite failed") util.GetLogger(req.Context()).WithError(err).Error("createInviteFrom3PIDInvite failed")
@ -108,7 +108,7 @@ func ExchangeThirdPartyInvite(
httpReq *http.Request, httpReq *http.Request,
request *gomatrixserverlib.FederationRequest, request *gomatrixserverlib.FederationRequest,
roomID string, roomID string,
queryAPI roomserverAPI.RoomserverQueryAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
cfg *config.Dendrite, cfg *config.Dendrite,
federation *gomatrixserverlib.FederationClient, federation *gomatrixserverlib.FederationClient,
producer *producers.RoomserverProducer, producer *producers.RoomserverProducer,
@ -148,7 +148,7 @@ func ExchangeThirdPartyInvite(
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID} verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
verRes := api.QueryRoomVersionForRoomResponse{} verRes := api.QueryRoomVersionForRoomResponse{}
if err = queryAPI.QueryRoomVersionForRoom(httpReq.Context(), &verReq, &verRes); err != nil { if err = rsAPI.QueryRoomVersionForRoom(httpReq.Context(), &verReq, &verRes); err != nil {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusBadRequest, Code: http.StatusBadRequest,
JSON: jsonerror.UnsupportedRoomVersion(err.Error()), JSON: jsonerror.UnsupportedRoomVersion(err.Error()),
@ -156,7 +156,7 @@ func ExchangeThirdPartyInvite(
} }
// Auth and build the event from what the remote server sent us // Auth and build the event from what the remote server sent us
event, err := buildMembershipEvent(httpReq.Context(), &builder, queryAPI, cfg) event, err := buildMembershipEvent(httpReq.Context(), &builder, rsAPI, cfg)
if err == errNotInRoom { if err == errNotInRoom {
return util.JSONResponse{ return util.JSONResponse{
Code: http.StatusNotFound, Code: http.StatusNotFound,
@ -199,14 +199,14 @@ func ExchangeThirdPartyInvite(
// Returns an error if there was a problem building the event or fetching the // Returns an error if there was a problem building the event or fetching the
// necessary data to do so. // necessary data to do so.
func createInviteFrom3PIDInvite( func createInviteFrom3PIDInvite(
ctx context.Context, queryAPI roomserverAPI.RoomserverQueryAPI, ctx context.Context, rsAPI roomserverAPI.RoomserverInternalAPI,
asAPI appserviceAPI.AppServiceQueryAPI, cfg *config.Dendrite, asAPI appserviceAPI.AppServiceQueryAPI, cfg *config.Dendrite,
inv invite, federation *gomatrixserverlib.FederationClient, inv invite, federation *gomatrixserverlib.FederationClient,
accountDB accounts.Database, accountDB accounts.Database,
) (*gomatrixserverlib.Event, error) { ) (*gomatrixserverlib.Event, error) {
verReq := api.QueryRoomVersionForRoomRequest{RoomID: inv.RoomID} verReq := api.QueryRoomVersionForRoomRequest{RoomID: inv.RoomID}
verRes := api.QueryRoomVersionForRoomResponse{} verRes := api.QueryRoomVersionForRoomResponse{}
if err := queryAPI.QueryRoomVersionForRoom(ctx, &verReq, &verRes); err != nil { if err := rsAPI.QueryRoomVersionForRoom(ctx, &verReq, &verRes); err != nil {
return nil, err return nil, err
} }
@ -245,7 +245,7 @@ func createInviteFrom3PIDInvite(
return nil, err return nil, err
} }
event, err := buildMembershipEvent(ctx, builder, queryAPI, cfg) event, err := buildMembershipEvent(ctx, builder, rsAPI, cfg)
if err == errNotInRoom { if err == errNotInRoom {
return nil, sendToRemoteServer(ctx, inv, federation, cfg, *builder) return nil, sendToRemoteServer(ctx, inv, federation, cfg, *builder)
} }
@ -263,7 +263,7 @@ func createInviteFrom3PIDInvite(
// Returns an error if something failed during the process. // Returns an error if something failed during the process.
func buildMembershipEvent( func buildMembershipEvent(
ctx context.Context, ctx context.Context,
builder *gomatrixserverlib.EventBuilder, queryAPI roomserverAPI.RoomserverQueryAPI, builder *gomatrixserverlib.EventBuilder, rsAPI roomserverAPI.RoomserverInternalAPI,
cfg *config.Dendrite, cfg *config.Dendrite,
) (*gomatrixserverlib.Event, error) { ) (*gomatrixserverlib.Event, error) {
eventsNeeded, err := gomatrixserverlib.StateNeededForEventBuilder(builder) eventsNeeded, err := gomatrixserverlib.StateNeededForEventBuilder(builder)
@ -281,7 +281,7 @@ func buildMembershipEvent(
StateToFetch: eventsNeeded.Tuples(), StateToFetch: eventsNeeded.Tuples(),
} }
var queryRes roomserverAPI.QueryLatestEventsAndStateResponse var queryRes roomserverAPI.QueryLatestEventsAndStateResponse
if err = queryAPI.QueryLatestEventsAndState(ctx, &queryReq, &queryRes); err != nil { if err = rsAPI.QueryLatestEventsAndState(ctx, &queryReq, &queryRes); err != nil {
return nil, err return nil, err
} }

View File

@ -33,11 +33,11 @@ import (
// OutputRoomEventConsumer consumes events that originated in the room server. // OutputRoomEventConsumer consumes events that originated in the room server.
type OutputRoomEventConsumer struct { type OutputRoomEventConsumer struct {
cfg *config.Dendrite cfg *config.Dendrite
roomServerConsumer *common.ContinualConsumer rsAPI api.RoomserverInternalAPI
db storage.Database rsConsumer *common.ContinualConsumer
queues *queue.OutgoingQueues db storage.Database
query api.RoomserverQueryAPI queues *queue.OutgoingQueues
} }
// NewOutputRoomEventConsumer creates a new OutputRoomEventConsumer. Call Start() to begin consuming from room servers. // NewOutputRoomEventConsumer creates a new OutputRoomEventConsumer. Call Start() to begin consuming from room servers.
@ -46,7 +46,7 @@ func NewOutputRoomEventConsumer(
kafkaConsumer sarama.Consumer, kafkaConsumer sarama.Consumer,
queues *queue.OutgoingQueues, queues *queue.OutgoingQueues,
store storage.Database, store storage.Database,
queryAPI api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
) *OutputRoomEventConsumer { ) *OutputRoomEventConsumer {
consumer := common.ContinualConsumer{ consumer := common.ContinualConsumer{
Topic: string(cfg.Kafka.Topics.OutputRoomEvent), Topic: string(cfg.Kafka.Topics.OutputRoomEvent),
@ -54,11 +54,11 @@ func NewOutputRoomEventConsumer(
PartitionStore: store, PartitionStore: store,
} }
s := &OutputRoomEventConsumer{ s := &OutputRoomEventConsumer{
cfg: cfg, cfg: cfg,
roomServerConsumer: &consumer, rsConsumer: &consumer,
db: store, db: store,
queues: queues, queues: queues,
query: queryAPI, rsAPI: rsAPI,
} }
consumer.ProcessMessage = s.onMessage consumer.ProcessMessage = s.onMessage
@ -67,7 +67,7 @@ func NewOutputRoomEventConsumer(
// Start consuming from room servers // Start consuming from room servers
func (s *OutputRoomEventConsumer) Start() error { func (s *OutputRoomEventConsumer) Start() error {
return s.roomServerConsumer.Start() return s.rsConsumer.Start()
} }
// onMessage is called when the federation server receives a new event from the room server output log. // onMessage is called when the federation server receives a new event from the room server output log.
@ -369,7 +369,7 @@ func (s *OutputRoomEventConsumer) lookupStateEvents(
// from the roomserver using the query API. // from the roomserver using the query API.
eventReq := api.QueryEventsByIDRequest{EventIDs: missing} eventReq := api.QueryEventsByIDRequest{EventIDs: missing}
var eventResp api.QueryEventsByIDResponse var eventResp api.QueryEventsByIDResponse
if err := s.query.QueryEventsByID(context.TODO(), &eventReq, &eventResp); err != nil { if err := s.rsAPI.QueryEventsByID(context.TODO(), &eventReq, &eventResp); err != nil {
return nil, err return nil, err
} }

View File

@ -34,8 +34,7 @@ import (
func SetupFederationSenderComponent( func SetupFederationSenderComponent(
base *basecomponent.BaseDendrite, base *basecomponent.BaseDendrite,
federation *gomatrixserverlib.FederationClient, federation *gomatrixserverlib.FederationClient,
rsQueryAPI roomserverAPI.RoomserverQueryAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
rsInputAPI roomserverAPI.RoomserverInputAPI,
keyRing *gomatrixserverlib.KeyRing, keyRing *gomatrixserverlib.KeyRing,
) api.FederationSenderInternalAPI { ) api.FederationSenderInternalAPI {
federationSenderDB, err := storage.NewDatabase(string(base.Cfg.Database.FederationSender)) federationSenderDB, err := storage.NewDatabase(string(base.Cfg.Database.FederationSender))
@ -43,13 +42,13 @@ func SetupFederationSenderComponent(
logrus.WithError(err).Panic("failed to connect to federation sender db") logrus.WithError(err).Panic("failed to connect to federation sender db")
} }
roomserverProducer := producers.NewRoomserverProducer(rsInputAPI, base.Cfg.Matrix.ServerName) roomserverProducer := producers.NewRoomserverProducer(rsAPI, base.Cfg.Matrix.ServerName)
queues := queue.NewOutgoingQueues(base.Cfg.Matrix.ServerName, federation, roomserverProducer) queues := queue.NewOutgoingQueues(base.Cfg.Matrix.ServerName, federation, roomserverProducer)
rsConsumer := consumers.NewOutputRoomEventConsumer( rsConsumer := consumers.NewOutputRoomEventConsumer(
base.Cfg, base.KafkaConsumer, queues, base.Cfg, base.KafkaConsumer, queues,
federationSenderDB, rsQueryAPI, federationSenderDB, rsAPI,
) )
if err = rsConsumer.Start(); err != nil { if err = rsConsumer.Start(); err != nil {
logrus.WithError(err).Panic("failed to start room server consumer") logrus.WithError(err).Panic("failed to start room server consumer")

View File

@ -23,16 +23,16 @@ import (
// RoomserverProducer produces events for the roomserver to consume. // RoomserverProducer produces events for the roomserver to consume.
type RoomserverProducer struct { type RoomserverProducer struct {
InputAPI api.RoomserverInputAPI InputAPI api.RoomserverInternalAPI
serverName gomatrixserverlib.ServerName serverName gomatrixserverlib.ServerName
} }
// NewRoomserverProducer creates a new RoomserverProducer // NewRoomserverProducer creates a new RoomserverProducer
func NewRoomserverProducer( func NewRoomserverProducer(
inputAPI api.RoomserverInputAPI, serverName gomatrixserverlib.ServerName, rsAPI api.RoomserverInternalAPI, serverName gomatrixserverlib.ServerName,
) *RoomserverProducer { ) *RoomserverProducer {
return &RoomserverProducer{ return &RoomserverProducer{
InputAPI: inputAPI, InputAPI: rsAPI,
serverName: serverName, serverName: serverName,
} }
} }

View File

@ -29,9 +29,9 @@ import (
// OutputRoomEventConsumer consumes events that originated in the room server. // OutputRoomEventConsumer consumes events that originated in the room server.
type OutputRoomEventConsumer struct { type OutputRoomEventConsumer struct {
roomServerConsumer *common.ContinualConsumer rsAPI api.RoomserverInternalAPI
db storage.Database rsConsumer *common.ContinualConsumer
query api.RoomserverQueryAPI db storage.Database
} }
// NewOutputRoomEventConsumer creates a new OutputRoomEventConsumer. Call Start() to begin consuming from room servers. // NewOutputRoomEventConsumer creates a new OutputRoomEventConsumer. Call Start() to begin consuming from room servers.
@ -39,7 +39,7 @@ func NewOutputRoomEventConsumer(
cfg *config.Dendrite, cfg *config.Dendrite,
kafkaConsumer sarama.Consumer, kafkaConsumer sarama.Consumer,
store storage.Database, store storage.Database,
queryAPI api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
) *OutputRoomEventConsumer { ) *OutputRoomEventConsumer {
consumer := common.ContinualConsumer{ consumer := common.ContinualConsumer{
Topic: string(cfg.Kafka.Topics.OutputRoomEvent), Topic: string(cfg.Kafka.Topics.OutputRoomEvent),
@ -47,9 +47,9 @@ func NewOutputRoomEventConsumer(
PartitionStore: store, PartitionStore: store,
} }
s := &OutputRoomEventConsumer{ s := &OutputRoomEventConsumer{
roomServerConsumer: &consumer, rsConsumer: &consumer,
db: store, db: store,
query: queryAPI, rsAPI: rsAPI,
} }
consumer.ProcessMessage = s.onMessage consumer.ProcessMessage = s.onMessage
@ -58,7 +58,7 @@ func NewOutputRoomEventConsumer(
// Start consuming from room servers // Start consuming from room servers
func (s *OutputRoomEventConsumer) Start() error { func (s *OutputRoomEventConsumer) Start() error {
return s.roomServerConsumer.Start() return s.rsConsumer.Start()
} }
// onMessage is called when the sync server receives a new event from the room server output log. // onMessage is called when the sync server receives a new event from the room server output log.
@ -87,14 +87,14 @@ func (s *OutputRoomEventConsumer) onMessage(msg *sarama.ConsumerMessage) error {
addQueryReq := api.QueryEventsByIDRequest{EventIDs: output.NewRoomEvent.AddsStateEventIDs} addQueryReq := api.QueryEventsByIDRequest{EventIDs: output.NewRoomEvent.AddsStateEventIDs}
var addQueryRes api.QueryEventsByIDResponse var addQueryRes api.QueryEventsByIDResponse
if err := s.query.QueryEventsByID(context.TODO(), &addQueryReq, &addQueryRes); err != nil { if err := s.rsAPI.QueryEventsByID(context.TODO(), &addQueryReq, &addQueryRes); err != nil {
log.Warn(err) log.Warn(err)
return err return err
} }
remQueryReq := api.QueryEventsByIDRequest{EventIDs: output.NewRoomEvent.RemovesStateEventIDs} remQueryReq := api.QueryEventsByIDRequest{EventIDs: output.NewRoomEvent.RemovesStateEventIDs}
var remQueryRes api.QueryEventsByIDResponse var remQueryRes api.QueryEventsByIDResponse
if err := s.query.QueryEventsByID(context.TODO(), &remQueryReq, &remQueryRes); err != nil { if err := s.rsAPI.QueryEventsByID(context.TODO(), &remQueryReq, &remQueryRes); err != nil {
log.Warn(err) log.Warn(err)
return err return err
} }

View File

@ -59,7 +59,7 @@ func GetVisibility(
// SetVisibility implements PUT /directory/list/room/{roomID} // SetVisibility implements PUT /directory/list/room/{roomID}
// TODO: Allow admin users to edit the room visibility // TODO: Allow admin users to edit the room visibility
func SetVisibility( func SetVisibility(
req *http.Request, publicRoomsDatabase storage.Database, queryAPI api.RoomserverQueryAPI, dev *authtypes.Device, req *http.Request, publicRoomsDatabase storage.Database, rsAPI api.RoomserverInternalAPI, dev *authtypes.Device,
roomID string, roomID string,
) util.JSONResponse { ) util.JSONResponse {
queryMembershipReq := api.QueryMembershipForUserRequest{ queryMembershipReq := api.QueryMembershipForUserRequest{
@ -67,7 +67,7 @@ func SetVisibility(
UserID: dev.UserID, UserID: dev.UserID,
} }
var queryMembershipRes api.QueryMembershipForUserResponse var queryMembershipRes api.QueryMembershipForUserResponse
err := queryAPI.QueryMembershipForUser(req.Context(), &queryMembershipReq, &queryMembershipRes) err := rsAPI.QueryMembershipForUser(req.Context(), &queryMembershipReq, &queryMembershipRes)
if err != nil { if err != nil {
util.GetLogger(req.Context()).WithError(err).Error("could not query membership for user") util.GetLogger(req.Context()).WithError(err).Error("could not query membership for user")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()
@ -87,7 +87,7 @@ func SetVisibility(
}}, }},
} }
var queryEventsRes api.QueryLatestEventsAndStateResponse var queryEventsRes api.QueryLatestEventsAndStateResponse
err = queryAPI.QueryLatestEventsAndState(req.Context(), &queryEventsReq, &queryEventsRes) err = rsAPI.QueryLatestEventsAndState(req.Context(), &queryEventsReq, &queryEventsRes)
if err != nil || len(queryEventsRes.StateEvents) == 0 { if err != nil || len(queryEventsRes.StateEvents) == 0 {
util.GetLogger(req.Context()).WithError(err).Error("could not query events from room") util.GetLogger(req.Context()).WithError(err).Error("could not query events from room")
return jsonerror.InternalServerError() return jsonerror.InternalServerError()

View File

@ -32,16 +32,16 @@ func SetupPublicRoomsAPIComponent(
base *basecomponent.BaseDendrite, base *basecomponent.BaseDendrite,
deviceDB devices.Database, deviceDB devices.Database,
publicRoomsDB storage.Database, publicRoomsDB storage.Database,
rsQueryAPI roomserverAPI.RoomserverQueryAPI, rsAPI roomserverAPI.RoomserverInternalAPI,
fedClient *gomatrixserverlib.FederationClient, fedClient *gomatrixserverlib.FederationClient,
extRoomsProvider types.ExternalPublicRoomsProvider, extRoomsProvider types.ExternalPublicRoomsProvider,
) { ) {
rsConsumer := consumers.NewOutputRoomEventConsumer( rsConsumer := consumers.NewOutputRoomEventConsumer(
base.Cfg, base.KafkaConsumer, publicRoomsDB, rsQueryAPI, base.Cfg, base.KafkaConsumer, publicRoomsDB, rsAPI,
) )
if err := rsConsumer.Start(); err != nil { if err := rsConsumer.Start(); err != nil {
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.APIMux, deviceDB, publicRoomsDB, rsQueryAPI, fedClient, extRoomsProvider) routing.Setup(base.APIMux, deviceDB, publicRoomsDB, rsAPI, fedClient, extRoomsProvider)
} }

View File

@ -39,7 +39,7 @@ const pathPrefixR0 = "/_matrix/client/r0"
// applied: // applied:
// nolint: gocyclo // nolint: gocyclo
func Setup( func Setup(
apiMux *mux.Router, deviceDB devices.Database, publicRoomsDB storage.Database, queryAPI api.RoomserverQueryAPI, apiMux *mux.Router, deviceDB devices.Database, publicRoomsDB storage.Database, rsAPI api.RoomserverInternalAPI,
fedClient *gomatrixserverlib.FederationClient, extRoomsProvider types.ExternalPublicRoomsProvider, fedClient *gomatrixserverlib.FederationClient, extRoomsProvider types.ExternalPublicRoomsProvider,
) { ) {
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter() r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter()
@ -66,7 +66,7 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return directory.SetVisibility(req, publicRoomsDB, queryAPI, device, vars["roomID"]) return directory.SetVisibility(req, publicRoomsDB, rsAPI, device, vars["roomID"])
}), }),
).Methods(http.MethodPut, http.MethodOptions) ).Methods(http.MethodPut, http.MethodOptions)
r0mux.Handle("/publicRooms", r0mux.Handle("/publicRooms",

View File

@ -1,209 +0,0 @@
// Copyright 2019 Serra Allgood
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package alias
import (
"context"
"fmt"
"strings"
"testing"
appserviceAPI "github.com/matrix-org/dendrite/appservice/api"
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/gomatrixserverlib"
)
type MockRoomserverAliasAPIDatabase struct {
mode string
attempts int
}
// These methods can be essentially noop
func (db MockRoomserverAliasAPIDatabase) SetRoomAlias(ctx context.Context, alias string, roomID string, creatorUserID string) error {
return nil
}
func (db MockRoomserverAliasAPIDatabase) GetAliasesForRoomID(ctx context.Context, roomID string) ([]string, error) {
aliases := make([]string, 0)
return aliases, nil
}
func (db MockRoomserverAliasAPIDatabase) RemoveRoomAlias(ctx context.Context, alias string) error {
return nil
}
func (db *MockRoomserverAliasAPIDatabase) GetCreatorIDForAlias(
ctx context.Context, alias string,
) (string, error) {
return "", nil
}
func (db *MockRoomserverAliasAPIDatabase) GetRoomVersionForRoom(
ctx context.Context, roomID string,
) (gomatrixserverlib.RoomVersion, error) {
return gomatrixserverlib.RoomVersionV1, nil
}
// This method needs to change depending on test case
func (db *MockRoomserverAliasAPIDatabase) GetRoomIDForAlias(
ctx context.Context,
alias string,
) (string, error) {
switch db.mode {
case "empty":
return "", nil
case "error":
return "", fmt.Errorf("found an error from GetRoomIDForAlias")
case "found":
return "123", nil
case "emptyFound":
switch db.attempts {
case 0:
db.attempts = 1
return "", nil
case 1:
db.attempts = 0
return "123", nil
default:
return "", nil
}
default:
return "", fmt.Errorf("unknown option used")
}
}
type MockAppServiceQueryAPI struct {
mode string
}
// This method can be noop
func (q MockAppServiceQueryAPI) UserIDExists(
ctx context.Context,
req *appserviceAPI.UserIDExistsRequest,
resp *appserviceAPI.UserIDExistsResponse,
) error {
return nil
}
func (q MockAppServiceQueryAPI) RoomAliasExists(
ctx context.Context,
req *appserviceAPI.RoomAliasExistsRequest,
resp *appserviceAPI.RoomAliasExistsResponse,
) error {
switch q.mode {
case "error":
return fmt.Errorf("found an error from RoomAliasExists")
case "found":
resp.AliasExists = true
return nil
case "empty":
resp.AliasExists = false
return nil
default:
return fmt.Errorf("Unknown option used")
}
}
func TestGetRoomIDForAlias(t *testing.T) {
type arguments struct {
ctx context.Context
request *roomserverAPI.GetRoomIDForAliasRequest
response *roomserverAPI.GetRoomIDForAliasResponse
}
args := arguments{
context.Background(),
&roomserverAPI.GetRoomIDForAliasRequest{},
&roomserverAPI.GetRoomIDForAliasResponse{},
}
type testCase struct {
name string
dbMode string
queryMode string
wantError bool
errorMsg string
want string
}
tt := []testCase{
{
"found local alias",
"found",
"error",
false,
"",
"123",
},
{
"found appservice alias",
"emptyFound",
"found",
false,
"",
"123",
},
{
"error returned from DB",
"error",
"",
true,
"GetRoomIDForAlias",
"",
},
{
"error returned from appserviceAPI",
"empty",
"error",
true,
"RoomAliasExists",
"",
},
{
"no errors but no alias",
"empty",
"empty",
false,
"",
"",
},
}
setup := func(dbMode, queryMode string) *RoomserverAliasAPI {
mockAliasAPIDB := &MockRoomserverAliasAPIDatabase{dbMode, 0}
mockAppServiceQueryAPI := MockAppServiceQueryAPI{queryMode}
return &RoomserverAliasAPI{
DB: mockAliasAPIDB,
AppserviceAPI: mockAppServiceQueryAPI,
}
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
aliasAPI := setup(tc.dbMode, tc.queryMode)
err := aliasAPI.GetRoomIDForAlias(args.ctx, args.request, args.response)
if tc.wantError {
if err == nil {
t.Fatalf("Got no error; wanted error from %s", tc.errorMsg)
} else if !strings.Contains(err.Error(), tc.errorMsg) {
t.Fatalf("Got %s; wanted error from %s", err, tc.errorMsg)
}
} else if err != nil {
t.Fatalf("Got %s; wanted no error", err)
} else if args.response.RoomID != tc.want {
t.Errorf("Got '%s'; wanted '%s'", args.response.RoomID, tc.want)
}
})
}
}

View File

@ -16,8 +16,6 @@ package api
import ( import (
"context" "context"
"errors"
"net/http"
commonHTTP "github.com/matrix-org/dendrite/common/http" commonHTTP "github.com/matrix-org/dendrite/common/http"
opentracing "github.com/opentracing/opentracing-go" opentracing "github.com/opentracing/opentracing-go"
@ -86,44 +84,6 @@ type RemoveRoomAliasRequest struct {
// RemoveRoomAliasResponse is a response to RemoveRoomAlias // RemoveRoomAliasResponse is a response to RemoveRoomAlias
type RemoveRoomAliasResponse struct{} type RemoveRoomAliasResponse struct{}
// RoomserverAliasAPI is used to save, lookup or remove a room alias
type RoomserverAliasAPI interface {
// Set a room alias
SetRoomAlias(
ctx context.Context,
req *SetRoomAliasRequest,
response *SetRoomAliasResponse,
) error
// Get the room ID for an alias
GetRoomIDForAlias(
ctx context.Context,
req *GetRoomIDForAliasRequest,
response *GetRoomIDForAliasResponse,
) error
// Get all known aliases for a room ID
GetAliasesForRoomID(
ctx context.Context,
req *GetAliasesForRoomIDRequest,
response *GetAliasesForRoomIDResponse,
) error
// Get the user ID of the creator of an alias
GetCreatorIDForAlias(
ctx context.Context,
req *GetCreatorIDForAliasRequest,
response *GetCreatorIDForAliasResponse,
) error
// Remove a room alias
RemoveRoomAlias(
ctx context.Context,
req *RemoveRoomAliasRequest,
response *RemoveRoomAliasResponse,
) error
}
// RoomserverSetRoomAliasPath is the HTTP path for the SetRoomAlias API. // RoomserverSetRoomAliasPath is the HTTP path for the SetRoomAlias API.
const RoomserverSetRoomAliasPath = "/api/roomserver/setRoomAlias" const RoomserverSetRoomAliasPath = "/api/roomserver/setRoomAlias"
@ -139,22 +99,8 @@ const RoomserverGetCreatorIDForAliasPath = "/api/roomserver/GetCreatorIDForAlias
// RoomserverRemoveRoomAliasPath is the HTTP path for the RemoveRoomAlias API. // RoomserverRemoveRoomAliasPath is the HTTP path for the RemoveRoomAlias API.
const RoomserverRemoveRoomAliasPath = "/api/roomserver/removeRoomAlias" const RoomserverRemoveRoomAliasPath = "/api/roomserver/removeRoomAlias"
// NewRoomserverAliasAPIHTTP creates a RoomserverAliasAPI implemented by talking to a HTTP POST API.
// If httpClient is nil an error is returned
func NewRoomserverAliasAPIHTTP(roomserverURL string, httpClient *http.Client) (RoomserverAliasAPI, error) {
if httpClient == nil {
return nil, errors.New("NewRoomserverAliasAPIHTTP: httpClient is <nil>")
}
return &httpRoomserverAliasAPI{roomserverURL, httpClient}, nil
}
type httpRoomserverAliasAPI struct {
roomserverURL string
httpClient *http.Client
}
// SetRoomAlias implements RoomserverAliasAPI // SetRoomAlias implements RoomserverAliasAPI
func (h *httpRoomserverAliasAPI) SetRoomAlias( func (h *httpRoomserverInternalAPI) SetRoomAlias(
ctx context.Context, ctx context.Context,
request *SetRoomAliasRequest, request *SetRoomAliasRequest,
response *SetRoomAliasResponse, response *SetRoomAliasResponse,
@ -167,7 +113,7 @@ func (h *httpRoomserverAliasAPI) SetRoomAlias(
} }
// GetRoomIDForAlias implements RoomserverAliasAPI // GetRoomIDForAlias implements RoomserverAliasAPI
func (h *httpRoomserverAliasAPI) GetRoomIDForAlias( func (h *httpRoomserverInternalAPI) GetRoomIDForAlias(
ctx context.Context, ctx context.Context,
request *GetRoomIDForAliasRequest, request *GetRoomIDForAliasRequest,
response *GetRoomIDForAliasResponse, response *GetRoomIDForAliasResponse,
@ -180,7 +126,7 @@ func (h *httpRoomserverAliasAPI) GetRoomIDForAlias(
} }
// GetAliasesForRoomID implements RoomserverAliasAPI // GetAliasesForRoomID implements RoomserverAliasAPI
func (h *httpRoomserverAliasAPI) GetAliasesForRoomID( func (h *httpRoomserverInternalAPI) GetAliasesForRoomID(
ctx context.Context, ctx context.Context,
request *GetAliasesForRoomIDRequest, request *GetAliasesForRoomIDRequest,
response *GetAliasesForRoomIDResponse, response *GetAliasesForRoomIDResponse,
@ -193,7 +139,7 @@ func (h *httpRoomserverAliasAPI) GetAliasesForRoomID(
} }
// GetCreatorIDForAlias implements RoomserverAliasAPI // GetCreatorIDForAlias implements RoomserverAliasAPI
func (h *httpRoomserverAliasAPI) GetCreatorIDForAlias( func (h *httpRoomserverInternalAPI) GetCreatorIDForAlias(
ctx context.Context, ctx context.Context,
request *GetCreatorIDForAliasRequest, request *GetCreatorIDForAliasRequest,
response *GetCreatorIDForAliasResponse, response *GetCreatorIDForAliasResponse,
@ -206,7 +152,7 @@ func (h *httpRoomserverAliasAPI) GetCreatorIDForAlias(
} }
// RemoveRoomAlias implements RoomserverAliasAPI // RemoveRoomAlias implements RoomserverAliasAPI
func (h *httpRoomserverAliasAPI) RemoveRoomAlias( func (h *httpRoomserverInternalAPI) RemoveRoomAlias(
ctx context.Context, ctx context.Context,
request *RemoveRoomAliasRequest, request *RemoveRoomAliasRequest,
response *RemoveRoomAliasResponse, response *RemoveRoomAliasResponse,

141
roomserver/api/api.go Normal file
View File

@ -0,0 +1,141 @@
package api
import (
"context"
fsAPI "github.com/matrix-org/dendrite/federationsender/api"
)
// RoomserverInputAPI is used to write events to the room server.
type RoomserverInternalAPI interface {
// needed to avoid chicken and egg scenario when setting up the
// interdependencies between the roomserver and other input APIs
SetFederationSenderAPI(fsAPI fsAPI.FederationSenderInternalAPI)
InputRoomEvents(
ctx context.Context,
request *InputRoomEventsRequest,
response *InputRoomEventsResponse,
) error
// Query the latest events and state for a room from the room server.
QueryLatestEventsAndState(
ctx context.Context,
request *QueryLatestEventsAndStateRequest,
response *QueryLatestEventsAndStateResponse,
) error
// Query the state after a list of events in a room from the room server.
QueryStateAfterEvents(
ctx context.Context,
request *QueryStateAfterEventsRequest,
response *QueryStateAfterEventsResponse,
) error
// Query a list of events by event ID.
QueryEventsByID(
ctx context.Context,
request *QueryEventsByIDRequest,
response *QueryEventsByIDResponse,
) error
// Query the membership event for an user for a room.
QueryMembershipForUser(
ctx context.Context,
request *QueryMembershipForUserRequest,
response *QueryMembershipForUserResponse,
) error
// Query a list of membership events for a room
QueryMembershipsForRoom(
ctx context.Context,
request *QueryMembershipsForRoomRequest,
response *QueryMembershipsForRoomResponse,
) error
// Query a list of invite event senders for a user in a room.
QueryInvitesForUser(
ctx context.Context,
request *QueryInvitesForUserRequest,
response *QueryInvitesForUserResponse,
) error
// Query whether a server is allowed to see an event
QueryServerAllowedToSeeEvent(
ctx context.Context,
request *QueryServerAllowedToSeeEventRequest,
response *QueryServerAllowedToSeeEventResponse,
) error
// Query missing events for a room from roomserver
QueryMissingEvents(
ctx context.Context,
request *QueryMissingEventsRequest,
response *QueryMissingEventsResponse,
) error
// Query to get state and auth chain for a (potentially hypothetical) event.
// Takes lists of PrevEventIDs and AuthEventsIDs and uses them to calculate
// the state and auth chain to return.
QueryStateAndAuthChain(
ctx context.Context,
request *QueryStateAndAuthChainRequest,
response *QueryStateAndAuthChainResponse,
) error
// Query a given amount (or less) of events prior to a given set of events.
QueryBackfill(
ctx context.Context,
request *QueryBackfillRequest,
response *QueryBackfillResponse,
) error
// Asks for the default room version as preferred by the server.
QueryRoomVersionCapabilities(
ctx context.Context,
request *QueryRoomVersionCapabilitiesRequest,
response *QueryRoomVersionCapabilitiesResponse,
) error
// Asks for the room version for a given room.
QueryRoomVersionForRoom(
ctx context.Context,
request *QueryRoomVersionForRoomRequest,
response *QueryRoomVersionForRoomResponse,
) error
// Set a room alias
SetRoomAlias(
ctx context.Context,
req *SetRoomAliasRequest,
response *SetRoomAliasResponse,
) error
// Get the room ID for an alias
GetRoomIDForAlias(
ctx context.Context,
req *GetRoomIDForAliasRequest,
response *GetRoomIDForAliasResponse,
) error
// Get all known aliases for a room ID
GetAliasesForRoomID(
ctx context.Context,
req *GetAliasesForRoomIDRequest,
response *GetAliasesForRoomIDResponse,
) error
// Get the user ID of the creator of an alias
GetCreatorIDForAlias(
ctx context.Context,
req *GetCreatorIDForAliasRequest,
response *GetCreatorIDForAliasResponse,
) error
// Remove a room alias
RemoveRoomAlias(
ctx context.Context,
req *RemoveRoomAliasRequest,
response *RemoveRoomAliasResponse,
) error
}

41
roomserver/api/http.go Normal file
View File

@ -0,0 +1,41 @@
package api
import (
"errors"
"net/http"
"github.com/matrix-org/dendrite/common/caching"
fsInputAPI "github.com/matrix-org/dendrite/federationsender/api"
)
type httpRoomserverInternalAPI struct {
roomserverURL string
httpClient *http.Client
fsAPI fsInputAPI.FederationSenderInternalAPI
immutableCache caching.ImmutableCache
}
// NewRoomserverInputAPIHTTP creates a RoomserverInputAPI implemented by talking to a HTTP POST API.
// If httpClient is nil an error is returned
func NewRoomserverInternalAPIHTTP(
roomserverURL string,
httpClient *http.Client,
//fsInputAPI fsAPI.FederationSenderInternalAPI,
immutableCache caching.ImmutableCache,
) (RoomserverInternalAPI, error) {
if httpClient == nil {
return nil, errors.New("NewRoomserverInternalAPIHTTP: httpClient is <nil>")
}
return &httpRoomserverInternalAPI{
roomserverURL: roomserverURL,
httpClient: httpClient,
immutableCache: immutableCache,
}, nil
}
// SetFederationSenderInputAPI passes in a federation sender input API reference
// so that we can avoid the chicken-and-egg problem of both the roomserver input API
// and the federation sender input API being interdependent.
func (h *httpRoomserverInternalAPI) SetFederationSenderAPI(fsAPI fsInputAPI.FederationSenderInternalAPI) {
h.fsAPI = fsAPI
}

View File

@ -17,11 +17,8 @@ package api
import ( import (
"context" "context"
"errors"
"net/http"
commonHTTP "github.com/matrix-org/dendrite/common/http" commonHTTP "github.com/matrix-org/dendrite/common/http"
fsAPI "github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
opentracing "github.com/opentracing/opentracing-go" opentracing "github.com/opentracing/opentracing-go"
) )
@ -105,47 +102,11 @@ type InputRoomEventsResponse struct {
EventID string `json:"event_id"` EventID string `json:"event_id"`
} }
// RoomserverInputAPI is used to write events to the room server.
type RoomserverInputAPI interface {
// needed to avoid chicken and egg scenario when setting up the
// interdependencies between the roomserver and the FS input API
SetFederationSenderAPI(fsInputAPI fsAPI.FederationSenderInternalAPI)
InputRoomEvents(
ctx context.Context,
request *InputRoomEventsRequest,
response *InputRoomEventsResponse,
) error
}
// RoomserverInputRoomEventsPath is the HTTP path for the InputRoomEvents API. // RoomserverInputRoomEventsPath is the HTTP path for the InputRoomEvents API.
const RoomserverInputRoomEventsPath = "/api/roomserver/inputRoomEvents" const RoomserverInputRoomEventsPath = "/api/roomserver/inputRoomEvents"
// NewRoomserverInputAPIHTTP creates a RoomserverInputAPI implemented by talking to a HTTP POST API.
// If httpClient is nil an error is returned
func NewRoomserverInputAPIHTTP(roomserverURL string, httpClient *http.Client) (RoomserverInputAPI, error) {
if httpClient == nil {
return nil, errors.New("NewRoomserverInputAPIHTTP: httpClient is <nil>")
}
return &httpRoomserverInputAPI{roomserverURL, httpClient, nil}, nil
}
type httpRoomserverInputAPI struct {
roomserverURL string
httpClient *http.Client
// The federation sender API allows us to send federation
// requests from the new perform input requests, still TODO.
fsInputAPI fsAPI.FederationSenderInternalAPI
}
// SetFederationSenderInputAPI passes in a federation sender input API reference
// so that we can avoid the chicken-and-egg problem of both the roomserver input API
// and the federation sender input API being interdependent.
func (h *httpRoomserverInputAPI) SetFederationSenderAPI(fsInputAPI fsAPI.FederationSenderInternalAPI) {
h.fsInputAPI = fsInputAPI
}
// InputRoomEvents implements RoomserverInputAPI // InputRoomEvents implements RoomserverInputAPI
func (h *httpRoomserverInputAPI) InputRoomEvents( func (h *httpRoomserverInternalAPI) InputRoomEvents(
ctx context.Context, ctx context.Context,
request *InputRoomEventsRequest, request *InputRoomEventsRequest,
response *InputRoomEventsResponse, response *InputRoomEventsResponse,

View File

@ -18,10 +18,7 @@ package api
import ( import (
"context" "context"
"errors"
"net/http"
"github.com/matrix-org/dendrite/common/caching"
commonHTTP "github.com/matrix-org/dendrite/common/http" commonHTTP "github.com/matrix-org/dendrite/common/http"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
opentracing "github.com/opentracing/opentracing-go" opentracing "github.com/opentracing/opentracing-go"
@ -264,95 +261,6 @@ type QueryRoomVersionForRoomResponse struct {
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"` RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
} }
// RoomserverQueryAPI is used to query information from the room server.
type RoomserverQueryAPI interface {
// Query the latest events and state for a room from the room server.
QueryLatestEventsAndState(
ctx context.Context,
request *QueryLatestEventsAndStateRequest,
response *QueryLatestEventsAndStateResponse,
) error
// Query the state after a list of events in a room from the room server.
QueryStateAfterEvents(
ctx context.Context,
request *QueryStateAfterEventsRequest,
response *QueryStateAfterEventsResponse,
) error
// Query a list of events by event ID.
QueryEventsByID(
ctx context.Context,
request *QueryEventsByIDRequest,
response *QueryEventsByIDResponse,
) error
// Query the membership event for an user for a room.
QueryMembershipForUser(
ctx context.Context,
request *QueryMembershipForUserRequest,
response *QueryMembershipForUserResponse,
) error
// Query a list of membership events for a room
QueryMembershipsForRoom(
ctx context.Context,
request *QueryMembershipsForRoomRequest,
response *QueryMembershipsForRoomResponse,
) error
// Query a list of invite event senders for a user in a room.
QueryInvitesForUser(
ctx context.Context,
request *QueryInvitesForUserRequest,
response *QueryInvitesForUserResponse,
) error
// Query whether a server is allowed to see an event
QueryServerAllowedToSeeEvent(
ctx context.Context,
request *QueryServerAllowedToSeeEventRequest,
response *QueryServerAllowedToSeeEventResponse,
) error
// Query missing events for a room from roomserver
QueryMissingEvents(
ctx context.Context,
request *QueryMissingEventsRequest,
response *QueryMissingEventsResponse,
) error
// Query to get state and auth chain for a (potentially hypothetical) event.
// Takes lists of PrevEventIDs and AuthEventsIDs and uses them to calculate
// the state and auth chain to return.
QueryStateAndAuthChain(
ctx context.Context,
request *QueryStateAndAuthChainRequest,
response *QueryStateAndAuthChainResponse,
) error
// Query a given amount (or less) of events prior to a given set of events.
QueryBackfill(
ctx context.Context,
request *QueryBackfillRequest,
response *QueryBackfillResponse,
) error
// Asks for the default room version as preferred by the server.
QueryRoomVersionCapabilities(
ctx context.Context,
request *QueryRoomVersionCapabilitiesRequest,
response *QueryRoomVersionCapabilitiesResponse,
) error
// Asks for the room version for a given room.
QueryRoomVersionForRoom(
ctx context.Context,
request *QueryRoomVersionForRoomRequest,
response *QueryRoomVersionForRoomResponse,
) error
}
// RoomserverQueryLatestEventsAndStatePath is the HTTP path for the QueryLatestEventsAndState API. // RoomserverQueryLatestEventsAndStatePath is the HTTP path for the QueryLatestEventsAndState API.
const RoomserverQueryLatestEventsAndStatePath = "/api/roomserver/queryLatestEventsAndState" const RoomserverQueryLatestEventsAndStatePath = "/api/roomserver/queryLatestEventsAndState"
@ -389,23 +297,8 @@ const RoomserverQueryRoomVersionCapabilitiesPath = "/api/roomserver/queryRoomVer
// RoomserverQueryRoomVersionForRoomPath is the HTTP path for the QueryRoomVersionForRoom API // RoomserverQueryRoomVersionForRoomPath is the HTTP path for the QueryRoomVersionForRoom API
const RoomserverQueryRoomVersionForRoomPath = "/api/roomserver/queryRoomVersionForRoom" const RoomserverQueryRoomVersionForRoomPath = "/api/roomserver/queryRoomVersionForRoom"
// NewRoomserverQueryAPIHTTP creates a RoomserverQueryAPI implemented by talking to a HTTP POST API.
// If httpClient is nil an error is returned
func NewRoomserverQueryAPIHTTP(roomserverURL string, httpClient *http.Client, cache caching.ImmutableCache) (RoomserverQueryAPI, error) {
if httpClient == nil {
return nil, errors.New("NewRoomserverQueryAPIHTTP: httpClient is <nil>")
}
return &httpRoomserverQueryAPI{roomserverURL, httpClient, cache}, nil
}
type httpRoomserverQueryAPI struct {
roomserverURL string
httpClient *http.Client
immutableCache caching.ImmutableCache
}
// QueryLatestEventsAndState implements RoomserverQueryAPI // QueryLatestEventsAndState implements RoomserverQueryAPI
func (h *httpRoomserverQueryAPI) QueryLatestEventsAndState( func (h *httpRoomserverInternalAPI) QueryLatestEventsAndState(
ctx context.Context, ctx context.Context,
request *QueryLatestEventsAndStateRequest, request *QueryLatestEventsAndStateRequest,
response *QueryLatestEventsAndStateResponse, response *QueryLatestEventsAndStateResponse,
@ -418,7 +311,7 @@ func (h *httpRoomserverQueryAPI) QueryLatestEventsAndState(
} }
// QueryStateAfterEvents implements RoomserverQueryAPI // QueryStateAfterEvents implements RoomserverQueryAPI
func (h *httpRoomserverQueryAPI) QueryStateAfterEvents( func (h *httpRoomserverInternalAPI) QueryStateAfterEvents(
ctx context.Context, ctx context.Context,
request *QueryStateAfterEventsRequest, request *QueryStateAfterEventsRequest,
response *QueryStateAfterEventsResponse, response *QueryStateAfterEventsResponse,
@ -431,7 +324,7 @@ func (h *httpRoomserverQueryAPI) QueryStateAfterEvents(
} }
// QueryEventsByID implements RoomserverQueryAPI // QueryEventsByID implements RoomserverQueryAPI
func (h *httpRoomserverQueryAPI) QueryEventsByID( func (h *httpRoomserverInternalAPI) QueryEventsByID(
ctx context.Context, ctx context.Context,
request *QueryEventsByIDRequest, request *QueryEventsByIDRequest,
response *QueryEventsByIDResponse, response *QueryEventsByIDResponse,
@ -444,7 +337,7 @@ func (h *httpRoomserverQueryAPI) QueryEventsByID(
} }
// QueryMembershipForUser implements RoomserverQueryAPI // QueryMembershipForUser implements RoomserverQueryAPI
func (h *httpRoomserverQueryAPI) QueryMembershipForUser( func (h *httpRoomserverInternalAPI) QueryMembershipForUser(
ctx context.Context, ctx context.Context,
request *QueryMembershipForUserRequest, request *QueryMembershipForUserRequest,
response *QueryMembershipForUserResponse, response *QueryMembershipForUserResponse,
@ -457,7 +350,7 @@ func (h *httpRoomserverQueryAPI) QueryMembershipForUser(
} }
// QueryMembershipsForRoom implements RoomserverQueryAPI // QueryMembershipsForRoom implements RoomserverQueryAPI
func (h *httpRoomserverQueryAPI) QueryMembershipsForRoom( func (h *httpRoomserverInternalAPI) QueryMembershipsForRoom(
ctx context.Context, ctx context.Context,
request *QueryMembershipsForRoomRequest, request *QueryMembershipsForRoomRequest,
response *QueryMembershipsForRoomResponse, response *QueryMembershipsForRoomResponse,
@ -470,7 +363,7 @@ func (h *httpRoomserverQueryAPI) QueryMembershipsForRoom(
} }
// QueryInvitesForUser implements RoomserverQueryAPI // QueryInvitesForUser implements RoomserverQueryAPI
func (h *httpRoomserverQueryAPI) QueryInvitesForUser( func (h *httpRoomserverInternalAPI) QueryInvitesForUser(
ctx context.Context, ctx context.Context,
request *QueryInvitesForUserRequest, request *QueryInvitesForUserRequest,
response *QueryInvitesForUserResponse, response *QueryInvitesForUserResponse,
@ -483,7 +376,7 @@ func (h *httpRoomserverQueryAPI) QueryInvitesForUser(
} }
// QueryServerAllowedToSeeEvent implements RoomserverQueryAPI // QueryServerAllowedToSeeEvent implements RoomserverQueryAPI
func (h *httpRoomserverQueryAPI) QueryServerAllowedToSeeEvent( func (h *httpRoomserverInternalAPI) QueryServerAllowedToSeeEvent(
ctx context.Context, ctx context.Context,
request *QueryServerAllowedToSeeEventRequest, request *QueryServerAllowedToSeeEventRequest,
response *QueryServerAllowedToSeeEventResponse, response *QueryServerAllowedToSeeEventResponse,
@ -496,7 +389,7 @@ func (h *httpRoomserverQueryAPI) QueryServerAllowedToSeeEvent(
} }
// QueryMissingEvents implements RoomServerQueryAPI // QueryMissingEvents implements RoomServerQueryAPI
func (h *httpRoomserverQueryAPI) QueryMissingEvents( func (h *httpRoomserverInternalAPI) QueryMissingEvents(
ctx context.Context, ctx context.Context,
request *QueryMissingEventsRequest, request *QueryMissingEventsRequest,
response *QueryMissingEventsResponse, response *QueryMissingEventsResponse,
@ -509,7 +402,7 @@ func (h *httpRoomserverQueryAPI) QueryMissingEvents(
} }
// QueryStateAndAuthChain implements RoomserverQueryAPI // QueryStateAndAuthChain implements RoomserverQueryAPI
func (h *httpRoomserverQueryAPI) QueryStateAndAuthChain( func (h *httpRoomserverInternalAPI) QueryStateAndAuthChain(
ctx context.Context, ctx context.Context,
request *QueryStateAndAuthChainRequest, request *QueryStateAndAuthChainRequest,
response *QueryStateAndAuthChainResponse, response *QueryStateAndAuthChainResponse,
@ -522,7 +415,7 @@ func (h *httpRoomserverQueryAPI) QueryStateAndAuthChain(
} }
// QueryBackfill implements RoomServerQueryAPI // QueryBackfill implements RoomServerQueryAPI
func (h *httpRoomserverQueryAPI) QueryBackfill( func (h *httpRoomserverInternalAPI) QueryBackfill(
ctx context.Context, ctx context.Context,
request *QueryBackfillRequest, request *QueryBackfillRequest,
response *QueryBackfillResponse, response *QueryBackfillResponse,
@ -535,7 +428,7 @@ func (h *httpRoomserverQueryAPI) QueryBackfill(
} }
// QueryRoomVersionCapabilities implements RoomServerQueryAPI // QueryRoomVersionCapabilities implements RoomServerQueryAPI
func (h *httpRoomserverQueryAPI) QueryRoomVersionCapabilities( func (h *httpRoomserverInternalAPI) QueryRoomVersionCapabilities(
ctx context.Context, ctx context.Context,
request *QueryRoomVersionCapabilitiesRequest, request *QueryRoomVersionCapabilitiesRequest,
response *QueryRoomVersionCapabilitiesResponse, response *QueryRoomVersionCapabilitiesResponse,
@ -548,7 +441,7 @@ func (h *httpRoomserverQueryAPI) QueryRoomVersionCapabilities(
} }
// QueryRoomVersionForRoom implements RoomServerQueryAPI // QueryRoomVersionForRoom implements RoomServerQueryAPI
func (h *httpRoomserverQueryAPI) QueryRoomVersionForRoom( func (h *httpRoomserverInternalAPI) QueryRoomVersionForRoom(
ctx context.Context, ctx context.Context,
request *QueryRoomVersionForRoomRequest, request *QueryRoomVersionForRoomRequest,
response *QueryRoomVersionForRoomResponse, response *QueryRoomVersionForRoomResponse,

View File

@ -12,25 +12,20 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package alias package internal
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"net/http"
"time" "time"
appserviceAPI "github.com/matrix-org/dendrite/appservice/api" "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/common/config"
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
) )
// RoomserverAliasAPIDatabase has the storage APIs needed to implement the alias API. // RoomserverInternalAPIDatabase has the storage APIs needed to implement the alias API.
type RoomserverAliasAPIDatabase interface { type RoomserverInternalAPIDatabase interface {
// Save a given room alias with the room ID it refers to. // Save a given room alias with the room ID it refers to.
// Returns an error if there was a problem talking to the database. // Returns an error if there was a problem talking to the database.
SetRoomAlias(ctx context.Context, alias string, roomID string, creatorUserID string) error SetRoomAlias(ctx context.Context, alias string, roomID string, creatorUserID string) error
@ -52,20 +47,11 @@ type RoomserverAliasAPIDatabase interface {
) (gomatrixserverlib.RoomVersion, error) ) (gomatrixserverlib.RoomVersion, error)
} }
// RoomserverAliasAPI is an implementation of alias.RoomserverAliasAPI // SetRoomAlias implements alias.RoomserverInternalAPI
type RoomserverAliasAPI struct { func (r *RoomserverInternalAPI) SetRoomAlias(
DB RoomserverAliasAPIDatabase
Cfg *config.Dendrite
InputAPI roomserverAPI.RoomserverInputAPI
QueryAPI roomserverAPI.RoomserverQueryAPI
AppserviceAPI appserviceAPI.AppServiceQueryAPI
}
// SetRoomAlias implements alias.RoomserverAliasAPI
func (r *RoomserverAliasAPI) SetRoomAlias(
ctx context.Context, ctx context.Context,
request *roomserverAPI.SetRoomAliasRequest, request *api.SetRoomAliasRequest,
response *roomserverAPI.SetRoomAliasResponse, response *api.SetRoomAliasResponse,
) error { ) error {
// Check if the alias isn't already referring to a room // Check if the alias isn't already referring to a room
roomID, err := r.DB.GetRoomIDForAlias(ctx, request.Alias) roomID, err := r.DB.GetRoomIDForAlias(ctx, request.Alias)
@ -91,11 +77,11 @@ func (r *RoomserverAliasAPI) SetRoomAlias(
return r.sendUpdatedAliasesEvent(context.TODO(), request.UserID, request.RoomID) return r.sendUpdatedAliasesEvent(context.TODO(), request.UserID, request.RoomID)
} }
// GetRoomIDForAlias implements alias.RoomserverAliasAPI // GetRoomIDForAlias implements alias.RoomserverInternalAPI
func (r *RoomserverAliasAPI) GetRoomIDForAlias( func (r *RoomserverInternalAPI) GetRoomIDForAlias(
ctx context.Context, ctx context.Context,
request *roomserverAPI.GetRoomIDForAliasRequest, request *api.GetRoomIDForAliasRequest,
response *roomserverAPI.GetRoomIDForAliasResponse, response *api.GetRoomIDForAliasResponse,
) error { ) error {
// Look up the room ID in the database // Look up the room ID in the database
roomID, err := r.DB.GetRoomIDForAlias(ctx, request.Alias) roomID, err := r.DB.GetRoomIDForAlias(ctx, request.Alias)
@ -103,32 +89,38 @@ func (r *RoomserverAliasAPI) GetRoomIDForAlias(
return err return err
} }
if roomID == "" { /*
// No room found locally, try our application services by making a call to TODO: Why is this here? It creates an unnecessary dependency
// the appservice component from the roomserver to the appservice component, which should be
aliasReq := appserviceAPI.RoomAliasExistsRequest{Alias: request.Alias} altogether optional.
var aliasResp appserviceAPI.RoomAliasExistsResponse
if err = r.AppserviceAPI.RoomAliasExists(ctx, &aliasReq, &aliasResp); err != nil {
return err
}
if aliasResp.AliasExists { if roomID == "" {
roomID, err = r.DB.GetRoomIDForAlias(ctx, request.Alias) // No room found locally, try our application services by making a call to
if err != nil { // the appservice component
aliasReq := appserviceAPI.RoomAliasExistsRequest{Alias: request.Alias}
var aliasResp appserviceAPI.RoomAliasExistsResponse
if err = r.AppserviceAPI.RoomAliasExists(ctx, &aliasReq, &aliasResp); err != nil {
return err return err
} }
if aliasResp.AliasExists {
roomID, err = r.DB.GetRoomIDForAlias(ctx, request.Alias)
if err != nil {
return err
}
}
} }
} */
response.RoomID = roomID response.RoomID = roomID
return nil return nil
} }
// GetAliasesForRoomID implements alias.RoomserverAliasAPI // GetAliasesForRoomID implements alias.RoomserverInternalAPI
func (r *RoomserverAliasAPI) GetAliasesForRoomID( func (r *RoomserverInternalAPI) GetAliasesForRoomID(
ctx context.Context, ctx context.Context,
request *roomserverAPI.GetAliasesForRoomIDRequest, request *api.GetAliasesForRoomIDRequest,
response *roomserverAPI.GetAliasesForRoomIDResponse, response *api.GetAliasesForRoomIDResponse,
) error { ) error {
// Look up the aliases in the database for the given RoomID // Look up the aliases in the database for the given RoomID
aliases, err := r.DB.GetAliasesForRoomID(ctx, request.RoomID) aliases, err := r.DB.GetAliasesForRoomID(ctx, request.RoomID)
@ -140,11 +132,11 @@ func (r *RoomserverAliasAPI) GetAliasesForRoomID(
return nil return nil
} }
// GetCreatorIDForAlias implements alias.RoomserverAliasAPI // GetCreatorIDForAlias implements alias.RoomserverInternalAPI
func (r *RoomserverAliasAPI) GetCreatorIDForAlias( func (r *RoomserverInternalAPI) GetCreatorIDForAlias(
ctx context.Context, ctx context.Context,
request *roomserverAPI.GetCreatorIDForAliasRequest, request *api.GetCreatorIDForAliasRequest,
response *roomserverAPI.GetCreatorIDForAliasResponse, response *api.GetCreatorIDForAliasResponse,
) error { ) error {
// Look up the aliases in the database for the given RoomID // Look up the aliases in the database for the given RoomID
creatorID, err := r.DB.GetCreatorIDForAlias(ctx, request.Alias) creatorID, err := r.DB.GetCreatorIDForAlias(ctx, request.Alias)
@ -156,11 +148,11 @@ func (r *RoomserverAliasAPI) GetCreatorIDForAlias(
return nil return nil
} }
// RemoveRoomAlias implements alias.RoomserverAliasAPI // RemoveRoomAlias implements alias.RoomserverInternalAPI
func (r *RoomserverAliasAPI) RemoveRoomAlias( func (r *RoomserverInternalAPI) RemoveRoomAlias(
ctx context.Context, ctx context.Context,
request *roomserverAPI.RemoveRoomAliasRequest, request *api.RemoveRoomAliasRequest,
response *roomserverAPI.RemoveRoomAliasResponse, response *api.RemoveRoomAliasResponse,
) error { ) error {
// Look up the room ID in the database // Look up the room ID in the database
roomID, err := r.DB.GetRoomIDForAlias(ctx, request.Alias) roomID, err := r.DB.GetRoomIDForAlias(ctx, request.Alias)
@ -186,7 +178,7 @@ type roomAliasesContent struct {
// Build the updated m.room.aliases event to send to the room after addition or // Build the updated m.room.aliases event to send to the room after addition or
// removal of an alias // removal of an alias
func (r *RoomserverAliasAPI) sendUpdatedAliasesEvent( func (r *RoomserverInternalAPI) sendUpdatedAliasesEvent(
ctx context.Context, userID string, roomID string, ctx context.Context, userID string, roomID string,
) error { ) error {
serverName := string(r.Cfg.Matrix.ServerName) serverName := string(r.Cfg.Matrix.ServerName)
@ -222,12 +214,12 @@ func (r *RoomserverAliasAPI) sendUpdatedAliasesEvent(
if len(eventsNeeded.Tuples()) == 0 { if len(eventsNeeded.Tuples()) == 0 {
return errors.New("expecting state tuples for event builder, got none") return errors.New("expecting state tuples for event builder, got none")
} }
req := roomserverAPI.QueryLatestEventsAndStateRequest{ req := api.QueryLatestEventsAndStateRequest{
RoomID: roomID, RoomID: roomID,
StateToFetch: eventsNeeded.Tuples(), StateToFetch: eventsNeeded.Tuples(),
} }
var res roomserverAPI.QueryLatestEventsAndStateResponse var res api.QueryLatestEventsAndStateResponse
if err = r.QueryAPI.QueryLatestEventsAndState(ctx, &req, &res); err != nil { if err = r.QueryLatestEventsAndState(ctx, &req, &res); err != nil {
return err return err
} }
builder.Depth = res.Depth builder.Depth = res.Depth
@ -263,91 +255,17 @@ func (r *RoomserverAliasAPI) sendUpdatedAliasesEvent(
} }
// Create the request // Create the request
ire := roomserverAPI.InputRoomEvent{ ire := api.InputRoomEvent{
Kind: roomserverAPI.KindNew, Kind: api.KindNew,
Event: event.Headered(roomVersion), Event: event.Headered(roomVersion),
AuthEventIDs: event.AuthEventIDs(), AuthEventIDs: event.AuthEventIDs(),
SendAsServer: serverName, SendAsServer: serverName,
} }
inputReq := roomserverAPI.InputRoomEventsRequest{ inputReq := api.InputRoomEventsRequest{
InputRoomEvents: []roomserverAPI.InputRoomEvent{ire}, InputRoomEvents: []api.InputRoomEvent{ire},
} }
var inputRes roomserverAPI.InputRoomEventsResponse var inputRes api.InputRoomEventsResponse
// Send the request // Send the request
return r.InputAPI.InputRoomEvents(ctx, &inputReq, &inputRes) return r.InputRoomEvents(ctx, &inputReq, &inputRes)
}
// SetupHTTP adds the RoomserverAliasAPI handlers to the http.ServeMux.
func (r *RoomserverAliasAPI) SetupHTTP(servMux *http.ServeMux) {
servMux.Handle(
roomserverAPI.RoomserverSetRoomAliasPath,
common.MakeInternalAPI("setRoomAlias", func(req *http.Request) util.JSONResponse {
var request roomserverAPI.SetRoomAliasRequest
var response roomserverAPI.SetRoomAliasResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.SetRoomAlias(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
roomserverAPI.RoomserverGetRoomIDForAliasPath,
common.MakeInternalAPI("GetRoomIDForAlias", func(req *http.Request) util.JSONResponse {
var request roomserverAPI.GetRoomIDForAliasRequest
var response roomserverAPI.GetRoomIDForAliasResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.GetRoomIDForAlias(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
roomserverAPI.RoomserverGetCreatorIDForAliasPath,
common.MakeInternalAPI("GetCreatorIDForAlias", func(req *http.Request) util.JSONResponse {
var request roomserverAPI.GetCreatorIDForAliasRequest
var response roomserverAPI.GetCreatorIDForAliasResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.GetCreatorIDForAlias(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
roomserverAPI.RoomserverGetAliasesForRoomIDPath,
common.MakeInternalAPI("getAliasesForRoomID", func(req *http.Request) util.JSONResponse {
var request roomserverAPI.GetAliasesForRoomIDRequest
var response roomserverAPI.GetAliasesForRoomIDResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.GetAliasesForRoomID(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
roomserverAPI.RoomserverRemoveRoomAliasPath,
common.MakeInternalAPI("removeRoomAlias", func(req *http.Request) util.JSONResponse {
var request roomserverAPI.RemoveRoomAliasRequest
var response roomserverAPI.RemoveRoomAliasResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.RemoveRoomAlias(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
} }

287
roomserver/internal/api.go Normal file
View File

@ -0,0 +1,287 @@
package internal
import (
"encoding/json"
"net/http"
"sync"
"github.com/Shopify/sarama"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/common/caching"
"github.com/matrix-org/dendrite/common/config"
fsAPI "github.com/matrix-org/dendrite/federationsender/api"
"github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/roomserver/storage"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
)
// RoomserverInternalAPI is an implementation of api.RoomserverInternalAPI
type RoomserverInternalAPI struct {
DB storage.Database
Cfg *config.Dendrite
Producer sarama.SyncProducer
ImmutableCache caching.ImmutableCache
ServerName gomatrixserverlib.ServerName
KeyRing gomatrixserverlib.JSONVerifier
FedClient *gomatrixserverlib.FederationClient
OutputRoomEventTopic string // Kafka topic for new output room events
mutex sync.Mutex // Protects calls to processRoomEvent
fsAPI fsAPI.FederationSenderInternalAPI
}
// SetupHTTP adds the RoomserverInternalAPI handlers to the http.ServeMux.
// nolint: gocyclo
func (r *RoomserverInternalAPI) SetupHTTP(servMux *http.ServeMux) {
servMux.Handle(api.RoomserverInputRoomEventsPath,
common.MakeInternalAPI("inputRoomEvents", func(req *http.Request) util.JSONResponse {
var request api.InputRoomEventsRequest
var response api.InputRoomEventsResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.MessageResponse(http.StatusBadRequest, err.Error())
}
if err := r.InputRoomEvents(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryLatestEventsAndStatePath,
common.MakeInternalAPI("queryLatestEventsAndState", func(req *http.Request) util.JSONResponse {
var request api.QueryLatestEventsAndStateRequest
var response api.QueryLatestEventsAndStateResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryLatestEventsAndState(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryStateAfterEventsPath,
common.MakeInternalAPI("queryStateAfterEvents", func(req *http.Request) util.JSONResponse {
var request api.QueryStateAfterEventsRequest
var response api.QueryStateAfterEventsResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryStateAfterEvents(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryEventsByIDPath,
common.MakeInternalAPI("queryEventsByID", func(req *http.Request) util.JSONResponse {
var request api.QueryEventsByIDRequest
var response api.QueryEventsByIDResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryEventsByID(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryMembershipForUserPath,
common.MakeInternalAPI("QueryMembershipForUser", func(req *http.Request) util.JSONResponse {
var request api.QueryMembershipForUserRequest
var response api.QueryMembershipForUserResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryMembershipForUser(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryMembershipsForRoomPath,
common.MakeInternalAPI("queryMembershipsForRoom", func(req *http.Request) util.JSONResponse {
var request api.QueryMembershipsForRoomRequest
var response api.QueryMembershipsForRoomResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryMembershipsForRoom(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryInvitesForUserPath,
common.MakeInternalAPI("queryInvitesForUser", func(req *http.Request) util.JSONResponse {
var request api.QueryInvitesForUserRequest
var response api.QueryInvitesForUserResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryInvitesForUser(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryServerAllowedToSeeEventPath,
common.MakeInternalAPI("queryServerAllowedToSeeEvent", func(req *http.Request) util.JSONResponse {
var request api.QueryServerAllowedToSeeEventRequest
var response api.QueryServerAllowedToSeeEventResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryServerAllowedToSeeEvent(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryMissingEventsPath,
common.MakeInternalAPI("queryMissingEvents", func(req *http.Request) util.JSONResponse {
var request api.QueryMissingEventsRequest
var response api.QueryMissingEventsResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryMissingEvents(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryStateAndAuthChainPath,
common.MakeInternalAPI("queryStateAndAuthChain", func(req *http.Request) util.JSONResponse {
var request api.QueryStateAndAuthChainRequest
var response api.QueryStateAndAuthChainResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryStateAndAuthChain(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryBackfillPath,
common.MakeInternalAPI("QueryBackfill", func(req *http.Request) util.JSONResponse {
var request api.QueryBackfillRequest
var response api.QueryBackfillResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryBackfill(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryRoomVersionCapabilitiesPath,
common.MakeInternalAPI("QueryRoomVersionCapabilities", func(req *http.Request) util.JSONResponse {
var request api.QueryRoomVersionCapabilitiesRequest
var response api.QueryRoomVersionCapabilitiesResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryRoomVersionCapabilities(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryRoomVersionForRoomPath,
common.MakeInternalAPI("QueryRoomVersionForRoom", func(req *http.Request) util.JSONResponse {
var request api.QueryRoomVersionForRoomRequest
var response api.QueryRoomVersionForRoomResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryRoomVersionForRoom(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverSetRoomAliasPath,
common.MakeInternalAPI("setRoomAlias", func(req *http.Request) util.JSONResponse {
var request api.SetRoomAliasRequest
var response api.SetRoomAliasResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.SetRoomAlias(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverGetRoomIDForAliasPath,
common.MakeInternalAPI("GetRoomIDForAlias", func(req *http.Request) util.JSONResponse {
var request api.GetRoomIDForAliasRequest
var response api.GetRoomIDForAliasResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.GetRoomIDForAlias(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverGetCreatorIDForAliasPath,
common.MakeInternalAPI("GetCreatorIDForAlias", func(req *http.Request) util.JSONResponse {
var request api.GetCreatorIDForAliasRequest
var response api.GetCreatorIDForAliasResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.GetCreatorIDForAlias(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverGetAliasesForRoomIDPath,
common.MakeInternalAPI("getAliasesForRoomID", func(req *http.Request) util.JSONResponse {
var request api.GetAliasesForRoomIDRequest
var response api.GetAliasesForRoomIDResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.GetAliasesForRoomID(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverRemoveRoomAliasPath,
common.MakeInternalAPI("removeRoomAlias", func(req *http.Request) util.JSONResponse {
var request api.RemoveRoomAliasRequest
var response api.RemoveRoomAliasResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.RemoveRoomAlias(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
}

View File

@ -13,46 +13,27 @@
// limitations under the License. // limitations under the License.
// Package input contains the code processes new room events // Package input contains the code processes new room events
package input package internal
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"net/http"
"sync"
"github.com/Shopify/sarama" "github.com/Shopify/sarama"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/roomserver/storage"
"github.com/matrix-org/util"
fsAPI "github.com/matrix-org/dendrite/federationsender/api" fsAPI "github.com/matrix-org/dendrite/federationsender/api"
) )
// RoomserverInputAPI implements api.RoomserverInputAPI
type RoomserverInputAPI struct {
DB storage.Database
Producer sarama.SyncProducer
// The kafkaesque topic to output new room events to.
// This is the name used in kafka to identify the stream to write events to.
OutputRoomEventTopic string
// Protects calls to processRoomEvent
mutex sync.Mutex
// The federation sender API allows us to send federation
// requests from the new perform input requests, still TODO.
fsAPI fsAPI.FederationSenderInternalAPI
}
// SetFederationSenderInputAPI passes in a federation sender input API reference // SetFederationSenderInputAPI passes in a federation sender input API reference
// so that we can avoid the chicken-and-egg problem of both the roomserver input API // so that we can avoid the chicken-and-egg problem of both the roomserver input API
// and the federation sender input API being interdependent. // and the federation sender input API being interdependent.
func (r *RoomserverInputAPI) SetFederationSenderAPI(fsAPI fsAPI.FederationSenderInternalAPI) { func (r *RoomserverInternalAPI) SetFederationSenderAPI(fsAPI fsAPI.FederationSenderInternalAPI) {
r.fsAPI = fsAPI r.fsAPI = fsAPI
} }
// WriteOutputEvents implements OutputRoomEventWriter // WriteOutputEvents implements OutputRoomEventWriter
func (r *RoomserverInputAPI) WriteOutputEvents(roomID string, updates []api.OutputEvent) error { func (r *RoomserverInternalAPI) WriteOutputEvents(roomID string, updates []api.OutputEvent) error {
messages := make([]*sarama.ProducerMessage, len(updates)) messages := make([]*sarama.ProducerMessage, len(updates))
for i := range updates { for i := range updates {
value, err := json.Marshal(updates[i]) value, err := json.Marshal(updates[i])
@ -68,8 +49,8 @@ func (r *RoomserverInputAPI) WriteOutputEvents(roomID string, updates []api.Outp
return r.Producer.SendMessages(messages) return r.Producer.SendMessages(messages)
} }
// InputRoomEvents implements api.RoomserverInputAPI // InputRoomEvents implements api.RoomserverInternalAPI
func (r *RoomserverInputAPI) InputRoomEvents( func (r *RoomserverInternalAPI) InputRoomEvents(
ctx context.Context, ctx context.Context,
request *api.InputRoomEventsRequest, request *api.InputRoomEventsRequest,
response *api.InputRoomEventsResponse, response *api.InputRoomEventsResponse,
@ -89,20 +70,3 @@ func (r *RoomserverInputAPI) InputRoomEvents(
} }
return nil return nil
} }
// SetupHTTP adds the RoomserverInputAPI handlers to the http.ServeMux.
func (r *RoomserverInputAPI) SetupHTTP(servMux *http.ServeMux) {
servMux.Handle(api.RoomserverInputRoomEventsPath,
common.MakeInternalAPI("inputRoomEvents", func(req *http.Request) util.JSONResponse {
var request api.InputRoomEventsRequest
var response api.InputRoomEventsResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.MessageResponse(http.StatusBadRequest, err.Error())
}
if err := r.InputRoomEvents(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
}

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package input package internal
import ( import (
"context" "context"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package input package internal
import ( import (
"testing" "testing"

View File

@ -14,7 +14,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package input package internal
import ( import (
"context" "context"

View File

@ -14,7 +14,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package input package internal
import ( import (
"bytes" "bytes"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package input package internal
import ( import (
"context" "context"

View File

@ -14,16 +14,12 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package query package internal
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"net/http"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/common/caching"
"github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/dendrite/roomserver/auth" "github.com/matrix-org/dendrite/roomserver/auth"
"github.com/matrix-org/dendrite/roomserver/state" "github.com/matrix-org/dendrite/roomserver/state"
@ -35,17 +31,8 @@ import (
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
// RoomserverQueryAPI is an implementation of api.RoomserverQueryAPI // QueryLatestEventsAndState implements api.RoomserverInternalAPI
type RoomserverQueryAPI struct { func (r *RoomserverInternalAPI) QueryLatestEventsAndState(
DB storage.Database
ImmutableCache caching.ImmutableCache
ServerName gomatrixserverlib.ServerName
KeyRing gomatrixserverlib.JSONVerifier
FedClient *gomatrixserverlib.FederationClient
}
// QueryLatestEventsAndState implements api.RoomserverQueryAPI
func (r *RoomserverQueryAPI) QueryLatestEventsAndState(
ctx context.Context, ctx context.Context,
request *api.QueryLatestEventsAndStateRequest, request *api.QueryLatestEventsAndStateRequest,
response *api.QueryLatestEventsAndStateResponse, response *api.QueryLatestEventsAndStateResponse,
@ -104,8 +91,8 @@ func (r *RoomserverQueryAPI) QueryLatestEventsAndState(
return nil return nil
} }
// QueryStateAfterEvents implements api.RoomserverQueryAPI // QueryStateAfterEvents implements api.RoomserverInternalAPI
func (r *RoomserverQueryAPI) QueryStateAfterEvents( func (r *RoomserverInternalAPI) QueryStateAfterEvents(
ctx context.Context, ctx context.Context,
request *api.QueryStateAfterEventsRequest, request *api.QueryStateAfterEventsRequest,
response *api.QueryStateAfterEventsResponse, response *api.QueryStateAfterEventsResponse,
@ -160,8 +147,8 @@ func (r *RoomserverQueryAPI) QueryStateAfterEvents(
return nil return nil
} }
// QueryEventsByID implements api.RoomserverQueryAPI // QueryEventsByID implements api.RoomserverInternalAPI
func (r *RoomserverQueryAPI) QueryEventsByID( func (r *RoomserverInternalAPI) QueryEventsByID(
ctx context.Context, ctx context.Context,
request *api.QueryEventsByIDRequest, request *api.QueryEventsByIDRequest,
response *api.QueryEventsByIDResponse, response *api.QueryEventsByIDResponse,
@ -195,7 +182,7 @@ func (r *RoomserverQueryAPI) QueryEventsByID(
return nil return nil
} }
func (r *RoomserverQueryAPI) loadStateEvents( func (r *RoomserverInternalAPI) loadStateEvents(
ctx context.Context, stateEntries []types.StateEntry, ctx context.Context, stateEntries []types.StateEntry,
) ([]gomatrixserverlib.Event, error) { ) ([]gomatrixserverlib.Event, error) {
eventNIDs := make([]types.EventNID, len(stateEntries)) eventNIDs := make([]types.EventNID, len(stateEntries))
@ -205,7 +192,7 @@ func (r *RoomserverQueryAPI) loadStateEvents(
return r.loadEvents(ctx, eventNIDs) return r.loadEvents(ctx, eventNIDs)
} }
func (r *RoomserverQueryAPI) loadEvents( func (r *RoomserverInternalAPI) loadEvents(
ctx context.Context, eventNIDs []types.EventNID, ctx context.Context, eventNIDs []types.EventNID,
) ([]gomatrixserverlib.Event, error) { ) ([]gomatrixserverlib.Event, error) {
stateEvents, err := r.DB.Events(ctx, eventNIDs) stateEvents, err := r.DB.Events(ctx, eventNIDs)
@ -220,8 +207,8 @@ func (r *RoomserverQueryAPI) loadEvents(
return result, nil return result, nil
} }
// QueryMembershipForUser implements api.RoomserverQueryAPI // QueryMembershipForUser implements api.RoomserverInternalAPI
func (r *RoomserverQueryAPI) QueryMembershipForUser( func (r *RoomserverInternalAPI) QueryMembershipForUser(
ctx context.Context, ctx context.Context,
request *api.QueryMembershipForUserRequest, request *api.QueryMembershipForUserRequest,
response *api.QueryMembershipForUserResponse, response *api.QueryMembershipForUserResponse,
@ -251,8 +238,8 @@ func (r *RoomserverQueryAPI) QueryMembershipForUser(
return nil return nil
} }
// QueryMembershipsForRoom implements api.RoomserverQueryAPI // QueryMembershipsForRoom implements api.RoomserverInternalAPI
func (r *RoomserverQueryAPI) QueryMembershipsForRoom( func (r *RoomserverInternalAPI) QueryMembershipsForRoom(
ctx context.Context, ctx context.Context,
request *api.QueryMembershipsForRoomRequest, request *api.QueryMembershipsForRoomRequest,
response *api.QueryMembershipsForRoomResponse, response *api.QueryMembershipsForRoomResponse,
@ -366,8 +353,8 @@ func getMembershipsAtState(
return events, nil return events, nil
} }
// QueryInvitesForUser implements api.RoomserverQueryAPI // QueryInvitesForUser implements api.RoomserverInternalAPI
func (r *RoomserverQueryAPI) QueryInvitesForUser( func (r *RoomserverInternalAPI) QueryInvitesForUser(
ctx context.Context, ctx context.Context,
request *api.QueryInvitesForUserRequest, request *api.QueryInvitesForUserRequest,
response *api.QueryInvitesForUserResponse, response *api.QueryInvitesForUserResponse,
@ -400,8 +387,8 @@ func (r *RoomserverQueryAPI) QueryInvitesForUser(
return nil return nil
} }
// QueryServerAllowedToSeeEvent implements api.RoomserverQueryAPI // QueryServerAllowedToSeeEvent implements api.RoomserverInternalAPI
func (r *RoomserverQueryAPI) QueryServerAllowedToSeeEvent( func (r *RoomserverInternalAPI) QueryServerAllowedToSeeEvent(
ctx context.Context, ctx context.Context,
request *api.QueryServerAllowedToSeeEventRequest, request *api.QueryServerAllowedToSeeEventRequest,
response *api.QueryServerAllowedToSeeEventResponse, response *api.QueryServerAllowedToSeeEventResponse,
@ -424,7 +411,7 @@ func (r *RoomserverQueryAPI) QueryServerAllowedToSeeEvent(
return return
} }
func (r *RoomserverQueryAPI) checkServerAllowedToSeeEvent( func (r *RoomserverInternalAPI) checkServerAllowedToSeeEvent(
ctx context.Context, eventID string, serverName gomatrixserverlib.ServerName, isServerInRoom bool, ctx context.Context, eventID string, serverName gomatrixserverlib.ServerName, isServerInRoom bool,
) (bool, error) { ) (bool, error) {
roomState := state.NewStateResolution(r.DB) roomState := state.NewStateResolution(r.DB)
@ -443,8 +430,8 @@ func (r *RoomserverQueryAPI) checkServerAllowedToSeeEvent(
return auth.IsServerAllowed(serverName, isServerInRoom, stateAtEvent), nil return auth.IsServerAllowed(serverName, isServerInRoom, stateAtEvent), nil
} }
// QueryMissingEvents implements api.RoomserverQueryAPI // QueryMissingEvents implements api.RoomserverInternalAPI
func (r *RoomserverQueryAPI) QueryMissingEvents( func (r *RoomserverInternalAPI) QueryMissingEvents(
ctx context.Context, ctx context.Context,
request *api.QueryMissingEventsRequest, request *api.QueryMissingEventsRequest,
response *api.QueryMissingEventsResponse, response *api.QueryMissingEventsResponse,
@ -489,7 +476,7 @@ func (r *RoomserverQueryAPI) QueryMissingEvents(
} }
// QueryBackfill implements api.RoomServerQueryAPI // QueryBackfill implements api.RoomServerQueryAPI
func (r *RoomserverQueryAPI) QueryBackfill( func (r *RoomserverInternalAPI) QueryBackfill(
ctx context.Context, ctx context.Context,
request *api.QueryBackfillRequest, request *api.QueryBackfillRequest,
response *api.QueryBackfillResponse, response *api.QueryBackfillResponse,
@ -542,7 +529,7 @@ func (r *RoomserverQueryAPI) QueryBackfill(
return err return err
} }
func (r *RoomserverQueryAPI) backfillViaFederation(ctx context.Context, req *api.QueryBackfillRequest, res *api.QueryBackfillResponse) error { func (r *RoomserverInternalAPI) backfillViaFederation(ctx context.Context, req *api.QueryBackfillRequest, res *api.QueryBackfillResponse) error {
roomVer, err := r.DB.GetRoomVersionForRoom(ctx, req.RoomID) roomVer, err := r.DB.GetRoomVersionForRoom(ctx, req.RoomID)
if err != nil { if err != nil {
return fmt.Errorf("backfillViaFederation: unknown room version for room %s : %w", req.RoomID, err) return fmt.Errorf("backfillViaFederation: unknown room version for room %s : %w", req.RoomID, err)
@ -600,7 +587,7 @@ func (r *RoomserverQueryAPI) backfillViaFederation(ctx context.Context, req *api
return nil return nil
} }
func (r *RoomserverQueryAPI) isServerCurrentlyInRoom(ctx context.Context, serverName gomatrixserverlib.ServerName, roomID string) (bool, error) { func (r *RoomserverInternalAPI) isServerCurrentlyInRoom(ctx context.Context, serverName gomatrixserverlib.ServerName, roomID string) (bool, error) {
roomNID, err := r.DB.RoomNID(ctx, roomID) roomNID, err := r.DB.RoomNID(ctx, roomID)
if err != nil { if err != nil {
return false, err return false, err
@ -624,7 +611,7 @@ func (r *RoomserverQueryAPI) isServerCurrentlyInRoom(ctx context.Context, server
// fetchAndStoreMissingEvents does a best-effort fetch and store of missing events specified in stateIDs. Returns no error as it is just // fetchAndStoreMissingEvents does a best-effort fetch and store of missing events specified in stateIDs. Returns no error as it is just
// best effort. // best effort.
func (r *RoomserverQueryAPI) fetchAndStoreMissingEvents(ctx context.Context, roomVer gomatrixserverlib.RoomVersion, func (r *RoomserverInternalAPI) fetchAndStoreMissingEvents(ctx context.Context, roomVer gomatrixserverlib.RoomVersion,
backfillRequester *backfillRequester, stateIDs []string) { backfillRequester *backfillRequester, stateIDs []string) {
servers := backfillRequester.servers servers := backfillRequester.servers
@ -684,7 +671,7 @@ func (r *RoomserverQueryAPI) fetchAndStoreMissingEvents(ctx context.Context, roo
// TODO: Remove this when we have tests to assert correctness of this function // TODO: Remove this when we have tests to assert correctness of this function
// nolint:gocyclo // nolint:gocyclo
func (r *RoomserverQueryAPI) scanEventTree( func (r *RoomserverInternalAPI) scanEventTree(
ctx context.Context, front []string, visited map[string]bool, limit int, ctx context.Context, front []string, visited map[string]bool, limit int,
serverName gomatrixserverlib.ServerName, serverName gomatrixserverlib.ServerName,
) ([]types.EventNID, error) { ) ([]types.EventNID, error) {
@ -777,8 +764,8 @@ BFSLoop:
return resultNIDs, err return resultNIDs, err
} }
// QueryStateAndAuthChain implements api.RoomserverQueryAPI // QueryStateAndAuthChain implements api.RoomserverInternalAPI
func (r *RoomserverQueryAPI) QueryStateAndAuthChain( func (r *RoomserverInternalAPI) QueryStateAndAuthChain(
ctx context.Context, ctx context.Context,
request *api.QueryStateAndAuthChainRequest, request *api.QueryStateAndAuthChainRequest,
response *api.QueryStateAndAuthChainResponse, response *api.QueryStateAndAuthChainResponse,
@ -837,7 +824,7 @@ func (r *RoomserverQueryAPI) QueryStateAndAuthChain(
return err return err
} }
func (r *RoomserverQueryAPI) loadStateAtEventIDs(ctx context.Context, eventIDs []string) ([]gomatrixserverlib.Event, error) { func (r *RoomserverInternalAPI) loadStateAtEventIDs(ctx context.Context, eventIDs []string) ([]gomatrixserverlib.Event, error) {
roomState := state.NewStateResolution(r.DB) roomState := state.NewStateResolution(r.DB)
prevStates, err := r.DB.StateAtEventIDs(ctx, eventIDs) prevStates, err := r.DB.StateAtEventIDs(ctx, eventIDs)
if err != nil { if err != nil {
@ -942,8 +929,8 @@ func persistEvents(ctx context.Context, db storage.Database, events []gomatrixse
return roomNID, backfilledEventMap return roomNID, backfilledEventMap
} }
// QueryRoomVersionCapabilities implements api.RoomserverQueryAPI // QueryRoomVersionCapabilities implements api.RoomserverInternalAPI
func (r *RoomserverQueryAPI) QueryRoomVersionCapabilities( func (r *RoomserverInternalAPI) QueryRoomVersionCapabilities(
ctx context.Context, ctx context.Context,
request *api.QueryRoomVersionCapabilitiesRequest, request *api.QueryRoomVersionCapabilitiesRequest,
response *api.QueryRoomVersionCapabilitiesResponse, response *api.QueryRoomVersionCapabilitiesResponse,
@ -960,8 +947,8 @@ func (r *RoomserverQueryAPI) QueryRoomVersionCapabilities(
return nil return nil
} }
// QueryRoomVersionCapabilities implements api.RoomserverQueryAPI // QueryRoomVersionCapabilities implements api.RoomserverInternalAPI
func (r *RoomserverQueryAPI) QueryRoomVersionForRoom( func (r *RoomserverInternalAPI) QueryRoomVersionForRoom(
ctx context.Context, ctx context.Context,
request *api.QueryRoomVersionForRoomRequest, request *api.QueryRoomVersionForRoomRequest,
response *api.QueryRoomVersionForRoomResponse, response *api.QueryRoomVersionForRoomResponse,
@ -979,176 +966,3 @@ func (r *RoomserverQueryAPI) QueryRoomVersionForRoom(
r.ImmutableCache.StoreRoomVersion(request.RoomID, response.RoomVersion) r.ImmutableCache.StoreRoomVersion(request.RoomID, response.RoomVersion)
return nil return nil
} }
// SetupHTTP adds the RoomserverQueryAPI handlers to the http.ServeMux.
// nolint: gocyclo
func (r *RoomserverQueryAPI) SetupHTTP(servMux *http.ServeMux) {
servMux.Handle(
api.RoomserverQueryLatestEventsAndStatePath,
common.MakeInternalAPI("queryLatestEventsAndState", func(req *http.Request) util.JSONResponse {
var request api.QueryLatestEventsAndStateRequest
var response api.QueryLatestEventsAndStateResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryLatestEventsAndState(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryStateAfterEventsPath,
common.MakeInternalAPI("queryStateAfterEvents", func(req *http.Request) util.JSONResponse {
var request api.QueryStateAfterEventsRequest
var response api.QueryStateAfterEventsResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryStateAfterEvents(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryEventsByIDPath,
common.MakeInternalAPI("queryEventsByID", func(req *http.Request) util.JSONResponse {
var request api.QueryEventsByIDRequest
var response api.QueryEventsByIDResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryEventsByID(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryMembershipForUserPath,
common.MakeInternalAPI("QueryMembershipForUser", func(req *http.Request) util.JSONResponse {
var request api.QueryMembershipForUserRequest
var response api.QueryMembershipForUserResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryMembershipForUser(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryMembershipsForRoomPath,
common.MakeInternalAPI("queryMembershipsForRoom", func(req *http.Request) util.JSONResponse {
var request api.QueryMembershipsForRoomRequest
var response api.QueryMembershipsForRoomResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryMembershipsForRoom(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryInvitesForUserPath,
common.MakeInternalAPI("queryInvitesForUser", func(req *http.Request) util.JSONResponse {
var request api.QueryInvitesForUserRequest
var response api.QueryInvitesForUserResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryInvitesForUser(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryServerAllowedToSeeEventPath,
common.MakeInternalAPI("queryServerAllowedToSeeEvent", func(req *http.Request) util.JSONResponse {
var request api.QueryServerAllowedToSeeEventRequest
var response api.QueryServerAllowedToSeeEventResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryServerAllowedToSeeEvent(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryMissingEventsPath,
common.MakeInternalAPI("queryMissingEvents", func(req *http.Request) util.JSONResponse {
var request api.QueryMissingEventsRequest
var response api.QueryMissingEventsResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryMissingEvents(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryStateAndAuthChainPath,
common.MakeInternalAPI("queryStateAndAuthChain", func(req *http.Request) util.JSONResponse {
var request api.QueryStateAndAuthChainRequest
var response api.QueryStateAndAuthChainResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryStateAndAuthChain(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryBackfillPath,
common.MakeInternalAPI("QueryBackfill", func(req *http.Request) util.JSONResponse {
var request api.QueryBackfillRequest
var response api.QueryBackfillResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryBackfill(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryRoomVersionCapabilitiesPath,
common.MakeInternalAPI("QueryRoomVersionCapabilities", func(req *http.Request) util.JSONResponse {
var request api.QueryRoomVersionCapabilitiesRequest
var response api.QueryRoomVersionCapabilitiesResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryRoomVersionCapabilities(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
servMux.Handle(
api.RoomserverQueryRoomVersionForRoomPath,
common.MakeInternalAPI("QueryRoomVersionForRoom", func(req *http.Request) util.JSONResponse {
var request api.QueryRoomVersionForRoomRequest
var response api.QueryRoomVersionForRoomResponse
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
return util.ErrorResponse(err)
}
if err := r.QueryRoomVersionForRoom(req.Context(), &request, &response); err != nil {
return util.ErrorResponse(err)
}
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
}

View File

@ -1,4 +1,4 @@
package query package internal
import ( import (
"context" "context"

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package query package internal
import ( import (
"context" "context"
@ -24,7 +24,7 @@ import (
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
) )
// used to implement RoomserverQueryAPIEventDB to test getAuthChain // used to implement RoomserverInternalAPIEventDB to test getAuthChain
type getEventDB struct { type getEventDB struct {
eventMap map[string]gomatrixserverlib.Event eventMap map[string]gomatrixserverlib.Event
} }
@ -79,7 +79,7 @@ func (db *getEventDB) addFakeEvents(graph map[string][]string) error {
return nil return nil
} }
// EventsFromIDs implements RoomserverQueryAPIEventDB // EventsFromIDs implements RoomserverInternalAPIEventDB
func (db *getEventDB) EventsFromIDs(ctx context.Context, eventIDs []string) (res []types.Event, err error) { func (db *getEventDB) EventsFromIDs(ctx context.Context, eventIDs []string) (res []types.Event, err error) {
for _, evID := range eventIDs { for _, evID := range eventIDs {
res = append(res, types.Event{ res = append(res, types.Event{

View File

@ -20,12 +20,8 @@ import (
"github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/api"
"github.com/matrix-org/gomatrixserverlib" "github.com/matrix-org/gomatrixserverlib"
asQuery "github.com/matrix-org/dendrite/appservice/query"
"github.com/matrix-org/dendrite/common/basecomponent" "github.com/matrix-org/dendrite/common/basecomponent"
"github.com/matrix-org/dendrite/roomserver/alias" "github.com/matrix-org/dendrite/roomserver/internal"
"github.com/matrix-org/dendrite/roomserver/input"
"github.com/matrix-org/dendrite/roomserver/query"
"github.com/matrix-org/dendrite/roomserver/storage" "github.com/matrix-org/dendrite/roomserver/storage"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
@ -35,45 +31,27 @@ import (
// allowing other components running in the same process to hit the query the // allowing other components running in the same process to hit the query the
// APIs directly instead of having to use HTTP. // APIs directly instead of having to use HTTP.
func SetupRoomServerComponent( func SetupRoomServerComponent(
base *basecomponent.BaseDendrite, keyRing gomatrixserverlib.JSONVerifier, base *basecomponent.BaseDendrite,
keyRing gomatrixserverlib.JSONVerifier,
fedClient *gomatrixserverlib.FederationClient, fedClient *gomatrixserverlib.FederationClient,
) (api.RoomserverAliasAPI, api.RoomserverInputAPI, api.RoomserverQueryAPI) { ) api.RoomserverInternalAPI {
roomserverDB, err := storage.Open(string(base.Cfg.Database.RoomServer)) roomserverDB, err := storage.Open(string(base.Cfg.Database.RoomServer))
if err != nil { if err != nil {
logrus.WithError(err).Panicf("failed to connect to room server db") logrus.WithError(err).Panicf("failed to connect to room server db")
} }
inputAPI := input.RoomserverInputAPI{ internalAPI := internal.RoomserverInternalAPI{
DB: roomserverDB, DB: roomserverDB,
Cfg: base.Cfg,
Producer: base.KafkaProducer, Producer: base.KafkaProducer,
OutputRoomEventTopic: string(base.Cfg.Kafka.Topics.OutputRoomEvent), OutputRoomEventTopic: string(base.Cfg.Kafka.Topics.OutputRoomEvent),
ImmutableCache: base.ImmutableCache,
ServerName: base.Cfg.Matrix.ServerName,
FedClient: fedClient,
KeyRing: keyRing,
} }
inputAPI.SetupHTTP(http.DefaultServeMux) internalAPI.SetupHTTP(http.DefaultServeMux)
queryAPI := query.RoomserverQueryAPI{ return &internalAPI
DB: roomserverDB,
ImmutableCache: base.ImmutableCache,
ServerName: base.Cfg.Matrix.ServerName,
FedClient: fedClient,
// TODO: We should have a key server so we don't keep adding components
// which talk to the same DB.
KeyRing: keyRing,
}
queryAPI.SetupHTTP(http.DefaultServeMux)
asAPI := asQuery.AppServiceQueryAPI{Cfg: base.Cfg}
aliasAPI := alias.RoomserverAliasAPI{
DB: roomserverDB,
Cfg: base.Cfg,
InputAPI: &inputAPI,
QueryAPI: &queryAPI,
AppserviceAPI: &asAPI,
}
aliasAPI.SetupHTTP(http.DefaultServeMux)
return &aliasAPI, &inputAPI, &queryAPI
} }

View File

@ -32,10 +32,10 @@ import (
// OutputRoomEventConsumer consumes events that originated in the room server. // OutputRoomEventConsumer consumes events that originated in the room server.
type OutputRoomEventConsumer struct { type OutputRoomEventConsumer struct {
roomServerConsumer *common.ContinualConsumer rsAPI api.RoomserverInternalAPI
db storage.Database rsConsumer *common.ContinualConsumer
notifier *sync.Notifier db storage.Database
query api.RoomserverQueryAPI notifier *sync.Notifier
} }
// NewOutputRoomEventConsumer creates a new OutputRoomEventConsumer. Call Start() to begin consuming from room servers. // NewOutputRoomEventConsumer creates a new OutputRoomEventConsumer. Call Start() to begin consuming from room servers.
@ -44,7 +44,7 @@ func NewOutputRoomEventConsumer(
kafkaConsumer sarama.Consumer, kafkaConsumer sarama.Consumer,
n *sync.Notifier, n *sync.Notifier,
store storage.Database, store storage.Database,
queryAPI api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
) *OutputRoomEventConsumer { ) *OutputRoomEventConsumer {
consumer := common.ContinualConsumer{ consumer := common.ContinualConsumer{
@ -53,10 +53,10 @@ func NewOutputRoomEventConsumer(
PartitionStore: store, PartitionStore: store,
} }
s := &OutputRoomEventConsumer{ s := &OutputRoomEventConsumer{
roomServerConsumer: &consumer, rsConsumer: &consumer,
db: store, db: store,
notifier: n, notifier: n,
query: queryAPI, rsAPI: rsAPI,
} }
consumer.ProcessMessage = s.onMessage consumer.ProcessMessage = s.onMessage
@ -65,7 +65,7 @@ func NewOutputRoomEventConsumer(
// Start consuming from room servers // Start consuming from room servers
func (s *OutputRoomEventConsumer) Start() error { func (s *OutputRoomEventConsumer) Start() error {
return s.roomServerConsumer.Start() return s.rsConsumer.Start()
} }
// onMessage is called when the sync server receives a new event from the room server output log. // onMessage is called when the sync server receives a new event from the room server output log.
@ -226,7 +226,7 @@ func (s *OutputRoomEventConsumer) lookupStateEvents(
// from the roomserver using the query API. // from the roomserver using the query API.
eventReq := api.QueryEventsByIDRequest{EventIDs: missing} eventReq := api.QueryEventsByIDRequest{EventIDs: missing}
var eventResp api.QueryEventsByIDResponse var eventResp api.QueryEventsByIDResponse
if err := s.query.QueryEventsByID(context.TODO(), &eventReq, &eventResp); err != nil { if err := s.rsAPI.QueryEventsByID(context.TODO(), &eventReq, &eventResp); err != nil {
return nil, err return nil, err
} }

View File

@ -34,7 +34,7 @@ import (
type messagesReq struct { type messagesReq struct {
ctx context.Context ctx context.Context
db storage.Database db storage.Database
queryAPI api.RoomserverQueryAPI rsAPI api.RoomserverInternalAPI
federation *gomatrixserverlib.FederationClient federation *gomatrixserverlib.FederationClient
cfg *config.Dendrite cfg *config.Dendrite
roomID string roomID string
@ -59,7 +59,7 @@ const defaultMessagesLimit = 10
func OnIncomingMessagesRequest( func OnIncomingMessagesRequest(
req *http.Request, db storage.Database, roomID string, req *http.Request, db storage.Database, roomID string,
federation *gomatrixserverlib.FederationClient, federation *gomatrixserverlib.FederationClient,
queryAPI api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
cfg *config.Dendrite, cfg *config.Dendrite,
) util.JSONResponse { ) util.JSONResponse {
var err error var err error
@ -135,7 +135,7 @@ func OnIncomingMessagesRequest(
mReq := messagesReq{ mReq := messagesReq{
ctx: req.Context(), ctx: req.Context(),
db: db, db: db,
queryAPI: queryAPI, rsAPI: rsAPI,
federation: federation, federation: federation,
cfg: cfg, cfg: cfg,
roomID: roomID, roomID: roomID,
@ -360,7 +360,7 @@ func (r *messagesReq) handleNonEmptyEventsSlice(streamEvents []types.StreamEvent
// the room or sending the request. // the room or sending the request.
func (r *messagesReq) backfill(roomID string, fromEventIDs []string, limit int) ([]gomatrixserverlib.HeaderedEvent, error) { func (r *messagesReq) backfill(roomID string, fromEventIDs []string, limit int) ([]gomatrixserverlib.HeaderedEvent, error) {
var res api.QueryBackfillResponse var res api.QueryBackfillResponse
err := r.queryAPI.QueryBackfill(context.Background(), &api.QueryBackfillRequest{ err := r.rsAPI.QueryBackfill(context.Background(), &api.QueryBackfillRequest{
RoomID: roomID, RoomID: roomID,
EarliestEventsIDs: fromEventIDs, EarliestEventsIDs: fromEventIDs,
Limit: limit, Limit: limit,

View File

@ -40,7 +40,7 @@ const pathPrefixR0 = "/_matrix/client/r0"
func Setup( func Setup(
apiMux *mux.Router, srp *sync.RequestPool, syncDB storage.Database, apiMux *mux.Router, srp *sync.RequestPool, syncDB storage.Database,
deviceDB devices.Database, federation *gomatrixserverlib.FederationClient, deviceDB devices.Database, federation *gomatrixserverlib.FederationClient,
queryAPI api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
cfg *config.Dendrite, cfg *config.Dendrite,
) { ) {
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter() r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter()
@ -61,6 +61,6 @@ func Setup(
if err != nil { if err != nil {
return util.ErrorResponse(err) return util.ErrorResponse(err)
} }
return OnIncomingMessagesRequest(req, syncDB, vars["roomID"], federation, queryAPI, cfg) return OnIncomingMessagesRequest(req, syncDB, vars["roomID"], federation, rsAPI, cfg)
})).Methods(http.MethodGet, http.MethodOptions) })).Methods(http.MethodGet, http.MethodOptions)
} }

View File

@ -38,7 +38,7 @@ func SetupSyncAPIComponent(
base *basecomponent.BaseDendrite, base *basecomponent.BaseDendrite,
deviceDB devices.Database, deviceDB devices.Database,
accountsDB accounts.Database, accountsDB accounts.Database,
queryAPI api.RoomserverQueryAPI, rsAPI api.RoomserverInternalAPI,
federation *gomatrixserverlib.FederationClient, federation *gomatrixserverlib.FederationClient,
cfg *config.Dendrite, cfg *config.Dendrite,
) { ) {
@ -61,7 +61,7 @@ func SetupSyncAPIComponent(
requestPool := sync.NewRequestPool(syncDB, notifier, accountsDB) requestPool := sync.NewRequestPool(syncDB, notifier, accountsDB)
roomConsumer := consumers.NewOutputRoomEventConsumer( roomConsumer := consumers.NewOutputRoomEventConsumer(
base.Cfg, base.KafkaConsumer, notifier, syncDB, queryAPI, base.Cfg, base.KafkaConsumer, notifier, syncDB, rsAPI,
) )
if err = roomConsumer.Start(); err != nil { if err = roomConsumer.Start(); err != nil {
logrus.WithError(err).Panicf("failed to start room server consumer") logrus.WithError(err).Panicf("failed to start room server consumer")
@ -81,5 +81,5 @@ func SetupSyncAPIComponent(
logrus.WithError(err).Panicf("failed to start typing server consumer") logrus.WithError(err).Panicf("failed to start typing server consumer")
} }
routing.Setup(base.APIMux, requestPool, syncDB, deviceDB, federation, queryAPI, cfg) routing.Setup(base.APIMux, requestPool, syncDB, deviceDB, federation, rsAPI, cfg)
} }