2020-05-01 14:01:50 +02:00
|
|
|
package internal
|
2020-04-29 12:34:31 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2020-06-25 16:04:48 +02:00
|
|
|
"errors"
|
2020-04-29 16:29:39 +02:00
|
|
|
"fmt"
|
|
|
|
"time"
|
2020-04-29 12:34:31 +02:00
|
|
|
|
|
|
|
"github.com/matrix-org/dendrite/federationsender/api"
|
2020-05-01 14:01:50 +02:00
|
|
|
"github.com/matrix-org/dendrite/federationsender/internal/perform"
|
2020-06-10 17:54:43 +02:00
|
|
|
roomserverAPI "github.com/matrix-org/dendrite/roomserver/api"
|
2020-04-29 16:29:39 +02:00
|
|
|
"github.com/matrix-org/dendrite/roomserver/version"
|
2020-06-25 16:04:48 +02:00
|
|
|
"github.com/matrix-org/gomatrix"
|
2020-04-29 16:29:39 +02:00
|
|
|
"github.com/matrix-org/gomatrixserverlib"
|
2020-05-04 14:53:47 +02:00
|
|
|
"github.com/matrix-org/util"
|
|
|
|
"github.com/sirupsen/logrus"
|
2020-04-29 12:34:31 +02:00
|
|
|
)
|
|
|
|
|
2020-05-04 14:53:47 +02:00
|
|
|
// PerformLeaveRequest implements api.FederationSenderInternalAPI
|
|
|
|
func (r *FederationSenderInternalAPI) PerformDirectoryLookup(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformDirectoryLookupRequest,
|
|
|
|
response *api.PerformDirectoryLookupResponse,
|
|
|
|
) (err error) {
|
|
|
|
dir, err := r.federation.LookupRoomAlias(
|
|
|
|
ctx,
|
|
|
|
request.ServerName,
|
|
|
|
request.RoomAlias,
|
|
|
|
)
|
|
|
|
if err != nil {
|
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 13:42:06 +02:00
|
|
|
r.statistics.ForServer(request.ServerName).Failure()
|
2020-05-04 14:53:47 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
response.RoomID = dir.RoomID
|
|
|
|
response.ServerNames = dir.Servers
|
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 13:42:06 +02:00
|
|
|
r.statistics.ForServer(request.ServerName).Success()
|
2020-05-04 14:53:47 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-04-29 12:34:31 +02:00
|
|
|
// PerformJoinRequest implements api.FederationSenderInternalAPI
|
2020-04-29 16:29:39 +02:00
|
|
|
func (r *FederationSenderInternalAPI) PerformJoin(
|
2020-04-29 12:34:31 +02:00
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformJoinRequest,
|
|
|
|
response *api.PerformJoinResponse,
|
2020-06-25 16:04:48 +02:00
|
|
|
) {
|
2020-04-29 16:29:39 +02:00
|
|
|
// Look up the supported room versions.
|
|
|
|
var supportedVersions []gomatrixserverlib.RoomVersion
|
|
|
|
for version := range version.SupportedRoomVersions() {
|
|
|
|
supportedVersions = append(supportedVersions, version)
|
|
|
|
}
|
|
|
|
|
2020-05-29 14:50:06 +02:00
|
|
|
// Deduplicate the server names we were provided but keep the ordering
|
|
|
|
// as this encodes useful information about which servers are most likely
|
|
|
|
// to respond.
|
|
|
|
seenSet := make(map[gomatrixserverlib.ServerName]bool)
|
|
|
|
var uniqueList []gomatrixserverlib.ServerName
|
|
|
|
for _, srv := range request.ServerNames {
|
|
|
|
if seenSet[srv] {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
seenSet[srv] = true
|
|
|
|
uniqueList = append(uniqueList, srv)
|
|
|
|
}
|
|
|
|
request.ServerNames = uniqueList
|
2020-04-29 16:29:39 +02:00
|
|
|
|
2020-05-04 14:53:47 +02:00
|
|
|
// Try each server that we were provided until we land on one that
|
|
|
|
// successfully completes the make-join send-join dance.
|
2020-06-25 16:04:48 +02:00
|
|
|
var lastErr error
|
2020-05-04 14:53:47 +02:00
|
|
|
for _, serverName := range request.ServerNames {
|
2020-05-15 14:55:14 +02:00
|
|
|
if err := r.performJoinUsingServer(
|
2020-05-04 14:53:47 +02:00
|
|
|
ctx,
|
|
|
|
request.RoomID,
|
|
|
|
request.UserID,
|
2020-05-15 14:55:14 +02:00
|
|
|
request.Content,
|
2020-05-04 14:53:47 +02:00
|
|
|
serverName,
|
2020-05-15 14:55:14 +02:00
|
|
|
supportedVersions,
|
2020-05-04 14:53:47 +02:00
|
|
|
); err != nil {
|
2020-05-15 14:55:14 +02:00
|
|
|
logrus.WithError(err).WithFields(logrus.Fields{
|
|
|
|
"server_name": serverName,
|
|
|
|
"room_id": request.RoomID,
|
|
|
|
}).Warnf("Failed to join room through server")
|
2020-06-25 16:04:48 +02:00
|
|
|
lastErr = err
|
2020-05-04 14:53:47 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're all good.
|
2020-06-25 16:04:48 +02:00
|
|
|
return
|
2020-04-29 16:29:39 +02:00
|
|
|
}
|
|
|
|
|
2020-05-04 14:53:47 +02:00
|
|
|
// If we reach here then we didn't complete a join for some reason.
|
2020-06-25 16:04:48 +02:00
|
|
|
var httpErr gomatrix.HTTPError
|
|
|
|
if ok := errors.As(lastErr, &httpErr); ok {
|
|
|
|
httpErr.Message = string(httpErr.Contents)
|
|
|
|
// Clear the wrapped error, else serialising to JSON (in polylith mode) will fail
|
|
|
|
httpErr.WrappedError = nil
|
|
|
|
response.LastError = &httpErr
|
|
|
|
} else {
|
|
|
|
response.LastError = &gomatrix.HTTPError{
|
|
|
|
Code: 0,
|
|
|
|
WrappedError: nil,
|
|
|
|
Message: lastErr.Error(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logrus.Errorf(
|
|
|
|
"failed to join user %q to room %q through %d server(s): last error %s",
|
|
|
|
request.UserID, request.RoomID, len(request.ServerNames), lastErr,
|
2020-05-04 14:53:47 +02:00
|
|
|
)
|
2020-04-29 12:34:31 +02:00
|
|
|
}
|
|
|
|
|
2020-05-15 14:55:14 +02:00
|
|
|
func (r *FederationSenderInternalAPI) performJoinUsingServer(
|
|
|
|
ctx context.Context,
|
|
|
|
roomID, userID string,
|
|
|
|
content map[string]interface{},
|
|
|
|
serverName gomatrixserverlib.ServerName,
|
|
|
|
supportedVersions []gomatrixserverlib.RoomVersion,
|
|
|
|
) error {
|
|
|
|
// Try to perform a make_join using the information supplied in the
|
|
|
|
// request.
|
|
|
|
respMakeJoin, err := r.federation.MakeJoin(
|
|
|
|
ctx,
|
|
|
|
serverName,
|
|
|
|
roomID,
|
|
|
|
userID,
|
|
|
|
supportedVersions,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
// TODO: Check if the user was not allowed to join the room.
|
|
|
|
r.statistics.ForServer(serverName).Failure()
|
|
|
|
return fmt.Errorf("r.federation.MakeJoin: %w", err)
|
|
|
|
}
|
|
|
|
r.statistics.ForServer(serverName).Success()
|
|
|
|
|
|
|
|
// Set all the fields to be what they should be, this should be a no-op
|
|
|
|
// but it's possible that the remote server returned us something "odd"
|
|
|
|
respMakeJoin.JoinEvent.Type = gomatrixserverlib.MRoomMember
|
|
|
|
respMakeJoin.JoinEvent.Sender = userID
|
|
|
|
respMakeJoin.JoinEvent.StateKey = &userID
|
|
|
|
respMakeJoin.JoinEvent.RoomID = roomID
|
|
|
|
respMakeJoin.JoinEvent.Redacts = ""
|
|
|
|
if content == nil {
|
|
|
|
content = map[string]interface{}{}
|
|
|
|
}
|
|
|
|
content["membership"] = "join"
|
|
|
|
if err = respMakeJoin.JoinEvent.SetContent(content); err != nil {
|
|
|
|
return fmt.Errorf("respMakeJoin.JoinEvent.SetContent: %w", err)
|
|
|
|
}
|
|
|
|
if err = respMakeJoin.JoinEvent.SetUnsigned(struct{}{}); err != nil {
|
|
|
|
return fmt.Errorf("respMakeJoin.JoinEvent.SetUnsigned: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Work out if we support the room version that has been supplied in
|
|
|
|
// the make_join response.
|
|
|
|
if respMakeJoin.RoomVersion == "" {
|
|
|
|
respMakeJoin.RoomVersion = gomatrixserverlib.RoomVersionV1
|
|
|
|
}
|
|
|
|
if _, err = respMakeJoin.RoomVersion.EventFormat(); err != nil {
|
|
|
|
return fmt.Errorf("respMakeJoin.RoomVersion.EventFormat: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the join event.
|
|
|
|
event, err := respMakeJoin.JoinEvent.Build(
|
|
|
|
time.Now(),
|
|
|
|
r.cfg.Matrix.ServerName,
|
|
|
|
r.cfg.Matrix.KeyID,
|
|
|
|
r.cfg.Matrix.PrivateKey,
|
|
|
|
respMakeJoin.RoomVersion,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("respMakeJoin.JoinEvent.Build: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to perform a send_join using the newly built event.
|
|
|
|
respSendJoin, err := r.federation.SendJoin(
|
|
|
|
ctx,
|
|
|
|
serverName,
|
|
|
|
event,
|
|
|
|
respMakeJoin.RoomVersion,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
r.statistics.ForServer(serverName).Failure()
|
|
|
|
return fmt.Errorf("r.federation.SendJoin: %w", err)
|
|
|
|
}
|
|
|
|
r.statistics.ForServer(serverName).Success()
|
|
|
|
|
|
|
|
// Check that the send_join response was valid.
|
|
|
|
joinCtx := perform.JoinContext(r.federation, r.keyRing)
|
2020-09-07 17:54:51 +02:00
|
|
|
respState, err := joinCtx.CheckSendJoinResponse(
|
2020-05-15 14:55:14 +02:00
|
|
|
ctx, event, serverName, respMakeJoin, respSendJoin,
|
2020-09-07 17:54:51 +02:00
|
|
|
)
|
|
|
|
if err != nil {
|
2020-05-15 14:55:14 +02:00
|
|
|
return fmt.Errorf("joinCtx.CheckSendJoinResponse: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we successfully performed a send_join above then the other
|
|
|
|
// server now thinks we're a part of the room. Send the newly
|
|
|
|
// returned state to the roomserver to update our local view.
|
2020-06-10 17:54:43 +02:00
|
|
|
if err = roomserverAPI.SendEventWithState(
|
|
|
|
ctx, r.rsAPI,
|
2020-09-07 17:54:51 +02:00
|
|
|
respState,
|
|
|
|
event.Headered(respMakeJoin.RoomVersion),
|
|
|
|
nil,
|
2020-05-15 14:55:14 +02:00
|
|
|
); err != nil {
|
|
|
|
return fmt.Errorf("r.producer.SendEventWithState: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-04-29 12:34:31 +02:00
|
|
|
// PerformLeaveRequest implements api.FederationSenderInternalAPI
|
2020-04-29 16:29:39 +02:00
|
|
|
func (r *FederationSenderInternalAPI) PerformLeave(
|
2020-04-29 12:34:31 +02:00
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformLeaveRequest,
|
|
|
|
response *api.PerformLeaveResponse,
|
|
|
|
) (err error) {
|
2020-05-04 19:34:09 +02:00
|
|
|
// Deduplicate the server names we were provided.
|
2020-05-07 18:14:32 +02:00
|
|
|
util.SortAndUnique(request.ServerNames)
|
2020-05-04 19:34:09 +02:00
|
|
|
|
|
|
|
// Try each server that we were provided until we land on one that
|
|
|
|
// successfully completes the make-leave send-leave dance.
|
|
|
|
for _, serverName := range request.ServerNames {
|
|
|
|
// Try to perform a make_leave using the information supplied in the
|
|
|
|
// request.
|
|
|
|
respMakeLeave, err := r.federation.MakeLeave(
|
|
|
|
ctx,
|
|
|
|
serverName,
|
|
|
|
request.RoomID,
|
|
|
|
request.UserID,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
// TODO: Check if the user was not allowed to leave the room.
|
|
|
|
logrus.WithError(err).Warnf("r.federation.MakeLeave failed")
|
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 13:42:06 +02:00
|
|
|
r.statistics.ForServer(serverName).Failure()
|
2020-05-04 19:34:09 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set all the fields to be what they should be, this should be a no-op
|
|
|
|
// but it's possible that the remote server returned us something "odd"
|
|
|
|
respMakeLeave.LeaveEvent.Type = gomatrixserverlib.MRoomMember
|
|
|
|
respMakeLeave.LeaveEvent.Sender = request.UserID
|
|
|
|
respMakeLeave.LeaveEvent.StateKey = &request.UserID
|
|
|
|
respMakeLeave.LeaveEvent.RoomID = request.RoomID
|
|
|
|
respMakeLeave.LeaveEvent.Redacts = ""
|
|
|
|
if respMakeLeave.LeaveEvent.Content == nil {
|
|
|
|
content := map[string]interface{}{
|
|
|
|
"membership": "leave",
|
|
|
|
}
|
|
|
|
if err = respMakeLeave.LeaveEvent.SetContent(content); err != nil {
|
|
|
|
logrus.WithError(err).Warnf("respMakeLeave.LeaveEvent.SetContent failed")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err = respMakeLeave.LeaveEvent.SetUnsigned(struct{}{}); err != nil {
|
|
|
|
logrus.WithError(err).Warnf("respMakeLeave.LeaveEvent.SetUnsigned failed")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Work out if we support the room version that has been supplied in
|
|
|
|
// the make_leave response.
|
|
|
|
if _, err = respMakeLeave.RoomVersion.EventFormat(); err != nil {
|
|
|
|
return gomatrixserverlib.UnsupportedRoomVersionError{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the leave event.
|
|
|
|
event, err := respMakeLeave.LeaveEvent.Build(
|
|
|
|
time.Now(),
|
|
|
|
r.cfg.Matrix.ServerName,
|
|
|
|
r.cfg.Matrix.KeyID,
|
|
|
|
r.cfg.Matrix.PrivateKey,
|
|
|
|
respMakeLeave.RoomVersion,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
logrus.WithError(err).Warnf("respMakeLeave.LeaveEvent.Build failed")
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to perform a send_leave using the newly built event.
|
|
|
|
err = r.federation.SendLeave(
|
|
|
|
ctx,
|
|
|
|
serverName,
|
|
|
|
event,
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
logrus.WithError(err).Warnf("r.federation.SendLeave failed")
|
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 13:42:06 +02:00
|
|
|
r.statistics.ForServer(serverName).Failure()
|
2020-05-04 19:34:09 +02:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
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 13:42:06 +02:00
|
|
|
r.statistics.ForServer(serverName).Success()
|
2020-05-04 19:34:09 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we reach here then we didn't complete a leave for some reason.
|
|
|
|
return fmt.Errorf(
|
|
|
|
"Failed to leave room %q through %d server(s)",
|
|
|
|
request.RoomID, len(request.ServerNames),
|
|
|
|
)
|
2020-04-29 12:34:31 +02:00
|
|
|
}
|
2020-06-01 19:34:08 +02:00
|
|
|
|
2020-08-17 12:40:49 +02:00
|
|
|
// PerformLeaveRequest implements api.FederationSenderInternalAPI
|
|
|
|
func (r *FederationSenderInternalAPI) PerformInvite(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformInviteRequest,
|
|
|
|
response *api.PerformInviteResponse,
|
|
|
|
) (err error) {
|
|
|
|
if request.Event.StateKey() == nil {
|
|
|
|
return errors.New("invite must be a state event")
|
|
|
|
}
|
|
|
|
|
|
|
|
_, destination, err := gomatrixserverlib.SplitID('@', *request.Event.StateKey())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("gomatrixserverlib.SplitID: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
logrus.WithFields(logrus.Fields{
|
|
|
|
"event_id": request.Event.EventID(),
|
|
|
|
"user_id": *request.Event.StateKey(),
|
|
|
|
"room_id": request.Event.RoomID(),
|
|
|
|
"room_version": request.RoomVersion,
|
|
|
|
"destination": destination,
|
|
|
|
}).Info("Sending invite")
|
|
|
|
|
|
|
|
inviteReq, err := gomatrixserverlib.NewInviteV2Request(&request.Event, request.InviteRoomState)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("gomatrixserverlib.NewInviteV2Request: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
inviteRes, err := r.federation.SendInviteV2(ctx, destination, inviteReq)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("r.federation.SendInviteV2: %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
response.Event = inviteRes.Event.Headered(request.RoomVersion)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-06-01 19:34:08 +02:00
|
|
|
// PerformServersAlive implements api.FederationSenderInternalAPI
|
|
|
|
func (r *FederationSenderInternalAPI) PerformServersAlive(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformServersAliveRequest,
|
|
|
|
response *api.PerformServersAliveResponse,
|
|
|
|
) (err error) {
|
|
|
|
for _, srv := range request.Servers {
|
|
|
|
r.queues.RetryServer(srv)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-07-16 14:52:08 +02:00
|
|
|
|
|
|
|
// PerformServersAlive implements api.FederationSenderInternalAPI
|
|
|
|
func (r *FederationSenderInternalAPI) PerformBroadcastEDU(
|
|
|
|
ctx context.Context,
|
|
|
|
request *api.PerformBroadcastEDURequest,
|
|
|
|
response *api.PerformBroadcastEDUResponse,
|
|
|
|
) (err error) {
|
|
|
|
destinations, err := r.db.GetAllJoinedHosts(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("r.db.GetAllJoinedHosts: %w", err)
|
|
|
|
}
|
2020-08-06 17:00:42 +02:00
|
|
|
if len(destinations) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
logrus.WithContext(ctx).Infof("Sending wake-up EDU to %d destination(s)", len(destinations))
|
2020-07-16 14:52:08 +02:00
|
|
|
|
|
|
|
edu := &gomatrixserverlib.EDU{
|
|
|
|
Type: "org.matrix.dendrite.wakeup",
|
|
|
|
Origin: string(r.cfg.Matrix.ServerName),
|
|
|
|
}
|
|
|
|
if err = r.queues.SendEDU(edu, r.cfg.Matrix.ServerName, destinations); err != nil {
|
|
|
|
return fmt.Errorf("r.queues.SendEDU: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-08-06 17:00:42 +02:00
|
|
|
wakeReq := &api.PerformServersAliveRequest{
|
|
|
|
Servers: destinations,
|
|
|
|
}
|
|
|
|
wakeRes := &api.PerformServersAliveResponse{}
|
|
|
|
if err := r.PerformServersAlive(ctx, wakeReq, wakeRes); err != nil {
|
|
|
|
return fmt.Errorf("r.PerformServersAlive: %w", err)
|
|
|
|
}
|
|
|
|
|
2020-07-16 14:52:08 +02:00
|
|
|
return nil
|
|
|
|
}
|