mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
Clean up interface definitions (#2427)
* tidy up interfaces * remove unused GetCreatorIDForAlias * Add RoomserverUserAPI interface * Define more interfaces * Use AppServiceInternalAPI for consistent naming * clean up federationapi constructor a bit * Fix monolith in -http mode
This commit is contained in:
parent
4705f5761e
commit
85704eff20
37 changed files with 236 additions and 429 deletions
|
@ -59,18 +59,6 @@ type GetAliasesForRoomIDResponse struct {
|
|||
Aliases []string `json:"aliases"`
|
||||
}
|
||||
|
||||
// GetCreatorIDForAliasRequest is a request to GetCreatorIDForAlias
|
||||
type GetCreatorIDForAliasRequest struct {
|
||||
// The alias we want to find the creator of
|
||||
Alias string `json:"alias"`
|
||||
}
|
||||
|
||||
// GetCreatorIDForAliasResponse is a response to GetCreatorIDForAlias
|
||||
type GetCreatorIDForAliasResponse struct {
|
||||
// The user ID of the alias creator
|
||||
UserID string `json:"user_id"`
|
||||
}
|
||||
|
||||
// RemoveRoomAliasRequest is a request to RemoveRoomAlias
|
||||
type RemoveRoomAliasRequest struct {
|
||||
// ID of the user removing the alias
|
||||
|
|
|
@ -12,10 +12,6 @@ import (
|
|||
|
||||
// RoomserverInputAPI is used to write events to the room server.
|
||||
type RoomserverInternalAPI interface {
|
||||
InputRoomEventsAPI
|
||||
QueryLatestEventsAndStateAPI
|
||||
QueryEventsAPI
|
||||
|
||||
SyncRoomserverAPI
|
||||
AppserviceRoomserverAPI
|
||||
ClientRoomserverAPI
|
||||
|
@ -25,101 +21,18 @@ type RoomserverInternalAPI interface {
|
|||
// needed to avoid chicken and egg scenario when setting up the
|
||||
// interdependencies between the roomserver and other input APIs
|
||||
SetFederationAPI(fsAPI fsAPI.RoomserverFederationAPI, keyRing *gomatrixserverlib.KeyRing)
|
||||
SetAppserviceAPI(asAPI asAPI.AppServiceQueryAPI)
|
||||
SetUserAPI(userAPI userapi.UserInternalAPI)
|
||||
|
||||
PerformInvite(
|
||||
ctx context.Context,
|
||||
req *PerformInviteRequest,
|
||||
res *PerformInviteResponse,
|
||||
) error
|
||||
|
||||
PerformJoin(
|
||||
ctx context.Context,
|
||||
req *PerformJoinRequest,
|
||||
res *PerformJoinResponse,
|
||||
)
|
||||
|
||||
PerformLeave(
|
||||
ctx context.Context,
|
||||
req *PerformLeaveRequest,
|
||||
res *PerformLeaveResponse,
|
||||
) error
|
||||
|
||||
PerformPeek(
|
||||
ctx context.Context,
|
||||
req *PerformPeekRequest,
|
||||
res *PerformPeekResponse,
|
||||
)
|
||||
|
||||
PerformUnpeek(
|
||||
ctx context.Context,
|
||||
req *PerformUnpeekRequest,
|
||||
res *PerformUnpeekResponse,
|
||||
)
|
||||
|
||||
PerformPublish(
|
||||
ctx context.Context,
|
||||
req *PerformPublishRequest,
|
||||
res *PerformPublishResponse,
|
||||
)
|
||||
SetAppserviceAPI(asAPI asAPI.AppServiceInternalAPI)
|
||||
SetUserAPI(userAPI userapi.RoomserverUserAPI)
|
||||
|
||||
// QueryAuthChain returns the entire auth chain for the event IDs given.
|
||||
// The response includes the events in the request.
|
||||
// Omits without error for any missing auth events. There will be no duplicates.
|
||||
// Used in MSC2836.
|
||||
QueryAuthChain(
|
||||
ctx context.Context,
|
||||
req *QueryAuthChainRequest,
|
||||
res *QueryAuthChainResponse,
|
||||
) error
|
||||
|
||||
// QueryRoomsForUser retrieves a list of room IDs matching the given query.
|
||||
QueryRoomsForUser(ctx context.Context, req *QueryRoomsForUserRequest, res *QueryRoomsForUserResponse) error
|
||||
|
||||
// PerformRoomUpgrade upgrades a room to a newer version
|
||||
PerformRoomUpgrade(ctx context.Context, req *PerformRoomUpgradeRequest, resp *PerformRoomUpgradeResponse)
|
||||
|
||||
// Asks for the default room version as preferred by the server.
|
||||
QueryRoomVersionCapabilities(
|
||||
ctx context.Context,
|
||||
req *QueryRoomVersionCapabilitiesRequest,
|
||||
res *QueryRoomVersionCapabilitiesResponse,
|
||||
) error
|
||||
|
||||
// Asks for the room version for a given room.
|
||||
QueryRoomVersionForRoom(
|
||||
ctx context.Context,
|
||||
req *QueryRoomVersionForRoomRequest,
|
||||
res *QueryRoomVersionForRoomResponse,
|
||||
) error
|
||||
|
||||
// Set a room alias
|
||||
SetRoomAlias(
|
||||
ctx context.Context,
|
||||
req *SetRoomAliasRequest,
|
||||
res *SetRoomAliasResponse,
|
||||
) error
|
||||
|
||||
// Get the room ID for an alias
|
||||
GetRoomIDForAlias(
|
||||
ctx context.Context,
|
||||
req *GetRoomIDForAliasRequest,
|
||||
res *GetRoomIDForAliasResponse,
|
||||
) error
|
||||
|
||||
// Get the user ID of the creator of an alias
|
||||
GetCreatorIDForAlias(
|
||||
ctx context.Context,
|
||||
req *GetCreatorIDForAliasRequest,
|
||||
res *GetCreatorIDForAliasResponse,
|
||||
) error
|
||||
|
||||
// Remove a room alias
|
||||
RemoveRoomAlias(
|
||||
ctx context.Context,
|
||||
req *RemoveRoomAliasRequest,
|
||||
res *RemoveRoomAliasResponse,
|
||||
) error
|
||||
}
|
||||
|
||||
type InputRoomEventsAPI interface {
|
||||
|
|
|
@ -23,11 +23,11 @@ func (t *RoomserverInternalAPITrace) SetFederationAPI(fsAPI fsAPI.RoomserverFede
|
|||
t.Impl.SetFederationAPI(fsAPI, keyRing)
|
||||
}
|
||||
|
||||
func (t *RoomserverInternalAPITrace) SetAppserviceAPI(asAPI asAPI.AppServiceQueryAPI) {
|
||||
func (t *RoomserverInternalAPITrace) SetAppserviceAPI(asAPI asAPI.AppServiceInternalAPI) {
|
||||
t.Impl.SetAppserviceAPI(asAPI)
|
||||
}
|
||||
|
||||
func (t *RoomserverInternalAPITrace) SetUserAPI(userAPI userapi.UserInternalAPI) {
|
||||
func (t *RoomserverInternalAPITrace) SetUserAPI(userAPI userapi.RoomserverUserAPI) {
|
||||
t.Impl.SetUserAPI(userAPI)
|
||||
}
|
||||
|
||||
|
@ -293,16 +293,6 @@ func (t *RoomserverInternalAPITrace) GetAliasesForRoomID(
|
|||
return err
|
||||
}
|
||||
|
||||
func (t *RoomserverInternalAPITrace) GetCreatorIDForAlias(
|
||||
ctx context.Context,
|
||||
req *GetCreatorIDForAliasRequest,
|
||||
res *GetCreatorIDForAliasResponse,
|
||||
) error {
|
||||
err := t.Impl.GetCreatorIDForAlias(ctx, req, res)
|
||||
util.GetLogger(ctx).WithError(err).Infof("GetCreatorIDForAlias req=%+v res=%+v", js(req), js(res))
|
||||
return err
|
||||
}
|
||||
|
||||
func (t *RoomserverInternalAPITrace) RemoveRoomAlias(
|
||||
ctx context.Context,
|
||||
req *RemoveRoomAliasRequest,
|
||||
|
|
|
@ -41,9 +41,6 @@ type RoomserverInternalAPIDatabase interface {
|
|||
// Look up all aliases referring to a given room ID.
|
||||
// Returns an error if there was a problem talking to the database.
|
||||
GetAliasesForRoomID(ctx context.Context, roomID string) ([]string, error)
|
||||
// Get the user ID of the creator of an alias.
|
||||
// Returns an error if there was a problem talking to the database.
|
||||
GetCreatorIDForAlias(ctx context.Context, alias string) (string, error)
|
||||
// Remove a given room alias.
|
||||
// Returns an error if there was a problem talking to the database.
|
||||
RemoveRoomAlias(ctx context.Context, alias string) error
|
||||
|
@ -134,22 +131,6 @@ func (r *RoomserverInternalAPI) GetAliasesForRoomID(
|
|||
return nil
|
||||
}
|
||||
|
||||
// GetCreatorIDForAlias implements alias.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) GetCreatorIDForAlias(
|
||||
ctx context.Context,
|
||||
request *api.GetCreatorIDForAliasRequest,
|
||||
response *api.GetCreatorIDForAliasResponse,
|
||||
) error {
|
||||
// Look up the aliases in the database for the given RoomID
|
||||
creatorID, err := r.DB.GetCreatorIDForAlias(ctx, request.Alias)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
response.UserID = creatorID
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveRoomAlias implements alias.RoomserverInternalAPI
|
||||
func (r *RoomserverInternalAPI) RemoveRoomAlias(
|
||||
ctx context.Context,
|
||||
|
|
|
@ -44,7 +44,7 @@ type RoomserverInternalAPI struct {
|
|||
KeyRing gomatrixserverlib.JSONVerifier
|
||||
ServerACLs *acls.ServerACLs
|
||||
fsAPI fsAPI.RoomserverFederationAPI
|
||||
asAPI asAPI.AppServiceQueryAPI
|
||||
asAPI asAPI.AppServiceInternalAPI
|
||||
NATSClient *nats.Conn
|
||||
JetStream nats.JetStreamContext
|
||||
Durable string
|
||||
|
@ -177,11 +177,11 @@ func (r *RoomserverInternalAPI) SetFederationAPI(fsAPI fsAPI.RoomserverFederatio
|
|||
}
|
||||
}
|
||||
|
||||
func (r *RoomserverInternalAPI) SetUserAPI(userAPI userapi.UserInternalAPI) {
|
||||
func (r *RoomserverInternalAPI) SetUserAPI(userAPI userapi.RoomserverUserAPI) {
|
||||
r.Leaver.UserAPI = userAPI
|
||||
}
|
||||
|
||||
func (r *RoomserverInternalAPI) SetAppserviceAPI(asAPI asAPI.AppServiceQueryAPI) {
|
||||
func (r *RoomserverInternalAPI) SetAppserviceAPI(asAPI asAPI.AppServiceInternalAPI) {
|
||||
r.asAPI = asAPI
|
||||
}
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ type Leaver struct {
|
|||
Cfg *config.RoomServer
|
||||
DB storage.Database
|
||||
FSAPI fsAPI.RoomserverFederationAPI
|
||||
UserAPI userapi.UserInternalAPI
|
||||
UserAPI userapi.RoomserverUserAPI
|
||||
Inputer *input.Inputer
|
||||
}
|
||||
|
||||
|
|
|
@ -91,11 +91,11 @@ func (h *httpRoomserverInternalAPI) SetFederationAPI(fsAPI fsInputAPI.Roomserver
|
|||
}
|
||||
|
||||
// SetAppserviceAPI no-ops in HTTP client mode as there is no chicken/egg scenario
|
||||
func (h *httpRoomserverInternalAPI) SetAppserviceAPI(asAPI asAPI.AppServiceQueryAPI) {
|
||||
func (h *httpRoomserverInternalAPI) SetAppserviceAPI(asAPI asAPI.AppServiceInternalAPI) {
|
||||
}
|
||||
|
||||
// SetUserAPI no-ops in HTTP client mode as there is no chicken/egg scenario
|
||||
func (h *httpRoomserverInternalAPI) SetUserAPI(userAPI userapi.UserInternalAPI) {
|
||||
func (h *httpRoomserverInternalAPI) SetUserAPI(userAPI userapi.RoomserverUserAPI) {
|
||||
}
|
||||
|
||||
// SetRoomAlias implements RoomserverAliasAPI
|
||||
|
@ -137,19 +137,6 @@ func (h *httpRoomserverInternalAPI) GetAliasesForRoomID(
|
|||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// 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
|
||||
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
||||
}
|
||||
|
||||
// RemoveRoomAlias implements RoomserverAliasAPI
|
||||
func (h *httpRoomserverInternalAPI) RemoveRoomAlias(
|
||||
ctx context.Context,
|
||||
|
|
|
@ -353,20 +353,6 @@ func AddRoutes(r api.RoomserverInternalAPI, internalAPIMux *mux.Router) {
|
|||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||
}),
|
||||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverGetCreatorIDForAliasPath,
|
||||
httputil.MakeInternalAPI("GetCreatorIDForAlias", func(req *http.Request) util.JSONResponse {
|
||||
var request api.GetCreatorIDForAliasRequest
|
||||
var response api.GetCreatorIDForAliasResponse
|
||||
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
if err := r.GetCreatorIDForAlias(req.Context(), &request, &response); err != nil {
|
||||
return util.ErrorResponse(err)
|
||||
}
|
||||
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
||||
}),
|
||||
)
|
||||
internalAPIMux.Handle(
|
||||
RoomserverGetAliasesForRoomIDPath,
|
||||
httputil.MakeInternalAPI("getAliasesForRoomID", func(req *http.Request) util.JSONResponse {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue