2020-06-04 14:27:10 +01:00
|
|
|
package inthttp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"net/http"
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
"github.com/matrix-org/dendrite/federationapi/api"
|
|
|
|
"github.com/matrix-org/dendrite/internal/caching"
|
2020-06-12 14:55:57 +01:00
|
|
|
"github.com/matrix-org/dendrite/internal/httputil"
|
2020-06-25 15:04:48 +01:00
|
|
|
"github.com/matrix-org/gomatrix"
|
2020-08-20 17:03:07 +01:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2020-06-04 14:27:10 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// HTTP paths for the internal HTTP API
|
|
|
|
const (
|
2021-11-24 10:45:23 +00:00
|
|
|
FederationAPIQueryJoinedHostServerNamesInRoomPath = "/federationapi/queryJoinedHostServerNamesInRoom"
|
|
|
|
FederationAPIQueryServerKeysPath = "/federationapi/queryServerKeys"
|
|
|
|
|
|
|
|
FederationAPIPerformDirectoryLookupRequestPath = "/federationapi/performDirectoryLookup"
|
|
|
|
FederationAPIPerformJoinRequestPath = "/federationapi/performJoinRequest"
|
|
|
|
FederationAPIPerformLeaveRequestPath = "/federationapi/performLeaveRequest"
|
|
|
|
FederationAPIPerformInviteRequestPath = "/federationapi/performInviteRequest"
|
|
|
|
FederationAPIPerformOutboundPeekRequestPath = "/federationapi/performOutboundPeekRequest"
|
|
|
|
FederationAPIPerformBroadcastEDUPath = "/federationapi/performBroadcastEDU"
|
2022-11-18 00:29:23 +00:00
|
|
|
FederationAPIPerformWakeupServers = "/federationapi/performWakeupServers"
|
2021-11-24 10:45:23 +00:00
|
|
|
|
2022-01-27 14:29:14 +00:00
|
|
|
FederationAPIGetUserDevicesPath = "/federationapi/client/getUserDevices"
|
|
|
|
FederationAPIClaimKeysPath = "/federationapi/client/claimKeys"
|
|
|
|
FederationAPIQueryKeysPath = "/federationapi/client/queryKeys"
|
|
|
|
FederationAPIBackfillPath = "/federationapi/client/backfill"
|
|
|
|
FederationAPILookupStatePath = "/federationapi/client/lookupState"
|
|
|
|
FederationAPILookupStateIDsPath = "/federationapi/client/lookupStateIDs"
|
|
|
|
FederationAPILookupMissingEventsPath = "/federationapi/client/lookupMissingEvents"
|
|
|
|
FederationAPIGetEventPath = "/federationapi/client/getEvent"
|
|
|
|
FederationAPILookupServerKeysPath = "/federationapi/client/lookupServerKeys"
|
|
|
|
FederationAPIEventRelationshipsPath = "/federationapi/client/msc2836eventRelationships"
|
|
|
|
FederationAPISpacesSummaryPath = "/federationapi/client/msc2946spacesSummary"
|
|
|
|
FederationAPIGetEventAuthPath = "/federationapi/client/getEventAuth"
|
2021-11-24 10:45:23 +00:00
|
|
|
|
|
|
|
FederationAPIInputPublicKeyPath = "/federationapi/inputPublicKey"
|
|
|
|
FederationAPIQueryPublicKeyPath = "/federationapi/queryPublicKey"
|
2020-06-04 14:27:10 +01:00
|
|
|
)
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
// NewFederationAPIClient creates a FederationInternalAPI implemented by talking to a HTTP POST API.
|
2020-06-04 14:27:10 +01:00
|
|
|
// If httpClient is nil an error is returned
|
2021-11-24 10:45:23 +00:00
|
|
|
func NewFederationAPIClient(federationSenderURL string, httpClient *http.Client, cache caching.ServerKeyCache) (api.FederationInternalAPI, error) {
|
2020-06-04 14:27:10 +01:00
|
|
|
if httpClient == nil {
|
2021-11-24 10:45:23 +00:00
|
|
|
return nil, errors.New("NewFederationInternalAPIHTTP: httpClient is <nil>")
|
2020-06-04 14:27:10 +01:00
|
|
|
}
|
2022-08-11 15:29:33 +01:00
|
|
|
return &httpFederationInternalAPI{
|
|
|
|
federationAPIURL: federationSenderURL,
|
|
|
|
httpClient: httpClient,
|
|
|
|
cache: cache,
|
|
|
|
}, nil
|
2020-06-04 14:27:10 +01:00
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
type httpFederationInternalAPI struct {
|
|
|
|
federationAPIURL string
|
|
|
|
httpClient *http.Client
|
|
|
|
cache caching.ServerKeyCache
|
2020-06-04 14:27:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handle an instruction to make_leave & send_leave with a remote server.
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) PerformLeave(
|
2020-06-04 14:27:10 +01:00
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformLeaveRequest,
|
|
|
|
response *api.PerformLeaveResponse,
|
|
|
|
) error {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"PerformLeave", h.federationAPIURL+FederationAPIPerformLeaveRequestPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2020-06-04 14:27:10 +01:00
|
|
|
}
|
|
|
|
|
2020-08-17 11:40:49 +01:00
|
|
|
// Handle sending an invite to a remote server.
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) PerformInvite(
|
2020-08-17 11:40:49 +01:00
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformInviteRequest,
|
|
|
|
response *api.PerformInviteResponse,
|
|
|
|
) error {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"PerformInvite", h.federationAPIURL+FederationAPIPerformInviteRequestPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2020-08-17 11:40:49 +01:00
|
|
|
}
|
|
|
|
|
2021-01-22 14:55:08 +00:00
|
|
|
// Handle starting a peek on a remote server.
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) PerformOutboundPeek(
|
2021-01-22 14:55:08 +00:00
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformOutboundPeekRequest,
|
|
|
|
response *api.PerformOutboundPeekResponse,
|
|
|
|
) error {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"PerformOutboundPeek", h.federationAPIURL+FederationAPIPerformOutboundPeekRequestPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2021-01-22 14:55:08 +00:00
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
// QueryJoinedHostServerNamesInRoom implements FederationInternalAPI
|
|
|
|
func (h *httpFederationInternalAPI) QueryJoinedHostServerNamesInRoom(
|
2020-06-04 14:27:10 +01:00
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryJoinedHostServerNamesInRoomRequest,
|
|
|
|
response *api.QueryJoinedHostServerNamesInRoomResponse,
|
|
|
|
) error {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"QueryJoinedHostServerNamesInRoom", h.federationAPIURL+FederationAPIQueryJoinedHostServerNamesInRoomPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2020-06-04 14:27:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handle an instruction to make_join & send_join with a remote server.
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) PerformJoin(
|
2020-06-04 14:27:10 +01:00
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformJoinRequest,
|
|
|
|
response *api.PerformJoinResponse,
|
2020-06-25 15:04:48 +01:00
|
|
|
) {
|
2022-08-11 15:29:33 +01:00
|
|
|
if err := httputil.CallInternalRPCAPI(
|
|
|
|
"PerformJoinRequest", h.federationAPIURL+FederationAPIPerformJoinRequestPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
); err != nil {
|
2020-06-25 15:04:48 +01:00
|
|
|
response.LastError = &gomatrix.HTTPError{
|
|
|
|
Message: err.Error(),
|
|
|
|
Code: 0,
|
|
|
|
WrappedError: err,
|
|
|
|
}
|
|
|
|
}
|
2020-06-04 14:27:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Handle an instruction to make_join & send_join with a remote server.
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) PerformDirectoryLookup(
|
2020-06-04 14:27:10 +01:00
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformDirectoryLookupRequest,
|
|
|
|
response *api.PerformDirectoryLookupResponse,
|
|
|
|
) error {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"PerformDirectoryLookup", h.federationAPIURL+FederationAPIPerformDirectoryLookupRequestPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2020-06-04 14:27:10 +01:00
|
|
|
}
|
2020-07-16 13:52:08 +01:00
|
|
|
|
|
|
|
// Handle an instruction to broadcast an EDU to all servers in rooms we are joined to.
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) PerformBroadcastEDU(
|
2020-07-16 13:52:08 +01:00
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformBroadcastEDURequest,
|
|
|
|
response *api.PerformBroadcastEDUResponse,
|
|
|
|
) error {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"PerformBroadcastEDU", h.federationAPIURL+FederationAPIPerformBroadcastEDUPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2020-07-16 13:52:08 +01:00
|
|
|
}
|
2020-08-20 17:03:07 +01:00
|
|
|
|
2022-11-18 00:29:23 +00:00
|
|
|
// Handle an instruction to remove the respective servers from being blacklisted.
|
|
|
|
func (h *httpFederationInternalAPI) PerformWakeupServers(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformWakeupServersRequest,
|
|
|
|
response *api.PerformWakeupServersResponse,
|
|
|
|
) error {
|
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"PerformWakeupServers", h.federationAPIURL+FederationAPIPerformWakeupServers,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-08-20 17:03:07 +01:00
|
|
|
type getUserDevices struct {
|
|
|
|
S gomatrixserverlib.ServerName
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin gomatrixserverlib.ServerName
|
2020-08-20 17:03:07 +01:00
|
|
|
UserID string
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) GetUserDevices(
|
2022-11-15 15:05:23 +00:00
|
|
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, userID string,
|
2020-08-20 17:03:07 +01:00
|
|
|
) (gomatrixserverlib.RespUserDevices, error) {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalProxyAPI[getUserDevices, gomatrixserverlib.RespUserDevices, *api.FederationClientError](
|
|
|
|
"GetUserDevices", h.federationAPIURL+FederationAPIGetUserDevicesPath, h.httpClient,
|
|
|
|
ctx, &getUserDevices{
|
|
|
|
S: s,
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin: origin,
|
2022-08-11 15:29:33 +01:00
|
|
|
UserID: userID,
|
|
|
|
},
|
|
|
|
)
|
2020-08-20 17:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type claimKeys struct {
|
|
|
|
S gomatrixserverlib.ServerName
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin gomatrixserverlib.ServerName
|
2020-08-20 17:03:07 +01:00
|
|
|
OneTimeKeys map[string]map[string]string
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) ClaimKeys(
|
2022-11-15 15:05:23 +00:00
|
|
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, oneTimeKeys map[string]map[string]string,
|
2020-08-20 17:03:07 +01:00
|
|
|
) (gomatrixserverlib.RespClaimKeys, error) {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalProxyAPI[claimKeys, gomatrixserverlib.RespClaimKeys, *api.FederationClientError](
|
|
|
|
"ClaimKeys", h.federationAPIURL+FederationAPIClaimKeysPath, h.httpClient,
|
|
|
|
ctx, &claimKeys{
|
|
|
|
S: s,
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin: origin,
|
2022-08-11 15:29:33 +01:00
|
|
|
OneTimeKeys: oneTimeKeys,
|
|
|
|
},
|
|
|
|
)
|
2020-08-20 17:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type queryKeys struct {
|
2022-11-15 15:05:23 +00:00
|
|
|
S gomatrixserverlib.ServerName
|
|
|
|
Origin gomatrixserverlib.ServerName
|
|
|
|
Keys map[string][]string
|
2020-08-20 17:03:07 +01:00
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) QueryKeys(
|
2022-11-15 15:05:23 +00:00
|
|
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, keys map[string][]string,
|
2020-08-20 17:03:07 +01:00
|
|
|
) (gomatrixserverlib.RespQueryKeys, error) {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalProxyAPI[queryKeys, gomatrixserverlib.RespQueryKeys, *api.FederationClientError](
|
|
|
|
"QueryKeys", h.federationAPIURL+FederationAPIQueryKeysPath, h.httpClient,
|
|
|
|
ctx, &queryKeys{
|
2022-11-15 15:05:23 +00:00
|
|
|
S: s,
|
|
|
|
Origin: origin,
|
|
|
|
Keys: keys,
|
2022-08-11 15:29:33 +01:00
|
|
|
},
|
|
|
|
)
|
2020-08-20 17:03:07 +01:00
|
|
|
}
|
2020-09-02 15:26:30 +01:00
|
|
|
|
|
|
|
type backfill struct {
|
|
|
|
S gomatrixserverlib.ServerName
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin gomatrixserverlib.ServerName
|
2020-09-02 15:26:30 +01:00
|
|
|
RoomID string
|
|
|
|
Limit int
|
|
|
|
EventIDs []string
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) Backfill(
|
2022-11-15 15:05:23 +00:00
|
|
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string, limit int, eventIDs []string,
|
2020-09-02 15:26:30 +01:00
|
|
|
) (gomatrixserverlib.Transaction, error) {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalProxyAPI[backfill, gomatrixserverlib.Transaction, *api.FederationClientError](
|
|
|
|
"Backfill", h.federationAPIURL+FederationAPIBackfillPath, h.httpClient,
|
|
|
|
ctx, &backfill{
|
|
|
|
S: s,
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin: origin,
|
2022-08-11 15:29:33 +01:00
|
|
|
RoomID: roomID,
|
|
|
|
Limit: limit,
|
|
|
|
EventIDs: eventIDs,
|
|
|
|
},
|
|
|
|
)
|
2020-09-02 15:26:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type lookupState struct {
|
|
|
|
S gomatrixserverlib.ServerName
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin gomatrixserverlib.ServerName
|
2020-09-02 15:26:30 +01:00
|
|
|
RoomID string
|
|
|
|
EventID string
|
|
|
|
RoomVersion gomatrixserverlib.RoomVersion
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) LookupState(
|
2022-11-15 15:05:23 +00:00
|
|
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, eventID string, roomVersion gomatrixserverlib.RoomVersion,
|
2020-09-02 15:26:30 +01:00
|
|
|
) (gomatrixserverlib.RespState, error) {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalProxyAPI[lookupState, gomatrixserverlib.RespState, *api.FederationClientError](
|
|
|
|
"LookupState", h.federationAPIURL+FederationAPILookupStatePath, h.httpClient,
|
|
|
|
ctx, &lookupState{
|
|
|
|
S: s,
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin: origin,
|
2022-08-11 15:29:33 +01:00
|
|
|
RoomID: roomID,
|
|
|
|
EventID: eventID,
|
|
|
|
RoomVersion: roomVersion,
|
|
|
|
},
|
|
|
|
)
|
2020-09-02 15:26:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type lookupStateIDs struct {
|
|
|
|
S gomatrixserverlib.ServerName
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin gomatrixserverlib.ServerName
|
2020-09-02 15:26:30 +01:00
|
|
|
RoomID string
|
|
|
|
EventID string
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) LookupStateIDs(
|
2022-11-15 15:05:23 +00:00
|
|
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID, eventID string,
|
2020-09-02 15:26:30 +01:00
|
|
|
) (gomatrixserverlib.RespStateIDs, error) {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalProxyAPI[lookupStateIDs, gomatrixserverlib.RespStateIDs, *api.FederationClientError](
|
|
|
|
"LookupStateIDs", h.federationAPIURL+FederationAPILookupStateIDsPath, h.httpClient,
|
|
|
|
ctx, &lookupStateIDs{
|
|
|
|
S: s,
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin: origin,
|
2022-08-11 15:29:33 +01:00
|
|
|
RoomID: roomID,
|
|
|
|
EventID: eventID,
|
|
|
|
},
|
|
|
|
)
|
2020-09-02 15:26:30 +01:00
|
|
|
}
|
|
|
|
|
2022-01-27 14:29:14 +00:00
|
|
|
type lookupMissingEvents struct {
|
|
|
|
S gomatrixserverlib.ServerName
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin gomatrixserverlib.ServerName
|
2022-01-27 14:29:14 +00:00
|
|
|
RoomID string
|
|
|
|
Missing gomatrixserverlib.MissingEvents
|
|
|
|
RoomVersion gomatrixserverlib.RoomVersion
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *httpFederationInternalAPI) LookupMissingEvents(
|
2022-11-15 15:05:23 +00:00
|
|
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, roomID string,
|
2022-01-27 14:29:14 +00:00
|
|
|
missing gomatrixserverlib.MissingEvents, roomVersion gomatrixserverlib.RoomVersion,
|
|
|
|
) (res gomatrixserverlib.RespMissingEvents, err error) {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalProxyAPI[lookupMissingEvents, gomatrixserverlib.RespMissingEvents, *api.FederationClientError](
|
|
|
|
"LookupMissingEvents", h.federationAPIURL+FederationAPILookupMissingEventsPath, h.httpClient,
|
|
|
|
ctx, &lookupMissingEvents{
|
|
|
|
S: s,
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin: origin,
|
2022-08-11 15:29:33 +01:00
|
|
|
RoomID: roomID,
|
|
|
|
Missing: missing,
|
|
|
|
RoomVersion: roomVersion,
|
|
|
|
},
|
|
|
|
)
|
2022-01-27 14:29:14 +00:00
|
|
|
}
|
|
|
|
|
2020-09-02 15:26:30 +01:00
|
|
|
type getEvent struct {
|
|
|
|
S gomatrixserverlib.ServerName
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin gomatrixserverlib.ServerName
|
2020-09-02 15:26:30 +01:00
|
|
|
EventID string
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) GetEvent(
|
2022-11-15 15:05:23 +00:00
|
|
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, eventID string,
|
2020-09-02 15:26:30 +01:00
|
|
|
) (gomatrixserverlib.Transaction, error) {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalProxyAPI[getEvent, gomatrixserverlib.Transaction, *api.FederationClientError](
|
|
|
|
"GetEvent", h.federationAPIURL+FederationAPIGetEventPath, h.httpClient,
|
|
|
|
ctx, &getEvent{
|
|
|
|
S: s,
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin: origin,
|
2022-08-11 15:29:33 +01:00
|
|
|
EventID: eventID,
|
|
|
|
},
|
|
|
|
)
|
2020-09-02 15:26:30 +01:00
|
|
|
}
|
2020-09-22 14:40:54 +01:00
|
|
|
|
2022-01-27 14:29:14 +00:00
|
|
|
type getEventAuth struct {
|
|
|
|
S gomatrixserverlib.ServerName
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin gomatrixserverlib.ServerName
|
2022-01-27 14:29:14 +00:00
|
|
|
RoomVersion gomatrixserverlib.RoomVersion
|
|
|
|
RoomID string
|
|
|
|
EventID string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *httpFederationInternalAPI) GetEventAuth(
|
2022-11-15 15:05:23 +00:00
|
|
|
ctx context.Context, origin, s gomatrixserverlib.ServerName,
|
2022-01-27 14:29:14 +00:00
|
|
|
roomVersion gomatrixserverlib.RoomVersion, roomID, eventID string,
|
|
|
|
) (gomatrixserverlib.RespEventAuth, error) {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalProxyAPI[getEventAuth, gomatrixserverlib.RespEventAuth, *api.FederationClientError](
|
|
|
|
"GetEventAuth", h.federationAPIURL+FederationAPIGetEventAuthPath, h.httpClient,
|
|
|
|
ctx, &getEventAuth{
|
|
|
|
S: s,
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin: origin,
|
2022-08-11 15:29:33 +01:00
|
|
|
RoomVersion: roomVersion,
|
|
|
|
RoomID: roomID,
|
|
|
|
EventID: eventID,
|
|
|
|
},
|
|
|
|
)
|
2022-01-27 14:29:14 +00:00
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) QueryServerKeys(
|
2021-07-15 17:45:37 +01:00
|
|
|
ctx context.Context, req *api.QueryServerKeysRequest, res *api.QueryServerKeysResponse,
|
|
|
|
) error {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"QueryServerKeys", h.federationAPIURL+FederationAPIQueryServerKeysPath,
|
|
|
|
h.httpClient, ctx, req, res,
|
|
|
|
)
|
2020-09-22 14:40:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type lookupServerKeys struct {
|
|
|
|
S gomatrixserverlib.ServerName
|
|
|
|
KeyRequests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) LookupServerKeys(
|
2020-09-22 14:40:54 +01:00
|
|
|
ctx context.Context, s gomatrixserverlib.ServerName, keyRequests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp,
|
|
|
|
) ([]gomatrixserverlib.ServerKeys, error) {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalProxyAPI[lookupServerKeys, []gomatrixserverlib.ServerKeys, *api.FederationClientError](
|
|
|
|
"LookupServerKeys", h.federationAPIURL+FederationAPILookupServerKeysPath, h.httpClient,
|
|
|
|
ctx, &lookupServerKeys{
|
|
|
|
S: s,
|
|
|
|
KeyRequests: keyRequests,
|
|
|
|
},
|
|
|
|
)
|
2020-09-22 14:40:54 +01:00
|
|
|
}
|
2020-12-04 14:11:01 +00:00
|
|
|
|
|
|
|
type eventRelationships struct {
|
|
|
|
S gomatrixserverlib.ServerName
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin gomatrixserverlib.ServerName
|
2020-12-04 14:11:01 +00:00
|
|
|
Req gomatrixserverlib.MSC2836EventRelationshipsRequest
|
|
|
|
RoomVer gomatrixserverlib.RoomVersion
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) MSC2836EventRelationships(
|
2022-11-15 15:05:23 +00:00
|
|
|
ctx context.Context, origin, s gomatrixserverlib.ServerName, r gomatrixserverlib.MSC2836EventRelationshipsRequest,
|
2020-12-04 14:11:01 +00:00
|
|
|
roomVersion gomatrixserverlib.RoomVersion,
|
|
|
|
) (res gomatrixserverlib.MSC2836EventRelationshipsResponse, err error) {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalProxyAPI[eventRelationships, gomatrixserverlib.MSC2836EventRelationshipsResponse, *api.FederationClientError](
|
|
|
|
"MSC2836EventRelationships", h.federationAPIURL+FederationAPIEventRelationshipsPath, h.httpClient,
|
|
|
|
ctx, &eventRelationships{
|
|
|
|
S: s,
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin: origin,
|
2022-08-11 15:29:33 +01:00
|
|
|
Req: r,
|
|
|
|
RoomVer: roomVersion,
|
|
|
|
},
|
|
|
|
)
|
2020-12-04 14:11:01 +00:00
|
|
|
}
|
2021-01-19 17:14:25 +00:00
|
|
|
|
|
|
|
type spacesReq struct {
|
2022-03-01 13:40:07 +00:00
|
|
|
S gomatrixserverlib.ServerName
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin gomatrixserverlib.ServerName
|
2022-03-01 13:40:07 +00:00
|
|
|
SuggestedOnly bool
|
|
|
|
RoomID string
|
2021-01-19 17:14:25 +00:00
|
|
|
}
|
|
|
|
|
2021-11-24 10:45:23 +00:00
|
|
|
func (h *httpFederationInternalAPI) MSC2946Spaces(
|
2022-11-15 15:05:23 +00:00
|
|
|
ctx context.Context, origin, dst gomatrixserverlib.ServerName, roomID string, suggestedOnly bool,
|
2021-01-19 17:14:25 +00:00
|
|
|
) (res gomatrixserverlib.MSC2946SpacesResponse, err error) {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalProxyAPI[spacesReq, gomatrixserverlib.MSC2946SpacesResponse, *api.FederationClientError](
|
|
|
|
"MSC2836EventRelationships", h.federationAPIURL+FederationAPISpacesSummaryPath, h.httpClient,
|
|
|
|
ctx, &spacesReq{
|
|
|
|
S: dst,
|
2022-11-15 15:05:23 +00:00
|
|
|
Origin: origin,
|
2022-08-11 15:29:33 +01:00
|
|
|
SuggestedOnly: suggestedOnly,
|
|
|
|
RoomID: roomID,
|
|
|
|
},
|
|
|
|
)
|
2021-01-19 17:14:25 +00:00
|
|
|
}
|
2021-11-24 10:45:23 +00:00
|
|
|
|
|
|
|
func (s *httpFederationInternalAPI) KeyRing() *gomatrixserverlib.KeyRing {
|
|
|
|
// This is a bit of a cheat - we tell gomatrixserverlib that this API is
|
|
|
|
// both the key database and the key fetcher. While this does have the
|
|
|
|
// rather unfortunate effect of preventing gomatrixserverlib from handling
|
|
|
|
// key fetchers directly, we can at least reimplement this behaviour on
|
|
|
|
// the other end of the API.
|
|
|
|
return &gomatrixserverlib.KeyRing{
|
|
|
|
KeyDatabase: s,
|
|
|
|
KeyFetchers: []gomatrixserverlib.KeyFetcher{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpFederationInternalAPI) FetcherName() string {
|
|
|
|
return "httpServerKeyInternalAPI"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpFederationInternalAPI) StoreKeys(
|
|
|
|
_ context.Context,
|
|
|
|
results map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult,
|
|
|
|
) error {
|
|
|
|
// Run in a background context - we don't want to stop this work just
|
|
|
|
// because the caller gives up waiting.
|
|
|
|
ctx := context.Background()
|
|
|
|
request := api.InputPublicKeysRequest{
|
|
|
|
Keys: make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult),
|
|
|
|
}
|
|
|
|
response := api.InputPublicKeysResponse{}
|
|
|
|
for req, res := range results {
|
|
|
|
request.Keys[req] = res
|
|
|
|
s.cache.StoreServerKey(req, res)
|
|
|
|
}
|
|
|
|
return s.InputPublicKeys(ctx, &request, &response)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *httpFederationInternalAPI) FetchKeys(
|
|
|
|
_ context.Context,
|
|
|
|
requests map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp,
|
|
|
|
) (map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult, error) {
|
|
|
|
// Run in a background context - we don't want to stop this work just
|
|
|
|
// because the caller gives up waiting.
|
|
|
|
ctx := context.Background()
|
|
|
|
result := make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult)
|
|
|
|
request := api.QueryPublicKeysRequest{
|
|
|
|
Requests: make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.Timestamp),
|
|
|
|
}
|
|
|
|
response := api.QueryPublicKeysResponse{
|
|
|
|
Results: make(map[gomatrixserverlib.PublicKeyLookupRequest]gomatrixserverlib.PublicKeyLookupResult),
|
|
|
|
}
|
|
|
|
for req, ts := range requests {
|
|
|
|
if res, ok := s.cache.GetServerKey(req, ts); ok {
|
|
|
|
result[req] = res
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
request.Requests[req] = ts
|
|
|
|
}
|
|
|
|
err := s.QueryPublicKeys(ctx, &request, &response)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
for req, res := range response.Results {
|
|
|
|
result[req] = res
|
|
|
|
s.cache.StoreServerKey(req, res)
|
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *httpFederationInternalAPI) InputPublicKeys(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.InputPublicKeysRequest,
|
|
|
|
response *api.InputPublicKeysResponse,
|
|
|
|
) error {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"InputPublicKey", h.federationAPIURL+FederationAPIInputPublicKeyPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2021-11-24 10:45:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (h *httpFederationInternalAPI) QueryPublicKeys(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryPublicKeysRequest,
|
|
|
|
response *api.QueryPublicKeysResponse,
|
|
|
|
) error {
|
2022-08-11 15:29:33 +01:00
|
|
|
return httputil.CallInternalRPCAPI(
|
|
|
|
"QueryPublicKeys", h.federationAPIURL+FederationAPIQueryPublicKeyPath,
|
|
|
|
h.httpClient, ctx, request, response,
|
|
|
|
)
|
2021-11-24 10:45:23 +00:00
|
|
|
}
|