mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 21:32:46 +00:00
Refactor how federationsender gets created (#1095)
* Refactor how federationsender gets created * s/httpint/inthttp/ for alphabetical niceness with internal package
This commit is contained in:
parent
f7025d3499
commit
f4c676ccdd
15 changed files with 288 additions and 303 deletions
|
@ -2,8 +2,9 @@ package api
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/matrix-org/dendrite/federationsender/types"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
// FederationSenderInternalAPI is used to query information from the federation sender.
|
||||
|
@ -50,16 +51,59 @@ type FederationSenderInternalAPI interface {
|
|||
) error
|
||||
}
|
||||
|
||||
// NewFederationSenderInternalAPIHTTP creates a FederationSenderInternalAPI implemented by talking to a HTTP POST API.
|
||||
// If httpClient is nil an error is returned
|
||||
func NewFederationSenderInternalAPIHTTP(federationSenderURL string, httpClient *http.Client) (FederationSenderInternalAPI, error) {
|
||||
if httpClient == nil {
|
||||
return nil, errors.New("NewFederationSenderInternalAPIHTTP: httpClient is <nil>")
|
||||
}
|
||||
return &httpFederationSenderInternalAPI{federationSenderURL, httpClient}, nil
|
||||
type PerformDirectoryLookupRequest struct {
|
||||
RoomAlias string `json:"room_alias"`
|
||||
ServerName gomatrixserverlib.ServerName `json:"server_name"`
|
||||
}
|
||||
|
||||
type httpFederationSenderInternalAPI struct {
|
||||
federationSenderURL string
|
||||
httpClient *http.Client
|
||||
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 {
|
||||
}
|
||||
|
||||
type PerformLeaveRequest struct {
|
||||
RoomID string `json:"room_id"`
|
||||
UserID string `json:"user_id"`
|
||||
ServerNames types.ServerNames `json:"server_names"`
|
||||
}
|
||||
|
||||
type PerformLeaveResponse struct {
|
||||
}
|
||||
|
||||
type PerformServersAliveRequest struct {
|
||||
Servers []gomatrixserverlib.ServerName
|
||||
}
|
||||
|
||||
type PerformServersAliveResponse struct {
|
||||
}
|
||||
|
||||
// QueryJoinedHostsInRoomRequest is a request to QueryJoinedHostsInRoom
|
||||
type QueryJoinedHostsInRoomRequest struct {
|
||||
RoomID string `json:"room_id"`
|
||||
}
|
||||
|
||||
// QueryJoinedHostsInRoomResponse is a response to QueryJoinedHostsInRoom
|
||||
type QueryJoinedHostsInRoomResponse struct {
|
||||
JoinedHosts []types.JoinedHost `json:"joined_hosts"`
|
||||
}
|
||||
|
||||
// QueryJoinedHostServerNamesRequest is a request to QueryJoinedHostServerNames
|
||||
type QueryJoinedHostServerNamesInRoomRequest struct {
|
||||
RoomID string `json:"room_id"`
|
||||
}
|
||||
|
||||
// QueryJoinedHostServerNamesResponse is a response to QueryJoinedHostServerNames
|
||||
type QueryJoinedHostServerNamesInRoomResponse struct {
|
||||
ServerNames []gomatrixserverlib.ServerName `json:"server_names"`
|
||||
}
|
||||
|
|
|
@ -1,112 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/matrix-org/dendrite/federationsender/types"
|
||||
internalHTTP "github.com/matrix-org/dendrite/internal/http"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
)
|
||||
|
||||
const (
|
||||
// FederationSenderPerformJoinRequestPath is the HTTP path for the PerformJoinRequest API.
|
||||
FederationSenderPerformDirectoryLookupRequestPath = "/federationsender/performDirectoryLookup"
|
||||
|
||||
// FederationSenderPerformJoinRequestPath is the HTTP path for the PerformJoinRequest API.
|
||||
FederationSenderPerformJoinRequestPath = "/federationsender/performJoinRequest"
|
||||
|
||||
// FederationSenderPerformLeaveRequestPath is the HTTP path for the PerformLeaveRequest API.
|
||||
FederationSenderPerformLeaveRequestPath = "/federationsender/performLeaveRequest"
|
||||
|
||||
// FederationSenderPerformServersAlivePath is the HTTP path for the PerformServersAlive API.
|
||||
FederationSenderPerformServersAlivePath = "/federationsender/performServersAlive"
|
||||
)
|
||||
|
||||
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"`
|
||||
}
|
||||
|
||||
// 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 internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
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 {
|
||||
}
|
||||
|
||||
// Handle an instruction to make_join & send_join with a remote server.
|
||||
func (h *httpFederationSenderInternalAPI) PerformJoin(
|
||||
ctx context.Context,
|
||||
request *PerformJoinRequest,
|
||||
response *PerformJoinResponse,
|
||||
) error {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformJoinRequest")
|
||||
defer span.Finish()
|
||||
|
||||
apiURL := h.federationSenderURL + FederationSenderPerformJoinRequestPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
type PerformLeaveRequest struct {
|
||||
RoomID string `json:"room_id"`
|
||||
UserID string `json:"user_id"`
|
||||
ServerNames types.ServerNames `json:"server_names"`
|
||||
}
|
||||
|
||||
type PerformLeaveResponse struct {
|
||||
}
|
||||
|
||||
// Handle an instruction to make_leave & send_leave with a remote server.
|
||||
func (h *httpFederationSenderInternalAPI) PerformLeave(
|
||||
ctx context.Context,
|
||||
request *PerformLeaveRequest,
|
||||
response *PerformLeaveResponse,
|
||||
) error {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "PerformLeaveRequest")
|
||||
defer span.Finish()
|
||||
|
||||
apiURL := h.federationSenderURL + FederationSenderPerformLeaveRequestPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/matrix-org/dendrite/federationsender/types"
|
||||
internalHTTP "github.com/matrix-org/dendrite/internal/http"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
|
||||
"github.com/opentracing/opentracing-go"
|
||||
)
|
||||
|
||||
// FederationSenderQueryJoinedHostsInRoomPath is the HTTP path for the QueryJoinedHostsInRoom API.
|
||||
const FederationSenderQueryJoinedHostsInRoomPath = "/federationsender/queryJoinedHostsInRoom"
|
||||
|
||||
// FederationSenderQueryJoinedHostServerNamesInRoomPath is the HTTP path for the QueryJoinedHostServerNamesInRoom API.
|
||||
const FederationSenderQueryJoinedHostServerNamesInRoomPath = "/federationsender/queryJoinedHostServerNamesInRoom"
|
||||
|
||||
// QueryJoinedHostsInRoomRequest is a request to QueryJoinedHostsInRoom
|
||||
type QueryJoinedHostsInRoomRequest struct {
|
||||
RoomID string `json:"room_id"`
|
||||
}
|
||||
|
||||
// QueryJoinedHostsInRoomResponse is a response to QueryJoinedHostsInRoom
|
||||
type QueryJoinedHostsInRoomResponse struct {
|
||||
JoinedHosts []types.JoinedHost `json:"joined_hosts"`
|
||||
}
|
||||
|
||||
// QueryJoinedHostsInRoom implements FederationSenderInternalAPI
|
||||
func (h *httpFederationSenderInternalAPI) QueryJoinedHostsInRoom(
|
||||
ctx context.Context,
|
||||
request *QueryJoinedHostsInRoomRequest,
|
||||
response *QueryJoinedHostsInRoomResponse,
|
||||
) error {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryJoinedHostsInRoom")
|
||||
defer span.Finish()
|
||||
|
||||
apiURL := h.federationSenderURL + FederationSenderQueryJoinedHostsInRoomPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// QueryJoinedHostServerNamesRequest is a request to QueryJoinedHostServerNames
|
||||
type QueryJoinedHostServerNamesInRoomRequest struct {
|
||||
RoomID string `json:"room_id"`
|
||||
}
|
||||
|
||||
// QueryJoinedHostServerNamesResponse is a response to QueryJoinedHostServerNames
|
||||
type QueryJoinedHostServerNamesInRoomResponse struct {
|
||||
ServerNames []gomatrixserverlib.ServerName `json:"server_names"`
|
||||
}
|
||||
|
||||
// QueryJoinedHostServerNamesInRoom implements FederationSenderInternalAPI
|
||||
func (h *httpFederationSenderInternalAPI) QueryJoinedHostServerNamesInRoom(
|
||||
ctx context.Context,
|
||||
request *QueryJoinedHostServerNamesInRoomRequest,
|
||||
response *QueryJoinedHostServerNamesInRoomResponse,
|
||||
) error {
|
||||
span, ctx := opentracing.StartSpanFromContext(ctx, "QueryJoinedHostServerNamesInRoom")
|
||||
defer span.Finish()
|
||||
|
||||
apiURL := h.federationSenderURL + FederationSenderQueryJoinedHostServerNamesInRoomPath
|
||||
return internalHTTP.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue