mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-06 13:43:09 -06:00
Use more interfaces in federationapi; begin adding regression test
This commit is contained in:
parent
c7f4e163b1
commit
58cef49f4e
|
|
@ -12,12 +12,16 @@ import (
|
|||
|
||||
// FederationInternalAPI is used to query information from the federation sender.
|
||||
type FederationInternalAPI interface {
|
||||
FederationClient
|
||||
gomatrixserverlib.FederatedStateClient
|
||||
KeyserverFederationAPI
|
||||
gomatrixserverlib.KeyDatabase
|
||||
ClientFederationAPI
|
||||
RoomserverFederationAPI
|
||||
|
||||
QueryServerKeys(ctx context.Context, request *QueryServerKeysRequest, response *QueryServerKeysResponse) error
|
||||
LookupServerKeys(ctx context.Context, s gomatrixserverlib.ServerName, keyRequests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp) ([]gomatrixserverlib.ServerKeys, error)
|
||||
MSC2836EventRelationships(ctx context.Context, dst gomatrixserverlib.ServerName, r gomatrixserverlib.MSC2836EventRelationshipsRequest, roomVersion gomatrixserverlib.RoomVersion) (res gomatrixserverlib.MSC2836EventRelationshipsResponse, err error)
|
||||
MSC2946Spaces(ctx context.Context, dst gomatrixserverlib.ServerName, roomID string, suggestedOnly bool) (res gomatrixserverlib.MSC2946SpacesResponse, err error)
|
||||
|
||||
// Broadcasts an EDU to all servers in rooms we are joined to. Used in the yggdrasil demos.
|
||||
PerformBroadcastEDU(
|
||||
|
|
@ -60,17 +64,43 @@ type RoomserverFederationAPI interface {
|
|||
LookupMissingEvents(ctx context.Context, s gomatrixserverlib.ServerName, roomID string, missing gomatrixserverlib.MissingEvents, roomVersion gomatrixserverlib.RoomVersion) (res gomatrixserverlib.RespMissingEvents, err error)
|
||||
}
|
||||
|
||||
// FederationClient is a subset of gomatrixserverlib.FederationClient functions which the fedsender
|
||||
// KeyserverFederationAPI is a subset of gomatrixserverlib.FederationClient functions which the keyserver
|
||||
// implements as proxy calls, with built-in backoff/retries/etc. Errors returned from functions in
|
||||
// this interface are of type FederationClientError
|
||||
type FederationClient interface {
|
||||
gomatrixserverlib.FederatedStateClient
|
||||
type KeyserverFederationAPI interface {
|
||||
GetUserDevices(ctx context.Context, s gomatrixserverlib.ServerName, userID string) (res gomatrixserverlib.RespUserDevices, err error)
|
||||
ClaimKeys(ctx context.Context, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string) (res gomatrixserverlib.RespClaimKeys, err error)
|
||||
QueryKeys(ctx context.Context, s gomatrixserverlib.ServerName, keys map[string][]string) (res gomatrixserverlib.RespQueryKeys, err error)
|
||||
}
|
||||
|
||||
// an interface for gmsl.FederationClient - contains functions called by federationapi only.
|
||||
type FederationClient interface {
|
||||
gomatrixserverlib.KeyClient
|
||||
SendTransaction(ctx context.Context, t gomatrixserverlib.Transaction) (res gomatrixserverlib.RespSend, err error)
|
||||
|
||||
// Perform operations
|
||||
LookupRoomAlias(ctx context.Context, s gomatrixserverlib.ServerName, roomAlias string) (res gomatrixserverlib.RespDirectory, err error)
|
||||
Peek(ctx context.Context, s gomatrixserverlib.ServerName, roomID, peekID string, roomVersions []gomatrixserverlib.RoomVersion) (res gomatrixserverlib.RespPeek, err error)
|
||||
MakeJoin(ctx context.Context, s gomatrixserverlib.ServerName, roomID, userID string, roomVersions []gomatrixserverlib.RoomVersion) (res gomatrixserverlib.RespMakeJoin, err error)
|
||||
SendJoin(ctx context.Context, s gomatrixserverlib.ServerName, event *gomatrixserverlib.Event) (res gomatrixserverlib.RespSendJoin, err error)
|
||||
MakeLeave(ctx context.Context, s gomatrixserverlib.ServerName, roomID, userID string) (res gomatrixserverlib.RespMakeLeave, err error)
|
||||
SendLeave(ctx context.Context, s gomatrixserverlib.ServerName, event *gomatrixserverlib.Event) (err error)
|
||||
SendInviteV2(ctx context.Context, s gomatrixserverlib.ServerName, request gomatrixserverlib.InviteV2Request) (res gomatrixserverlib.RespInviteV2, err error)
|
||||
|
||||
GetEvent(ctx context.Context, s gomatrixserverlib.ServerName, eventID string) (res gomatrixserverlib.Transaction, err error)
|
||||
|
||||
GetEventAuth(ctx context.Context, s gomatrixserverlib.ServerName, roomVersion gomatrixserverlib.RoomVersion, roomID, eventID string) (res gomatrixserverlib.RespEventAuth, err error)
|
||||
GetUserDevices(ctx context.Context, s gomatrixserverlib.ServerName, userID string) (gomatrixserverlib.RespUserDevices, error)
|
||||
ClaimKeys(ctx context.Context, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string) (gomatrixserverlib.RespClaimKeys, error)
|
||||
QueryKeys(ctx context.Context, s gomatrixserverlib.ServerName, keys map[string][]string) (gomatrixserverlib.RespQueryKeys, error)
|
||||
Backfill(ctx context.Context, s gomatrixserverlib.ServerName, roomID string, limit int, eventIDs []string) (res gomatrixserverlib.Transaction, err error)
|
||||
MSC2836EventRelationships(ctx context.Context, dst gomatrixserverlib.ServerName, r gomatrixserverlib.MSC2836EventRelationshipsRequest, roomVersion gomatrixserverlib.RoomVersion) (res gomatrixserverlib.MSC2836EventRelationshipsResponse, err error)
|
||||
MSC2946Spaces(ctx context.Context, dst gomatrixserverlib.ServerName, roomID string, suggestedOnly bool) (res gomatrixserverlib.MSC2946SpacesResponse, err error)
|
||||
LookupServerKeys(ctx context.Context, s gomatrixserverlib.ServerName, keyRequests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp) ([]gomatrixserverlib.ServerKeys, error)
|
||||
|
||||
ExchangeThirdPartyInvite(ctx context.Context, s gomatrixserverlib.ServerName, builder gomatrixserverlib.EventBuilder) (err error)
|
||||
LookupState(ctx context.Context, s gomatrixserverlib.ServerName, roomID string, eventID string, roomVersion gomatrixserverlib.RoomVersion) (res gomatrixserverlib.RespState, err error)
|
||||
LookupStateIDs(ctx context.Context, s gomatrixserverlib.ServerName, roomID string, eventID string) (res gomatrixserverlib.RespStateIDs, err error)
|
||||
LookupMissingEvents(ctx context.Context, s gomatrixserverlib.ServerName, roomID string, missing gomatrixserverlib.MissingEvents, roomVersion gomatrixserverlib.RoomVersion) (res gomatrixserverlib.RespMissingEvents, err error)
|
||||
}
|
||||
|
||||
// FederationClientError is returned from FederationClient methods in the event of a problem.
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ func AddPublicRoutes(
|
|||
// can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes.
|
||||
func NewInternalAPI(
|
||||
base *base.BaseDendrite,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
federation api.FederationClient,
|
||||
rsAPI roomserverAPI.FederationRoomserverAPI,
|
||||
caches *caching.Caches,
|
||||
keyRing *gomatrixserverlib.KeyRing,
|
||||
|
|
|
|||
|
|
@ -3,21 +3,103 @@ package federationapi_test
|
|||
import (
|
||||
"context"
|
||||
"crypto/ed25519"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/matrix-org/dendrite/federationapi"
|
||||
"github.com/matrix-org/dendrite/federationapi/api"
|
||||
"github.com/matrix-org/dendrite/federationapi/internal"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
rsapi "github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/setup/base"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
"github.com/matrix-org/dendrite/setup/jetstream"
|
||||
"github.com/matrix-org/dendrite/test"
|
||||
"github.com/matrix-org/dendrite/test/testrig"
|
||||
"github.com/matrix-org/gomatrix"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
type fedRoomserverAPI struct {
|
||||
api.FederationRoomserverAPI
|
||||
rsapi.FederationRoomserverAPI
|
||||
inputRoomEvents func(ctx context.Context, req *rsapi.InputRoomEventsRequest, res *rsapi.InputRoomEventsResponse)
|
||||
}
|
||||
|
||||
// PerformJoin will call this function
|
||||
func (f *fedRoomserverAPI) InputRoomEvents(ctx context.Context, req *rsapi.InputRoomEventsRequest, res *rsapi.InputRoomEventsResponse) {
|
||||
if f.inputRoomEvents == nil {
|
||||
return
|
||||
}
|
||||
f.inputRoomEvents(ctx, req, res)
|
||||
}
|
||||
|
||||
type fedClient struct {
|
||||
api.FederationClient
|
||||
allowJoins []*test.Room
|
||||
t *testing.T
|
||||
}
|
||||
|
||||
func (f *fedClient) GetServerKeys(ctx context.Context, matrixServer gomatrixserverlib.ServerName) (gomatrixserverlib.ServerKeys, error) {
|
||||
var keys gomatrixserverlib.ServerKeys
|
||||
|
||||
keys.ServerName = matrixServer
|
||||
keys.ValidUntilTS = gomatrixserverlib.AsTimestamp(time.Now().Add(10 * time.Hour))
|
||||
publicKey := test.PrivateKey.Public().(ed25519.PublicKey)
|
||||
keys.VerifyKeys = map[gomatrixserverlib.KeyID]gomatrixserverlib.VerifyKey{
|
||||
test.KeyID: {
|
||||
Key: gomatrixserverlib.Base64Bytes(publicKey),
|
||||
},
|
||||
}
|
||||
toSign, err := json.Marshal(keys.ServerKeyFields)
|
||||
if err != nil {
|
||||
return keys, err
|
||||
}
|
||||
|
||||
keys.Raw, err = gomatrixserverlib.SignJSON(
|
||||
string(matrixServer), test.KeyID, test.PrivateKey, toSign,
|
||||
)
|
||||
if err != nil {
|
||||
return keys, err
|
||||
}
|
||||
|
||||
return keys, nil
|
||||
}
|
||||
|
||||
func (f *fedClient) MakeJoin(ctx context.Context, s gomatrixserverlib.ServerName, roomID, userID string, roomVersions []gomatrixserverlib.RoomVersion) (res gomatrixserverlib.RespMakeJoin, err error) {
|
||||
for _, r := range f.allowJoins {
|
||||
if r.ID == roomID {
|
||||
res.RoomVersion = r.Version
|
||||
res.JoinEvent = gomatrixserverlib.EventBuilder{
|
||||
Sender: userID,
|
||||
RoomID: roomID,
|
||||
Type: "m.room.member",
|
||||
StateKey: &userID,
|
||||
Content: gomatrixserverlib.RawJSON([]byte(`{"membership":"join"}`)),
|
||||
PrevEvents: r.ForwardExtremities(),
|
||||
}
|
||||
var needed gomatrixserverlib.StateNeeded
|
||||
needed, err = gomatrixserverlib.StateNeededForEventBuilder(&res.JoinEvent)
|
||||
if err != nil {
|
||||
f.t.Errorf("StateNeededForEventBuilder: %v", err)
|
||||
return
|
||||
}
|
||||
res.JoinEvent.AuthEvents = r.MustGetAuthEventRefsForEvent(f.t, needed)
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
func (f *fedClient) SendJoin(ctx context.Context, s gomatrixserverlib.ServerName, event *gomatrixserverlib.Event) (res gomatrixserverlib.RespSendJoin, err error) {
|
||||
for _, r := range f.allowJoins {
|
||||
if r.ID == event.RoomID() {
|
||||
r.InsertEvent(f.t, event.Headered(r.Version))
|
||||
f.t.Logf("Join event: %v", event.EventID())
|
||||
res.StateEvents = gomatrixserverlib.NewEventJSONsFromHeaderedEvents(r.CurrentState())
|
||||
res.AuthEvents = gomatrixserverlib.NewEventJSONsFromHeaderedEvents(r.Events())
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Regression test to make sure that /send_join is updating the destination hosts synchronously and
|
||||
|
|
@ -29,7 +111,6 @@ func TestFederationAPIJoinThenKeyUpdate(t *testing.T) {
|
|||
}
|
||||
|
||||
func testFederationAPIJoinThenKeyUpdate(t *testing.T, dbType test.DBType) {
|
||||
/*
|
||||
base, close := testrig.CreateBaseDendrite(t, dbType)
|
||||
defer close()
|
||||
jsctx, _ := base.NATS.Prepare(base.ProcessContext, &base.Cfg.Global.JetStream)
|
||||
|
|
@ -37,9 +118,37 @@ func testFederationAPIJoinThenKeyUpdate(t *testing.T, dbType test.DBType) {
|
|||
|
||||
user := test.NewUser()
|
||||
room := test.NewRoom(t, user)
|
||||
joiningVia := gomatrixserverlib.ServerName("example.localhost")
|
||||
|
||||
rsapi := &fedRoomserverAPI{
|
||||
inputRoomEvents: func(ctx context.Context, req *rsapi.InputRoomEventsRequest, res *rsapi.InputRoomEventsResponse) {
|
||||
if req.Asynchronous {
|
||||
t.Errorf("InputRoomEvents from PerformJoin MUST be synchronous")
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
fsapi := federationapi.NewInternalAPI(base, &fedClient{
|
||||
allowJoins: []*test.Room{room},
|
||||
t: t,
|
||||
}, rsapi, base.Caches, nil, false)
|
||||
|
||||
var resp api.PerformJoinResponse
|
||||
fsapi.PerformJoin(context.Background(), &api.PerformJoinRequest{
|
||||
RoomID: room.ID,
|
||||
UserID: user.ID,
|
||||
ServerNames: []gomatrixserverlib.ServerName{joiningVia},
|
||||
}, &resp)
|
||||
if resp.JoinedVia != joiningVia {
|
||||
t.Errorf("PerformJoin: joined via %v want %v", resp.JoinedVia, joiningVia)
|
||||
}
|
||||
if resp.LastError != nil {
|
||||
t.Fatalf("PerformJoin: returned error: %+v", *resp.LastError)
|
||||
}
|
||||
|
||||
// TODO:
|
||||
// Inject a keyserver key change event and ensure we try to send it out
|
||||
|
||||
fsapi := federationapi.NewInternalAPI(base, mockClient, fedRoomserverAPI{}, base.Caches, nil, false)
|
||||
*/
|
||||
}
|
||||
|
||||
// Tests that event IDs with '/' in them (escaped as %2F) are correctly passed to the right handler and don't 404.
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ type FederationInternalAPI struct {
|
|||
cfg *config.FederationAPI
|
||||
statistics *statistics.Statistics
|
||||
rsAPI roomserverAPI.FederationRoomserverAPI
|
||||
federation *gomatrixserverlib.FederationClient
|
||||
federation api.FederationClient
|
||||
keyRing *gomatrixserverlib.KeyRing
|
||||
queues *queue.OutgoingQueues
|
||||
joins sync.Map // joins currently in progress
|
||||
|
|
@ -35,7 +35,7 @@ type FederationInternalAPI struct {
|
|||
func NewFederationInternalAPI(
|
||||
db storage.Database, cfg *config.FederationAPI,
|
||||
rsAPI roomserverAPI.FederationRoomserverAPI,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
federation api.FederationClient,
|
||||
statistics *statistics.Statistics,
|
||||
caches *caching.Caches,
|
||||
queues *queue.OutgoingQueues,
|
||||
|
|
|
|||
|
|
@ -666,7 +666,7 @@ func setDefaultRoomVersionFromJoinEvent(joinEvent gomatrixserverlib.EventBuilder
|
|||
|
||||
// FederatedAuthProvider is an auth chain provider which fetches events from the server provided
|
||||
func federatedAuthProvider(
|
||||
ctx context.Context, federation *gomatrixserverlib.FederationClient,
|
||||
ctx context.Context, federation api.FederationClient,
|
||||
keyRing gomatrixserverlib.JSONVerifier, server gomatrixserverlib.ServerName,
|
||||
) gomatrixserverlib.AuthChainProvider {
|
||||
// A list of events that we have retried, if they were not included in
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
fedapi "github.com/matrix-org/dendrite/federationapi/api"
|
||||
"github.com/matrix-org/dendrite/federationapi/statistics"
|
||||
"github.com/matrix-org/dendrite/federationapi/storage"
|
||||
"github.com/matrix-org/dendrite/federationapi/storage/shared"
|
||||
|
|
@ -50,7 +51,7 @@ type destinationQueue struct {
|
|||
process *process.ProcessContext
|
||||
signing *SigningInfo
|
||||
rsAPI api.FederationRoomserverAPI
|
||||
client *gomatrixserverlib.FederationClient // federation client
|
||||
client fedapi.FederationClient // federation client
|
||||
origin gomatrixserverlib.ServerName // origin of requests
|
||||
destination gomatrixserverlib.ServerName // destination of requests
|
||||
running atomic.Bool // is the queue worker running?
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/gjson"
|
||||
|
||||
fedapi "github.com/matrix-org/dendrite/federationapi/api"
|
||||
"github.com/matrix-org/dendrite/federationapi/statistics"
|
||||
"github.com/matrix-org/dendrite/federationapi/storage"
|
||||
"github.com/matrix-org/dendrite/federationapi/storage/shared"
|
||||
|
|
@ -41,7 +42,7 @@ type OutgoingQueues struct {
|
|||
disabled bool
|
||||
rsAPI api.FederationRoomserverAPI
|
||||
origin gomatrixserverlib.ServerName
|
||||
client *gomatrixserverlib.FederationClient
|
||||
client fedapi.FederationClient
|
||||
statistics *statistics.Statistics
|
||||
signing *SigningInfo
|
||||
queuesMutex sync.Mutex // protects the below
|
||||
|
|
@ -85,7 +86,7 @@ func NewOutgoingQueues(
|
|||
process *process.ProcessContext,
|
||||
disabled bool,
|
||||
origin gomatrixserverlib.ServerName,
|
||||
client *gomatrixserverlib.FederationClient,
|
||||
client fedapi.FederationClient,
|
||||
rsAPI api.FederationRoomserverAPI,
|
||||
statistics *statistics.Statistics,
|
||||
signing *SigningInfo,
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import (
|
|||
// RoomAliasToID converts the queried alias into a room ID and returns it
|
||||
func RoomAliasToID(
|
||||
httpReq *http.Request,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
federation federationAPI.FederationClient,
|
||||
cfg *config.FederationAPI,
|
||||
rsAPI roomserverAPI.FederationRoomserverAPI,
|
||||
senderAPI federationAPI.FederationInternalAPI,
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ func Setup(
|
|||
rsAPI roomserverAPI.FederationRoomserverAPI,
|
||||
fsAPI *fedInternal.FederationInternalAPI,
|
||||
keys gomatrixserverlib.JSONVerifier,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
federation federationAPI.FederationClient,
|
||||
userAPI userapi.FederationUserAPI,
|
||||
keyAPI keyserverAPI.FederationKeyAPI,
|
||||
mscCfg *config.MSCs,
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ func Send(
|
|||
rsAPI api.FederationRoomserverAPI,
|
||||
keyAPI keyapi.FederationKeyAPI,
|
||||
keys gomatrixserverlib.JSONVerifier,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
federation federationAPI.FederationClient,
|
||||
mu *internal.MutexByRoom,
|
||||
servers federationAPI.ServersInRoomProvider,
|
||||
producer *producers.SyncAPIProducer,
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import (
|
|||
|
||||
"github.com/matrix-org/dendrite/clientapi/httputil"
|
||||
"github.com/matrix-org/dendrite/clientapi/jsonerror"
|
||||
federationAPI "github.com/matrix-org/dendrite/federationapi/api"
|
||||
"github.com/matrix-org/dendrite/roomserver/api"
|
||||
"github.com/matrix-org/dendrite/setup/config"
|
||||
userapi "github.com/matrix-org/dendrite/userapi/api"
|
||||
|
|
@ -57,7 +58,7 @@ var (
|
|||
func CreateInvitesFrom3PIDInvites(
|
||||
req *http.Request, rsAPI api.FederationRoomserverAPI,
|
||||
cfg *config.FederationAPI,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
federation federationAPI.FederationClient,
|
||||
userAPI userapi.FederationUserAPI,
|
||||
) util.JSONResponse {
|
||||
var body invites
|
||||
|
|
@ -107,7 +108,7 @@ func ExchangeThirdPartyInvite(
|
|||
roomID string,
|
||||
rsAPI api.FederationRoomserverAPI,
|
||||
cfg *config.FederationAPI,
|
||||
federation *gomatrixserverlib.FederationClient,
|
||||
federation federationAPI.FederationClient,
|
||||
) util.JSONResponse {
|
||||
var builder gomatrixserverlib.EventBuilder
|
||||
if err := json.Unmarshal(request.Content(), &builder); err != nil {
|
||||
|
|
@ -165,7 +166,8 @@ func ExchangeThirdPartyInvite(
|
|||
|
||||
// Ask the requesting server to sign the newly created event so we know it
|
||||
// acknowledged it
|
||||
signedEvent, err := federation.SendInvite(httpReq.Context(), request.Origin(), event)
|
||||
inviteReq, err := gomatrixserverlib.NewInviteV2Request(event.Headered(verRes.RoomVersion), nil)
|
||||
signedEvent, err := federation.SendInviteV2(httpReq.Context(), request.Origin(), inviteReq)
|
||||
if err != nil {
|
||||
util.GetLogger(httpReq.Context()).WithError(err).Error("federation.SendInvite failed")
|
||||
return jsonerror.InternalServerError()
|
||||
|
|
@ -205,7 +207,7 @@ func ExchangeThirdPartyInvite(
|
|||
func createInviteFrom3PIDInvite(
|
||||
ctx context.Context, rsAPI api.FederationRoomserverAPI,
|
||||
cfg *config.FederationAPI,
|
||||
inv invite, federation *gomatrixserverlib.FederationClient,
|
||||
inv invite, federation federationAPI.FederationClient,
|
||||
userAPI userapi.FederationUserAPI,
|
||||
) (*gomatrixserverlib.Event, error) {
|
||||
verReq := api.QueryRoomVersionForRoomRequest{RoomID: inv.RoomID}
|
||||
|
|
@ -335,7 +337,7 @@ func buildMembershipEvent(
|
|||
// them responded with an error.
|
||||
func sendToRemoteServer(
|
||||
ctx context.Context, inv invite,
|
||||
federation *gomatrixserverlib.FederationClient, _ *config.FederationAPI,
|
||||
federation federationAPI.FederationClient, _ *config.FederationAPI,
|
||||
builder gomatrixserverlib.EventBuilder,
|
||||
) (err error) {
|
||||
remoteServers := make([]gomatrixserverlib.ServerName, 2)
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ type DeviceListUpdater struct {
|
|||
db DeviceListUpdaterDatabase
|
||||
api DeviceListUpdaterAPI
|
||||
producer KeyChangeProducer
|
||||
fedClient fedsenderapi.FederationClient
|
||||
fedClient fedsenderapi.KeyserverFederationAPI
|
||||
workerChans []chan gomatrixserverlib.ServerName
|
||||
|
||||
// When device lists are stale for a user, they get inserted into this map with a channel which `Update` will
|
||||
|
|
@ -127,7 +127,7 @@ type KeyChangeProducer interface {
|
|||
// NewDeviceListUpdater creates a new updater which fetches fresh device lists when they go stale.
|
||||
func NewDeviceListUpdater(
|
||||
db DeviceListUpdaterDatabase, api DeviceListUpdaterAPI, producer KeyChangeProducer,
|
||||
fedClient fedsenderapi.FederationClient, numWorkers int,
|
||||
fedClient fedsenderapi.KeyserverFederationAPI, numWorkers int,
|
||||
) *DeviceListUpdater {
|
||||
return &DeviceListUpdater{
|
||||
userIDToMutex: make(map[string]*sync.Mutex),
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ import (
|
|||
type KeyInternalAPI struct {
|
||||
DB storage.Database
|
||||
ThisServer gomatrixserverlib.ServerName
|
||||
FedClient fedsenderapi.FederationClient
|
||||
FedClient fedsenderapi.KeyserverFederationAPI
|
||||
UserAPI userapi.KeyserverUserAPI
|
||||
Producer *producers.KeyChange
|
||||
Updater *DeviceListUpdater
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ func AddInternalRoutes(router *mux.Router, intAPI api.KeyInternalAPI) {
|
|||
// NewInternalAPI returns a concerete implementation of the internal API. Callers
|
||||
// can call functions directly on the returned API or via an HTTP interface using AddInternalRoutes.
|
||||
func NewInternalAPI(
|
||||
base *base.BaseDendrite, cfg *config.KeyServer, fedClient fedsenderapi.FederationClient,
|
||||
base *base.BaseDendrite, cfg *config.KeyServer, fedClient fedsenderapi.KeyserverFederationAPI,
|
||||
) api.KeyInternalAPI {
|
||||
js, _ := base.NATS.Prepare(base.ProcessContext, &cfg.Matrix.JetStream)
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,18 @@ func WithUnsigned(unsigned interface{}) eventModifier {
|
|||
}
|
||||
}
|
||||
|
||||
func WithKeyID(keyID gomatrixserverlib.KeyID) eventModifier {
|
||||
return func(e *eventMods) {
|
||||
e.keyID = keyID
|
||||
}
|
||||
}
|
||||
|
||||
func WithPrivateKey(pkey ed25519.PrivateKey) eventModifier {
|
||||
return func(e *eventMods) {
|
||||
e.privKey = pkey
|
||||
}
|
||||
}
|
||||
|
||||
// Reverse a list of events
|
||||
func Reversed(in []*gomatrixserverlib.HeaderedEvent) []*gomatrixserverlib.HeaderedEvent {
|
||||
out := make([]*gomatrixserverlib.HeaderedEvent, len(in))
|
||||
|
|
|
|||
41
test/room.go
41
test/room.go
|
|
@ -36,8 +36,8 @@ var (
|
|||
|
||||
roomIDCounter = int64(0)
|
||||
|
||||
testKeyID = gomatrixserverlib.KeyID("ed25519:test")
|
||||
testPrivateKey = ed25519.NewKeyFromSeed([]byte{
|
||||
KeyID = gomatrixserverlib.KeyID("ed25519:test")
|
||||
PrivateKey = ed25519.NewKeyFromSeed([]byte{
|
||||
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
|
||||
17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,
|
||||
})
|
||||
|
|
@ -50,6 +50,7 @@ type Room struct {
|
|||
creator *User
|
||||
|
||||
authEvents gomatrixserverlib.AuthEvents
|
||||
currentState map[string]*gomatrixserverlib.HeaderedEvent
|
||||
events []*gomatrixserverlib.HeaderedEvent
|
||||
}
|
||||
|
||||
|
|
@ -65,6 +66,7 @@ func NewRoom(t *testing.T, creator *User, modifiers ...roomModifier) *Room {
|
|||
authEvents: gomatrixserverlib.NewAuthEvents(nil),
|
||||
preset: PresetPublicChat,
|
||||
Version: gomatrixserverlib.RoomVersionV9,
|
||||
currentState: make(map[string]*gomatrixserverlib.HeaderedEvent),
|
||||
}
|
||||
for _, m := range modifiers {
|
||||
m(t, r)
|
||||
|
|
@ -73,6 +75,24 @@ func NewRoom(t *testing.T, creator *User, modifiers ...roomModifier) *Room {
|
|||
return r
|
||||
}
|
||||
|
||||
func (r *Room) MustGetAuthEventRefsForEvent(t *testing.T, needed gomatrixserverlib.StateNeeded) []gomatrixserverlib.EventReference {
|
||||
t.Helper()
|
||||
a, err := needed.AuthEventReferences(&r.authEvents)
|
||||
if err != nil {
|
||||
t.Fatalf("MustGetAuthEvents: %v", err)
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func (r *Room) ForwardExtremities() []string {
|
||||
if len(r.events) == 0 {
|
||||
return nil
|
||||
}
|
||||
return []string{
|
||||
r.events[len(r.events)-1].EventID(),
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Room) insertCreateEvents(t *testing.T) {
|
||||
t.Helper()
|
||||
var joinRule gomatrixserverlib.JoinRuleContent
|
||||
|
|
@ -112,10 +132,10 @@ func (r *Room) CreateEvent(t *testing.T, creator *User, eventType string, conten
|
|||
}
|
||||
|
||||
if mod.privKey == nil {
|
||||
mod.privKey = testPrivateKey
|
||||
mod.privKey = PrivateKey
|
||||
}
|
||||
if mod.keyID == "" {
|
||||
mod.keyID = testKeyID
|
||||
mod.keyID = KeyID
|
||||
}
|
||||
if mod.originServerTS.IsZero() {
|
||||
mod.originServerTS = time.Now()
|
||||
|
|
@ -174,13 +194,14 @@ func (r *Room) CreateEvent(t *testing.T, creator *User, eventType string, conten
|
|||
// Add a new event to this room DAG. Not thread-safe.
|
||||
func (r *Room) InsertEvent(t *testing.T, he *gomatrixserverlib.HeaderedEvent) {
|
||||
t.Helper()
|
||||
// Add the event to the list of auth events
|
||||
// Add the event to the list of auth/state events
|
||||
r.events = append(r.events, he)
|
||||
if he.StateKey() != nil {
|
||||
err := r.authEvents.AddEvent(he.Unwrap())
|
||||
if err != nil {
|
||||
t.Fatalf("InsertEvent: failed to add event to auth events: %s", err)
|
||||
}
|
||||
r.currentState[he.Type()+" "+*he.StateKey()] = he
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -188,6 +209,16 @@ func (r *Room) Events() []*gomatrixserverlib.HeaderedEvent {
|
|||
return r.events
|
||||
}
|
||||
|
||||
func (r *Room) CurrentState() []*gomatrixserverlib.HeaderedEvent {
|
||||
events := make([]*gomatrixserverlib.HeaderedEvent, len(r.currentState))
|
||||
i := 0
|
||||
for _, e := range r.currentState {
|
||||
events[i] = e
|
||||
i++
|
||||
}
|
||||
return events
|
||||
}
|
||||
|
||||
func (r *Room) CreateAndInsert(t *testing.T, creator *User, eventType string, content interface{}, mods ...eventModifier) *gomatrixserverlib.HeaderedEvent {
|
||||
t.Helper()
|
||||
he := r.CreateEvent(t, creator, eventType, content, mods...)
|
||||
|
|
|
|||
Loading…
Reference in a new issue