2020-05-01 07:01:50 -05:00
|
|
|
package internal
|
2020-04-29 05:34:31 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
2020-05-22 05:43:17 -05:00
|
|
|
"github.com/gorilla/mux"
|
2020-04-29 05:34:31 -05:00
|
|
|
"github.com/matrix-org/dendrite/federationsender/api"
|
2020-04-29 09:29:39 -05:00
|
|
|
"github.com/matrix-org/dendrite/federationsender/producers"
|
2020-04-29 05:34:31 -05:00
|
|
|
"github.com/matrix-org/dendrite/federationsender/storage"
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 06:42:06 -05:00
|
|
|
"github.com/matrix-org/dendrite/federationsender/types"
|
2020-05-21 08:40:13 -05:00
|
|
|
"github.com/matrix-org/dendrite/internal"
|
|
|
|
"github.com/matrix-org/dendrite/internal/config"
|
2020-04-29 09:29:39 -05:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2020-04-29 05:34:31 -05:00
|
|
|
"github.com/matrix-org/util"
|
|
|
|
)
|
|
|
|
|
|
|
|
// FederationSenderInternalAPI is an implementation of api.FederationSenderInternalAPI
|
|
|
|
type FederationSenderInternalAPI struct {
|
|
|
|
api.FederationSenderInternalAPI
|
2020-04-29 09:29:39 -05:00
|
|
|
db storage.Database
|
|
|
|
cfg *config.Dendrite
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 06:42:06 -05:00
|
|
|
statistics *types.Statistics
|
2020-04-29 09:29:39 -05:00
|
|
|
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,
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 06:42:06 -05:00
|
|
|
statistics *types.Statistics,
|
2020-04-29 09:29:39 -05:00
|
|
|
) *FederationSenderInternalAPI {
|
|
|
|
return &FederationSenderInternalAPI{
|
|
|
|
db: db,
|
|
|
|
cfg: cfg,
|
|
|
|
producer: producer,
|
|
|
|
federation: federation,
|
|
|
|
keyRing: keyRing,
|
Improve federation sender performance, implement backoff and blacklisting, fix up invites a bit (#1007)
* Improve federation sender performance and behaviour, add backoff
* Tweaks
* Tweaks
* Tweaks
* Take copies of events before passing to destination queues
* Don't accidentally drop queued messages
* Don't take copies again
* Tidy up a bit
* Break out statistics (tracked component-wide), report success and failures from Perform actions
* Fix comment, use atomic add
* Improve logic a bit, don't block on wakeup, move idle check
* Don't retry sucessful invites, don't dispatch sendEvent, sendInvite etc
* Dedupe destinations, fix other bug hopefully
* Dispatch sends again
* Federation sender to ignore invites that are destined locally
* Loopback invite events
* Remodel a bit with channels
* Linter
* Only loopback invite event if we know the room
* We should tell other resident servers about the invite if we know about the room
* Correct invite signing
* Fix invite loopback
* Check HTTP response codes, push new invites to front of queue
* Review comments
2020-05-07 06:42:06 -05:00
|
|
|
statistics: statistics,
|
2020-04-29 09:29:39 -05:00
|
|
|
}
|
2020-04-29 05:34:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetupHTTP adds the FederationSenderInternalAPI handlers to the http.ServeMux.
|
2020-05-22 05:43:17 -05:00
|
|
|
func (f *FederationSenderInternalAPI) SetupHTTP(internalAPIMux *mux.Router) {
|
|
|
|
internalAPIMux.Handle(
|
2020-04-29 05:34:31 -05:00
|
|
|
api.FederationSenderQueryJoinedHostsInRoomPath,
|
2020-05-21 08:40:13 -05:00
|
|
|
internal.MakeInternalAPI("QueryJoinedHostsInRoom", func(req *http.Request) util.JSONResponse {
|
2020-04-29 05:34:31 -05:00
|
|
|
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}
|
|
|
|
}),
|
|
|
|
)
|
2020-05-22 05:43:17 -05:00
|
|
|
internalAPIMux.Handle(
|
2020-04-29 05:34:31 -05:00
|
|
|
api.FederationSenderQueryJoinedHostServerNamesInRoomPath,
|
2020-05-21 08:40:13 -05:00
|
|
|
internal.MakeInternalAPI("QueryJoinedHostServerNamesInRoom", func(req *http.Request) util.JSONResponse {
|
2020-04-29 05:34:31 -05:00
|
|
|
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}
|
|
|
|
}),
|
|
|
|
)
|
2020-05-22 05:43:17 -05:00
|
|
|
internalAPIMux.Handle(api.FederationSenderPerformJoinRequestPath,
|
2020-05-21 08:40:13 -05:00
|
|
|
internal.MakeInternalAPI("PerformJoinRequest", func(req *http.Request) util.JSONResponse {
|
2020-04-29 05:34:31 -05:00
|
|
|
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())
|
|
|
|
}
|
2020-04-29 09:29:39 -05:00
|
|
|
if err := f.PerformJoin(req.Context(), &request, &response); err != nil {
|
2020-04-29 05:34:31 -05:00
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2020-05-22 05:43:17 -05:00
|
|
|
internalAPIMux.Handle(api.FederationSenderPerformLeaveRequestPath,
|
2020-05-21 08:40:13 -05:00
|
|
|
internal.MakeInternalAPI("PerformLeaveRequest", func(req *http.Request) util.JSONResponse {
|
2020-04-29 05:34:31 -05:00
|
|
|
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())
|
|
|
|
}
|
2020-04-29 09:29:39 -05:00
|
|
|
if err := f.PerformLeave(req.Context(), &request, &response); err != nil {
|
2020-04-29 05:34:31 -05:00
|
|
|
return util.ErrorResponse(err)
|
|
|
|
}
|
|
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
|
|
}),
|
|
|
|
)
|
2020-05-26 08:41:16 -05:00
|
|
|
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}
|
|
|
|
}),
|
|
|
|
)
|
2020-04-29 05:34:31 -05:00
|
|
|
}
|