2020-05-01 11:48:17 +02:00
|
|
|
package internal
|
|
|
|
|
|
|
|
import (
|
2020-09-02 14:47:31 +02:00
|
|
|
"context"
|
2020-05-01 11:48:17 +02:00
|
|
|
|
|
|
|
"github.com/Shopify/sarama"
|
2020-12-18 14:33:28 +01:00
|
|
|
asAPI "github.com/matrix-org/dendrite/appservice/api"
|
2020-05-01 11:48:17 +02:00
|
|
|
fsAPI "github.com/matrix-org/dendrite/federationsender/api"
|
2020-05-21 15:40:13 +02:00
|
|
|
"github.com/matrix-org/dendrite/internal/caching"
|
2020-09-03 18:20:54 +02:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/acls"
|
2020-09-02 14:47:31 +02:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/api"
|
2020-09-02 18:13:15 +02:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/internal/input"
|
2020-09-02 14:47:31 +02:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/internal/perform"
|
2020-09-02 18:13:15 +02:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/internal/query"
|
2020-05-01 11:48:17 +02:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/storage"
|
2020-12-02 18:41:00 +01:00
|
|
|
"github.com/matrix-org/dendrite/setup/config"
|
2020-05-01 11:48:17 +02:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
|
|
|
)
|
|
|
|
|
|
|
|
// RoomserverInternalAPI is an implementation of api.RoomserverInternalAPI
|
|
|
|
type RoomserverInternalAPI struct {
|
2020-09-02 18:13:15 +02:00
|
|
|
*input.Inputer
|
|
|
|
*query.Queryer
|
|
|
|
*perform.Inviter
|
|
|
|
*perform.Joiner
|
2020-09-10 15:39:18 +02:00
|
|
|
*perform.Peeker
|
2020-12-03 12:11:46 +01:00
|
|
|
*perform.Unpeeker
|
2020-09-02 18:13:15 +02:00
|
|
|
*perform.Leaver
|
|
|
|
*perform.Publisher
|
|
|
|
*perform.Backfiller
|
2020-11-05 11:19:23 +01:00
|
|
|
*perform.Forgetter
|
2020-10-06 19:09:02 +02:00
|
|
|
DB storage.Database
|
|
|
|
Cfg *config.RoomServer
|
|
|
|
Producer sarama.SyncProducer
|
|
|
|
Cache caching.RoomServerCaches
|
|
|
|
ServerName gomatrixserverlib.ServerName
|
|
|
|
KeyRing gomatrixserverlib.JSONVerifier
|
|
|
|
fsAPI fsAPI.FederationSenderInternalAPI
|
2020-12-18 14:33:28 +01:00
|
|
|
asAPI asAPI.AppServiceQueryAPI
|
2020-10-06 19:09:02 +02:00
|
|
|
OutputRoomEventTopic string // Kafka topic for new output room events
|
|
|
|
PerspectiveServerNames []gomatrixserverlib.ServerName
|
2020-05-01 11:48:17 +02:00
|
|
|
}
|
2020-09-02 14:47:31 +02:00
|
|
|
|
|
|
|
func NewRoomserverAPI(
|
|
|
|
cfg *config.RoomServer, roomserverDB storage.Database, producer sarama.SyncProducer,
|
2020-09-02 16:26:30 +02:00
|
|
|
outputRoomEventTopic string, caches caching.RoomServerCaches,
|
2020-10-06 19:09:02 +02:00
|
|
|
keyRing gomatrixserverlib.JSONVerifier, perspectiveServerNames []gomatrixserverlib.ServerName,
|
2020-09-02 14:47:31 +02:00
|
|
|
) *RoomserverInternalAPI {
|
2020-09-04 11:40:58 +02:00
|
|
|
serverACLs := acls.NewServerACLs(roomserverDB)
|
2020-09-02 14:47:31 +02:00
|
|
|
a := &RoomserverInternalAPI{
|
2020-10-06 19:09:02 +02:00
|
|
|
DB: roomserverDB,
|
|
|
|
Cfg: cfg,
|
|
|
|
Cache: caches,
|
|
|
|
ServerName: cfg.Matrix.ServerName,
|
|
|
|
PerspectiveServerNames: perspectiveServerNames,
|
|
|
|
KeyRing: keyRing,
|
2020-09-02 18:13:15 +02:00
|
|
|
Queryer: &query.Queryer{
|
2020-09-03 18:20:54 +02:00
|
|
|
DB: roomserverDB,
|
|
|
|
Cache: caches,
|
2020-09-04 11:40:58 +02:00
|
|
|
ServerACLs: serverACLs,
|
2020-09-02 18:13:15 +02:00
|
|
|
},
|
|
|
|
Inputer: &input.Inputer{
|
|
|
|
DB: roomserverDB,
|
|
|
|
OutputRoomEventTopic: outputRoomEventTopic,
|
|
|
|
Producer: producer,
|
|
|
|
ServerName: cfg.Matrix.ServerName,
|
2020-09-04 11:40:58 +02:00
|
|
|
ACLs: serverACLs,
|
2020-09-02 18:13:15 +02:00
|
|
|
},
|
2020-09-02 14:47:31 +02: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 18:13:15 +02:00
|
|
|
DB: r.DB,
|
|
|
|
Cfg: r.Cfg,
|
|
|
|
FSAPI: r.fsAPI,
|
|
|
|
Inputer: r.Inputer,
|
2020-09-02 14:47:31 +02:00
|
|
|
}
|
|
|
|
r.Joiner = &perform.Joiner{
|
|
|
|
ServerName: r.Cfg.Matrix.ServerName,
|
|
|
|
Cfg: r.Cfg,
|
|
|
|
DB: r.DB,
|
|
|
|
FSAPI: r.fsAPI,
|
2020-09-10 15:39:18 +02:00
|
|
|
Inputer: r.Inputer,
|
|
|
|
}
|
|
|
|
r.Peeker = &perform.Peeker{
|
|
|
|
ServerName: r.Cfg.Matrix.ServerName,
|
|
|
|
Cfg: r.Cfg,
|
|
|
|
DB: r.DB,
|
|
|
|
FSAPI: r.fsAPI,
|
2020-09-02 18:13:15 +02:00
|
|
|
Inputer: r.Inputer,
|
2020-09-02 14:47:31 +02:00
|
|
|
}
|
2020-12-03 12:11:46 +01:00
|
|
|
r.Unpeeker = &perform.Unpeeker{
|
|
|
|
ServerName: r.Cfg.Matrix.ServerName,
|
|
|
|
Cfg: r.Cfg,
|
|
|
|
DB: r.DB,
|
|
|
|
FSAPI: r.fsAPI,
|
|
|
|
Inputer: r.Inputer,
|
|
|
|
}
|
2020-09-02 14:47:31 +02:00
|
|
|
r.Leaver = &perform.Leaver{
|
2020-09-02 18:13:15 +02:00
|
|
|
Cfg: r.Cfg,
|
|
|
|
DB: r.DB,
|
|
|
|
FSAPI: r.fsAPI,
|
|
|
|
Inputer: r.Inputer,
|
2020-09-02 14:47:31 +02:00
|
|
|
}
|
|
|
|
r.Publisher = &perform.Publisher{
|
|
|
|
DB: r.DB,
|
|
|
|
}
|
|
|
|
r.Backfiller = &perform.Backfiller{
|
|
|
|
ServerName: r.ServerName,
|
|
|
|
DB: r.DB,
|
2020-09-02 16:26:30 +02:00
|
|
|
FSAPI: r.fsAPI,
|
2020-09-02 14:47:31 +02:00
|
|
|
KeyRing: r.KeyRing,
|
2020-10-06 19:09:02 +02:00
|
|
|
// Perspective servers are trusted to not lie about server keys, so we will also
|
|
|
|
// prefer these servers when backfilling (assuming they are in the room) rather
|
|
|
|
// than trying random servers
|
|
|
|
PreferServers: r.PerspectiveServerNames,
|
2020-09-02 14:47:31 +02:00
|
|
|
}
|
2020-11-05 11:19:23 +01:00
|
|
|
r.Forgetter = &perform.Forgetter{
|
|
|
|
DB: r.DB,
|
|
|
|
}
|
2020-09-02 14:47:31 +02:00
|
|
|
}
|
|
|
|
|
2020-12-18 14:33:28 +01:00
|
|
|
func (r *RoomserverInternalAPI) SetAppserviceAPI(asAPI asAPI.AppServiceQueryAPI) {
|
|
|
|
r.asAPI = asAPI
|
|
|
|
}
|
|
|
|
|
2020-09-02 14:47:31 +02:00
|
|
|
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)
|
|
|
|
}
|
2020-11-05 11:19:23 +01:00
|
|
|
|
|
|
|
func (r *RoomserverInternalAPI) PerformForget(
|
|
|
|
ctx context.Context,
|
|
|
|
req *api.PerformForgetRequest,
|
|
|
|
resp *api.PerformForgetResponse,
|
|
|
|
) error {
|
|
|
|
return r.Forgetter.PerformForget(ctx, req, resp)
|
|
|
|
}
|