2020-05-01 09:48:17 +00:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
2020-09-02 12:47:31 +00:00
|
|
|
"context"
|
2020-05-01 09:48:17 +00:00
|
|
|
|
|
|
|
"github.com/Shopify/sarama"
|
|
|
|
fsAPI "github.com/matrix-org/dendrite/federationsender/api"
|
2020-05-21 13:40:13 +00:00
|
|
|
"github.com/matrix-org/dendrite/internal/caching"
|
|
|
|
"github.com/matrix-org/dendrite/internal/config"
|
2020-09-02 12:47:31 +00:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/api"
|
2020-09-02 16:13:15 +00:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/internal/input"
|
2020-09-02 12:47:31 +00:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/internal/perform"
|
2020-09-02 16:13:15 +00:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/internal/query"
|
2020-05-01 09:48:17 +00:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/storage"
|
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RoomserverInternalAPI is an implementation of api.RoomserverInternalAPI
|
|
|
|
type RoomserverInternalAPI struct {
|
2020-09-02 16:13:15 +00:00
|
|
|
*input.Inputer
|
|
|
|
*query.Queryer
|
|
|
|
*perform.Inviter
|
|
|
|
*perform.Joiner
|
|
|
|
*perform.Leaver
|
|
|
|
*perform.Publisher
|
|
|
|
*perform.Backfiller
|
2020-05-01 09:48:17 +00:00
|
|
|
DB storage.Database
|
2020-08-10 13:18:04 +00:00
|
|
|
Cfg *config.RoomServer
|
2020-05-01 09:48:17 +00:00
|
|
|
Producer sarama.SyncProducer
|
2020-08-25 11:32:29 +00:00
|
|
|
Cache caching.RoomServerCaches
|
2020-05-01 09:48:17 +00:00
|
|
|
ServerName gomatrixserverlib.ServerName
|
|
|
|
KeyRing gomatrixserverlib.JSONVerifier
|
2020-09-02 14:26:30 +00:00
|
|
|
fsAPI fsAPI.FederationSenderInternalAPI
|
2020-09-02 12:47:31 +00:00
|
|
|
OutputRoomEventTopic string // Kafka topic for new output room events
|
2020-05-01 09:48:17 +00:00
|
|
|
}
|
2020-09-02 12:47:31 +00:00
|
|
|
|
|
|
|
func NewRoomserverAPI(
|
|
|
|
cfg *config.RoomServer, roomserverDB storage.Database, producer sarama.SyncProducer,
|
2020-09-02 14:26:30 +00:00
|
|
|
outputRoomEventTopic string, caches caching.RoomServerCaches,
|
2020-09-02 12:47:31 +00:00
|
|
|
keyRing gomatrixserverlib.JSONVerifier,
|
|
|
|
) *RoomserverInternalAPI {
|
|
|
|
a := &RoomserverInternalAPI{
|
2020-09-02 16:13:15 +00:00
|
|
|
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,
|
|
|
|
},
|
2020-09-02 12:47:31 +00:00
|
|
|
// perform-er structs get initialised when we have a federation sender to use
|
|
|
|
}
|
|
|
|
return a
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 *RoomserverInternalAPI) SetFederationSenderAPI(fsAPI fsAPI.FederationSenderInternalAPI) {
|
|
|
|
r.fsAPI = fsAPI
|
|
|
|
|
|
|
|
r.Inviter = &perform.Inviter{
|
2020-09-02 16:13:15 +00:00
|
|
|
DB: r.DB,
|
|
|
|
Cfg: r.Cfg,
|
|
|
|
FSAPI: r.fsAPI,
|
|
|
|
Inputer: r.Inputer,
|
2020-09-02 12:47:31 +00:00
|
|
|
}
|
|
|
|
r.Joiner = &perform.Joiner{
|
|
|
|
ServerName: r.Cfg.Matrix.ServerName,
|
|
|
|
Cfg: r.Cfg,
|
|
|
|
DB: r.DB,
|
|
|
|
FSAPI: r.fsAPI,
|
2020-09-02 16:13:15 +00:00
|
|
|
Inputer: r.Inputer,
|
2020-09-02 12:47:31 +00:00
|
|
|
}
|
|
|
|
r.Leaver = &perform.Leaver{
|
2020-09-02 16:13:15 +00:00
|
|
|
Cfg: r.Cfg,
|
|
|
|
DB: r.DB,
|
|
|
|
FSAPI: r.fsAPI,
|
|
|
|
Inputer: r.Inputer,
|
2020-09-02 12:47:31 +00:00
|
|
|
}
|
|
|
|
r.Publisher = &perform.Publisher{
|
|
|
|
DB: r.DB,
|
|
|
|
}
|
|
|
|
r.Backfiller = &perform.Backfiller{
|
|
|
|
ServerName: r.ServerName,
|
|
|
|
DB: r.DB,
|
2020-09-02 14:26:30 +00:00
|
|
|
FSAPI: r.fsAPI,
|
2020-09-02 12:47:31 +00:00
|
|
|
KeyRing: r.KeyRing,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RoomserverInternalAPI) PerformInvite(
|
|
|
|
ctx context.Context,
|
|
|
|
req *api.PerformInviteRequest,
|
|
|
|
res *api.PerformInviteResponse,
|
|
|
|
) error {
|
|
|
|
outputEvents, err := r.Inviter.PerformInvite(ctx, req, res)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(outputEvents) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return r.WriteOutputEvents(req.Event.RoomID(), outputEvents)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *RoomserverInternalAPI) PerformLeave(
|
|
|
|
ctx context.Context,
|
|
|
|
req *api.PerformLeaveRequest,
|
|
|
|
res *api.PerformLeaveResponse,
|
|
|
|
) error {
|
|
|
|
outputEvents, err := r.Leaver.PerformLeave(ctx, req, res)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(outputEvents) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return r.WriteOutputEvents(req.RoomID, outputEvents)
|
|
|
|
}
|