Loopback event from invite response (#982)

* Working invite v2 support

* Fix copyright notice

* Update gomatrixserverlib

* Add fallthrough

* Add missing continue

* Update sytest-whitelist, gomatrixserverlib

* Update gomatrixserverlib to test matrix-org/gomatrixserverlib#181

* Update gomatrixserverlib
This commit is contained in:
Neil Alexander 2020-04-28 10:53:07 +01:00 committed by GitHub
parent 87f05721b0
commit 3a858afca2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 135 additions and 28 deletions

View file

@ -21,6 +21,7 @@ import (
"sync"
"time"
"github.com/matrix-org/dendrite/federationsender/producers"
"github.com/matrix-org/gomatrixserverlib"
"github.com/matrix-org/util"
log "github.com/sirupsen/logrus"
@ -32,6 +33,7 @@ import (
// ensures that only one request is in flight to a given destination
// at a time.
type destinationQueue struct {
rsProducer *producers.RoomserverProducer
client *gomatrixserverlib.FederationClient
origin gomatrixserverlib.ServerName
destination gomatrixserverlib.ServerName
@ -165,18 +167,38 @@ func (oq *destinationQueue) nextInvites() bool {
}
for _, inviteReq := range oq.pendingInvites {
ev := inviteReq.Event()
ev, roomVersion := inviteReq.Event(), inviteReq.RoomVersion()
if _, err := oq.client.SendInviteV2(
log.WithFields(log.Fields{
"event_id": ev.EventID(),
"room_version": roomVersion,
"destination": oq.destination,
}).Info("sending invite")
inviteRes, err := oq.client.SendInviteV2(
context.TODO(),
oq.destination,
*inviteReq,
); err != nil {
)
if err != nil {
log.WithFields(log.Fields{
"event_id": ev.EventID(),
"state_key": ev.StateKey(),
"destination": oq.destination,
}).WithError(err).Error("failed to send invite")
continue
}
if _, err = oq.rsProducer.SendInviteResponse(
context.TODO(),
inviteRes,
roomVersion,
); err != nil {
log.WithFields(log.Fields{
"event_id": ev.EventID(),
"state_key": ev.StateKey(),
"destination": oq.destination,
}).WithError(err).Error("failed to return signed invite to roomserver")
}
}

View file

@ -18,6 +18,7 @@ import (
"fmt"
"sync"
"github.com/matrix-org/dendrite/federationsender/producers"
"github.com/matrix-org/gomatrixserverlib"
log "github.com/sirupsen/logrus"
)
@ -25,19 +26,25 @@ import (
// OutgoingQueues is a collection of queues for sending transactions to other
// matrix servers
type OutgoingQueues struct {
origin gomatrixserverlib.ServerName
client *gomatrixserverlib.FederationClient
rsProducer *producers.RoomserverProducer
origin gomatrixserverlib.ServerName
client *gomatrixserverlib.FederationClient
// The queuesMutex protects queues
queuesMutex sync.Mutex
queues map[gomatrixserverlib.ServerName]*destinationQueue
}
// NewOutgoingQueues makes a new OutgoingQueues
func NewOutgoingQueues(origin gomatrixserverlib.ServerName, client *gomatrixserverlib.FederationClient) *OutgoingQueues {
func NewOutgoingQueues(
origin gomatrixserverlib.ServerName,
client *gomatrixserverlib.FederationClient,
rsProducer *producers.RoomserverProducer,
) *OutgoingQueues {
return &OutgoingQueues{
origin: origin,
client: client,
queues: map[gomatrixserverlib.ServerName]*destinationQueue{},
rsProducer: rsProducer,
origin: origin,
client: client,
queues: map[gomatrixserverlib.ServerName]*destinationQueue{},
}
}
@ -67,6 +74,7 @@ func (oqs *OutgoingQueues) SendEvent(
oq := oqs.queues[destination]
if oq == nil {
oq = &destinationQueue{
rsProducer: oqs.rsProducer,
origin: oqs.origin,
destination: destination,
client: oqs.client,
@ -111,6 +119,7 @@ func (oqs *OutgoingQueues) SendInvite(
oq := oqs.queues[destination]
if oq == nil {
oq = &destinationQueue{
rsProducer: oqs.rsProducer,
origin: oqs.origin,
destination: destination,
client: oqs.client,
@ -151,6 +160,7 @@ func (oqs *OutgoingQueues) SendEDU(
oq := oqs.queues[destination]
if oq == nil {
oq = &destinationQueue{
rsProducer: oqs.rsProducer,
origin: oqs.origin,
destination: destination,
client: oqs.client,