2020-04-29 11:34:31 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-08-20 17:03:07 +01:00
|
|
|
"fmt"
|
|
|
|
"time"
|
2020-06-04 14:27:10 +01:00
|
|
|
|
2020-06-25 15:04:48 +01:00
|
|
|
"github.com/matrix-org/gomatrix"
|
2020-06-04 14:27:10 +01:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2023-04-06 09:55:01 +01:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
2023-04-19 15:50:33 +01:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
2022-09-07 15:14:09 +01:00
|
|
|
|
|
|
|
"github.com/matrix-org/dendrite/federationapi/types"
|
2020-04-29 11:34:31 +01:00
|
|
|
)
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
// FederationInternalAPI is used to query information from the federation sender.
|
|
|
|
type FederationInternalAPI interface {
|
2022-05-17 13:23:35 +01:00
|
|
|
gomatrixserverlib.FederatedStateClient
|
2023-04-27 01:43:46 +01:00
|
|
|
gomatrixserverlib.FederatedJoinClient
|
2022-05-17 13:23:35 +01:00
|
|
|
KeyserverFederationAPI
|
2021-11-24 10:45:23 +00:00
|
|
|
gomatrixserverlib.KeyDatabase
|
2022-05-05 13:17:38 +01:00
|
|
|
ClientFederationAPI
|
2022-05-05 19:30:38 +01:00
|
|
|
RoomserverFederationAPI
|
2023-01-23 17:55:12 +00:00
|
|
|
P2PFederationAPI
|
2020-08-20 17:03:07 +01:00
|
|
|
|
2021-07-15 17:45:37 +01:00
|
|
|
QueryServerKeys(ctx context.Context, request *QueryServerKeysRequest, response *QueryServerKeysResponse) error
|
2023-04-19 15:50:33 +01:00
|
|
|
LookupServerKeys(ctx context.Context, s spec.ServerName, keyRequests map[gomatrixserverlib.PublicKeyLookupRequest]spec.Timestamp) ([]gomatrixserverlib.ServerKeys, error)
|
|
|
|
MSC2836EventRelationships(ctx context.Context, origin, dst spec.ServerName, r fclient.MSC2836EventRelationshipsRequest, roomVersion gomatrixserverlib.RoomVersion) (res fclient.MSC2836EventRelationshipsResponse, err error)
|
|
|
|
MSC2946Spaces(ctx context.Context, origin, dst spec.ServerName, roomID string, suggestedOnly bool) (res fclient.MSC2946SpacesResponse, err error)
|
2021-07-15 17:45:37 +01:00
|
|
|
|
2022-05-06 12:39:26 +01:00
|
|
|
// Broadcasts an EDU to all servers in rooms we are joined to. Used in the yggdrasil demos.
|
2020-07-16 13:52:08 +01:00
|
|
|
PerformBroadcastEDU(
|
|
|
|
ctx context.Context,
|
|
|
|
request *PerformBroadcastEDURequest,
|
|
|
|
response *PerformBroadcastEDUResponse,
|
|
|
|
) error
|
2022-11-18 00:29:23 +00:00
|
|
|
PerformWakeupServers(
|
|
|
|
ctx context.Context,
|
|
|
|
request *PerformWakeupServersRequest,
|
|
|
|
response *PerformWakeupServersResponse,
|
|
|
|
) error
|
2020-04-29 11:34:31 +01:00
|
|
|
}
|
|
|
|
|
2022-05-05 13:17:38 +01:00
|
|
|
type ClientFederationAPI interface {
|
2022-05-06 12:39:26 +01:00
|
|
|
// Query the server names of the joined hosts in a room.
|
|
|
|
// Unlike QueryJoinedHostsInRoom, this function returns a de-duplicated slice
|
|
|
|
// containing only the server names (without information for membership events).
|
|
|
|
// The response will include this server if they are joined to the room.
|
2022-05-05 13:17:38 +01:00
|
|
|
QueryJoinedHostServerNamesInRoom(ctx context.Context, request *QueryJoinedHostServerNamesInRoomRequest, response *QueryJoinedHostServerNamesInRoomResponse) error
|
|
|
|
}
|
|
|
|
|
2022-05-05 19:30:38 +01:00
|
|
|
type RoomserverFederationAPI interface {
|
|
|
|
gomatrixserverlib.BackfillClient
|
|
|
|
gomatrixserverlib.FederatedStateClient
|
|
|
|
KeyRing() *gomatrixserverlib.KeyRing
|
|
|
|
|
|
|
|
// PerformDirectoryLookup looks up a remote room ID from a room alias.
|
|
|
|
PerformDirectoryLookup(ctx context.Context, request *PerformDirectoryLookupRequest, response *PerformDirectoryLookupResponse) error
|
|
|
|
// Handle an instruction to make_join & send_join with a remote server.
|
|
|
|
PerformJoin(ctx context.Context, request *PerformJoinRequest, response *PerformJoinResponse)
|
|
|
|
// Handle an instruction to make_leave & send_leave with a remote server.
|
|
|
|
PerformLeave(ctx context.Context, request *PerformLeaveRequest, response *PerformLeaveResponse) error
|
|
|
|
// Handle sending an invite to a remote server.
|
|
|
|
PerformInvite(ctx context.Context, request *PerformInviteRequest, response *PerformInviteResponse) error
|
|
|
|
// Handle an instruction to peek a room on a remote server.
|
|
|
|
PerformOutboundPeek(ctx context.Context, request *PerformOutboundPeekRequest, response *PerformOutboundPeekResponse) error
|
|
|
|
// Query the server names of the joined hosts in a room.
|
|
|
|
// Unlike QueryJoinedHostsInRoom, this function returns a de-duplicated slice
|
|
|
|
// containing only the server names (without information for membership events).
|
|
|
|
// The response will include this server if they are joined to the room.
|
|
|
|
QueryJoinedHostServerNamesInRoom(ctx context.Context, request *QueryJoinedHostServerNamesInRoomRequest, response *QueryJoinedHostServerNamesInRoomResponse) error
|
2023-04-19 15:50:33 +01:00
|
|
|
GetEventAuth(ctx context.Context, origin, s spec.ServerName, roomVersion gomatrixserverlib.RoomVersion, roomID, eventID string) (res fclient.RespEventAuth, err error)
|
|
|
|
GetEvent(ctx context.Context, origin, s spec.ServerName, eventID string) (res gomatrixserverlib.Transaction, err error)
|
|
|
|
LookupMissingEvents(ctx context.Context, origin, s spec.ServerName, roomID string, missing fclient.MissingEvents, roomVersion gomatrixserverlib.RoomVersion) (res fclient.RespMissingEvents, err error)
|
2022-05-05 19:30:38 +01:00
|
|
|
}
|
|
|
|
|
2023-01-23 17:55:12 +00:00
|
|
|
type P2PFederationAPI interface {
|
2023-01-28 23:27:53 +00:00
|
|
|
// Get the relay servers associated for the given server.
|
2023-01-23 17:55:12 +00:00
|
|
|
P2PQueryRelayServers(
|
|
|
|
ctx context.Context,
|
|
|
|
request *P2PQueryRelayServersRequest,
|
|
|
|
response *P2PQueryRelayServersResponse,
|
|
|
|
) error
|
2023-01-28 23:27:53 +00:00
|
|
|
|
|
|
|
// Add relay server associations to the given server.
|
|
|
|
P2PAddRelayServers(
|
|
|
|
ctx context.Context,
|
|
|
|
request *P2PAddRelayServersRequest,
|
|
|
|
response *P2PAddRelayServersResponse,
|
|
|
|
) error
|
|
|
|
|
|
|
|
// Remove relay server associations from the given server.
|
|
|
|
P2PRemoveRelayServers(
|
|
|
|
ctx context.Context,
|
|
|
|
request *P2PRemoveRelayServersRequest,
|
|
|
|
response *P2PRemoveRelayServersResponse,
|
|
|
|
) error
|
2023-01-23 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
2022-05-17 13:23:35 +01:00
|
|
|
// KeyserverFederationAPI is a subset of gomatrixserverlib.FederationClient functions which the keyserver
|
2022-05-06 12:39:26 +01:00
|
|
|
// implements as proxy calls, with built-in backoff/retries/etc. Errors returned from functions in
|
|
|
|
// this interface are of type FederationClientError
|
2022-05-17 13:23:35 +01:00
|
|
|
type KeyserverFederationAPI interface {
|
2023-04-19 15:50:33 +01:00
|
|
|
GetUserDevices(ctx context.Context, origin, s spec.ServerName, userID string) (res fclient.RespUserDevices, err error)
|
|
|
|
ClaimKeys(ctx context.Context, origin, s spec.ServerName, oneTimeKeys map[string]map[string]string) (res fclient.RespClaimKeys, err error)
|
|
|
|
QueryKeys(ctx context.Context, origin, s spec.ServerName, keys map[string][]string) (res fclient.RespQueryKeys, err error)
|
2022-05-17 13:23:35 +01:00
|
|
|
}
|
|
|
|
|
2022-05-06 12:39:26 +01:00
|
|
|
// FederationClientError is returned from FederationClient methods in the event of a problem.
|
|
|
|
type FederationClientError struct {
|
|
|
|
Err string
|
|
|
|
RetryAfter time.Duration
|
|
|
|
Blacklisted bool
|
2022-09-07 15:14:09 +01:00
|
|
|
Code int // HTTP Status code from the remote server
|
2022-05-06 12:39:26 +01:00
|
|
|
}
|
|
|
|
|
2022-08-11 15:29:33 +01:00
|
|
|
func (e FederationClientError) Error() string {
|
2022-05-06 12:39:26 +01:00
|
|
|
return fmt.Sprintf("%s - (retry_after=%s, blacklisted=%v)", e.Err, e.RetryAfter.String(), e.Blacklisted)
|
|
|
|
}
|
|
|
|
|
2021-07-15 17:45:37 +01:00
|
|
|
type QueryServerKeysRequest struct {
|
2023-04-19 15:50:33 +01:00
|
|
|
ServerName spec.ServerName
|
2021-07-16 11:35:42 +01:00
|
|
|
KeyIDToCriteria map[gomatrixserverlib.KeyID]gomatrixserverlib.PublicKeyNotaryQueryCriteria
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *QueryServerKeysRequest) KeyIDs() []gomatrixserverlib.KeyID {
|
|
|
|
kids := make([]gomatrixserverlib.KeyID, len(q.KeyIDToCriteria))
|
|
|
|
i := 0
|
|
|
|
for keyID := range q.KeyIDToCriteria {
|
|
|
|
kids[i] = keyID
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
return kids
|
2021-07-15 17:45:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type QueryServerKeysResponse struct {
|
|
|
|
ServerKeys []gomatrixserverlib.ServerKeys
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
type QueryPublicKeysRequest struct {
|
2023-04-19 15:50:33 +01:00
|
|
|
Requests map[gomatrixserverlib.PublicKeyLookupRequest]spec.Timestamp `json:"requests"`
|
2021-11-24 10:45:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type QueryPublicKeysResponse struct {
|
|
|
|
Results map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult `json:"results"`
|
|
|
|
}
|
|
|
|
|
2020-06-04 14:27:10 +01:00
|
|
|
type PerformDirectoryLookupRequest struct {
|
2023-04-19 15:50:33 +01:00
|
|
|
RoomAlias string `json:"room_alias"`
|
|
|
|
ServerName spec.ServerName `json:"server_name"`
|
2020-06-04 14:27:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type PerformDirectoryLookupResponse struct {
|
2023-04-19 15:50:33 +01:00
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
ServerNames []spec.ServerName `json:"server_names"`
|
2020-06-04 14:27:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type PerformJoinRequest struct {
|
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
UserID string `json:"user_id"`
|
|
|
|
// The sorted list of servers to try. Servers will be tried sequentially, after de-duplication.
|
|
|
|
ServerNames types.ServerNames `json:"server_names"`
|
|
|
|
Content map[string]interface{} `json:"content"`
|
2022-10-07 15:00:12 +01:00
|
|
|
Unsigned map[string]interface{} `json:"unsigned"`
|
2020-06-04 14:27:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type PerformJoinResponse struct {
|
2023-04-19 15:50:33 +01:00
|
|
|
JoinedVia spec.ServerName
|
2020-06-25 15:04:48 +01:00
|
|
|
LastError *gomatrix.HTTPError
|
2020-06-04 14:27:10 +01:00
|
|
|
}
|
|
|
|
|
2021-01-22 14:55:08 +00:00
|
|
|
type PerformOutboundPeekRequest struct {
|
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
// The sorted list of servers to try. Servers will be tried sequentially, after de-duplication.
|
|
|
|
ServerNames types.ServerNames `json:"server_names"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PerformOutboundPeekResponse struct {
|
|
|
|
LastError *gomatrix.HTTPError
|
|
|
|
}
|
|
|
|
|
2020-06-04 14:27:10 +01:00
|
|
|
type PerformLeaveRequest struct {
|
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
UserID string `json:"user_id"`
|
|
|
|
ServerNames types.ServerNames `json:"server_names"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PerformLeaveResponse struct {
|
|
|
|
}
|
|
|
|
|
2020-08-17 11:40:49 +01:00
|
|
|
type PerformInviteRequest struct {
|
2023-04-19 15:50:33 +01:00
|
|
|
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
|
|
|
Event *gomatrixserverlib.HeaderedEvent `json:"event"`
|
|
|
|
InviteRoomState []fclient.InviteV2StrippedState `json:"invite_room_state"`
|
2020-08-17 11:40:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type PerformInviteResponse struct {
|
2020-11-16 15:44:53 +00:00
|
|
|
Event *gomatrixserverlib.HeaderedEvent `json:"event"`
|
2020-08-17 11:40:49 +01:00
|
|
|
}
|
|
|
|
|
2020-06-11 15:07:16 +01:00
|
|
|
// QueryJoinedHostServerNamesInRoomRequest is a request to QueryJoinedHostServerNames
|
2020-06-04 14:27:10 +01:00
|
|
|
type QueryJoinedHostServerNamesInRoomRequest struct {
|
2022-11-15 17:21:16 +00:00
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
ExcludeSelf bool `json:"exclude_self"`
|
|
|
|
ExcludeBlacklisted bool `json:"exclude_blacklisted"`
|
2020-04-29 11:34:31 +01:00
|
|
|
}
|
|
|
|
|
2020-06-11 15:07:16 +01:00
|
|
|
// QueryJoinedHostServerNamesInRoomResponse is a response to QueryJoinedHostServerNames
|
2020-06-04 14:27:10 +01:00
|
|
|
type QueryJoinedHostServerNamesInRoomResponse struct {
|
2023-04-19 15:50:33 +01:00
|
|
|
ServerNames []spec.ServerName `json:"server_names"`
|
2020-04-29 11:34:31 +01:00
|
|
|
}
|
2020-07-16 13:52:08 +01:00
|
|
|
|
|
|
|
type PerformBroadcastEDURequest struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
type PerformBroadcastEDUResponse struct {
|
|
|
|
}
|
2021-11-24 10:45:23 +00:00
|
|
|
|
2022-11-18 00:29:23 +00:00
|
|
|
type PerformWakeupServersRequest struct {
|
2023-04-19 15:50:33 +01:00
|
|
|
ServerNames []spec.ServerName `json:"server_names"`
|
2022-11-18 00:29:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type PerformWakeupServersResponse struct {
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
type InputPublicKeysRequest struct {
|
|
|
|
Keys map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult `json:"keys"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type InputPublicKeysResponse struct {
|
|
|
|
}
|
2023-01-23 17:55:12 +00:00
|
|
|
|
|
|
|
type P2PQueryRelayServersRequest struct {
|
2023-04-19 15:50:33 +01:00
|
|
|
Server spec.ServerName
|
2023-01-23 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type P2PQueryRelayServersResponse struct {
|
2023-04-19 15:50:33 +01:00
|
|
|
RelayServers []spec.ServerName
|
2023-01-23 17:55:12 +00:00
|
|
|
}
|
2023-01-28 23:27:53 +00:00
|
|
|
|
|
|
|
type P2PAddRelayServersRequest struct {
|
2023-04-19 15:50:33 +01:00
|
|
|
Server spec.ServerName
|
|
|
|
RelayServers []spec.ServerName
|
2023-01-28 23:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type P2PAddRelayServersResponse struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
type P2PRemoveRelayServersRequest struct {
|
2023-04-19 15:50:33 +01:00
|
|
|
Server spec.ServerName
|
|
|
|
RelayServers []spec.ServerName
|
2023-01-28 23:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type P2PRemoveRelayServersResponse struct {
|
|
|
|
}
|