2020-04-29 11:34:31 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
commonHTTP "github.com/matrix-org/dendrite/common/http"
|
2020-05-04 13:53:47 +01:00
|
|
|
"github.com/matrix-org/dendrite/federationsender/types"
|
2020-04-29 15:29:39 +01:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2020-04-29 11:34:31 +01:00
|
|
|
"github.com/opentracing/opentracing-go"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-05-04 13:53:47 +01:00
|
|
|
// FederationSenderPerformJoinRequestPath is the HTTP path for the PerformJoinRequest API.
|
|
|
|
FederationSenderPerformDirectoryLookupRequestPath = "/api/federationsender/performDirectoryLookup"
|
|
|
|
|
2020-04-29 11:34:31 +01:00
|
|
|
// FederationSenderPerformJoinRequestPath is the HTTP path for the PerformJoinRequest API.
|
|
|
|
FederationSenderPerformJoinRequestPath = "/api/federationsender/performJoinRequest"
|
|
|
|
|
|
|
|
// FederationSenderPerformLeaveRequestPath is the HTTP path for the PerformLeaveRequest API.
|
|
|
|
FederationSenderPerformLeaveRequestPath = "/api/federationsender/performLeaveRequest"
|
|
|
|
)
|
|
|
|
|
2020-05-04 13:53:47 +01:00
|
|
|
type PerformDirectoryLookupRequest struct {
|
|
|
|
RoomAlias string `json:"room_alias"`
|
2020-04-29 15:29:39 +01:00
|
|
|
ServerName gomatrixserverlib.ServerName `json:"server_name"`
|
2020-05-04 13:53:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type PerformDirectoryLookupResponse struct {
|
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
ServerNames []gomatrixserverlib.ServerName `json:"server_names"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle an instruction to make_join & send_join with a remote server.
|
|
|
|
func (h *httpFederationSenderInternalAPI) PerformDirectoryLookup(
|
|
|
|
ctx context.Context,
|
|
|
|
request *PerformDirectoryLookupRequest,
|
|
|
|
response *PerformDirectoryLookupResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformDirectoryLookup")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.federationSenderURL + FederationSenderPerformDirectoryLookupRequestPath
|
|
|
|
return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
|
|
}
|
|
|
|
|
|
|
|
type PerformJoinRequest struct {
|
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
UserID string `json:"user_id"`
|
|
|
|
ServerNames types.ServerNames `json:"server_names"`
|
|
|
|
Content map[string]interface{} `json:"content"`
|
2020-04-29 11:34:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type PerformJoinResponse struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle an instruction to make_join & send_join with a remote server.
|
2020-04-29 15:29:39 +01:00
|
|
|
func (h *httpFederationSenderInternalAPI) PerformJoin(
|
2020-04-29 11:34:31 +01:00
|
|
|
ctx context.Context,
|
|
|
|
request *PerformJoinRequest,
|
|
|
|
response *PerformJoinResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformJoinRequest")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.federationSenderURL + FederationSenderPerformJoinRequestPath
|
|
|
|
return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
|
|
}
|
|
|
|
|
|
|
|
type PerformLeaveRequest struct {
|
2020-05-04 18:34:09 +01:00
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
UserID string `json:"user_id"`
|
|
|
|
ServerNames types.ServerNames `json:"server_names"`
|
2020-04-29 11:34:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type PerformLeaveResponse struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle an instruction to make_leave & send_leave with a remote server.
|
2020-04-29 15:29:39 +01:00
|
|
|
func (h *httpFederationSenderInternalAPI) PerformLeave(
|
2020-04-29 11:34:31 +01:00
|
|
|
ctx context.Context,
|
|
|
|
request *PerformLeaveRequest,
|
|
|
|
response *PerformLeaveResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformLeaveRequest")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.federationSenderURL + FederationSenderPerformLeaveRequestPath
|
|
|
|
return commonHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
|
|
}
|