2020-04-29 12:34:31 +02:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-05-04 14:53:47 +02:00
|
|
|
"github.com/matrix-org/dendrite/federationsender/types"
|
2020-05-21 15:40:13 +02:00
|
|
|
internalHTTP "github.com/matrix-org/dendrite/internal/http"
|
2020-04-29 16:29:39 +02:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2020-04-29 12:34:31 +02:00
|
|
|
"github.com/opentracing/opentracing-go"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-05-04 14:53:47 +02:00
|
|
|
// FederationSenderPerformJoinRequestPath is the HTTP path for the PerformJoinRequest API.
|
2020-05-22 15:14:39 +02:00
|
|
|
FederationSenderPerformDirectoryLookupRequestPath = "/federationsender/performDirectoryLookup"
|
2020-05-04 14:53:47 +02:00
|
|
|
|
2020-04-29 12:34:31 +02:00
|
|
|
// FederationSenderPerformJoinRequestPath is the HTTP path for the PerformJoinRequest API.
|
2020-05-22 15:14:39 +02:00
|
|
|
FederationSenderPerformJoinRequestPath = "/federationsender/performJoinRequest"
|
2020-04-29 12:34:31 +02:00
|
|
|
|
|
|
|
// FederationSenderPerformLeaveRequestPath is the HTTP path for the PerformLeaveRequest API.
|
2020-05-22 15:14:39 +02:00
|
|
|
FederationSenderPerformLeaveRequestPath = "/federationsender/performLeaveRequest"
|
2020-06-01 19:34:08 +02:00
|
|
|
|
|
|
|
// FederationSenderPerformServersAlivePath is the HTTP path for the PerformServersAlive API.
|
|
|
|
FederationSenderPerformServersAlivePath = "/federationsender/performServersAlive"
|
2020-04-29 12:34:31 +02:00
|
|
|
)
|
|
|
|
|
2020-05-04 14:53:47 +02:00
|
|
|
type PerformDirectoryLookupRequest struct {
|
|
|
|
RoomAlias string `json:"room_alias"`
|
2020-04-29 16:29:39 +02:00
|
|
|
ServerName gomatrixserverlib.ServerName `json:"server_name"`
|
2020-05-04 14:53:47 +02: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
|
2020-05-21 15:40:13 +02:00
|
|
|
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-05-04 14:53:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type PerformJoinRequest struct {
|
2020-05-29 14:50:06 +02:00
|
|
|
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.
|
2020-05-04 14:53:47 +02:00
|
|
|
ServerNames types.ServerNames `json:"server_names"`
|
|
|
|
Content map[string]interface{} `json:"content"`
|
2020-04-29 12:34:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type PerformJoinResponse struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle an instruction to make_join & send_join with a remote server.
|
2020-04-29 16:29:39 +02:00
|
|
|
func (h *httpFederationSenderInternalAPI) PerformJoin(
|
2020-04-29 12:34:31 +02:00
|
|
|
ctx context.Context,
|
|
|
|
request *PerformJoinRequest,
|
|
|
|
response *PerformJoinResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformJoinRequest")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.federationSenderURL + FederationSenderPerformJoinRequestPath
|
2020-05-21 15:40:13 +02:00
|
|
|
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-04-29 12:34:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type PerformLeaveRequest struct {
|
2020-05-04 19:34:09 +02:00
|
|
|
RoomID string `json:"room_id"`
|
|
|
|
UserID string `json:"user_id"`
|
|
|
|
ServerNames types.ServerNames `json:"server_names"`
|
2020-04-29 12:34:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type PerformLeaveResponse struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle an instruction to make_leave & send_leave with a remote server.
|
2020-04-29 16:29:39 +02:00
|
|
|
func (h *httpFederationSenderInternalAPI) PerformLeave(
|
2020-04-29 12:34:31 +02:00
|
|
|
ctx context.Context,
|
|
|
|
request *PerformLeaveRequest,
|
|
|
|
response *PerformLeaveResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformLeaveRequest")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.federationSenderURL + FederationSenderPerformLeaveRequestPath
|
2020-05-21 15:40:13 +02:00
|
|
|
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
2020-04-29 12:34:31 +02:00
|
|
|
}
|
2020-06-01 19:34:08 +02:00
|
|
|
|
|
|
|
type PerformServersAliveRequest struct {
|
|
|
|
Servers []gomatrixserverlib.ServerName
|
|
|
|
}
|
|
|
|
|
|
|
|
type PerformServersAliveResponse struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *httpFederationSenderInternalAPI) PerformServersAlive(
|
|
|
|
ctx context.Context,
|
|
|
|
request *PerformServersAliveRequest,
|
|
|
|
response *PerformServersAliveResponse,
|
|
|
|
) error {
|
|
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformServersAlive")
|
|
|
|
defer span.Finish()
|
|
|
|
|
|
|
|
apiURL := h.federationSenderURL + FederationSenderPerformServersAlivePath
|
|
|
|
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
|
|
}
|