From 9a63837e6252a7d5017c8585f27b2594f4d33c36 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 17 Apr 2020 16:56:24 +0100 Subject: [PATCH] Attempt to find missing auth events over federation (this shouldn't happen but I am guessing there is a synapse bug involved where we don't get all of the auth events) --- clientapi/routing/joinroom.go | 40 ++++++++++++++++++++++++++++++++++- go.mod | 2 +- go.sum | 4 ++-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/clientapi/routing/joinroom.go b/clientapi/routing/joinroom.go index 0f1a9ba4d..4439bab58 100644 --- a/clientapi/routing/joinroom.go +++ b/clientapi/routing/joinroom.go @@ -365,8 +365,46 @@ func (r joinRoomReq) joinRoomUsingServer(roomID string, server gomatrixserverlib return nil, fmt.Errorf("r.federation.SendJoin: %w", err) } + // A list of events that we have retried, if they were not included in + // the auth events supplied in the send_join. + retries := map[string]bool{} + +retryCheck: + fmt.Println("STATE EVENTS:") + for _, e := range respSendJoin.StateEvents { + fmt.Println("*", e.EventID()) + } + fmt.Println("AUTH EVENTS:") + for _, e := range respSendJoin.AuthEvents { + fmt.Println("*", e.EventID()) + } if err = respSendJoin.Check(r.req.Context(), r.keyRing, event); err != nil { - return nil, fmt.Errorf("respSendJoin: %w", err) + switch e := err.(type) { + case gomatrixserverlib.MissingAuthEventError: + // Check that we haven't already retried for this event, prevents + // us from ending up in endless loops + if _, ok := retries[e.AuthEventID]; !ok { + // Ask the server that we're talking to right now for the event + tx, txerr := r.federation.GetEvent(r.req.Context(), server, e.AuthEventID) + if txerr != nil { + return nil, fmt.Errorf("r.federation.GetEvent: %w", txerr) + } + // For each event returned, add it to the auth events. + for _, pdu := range tx.PDUs { + ev, everr := gomatrixserverlib.NewEventFromUntrustedJSON(pdu, respMakeJoin.RoomVersion) + if everr != nil { + return nil, fmt.Errorf("gomatrixserverlib.NewEventFromUntrustedJSON: %w", everr) + } + respSendJoin.AuthEvents = append(respSendJoin.AuthEvents, ev) + } + // Mark the event as retried and then give the check another go. + retries[e.AuthEventID] = true + goto retryCheck + } + return nil, fmt.Errorf("respSendJoin (after retries): %w", e) + default: + return nil, fmt.Errorf("respSendJoin: %w", err) + } } if err = r.producer.SendEventWithState( diff --git a/go.mod b/go.mod index aa75a66f4..485de4bc7 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/matrix-org/go-http-js-libp2p v0.0.0-20200318135427-31631a9ef51f github.com/matrix-org/go-sqlite3-js v0.0.0-20200325174927-327088cdef10 github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 - github.com/matrix-org/gomatrixserverlib v0.0.0-20200417121920-a7a5d963b596 + github.com/matrix-org/gomatrixserverlib v0.0.0-20200417154207-c38787065567 github.com/matrix-org/naffka v0.0.0-20200127221512-0716baaabaf1 github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7 github.com/mattn/go-sqlite3 v2.0.3+incompatible diff --git a/go.sum b/go.sum index 7d5e5789a..80db083ed 100644 --- a/go.sum +++ b/go.sum @@ -364,8 +364,8 @@ github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26 h1:Hr3zjRsq2bh github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26/go.mod h1:3fxX6gUjWyI/2Bt7J1OLhpCzOfO/bB3AiX0cJtEKud0= github.com/matrix-org/gomatrixserverlib v0.0.0-20200124100636-0c2ec91d1df5 h1:kmRjpmFOenVpOaV/DRlo9p6z/IbOKlUC+hhKsAAh8Qg= github.com/matrix-org/gomatrixserverlib v0.0.0-20200124100636-0c2ec91d1df5/go.mod h1:FsKa2pWE/bpQql9H7U4boOPXFoJX/QcqaZZ6ijLkaZI= -github.com/matrix-org/gomatrixserverlib v0.0.0-20200417121920-a7a5d963b596 h1:+FBAOVJgB4BWbiBOYM96A1SqI+rUHVPRc0NlyTmp2oI= -github.com/matrix-org/gomatrixserverlib v0.0.0-20200417121920-a7a5d963b596/go.mod h1:FsKa2pWE/bpQql9H7U4boOPXFoJX/QcqaZZ6ijLkaZI= +github.com/matrix-org/gomatrixserverlib v0.0.0-20200417154207-c38787065567 h1:IjnhrozHJ4yzj52GLI98O3GnVL7BBxR0kr4yS93yfQw= +github.com/matrix-org/gomatrixserverlib v0.0.0-20200417154207-c38787065567/go.mod h1:FsKa2pWE/bpQql9H7U4boOPXFoJX/QcqaZZ6ijLkaZI= github.com/matrix-org/naffka v0.0.0-20200127221512-0716baaabaf1 h1:osLoFdOy+ChQqVUn2PeTDETFftVkl4w9t/OW18g3lnk= github.com/matrix-org/naffka v0.0.0-20200127221512-0716baaabaf1/go.mod h1:cXoYQIENbdWIQHt1SyCo6Bl3C3raHwJ0wgVrXHSqf+A= github.com/matrix-org/util v0.0.0-20171127121716-2e2df66af2f5 h1:W7l5CP4V7wPyPb4tYE11dbmeAOwtFQBTW0rf4OonOS8=