-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a handler for federation transactions #47
Conversation
Add a handler which can accept a federation transaction, validate the PDUs and return errors in the case of failing to process a given PDU. EDUs are accepted but we currently don't do anything with them.
I've just realised that a proto version of this exists here: complement/tests/federation_room_send_test.go Lines 45 to 65 in a7d6117
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nil check is important.
internal/federation/handle.go
Outdated
@@ -277,3 +279,101 @@ func HandleMediaRequests(mediaIds map[string]func(w http.ResponseWriter)) func(* | |||
mediamux.Handle("/r0/download/{origin}/{mediaId}", downloadFn).Methods("GET") | |||
} | |||
} | |||
|
|||
// HandleTransactionRequests is an option which will process GET /_matrix/federation/v1/send/{transactionID} requests universally when requested. | |||
func HandleTransactionRequests() func(*Server) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be cute to have a callback function here which is passed with valid gmsl.Event
structs, since it's fairly common to want to process stuff on /send
. E.g:
func HandleTransactionRequests(cb func(gmsl.Event)) func(*Server) {
// when ready..
cb(event)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I was thinking, yeah. Then we could perhaps augment TestOutboundFederationSend
to use this instead, while slimming down the test at the same time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall I add another callback method for EDUs? Edit: have done so.
req.Body has already been read from via gmsl.VerifyHTTPRequest thus trying to read from it again produces an empty body. I also added some more error logging.
Realised there was a bug in that we were reading from Additionally I added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logging needs to be more explicit, and the panic on error needs to be fixed, otherwise LGTM
Updates the following tests to use the new transaction handler introduced in #47: * `TestOutboundFederationSend` - This test failed with Synapse with the inline transaction handler. Not entirely sure why, the handler function was just never called. * `TestOutboundFederationIgnoresMissingEventWithBadJSONForRoomVersion6` - Synapse will attempt to send presence to the remote homeserver. The test would fail if not expecting this.andler.
Add a handler which can accept a federation transaction, validate the PDUs and return errors in the case of failing to process a given PDU.
EDUs are accepted but we currently don't do anything with them.
This grew out of trying to fix
TestOutboundFederationIgnoresMissingEventWithBadJSONForRoomVersion6
for Synapse. The test would fail because as soon as Synapse joined the room, it would start trying to send presence EDUs to the new server. Rather than disabling presence, I thought it would be better to write a proper handler for it.I'll use this handler for that test (and possibly others) in a separate PR.