mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 13:22:46 +00:00
Add pseudoID compatibility to Invites (#3126)
This commit is contained in:
parent
fea946d914
commit
d507c5fc95
17 changed files with 358 additions and 136 deletions
|
@ -54,11 +54,14 @@ func NewFederationInternalAPI(
|
|||
KeyDatabase: serverKeyDB,
|
||||
}
|
||||
|
||||
pubKey := cfg.Matrix.PrivateKey.Public().(ed25519.PublicKey)
|
||||
addDirectFetcher := func() {
|
||||
keyRing.KeyFetchers = append(
|
||||
keyRing.KeyFetchers,
|
||||
&gomatrixserverlib.DirectKeyFetcher{
|
||||
Client: federation,
|
||||
Client: federation,
|
||||
IsLocalServerName: cfg.Matrix.IsLocalServerName,
|
||||
LocalPublicKey: []byte(pubKey),
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
@ -599,6 +599,58 @@ func (r *FederationInternalAPI) SendInvite(
|
|||
return inviteEvent, nil
|
||||
}
|
||||
|
||||
// SendInviteV3 implements api.FederationInternalAPI
|
||||
func (r *FederationInternalAPI) SendInviteV3(
|
||||
ctx context.Context,
|
||||
event gomatrixserverlib.ProtoEvent,
|
||||
invitee spec.UserID,
|
||||
version gomatrixserverlib.RoomVersion,
|
||||
strippedState []gomatrixserverlib.InviteStrippedState,
|
||||
) (gomatrixserverlib.PDU, error) {
|
||||
validRoomID, err := spec.NewRoomID(event.RoomID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
verImpl, err := gomatrixserverlib.GetRoomVersion(version)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
inviter, err := r.rsAPI.QueryUserIDForSender(ctx, *validRoomID, spec.SenderID(event.SenderID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO (devon): This should be allowed via a relay. Currently only transactions
|
||||
// can be sent to relays. Would need to extend relays to handle invites.
|
||||
if !r.shouldAttemptDirectFederation(invitee.Domain()) {
|
||||
return nil, fmt.Errorf("relay servers have no meaningful response for invite.")
|
||||
}
|
||||
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"user_id": invitee.String(),
|
||||
"room_id": event.RoomID,
|
||||
"room_version": version,
|
||||
"destination": invitee.Domain(),
|
||||
}).Info("Sending invite")
|
||||
|
||||
inviteReq, err := fclient.NewInviteV3Request(event, version, strippedState)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("gomatrixserverlib.NewInviteV3Request: %w", err)
|
||||
}
|
||||
|
||||
inviteRes, err := r.federation.SendInviteV3(ctx, inviter.Domain(), invitee.Domain(), inviteReq, invitee)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("r.federation.SendInviteV3: failed to send invite: %w", err)
|
||||
}
|
||||
|
||||
inviteEvent, err := verImpl.NewEventFromUntrustedJSON(inviteRes.Event)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("r.federation.SendInviteV3 failed to decode event response: %w", err)
|
||||
}
|
||||
return inviteEvent, nil
|
||||
}
|
||||
|
||||
// PerformServersAlive implements api.FederationInternalAPI
|
||||
func (r *FederationInternalAPI) PerformBroadcastEDU(
|
||||
ctx context.Context,
|
||||
|
|
|
@ -16,6 +16,7 @@ package internal
|
|||
|
||||
import (
|
||||
"context"
|
||||
"crypto/ed25519"
|
||||
"testing"
|
||||
|
||||
"github.com/matrix-org/dendrite/federationapi/api"
|
||||
|
@ -53,10 +54,14 @@ func TestPerformWakeupServers(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.True(t, offline)
|
||||
|
||||
_, key, err := ed25519.GenerateKey(nil)
|
||||
assert.NoError(t, err)
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "relay",
|
||||
KeyID: "ed25519:1",
|
||||
PrivateKey: key,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -95,10 +100,14 @@ func TestQueryRelayServers(t *testing.T) {
|
|||
err := testDB.P2PAddRelayServersForServer(context.Background(), server, relayServers)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, key, err := ed25519.GenerateKey(nil)
|
||||
assert.NoError(t, err)
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "relay",
|
||||
KeyID: "ed25519:1",
|
||||
PrivateKey: key,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -132,10 +141,14 @@ func TestRemoveRelayServers(t *testing.T) {
|
|||
err := testDB.P2PAddRelayServersForServer(context.Background(), server, relayServers)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, key, err := ed25519.GenerateKey(nil)
|
||||
assert.NoError(t, err)
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "relay",
|
||||
KeyID: "ed25519:1",
|
||||
PrivateKey: key,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -168,10 +181,14 @@ func TestRemoveRelayServers(t *testing.T) {
|
|||
func TestPerformDirectoryLookup(t *testing.T) {
|
||||
testDB := test.NewInMemoryFederationDatabase()
|
||||
|
||||
_, key, err := ed25519.GenerateKey(nil)
|
||||
assert.NoError(t, err)
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: "relay",
|
||||
KeyID: "ed25519:1",
|
||||
PrivateKey: key,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -192,7 +209,7 @@ func TestPerformDirectoryLookup(t *testing.T) {
|
|||
ServerName: "server",
|
||||
}
|
||||
res := api.PerformDirectoryLookupResponse{}
|
||||
err := fedAPI.PerformDirectoryLookup(context.Background(), &req, &res)
|
||||
err = fedAPI.PerformDirectoryLookup(context.Background(), &req, &res)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
|
@ -203,10 +220,14 @@ func TestPerformDirectoryLookupRelaying(t *testing.T) {
|
|||
testDB.SetServerAssumedOffline(context.Background(), server)
|
||||
testDB.P2PAddRelayServersForServer(context.Background(), server, []spec.ServerName{"relay"})
|
||||
|
||||
_, key, err := ed25519.GenerateKey(nil)
|
||||
assert.NoError(t, err)
|
||||
cfg := config.FederationAPI{
|
||||
Matrix: &config.Global{
|
||||
SigningIdentity: fclient.SigningIdentity{
|
||||
ServerName: server,
|
||||
ServerName: "relay",
|
||||
KeyID: "ed25519:1",
|
||||
PrivateKey: key,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
@ -227,6 +248,6 @@ func TestPerformDirectoryLookupRelaying(t *testing.T) {
|
|||
ServerName: server,
|
||||
}
|
||||
res := api.PerformDirectoryLookupResponse{}
|
||||
err := fedAPI.PerformDirectoryLookup(context.Background(), &req, &res)
|
||||
err = fedAPI.PerformDirectoryLookup(context.Background(), &req, &res)
|
||||
assert.Error(t, err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue