Skip to content

Conversation

flub
Copy link
Collaborator

@flub flub commented Apr 11, 2025

This applies the refactors from quinn-rs#2168 and quinn-rs#2195 onto our multipath branch!

flub added 9 commits April 10, 2025 14:21
This TransmitBuf is a wrapper around the buffer in which datagrams are
being created.  It keeps track of the state required to know the
boundaries of the datagrams in the buffer.
This removes the extra arguments from Packetbuilder::new that tell the
builder about datagram boundaries in favour of using the state of
TransmitBuf directly.
This moves the logic of updating the buffer for new datagrams into a
function on the TransmitBuf.  This centralises all the manipulation of
these variables into one logical place, ensuring all the invariants
are upheld.
This helps encapsulation by ensuring that no outside users can mutate
these fields.  Reducing the amount of logic that needs to be reasoned
about.
We want to hide the actual buffer implementation from most of these
locations.  Currently it is a TransmitBuf but it likely will become
something else in the future.  So make this generic.
This allows making TransmitBuf::buf private at last.  Now all the
logic it handles is fully encapsulated.
This re-arranges the loop in poll_transmit to always finish the packet
before going to the next iteration.

This primarily enables to mutably borrow the TransmitBuf into a
packet-specific buffer while the packet is being built.  But this is
not yet utilised in this commit.

It does however remove the need of the mutable builder_storage Option,
which makes reasoning over packet building slightly easier.

- The logic to know on which packet space to send next, or whether
  there is no longer anything to send, has been moved to the
  next_send_space method.

- The logic to decide whether to pad a packet before finishing it is
  moved to the end of the loop.

- The logic to check the congestion controller and pacing is kept at
  the start of the loop.  Before a new packet is started.  Starting a
  new datagram also stays there.
Now that the packet is always finished at the end of the loop we no
longer need to carry around the mutable SentFrames.  Reducing further
the number of things to keep track of.
The PacketBuilder::finish_and_track function took a SentFrames
argument as an Option.  However this was an artifact of the
poll_transmit loop tracking it in an Option before, and it not being
clear this was always Some when things were going correctly.  Now all
the callers clearly always pass this in so we can remove the Option.
@Arqu Arqu added this to iroh Apr 11, 2025
@github-project-automation github-project-automation bot moved this to 🏗 In progress in iroh Apr 11, 2025
flub added 6 commits April 11, 2025 11:48
Now the lifetimes allow for this the PacketBuilder can own the
TransmitBuf.  This is gives it more control over the buffer into which
the packet can be written.

This commit itself does nothing interesting with this yet.  It merely
moves the buffer ownership in a mechanical way.  However, this enables
future changes to reduce the use of offsets in so many places.
This moves keeping track of the available frame space to the packet
builder.  The available space is now encoded into the BufMut returned
by PacketBuilder::frame_space_mut().  This removes the need for the
BufLen trait in many of the places writing frames.
Now that the PacketBuilder::frame_space_mut exists the direct BufMut
impl on it can be removed.  Nothing external needs to directly write
into the packet buffer outside of the frame space.
It no longer needs to keep track of this field because the TransmitBuf
already does.  Removing duplicate state is nice.
You always need to remember to handle pad_datagram if needed.  While
really this always happens just before the call to finish_and_track.
Instead this can be done in finish_and_track without any logic change,
and this helps avoiding mistakes.
@flub flub force-pushed the flub/poll-transmit-ref branch from 247a07d to a0ba958 Compare April 11, 2025 09:48
@flub flub merged commit 0cb9867 into multipath-quinn-0.11.x Apr 11, 2025
13 checks passed
@github-project-automation github-project-automation bot moved this from 🏗 In progress to ✅ Done in iroh Apr 11, 2025
@flub flub deleted the flub/poll-transmit-ref branch April 11, 2025 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

1 participant