mirror of
https://github.com/1f349/dendrite.git
synced 2024-12-28 11:06:26 +00:00
6d50212f29
* Add missing routing for PerformDirectoryLookupRequest * Tweak output * Fix some bugs in devices * Don't default to federated room joins in response to invite * Update sytest-whitelist * Update comments * Return correct room ID from PerformJoin * Fix appservice and EDU server API setup, update sytest-whitelist * Update sytest-whitelist
116 lines
4.4 KiB
Go
116 lines
4.4 KiB
Go
package internal
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/matrix-org/dendrite/federationsender/api"
|
|
"github.com/matrix-org/dendrite/federationsender/producers"
|
|
"github.com/matrix-org/dendrite/federationsender/storage"
|
|
"github.com/matrix-org/dendrite/federationsender/types"
|
|
"github.com/matrix-org/dendrite/internal"
|
|
"github.com/matrix-org/dendrite/internal/config"
|
|
"github.com/matrix-org/gomatrixserverlib"
|
|
"github.com/matrix-org/util"
|
|
)
|
|
|
|
// FederationSenderInternalAPI is an implementation of api.FederationSenderInternalAPI
|
|
type FederationSenderInternalAPI struct {
|
|
api.FederationSenderInternalAPI
|
|
db storage.Database
|
|
cfg *config.Dendrite
|
|
statistics *types.Statistics
|
|
producer *producers.RoomserverProducer
|
|
federation *gomatrixserverlib.FederationClient
|
|
keyRing *gomatrixserverlib.KeyRing
|
|
}
|
|
|
|
func NewFederationSenderInternalAPI(
|
|
db storage.Database, cfg *config.Dendrite,
|
|
producer *producers.RoomserverProducer,
|
|
federation *gomatrixserverlib.FederationClient,
|
|
keyRing *gomatrixserverlib.KeyRing,
|
|
statistics *types.Statistics,
|
|
) *FederationSenderInternalAPI {
|
|
return &FederationSenderInternalAPI{
|
|
db: db,
|
|
cfg: cfg,
|
|
producer: producer,
|
|
federation: federation,
|
|
keyRing: keyRing,
|
|
statistics: statistics,
|
|
}
|
|
}
|
|
|
|
// SetupHTTP adds the FederationSenderInternalAPI handlers to the http.ServeMux.
|
|
func (f *FederationSenderInternalAPI) SetupHTTP(internalAPIMux *mux.Router) {
|
|
internalAPIMux.Handle(
|
|
api.FederationSenderQueryJoinedHostsInRoomPath,
|
|
internal.MakeInternalAPI("QueryJoinedHostsInRoom", func(req *http.Request) util.JSONResponse {
|
|
var request api.QueryJoinedHostsInRoomRequest
|
|
var response api.QueryJoinedHostsInRoomResponse
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
return util.ErrorResponse(err)
|
|
}
|
|
if err := f.QueryJoinedHostsInRoom(req.Context(), &request, &response); err != nil {
|
|
return util.ErrorResponse(err)
|
|
}
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
}),
|
|
)
|
|
internalAPIMux.Handle(
|
|
api.FederationSenderQueryJoinedHostServerNamesInRoomPath,
|
|
internal.MakeInternalAPI("QueryJoinedHostServerNamesInRoom", func(req *http.Request) util.JSONResponse {
|
|
var request api.QueryJoinedHostServerNamesInRoomRequest
|
|
var response api.QueryJoinedHostServerNamesInRoomResponse
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
return util.ErrorResponse(err)
|
|
}
|
|
if err := f.QueryJoinedHostServerNamesInRoom(req.Context(), &request, &response); err != nil {
|
|
return util.ErrorResponse(err)
|
|
}
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
}),
|
|
)
|
|
internalAPIMux.Handle(api.FederationSenderPerformJoinRequestPath,
|
|
internal.MakeInternalAPI("PerformJoinRequest", func(req *http.Request) util.JSONResponse {
|
|
var request api.PerformJoinRequest
|
|
var response api.PerformJoinResponse
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
}
|
|
if err := f.PerformJoin(req.Context(), &request, &response); err != nil {
|
|
return util.ErrorResponse(err)
|
|
}
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
}),
|
|
)
|
|
internalAPIMux.Handle(api.FederationSenderPerformLeaveRequestPath,
|
|
internal.MakeInternalAPI("PerformLeaveRequest", func(req *http.Request) util.JSONResponse {
|
|
var request api.PerformLeaveRequest
|
|
var response api.PerformLeaveResponse
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
}
|
|
if err := f.PerformLeave(req.Context(), &request, &response); err != nil {
|
|
return util.ErrorResponse(err)
|
|
}
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
}),
|
|
)
|
|
internalAPIMux.Handle(api.FederationSenderPerformDirectoryLookupRequestPath,
|
|
internal.MakeInternalAPI("PerformDirectoryLookupRequest", func(req *http.Request) util.JSONResponse {
|
|
var request api.PerformDirectoryLookupRequest
|
|
var response api.PerformDirectoryLookupResponse
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
}
|
|
if err := f.PerformDirectoryLookup(req.Context(), &request, &response); err != nil {
|
|
return util.ErrorResponse(err)
|
|
}
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
}),
|
|
)
|
|
}
|