mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-13 21:02:25 +03:00
refactor: update GMSL (#3058)
Sister PR to https://github.com/matrix-org/gomatrixserverlib/pull/364 Read this commit by commit to avoid going insane.
This commit is contained in:
parent
9fa39263c0
commit
72285b2659
306 changed files with 2117 additions and 1934 deletions
|
@ -23,6 +23,7 @@ import (
|
|||
"github.com/getsentry/sentry-go"
|
||||
"github.com/matrix-org/gomatrixserverlib"
|
||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||
"github.com/matrix-org/gomatrixserverlib/spec"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/sirupsen/logrus"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
@ -43,12 +44,12 @@ type OutgoingQueues struct {
|
|||
process *process.ProcessContext
|
||||
disabled bool
|
||||
rsAPI api.FederationRoomserverAPI
|
||||
origin gomatrixserverlib.ServerName
|
||||
origin spec.ServerName
|
||||
client fedapi.FederationClient
|
||||
statistics *statistics.Statistics
|
||||
signing map[gomatrixserverlib.ServerName]*fclient.SigningIdentity
|
||||
signing map[spec.ServerName]*fclient.SigningIdentity
|
||||
queuesMutex sync.Mutex // protects the below
|
||||
queues map[gomatrixserverlib.ServerName]*destinationQueue
|
||||
queues map[spec.ServerName]*destinationQueue
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -87,7 +88,7 @@ func NewOutgoingQueues(
|
|||
db storage.Database,
|
||||
process *process.ProcessContext,
|
||||
disabled bool,
|
||||
origin gomatrixserverlib.ServerName,
|
||||
origin spec.ServerName,
|
||||
client fedapi.FederationClient,
|
||||
rsAPI api.FederationRoomserverAPI,
|
||||
statistics *statistics.Statistics,
|
||||
|
@ -101,15 +102,15 @@ func NewOutgoingQueues(
|
|||
origin: origin,
|
||||
client: client,
|
||||
statistics: statistics,
|
||||
signing: map[gomatrixserverlib.ServerName]*fclient.SigningIdentity{},
|
||||
queues: map[gomatrixserverlib.ServerName]*destinationQueue{},
|
||||
signing: map[spec.ServerName]*fclient.SigningIdentity{},
|
||||
queues: map[spec.ServerName]*destinationQueue{},
|
||||
}
|
||||
for _, identity := range signing {
|
||||
queues.signing[identity.ServerName] = identity
|
||||
}
|
||||
// Look up which servers we have pending items for and then rehydrate those queues.
|
||||
if !disabled {
|
||||
serverNames := map[gomatrixserverlib.ServerName]struct{}{}
|
||||
serverNames := map[spec.ServerName]struct{}{}
|
||||
if names, err := db.GetPendingPDUServerNames(process.Context()); err == nil {
|
||||
for _, serverName := range names {
|
||||
serverNames[serverName] = struct{}{}
|
||||
|
@ -148,7 +149,7 @@ type queuedEDU struct {
|
|||
edu *gomatrixserverlib.EDU
|
||||
}
|
||||
|
||||
func (oqs *OutgoingQueues) getQueue(destination gomatrixserverlib.ServerName) *destinationQueue {
|
||||
func (oqs *OutgoingQueues) getQueue(destination spec.ServerName) *destinationQueue {
|
||||
if oqs.statistics.ForServer(destination).Blacklisted() {
|
||||
return nil
|
||||
}
|
||||
|
@ -187,8 +188,8 @@ func (oqs *OutgoingQueues) clearQueue(oq *destinationQueue) {
|
|||
|
||||
// SendEvent sends an event to the destinations
|
||||
func (oqs *OutgoingQueues) SendEvent(
|
||||
ev *gomatrixserverlib.HeaderedEvent, origin gomatrixserverlib.ServerName,
|
||||
destinations []gomatrixserverlib.ServerName,
|
||||
ev *gomatrixserverlib.HeaderedEvent, origin spec.ServerName,
|
||||
destinations []spec.ServerName,
|
||||
) error {
|
||||
if oqs.disabled {
|
||||
log.Trace("Federation is disabled, not sending event")
|
||||
|
@ -203,7 +204,7 @@ func (oqs *OutgoingQueues) SendEvent(
|
|||
|
||||
// Deduplicate destinations and remove the origin from the list of
|
||||
// destinations just to be sure.
|
||||
destmap := map[gomatrixserverlib.ServerName]struct{}{}
|
||||
destmap := map[spec.ServerName]struct{}{}
|
||||
for _, d := range destinations {
|
||||
destmap[d] = struct{}{}
|
||||
}
|
||||
|
@ -277,8 +278,8 @@ func (oqs *OutgoingQueues) SendEvent(
|
|||
|
||||
// SendEDU sends an EDU event to the destinations.
|
||||
func (oqs *OutgoingQueues) SendEDU(
|
||||
e *gomatrixserverlib.EDU, origin gomatrixserverlib.ServerName,
|
||||
destinations []gomatrixserverlib.ServerName,
|
||||
e *gomatrixserverlib.EDU, origin spec.ServerName,
|
||||
destinations []spec.ServerName,
|
||||
) error {
|
||||
if oqs.disabled {
|
||||
log.Trace("Federation is disabled, not sending EDU")
|
||||
|
@ -293,7 +294,7 @@ func (oqs *OutgoingQueues) SendEDU(
|
|||
|
||||
// Deduplicate destinations and remove the origin from the list of
|
||||
// destinations just to be sure.
|
||||
destmap := map[gomatrixserverlib.ServerName]struct{}{}
|
||||
destmap := map[spec.ServerName]struct{}{}
|
||||
for _, d := range destinations {
|
||||
destmap[d] = struct{}{}
|
||||
}
|
||||
|
@ -376,7 +377,7 @@ func (oqs *OutgoingQueues) SendEDU(
|
|||
}
|
||||
|
||||
// RetryServer attempts to resend events to the given server if we had given up.
|
||||
func (oqs *OutgoingQueues) RetryServer(srv gomatrixserverlib.ServerName, wasBlacklisted bool) {
|
||||
func (oqs *OutgoingQueues) RetryServer(srv spec.ServerName, wasBlacklisted bool) {
|
||||
if oqs.disabled {
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue