2020-04-29 10:34:31 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-08-20 16:03:07 +00:00
|
|
|
"fmt"
|
|
|
|
"time"
|
2020-06-04 13:27:10 +00:00
|
|
|
|
2020-06-25 14:04:48 +00:00
|
|
|
"github.com/matrix-org/gomatrix"
|
2020-06-04 13:27:10 +00:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2023-04-06 08:55:01 +00:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
2023-04-19 14:50:33 +00:00
|
|
|
"github.com/matrix-org/gomatrixserverlib/spec"
|
2022-09-07 14:14:09 +00:00
|
|
|
|
|
|
|
"github.com/matrix-org/dendrite/federationapi/types"
|
2023-04-27 11:54:20 +00:00
|
|
|
rstypes "github.com/matrix-org/dendrite/roomserver/types"
|
2020-04-29 10:34:31 +00: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 12:23:35 +00:00
|
|
|
gomatrixserverlib.FederatedStateClient
|
2023-04-27 00:43:46 +00:00
|
|
|
gomatrixserverlib.FederatedJoinClient
|
2022-05-17 12:23:35 +00:00
|
|
|
KeyserverFederationAPI
|
2021-11-24 10:45:23 +00:00
|
|
|
gomatrixserverlib.KeyDatabase
|
2022-05-05 12:17:38 +00:00
|
|
|
ClientFederationAPI
|
2022-05-05 18:30:38 +00:00
|
|
|
RoomserverFederationAPI
|
2023-01-23 17:55:12 +00:00
|
|
|
P2PFederationAPI
|
2020-08-20 16:03:07 +00:00
|
|
|
|
2021-07-15 16:45:37 +00:00
|
|
|
QueryServerKeys(ctx context.Context, request *QueryServerKeysRequest, response *QueryServerKeysResponse) error
|
2023-04-19 14:50:33 +00: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)
|
2021-07-15 16:45:37 +00:00
|
|
|
|
2022-05-06 11:39:26 +00:00
|
|
|
// Broadcasts an EDU to all servers in rooms we are joined to. Used in the yggdrasil demos.
|
2020-07-16 12:52:08 +00: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 10:34:31 +00:00
|
|
|
}
|
|
|
|
|
2022-05-05 12:17:38 +00:00
|
|
|
type ClientFederationAPI interface {
|
2022-05-06 11:39:26 +00: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 12:17:38 +00:00
|
|
|
QueryJoinedHostServerNamesInRoom(ctx context.Context, request *QueryJoinedHostServerNamesInRoomRequest, response *QueryJoinedHostServerNamesInRoomResponse) error
|
|
|
|
}
|
|
|
|
|
2022-05-05 18:30:38 +00: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.
|
2023-05-31 16:33:49 +00:00
|
|
|
SendInvite(ctx context.Context, event gomatrixserverlib.PDU, strippedState []gomatrixserverlib.InviteStrippedState) (gomatrixserverlib.PDU, error)
|
2023-07-06 15:15:24 +00:00
|
|
|
// Handle sending an invite to a remote server.
|
|
|
|
SendInviteV3(ctx context.Context, event gomatrixserverlib.ProtoEvent, invitee spec.UserID, version gomatrixserverlib.RoomVersion, strippedState []gomatrixserverlib.InviteStrippedState) (gomatrixserverlib.PDU, error)
|
2022-05-05 18:30:38 +00:00
|
|
|
// 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 14:50:33 +00: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)
|
2023-07-20 14:06:05 +00:00
|
|
|
|
|
|
|
RoomHierarchies(ctx context.Context, origin, dst spec.ServerName, roomID string, suggestedOnly bool) (res fclient.RoomHierarchyResponse, err error)
|
2022-05-05 18:30:38 +00: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 12:23:35 +00:00
|
|
|
// KeyserverFederationAPI is a subset of gomatrixserverlib.FederationClient functions which the keyserver
|
2022-05-06 11:39:26 +00: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 12:23:35 +00:00
|
|
|
type KeyserverFederationAPI interface {
|
2023-04-19 14:50:33 +00: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 12:23:35 +00:00
|
|
|
}
|
|
|
|
|
2022-05-06 11:39:26 +00: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 14:14:09 +00:00
|
|
|
Code int // HTTP Status code from the remote server
|
2022-05-06 11:39:26 +00:00
|
|
|
}
|
|
|
|
|
2022-08-11 14:29:33 +00:00
|
|
|
func (e FederationClientError) Error() string {
|
2022-05-06 11:39:26 +00:00
|
|
|
return fmt.Sprintf("%s - (retry_after=%s, blacklisted=%v)", e.Err, e.RetryAfter.String(), e.Blacklisted)
|
|
|
|
}
|
|
|
|
|
2021-07-15 16:45:37 +00:00
|
|
|
type QueryServerKeysRequest struct {
|
2023-04-19 14:50:33 +00:00
|
|
|
ServerName spec.ServerName
|
2021-07-16 10:35:42 +00: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 16:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type QueryServerKeysResponse struct {
|
|
|
|
ServerKeys []gomatrixserverlib.ServerKeys
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
type QueryPublicKeysRequest struct {
|
2023-04-19 14:50:33 +00: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 13:27:10 +00:00
|
|
|
type PerformDirectoryLookupRequest struct {
|
2023-04-19 14:50:33 +00:00
|
|
|
RoomAlias string `json:"room_alias"`
|
|
|
|
ServerName spec.ServerName `json:"server_name"`
|
2020-06-04 13:27:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type PerformDirectoryLookupResponse struct {
|
2023-04-19 14:50:33 +00:00
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
ServerNames []spec.ServerName `json:"server_names"`
|
2020-06-04 13:27:10 +00: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 14:00:12 +00:00
|
|
|
Unsigned map[string]interface{} `json:"unsigned"`
|
2020-06-04 13:27:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type PerformJoinResponse struct {
|
2023-04-19 14:50:33 +00:00
|
|
|
JoinedVia spec.ServerName
|
2020-06-25 14:04:48 +00:00
|
|
|
LastError *gomatrix.HTTPError
|
2020-06-04 13:27:10 +00: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 13:27:10 +00: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 10:40:49 +00:00
|
|
|
type PerformInviteRequest struct {
|
2023-05-31 16:33:49 +00:00
|
|
|
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
|
|
|
Event *rstypes.HeaderedEvent `json:"event"`
|
|
|
|
InviteRoomState []gomatrixserverlib.InviteStrippedState `json:"invite_room_state"`
|
2020-08-17 10:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type PerformInviteResponse struct {
|
2023-04-27 11:54:20 +00:00
|
|
|
Event *rstypes.HeaderedEvent `json:"event"`
|
2020-08-17 10:40:49 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 14:07:16 +00:00
|
|
|
// QueryJoinedHostServerNamesInRoomRequest is a request to QueryJoinedHostServerNames
|
2020-06-04 13:27:10 +00: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 10:34:31 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 14:07:16 +00:00
|
|
|
// QueryJoinedHostServerNamesInRoomResponse is a response to QueryJoinedHostServerNames
|
2020-06-04 13:27:10 +00:00
|
|
|
type QueryJoinedHostServerNamesInRoomResponse struct {
|
2023-04-19 14:50:33 +00:00
|
|
|
ServerNames []spec.ServerName `json:"server_names"`
|
2020-04-29 10:34:31 +00:00
|
|
|
}
|
2020-07-16 12:52:08 +00: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 14:50:33 +00: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 14:50:33 +00:00
|
|
|
Server spec.ServerName
|
2023-01-23 17:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type P2PQueryRelayServersResponse struct {
|
2023-04-19 14:50:33 +00: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 14:50:33 +00:00
|
|
|
Server spec.ServerName
|
|
|
|
RelayServers []spec.ServerName
|
2023-01-28 23:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type P2PAddRelayServersResponse struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
type P2PRemoveRelayServersRequest struct {
|
2023-04-19 14:50:33 +00:00
|
|
|
Server spec.ServerName
|
|
|
|
RelayServers []spec.ServerName
|
2023-01-28 23:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type P2PRemoveRelayServersResponse struct {
|
|
|
|
}
|