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
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
"github.com/matrix-org/dendrite/federationapi/types"
|
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"
|
2020-04-29 11:34:31 +01:00
|
|
|
)
|
|
|
|
|
2020-08-20 17:03:07 +01:00
|
|
|
// FederationClient is a subset of gomatrixserverlib.FederationClient functions which the fedsender
|
|
|
|
// implements as proxy calls, with built-in backoff/retries/etc. Errors returned from functions in
|
|
|
|
// this interface are of type FederationClientError
|
|
|
|
type FederationClient interface {
|
2020-09-02 15:26:30 +01:00
|
|
|
gomatrixserverlib.BackfillClient
|
|
|
|
gomatrixserverlib.FederatedStateClient
|
2020-08-20 17:03:07 +01:00
|
|
|
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)
|
2020-09-02 15:26:30 +01:00
|
|
|
GetEvent(ctx context.Context, s gomatrixserverlib.ServerName, eventID string) (res gomatrixserverlib.Transaction, err error)
|
2020-12-04 14:11:01 +00:00
|
|
|
MSC2836EventRelationships(ctx context.Context, dst gomatrixserverlib.ServerName, r gomatrixserverlib.MSC2836EventRelationshipsRequest, roomVersion gomatrixserverlib.RoomVersion) (res gomatrixserverlib.MSC2836EventRelationshipsResponse, err error)
|
2022-03-01 13:40:07 +00:00
|
|
|
MSC2946Spaces(ctx context.Context, dst gomatrixserverlib.ServerName, roomID string, suggestedOnly bool) (res gomatrixserverlib.MSC2946SpacesResponse, err error)
|
2020-09-22 14:40:54 +01:00
|
|
|
LookupServerKeys(ctx context.Context, s gomatrixserverlib.ServerName, keyRequests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp) ([]gomatrixserverlib.ServerKeys, error)
|
2022-01-27 14:29:14 +00:00
|
|
|
GetEventAuth(ctx context.Context, s gomatrixserverlib.ServerName, roomVersion gomatrixserverlib.RoomVersion, roomID, eventID string) (res gomatrixserverlib.RespEventAuth, err error)
|
|
|
|
LookupMissingEvents(ctx context.Context, s gomatrixserverlib.ServerName, roomID string, missing gomatrixserverlib.MissingEvents, roomVersion gomatrixserverlib.RoomVersion) (res gomatrixserverlib.RespMissingEvents, err error)
|
2020-08-20 17:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// FederationClientError is returned from FederationClient methods in the event of a problem.
|
|
|
|
type FederationClientError struct {
|
|
|
|
Err string
|
|
|
|
RetryAfter time.Duration
|
|
|
|
Blacklisted bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (e *FederationClientError) Error() string {
|
2020-09-08 13:41:08 +01:00
|
|
|
return fmt.Sprintf("%s - (retry_after=%s, blacklisted=%v)", e.Err, e.RetryAfter.String(), e.Blacklisted)
|
2020-08-20 17:03:07 +01:00
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
// FederationInternalAPI is used to query information from the federation sender.
|
|
|
|
type FederationInternalAPI interface {
|
2020-08-20 17:03:07 +01:00
|
|
|
FederationClient
|
2021-11-24 10:45:23 +00:00
|
|
|
gomatrixserverlib.KeyDatabase
|
|
|
|
|
|
|
|
KeyRing() *gomatrixserverlib.KeyRing
|
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
|
|
|
|
|
2020-05-04 13:53:47 +01:00
|
|
|
// PerformDirectoryLookup looks up a remote room ID from a room alias.
|
|
|
|
PerformDirectoryLookup(
|
|
|
|
ctx context.Context,
|
|
|
|
request *PerformDirectoryLookupRequest,
|
|
|
|
response *PerformDirectoryLookupResponse,
|
|
|
|
) error
|
2020-04-29 11:34:31 +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).
|
2020-11-19 11:34:59 +00:00
|
|
|
// The response will include this server if they are joined to the room.
|
2020-04-29 11:34:31 +01:00
|
|
|
QueryJoinedHostServerNamesInRoom(
|
|
|
|
ctx context.Context,
|
|
|
|
request *QueryJoinedHostServerNamesInRoomRequest,
|
|
|
|
response *QueryJoinedHostServerNamesInRoomResponse,
|
|
|
|
) error
|
|
|
|
// Handle an instruction to make_join & send_join with a remote server.
|
2020-04-29 15:29:39 +01:00
|
|
|
PerformJoin(
|
2020-04-29 11:34:31 +01:00
|
|
|
ctx context.Context,
|
|
|
|
request *PerformJoinRequest,
|
|
|
|
response *PerformJoinResponse,
|
2020-06-25 15:04:48 +01:00
|
|
|
)
|
2021-01-22 14:55:08 +00:00
|
|
|
// Handle an instruction to peek a room on a remote server.
|
|
|
|
PerformOutboundPeek(
|
|
|
|
ctx context.Context,
|
|
|
|
request *PerformOutboundPeekRequest,
|
|
|
|
response *PerformOutboundPeekResponse,
|
|
|
|
) error
|
2020-04-29 11:34:31 +01:00
|
|
|
// Handle an instruction to make_leave & send_leave with a remote server.
|
2020-04-29 15:29:39 +01:00
|
|
|
PerformLeave(
|
2020-04-29 11:34:31 +01:00
|
|
|
ctx context.Context,
|
|
|
|
request *PerformLeaveRequest,
|
|
|
|
response *PerformLeaveResponse,
|
|
|
|
) error
|
2020-08-17 11:40:49 +01:00
|
|
|
// Handle sending an invite to a remote server.
|
|
|
|
PerformInvite(
|
|
|
|
ctx context.Context,
|
|
|
|
request *PerformInviteRequest,
|
|
|
|
response *PerformInviteResponse,
|
|
|
|
) error
|
2020-06-01 18:34:08 +01:00
|
|
|
// Notifies the federation sender that these servers may be online and to retry sending messages.
|
|
|
|
PerformServersAlive(
|
|
|
|
ctx context.Context,
|
|
|
|
request *PerformServersAliveRequest,
|
|
|
|
response *PerformServersAliveResponse,
|
|
|
|
) error
|
2020-07-16 13:52:08 +01:00
|
|
|
// Broadcasts an EDU to all servers in rooms we are joined to.
|
|
|
|
PerformBroadcastEDU(
|
|
|
|
ctx context.Context,
|
|
|
|
request *PerformBroadcastEDURequest,
|
|
|
|
response *PerformBroadcastEDUResponse,
|
|
|
|
) error
|
2020-04-29 11:34:31 +01:00
|
|
|
}
|
|
|
|
|
2021-07-15 17:45:37 +01:00
|
|
|
type QueryServerKeysRequest struct {
|
2021-07-16 11:35:42 +01:00
|
|
|
ServerName gomatrixserverlib.ServerName
|
|
|
|
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 {
|
|
|
|
Requests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp `json:"requests"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type QueryPublicKeysResponse struct {
|
|
|
|
Results map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult `json:"results"`
|
|
|
|
}
|
|
|
|
|
2020-06-04 14:27:10 +01:00
|
|
|
type PerformDirectoryLookupRequest struct {
|
|
|
|
RoomAlias string `json:"room_alias"`
|
|
|
|
ServerName gomatrixserverlib.ServerName `json:"server_name"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PerformDirectoryLookupResponse struct {
|
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
ServerNames []gomatrixserverlib.ServerName `json:"server_names"`
|
|
|
|
}
|
|
|
|
|
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type PerformJoinResponse struct {
|
2020-11-19 11:34:59 +00:00
|
|
|
JoinedVia gomatrixserverlib.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 {
|
|
|
|
RoomVersion gomatrixserverlib.RoomVersion `json:"room_version"`
|
2020-11-16 15:44:53 +00:00
|
|
|
Event *gomatrixserverlib.HeaderedEvent `json:"event"`
|
2020-08-17 11:40:49 +01:00
|
|
|
InviteRoomState []gomatrixserverlib.InviteV2StrippedState `json:"invite_room_state"`
|
|
|
|
}
|
|
|
|
|
|
|
|
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-04 14:27:10 +01:00
|
|
|
type PerformServersAliveRequest struct {
|
|
|
|
Servers []gomatrixserverlib.ServerName
|
|
|
|
}
|
|
|
|
|
|
|
|
type PerformServersAliveResponse struct {
|
|
|
|
}
|
|
|
|
|
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-01-25 17:00:39 +00:00
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
ExcludeSelf bool `json:"exclude_self"`
|
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 {
|
|
|
|
ServerNames []gomatrixserverlib.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
|
|
|
|
|
|
|
type InputPublicKeysRequest struct {
|
|
|
|
Keys map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult `json:"keys"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type InputPublicKeysResponse struct {
|
|
|
|
}
|