diff options
author | Kegsay <kegan@matrix.org> | 2020-09-02 17:13:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-02 17:13:15 +0100 |
commit | 9d9e854fe042cd2c83cf694d6b3e4c8e7046cde1 (patch) | |
tree | 75f9247df1d00b140c4249ef14b711b2839806bd /roomserver/internal/api.go | |
parent | f06637435b2124c89dfdd96cd723f54cc7055602 (diff) |
Add Queryer and Inputer and factor out more RSAPI stuff (#1382)
* Add Queryer and use embedded structs
* Add Inputer and factor out more RS API stuff
This neatly splits up the RS API based on the functionality it provides,
whilst providing a useful place for code sharing via the `helpers` package.
Diffstat (limited to 'roomserver/internal/api.go')
-rw-r--r-- | roomserver/internal/api.go | 81 |
1 files changed, 33 insertions, 48 deletions
diff --git a/roomserver/internal/api.go b/roomserver/internal/api.go index 8ac1bdda..93c0be77 100644 --- a/roomserver/internal/api.go +++ b/roomserver/internal/api.go @@ -2,20 +2,28 @@ package internal import ( "context" - "sync" "github.com/Shopify/sarama" fsAPI "github.com/matrix-org/dendrite/federationsender/api" "github.com/matrix-org/dendrite/internal/caching" "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" + "github.com/matrix-org/dendrite/roomserver/internal/input" "github.com/matrix-org/dendrite/roomserver/internal/perform" + "github.com/matrix-org/dendrite/roomserver/internal/query" "github.com/matrix-org/dendrite/roomserver/storage" "github.com/matrix-org/gomatrixserverlib" ) // RoomserverInternalAPI is an implementation of api.RoomserverInternalAPI type RoomserverInternalAPI struct { + *input.Inputer + *query.Queryer + *perform.Inviter + *perform.Joiner + *perform.Leaver + *perform.Publisher + *perform.Backfiller DB storage.Database Cfg *config.RoomServer Producer sarama.SyncProducer @@ -24,12 +32,6 @@ type RoomserverInternalAPI struct { KeyRing gomatrixserverlib.JSONVerifier fsAPI fsAPI.FederationSenderInternalAPI OutputRoomEventTopic string // Kafka topic for new output room events - Inviter *perform.Inviter - Joiner *perform.Joiner - Leaver *perform.Leaver - Publisher *perform.Publisher - Backfiller *perform.Backfiller - mutexes sync.Map // room ID -> *sync.Mutex, protects calls to processRoomEvent } func NewRoomserverAPI( @@ -38,13 +40,21 @@ func NewRoomserverAPI( keyRing gomatrixserverlib.JSONVerifier, ) *RoomserverInternalAPI { a := &RoomserverInternalAPI{ - DB: roomserverDB, - Cfg: cfg, - Producer: producer, - Cache: caches, - ServerName: cfg.Matrix.ServerName, - KeyRing: keyRing, - OutputRoomEventTopic: outputRoomEventTopic, + DB: roomserverDB, + Cfg: cfg, + Cache: caches, + ServerName: cfg.Matrix.ServerName, + KeyRing: keyRing, + Queryer: &query.Queryer{ + DB: roomserverDB, + Cache: caches, + }, + Inputer: &input.Inputer{ + DB: roomserverDB, + OutputRoomEventTopic: outputRoomEventTopic, + Producer: producer, + ServerName: cfg.Matrix.ServerName, + }, // perform-er structs get initialised when we have a federation sender to use } return a @@ -57,23 +67,23 @@ func (r *RoomserverInternalAPI) SetFederationSenderAPI(fsAPI fsAPI.FederationSen r.fsAPI = fsAPI r.Inviter = &perform.Inviter{ - DB: r.DB, - Cfg: r.Cfg, - FSAPI: r.fsAPI, - RSAPI: r, + DB: r.DB, + Cfg: r.Cfg, + FSAPI: r.fsAPI, + Inputer: r.Inputer, } r.Joiner = &perform.Joiner{ ServerName: r.Cfg.Matrix.ServerName, Cfg: r.Cfg, DB: r.DB, FSAPI: r.fsAPI, - RSAPI: r, + Inputer: r.Inputer, } r.Leaver = &perform.Leaver{ - Cfg: r.Cfg, - DB: r.DB, - FSAPI: r.fsAPI, - RSAPI: r, + Cfg: r.Cfg, + DB: r.DB, + FSAPI: r.fsAPI, + Inputer: r.Inputer, } r.Publisher = &perform.Publisher{ DB: r.DB, @@ -101,14 +111,6 @@ func (r *RoomserverInternalAPI) PerformInvite( return r.WriteOutputEvents(req.Event.RoomID(), outputEvents) } -func (r *RoomserverInternalAPI) PerformJoin( - ctx context.Context, - req *api.PerformJoinRequest, - res *api.PerformJoinResponse, -) { - r.Joiner.PerformJoin(ctx, req, res) -} - func (r *RoomserverInternalAPI) PerformLeave( ctx context.Context, req *api.PerformLeaveRequest, @@ -123,20 +125,3 @@ func (r *RoomserverInternalAPI) PerformLeave( } return r.WriteOutputEvents(req.RoomID, outputEvents) } - -func (r *RoomserverInternalAPI) PerformPublish( - ctx context.Context, - req *api.PerformPublishRequest, - res *api.PerformPublishResponse, -) { - r.Publisher.PerformPublish(ctx, req, res) -} - -// Query a given amount (or less) of events prior to a given set of events. -func (r *RoomserverInternalAPI) PerformBackfill( - ctx context.Context, - request *api.PerformBackfillRequest, - response *api.PerformBackfillResponse, -) error { - return r.Backfiller.PerformBackfill(ctx, request, response) -} |