mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-22 11:41:38 +00:00
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:
parent
ebbfc12592
commit
e15f6676ac
@ -44,8 +44,7 @@ func SetupAppServiceAPIComponent(
|
||||
accountsDB accounts.Database,
|
||||
deviceDB devices.Database,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
roomserverAliasAPI roomserverAPI.RoomserverAliasAPI,
|
||||
roomserverQueryAPI roomserverAPI.RoomserverQueryAPI,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
transactionsCache *transactions.Cache,
|
||||
) appserviceAPI.AppServiceQueryAPI {
|
||||
// Create a connection to the appservice postgres DB
|
||||
@ -87,7 +86,7 @@ func SetupAppServiceAPIComponent(
|
||||
|
||||
consumer := consumers.NewOutputRoomEventConsumer(
|
||||
base.Cfg, base.KafkaConsumer, accountsDB, appserviceDB,
|
||||
roomserverQueryAPI, roomserverAliasAPI, workerStates,
|
||||
rsAPI, workerStates,
|
||||
)
|
||||
if err := consumer.Start(); err != nil {
|
||||
logrus.WithError(err).Panicf("failed to start appservice roomserver consumer")
|
||||
@ -100,7 +99,7 @@ func SetupAppServiceAPIComponent(
|
||||
|
||||
// Set up HTTP Endpoints
|
||||
routing.Setup(
|
||||
base.APIMux, base.Cfg, roomserverQueryAPI, roomserverAliasAPI,
|
||||
base.APIMux, base.Cfg, rsAPI,
|
||||
accountsDB, federation, transactionsCache,
|
||||
)
|
||||
|
||||
|
@ -35,8 +35,7 @@ type OutputRoomEventConsumer struct {
|
||||
roomServerConsumer *common.ContinualConsumer
|
||||
db accounts.Database
|
||||
asDB storage.Database
|
||||
query api.RoomserverQueryAPI
|
||||
alias api.RoomserverAliasAPI
|
||||
rsAPI api.RoomserverInternalAPI
|
||||
serverName string
|
||||
workerStates []types.ApplicationServiceWorkerState
|
||||
}
|
||||
@ -48,8 +47,7 @@ func NewOutputRoomEventConsumer(
|
||||
kafkaConsumer sarama.Consumer,
|
||||
store accounts.Database,
|
||||
appserviceDB storage.Database,
|
||||
queryAPI api.RoomserverQueryAPI,
|
||||
aliasAPI api.RoomserverAliasAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
workerStates []types.ApplicationServiceWorkerState,
|
||||
) *OutputRoomEventConsumer {
|
||||
consumer := common.ContinualConsumer{
|
||||
@ -61,8 +59,7 @@ func NewOutputRoomEventConsumer(
|
||||
roomServerConsumer: &consumer,
|
||||
db: store,
|
||||
asDB: appserviceDB,
|
||||
query: queryAPI,
|
||||
alias: aliasAPI,
|
||||
rsAPI: rsAPI,
|
||||
serverName: string(cfg.Matrix.ServerName),
|
||||
workerStates: workerStates,
|
||||
}
|
||||
@ -139,7 +136,7 @@ func (s *OutputRoomEventConsumer) lookupMissingStateEvents(
|
||||
// Request the missing events from the roomserver
|
||||
eventReq := api.QueryEventsByIDRequest{EventIDs: missing}
|
||||
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
|
||||
}
|
||||
|
||||
@ -200,7 +197,7 @@ func (s *OutputRoomEventConsumer) appserviceIsInterestedInEvent(ctx context.Cont
|
||||
// Check all known room aliases of the room the event came from
|
||||
queryReq := api.GetAliasesForRoomIDRequest{RoomID: event.RoomID()}
|
||||
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 {
|
||||
if appservice.IsInterestedInRoomAlias(alias) {
|
||||
return true
|
||||
|
@ -37,7 +37,7 @@ const pathPrefixApp = "/_matrix/app/v1"
|
||||
// nolint: gocyclo
|
||||
func Setup(
|
||||
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
|
||||
federation *gomatrixserverlib.FederationClient, // nolint: unparam
|
||||
transactionsCache *transactions.Cache, // nolint: unparam
|
||||
|
@ -38,15 +38,13 @@ func SetupClientAPIComponent(
|
||||
accountsDB accounts.Database,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
keyRing *gomatrixserverlib.KeyRing,
|
||||
aliasAPI roomserverAPI.RoomserverAliasAPI,
|
||||
inputAPI roomserverAPI.RoomserverInputAPI,
|
||||
queryAPI roomserverAPI.RoomserverQueryAPI,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
eduInputAPI eduServerAPI.EDUServerInputAPI,
|
||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||
transactionsCache *transactions.Cache,
|
||||
fsAPI federationSenderAPI.FederationSenderInternalAPI,
|
||||
) {
|
||||
roomserverProducer := producers.NewRoomserverProducer(inputAPI, queryAPI)
|
||||
roomserverProducer := producers.NewRoomserverProducer(rsAPI)
|
||||
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
||||
|
||||
userUpdateProducer := &producers.UserUpdateProducer{
|
||||
@ -60,14 +58,14 @@ func SetupClientAPIComponent(
|
||||
}
|
||||
|
||||
consumer := consumers.NewOutputRoomEventConsumer(
|
||||
base.Cfg, base.KafkaConsumer, accountsDB, queryAPI,
|
||||
base.Cfg, base.KafkaConsumer, accountsDB, rsAPI,
|
||||
)
|
||||
if err := consumer.Start(); err != nil {
|
||||
logrus.WithError(err).Panicf("failed to start room server consumer")
|
||||
}
|
||||
|
||||
routing.Setup(
|
||||
base.APIMux, base.Cfg, roomserverProducer, queryAPI, aliasAPI, asAPI,
|
||||
base.APIMux, base.Cfg, roomserverProducer, rsAPI, asAPI,
|
||||
accountsDB, deviceDB, federation, *keyRing, userUpdateProducer,
|
||||
syncProducer, eduProducer, transactionsCache, fsAPI,
|
||||
)
|
||||
|
@ -30,10 +30,10 @@ import (
|
||||
|
||||
// OutputRoomEventConsumer consumes events that originated in the room server.
|
||||
type OutputRoomEventConsumer struct {
|
||||
roomServerConsumer *common.ContinualConsumer
|
||||
db accounts.Database
|
||||
query api.RoomserverQueryAPI
|
||||
serverName string
|
||||
rsAPI api.RoomserverInternalAPI
|
||||
rsConsumer *common.ContinualConsumer
|
||||
db accounts.Database
|
||||
serverName string
|
||||
}
|
||||
|
||||
// NewOutputRoomEventConsumer creates a new OutputRoomEventConsumer. Call Start() to begin consuming from room servers.
|
||||
@ -41,7 +41,7 @@ func NewOutputRoomEventConsumer(
|
||||
cfg *config.Dendrite,
|
||||
kafkaConsumer sarama.Consumer,
|
||||
store accounts.Database,
|
||||
queryAPI api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
) *OutputRoomEventConsumer {
|
||||
|
||||
consumer := common.ContinualConsumer{
|
||||
@ -50,10 +50,10 @@ func NewOutputRoomEventConsumer(
|
||||
PartitionStore: store,
|
||||
}
|
||||
s := &OutputRoomEventConsumer{
|
||||
roomServerConsumer: &consumer,
|
||||
db: store,
|
||||
query: queryAPI,
|
||||
serverName: string(cfg.Matrix.ServerName),
|
||||
rsConsumer: &consumer,
|
||||
db: store,
|
||||
rsAPI: rsAPI,
|
||||
serverName: string(cfg.Matrix.ServerName),
|
||||
}
|
||||
consumer.ProcessMessage = s.onMessage
|
||||
|
||||
@ -62,7 +62,7 @@ func NewOutputRoomEventConsumer(
|
||||
|
||||
// Start consuming from room servers
|
||||
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.
|
||||
@ -134,7 +134,7 @@ func (s *OutputRoomEventConsumer) lookupStateEvents(
|
||||
// Request the missing events from the roomserver
|
||||
eventReq := api.QueryEventsByIDRequest{EventIDs: missing}
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -23,15 +23,13 @@ import (
|
||||
|
||||
// RoomserverProducer produces events for the roomserver to consume.
|
||||
type RoomserverProducer struct {
|
||||
InputAPI api.RoomserverInputAPI
|
||||
QueryAPI api.RoomserverQueryAPI
|
||||
RsAPI api.RoomserverInternalAPI
|
||||
}
|
||||
|
||||
// NewRoomserverProducer creates a new RoomserverProducer
|
||||
func NewRoomserverProducer(inputAPI api.RoomserverInputAPI, queryAPI api.RoomserverQueryAPI) *RoomserverProducer {
|
||||
func NewRoomserverProducer(rsAPI api.RoomserverInternalAPI) *RoomserverProducer {
|
||||
return &RoomserverProducer{
|
||||
InputAPI: inputAPI,
|
||||
QueryAPI: queryAPI,
|
||||
RsAPI: rsAPI,
|
||||
}
|
||||
}
|
||||
|
||||
@ -95,7 +93,7 @@ func (c *RoomserverProducer) SendInputRoomEvents(
|
||||
) (eventID string, err error) {
|
||||
request := api.InputRoomEventsRequest{InputRoomEvents: ires}
|
||||
var response api.InputRoomEventsResponse
|
||||
err = c.InputAPI.InputRoomEvents(ctx, &request, &response)
|
||||
err = c.RsAPI.InputRoomEvents(ctx, &request, &response)
|
||||
eventID = response.EventID
|
||||
return
|
||||
}
|
||||
@ -118,5 +116,5 @@ func (c *RoomserverProducer) SendInvite(
|
||||
}},
|
||||
}
|
||||
var response api.InputRoomEventsResponse
|
||||
return c.InputAPI.InputRoomEvents(ctx, &request, &response)
|
||||
return c.RsAPI.InputRoomEvents(ctx, &request, &response)
|
||||
}
|
||||
|
@ -26,11 +26,11 @@ import (
|
||||
// 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
|
||||
func GetCapabilities(
|
||||
req *http.Request, queryAPI roomserverAPI.RoomserverQueryAPI,
|
||||
req *http.Request, rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
) util.JSONResponse {
|
||||
roomVersionsQueryReq := roomserverAPI.QueryRoomVersionCapabilitiesRequest{}
|
||||
roomVersionsQueryRes := roomserverAPI.QueryRoomVersionCapabilitiesResponse{}
|
||||
if err := queryAPI.QueryRoomVersionCapabilities(
|
||||
if err := rsAPI.QueryRoomVersionCapabilities(
|
||||
req.Context(),
|
||||
&roomVersionsQueryReq,
|
||||
&roomVersionsQueryRes,
|
||||
|
@ -137,13 +137,13 @@ type fledglingEvent struct {
|
||||
func CreateRoom(
|
||||
req *http.Request, device *authtypes.Device,
|
||||
cfg *config.Dendrite, producer *producers.RoomserverProducer,
|
||||
accountDB accounts.Database, aliasAPI roomserverAPI.RoomserverAliasAPI,
|
||||
accountDB accounts.Database, rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||
) util.JSONResponse {
|
||||
// TODO (#267): Check room ID doesn't clash with an existing one, and we
|
||||
// probably shouldn't be using pseudo-random strings, maybe GUIDs?
|
||||
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
|
||||
@ -151,7 +151,7 @@ func CreateRoom(
|
||||
func createRoom(
|
||||
req *http.Request, device *authtypes.Device,
|
||||
cfg *config.Dendrite, roomID string, producer *producers.RoomserverProducer,
|
||||
accountDB accounts.Database, aliasAPI roomserverAPI.RoomserverAliasAPI,
|
||||
accountDB accounts.Database, rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||
) util.JSONResponse {
|
||||
logger := util.GetLogger(req.Context())
|
||||
@ -340,7 +340,7 @@ func createRoom(
|
||||
}
|
||||
|
||||
var aliasResp roomserverAPI.SetRoomAliasResponse
|
||||
err = aliasAPI.SetRoomAlias(req.Context(), &aliasReq, &aliasResp)
|
||||
err = rsAPI.SetRoomAlias(req.Context(), &aliasReq, &aliasResp)
|
||||
if err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("aliasAPI.SetRoomAlias failed")
|
||||
return jsonerror.InternalServerError()
|
||||
|
@ -46,7 +46,7 @@ func DirectoryRoom(
|
||||
roomAlias string,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
cfg *config.Dendrite,
|
||||
rsAPI roomserverAPI.RoomserverAliasAPI,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
fedSenderAPI federationSenderAPI.FederationSenderInternalAPI,
|
||||
) util.JSONResponse {
|
||||
_, domain, err := gomatrixserverlib.SplitID('#', roomAlias)
|
||||
@ -115,7 +115,7 @@ func SetLocalAlias(
|
||||
device *authtypes.Device,
|
||||
alias string,
|
||||
cfg *config.Dendrite,
|
||||
aliasAPI roomserverAPI.RoomserverAliasAPI,
|
||||
aliasAPI roomserverAPI.RoomserverInternalAPI,
|
||||
) util.JSONResponse {
|
||||
_, domain, err := gomatrixserverlib.SplitID('#', alias)
|
||||
if err != nil {
|
||||
@ -190,7 +190,7 @@ func RemoveLocalAlias(
|
||||
req *http.Request,
|
||||
device *authtypes.Device,
|
||||
alias string,
|
||||
aliasAPI roomserverAPI.RoomserverAliasAPI,
|
||||
aliasAPI roomserverAPI.RoomserverInternalAPI,
|
||||
) util.JSONResponse {
|
||||
|
||||
creatorQueryReq := roomserverAPI.GetCreatorIDForAliasRequest{
|
||||
|
@ -44,7 +44,7 @@ func GetEvent(
|
||||
roomID string,
|
||||
eventID string,
|
||||
cfg *config.Dendrite,
|
||||
queryAPI api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
keyRing gomatrixserverlib.KeyRing,
|
||||
) util.JSONResponse {
|
||||
@ -52,7 +52,7 @@ func GetEvent(
|
||||
EventIDs: []string{eventID},
|
||||
}
|
||||
var eventsResp api.QueryEventsByIDResponse
|
||||
err := queryAPI.QueryEventsByID(req.Context(), &eventsReq, &eventsResp)
|
||||
err := rsAPI.QueryEventsByID(req.Context(), &eventsReq, &eventsResp)
|
||||
if err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("queryAPI.QueryEventsByID failed")
|
||||
return jsonerror.InternalServerError()
|
||||
@ -88,7 +88,7 @@ func GetEvent(
|
||||
}},
|
||||
}
|
||||
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")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
@ -43,8 +43,7 @@ func JoinRoomByIDOrAlias(
|
||||
cfg *config.Dendrite,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
producer *producers.RoomserverProducer,
|
||||
queryAPI roomserverAPI.RoomserverQueryAPI,
|
||||
aliasAPI roomserverAPI.RoomserverAliasAPI,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
fsAPI federationSenderAPI.FederationSenderInternalAPI,
|
||||
keyRing gomatrixserverlib.KeyRing,
|
||||
accountDB accounts.Database,
|
||||
@ -80,7 +79,7 @@ func JoinRoomByIDOrAlias(
|
||||
|
||||
r := joinRoomReq{
|
||||
req, evTime, content, device.UserID, cfg, federation, producer,
|
||||
queryAPI, aliasAPI, fsAPI, keyRing,
|
||||
rsAPI, fsAPI, keyRing,
|
||||
}
|
||||
|
||||
if strings.HasPrefix(roomIDOrAlias, "!") {
|
||||
@ -106,8 +105,7 @@ type joinRoomReq struct {
|
||||
cfg *config.Dendrite
|
||||
federation *gomatrixserverlib.FederationClient
|
||||
producer *producers.RoomserverProducer
|
||||
queryAPI roomserverAPI.RoomserverQueryAPI
|
||||
aliasAPI roomserverAPI.RoomserverAliasAPI
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI
|
||||
fsAPI federationSenderAPI.FederationSenderInternalAPI
|
||||
keyRing gomatrixserverlib.KeyRing
|
||||
}
|
||||
@ -124,7 +122,7 @@ func (r joinRoomReq) joinRoomByID(roomID string) util.JSONResponse {
|
||||
RoomID: roomID, TargetUserID: r.userID,
|
||||
}
|
||||
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")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
@ -172,7 +170,7 @@ func (r joinRoomReq) joinRoomByAlias(roomAlias string) util.JSONResponse {
|
||||
if domain == r.cfg.Matrix.ServerName {
|
||||
queryReq := roomserverAPI.GetRoomIDForAliasRequest{Alias: roomAlias}
|
||||
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")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
@ -243,7 +241,7 @@ func (r joinRoomReq) joinRoomUsingServers(
|
||||
}
|
||||
|
||||
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 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
|
||||
|
@ -45,12 +45,12 @@ var errMissingUserID = errors.New("'user_id' must be supplied")
|
||||
func SendMembership(
|
||||
req *http.Request, accountDB accounts.Database, device *authtypes.Device,
|
||||
roomID string, membership string, cfg *config.Dendrite,
|
||||
queryAPI roomserverAPI.RoomserverQueryAPI, asAPI appserviceAPI.AppServiceQueryAPI,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI,
|
||||
producer *producers.RoomserverProducer,
|
||||
) util.JSONResponse {
|
||||
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
|
||||
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{
|
||||
Code: http.StatusBadRequest,
|
||||
JSON: jsonerror.UnsupportedRoomVersion(err.Error()),
|
||||
@ -71,7 +71,7 @@ func SendMembership(
|
||||
}
|
||||
|
||||
inviteStored, jsonErrResp := checkAndProcessThreepid(
|
||||
req, device, &body, cfg, queryAPI, accountDB, producer,
|
||||
req, device, &body, cfg, rsAPI, accountDB, producer,
|
||||
membership, roomID, evTime,
|
||||
)
|
||||
if jsonErrResp != nil {
|
||||
@ -89,7 +89,7 @@ func SendMembership(
|
||||
}
|
||||
|
||||
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 {
|
||||
return util.JSONResponse{
|
||||
@ -153,7 +153,7 @@ func buildMembershipEvent(
|
||||
device *authtypes.Device,
|
||||
membership, roomID string,
|
||||
cfg *config.Dendrite, evTime time.Time,
|
||||
queryAPI roomserverAPI.RoomserverQueryAPI, asAPI appserviceAPI.AppServiceQueryAPI,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI,
|
||||
) (*gomatrixserverlib.Event, error) {
|
||||
stateKey, reason, err := getMembershipStateKey(body, device, membership)
|
||||
if err != nil {
|
||||
@ -188,7 +188,7 @@ func buildMembershipEvent(
|
||||
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
|
||||
@ -248,7 +248,7 @@ func checkAndProcessThreepid(
|
||||
device *authtypes.Device,
|
||||
body *threepid.MembershipRequest,
|
||||
cfg *config.Dendrite,
|
||||
queryAPI roomserverAPI.RoomserverQueryAPI,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
accountDB accounts.Database,
|
||||
producer *producers.RoomserverProducer,
|
||||
membership, roomID string,
|
||||
@ -256,7 +256,7 @@ func checkAndProcessThreepid(
|
||||
) (inviteStored bool, errRes *util.JSONResponse) {
|
||||
|
||||
inviteStored, err := threepid.CheckAndProcessInvite(
|
||||
req.Context(), device, body, cfg, queryAPI, accountDB, producer,
|
||||
req.Context(), device, body, cfg, rsAPI, accountDB, producer,
|
||||
membership, roomID, evTime,
|
||||
)
|
||||
if err == threepid.ErrMissingParameter {
|
||||
|
@ -39,7 +39,7 @@ type getJoinedRoomsResponse struct {
|
||||
func GetMemberships(
|
||||
req *http.Request, device *authtypes.Device, roomID string, joinedOnly bool,
|
||||
_ *config.Dendrite,
|
||||
queryAPI api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
) util.JSONResponse {
|
||||
queryReq := api.QueryMembershipsForRoomRequest{
|
||||
JoinedOnly: joinedOnly,
|
||||
@ -47,8 +47,8 @@ func GetMemberships(
|
||||
Sender: device.UserID,
|
||||
}
|
||||
var queryRes api.QueryMembershipsForRoomResponse
|
||||
if err := queryAPI.QueryMembershipsForRoom(req.Context(), &queryReq, &queryRes); err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("queryAPI.QueryMembershipsForRoom failed")
|
||||
if err := rsAPI.QueryMembershipsForRoom(req.Context(), &queryReq, &queryRes); err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("rsAPI.QueryMembershipsForRoom failed")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
||||
|
@ -94,7 +94,7 @@ func GetAvatarURL(
|
||||
func SetAvatarURL(
|
||||
req *http.Request, accountDB accounts.Database, device *authtypes.Device,
|
||||
userID string, producer *producers.UserUpdateProducer, cfg *config.Dendrite,
|
||||
rsProducer *producers.RoomserverProducer, queryAPI api.RoomserverQueryAPI,
|
||||
rsProducer *producers.RoomserverProducer, rsAPI api.RoomserverInternalAPI,
|
||||
) util.JSONResponse {
|
||||
if userID != device.UserID {
|
||||
return util.JSONResponse{
|
||||
@ -154,7 +154,7 @@ func SetAvatarURL(
|
||||
}
|
||||
|
||||
events, err := buildMembershipEvents(
|
||||
req.Context(), memberships, newProfile, userID, cfg, evTime, queryAPI,
|
||||
req.Context(), memberships, newProfile, userID, cfg, evTime, rsAPI,
|
||||
)
|
||||
if err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("buildMembershipEvents failed")
|
||||
@ -208,7 +208,7 @@ func GetDisplayName(
|
||||
func SetDisplayName(
|
||||
req *http.Request, accountDB accounts.Database, device *authtypes.Device,
|
||||
userID string, producer *producers.UserUpdateProducer, cfg *config.Dendrite,
|
||||
rsProducer *producers.RoomserverProducer, queryAPI api.RoomserverQueryAPI,
|
||||
rsProducer *producers.RoomserverProducer, rsAPI api.RoomserverInternalAPI,
|
||||
) util.JSONResponse {
|
||||
if userID != device.UserID {
|
||||
return util.JSONResponse{
|
||||
@ -268,7 +268,7 @@ func SetDisplayName(
|
||||
}
|
||||
|
||||
events, err := buildMembershipEvents(
|
||||
req.Context(), memberships, newProfile, userID, cfg, evTime, queryAPI,
|
||||
req.Context(), memberships, newProfile, userID, cfg, evTime, rsAPI,
|
||||
)
|
||||
if err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("buildMembershipEvents failed")
|
||||
@ -337,14 +337,14 @@ func buildMembershipEvents(
|
||||
ctx context.Context,
|
||||
memberships []authtypes.Membership,
|
||||
newProfile authtypes.Profile, userID string, cfg *config.Dendrite,
|
||||
evTime time.Time, queryAPI api.RoomserverQueryAPI,
|
||||
evTime time.Time, rsAPI api.RoomserverInternalAPI,
|
||||
) ([]gomatrixserverlib.HeaderedEvent, error) {
|
||||
evs := []gomatrixserverlib.HeaderedEvent{}
|
||||
|
||||
for _, membership := range memberships {
|
||||
verReq := api.QueryRoomVersionForRoomRequest{RoomID: membership.RoomID}
|
||||
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
|
||||
}
|
||||
|
||||
@ -366,7 +366,7 @@ func buildMembershipEvents(
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -49,8 +49,7 @@ const pathPrefixUnstable = "/_matrix/client/unstable"
|
||||
func Setup(
|
||||
apiMux *mux.Router, cfg *config.Dendrite,
|
||||
producer *producers.RoomserverProducer,
|
||||
queryAPI roomserverAPI.RoomserverQueryAPI,
|
||||
aliasAPI roomserverAPI.RoomserverAliasAPI,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||
accountDB accounts.Database,
|
||||
deviceDB devices.Database,
|
||||
@ -91,7 +90,7 @@ func Setup(
|
||||
|
||||
r0mux.Handle("/createRoom",
|
||||
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)
|
||||
r0mux.Handle("/join/{roomIDOrAlias}",
|
||||
@ -102,7 +101,7 @@ func Setup(
|
||||
}
|
||||
return JoinRoomByIDOrAlias(
|
||||
req, device, vars["roomIDOrAlias"], cfg, federation, producer,
|
||||
queryAPI, aliasAPI, federationSender, keyRing, accountDB,
|
||||
rsAPI, federationSender, keyRing, accountDB,
|
||||
)
|
||||
}),
|
||||
).Methods(http.MethodPost, http.MethodOptions)
|
||||
@ -118,7 +117,7 @@ func Setup(
|
||||
if err != nil {
|
||||
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)
|
||||
r0mux.Handle("/rooms/{roomID}/send/{eventType}",
|
||||
@ -127,7 +126,7 @@ func Setup(
|
||||
if err != nil {
|
||||
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)
|
||||
r0mux.Handle("/rooms/{roomID}/send/{eventType}/{txnID}",
|
||||
@ -138,7 +137,7 @@ func Setup(
|
||||
}
|
||||
txnID := vars["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)
|
||||
r0mux.Handle("/rooms/{roomID}/event/{eventID}",
|
||||
@ -147,7 +146,7 @@ func Setup(
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
@ -156,7 +155,7 @@ func Setup(
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return OnIncomingStateRequest(req.Context(), queryAPI, vars["roomID"])
|
||||
return OnIncomingStateRequest(req.Context(), rsAPI, vars["roomID"])
|
||||
})).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 {
|
||||
@ -164,7 +163,7 @@ func Setup(
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
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 {
|
||||
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)
|
||||
|
||||
r0mux.Handle("/rooms/{roomID}/state/{eventType:[^/]+/?}",
|
||||
@ -187,7 +186,7 @@ func Setup(
|
||||
if strings.HasSuffix(eventType, "/") {
|
||||
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)
|
||||
|
||||
@ -198,7 +197,7 @@ func Setup(
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
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)
|
||||
|
||||
@ -220,7 +219,7 @@ func Setup(
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
@ -230,7 +229,7 @@ func Setup(
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
@ -240,7 +239,7 @@ func Setup(
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return RemoveLocalAlias(req, device, vars["roomAlias"], aliasAPI)
|
||||
return RemoveLocalAlias(req, device, vars["roomAlias"], rsAPI)
|
||||
}),
|
||||
).Methods(http.MethodDelete, http.MethodOptions)
|
||||
|
||||
@ -354,7 +353,7 @@ func Setup(
|
||||
if err != nil {
|
||||
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)
|
||||
// Browsers use the OPTIONS HTTP method to check if the CORS policy allows
|
||||
@ -376,7 +375,7 @@ func Setup(
|
||||
if err != nil {
|
||||
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)
|
||||
// Browsers use the OPTIONS HTTP method to check if the CORS policy allows
|
||||
@ -489,7 +488,7 @@ func Setup(
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
@ -499,7 +498,7 @@ func Setup(
|
||||
if err != nil {
|
||||
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)
|
||||
|
||||
@ -603,7 +602,7 @@ func Setup(
|
||||
|
||||
r0mux.Handle("/capabilities",
|
||||
common.MakeAuthAPI("capabilities", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
|
||||
return GetCapabilities(req, queryAPI)
|
||||
return GetCapabilities(req, rsAPI)
|
||||
}),
|
||||
).Methods(http.MethodGet)
|
||||
}
|
||||
|
@ -45,13 +45,13 @@ func SendEvent(
|
||||
device *authtypes.Device,
|
||||
roomID, eventType string, txnID, stateKey *string,
|
||||
cfg *config.Dendrite,
|
||||
queryAPI api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
producer *producers.RoomserverProducer,
|
||||
txnCache *transactions.Cache,
|
||||
) util.JSONResponse {
|
||||
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
|
||||
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{
|
||||
Code: http.StatusBadRequest,
|
||||
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 {
|
||||
return *resErr
|
||||
}
|
||||
@ -115,7 +115,7 @@ func generateSendEvent(
|
||||
device *authtypes.Device,
|
||||
roomID, eventType string, stateKey *string,
|
||||
cfg *config.Dendrite,
|
||||
queryAPI api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
) (*gomatrixserverlib.Event, *util.JSONResponse) {
|
||||
// parse the incoming http request
|
||||
userID := device.UserID
|
||||
@ -148,7 +148,7 @@ func generateSendEvent(
|
||||
}
|
||||
|
||||
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 {
|
||||
return nil, &util.JSONResponse{
|
||||
Code: http.StatusNotFound,
|
||||
|
@ -40,7 +40,7 @@ type stateEventInStateResp struct {
|
||||
// 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
|
||||
// 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
|
||||
// we should return the state at the poin they left)
|
||||
stateReq := api.QueryLatestEventsAndStateRequest{
|
||||
@ -48,7 +48,7 @@ func OnIncomingStateRequest(ctx context.Context, queryAPI api.RoomserverQueryAPI
|
||||
}
|
||||
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")
|
||||
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
|
||||
// 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.
|
||||
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
|
||||
// we should return the state at the poin they left)
|
||||
util.GetLogger(ctx).WithFields(log.Fields{
|
||||
@ -118,7 +118,7 @@ func OnIncomingStateTypeRequest(ctx context.Context, queryAPI api.RoomserverQuer
|
||||
}
|
||||
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")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
@ -87,7 +87,7 @@ var (
|
||||
func CheckAndProcessInvite(
|
||||
ctx context.Context,
|
||||
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,
|
||||
evTime time.Time,
|
||||
) (inviteStoredOnIDServer bool, err error) {
|
||||
@ -112,7 +112,7 @@ func CheckAndProcessInvite(
|
||||
// "m.room.third_party_invite" have to be emitted from the data in
|
||||
// storeInviteRes.
|
||||
err = emit3PIDInviteEvent(
|
||||
ctx, body, storeInviteRes, device, roomID, cfg, queryAPI, producer, evTime,
|
||||
ctx, body, storeInviteRes, device, roomID, cfg, rsAPI, producer, evTime,
|
||||
)
|
||||
inviteStoredOnIDServer = err == nil
|
||||
|
||||
@ -331,7 +331,7 @@ func emit3PIDInviteEvent(
|
||||
ctx context.Context,
|
||||
body *MembershipRequest, res *idServerStoreInviteResponse,
|
||||
device *authtypes.Device, roomID string, cfg *config.Dendrite,
|
||||
queryAPI api.RoomserverQueryAPI, producer *producers.RoomserverProducer,
|
||||
rsAPI api.RoomserverInternalAPI, producer *producers.RoomserverProducer,
|
||||
evTime time.Time,
|
||||
) error {
|
||||
builder := &gomatrixserverlib.EventBuilder{
|
||||
@ -354,7 +354,7 @@ func emit3PIDInviteEvent(
|
||||
}
|
||||
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
@ -28,11 +28,11 @@ func main() {
|
||||
accountDB := base.CreateAccountsDB()
|
||||
deviceDB := base.CreateDeviceDB()
|
||||
federation := base.CreateFederationClient()
|
||||
alias, _, query := base.CreateHTTPRoomserverAPIs()
|
||||
rsAPI := base.CreateHTTPRoomserverAPIs()
|
||||
cache := transactions.New()
|
||||
|
||||
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))
|
||||
|
@ -36,13 +36,14 @@ func main() {
|
||||
keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives)
|
||||
|
||||
asQuery := base.CreateHTTPAppServiceAPIs()
|
||||
alias, input, query := base.CreateHTTPRoomserverAPIs()
|
||||
rsAPI := base.CreateHTTPRoomserverAPIs()
|
||||
fsAPI := base.CreateHTTPFederationSenderAPIs()
|
||||
rsAPI.SetFederationSenderAPI(fsAPI)
|
||||
eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New())
|
||||
|
||||
clientapi.SetupClientAPIComponent(
|
||||
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))
|
||||
|
@ -148,27 +148,34 @@ func main() {
|
||||
federation := createFederationClient(base)
|
||||
keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives)
|
||||
|
||||
alias, input, query := roomserver.SetupRoomServerComponent(&base.Base, keyRing, federation)
|
||||
eduInputAPI := eduserver.SetupEDUServerComponent(&base.Base, cache.New())
|
||||
asQuery := appservice.SetupAppServiceAPIComponent(
|
||||
&base.Base, accountDB, deviceDB, federation, alias, query, transactions.New(),
|
||||
rsAPI := roomserver.SetupRoomServerComponent(
|
||||
&base.Base, keyRing, federation,
|
||||
)
|
||||
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(
|
||||
&base.Base, deviceDB, accountDB,
|
||||
federation, &keyRing, alias, input, query,
|
||||
eduInputAPI, asQuery, transactions.New(), fsAPI,
|
||||
federation, &keyRing, rsAPI,
|
||||
eduInputAPI, asAPI, transactions.New(), fsAPI,
|
||||
)
|
||||
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)
|
||||
publicRoomsDB, err := storage.NewPublicRoomsServerDatabaseWithPubSub(string(base.Base.Cfg.Database.PublicRoomsAPI), base.LibP2PPubsub)
|
||||
if err != nil {
|
||||
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
||||
}
|
||||
publicroomsapi.SetupPublicRoomsAPIComponent(&base.Base, deviceDB, publicRoomsDB, query, federation, nil) // Check this later
|
||||
syncapi.SetupSyncAPIComponent(&base.Base, deviceDB, accountDB, query, federation, &cfg)
|
||||
publicroomsapi.SetupPublicRoomsAPIComponent(&base.Base, deviceDB, publicRoomsDB, rsAPI, federation, nil) // Check this later
|
||||
syncapi.SetupSyncAPIComponent(&base.Base, deviceDB, accountDB, rsAPI, federation, &cfg)
|
||||
|
||||
httpHandler := common.WrapHandlerInCORS(base.Base.APIMux)
|
||||
|
||||
|
@ -35,14 +35,15 @@ func main() {
|
||||
fsAPI := base.CreateHTTPFederationSenderAPIs()
|
||||
keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives)
|
||||
|
||||
alias, input, query := base.CreateHTTPRoomserverAPIs()
|
||||
asQuery := base.CreateHTTPAppServiceAPIs()
|
||||
rsAPI := base.CreateHTTPRoomserverAPIs()
|
||||
asAPI := base.CreateHTTPAppServiceAPIs()
|
||||
rsAPI.SetFederationSenderAPI(fsAPI)
|
||||
eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New())
|
||||
eduProducer := producers.NewEDUServerProducer(eduInputAPI)
|
||||
|
||||
federationapi.SetupFederationAPIComponent(
|
||||
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))
|
||||
|
@ -28,12 +28,11 @@ func main() {
|
||||
federation := base.CreateFederationClient()
|
||||
keyDB := base.CreateKeyDB()
|
||||
keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives)
|
||||
|
||||
_, input, query := base.CreateHTTPRoomserverAPIs()
|
||||
|
||||
federationsender.SetupFederationSenderComponent(
|
||||
base, federation, query, input, &keyRing,
|
||||
rsAPI := base.CreateHTTPRoomserverAPIs()
|
||||
fsAPI := federationsender.SetupFederationSenderComponent(
|
||||
base, federation, rsAPI, &keyRing,
|
||||
)
|
||||
rsAPI.SetFederationSenderAPI(fsAPI)
|
||||
|
||||
base.SetupAndServeHTTP(string(base.Cfg.Bind.FederationSender), string(base.Cfg.Listen.FederationSender))
|
||||
|
||||
|
@ -57,28 +57,34 @@ func main() {
|
||||
federation := base.CreateFederationClient()
|
||||
keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives)
|
||||
|
||||
alias, input, query := roomserver.SetupRoomServerComponent(base, keyRing, federation)
|
||||
eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New())
|
||||
asQuery := appservice.SetupAppServiceAPIComponent(
|
||||
base, accountDB, deviceDB, federation, alias, query, transactions.New(),
|
||||
rsAPI := roomserver.SetupRoomServerComponent(
|
||||
base, keyRing, federation,
|
||||
)
|
||||
fsAPI := federationsender.SetupFederationSenderComponent(base, federation, query, input, &keyRing)
|
||||
input.SetFederationSenderAPI(fsAPI)
|
||||
eduInputAPI := eduserver.SetupEDUServerComponent(
|
||||
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(
|
||||
base, deviceDB, accountDB,
|
||||
federation, &keyRing, alias, input, query,
|
||||
eduInputAPI, asQuery, transactions.New(), fsAPI,
|
||||
federation, &keyRing, rsAPI,
|
||||
eduInputAPI, asAPI, transactions.New(), fsAPI,
|
||||
)
|
||||
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)
|
||||
publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI))
|
||||
if err != nil {
|
||||
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
||||
}
|
||||
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, query, federation, nil)
|
||||
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, query, federation, cfg)
|
||||
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, nil)
|
||||
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg)
|
||||
|
||||
httpHandler := common.WrapHandlerInCORS(base.APIMux)
|
||||
|
||||
|
@ -28,12 +28,15 @@ func main() {
|
||||
|
||||
deviceDB := base.CreateDeviceDB()
|
||||
|
||||
_, _, query := base.CreateHTTPRoomserverAPIs()
|
||||
fsAPI := base.CreateHTTPFederationSenderAPIs()
|
||||
rsAPI := base.CreateHTTPRoomserverAPIs()
|
||||
rsAPI.SetFederationSenderAPI(fsAPI)
|
||||
|
||||
publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI))
|
||||
if err != nil {
|
||||
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))
|
||||
|
||||
|
@ -31,8 +31,8 @@ func main() {
|
||||
keyRing := keydb.CreateKeyRing(federation.Client, keyDB, cfg.Matrix.KeyPerspectives)
|
||||
|
||||
fsAPI := base.CreateHTTPFederationSenderAPIs()
|
||||
_, input, _ := roomserver.SetupRoomServerComponent(base, keyRing, federation)
|
||||
input.SetFederationSenderAPI(fsAPI)
|
||||
rsAPI := roomserver.SetupRoomServerComponent(base, keyRing, federation)
|
||||
rsAPI.SetFederationSenderAPI(fsAPI)
|
||||
|
||||
base.SetupAndServeHTTP(string(base.Cfg.Bind.RoomServer), string(base.Cfg.Listen.RoomServer))
|
||||
|
||||
|
@ -28,9 +28,9 @@ func main() {
|
||||
accountDB := base.CreateAccountsDB()
|
||||
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))
|
||||
|
||||
|
@ -123,28 +123,28 @@ func main() {
|
||||
}
|
||||
p2pPublicRoomProvider := NewLibP2PPublicRoomsProvider(node)
|
||||
|
||||
alias, input, query := roomserver.SetupRoomServerComponent(base, keyRing, federation)
|
||||
rsAPI := roomserver.SetupRoomServerComponent(base, keyRing, federation)
|
||||
eduInputAPI := eduserver.SetupEDUServerComponent(base, cache.New())
|
||||
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)
|
||||
input.SetFederationSenderAPI(fedSenderAPI)
|
||||
fedSenderAPI := federationsender.SetupFederationSenderComponent(base, federation, rsAPI, &keyRing)
|
||||
rsAPI.SetFederationSenderAPI(fedSenderAPI)
|
||||
|
||||
clientapi.SetupClientAPIComponent(
|
||||
base, deviceDB, accountDB,
|
||||
federation, &keyRing, alias, input, query,
|
||||
federation, &keyRing, rsAPI,
|
||||
eduInputAPI, asQuery, transactions.New(), fedSenderAPI,
|
||||
)
|
||||
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)
|
||||
publicRoomsDB, err := storage.NewPublicRoomsServerDatabase(string(base.Cfg.Database.PublicRoomsAPI))
|
||||
if err != nil {
|
||||
logrus.WithError(err).Panicf("failed to connect to public rooms db")
|
||||
}
|
||||
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, query, federation, p2pPublicRoomProvider)
|
||||
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, query, federation, cfg)
|
||||
publicroomsapi.SetupPublicRoomsAPIComponent(base, deviceDB, publicRoomsDB, rsAPI, federation, p2pPublicRoomProvider)
|
||||
syncapi.SetupSyncAPIComponent(base, deviceDB, accountDB, rsAPI, federation, cfg)
|
||||
|
||||
httpHandler := common.WrapHandlerInCORS(base.APIMux)
|
||||
|
||||
|
@ -209,7 +209,7 @@ func writeToRoomServer(input []string, roomserverURL string) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
x, err := api.NewRoomserverInputAPIHTTP(roomserverURL, &http.Client{Timeout: timeoutHTTP})
|
||||
x, err := api.NewRoomserverInternalAPIHTTP(roomserverURL, &http.Client{Timeout: timeoutHTTP}, nil)
|
||||
if err != nil {
|
||||
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
|
||||
// a api.RoomserverQueryAPI client. The caller can use this function to check the
|
||||
// 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")
|
||||
if err != nil {
|
||||
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)}
|
||||
|
||||
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)
|
||||
})
|
||||
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
|
||||
if err := q.QueryLatestEventsAndState(
|
||||
context.Background(),
|
||||
|
@ -119,24 +119,12 @@ func (b *BaseDendrite) CreateHTTPAppServiceAPIs() appserviceAPI.AppServiceQueryA
|
||||
|
||||
// CreateHTTPRoomserverAPIs returns the AliasAPI, InputAPI and QueryAPI for hitting
|
||||
// the roomserver over HTTP.
|
||||
func (b *BaseDendrite) CreateHTTPRoomserverAPIs() (
|
||||
roomserverAPI.RoomserverAliasAPI,
|
||||
roomserverAPI.RoomserverInputAPI,
|
||||
roomserverAPI.RoomserverQueryAPI,
|
||||
) {
|
||||
alias, err := roomserverAPI.NewRoomserverAliasAPIHTTP(b.Cfg.RoomServerURL(), b.httpClient)
|
||||
func (b *BaseDendrite) CreateHTTPRoomserverAPIs() roomserverAPI.RoomserverInternalAPI {
|
||||
rsAPI, err := roomserverAPI.NewRoomserverInternalAPIHTTP(b.Cfg.RoomServerURL(), b.httpClient, b.ImmutableCache)
|
||||
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)
|
||||
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
|
||||
return rsAPI
|
||||
}
|
||||
|
||||
// CreateHTTPEDUServerAPIs returns eduInputAPI for hitting the EDU
|
||||
|
@ -39,13 +39,13 @@ var ErrRoomNoExists = errors.New("Room does not exist")
|
||||
func BuildEvent(
|
||||
ctx context.Context,
|
||||
builder *gomatrixserverlib.EventBuilder, cfg *config.Dendrite, evTime time.Time,
|
||||
queryAPI api.RoomserverQueryAPI, queryRes *api.QueryLatestEventsAndStateResponse,
|
||||
rsAPI api.RoomserverInternalAPI, queryRes *api.QueryLatestEventsAndStateResponse,
|
||||
) (*gomatrixserverlib.Event, error) {
|
||||
if queryRes == nil {
|
||||
queryRes = &api.QueryLatestEventsAndStateResponse{}
|
||||
}
|
||||
|
||||
err := AddPrevEventsToEvent(ctx, builder, queryAPI, queryRes)
|
||||
err := AddPrevEventsToEvent(ctx, builder, rsAPI, queryRes)
|
||||
if err != nil {
|
||||
// This can pass through a ErrRoomNoExists to the caller
|
||||
return nil, err
|
||||
@ -66,7 +66,7 @@ func BuildEvent(
|
||||
func AddPrevEventsToEvent(
|
||||
ctx context.Context,
|
||||
builder *gomatrixserverlib.EventBuilder,
|
||||
queryAPI api.RoomserverQueryAPI, queryRes *api.QueryLatestEventsAndStateResponse,
|
||||
rsAPI api.RoomserverInternalAPI, queryRes *api.QueryLatestEventsAndStateResponse,
|
||||
) error {
|
||||
eventsNeeded, err := gomatrixserverlib.StateNeededForEventBuilder(builder)
|
||||
if err != nil {
|
||||
@ -82,8 +82,8 @@ func AddPrevEventsToEvent(
|
||||
RoomID: builder.RoomID,
|
||||
StateToFetch: eventsNeeded.Tuples(),
|
||||
}
|
||||
if err = queryAPI.QueryLatestEventsAndState(ctx, &queryReq, queryRes); err != nil {
|
||||
return fmt.Errorf("queryAPI.QueryLatestEventsAndState: %w", err)
|
||||
if err = rsAPI.QueryLatestEventsAndState(ctx, &queryReq, queryRes); err != nil {
|
||||
return fmt.Errorf("rsAPI.QueryLatestEventsAndState: %w", err)
|
||||
}
|
||||
|
||||
if !queryRes.RoomExists {
|
||||
|
@ -36,18 +36,16 @@ func SetupFederationAPIComponent(
|
||||
deviceDB devices.Database,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
keyRing *gomatrixserverlib.KeyRing,
|
||||
aliasAPI roomserverAPI.RoomserverAliasAPI,
|
||||
inputAPI roomserverAPI.RoomserverInputAPI,
|
||||
queryAPI roomserverAPI.RoomserverQueryAPI,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||
federationSenderAPI federationSenderAPI.FederationSenderInternalAPI,
|
||||
eduProducer *producers.EDUServerProducer,
|
||||
) {
|
||||
roomserverProducer := producers.NewRoomserverProducer(inputAPI, queryAPI)
|
||||
roomserverProducer := producers.NewRoomserverProducer(rsAPI)
|
||||
|
||||
routing.Setup(
|
||||
base.APIMux, base.Cfg, queryAPI, aliasAPI, asAPI,
|
||||
roomserverProducer, eduProducer, federationSenderAPI, *keyRing,
|
||||
base.APIMux, base.Cfg, rsAPI, asAPI, roomserverProducer,
|
||||
eduProducer, federationSenderAPI, *keyRing,
|
||||
federation, accountsDB, deviceDB,
|
||||
)
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ import (
|
||||
func Backfill(
|
||||
httpReq *http.Request,
|
||||
request *gomatrixserverlib.FederationRequest,
|
||||
query api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
roomID string,
|
||||
cfg *config.Dendrite,
|
||||
) util.JSONResponse {
|
||||
@ -82,7 +82,7 @@ func Backfill(
|
||||
}
|
||||
|
||||
// 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")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
@ -25,13 +25,13 @@ import (
|
||||
func GetEventAuth(
|
||||
ctx context.Context,
|
||||
request *gomatrixserverlib.FederationRequest,
|
||||
query api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
roomID string,
|
||||
eventID string,
|
||||
) util.JSONResponse {
|
||||
// TODO: Optimisation: we shouldn't be querying all the room state
|
||||
// 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 {
|
||||
return *err
|
||||
}
|
||||
|
@ -29,11 +29,11 @@ import (
|
||||
func GetEvent(
|
||||
ctx context.Context,
|
||||
request *gomatrixserverlib.FederationRequest,
|
||||
query api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
eventID string,
|
||||
origin gomatrixserverlib.ServerName,
|
||||
) util.JSONResponse {
|
||||
event, err := getEvent(ctx, request, query, eventID)
|
||||
event, err := getEvent(ctx, request, rsAPI, eventID)
|
||||
if err != nil {
|
||||
return *err
|
||||
}
|
||||
@ -52,11 +52,11 @@ func GetEvent(
|
||||
func getEvent(
|
||||
ctx context.Context,
|
||||
request *gomatrixserverlib.FederationRequest,
|
||||
query api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
eventID string,
|
||||
) (*gomatrixserverlib.Event, *util.JSONResponse) {
|
||||
var authResponse api.QueryServerAllowedToSeeEventResponse
|
||||
err := query.QueryServerAllowedToSeeEvent(
|
||||
err := rsAPI.QueryServerAllowedToSeeEvent(
|
||||
ctx,
|
||||
&api.QueryServerAllowedToSeeEventRequest{
|
||||
EventID: eventID,
|
||||
@ -75,7 +75,7 @@ func getEvent(
|
||||
}
|
||||
|
||||
var eventsResponse api.QueryEventsByIDResponse
|
||||
err = query.QueryEventsByID(
|
||||
err = rsAPI.QueryEventsByID(
|
||||
ctx,
|
||||
&api.QueryEventsByIDRequest{EventIDs: []string{eventID}},
|
||||
&eventsResponse,
|
||||
|
@ -33,13 +33,13 @@ func MakeJoin(
|
||||
httpReq *http.Request,
|
||||
request *gomatrixserverlib.FederationRequest,
|
||||
cfg *config.Dendrite,
|
||||
query api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
roomID, userID string,
|
||||
remoteVersions []gomatrixserverlib.RoomVersion,
|
||||
) util.JSONResponse {
|
||||
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
|
||||
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{
|
||||
Code: http.StatusInternalServerError,
|
||||
JSON: jsonerror.InternalServerError(),
|
||||
@ -97,7 +97,7 @@ func MakeJoin(
|
||||
queryRes := api.QueryLatestEventsAndStateResponse{
|
||||
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 {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusNotFound,
|
||||
@ -136,15 +136,15 @@ func SendJoin(
|
||||
httpReq *http.Request,
|
||||
request *gomatrixserverlib.FederationRequest,
|
||||
cfg *config.Dendrite,
|
||||
query api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
producer *producers.RoomserverProducer,
|
||||
keys gomatrixserverlib.KeyRing,
|
||||
roomID, eventID string,
|
||||
) util.JSONResponse {
|
||||
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
|
||||
verRes := api.QueryRoomVersionForRoomResponse{}
|
||||
if err := query.QueryRoomVersionForRoom(httpReq.Context(), &verReq, &verRes); err != nil {
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("query.QueryRoomVersionForRoom failed")
|
||||
if err := rsAPI.QueryRoomVersionForRoom(httpReq.Context(), &verReq, &verRes); err != nil {
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("rsAPI.QueryRoomVersionForRoom failed")
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusInternalServerError,
|
||||
JSON: jsonerror.InternalServerError(),
|
||||
@ -216,14 +216,14 @@ func SendJoin(
|
||||
// Fetch the state and auth chain. We do this before we send the events
|
||||
// on, in case this fails.
|
||||
var stateAndAuthChainResponse api.QueryStateAndAuthChainResponse
|
||||
err = query.QueryStateAndAuthChain(httpReq.Context(), &api.QueryStateAndAuthChainRequest{
|
||||
err = rsAPI.QueryStateAndAuthChain(httpReq.Context(), &api.QueryStateAndAuthChainRequest{
|
||||
PrevEventIDs: event.PrevEventIDs(),
|
||||
AuthEventIDs: event.AuthEventIDs(),
|
||||
RoomID: roomID,
|
||||
ResolveState: true,
|
||||
}, &stateAndAuthChainResponse)
|
||||
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()
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ func MakeLeave(
|
||||
httpReq *http.Request,
|
||||
request *gomatrixserverlib.FederationRequest,
|
||||
cfg *config.Dendrite,
|
||||
query api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
roomID, userID string,
|
||||
) util.JSONResponse {
|
||||
_, domain, err := gomatrixserverlib.SplitID('@', userID)
|
||||
@ -61,7 +61,7 @@ func MakeLeave(
|
||||
}
|
||||
|
||||
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 {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusNotFound,
|
||||
@ -102,7 +102,7 @@ func SendLeave(
|
||||
) util.JSONResponse {
|
||||
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
|
||||
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{
|
||||
Code: http.StatusBadRequest,
|
||||
JSON: jsonerror.UnsupportedRoomVersion(err.Error()),
|
||||
|
@ -34,7 +34,7 @@ type getMissingEventRequest struct {
|
||||
func GetMissingEvents(
|
||||
httpReq *http.Request,
|
||||
request *gomatrixserverlib.FederationRequest,
|
||||
query api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
roomID string,
|
||||
) util.JSONResponse {
|
||||
var gme getMissingEventRequest
|
||||
@ -46,7 +46,7 @@ func GetMissingEvents(
|
||||
}
|
||||
|
||||
var eventsResponse api.QueryMissingEventsResponse
|
||||
if err := query.QueryMissingEvents(
|
||||
if err := rsAPI.QueryMissingEvents(
|
||||
httpReq.Context(), &api.QueryMissingEventsRequest{
|
||||
EarliestEvents: gme.EarliestEvents,
|
||||
LatestEvents: gme.LatestEvents,
|
||||
|
@ -32,7 +32,7 @@ func RoomAliasToID(
|
||||
httpReq *http.Request,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
cfg *config.Dendrite,
|
||||
aliasAPI roomserverAPI.RoomserverAliasAPI,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
senderAPI federationSenderAPI.FederationSenderInternalAPI,
|
||||
) util.JSONResponse {
|
||||
roomAlias := httpReq.FormValue("room_alias")
|
||||
@ -55,7 +55,7 @@ func RoomAliasToID(
|
||||
if domain == cfg.Matrix.ServerName {
|
||||
queryReq := roomserverAPI.GetRoomIDForAliasRequest{Alias: roomAlias}
|
||||
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")
|
||||
return jsonerror.InternalServerError()
|
||||
}
|
||||
|
@ -44,8 +44,7 @@ const (
|
||||
func Setup(
|
||||
apiMux *mux.Router,
|
||||
cfg *config.Dendrite,
|
||||
query roomserverAPI.RoomserverQueryAPI,
|
||||
aliasAPI roomserverAPI.RoomserverAliasAPI,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
asAPI appserviceAPI.AppServiceQueryAPI,
|
||||
producer *producers.RoomserverProducer,
|
||||
eduProducer *producers.EDUServerProducer,
|
||||
@ -80,7 +79,7 @@ func Setup(
|
||||
}
|
||||
return Send(
|
||||
httpReq, request, gomatrixserverlib.TransactionID(vars["txnID"]),
|
||||
cfg, query, producer, eduProducer, keys, federation,
|
||||
cfg, rsAPI, producer, eduProducer, keys, federation,
|
||||
)
|
||||
},
|
||||
)).Methods(http.MethodPut, http.MethodOptions)
|
||||
@ -101,7 +100,7 @@ func Setup(
|
||||
|
||||
v1fedmux.Handle("/3pid/onbind", common.MakeExternalAPI("3pid_onbind",
|
||||
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)
|
||||
|
||||
@ -113,7 +112,7 @@ func Setup(
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return ExchangeThirdPartyInvite(
|
||||
httpReq, request, vars["roomID"], query, cfg, federation, producer,
|
||||
httpReq, request, vars["roomID"], rsAPI, cfg, federation, producer,
|
||||
)
|
||||
},
|
||||
)).Methods(http.MethodPut, http.MethodOptions)
|
||||
@ -126,7 +125,7 @@ func Setup(
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return GetEvent(
|
||||
httpReq.Context(), request, query, vars["eventID"], cfg.Matrix.ServerName,
|
||||
httpReq.Context(), request, rsAPI, vars["eventID"], cfg.Matrix.ServerName,
|
||||
)
|
||||
},
|
||||
)).Methods(http.MethodGet)
|
||||
@ -139,7 +138,7 @@ func Setup(
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return GetState(
|
||||
httpReq.Context(), request, query, vars["roomID"],
|
||||
httpReq.Context(), request, rsAPI, vars["roomID"],
|
||||
)
|
||||
},
|
||||
)).Methods(http.MethodGet)
|
||||
@ -152,7 +151,7 @@ func Setup(
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return GetStateIDs(
|
||||
httpReq.Context(), request, query, vars["roomID"],
|
||||
httpReq.Context(), request, rsAPI, vars["roomID"],
|
||||
)
|
||||
},
|
||||
)).Methods(http.MethodGet)
|
||||
@ -162,7 +161,7 @@ func Setup(
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
vars := mux.Vars(httpReq)
|
||||
return GetEventAuth(
|
||||
httpReq.Context(), request, query, vars["roomID"], vars["eventID"],
|
||||
httpReq.Context(), request, rsAPI, vars["roomID"], vars["eventID"],
|
||||
)
|
||||
},
|
||||
)).Methods(http.MethodGet)
|
||||
@ -171,7 +170,7 @@ func Setup(
|
||||
"federation_query_room_alias", cfg.Matrix.ServerName, keys,
|
||||
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest) util.JSONResponse {
|
||||
return RoomAliasToID(
|
||||
httpReq, federation, cfg, aliasAPI, federationSenderAPI,
|
||||
httpReq, federation, cfg, rsAPI, federationSenderAPI,
|
||||
)
|
||||
},
|
||||
)).Methods(http.MethodGet)
|
||||
@ -222,7 +221,7 @@ func Setup(
|
||||
remoteVersions = append(remoteVersions, gomatrixserverlib.RoomVersionV1)
|
||||
}
|
||||
return MakeJoin(
|
||||
httpReq, request, cfg, query, roomID, eventID, remoteVersions,
|
||||
httpReq, request, cfg, rsAPI, roomID, eventID, remoteVersions,
|
||||
)
|
||||
},
|
||||
)).Methods(http.MethodGet)
|
||||
@ -237,7 +236,7 @@ func Setup(
|
||||
roomID := vars["roomID"]
|
||||
eventID := vars["eventID"]
|
||||
return SendJoin(
|
||||
httpReq, request, cfg, query, producer, keys, roomID, eventID,
|
||||
httpReq, request, cfg, rsAPI, producer, keys, roomID, eventID,
|
||||
)
|
||||
},
|
||||
)).Methods(http.MethodPut)
|
||||
@ -252,7 +251,7 @@ func Setup(
|
||||
roomID := vars["roomID"]
|
||||
eventID := vars["eventID"]
|
||||
return MakeLeave(
|
||||
httpReq, request, cfg, query, roomID, eventID,
|
||||
httpReq, request, cfg, rsAPI, roomID, eventID,
|
||||
)
|
||||
},
|
||||
)).Methods(http.MethodGet)
|
||||
@ -286,7 +285,7 @@ func Setup(
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return GetMissingEvents(httpReq, request, query, vars["roomID"])
|
||||
return GetMissingEvents(httpReq, request, rsAPI, vars["roomID"])
|
||||
},
|
||||
)).Methods(http.MethodPost)
|
||||
|
||||
@ -297,7 +296,7 @@ func Setup(
|
||||
if err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return Backfill(httpReq, request, query, vars["roomID"], cfg)
|
||||
return Backfill(httpReq, request, rsAPI, vars["roomID"], cfg)
|
||||
},
|
||||
)).Methods(http.MethodGet)
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ func Send(
|
||||
request *gomatrixserverlib.FederationRequest,
|
||||
txnID gomatrixserverlib.TransactionID,
|
||||
cfg *config.Dendrite,
|
||||
query api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
producer *producers.RoomserverProducer,
|
||||
eduProducer *producers.EDUServerProducer,
|
||||
keys gomatrixserverlib.KeyRing,
|
||||
@ -42,7 +42,7 @@ func Send(
|
||||
) util.JSONResponse {
|
||||
t := txnReq{
|
||||
context: httpReq.Context(),
|
||||
query: query,
|
||||
rsAPI: rsAPI,
|
||||
producer: producer,
|
||||
eduProducer: eduProducer,
|
||||
keys: keys,
|
||||
@ -99,7 +99,7 @@ func Send(
|
||||
type txnReq struct {
|
||||
gomatrixserverlib.Transaction
|
||||
context context.Context
|
||||
query api.RoomserverQueryAPI
|
||||
rsAPI api.RoomserverInternalAPI
|
||||
producer *producers.RoomserverProducer
|
||||
eduProducer *producers.EDUServerProducer
|
||||
keys gomatrixserverlib.KeyRing
|
||||
@ -120,7 +120,7 @@ func (t *txnReq) processTransaction() (*gomatrixserverlib.RespSend, error) {
|
||||
}
|
||||
verReq := api.QueryRoomVersionForRoomRequest{RoomID: header.RoomID}
|
||||
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)
|
||||
return nil, roomNotFoundError{verReq.RoomID}
|
||||
}
|
||||
@ -228,7 +228,7 @@ func (t *txnReq) processEvent(e gomatrixserverlib.Event) error {
|
||||
StateToFetch: needed.Tuples(),
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ import (
|
||||
func GetState(
|
||||
ctx context.Context,
|
||||
request *gomatrixserverlib.FederationRequest,
|
||||
query api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
roomID string,
|
||||
) util.JSONResponse {
|
||||
eventID, err := parseEventIDParam(request)
|
||||
@ -35,7 +35,7 @@ func GetState(
|
||||
return *err
|
||||
}
|
||||
|
||||
state, err := getState(ctx, request, query, roomID, eventID)
|
||||
state, err := getState(ctx, request, rsAPI, roomID, eventID)
|
||||
if err != nil {
|
||||
return *err
|
||||
}
|
||||
@ -47,7 +47,7 @@ func GetState(
|
||||
func GetStateIDs(
|
||||
ctx context.Context,
|
||||
request *gomatrixserverlib.FederationRequest,
|
||||
query api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
roomID string,
|
||||
) util.JSONResponse {
|
||||
eventID, err := parseEventIDParam(request)
|
||||
@ -55,7 +55,7 @@ func GetStateIDs(
|
||||
return *err
|
||||
}
|
||||
|
||||
state, err := getState(ctx, request, query, roomID, eventID)
|
||||
state, err := getState(ctx, request, rsAPI, roomID, eventID)
|
||||
if err != nil {
|
||||
return *err
|
||||
}
|
||||
@ -94,11 +94,11 @@ func parseEventIDParam(
|
||||
func getState(
|
||||
ctx context.Context,
|
||||
request *gomatrixserverlib.FederationRequest,
|
||||
query api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
roomID string,
|
||||
eventID string,
|
||||
) (*gomatrixserverlib.RespState, *util.JSONResponse) {
|
||||
event, resErr := getEvent(ctx, request, query, eventID)
|
||||
event, resErr := getEvent(ctx, request, rsAPI, eventID)
|
||||
if resErr != nil {
|
||||
return nil, resErr
|
||||
}
|
||||
@ -110,7 +110,7 @@ func getState(
|
||||
authEventIDs := getIDsFromEventRef(event.AuthEvents())
|
||||
|
||||
var response api.QueryStateAndAuthChainResponse
|
||||
err := query.QueryStateAndAuthChain(
|
||||
err := rsAPI.QueryStateAndAuthChain(
|
||||
ctx,
|
||||
&api.QueryStateAndAuthChainRequest{
|
||||
RoomID: roomID,
|
||||
|
@ -58,7 +58,7 @@ var (
|
||||
|
||||
// CreateInvitesFrom3PIDInvites implements POST /_matrix/federation/v1/3pid/onbind
|
||||
func CreateInvitesFrom3PIDInvites(
|
||||
req *http.Request, queryAPI roomserverAPI.RoomserverQueryAPI,
|
||||
req *http.Request, rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
asAPI appserviceAPI.AppServiceQueryAPI, cfg *config.Dendrite,
|
||||
producer *producers.RoomserverProducer, federation *gomatrixserverlib.FederationClient,
|
||||
accountDB accounts.Database,
|
||||
@ -72,7 +72,7 @@ func CreateInvitesFrom3PIDInvites(
|
||||
for _, inv := range body.Invites {
|
||||
verReq := api.QueryRoomVersionForRoomRequest{RoomID: inv.RoomID}
|
||||
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{
|
||||
Code: http.StatusBadRequest,
|
||||
JSON: jsonerror.UnsupportedRoomVersion(err.Error()),
|
||||
@ -80,7 +80,7 @@ func CreateInvitesFrom3PIDInvites(
|
||||
}
|
||||
|
||||
event, err := createInviteFrom3PIDInvite(
|
||||
req.Context(), queryAPI, asAPI, cfg, inv, federation, accountDB,
|
||||
req.Context(), rsAPI, asAPI, cfg, inv, federation, accountDB,
|
||||
)
|
||||
if err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("createInviteFrom3PIDInvite failed")
|
||||
@ -108,7 +108,7 @@ func ExchangeThirdPartyInvite(
|
||||
httpReq *http.Request,
|
||||
request *gomatrixserverlib.FederationRequest,
|
||||
roomID string,
|
||||
queryAPI roomserverAPI.RoomserverQueryAPI,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
cfg *config.Dendrite,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
producer *producers.RoomserverProducer,
|
||||
@ -148,7 +148,7 @@ func ExchangeThirdPartyInvite(
|
||||
|
||||
verReq := api.QueryRoomVersionForRoomRequest{RoomID: roomID}
|
||||
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{
|
||||
Code: http.StatusBadRequest,
|
||||
JSON: jsonerror.UnsupportedRoomVersion(err.Error()),
|
||||
@ -156,7 +156,7 @@ func ExchangeThirdPartyInvite(
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return util.JSONResponse{
|
||||
Code: http.StatusNotFound,
|
||||
@ -199,14 +199,14 @@ func ExchangeThirdPartyInvite(
|
||||
// Returns an error if there was a problem building the event or fetching the
|
||||
// necessary data to do so.
|
||||
func createInviteFrom3PIDInvite(
|
||||
ctx context.Context, queryAPI roomserverAPI.RoomserverQueryAPI,
|
||||
ctx context.Context, rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
asAPI appserviceAPI.AppServiceQueryAPI, cfg *config.Dendrite,
|
||||
inv invite, federation *gomatrixserverlib.FederationClient,
|
||||
accountDB accounts.Database,
|
||||
) (*gomatrixserverlib.Event, error) {
|
||||
verReq := api.QueryRoomVersionForRoomRequest{RoomID: inv.RoomID}
|
||||
verRes := api.QueryRoomVersionForRoomResponse{}
|
||||
if err := queryAPI.QueryRoomVersionForRoom(ctx, &verReq, &verRes); err != nil {
|
||||
if err := rsAPI.QueryRoomVersionForRoom(ctx, &verReq, &verRes); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -245,7 +245,7 @@ func createInviteFrom3PIDInvite(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
event, err := buildMembershipEvent(ctx, builder, queryAPI, cfg)
|
||||
event, err := buildMembershipEvent(ctx, builder, rsAPI, cfg)
|
||||
if err == errNotInRoom {
|
||||
return nil, sendToRemoteServer(ctx, inv, federation, cfg, *builder)
|
||||
}
|
||||
@ -263,7 +263,7 @@ func createInviteFrom3PIDInvite(
|
||||
// Returns an error if something failed during the process.
|
||||
func buildMembershipEvent(
|
||||
ctx context.Context,
|
||||
builder *gomatrixserverlib.EventBuilder, queryAPI roomserverAPI.RoomserverQueryAPI,
|
||||
builder *gomatrixserverlib.EventBuilder, rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
cfg *config.Dendrite,
|
||||
) (*gomatrixserverlib.Event, error) {
|
||||
eventsNeeded, err := gomatrixserverlib.StateNeededForEventBuilder(builder)
|
||||
@ -281,7 +281,7 @@ func buildMembershipEvent(
|
||||
StateToFetch: eventsNeeded.Tuples(),
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -33,11 +33,11 @@ import (
|
||||
|
||||
// OutputRoomEventConsumer consumes events that originated in the room server.
|
||||
type OutputRoomEventConsumer struct {
|
||||
cfg *config.Dendrite
|
||||
roomServerConsumer *common.ContinualConsumer
|
||||
db storage.Database
|
||||
queues *queue.OutgoingQueues
|
||||
query api.RoomserverQueryAPI
|
||||
cfg *config.Dendrite
|
||||
rsAPI api.RoomserverInternalAPI
|
||||
rsConsumer *common.ContinualConsumer
|
||||
db storage.Database
|
||||
queues *queue.OutgoingQueues
|
||||
}
|
||||
|
||||
// NewOutputRoomEventConsumer creates a new OutputRoomEventConsumer. Call Start() to begin consuming from room servers.
|
||||
@ -46,7 +46,7 @@ func NewOutputRoomEventConsumer(
|
||||
kafkaConsumer sarama.Consumer,
|
||||
queues *queue.OutgoingQueues,
|
||||
store storage.Database,
|
||||
queryAPI api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
) *OutputRoomEventConsumer {
|
||||
consumer := common.ContinualConsumer{
|
||||
Topic: string(cfg.Kafka.Topics.OutputRoomEvent),
|
||||
@ -54,11 +54,11 @@ func NewOutputRoomEventConsumer(
|
||||
PartitionStore: store,
|
||||
}
|
||||
s := &OutputRoomEventConsumer{
|
||||
cfg: cfg,
|
||||
roomServerConsumer: &consumer,
|
||||
db: store,
|
||||
queues: queues,
|
||||
query: queryAPI,
|
||||
cfg: cfg,
|
||||
rsConsumer: &consumer,
|
||||
db: store,
|
||||
queues: queues,
|
||||
rsAPI: rsAPI,
|
||||
}
|
||||
consumer.ProcessMessage = s.onMessage
|
||||
|
||||
@ -67,7 +67,7 @@ func NewOutputRoomEventConsumer(
|
||||
|
||||
// Start consuming from room servers
|
||||
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.
|
||||
@ -369,7 +369,7 @@ func (s *OutputRoomEventConsumer) lookupStateEvents(
|
||||
// from the roomserver using the query API.
|
||||
eventReq := api.QueryEventsByIDRequest{EventIDs: missing}
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -34,8 +34,7 @@ import (
|
||||
func SetupFederationSenderComponent(
|
||||
base *basecomponent.BaseDendrite,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
rsQueryAPI roomserverAPI.RoomserverQueryAPI,
|
||||
rsInputAPI roomserverAPI.RoomserverInputAPI,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
keyRing *gomatrixserverlib.KeyRing,
|
||||
) api.FederationSenderInternalAPI {
|
||||
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")
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
rsConsumer := consumers.NewOutputRoomEventConsumer(
|
||||
base.Cfg, base.KafkaConsumer, queues,
|
||||
federationSenderDB, rsQueryAPI,
|
||||
federationSenderDB, rsAPI,
|
||||
)
|
||||
if err = rsConsumer.Start(); err != nil {
|
||||
logrus.WithError(err).Panic("failed to start room server consumer")
|
||||
|
@ -23,16 +23,16 @@ import (
|
||||
|
||||
// RoomserverProducer produces events for the roomserver to consume.
|
||||
type RoomserverProducer struct {
|
||||
InputAPI api.RoomserverInputAPI
|
||||
InputAPI api.RoomserverInternalAPI
|
||||
serverName gomatrixserverlib.ServerName
|
||||
}
|
||||
|
||||
// NewRoomserverProducer creates a new RoomserverProducer
|
||||
func NewRoomserverProducer(
|
||||
inputAPI api.RoomserverInputAPI, serverName gomatrixserverlib.ServerName,
|
||||
rsAPI api.RoomserverInternalAPI, serverName gomatrixserverlib.ServerName,
|
||||
) *RoomserverProducer {
|
||||
return &RoomserverProducer{
|
||||
InputAPI: inputAPI,
|
||||
InputAPI: rsAPI,
|
||||
serverName: serverName,
|
||||
}
|
||||
}
|
||||
|
@ -29,9 +29,9 @@ import (
|
||||
|
||||
// OutputRoomEventConsumer consumes events that originated in the room server.
|
||||
type OutputRoomEventConsumer struct {
|
||||
roomServerConsumer *common.ContinualConsumer
|
||||
db storage.Database
|
||||
query api.RoomserverQueryAPI
|
||||
rsAPI api.RoomserverInternalAPI
|
||||
rsConsumer *common.ContinualConsumer
|
||||
db storage.Database
|
||||
}
|
||||
|
||||
// NewOutputRoomEventConsumer creates a new OutputRoomEventConsumer. Call Start() to begin consuming from room servers.
|
||||
@ -39,7 +39,7 @@ func NewOutputRoomEventConsumer(
|
||||
cfg *config.Dendrite,
|
||||
kafkaConsumer sarama.Consumer,
|
||||
store storage.Database,
|
||||
queryAPI api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
) *OutputRoomEventConsumer {
|
||||
consumer := common.ContinualConsumer{
|
||||
Topic: string(cfg.Kafka.Topics.OutputRoomEvent),
|
||||
@ -47,9 +47,9 @@ func NewOutputRoomEventConsumer(
|
||||
PartitionStore: store,
|
||||
}
|
||||
s := &OutputRoomEventConsumer{
|
||||
roomServerConsumer: &consumer,
|
||||
db: store,
|
||||
query: queryAPI,
|
||||
rsConsumer: &consumer,
|
||||
db: store,
|
||||
rsAPI: rsAPI,
|
||||
}
|
||||
consumer.ProcessMessage = s.onMessage
|
||||
|
||||
@ -58,7 +58,7 @@ func NewOutputRoomEventConsumer(
|
||||
|
||||
// Start consuming from room servers
|
||||
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.
|
||||
@ -87,14 +87,14 @@ func (s *OutputRoomEventConsumer) onMessage(msg *sarama.ConsumerMessage) error {
|
||||
|
||||
addQueryReq := api.QueryEventsByIDRequest{EventIDs: output.NewRoomEvent.AddsStateEventIDs}
|
||||
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)
|
||||
return err
|
||||
}
|
||||
|
||||
remQueryReq := api.QueryEventsByIDRequest{EventIDs: output.NewRoomEvent.RemovesStateEventIDs}
|
||||
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)
|
||||
return err
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ func GetVisibility(
|
||||
// SetVisibility implements PUT /directory/list/room/{roomID}
|
||||
// TODO: Allow admin users to edit the room visibility
|
||||
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,
|
||||
) util.JSONResponse {
|
||||
queryMembershipReq := api.QueryMembershipForUserRequest{
|
||||
@ -67,7 +67,7 @@ func SetVisibility(
|
||||
UserID: dev.UserID,
|
||||
}
|
||||
var queryMembershipRes api.QueryMembershipForUserResponse
|
||||
err := queryAPI.QueryMembershipForUser(req.Context(), &queryMembershipReq, &queryMembershipRes)
|
||||
err := rsAPI.QueryMembershipForUser(req.Context(), &queryMembershipReq, &queryMembershipRes)
|
||||
if err != nil {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("could not query membership for user")
|
||||
return jsonerror.InternalServerError()
|
||||
@ -87,7 +87,7 @@ func SetVisibility(
|
||||
}},
|
||||
}
|
||||
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 {
|
||||
util.GetLogger(req.Context()).WithError(err).Error("could not query events from room")
|
||||
return jsonerror.InternalServerError()
|
||||
|
@ -32,16 +32,16 @@ func SetupPublicRoomsAPIComponent(
|
||||
base *basecomponent.BaseDendrite,
|
||||
deviceDB devices.Database,
|
||||
publicRoomsDB storage.Database,
|
||||
rsQueryAPI roomserverAPI.RoomserverQueryAPI,
|
||||
rsAPI roomserverAPI.RoomserverInternalAPI,
|
||||
fedClient *gomatrixserverlib.FederationClient,
|
||||
extRoomsProvider types.ExternalPublicRoomsProvider,
|
||||
) {
|
||||
rsConsumer := consumers.NewOutputRoomEventConsumer(
|
||||
base.Cfg, base.KafkaConsumer, publicRoomsDB, rsQueryAPI,
|
||||
base.Cfg, base.KafkaConsumer, publicRoomsDB, rsAPI,
|
||||
)
|
||||
if err := rsConsumer.Start(); err != nil {
|
||||
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)
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ const pathPrefixR0 = "/_matrix/client/r0"
|
||||
// applied:
|
||||
// nolint: gocyclo
|
||||
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,
|
||||
) {
|
||||
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter()
|
||||
@ -66,7 +66,7 @@ func Setup(
|
||||
if err != nil {
|
||||
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)
|
||||
r0mux.Handle("/publicRooms",
|
||||
|
@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
@ -16,8 +16,6 @@ package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
commonHTTP "github.com/matrix-org/dendrite/common/http"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
@ -86,44 +84,6 @@ type RemoveRoomAliasRequest struct {
|
||||
// RemoveRoomAliasResponse is a response to RemoveRoomAlias
|
||||
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.
|
||||
const RoomserverSetRoomAliasPath = "/api/roomserver/setRoomAlias"
|
||||
|
||||
@ -139,22 +99,8 @@ const RoomserverGetCreatorIDForAliasPath = "/api/roomserver/GetCreatorIDForAlias
|
||||
// RoomserverRemoveRoomAliasPath is the HTTP path for the RemoveRoomAlias API.
|
||||
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
|
||||
func (h *httpRoomserverAliasAPI) SetRoomAlias(
|
||||
func (h *httpRoomserverInternalAPI) SetRoomAlias(
|
||||
ctx context.Context,
|
||||
request *SetRoomAliasRequest,
|
||||
response *SetRoomAliasResponse,
|
||||
@ -167,7 +113,7 @@ func (h *httpRoomserverAliasAPI) SetRoomAlias(
|
||||
}
|
||||
|
||||
// GetRoomIDForAlias implements RoomserverAliasAPI
|
||||
func (h *httpRoomserverAliasAPI) GetRoomIDForAlias(
|
||||
func (h *httpRoomserverInternalAPI) GetRoomIDForAlias(
|
||||
ctx context.Context,
|
||||
request *GetRoomIDForAliasRequest,
|
||||
response *GetRoomIDForAliasResponse,
|
||||
@ -180,7 +126,7 @@ func (h *httpRoomserverAliasAPI) GetRoomIDForAlias(
|
||||
}
|
||||
|
||||
// GetAliasesForRoomID implements RoomserverAliasAPI
|
||||
func (h *httpRoomserverAliasAPI) GetAliasesForRoomID(
|
||||
func (h *httpRoomserverInternalAPI) GetAliasesForRoomID(
|
||||
ctx context.Context,
|
||||
request *GetAliasesForRoomIDRequest,
|
||||
response *GetAliasesForRoomIDResponse,
|
||||
@ -193,7 +139,7 @@ func (h *httpRoomserverAliasAPI) GetAliasesForRoomID(
|
||||
}
|
||||
|
||||
// GetCreatorIDForAlias implements RoomserverAliasAPI
|
||||
func (h *httpRoomserverAliasAPI) GetCreatorIDForAlias(
|
||||
func (h *httpRoomserverInternalAPI) GetCreatorIDForAlias(
|
||||
ctx context.Context,
|
||||
request *GetCreatorIDForAliasRequest,
|
||||
response *GetCreatorIDForAliasResponse,
|
||||
@ -206,7 +152,7 @@ func (h *httpRoomserverAliasAPI) GetCreatorIDForAlias(
|
||||
}
|
||||
|
||||
// RemoveRoomAlias implements RoomserverAliasAPI
|
||||
func (h *httpRoomserverAliasAPI) RemoveRoomAlias(
|
||||
func (h *httpRoomserverInternalAPI) RemoveRoomAlias(
|
||||
ctx context.Context,
|
||||
request *RemoveRoomAliasRequest,
|
||||
response *RemoveRoomAliasResponse,
|
||||
|
141
roomserver/api/api.go
Normal file
141
roomserver/api/api.go
Normal 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
41
roomserver/api/http.go
Normal 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
|
||||
}
|
@ -17,11 +17,8 @@ package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
commonHTTP "github.com/matrix-org/dendrite/common/http"
|
||||
fsAPI "github.com/matrix-org/dendrite/federationsender/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
)
|
||||
@ -105,47 +102,11 @@ type InputRoomEventsResponse struct {
|
||||
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.
|
||||
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
|
||||
func (h *httpRoomserverInputAPI) InputRoomEvents(
|
||||
func (h *httpRoomserverInternalAPI) InputRoomEvents(
|
||||
ctx context.Context,
|
||||
request *InputRoomEventsRequest,
|
||||
response *InputRoomEventsResponse,
|
||||
|
@ -18,10 +18,7 @@ package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/matrix-org/dendrite/common/caching"
|
||||
commonHTTP "github.com/matrix-org/dendrite/common/http"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
opentracing "github.com/opentracing/opentracing-go"
|
||||
@ -264,95 +261,6 @@ type QueryRoomVersionForRoomResponse struct {
|
||||
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.
|
||||
const RoomserverQueryLatestEventsAndStatePath = "/api/roomserver/queryLatestEventsAndState"
|
||||
|
||||
@ -389,23 +297,8 @@ const RoomserverQueryRoomVersionCapabilitiesPath = "/api/roomserver/queryRoomVer
|
||||
// RoomserverQueryRoomVersionForRoomPath is the HTTP path for the QueryRoomVersionForRoom API
|
||||
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
|
||||
func (h *httpRoomserverQueryAPI) QueryLatestEventsAndState(
|
||||
func (h *httpRoomserverInternalAPI) QueryLatestEventsAndState(
|
||||
ctx context.Context,
|
||||
request *QueryLatestEventsAndStateRequest,
|
||||
response *QueryLatestEventsAndStateResponse,
|
||||
@ -418,7 +311,7 @@ func (h *httpRoomserverQueryAPI) QueryLatestEventsAndState(
|
||||
}
|
||||
|
||||
// QueryStateAfterEvents implements RoomserverQueryAPI
|
||||
func (h *httpRoomserverQueryAPI) QueryStateAfterEvents(
|
||||
func (h *httpRoomserverInternalAPI) QueryStateAfterEvents(
|
||||
ctx context.Context,
|
||||
request *QueryStateAfterEventsRequest,
|
||||
response *QueryStateAfterEventsResponse,
|
||||
@ -431,7 +324,7 @@ func (h *httpRoomserverQueryAPI) QueryStateAfterEvents(
|
||||
}
|
||||
|
||||
// QueryEventsByID implements RoomserverQueryAPI
|
||||
func (h *httpRoomserverQueryAPI) QueryEventsByID(
|
||||
func (h *httpRoomserverInternalAPI) QueryEventsByID(
|
||||
ctx context.Context,
|
||||
request *QueryEventsByIDRequest,
|
||||
response *QueryEventsByIDResponse,
|
||||
@ -444,7 +337,7 @@ func (h *httpRoomserverQueryAPI) QueryEventsByID(
|
||||
}
|
||||
|
||||
// QueryMembershipForUser implements RoomserverQueryAPI
|
||||
func (h *httpRoomserverQueryAPI) QueryMembershipForUser(
|
||||
func (h *httpRoomserverInternalAPI) QueryMembershipForUser(
|
||||
ctx context.Context,
|
||||
request *QueryMembershipForUserRequest,
|
||||
response *QueryMembershipForUserResponse,
|
||||
@ -457,7 +350,7 @@ func (h *httpRoomserverQueryAPI) QueryMembershipForUser(
|
||||
}
|
||||
|
||||
// QueryMembershipsForRoom implements RoomserverQueryAPI
|
||||
func (h *httpRoomserverQueryAPI) QueryMembershipsForRoom(
|
||||
func (h *httpRoomserverInternalAPI) QueryMembershipsForRoom(
|
||||
ctx context.Context,
|
||||
request *QueryMembershipsForRoomRequest,
|
||||
response *QueryMembershipsForRoomResponse,
|
||||
@ -470,7 +363,7 @@ func (h *httpRoomserverQueryAPI) QueryMembershipsForRoom(
|
||||
}
|
||||
|
||||
// QueryInvitesForUser implements RoomserverQueryAPI
|
||||
func (h *httpRoomserverQueryAPI) QueryInvitesForUser(
|
||||
func (h *httpRoomserverInternalAPI) QueryInvitesForUser(
|
||||
ctx context.Context,
|
||||
request *QueryInvitesForUserRequest,
|
||||
response *QueryInvitesForUserResponse,
|
||||
@ -483,7 +376,7 @@ func (h *httpRoomserverQueryAPI) QueryInvitesForUser(
|
||||
}
|
||||
|
||||
// QueryServerAllowedToSeeEvent implements RoomserverQueryAPI
|
||||
func (h *httpRoomserverQueryAPI) QueryServerAllowedToSeeEvent(
|
||||
func (h *httpRoomserverInternalAPI) QueryServerAllowedToSeeEvent(
|
||||
ctx context.Context,
|
||||
request *QueryServerAllowedToSeeEventRequest,
|
||||
response *QueryServerAllowedToSeeEventResponse,
|
||||
@ -496,7 +389,7 @@ func (h *httpRoomserverQueryAPI) QueryServerAllowedToSeeEvent(
|
||||
}
|
||||
|
||||
// QueryMissingEvents implements RoomServerQueryAPI
|
||||
func (h *httpRoomserverQueryAPI) QueryMissingEvents(
|
||||
func (h *httpRoomserverInternalAPI) QueryMissingEvents(
|
||||
ctx context.Context,
|
||||
request *QueryMissingEventsRequest,
|
||||
response *QueryMissingEventsResponse,
|
||||
@ -509,7 +402,7 @@ func (h *httpRoomserverQueryAPI) QueryMissingEvents(
|
||||
}
|
||||
|
||||
// QueryStateAndAuthChain implements RoomserverQueryAPI
|
||||
func (h *httpRoomserverQueryAPI) QueryStateAndAuthChain(
|
||||
func (h *httpRoomserverInternalAPI) QueryStateAndAuthChain(
|
||||
ctx context.Context,
|
||||
request *QueryStateAndAuthChainRequest,
|
||||
response *QueryStateAndAuthChainResponse,
|
||||
@ -522,7 +415,7 @@ func (h *httpRoomserverQueryAPI) QueryStateAndAuthChain(
|
||||
}
|
||||
|
||||
// QueryBackfill implements RoomServerQueryAPI
|
||||
func (h *httpRoomserverQueryAPI) QueryBackfill(
|
||||
func (h *httpRoomserverInternalAPI) QueryBackfill(
|
||||
ctx context.Context,
|
||||
request *QueryBackfillRequest,
|
||||
response *QueryBackfillResponse,
|
||||
@ -535,7 +428,7 @@ func (h *httpRoomserverQueryAPI) QueryBackfill(
|
||||
}
|
||||
|
||||
// QueryRoomVersionCapabilities implements RoomServerQueryAPI
|
||||
func (h *httpRoomserverQueryAPI) QueryRoomVersionCapabilities(
|
||||
func (h *httpRoomserverInternalAPI) QueryRoomVersionCapabilities(
|
||||
ctx context.Context,
|
||||
request *QueryRoomVersionCapabilitiesRequest,
|
||||
response *QueryRoomVersionCapabilitiesResponse,
|
||||
@ -548,7 +441,7 @@ func (h *httpRoomserverQueryAPI) QueryRoomVersionCapabilities(
|
||||
}
|
||||
|
||||
// QueryRoomVersionForRoom implements RoomServerQueryAPI
|
||||
func (h *httpRoomserverQueryAPI) QueryRoomVersionForRoom(
|
||||
func (h *httpRoomserverInternalAPI) QueryRoomVersionForRoom(
|
||||
ctx context.Context,
|
||||
request *QueryRoomVersionForRoomRequest,
|
||||
response *QueryRoomVersionForRoomResponse,
|
||||
|
@ -12,25 +12,20 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package alias
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
appserviceAPI "github.com/matrix-org/dendrite/appservice/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/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
// RoomserverAliasAPIDatabase has the storage APIs needed to implement the alias API.
|
||||
type RoomserverAliasAPIDatabase interface {
|
||||
// RoomserverInternalAPIDatabase has the storage APIs needed to implement the alias API.
|
||||
type RoomserverInternalAPIDatabase interface {
|
||||
// Save a given room alias with the room ID it refers to.
|
||||
// Returns an error if there was a problem talking to the database.
|
||||
SetRoomAlias(ctx context.Context, alias string, roomID string, creatorUserID string) error
|
||||
@ -52,20 +47,11 @@ type RoomserverAliasAPIDatabase interface {
|
||||
) (gomatrixserverlib.RoomVersion, error)
|
||||
}
|
||||
|
||||
// RoomserverAliasAPI is an implementation of alias.RoomserverAliasAPI
|
||||
type RoomserverAliasAPI struct {
|
||||
DB RoomserverAliasAPIDatabase
|
||||
Cfg *config.Dendrite
|
||||
InputAPI roomserverAPI.RoomserverInputAPI
|
||||
QueryAPI roomserverAPI.RoomserverQueryAPI
|
||||
AppserviceAPI appserviceAPI.AppServiceQueryAPI
|
||||
}
|
||||
|
||||
// SetRoomAlias implements alias.RoomserverAliasAPI
|
||||
func (r *RoomserverAliasAPI) SetRoomAlias(
|
||||
// SetRoomAlias implements alias.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) SetRoomAlias(
|
||||
ctx context.Context,
|
||||
request *roomserverAPI.SetRoomAliasRequest,
|
||||
response *roomserverAPI.SetRoomAliasResponse,
|
||||
request *api.SetRoomAliasRequest,
|
||||
response *api.SetRoomAliasResponse,
|
||||
) error {
|
||||
// Check if the alias isn't already referring to a room
|
||||
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)
|
||||
}
|
||||
|
||||
// GetRoomIDForAlias implements alias.RoomserverAliasAPI
|
||||
func (r *RoomserverAliasAPI) GetRoomIDForAlias(
|
||||
// GetRoomIDForAlias implements alias.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) GetRoomIDForAlias(
|
||||
ctx context.Context,
|
||||
request *roomserverAPI.GetRoomIDForAliasRequest,
|
||||
response *roomserverAPI.GetRoomIDForAliasResponse,
|
||||
request *api.GetRoomIDForAliasRequest,
|
||||
response *api.GetRoomIDForAliasResponse,
|
||||
) error {
|
||||
// Look up the room ID in the database
|
||||
roomID, err := r.DB.GetRoomIDForAlias(ctx, request.Alias)
|
||||
@ -103,32 +89,38 @@ func (r *RoomserverAliasAPI) GetRoomIDForAlias(
|
||||
return err
|
||||
}
|
||||
|
||||
if roomID == "" {
|
||||
// No room found locally, try our application services by making a call to
|
||||
// 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
|
||||
}
|
||||
/*
|
||||
TODO: Why is this here? It creates an unnecessary dependency
|
||||
from the roomserver to the appservice component, which should be
|
||||
altogether optional.
|
||||
|
||||
if aliasResp.AliasExists {
|
||||
roomID, err = r.DB.GetRoomIDForAlias(ctx, request.Alias)
|
||||
if err != nil {
|
||||
if roomID == "" {
|
||||
// No room found locally, try our application services by making a call to
|
||||
// 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
|
||||
}
|
||||
|
||||
if aliasResp.AliasExists {
|
||||
roomID, err = r.DB.GetRoomIDForAlias(ctx, request.Alias)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
response.RoomID = roomID
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetAliasesForRoomID implements alias.RoomserverAliasAPI
|
||||
func (r *RoomserverAliasAPI) GetAliasesForRoomID(
|
||||
// GetAliasesForRoomID implements alias.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) GetAliasesForRoomID(
|
||||
ctx context.Context,
|
||||
request *roomserverAPI.GetAliasesForRoomIDRequest,
|
||||
response *roomserverAPI.GetAliasesForRoomIDResponse,
|
||||
request *api.GetAliasesForRoomIDRequest,
|
||||
response *api.GetAliasesForRoomIDResponse,
|
||||
) error {
|
||||
// Look up the aliases in the database for the given RoomID
|
||||
aliases, err := r.DB.GetAliasesForRoomID(ctx, request.RoomID)
|
||||
@ -140,11 +132,11 @@ func (r *RoomserverAliasAPI) GetAliasesForRoomID(
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetCreatorIDForAlias implements alias.RoomserverAliasAPI
|
||||
func (r *RoomserverAliasAPI) GetCreatorIDForAlias(
|
||||
// GetCreatorIDForAlias implements alias.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) GetCreatorIDForAlias(
|
||||
ctx context.Context,
|
||||
request *roomserverAPI.GetCreatorIDForAliasRequest,
|
||||
response *roomserverAPI.GetCreatorIDForAliasResponse,
|
||||
request *api.GetCreatorIDForAliasRequest,
|
||||
response *api.GetCreatorIDForAliasResponse,
|
||||
) error {
|
||||
// Look up the aliases in the database for the given RoomID
|
||||
creatorID, err := r.DB.GetCreatorIDForAlias(ctx, request.Alias)
|
||||
@ -156,11 +148,11 @@ func (r *RoomserverAliasAPI) GetCreatorIDForAlias(
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveRoomAlias implements alias.RoomserverAliasAPI
|
||||
func (r *RoomserverAliasAPI) RemoveRoomAlias(
|
||||
// RemoveRoomAlias implements alias.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) RemoveRoomAlias(
|
||||
ctx context.Context,
|
||||
request *roomserverAPI.RemoveRoomAliasRequest,
|
||||
response *roomserverAPI.RemoveRoomAliasResponse,
|
||||
request *api.RemoveRoomAliasRequest,
|
||||
response *api.RemoveRoomAliasResponse,
|
||||
) error {
|
||||
// Look up the room ID in the database
|
||||
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
|
||||
// removal of an alias
|
||||
func (r *RoomserverAliasAPI) sendUpdatedAliasesEvent(
|
||||
func (r *RoomserverInternalAPI) sendUpdatedAliasesEvent(
|
||||
ctx context.Context, userID string, roomID string,
|
||||
) error {
|
||||
serverName := string(r.Cfg.Matrix.ServerName)
|
||||
@ -222,12 +214,12 @@ func (r *RoomserverAliasAPI) sendUpdatedAliasesEvent(
|
||||
if len(eventsNeeded.Tuples()) == 0 {
|
||||
return errors.New("expecting state tuples for event builder, got none")
|
||||
}
|
||||
req := roomserverAPI.QueryLatestEventsAndStateRequest{
|
||||
req := api.QueryLatestEventsAndStateRequest{
|
||||
RoomID: roomID,
|
||||
StateToFetch: eventsNeeded.Tuples(),
|
||||
}
|
||||
var res roomserverAPI.QueryLatestEventsAndStateResponse
|
||||
if err = r.QueryAPI.QueryLatestEventsAndState(ctx, &req, &res); err != nil {
|
||||
var res api.QueryLatestEventsAndStateResponse
|
||||
if err = r.QueryLatestEventsAndState(ctx, &req, &res); err != nil {
|
||||
return err
|
||||
}
|
||||
builder.Depth = res.Depth
|
||||
@ -263,91 +255,17 @@ func (r *RoomserverAliasAPI) sendUpdatedAliasesEvent(
|
||||
}
|
||||
|
||||
// Create the request
|
||||
ire := roomserverAPI.InputRoomEvent{
|
||||
Kind: roomserverAPI.KindNew,
|
||||
ire := api.InputRoomEvent{
|
||||
Kind: api.KindNew,
|
||||
Event: event.Headered(roomVersion),
|
||||
AuthEventIDs: event.AuthEventIDs(),
|
||||
SendAsServer: serverName,
|
||||
}
|
||||
inputReq := roomserverAPI.InputRoomEventsRequest{
|
||||
InputRoomEvents: []roomserverAPI.InputRoomEvent{ire},
|
||||
inputReq := api.InputRoomEventsRequest{
|
||||
InputRoomEvents: []api.InputRoomEvent{ire},
|
||||
}
|
||||
var inputRes roomserverAPI.InputRoomEventsResponse
|
||||
var inputRes api.InputRoomEventsResponse
|
||||
|
||||
// Send the request
|
||||
return r.InputAPI.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}
|
||||
}),
|
||||
)
|
||||
return r.InputRoomEvents(ctx, &inputReq, &inputRes)
|
||||
}
|
287
roomserver/internal/api.go
Normal file
287
roomserver/internal/api.go
Normal 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}
|
||||
}),
|
||||
)
|
||||
}
|
@ -13,46 +13,27 @@
|
||||
// limitations under the License.
|
||||
|
||||
// Package input contains the code processes new room events
|
||||
package input
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"sync"
|
||||
|
||||
"github.com/Shopify/sarama"
|
||||
"github.com/matrix-org/dendrite/common"
|
||||
"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"
|
||||
)
|
||||
|
||||
// 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
|
||||
// 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 (r *RoomserverInputAPI) SetFederationSenderAPI(fsAPI fsAPI.FederationSenderInternalAPI) {
|
||||
func (r *RoomserverInternalAPI) SetFederationSenderAPI(fsAPI fsAPI.FederationSenderInternalAPI) {
|
||||
r.fsAPI = fsAPI
|
||||
}
|
||||
|
||||
// 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))
|
||||
for i := range updates {
|
||||
value, err := json.Marshal(updates[i])
|
||||
@ -68,8 +49,8 @@ func (r *RoomserverInputAPI) WriteOutputEvents(roomID string, updates []api.Outp
|
||||
return r.Producer.SendMessages(messages)
|
||||
}
|
||||
|
||||
// InputRoomEvents implements api.RoomserverInputAPI
|
||||
func (r *RoomserverInputAPI) InputRoomEvents(
|
||||
// InputRoomEvents implements api.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) InputRoomEvents(
|
||||
ctx context.Context,
|
||||
request *api.InputRoomEventsRequest,
|
||||
response *api.InputRoomEventsResponse,
|
||||
@ -89,20 +70,3 @@ func (r *RoomserverInputAPI) InputRoomEvents(
|
||||
}
|
||||
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}
|
||||
}),
|
||||
)
|
||||
}
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package input
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package input
|
||||
package internal
|
||||
|
||||
import (
|
||||
"testing"
|
@ -14,7 +14,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package input
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
@ -14,7 +14,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package input
|
||||
package internal
|
||||
|
||||
import (
|
||||
"bytes"
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package input
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
@ -14,16 +14,12 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package query
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"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/auth"
|
||||
"github.com/matrix-org/dendrite/roomserver/state"
|
||||
@ -35,17 +31,8 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// RoomserverQueryAPI is an implementation of api.RoomserverQueryAPI
|
||||
type RoomserverQueryAPI struct {
|
||||
DB storage.Database
|
||||
ImmutableCache caching.ImmutableCache
|
||||
ServerName gomatrixserverlib.ServerName
|
||||
KeyRing gomatrixserverlib.JSONVerifier
|
||||
FedClient *gomatrixserverlib.FederationClient
|
||||
}
|
||||
|
||||
// QueryLatestEventsAndState implements api.RoomserverQueryAPI
|
||||
func (r *RoomserverQueryAPI) QueryLatestEventsAndState(
|
||||
// QueryLatestEventsAndState implements api.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) QueryLatestEventsAndState(
|
||||
ctx context.Context,
|
||||
request *api.QueryLatestEventsAndStateRequest,
|
||||
response *api.QueryLatestEventsAndStateResponse,
|
||||
@ -104,8 +91,8 @@ func (r *RoomserverQueryAPI) QueryLatestEventsAndState(
|
||||
return nil
|
||||
}
|
||||
|
||||
// QueryStateAfterEvents implements api.RoomserverQueryAPI
|
||||
func (r *RoomserverQueryAPI) QueryStateAfterEvents(
|
||||
// QueryStateAfterEvents implements api.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) QueryStateAfterEvents(
|
||||
ctx context.Context,
|
||||
request *api.QueryStateAfterEventsRequest,
|
||||
response *api.QueryStateAfterEventsResponse,
|
||||
@ -160,8 +147,8 @@ func (r *RoomserverQueryAPI) QueryStateAfterEvents(
|
||||
return nil
|
||||
}
|
||||
|
||||
// QueryEventsByID implements api.RoomserverQueryAPI
|
||||
func (r *RoomserverQueryAPI) QueryEventsByID(
|
||||
// QueryEventsByID implements api.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) QueryEventsByID(
|
||||
ctx context.Context,
|
||||
request *api.QueryEventsByIDRequest,
|
||||
response *api.QueryEventsByIDResponse,
|
||||
@ -195,7 +182,7 @@ func (r *RoomserverQueryAPI) QueryEventsByID(
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *RoomserverQueryAPI) loadStateEvents(
|
||||
func (r *RoomserverInternalAPI) loadStateEvents(
|
||||
ctx context.Context, stateEntries []types.StateEntry,
|
||||
) ([]gomatrixserverlib.Event, error) {
|
||||
eventNIDs := make([]types.EventNID, len(stateEntries))
|
||||
@ -205,7 +192,7 @@ func (r *RoomserverQueryAPI) loadStateEvents(
|
||||
return r.loadEvents(ctx, eventNIDs)
|
||||
}
|
||||
|
||||
func (r *RoomserverQueryAPI) loadEvents(
|
||||
func (r *RoomserverInternalAPI) loadEvents(
|
||||
ctx context.Context, eventNIDs []types.EventNID,
|
||||
) ([]gomatrixserverlib.Event, error) {
|
||||
stateEvents, err := r.DB.Events(ctx, eventNIDs)
|
||||
@ -220,8 +207,8 @@ func (r *RoomserverQueryAPI) loadEvents(
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// QueryMembershipForUser implements api.RoomserverQueryAPI
|
||||
func (r *RoomserverQueryAPI) QueryMembershipForUser(
|
||||
// QueryMembershipForUser implements api.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) QueryMembershipForUser(
|
||||
ctx context.Context,
|
||||
request *api.QueryMembershipForUserRequest,
|
||||
response *api.QueryMembershipForUserResponse,
|
||||
@ -251,8 +238,8 @@ func (r *RoomserverQueryAPI) QueryMembershipForUser(
|
||||
return nil
|
||||
}
|
||||
|
||||
// QueryMembershipsForRoom implements api.RoomserverQueryAPI
|
||||
func (r *RoomserverQueryAPI) QueryMembershipsForRoom(
|
||||
// QueryMembershipsForRoom implements api.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) QueryMembershipsForRoom(
|
||||
ctx context.Context,
|
||||
request *api.QueryMembershipsForRoomRequest,
|
||||
response *api.QueryMembershipsForRoomResponse,
|
||||
@ -366,8 +353,8 @@ func getMembershipsAtState(
|
||||
return events, nil
|
||||
}
|
||||
|
||||
// QueryInvitesForUser implements api.RoomserverQueryAPI
|
||||
func (r *RoomserverQueryAPI) QueryInvitesForUser(
|
||||
// QueryInvitesForUser implements api.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) QueryInvitesForUser(
|
||||
ctx context.Context,
|
||||
request *api.QueryInvitesForUserRequest,
|
||||
response *api.QueryInvitesForUserResponse,
|
||||
@ -400,8 +387,8 @@ func (r *RoomserverQueryAPI) QueryInvitesForUser(
|
||||
return nil
|
||||
}
|
||||
|
||||
// QueryServerAllowedToSeeEvent implements api.RoomserverQueryAPI
|
||||
func (r *RoomserverQueryAPI) QueryServerAllowedToSeeEvent(
|
||||
// QueryServerAllowedToSeeEvent implements api.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) QueryServerAllowedToSeeEvent(
|
||||
ctx context.Context,
|
||||
request *api.QueryServerAllowedToSeeEventRequest,
|
||||
response *api.QueryServerAllowedToSeeEventResponse,
|
||||
@ -424,7 +411,7 @@ func (r *RoomserverQueryAPI) QueryServerAllowedToSeeEvent(
|
||||
return
|
||||
}
|
||||
|
||||
func (r *RoomserverQueryAPI) checkServerAllowedToSeeEvent(
|
||||
func (r *RoomserverInternalAPI) checkServerAllowedToSeeEvent(
|
||||
ctx context.Context, eventID string, serverName gomatrixserverlib.ServerName, isServerInRoom bool,
|
||||
) (bool, error) {
|
||||
roomState := state.NewStateResolution(r.DB)
|
||||
@ -443,8 +430,8 @@ func (r *RoomserverQueryAPI) checkServerAllowedToSeeEvent(
|
||||
return auth.IsServerAllowed(serverName, isServerInRoom, stateAtEvent), nil
|
||||
}
|
||||
|
||||
// QueryMissingEvents implements api.RoomserverQueryAPI
|
||||
func (r *RoomserverQueryAPI) QueryMissingEvents(
|
||||
// QueryMissingEvents implements api.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) QueryMissingEvents(
|
||||
ctx context.Context,
|
||||
request *api.QueryMissingEventsRequest,
|
||||
response *api.QueryMissingEventsResponse,
|
||||
@ -489,7 +476,7 @@ func (r *RoomserverQueryAPI) QueryMissingEvents(
|
||||
}
|
||||
|
||||
// QueryBackfill implements api.RoomServerQueryAPI
|
||||
func (r *RoomserverQueryAPI) QueryBackfill(
|
||||
func (r *RoomserverInternalAPI) QueryBackfill(
|
||||
ctx context.Context,
|
||||
request *api.QueryBackfillRequest,
|
||||
response *api.QueryBackfillResponse,
|
||||
@ -542,7 +529,7 @@ func (r *RoomserverQueryAPI) QueryBackfill(
|
||||
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)
|
||||
if err != nil {
|
||||
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
|
||||
}
|
||||
|
||||
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)
|
||||
if err != nil {
|
||||
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
|
||||
// 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) {
|
||||
|
||||
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
|
||||
// nolint:gocyclo
|
||||
func (r *RoomserverQueryAPI) scanEventTree(
|
||||
func (r *RoomserverInternalAPI) scanEventTree(
|
||||
ctx context.Context, front []string, visited map[string]bool, limit int,
|
||||
serverName gomatrixserverlib.ServerName,
|
||||
) ([]types.EventNID, error) {
|
||||
@ -777,8 +764,8 @@ BFSLoop:
|
||||
return resultNIDs, err
|
||||
}
|
||||
|
||||
// QueryStateAndAuthChain implements api.RoomserverQueryAPI
|
||||
func (r *RoomserverQueryAPI) QueryStateAndAuthChain(
|
||||
// QueryStateAndAuthChain implements api.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) QueryStateAndAuthChain(
|
||||
ctx context.Context,
|
||||
request *api.QueryStateAndAuthChainRequest,
|
||||
response *api.QueryStateAndAuthChainResponse,
|
||||
@ -837,7 +824,7 @@ func (r *RoomserverQueryAPI) QueryStateAndAuthChain(
|
||||
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)
|
||||
prevStates, err := r.DB.StateAtEventIDs(ctx, eventIDs)
|
||||
if err != nil {
|
||||
@ -942,8 +929,8 @@ func persistEvents(ctx context.Context, db storage.Database, events []gomatrixse
|
||||
return roomNID, backfilledEventMap
|
||||
}
|
||||
|
||||
// QueryRoomVersionCapabilities implements api.RoomserverQueryAPI
|
||||
func (r *RoomserverQueryAPI) QueryRoomVersionCapabilities(
|
||||
// QueryRoomVersionCapabilities implements api.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) QueryRoomVersionCapabilities(
|
||||
ctx context.Context,
|
||||
request *api.QueryRoomVersionCapabilitiesRequest,
|
||||
response *api.QueryRoomVersionCapabilitiesResponse,
|
||||
@ -960,8 +947,8 @@ func (r *RoomserverQueryAPI) QueryRoomVersionCapabilities(
|
||||
return nil
|
||||
}
|
||||
|
||||
// QueryRoomVersionCapabilities implements api.RoomserverQueryAPI
|
||||
func (r *RoomserverQueryAPI) QueryRoomVersionForRoom(
|
||||
// QueryRoomVersionCapabilities implements api.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) QueryRoomVersionForRoom(
|
||||
ctx context.Context,
|
||||
request *api.QueryRoomVersionForRoomRequest,
|
||||
response *api.QueryRoomVersionForRoomResponse,
|
||||
@ -979,176 +966,3 @@ func (r *RoomserverQueryAPI) QueryRoomVersionForRoom(
|
||||
r.ImmutableCache.StoreRoomVersion(request.RoomID, response.RoomVersion)
|
||||
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}
|
||||
}),
|
||||
)
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package query
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package query
|
||||
package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -24,7 +24,7 @@ import (
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
// used to implement RoomserverQueryAPIEventDB to test getAuthChain
|
||||
// used to implement RoomserverInternalAPIEventDB to test getAuthChain
|
||||
type getEventDB struct {
|
||||
eventMap map[string]gomatrixserverlib.Event
|
||||
}
|
||||
@ -79,7 +79,7 @@ func (db *getEventDB) addFakeEvents(graph map[string][]string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// EventsFromIDs implements RoomserverQueryAPIEventDB
|
||||
// EventsFromIDs implements RoomserverInternalAPIEventDB
|
||||
func (db *getEventDB) EventsFromIDs(ctx context.Context, eventIDs []string) (res []types.Event, err error) {
|
||||
for _, evID := range eventIDs {
|
||||
res = append(res, types.Event{
|
@ -20,12 +20,8 @@ import (
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"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/roomserver/alias"
|
||||
"github.com/matrix-org/dendrite/roomserver/input"
|
||||
"github.com/matrix-org/dendrite/roomserver/query"
|
||||
"github.com/matrix-org/dendrite/roomserver/internal"
|
||||
"github.com/matrix-org/dendrite/roomserver/storage"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -35,45 +31,27 @@ import (
|
||||
// allowing other components running in the same process to hit the query the
|
||||
// APIs directly instead of having to use HTTP.
|
||||
func SetupRoomServerComponent(
|
||||
base *basecomponent.BaseDendrite, keyRing gomatrixserverlib.JSONVerifier,
|
||||
base *basecomponent.BaseDendrite,
|
||||
keyRing gomatrixserverlib.JSONVerifier,
|
||||
fedClient *gomatrixserverlib.FederationClient,
|
||||
) (api.RoomserverAliasAPI, api.RoomserverInputAPI, api.RoomserverQueryAPI) {
|
||||
) api.RoomserverInternalAPI {
|
||||
roomserverDB, err := storage.Open(string(base.Cfg.Database.RoomServer))
|
||||
if err != nil {
|
||||
logrus.WithError(err).Panicf("failed to connect to room server db")
|
||||
}
|
||||
|
||||
inputAPI := input.RoomserverInputAPI{
|
||||
internalAPI := internal.RoomserverInternalAPI{
|
||||
DB: roomserverDB,
|
||||
Cfg: base.Cfg,
|
||||
Producer: base.KafkaProducer,
|
||||
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{
|
||||
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
|
||||
return &internalAPI
|
||||
}
|
||||
|
@ -32,10 +32,10 @@ import (
|
||||
|
||||
// OutputRoomEventConsumer consumes events that originated in the room server.
|
||||
type OutputRoomEventConsumer struct {
|
||||
roomServerConsumer *common.ContinualConsumer
|
||||
db storage.Database
|
||||
notifier *sync.Notifier
|
||||
query api.RoomserverQueryAPI
|
||||
rsAPI api.RoomserverInternalAPI
|
||||
rsConsumer *common.ContinualConsumer
|
||||
db storage.Database
|
||||
notifier *sync.Notifier
|
||||
}
|
||||
|
||||
// NewOutputRoomEventConsumer creates a new OutputRoomEventConsumer. Call Start() to begin consuming from room servers.
|
||||
@ -44,7 +44,7 @@ func NewOutputRoomEventConsumer(
|
||||
kafkaConsumer sarama.Consumer,
|
||||
n *sync.Notifier,
|
||||
store storage.Database,
|
||||
queryAPI api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
) *OutputRoomEventConsumer {
|
||||
|
||||
consumer := common.ContinualConsumer{
|
||||
@ -53,10 +53,10 @@ func NewOutputRoomEventConsumer(
|
||||
PartitionStore: store,
|
||||
}
|
||||
s := &OutputRoomEventConsumer{
|
||||
roomServerConsumer: &consumer,
|
||||
db: store,
|
||||
notifier: n,
|
||||
query: queryAPI,
|
||||
rsConsumer: &consumer,
|
||||
db: store,
|
||||
notifier: n,
|
||||
rsAPI: rsAPI,
|
||||
}
|
||||
consumer.ProcessMessage = s.onMessage
|
||||
|
||||
@ -65,7 +65,7 @@ func NewOutputRoomEventConsumer(
|
||||
|
||||
// Start consuming from room servers
|
||||
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.
|
||||
@ -226,7 +226,7 @@ func (s *OutputRoomEventConsumer) lookupStateEvents(
|
||||
// from the roomserver using the query API.
|
||||
eventReq := api.QueryEventsByIDRequest{EventIDs: missing}
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ import (
|
||||
type messagesReq struct {
|
||||
ctx context.Context
|
||||
db storage.Database
|
||||
queryAPI api.RoomserverQueryAPI
|
||||
rsAPI api.RoomserverInternalAPI
|
||||
federation *gomatrixserverlib.FederationClient
|
||||
cfg *config.Dendrite
|
||||
roomID string
|
||||
@ -59,7 +59,7 @@ const defaultMessagesLimit = 10
|
||||
func OnIncomingMessagesRequest(
|
||||
req *http.Request, db storage.Database, roomID string,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
queryAPI api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
cfg *config.Dendrite,
|
||||
) util.JSONResponse {
|
||||
var err error
|
||||
@ -135,7 +135,7 @@ func OnIncomingMessagesRequest(
|
||||
mReq := messagesReq{
|
||||
ctx: req.Context(),
|
||||
db: db,
|
||||
queryAPI: queryAPI,
|
||||
rsAPI: rsAPI,
|
||||
federation: federation,
|
||||
cfg: cfg,
|
||||
roomID: roomID,
|
||||
@ -360,7 +360,7 @@ func (r *messagesReq) handleNonEmptyEventsSlice(streamEvents []types.StreamEvent
|
||||
// the room or sending the request.
|
||||
func (r *messagesReq) backfill(roomID string, fromEventIDs []string, limit int) ([]gomatrixserverlib.HeaderedEvent, error) {
|
||||
var res api.QueryBackfillResponse
|
||||
err := r.queryAPI.QueryBackfill(context.Background(), &api.QueryBackfillRequest{
|
||||
err := r.rsAPI.QueryBackfill(context.Background(), &api.QueryBackfillRequest{
|
||||
RoomID: roomID,
|
||||
EarliestEventsIDs: fromEventIDs,
|
||||
Limit: limit,
|
||||
|
@ -40,7 +40,7 @@ const pathPrefixR0 = "/_matrix/client/r0"
|
||||
func Setup(
|
||||
apiMux *mux.Router, srp *sync.RequestPool, syncDB storage.Database,
|
||||
deviceDB devices.Database, federation *gomatrixserverlib.FederationClient,
|
||||
queryAPI api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
cfg *config.Dendrite,
|
||||
) {
|
||||
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter()
|
||||
@ -61,6 +61,6 @@ func Setup(
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ func SetupSyncAPIComponent(
|
||||
base *basecomponent.BaseDendrite,
|
||||
deviceDB devices.Database,
|
||||
accountsDB accounts.Database,
|
||||
queryAPI api.RoomserverQueryAPI,
|
||||
rsAPI api.RoomserverInternalAPI,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
cfg *config.Dendrite,
|
||||
) {
|
||||
@ -61,7 +61,7 @@ func SetupSyncAPIComponent(
|
||||
requestPool := sync.NewRequestPool(syncDB, notifier, accountsDB)
|
||||
|
||||
roomConsumer := consumers.NewOutputRoomEventConsumer(
|
||||
base.Cfg, base.KafkaConsumer, notifier, syncDB, queryAPI,
|
||||
base.Cfg, base.KafkaConsumer, notifier, syncDB, rsAPI,
|
||||
)
|
||||
if err = roomConsumer.Start(); err != nil {
|
||||
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")
|
||||
}
|
||||
|
||||
routing.Setup(base.APIMux, requestPool, syncDB, deviceDB, federation, queryAPI, cfg)
|
||||
routing.Setup(base.APIMux, requestPool, syncDB, deviceDB, federation, rsAPI, cfg)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user