|
|
|
|
@ -124,7 +124,7 @@ func Setup(
|
|
|
|
|
|
|
|
|
|
mu := internal.NewMutexByRoom()
|
|
|
|
|
v1fedmux.Handle("/send/{txnID}", MakeFedAPI(
|
|
|
|
|
"federation_send", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_send", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
return Send(
|
|
|
|
|
httpReq, request, gomatrixserverlib.TransactionID(vars["txnID"]),
|
|
|
|
|
@ -134,7 +134,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/invite/{roomID}/{eventID}", MakeFedAPI(
|
|
|
|
|
"federation_invite", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_invite", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
@ -150,7 +150,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
v2fedmux.Handle("/invite/{roomID}/{eventID}", MakeFedAPI(
|
|
|
|
|
"federation_invite", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_invite", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
@ -172,7 +172,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodPost, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/exchange_third_party_invite/{roomID}", MakeFedAPI(
|
|
|
|
|
"exchange_third_party_invite", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"exchange_third_party_invite", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
return ExchangeThirdPartyInvite(
|
|
|
|
|
httpReq, request, vars["roomID"], rsAPI, cfg, federation,
|
|
|
|
|
@ -181,7 +181,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodPut, http.MethodOptions)
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/event/{eventID}", MakeFedAPI(
|
|
|
|
|
"federation_get_event", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_get_event", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
return GetEvent(
|
|
|
|
|
httpReq.Context(), request, rsAPI, vars["eventID"], cfg.Matrix.ServerName,
|
|
|
|
|
@ -190,7 +190,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodGet)
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/state/{roomID}", MakeFedAPI(
|
|
|
|
|
"federation_get_state", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_get_state", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
@ -205,7 +205,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodGet)
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/state_ids/{roomID}", MakeFedAPI(
|
|
|
|
|
"federation_get_state_ids", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_get_state_ids", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
@ -220,7 +220,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodGet)
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/event_auth/{roomID}/{eventID}", MakeFedAPI(
|
|
|
|
|
"federation_get_event_auth", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_get_event_auth", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
@ -235,7 +235,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodGet)
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/query/directory", MakeFedAPI(
|
|
|
|
|
"federation_query_room_alias", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_query_room_alias", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
return RoomAliasToID(
|
|
|
|
|
httpReq, federation, cfg, rsAPI, fsAPI,
|
|
|
|
|
@ -244,7 +244,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodGet)
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/query/profile", MakeFedAPI(
|
|
|
|
|
"federation_query_profile", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_query_profile", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
return GetProfile(
|
|
|
|
|
httpReq, userAPI, cfg,
|
|
|
|
|
@ -253,7 +253,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodGet)
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/user/devices/{userID}", MakeFedAPI(
|
|
|
|
|
"federation_user_devices", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_user_devices", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
return GetUserDevices(
|
|
|
|
|
httpReq, keyAPI, vars["userID"],
|
|
|
|
|
@ -263,7 +263,7 @@ func Setup(
|
|
|
|
|
|
|
|
|
|
if mscCfg.Enabled("msc2444") {
|
|
|
|
|
v1fedmux.Handle("/peek/{roomID}/{peekID}", MakeFedAPI(
|
|
|
|
|
"federation_peek", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_peek", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
@ -294,7 +294,7 @@ func Setup(
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/make_join/{roomID}/{userID}", MakeFedAPI(
|
|
|
|
|
"federation_make_join", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_make_join", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
@ -325,7 +325,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodGet)
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/send_join/{roomID}/{eventID}", MakeFedAPI(
|
|
|
|
|
"federation_send_join", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_send_join", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
@ -357,7 +357,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodPut)
|
|
|
|
|
|
|
|
|
|
v2fedmux.Handle("/send_join/{roomID}/{eventID}", MakeFedAPI(
|
|
|
|
|
"federation_send_join", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_send_join", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
@ -374,7 +374,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodPut)
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/make_leave/{roomID}/{eventID}", MakeFedAPI(
|
|
|
|
|
"federation_make_leave", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_make_leave", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
@ -391,7 +391,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodGet)
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/send_leave/{roomID}/{eventID}", MakeFedAPI(
|
|
|
|
|
"federation_send_leave", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_send_leave", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
@ -423,7 +423,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodPut)
|
|
|
|
|
|
|
|
|
|
v2fedmux.Handle("/send_leave/{roomID}/{eventID}", MakeFedAPI(
|
|
|
|
|
"federation_send_leave", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_send_leave", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
@ -447,7 +447,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodGet)
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/get_missing_events/{roomID}", MakeFedAPI(
|
|
|
|
|
"federation_get_missing_events", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_get_missing_events", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
@ -460,7 +460,7 @@ func Setup(
|
|
|
|
|
)).Methods(http.MethodPost)
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/backfill/{roomID}", MakeFedAPI(
|
|
|
|
|
"federation_backfill", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_backfill", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
if roomserverAPI.IsServerBannedFromRoom(httpReq.Context(), rsAPI, vars["roomID"], request.Origin()) {
|
|
|
|
|
return util.JSONResponse{
|
|
|
|
|
@ -479,14 +479,14 @@ func Setup(
|
|
|
|
|
).Methods(http.MethodGet, http.MethodPost)
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/user/keys/claim", MakeFedAPI(
|
|
|
|
|
"federation_keys_claim", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_keys_claim", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
return ClaimOneTimeKeys(httpReq, request, keyAPI, cfg.Matrix.ServerName)
|
|
|
|
|
},
|
|
|
|
|
)).Methods(http.MethodPost)
|
|
|
|
|
|
|
|
|
|
v1fedmux.Handle("/user/keys/query", MakeFedAPI(
|
|
|
|
|
"federation_keys_query", cfg.Matrix.ServerName, keys, wakeup,
|
|
|
|
|
"federation_keys_query", cfg.Matrix.ServerName, cfg.Matrix.IsLocalServerName, keys, wakeup,
|
|
|
|
|
func(httpReq *http.Request, request *gomatrixserverlib.FederationRequest, vars map[string]string) util.JSONResponse {
|
|
|
|
|
return QueryDeviceKeys(httpReq, request, keyAPI, cfg.Matrix.ServerName)
|
|
|
|
|
},
|
|
|
|
|
@ -525,15 +525,15 @@ func ErrorIfLocalServerNotInRoom(
|
|
|
|
|
|
|
|
|
|
// MakeFedAPI makes an http.Handler that checks matrix federation authentication.
|
|
|
|
|
func MakeFedAPI(
|
|
|
|
|
metricsName string,
|
|
|
|
|
serverName gomatrixserverlib.ServerName,
|
|
|
|
|
metricsName string, serverName gomatrixserverlib.ServerName,
|
|
|
|
|
isLocalServerName func(gomatrixserverlib.ServerName) bool,
|
|
|
|
|
keyRing gomatrixserverlib.JSONVerifier,
|
|
|
|
|
wakeup *FederationWakeups,
|
|
|
|
|
f func(*http.Request, *gomatrixserverlib.FederationRequest, map[string]string) util.JSONResponse,
|
|
|
|
|
) http.Handler {
|
|
|
|
|
h := func(req *http.Request) util.JSONResponse {
|
|
|
|
|
fedReq, errResp := gomatrixserverlib.VerifyHTTPRequest(
|
|
|
|
|
req, time.Now(), serverName, keyRing,
|
|
|
|
|
req, time.Now(), serverName, isLocalServerName, keyRing,
|
|
|
|
|
)
|
|
|
|
|
if fedReq == nil {
|
|
|
|
|
return errResp
|
|
|
|
|
|