Add support for downstream labeled-response #55
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "delthas/soju:feature-labeled-response"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Moved over from: https://github.com/emersion/soju/pull/40
Rebased since May 2022! 💪😭
This adds support for downstream labeled response. Instead of doing
specific processing on each SendMessage call site, the idea is to add
some logic to SendMessage.
The cap is advertised only in single-upstream mode when the upstream
server supports it too.
When handling a downstream message, we store the label of the current
message we're processing, in the downstream struct. (This should be
understood as data whose lifetime is limited to the processing of one
message. It is reset when we're done handling the message.)
During the handling of that downstream message, at any point, when we
send out messages to this downstream:
that batch.
Then, at the end of the processing:
This enables us to always send the minimum amount of messages.
While we may send messages to many upstreams and downstreams, obviosuly
only the downstream from which the message we're processing was received
is affected.
A special case affects the above behavior, which makes it differ from a
typical server implementation. Soju handles many commands by forwarding
the command to the server, ending the downstream message handling
without responding anything, then forwarding the server response later
when we receive it.
In this case we must not send an empty ACK at the end of our routine,
but we must instead not send anything, copy the message label to the
message we're sending to the server, and then when we get the response
(or batches) from the server, forward that to the downstream.
Examples:
(This is a bit more complicated because we wrap downstream labels with
our own labels.)
The patch therefore adds a DeferredResponse method to downstreamConn,
which basically tells it not to send an empty ACK at the end of the
routine, because we'll do a proper response later.
When handling upstream messages, we extract the downstream label from
the server labeled response, if it exists. We also extract the
downstream batch tag if it corresponds to a label. We store that info in
the downstreamConn, much like the downstream message handling.
We forward BATCH + and BATCH - as is, even keeping the same batch IDs.
This way, we also support cases where the server responds with a single
message but our logic turns that into multiple messages, or no messages.
(We'd buffer the first message, open a batch, send the messages, close
it etc. just like the downstream message case.)
Some cases are a bit more difficult to implement and not really useful.
(And also not mandatory according to the spec since this is
best-effort.) Those were left TODO for now.
7507260f9c1d7c27131dI've rebased this patch against master.
1d7c27131d7b8a99cad4I've pushed the
ircErrorhandling change as967cb94695, because it had value on its own.7b8a99cad4da1f7af720This is what I had in mind regarding context use over stuffing temporary fields into
downstreamConn: https://codeberg.org/emersion/soju/compare/master...downstream-labeled-responseDo you see an issue with this approach?
da1f7af7207569b3c7daOK, updated based on your approach, using contexts. Testing.
Also rebased ofc ;)
Wishing a happy 40th month anniversary to this MR! 🎂
7569b3c7da70c4ded594Late is better than never.
Many thanks!