@@ -68,53 +68,56 @@ func TestEventBetweenMakeJoinAndSendJoinIsNotLost(t *testing.T) {
6868 // Complement server is not fully in the room until send_join completes, so
6969 // we can't use HandleTransactionRequests (which requires the room in
7070 // srv.rooms). Instead we parse the raw transaction body ourselves.
71- srv .Mux ().Handle ("/_matrix/federation/v1/send/{transactionID}" , http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
72- body , err := io .ReadAll (req .Body )
73- must .NotError (t , "failed to read request body in /send handler: %v" , err )
74- txn := gjson .ParseBytes (body )
75- txn .Get ("pdus" ).ForEach (func (_ , pdu gjson.Result ) bool {
76- eventID := pdu .Get ("event_id" ).String ()
77- eventType := pdu .Get ("type" ).String ()
78- t .Logf ("Received PDU via /send: type=%s id=%s" , eventType , eventID )
79-
80- // messageEventID is set after make_join but before send_join.
81- // Transactions can arrive before that window, so skip PDUs that
82- // arrive before we know which event to look for.
83- msgID , _ := messageEventID .Load ().(string )
84- if msgID == "" {
85- return true
86- }
71+ srv .Mux ().
72+ Handle ("/_matrix/federation/v1/send/{transactionID}" , http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
73+ body , err := io .ReadAll (req .Body )
74+ must .NotError (t , "failed to read request body in /send handler: %v" , err )
75+ txn := gjson .ParseBytes (body )
76+ txn .Get ("pdus" ).ForEach (func (_ , pdu gjson.Result ) bool {
77+ eventID := pdu .Get ("event_id" ).String ()
78+ eventType := pdu .Get ("type" ).String ()
79+ t .Logf ("Received PDU via /send: type=%s id=%s" , eventType , eventID )
80+
81+ // messageEventID is set after make_join but before send_join.
82+ // Transactions can arrive before that window, so skip PDUs that
83+ // arrive before we know which event to look for.
84+ msgID , _ := messageEventID .Load ().(string )
85+ if msgID == "" {
86+ return true
87+ }
8788
88- // Check if this IS the message event (server pushed it directly).
89- if eventID == msgID {
90- messageDiscoverableWaiter .Finish ()
91- return true
92- }
93-
94- // Check if this event's prev_events directly reference the message (e.g. a dummy
95- // event tying the two forward extremities together). If so, the joining server
96- // can backfill from that event and will discover the message.
97- //
98- // XXX: We only check one level of prev_events: if the reference is deeper in the
99- // DAG, it's valid and the joining server can still reach the message through
100- // backfill but our checks don't account for that yet (feel free to edit this
101- // assertion if you run into this)
102- pdu .Get ("prev_events" ).ForEach (func (_ , prevEvent gjson.Result ) bool {
103- if prevEvent .String () == msgID {
89+ // Check if this IS the message event (server pushed it directly).
90+ if eventID == msgID {
10491 messageDiscoverableWaiter .Finish ()
105- return false
92+ return true
10693 }
94+
95+ // Check if this event's prev_events directly reference the message (e.g. a dummy
96+ // event tying the two forward extremities together). If so, the joining server
97+ // can backfill from that event and will discover the message.
98+ //
99+ // XXX: We only check one level of prev_events: if the reference is deeper in the
100+ // DAG, it's valid and the joining server can still reach the message through
101+ // backfill but our checks don't account for that yet (feel free to edit this
102+ // assertion if you run into this)
103+ pdu .Get ("prev_events" ).ForEach (func (_ , prevEvent gjson.Result ) bool {
104+ if prevEvent .String () == msgID {
105+ messageDiscoverableWaiter .Finish ()
106+ return false
107+ }
108+ return true
109+ })
110+
107111 return true
108112 })
109-
110- return true
111- })
112- w .WriteHeader (200 )
113- // Respond with an empty PDU error map, which is the federation /send
114- // success response format: each key would be a PDU ID whose processing
115- // failed; an empty object means all PDUs were accepted.
116- w .Write ([]byte (`{"pdus":{}}` ))
117- })).Methods ("PUT" )
113+ w .WriteHeader (200 )
114+ // Respond with an empty PDU error map, which is the federation /send
115+ // success response format: each key would be a PDU ID whose processing
116+ // failed; an empty object means all PDUs were accepted.
117+ _ , err = w .Write ([]byte (`{"pdus":{}}` ))
118+ must .NotError (t , "failed to write response body in /send handler: %v" , err )
119+ })).
120+ Methods ("PUT" )
118121
119122 cancel := srv .Listen ()
120123 defer cancel ()
0 commit comments