2020-06-04 14:43:07 +00:00
|
|
|
package inthttp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"errors"
|
2020-06-24 14:06:14 +00:00
|
|
|
"fmt"
|
2020-06-04 14:43:07 +00:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
fsInputAPI "github.com/matrix-org/dendrite/federationsender/api"
|
|
|
|
"github.com/matrix-org/dendrite/internal/caching"
|
2020-06-12 13:55:57 +00:00
|
|
|
"github.com/matrix-org/dendrite/internal/httputil"
|
2020-06-04 14:43:07 +00:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/api"
|
|
|
|
"github.com/opentracing/opentracing-go"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// Alias operations
|
|
|
|
RoomserverSetRoomAliasPath = "/roomserver/setRoomAlias"
|
|
|
|
RoomserverGetRoomIDForAliasPath = "/roomserver/GetRoomIDForAlias"
|
|
|
|
RoomserverGetAliasesForRoomIDPath = "/roomserver/GetAliasesForRoomID"
|
|
|
|
RoomserverGetCreatorIDForAliasPath = "/roomserver/GetCreatorIDForAlias"
|
|
|
|
RoomserverRemoveRoomAliasPath = "/roomserver/removeRoomAlias"
|
|
|
|
|
|
|
|
// Input operations
|
|
|
|
RoomserverInputRoomEventsPath = "/roomserver/inputRoomEvents"
|
|
|
|
|
|
|
|
// Perform operations
|
2020-06-24 14:06:14 +00:00
|
|
|
RoomserverPerformInvitePath = "/roomserver/performInvite"
|
2020-09-10 13:39:18 +00:00
|
|
|
RoomserverPerformPeekPath = "/roomserver/performPeek"
|
2020-06-11 18:50:40 +00:00
|
|
|
RoomserverPerformJoinPath = "/roomserver/performJoin"
|
|
|
|
RoomserverPerformLeavePath = "/roomserver/performLeave"
|
|
|
|
RoomserverPerformBackfillPath = "/roomserver/performBackfill"
|
2020-07-02 14:41:18 +00:00
|
|
|
RoomserverPerformPublishPath = "/roomserver/performPublish"
|
2020-06-04 14:43:07 +00:00
|
|
|
|
|
|
|
// Query operations
|
|
|
|
RoomserverQueryLatestEventsAndStatePath = "/roomserver/queryLatestEventsAndState"
|
|
|
|
RoomserverQueryStateAfterEventsPath = "/roomserver/queryStateAfterEvents"
|
2020-09-29 12:40:29 +00:00
|
|
|
RoomserverQueryMissingAuthPrevEventsPath = "/roomserver/queryMissingAuthPrevEvents"
|
2020-06-04 14:43:07 +00:00
|
|
|
RoomserverQueryEventsByIDPath = "/roomserver/queryEventsByID"
|
|
|
|
RoomserverQueryMembershipForUserPath = "/roomserver/queryMembershipForUser"
|
|
|
|
RoomserverQueryMembershipsForRoomPath = "/roomserver/queryMembershipsForRoom"
|
2020-09-24 15:18:13 +00:00
|
|
|
RoomserverQueryServerJoinedToRoomPath = "/roomserver/queryServerJoinedToRoomPath"
|
2020-06-04 14:43:07 +00:00
|
|
|
RoomserverQueryServerAllowedToSeeEventPath = "/roomserver/queryServerAllowedToSeeEvent"
|
|
|
|
RoomserverQueryMissingEventsPath = "/roomserver/queryMissingEvents"
|
|
|
|
RoomserverQueryStateAndAuthChainPath = "/roomserver/queryStateAndAuthChain"
|
|
|
|
RoomserverQueryRoomVersionCapabilitiesPath = "/roomserver/queryRoomVersionCapabilities"
|
|
|
|
RoomserverQueryRoomVersionForRoomPath = "/roomserver/queryRoomVersionForRoom"
|
2020-07-02 14:41:18 +00:00
|
|
|
RoomserverQueryPublishedRoomsPath = "/roomserver/queryPublishedRooms"
|
2020-09-03 16:20:54 +00:00
|
|
|
RoomserverQueryCurrentStatePath = "/roomserver/queryCurrentState"
|
|
|
|
RoomserverQueryRoomsForUserPath = "/roomserver/queryRoomsForUser"
|
|
|
|
RoomserverQueryBulkStateContentPath = "/roomserver/queryBulkStateContent"
|
|
|
|
RoomserverQuerySharedUsersPath = "/roomserver/querySharedUsers"
|
|
|
|
RoomserverQueryKnownUsersPath = "/roomserver/queryKnownUsers"
|
|
|
|
RoomserverQueryServerBannedFromRoomPath = "/roomserver/queryServerBannedFromRoom"
|
2020-06-04 14:43:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type httpRoomserverInternalAPI struct {
|
2020-06-05 15:42:01 +00:00
|
|
|
roomserverURL string
|
|
|
|
httpClient *http.Client
|
|
|
|
cache caching.RoomVersionCache
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewRoomserverClient creates a RoomserverInputAPI implemented by talking to a HTTP POST API.
|
|
|
|
// If httpClient is nil an error is returned
|
|
|
|
func NewRoomserverClient(
|
|
|
|
roomserverURL string,
|
|
|
|
httpClient *http.Client,
|
2020-06-05 15:42:01 +00:00
|
|
|
cache caching.RoomVersionCache,
|
2020-06-04 14:43:07 +00:00
|
|
|
) (api.RoomserverInternalAPI, error) {
|
|
|
|
if httpClient == nil {
|
|
|
|
return nil, errors.New("NewRoomserverInternalAPIHTTP: httpClient is <nil>")
|
|
|
|
}
|
|
|
|
return &httpRoomserverInternalAPI{
|
2020-06-05 15:42:01 +00:00
|
|
|
roomserverURL: roomserverURL,
|
|
|
|
httpClient: httpClient,
|
|
|
|
cache: cache,
|
2020-06-04 14:43:07 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2020-06-05 08:28:15 +00:00
|
|
|
// SetFederationSenderInputAPI no-ops in HTTP client mode as there is no chicken/egg scenario
|
2020-06-04 14:43:07 +00:00
|
|
|
func (h *httpRoomserverInternalAPI) SetFederationSenderAPI(fsAPI fsInputAPI.FederationSenderInternalAPI) {
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetRoomAlias implements RoomserverAliasAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) SetRoomAlias(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.SetRoomAliasRequest,
|
|
|
|
response *api.SetRoomAliasResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "SetRoomAlias")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverSetRoomAliasPath
|
2020-06-12 13:55:57 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetRoomIDForAlias implements RoomserverAliasAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) GetRoomIDForAlias(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.GetRoomIDForAliasRequest,
|
|
|
|
response *api.GetRoomIDForAliasResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "GetRoomIDForAlias")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverGetRoomIDForAliasPath
|
2020-06-12 13:55:57 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetAliasesForRoomID implements RoomserverAliasAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) GetAliasesForRoomID(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.GetAliasesForRoomIDRequest,
|
|
|
|
response *api.GetAliasesForRoomIDResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "GetAliasesForRoomID")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverGetAliasesForRoomIDPath
|
2020-06-12 13:55:57 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GetCreatorIDForAlias implements RoomserverAliasAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) GetCreatorIDForAlias(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.GetCreatorIDForAliasRequest,
|
|
|
|
response *api.GetCreatorIDForAliasResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "GetCreatorIDForAlias")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverGetCreatorIDForAliasPath
|
2020-06-12 13:55:57 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// RemoveRoomAlias implements RoomserverAliasAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) RemoveRoomAlias(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.RemoveRoomAliasRequest,
|
|
|
|
response *api.RemoveRoomAliasResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "RemoveRoomAlias")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverRemoveRoomAliasPath
|
2020-06-12 13:55:57 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// InputRoomEvents implements RoomserverInputAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) InputRoomEvents(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.InputRoomEventsRequest,
|
|
|
|
response *api.InputRoomEventsResponse,
|
2020-09-16 12:00:52 +00:00
|
|
|
) {
|
2020-06-04 14:43:07 +00:00
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "InputRoomEvents")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverInputRoomEventsPath
|
2020-09-16 12:00:52 +00:00
|
|
|
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
|
|
if err != nil {
|
|
|
|
response.ErrMsg = err.Error()
|
|
|
|
}
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 14:06:14 +00:00
|
|
|
func (h *httpRoomserverInternalAPI) PerformInvite(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformInviteRequest,
|
|
|
|
response *api.PerformInviteResponse,
|
2020-08-17 10:40:49 +00:00
|
|
|
) error {
|
2020-06-24 14:06:14 +00:00
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformInvite")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverPerformInvitePath
|
2020-08-17 10:40:49 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-24 14:06:14 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 14:43:07 +00:00
|
|
|
func (h *httpRoomserverInternalAPI) PerformJoin(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformJoinRequest,
|
|
|
|
response *api.PerformJoinResponse,
|
2020-06-24 14:06:14 +00:00
|
|
|
) {
|
2020-06-04 14:43:07 +00:00
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformJoin")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverPerformJoinPath
|
2020-06-24 14:06:14 +00:00
|
|
|
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
|
|
if err != nil {
|
|
|
|
response.Error = &api.PerformError{
|
|
|
|
Msg: fmt.Sprintf("failed to communicate with roomserver: %s", err),
|
|
|
|
}
|
|
|
|
}
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
2020-09-10 13:39:18 +00:00
|
|
|
func (h *httpRoomserverInternalAPI) PerformPeek(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformPeekRequest,
|
|
|
|
response *api.PerformPeekResponse,
|
|
|
|
) {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformPeek")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverPerformPeekPath
|
|
|
|
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
|
|
if err != nil {
|
|
|
|
response.Error = &api.PerformError{
|
|
|
|
Msg: fmt.Sprintf("failed to communicate with roomserver: %s", err),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-04 14:43:07 +00:00
|
|
|
func (h *httpRoomserverInternalAPI) PerformLeave(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformLeaveRequest,
|
|
|
|
response *api.PerformLeaveResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformLeave")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverPerformLeavePath
|
2020-06-12 13:55:57 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
2020-07-02 14:41:18 +00:00
|
|
|
func (h *httpRoomserverInternalAPI) PerformPublish(
|
|
|
|
ctx context.Context,
|
|
|
|
req *api.PerformPublishRequest,
|
|
|
|
res *api.PerformPublishResponse,
|
|
|
|
) {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformPublish")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverPerformPublishPath
|
|
|
|
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
|
|
|
if err != nil {
|
|
|
|
res.Error = &api.PerformError{
|
|
|
|
Msg: fmt.Sprintf("failed to communicate with roomserver: %s", err),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-04 14:43:07 +00:00
|
|
|
// QueryLatestEventsAndState implements RoomserverQueryAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryLatestEventsAndState(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryLatestEventsAndStateRequest,
|
|
|
|
response *api.QueryLatestEventsAndStateResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryLatestEventsAndState")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryLatestEventsAndStatePath
|
2020-06-12 13:55:57 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryStateAfterEvents implements RoomserverQueryAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryStateAfterEvents(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryStateAfterEventsRequest,
|
|
|
|
response *api.QueryStateAfterEventsResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryStateAfterEvents")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryStateAfterEventsPath
|
2020-06-12 13:55:57 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
2020-09-29 12:40:29 +00:00
|
|
|
// QueryStateAfterEvents implements RoomserverQueryAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryMissingAuthPrevEvents(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryMissingAuthPrevEventsRequest,
|
|
|
|
response *api.QueryMissingAuthPrevEventsResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryMissingAuthPrevEvents")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryMissingAuthPrevEventsPath
|
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
|
|
}
|
|
|
|
|
2020-06-04 14:43:07 +00:00
|
|
|
// QueryEventsByID implements RoomserverQueryAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryEventsByID(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryEventsByIDRequest,
|
|
|
|
response *api.QueryEventsByIDResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryEventsByID")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryEventsByIDPath
|
2020-06-12 13:55:57 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
2020-07-02 14:41:18 +00:00
|
|
|
func (h *httpRoomserverInternalAPI) QueryPublishedRooms(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryPublishedRoomsRequest,
|
|
|
|
response *api.QueryPublishedRoomsResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryPublishedRooms")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryPublishedRoomsPath
|
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
|
|
}
|
|
|
|
|
2020-06-04 14:43:07 +00:00
|
|
|
// QueryMembershipForUser implements RoomserverQueryAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryMembershipForUser(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryMembershipForUserRequest,
|
|
|
|
response *api.QueryMembershipForUserResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryMembershipForUser")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryMembershipForUserPath
|
2020-06-12 13:55:57 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryMembershipsForRoom implements RoomserverQueryAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryMembershipsForRoom(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryMembershipsForRoomRequest,
|
|
|
|
response *api.QueryMembershipsForRoomResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryMembershipsForRoom")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryMembershipsForRoomPath
|
2020-06-12 13:55:57 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
2020-09-24 15:18:13 +00:00
|
|
|
// QueryMembershipsForRoom implements RoomserverQueryAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryServerJoinedToRoom(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryServerJoinedToRoomRequest,
|
|
|
|
response *api.QueryServerJoinedToRoomResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryServerJoinedToRoom")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryServerJoinedToRoomPath
|
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
|
|
}
|
|
|
|
|
2020-06-04 14:43:07 +00:00
|
|
|
// QueryServerAllowedToSeeEvent implements RoomserverQueryAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryServerAllowedToSeeEvent(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryServerAllowedToSeeEventRequest,
|
|
|
|
response *api.QueryServerAllowedToSeeEventResponse,
|
|
|
|
) (err error) {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryServerAllowedToSeeEvent")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryServerAllowedToSeeEventPath
|
2020-06-12 13:55:57 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryMissingEvents implements RoomServerQueryAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryMissingEvents(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryMissingEventsRequest,
|
|
|
|
response *api.QueryMissingEventsResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryMissingEvents")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryMissingEventsPath
|
2020-06-12 13:55:57 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryStateAndAuthChain implements RoomserverQueryAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryStateAndAuthChain(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryStateAndAuthChainRequest,
|
|
|
|
response *api.QueryStateAndAuthChainResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryStateAndAuthChain")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryStateAndAuthChainPath
|
2020-06-12 13:55:57 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
2020-06-11 18:50:40 +00:00
|
|
|
// PerformBackfill implements RoomServerQueryAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) PerformBackfill(
|
2020-06-04 14:43:07 +00:00
|
|
|
ctx context.Context,
|
2020-06-11 18:50:40 +00:00
|
|
|
request *api.PerformBackfillRequest,
|
|
|
|
response *api.PerformBackfillResponse,
|
2020-06-04 14:43:07 +00:00
|
|
|
) error {
|
2020-06-11 18:50:40 +00:00
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformBackfill")
|
2020-06-04 14:43:07 +00:00
|
|
|
defer span.Finish()
|
|
|
|
|
2020-06-11 18:50:40 +00:00
|
|
|
apiURL := h.roomserverURL + RoomserverPerformBackfillPath
|
2020-06-12 13:55:57 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryRoomVersionCapabilities implements RoomServerQueryAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryRoomVersionCapabilities(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryRoomVersionCapabilitiesRequest,
|
|
|
|
response *api.QueryRoomVersionCapabilitiesResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryRoomVersionCapabilities")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryRoomVersionCapabilitiesPath
|
2020-06-12 13:55:57 +00:00
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// QueryRoomVersionForRoom implements RoomServerQueryAPI
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryRoomVersionForRoom(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryRoomVersionForRoomRequest,
|
|
|
|
response *api.QueryRoomVersionForRoomResponse,
|
|
|
|
) error {
|
2020-06-05 15:42:01 +00:00
|
|
|
if roomVersion, ok := h.cache.GetRoomVersion(request.RoomID); ok {
|
2020-06-04 14:43:07 +00:00
|
|
|
response.RoomVersion = roomVersion
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryRoomVersionForRoom")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryRoomVersionForRoomPath
|
2020-06-12 13:55:57 +00:00
|
|
|
err := httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-06-04 14:43:07 +00:00
|
|
|
if err == nil {
|
2020-06-05 15:42:01 +00:00
|
|
|
h.cache.StoreRoomVersion(request.RoomID, response.RoomVersion)
|
2020-06-04 14:43:07 +00:00
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
2020-09-03 16:20:54 +00:00
|
|
|
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryCurrentState(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryCurrentStateRequest,
|
|
|
|
response *api.QueryCurrentStateResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryCurrentState")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryCurrentStatePath
|
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryRoomsForUser(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryRoomsForUserRequest,
|
|
|
|
response *api.QueryRoomsForUserResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryRoomsForUser")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryRoomsForUserPath
|
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryBulkStateContent(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.QueryBulkStateContentRequest,
|
|
|
|
response *api.QueryBulkStateContentResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryBulkStateContent")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryBulkStateContentPath
|
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *httpRoomserverInternalAPI) QuerySharedUsers(
|
|
|
|
ctx context.Context, req *api.QuerySharedUsersRequest, res *api.QuerySharedUsersResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QuerySharedUsers")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQuerySharedUsersPath
|
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryKnownUsers(
|
|
|
|
ctx context.Context, req *api.QueryKnownUsersRequest, res *api.QueryKnownUsersResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryKnownUsers")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryKnownUsersPath
|
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *httpRoomserverInternalAPI) QueryServerBannedFromRoom(
|
|
|
|
ctx context.Context, req *api.QueryServerBannedFromRoomRequest, res *api.QueryServerBannedFromRoomResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryServerBannedFromRoom")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.roomserverURL + RoomserverQueryServerBannedFromRoomPath
|
|
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
|
|
|
|
}
|