feat: add Connection::set_send_window()
#2268
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We have a desire to limit the amount of bandwidth used for a given peer in both directions, but by the nature of the application, we can't decide that limit is until we're already connected to the peer and have verified their identity.
We already make use of backpressure throughout the application, so we can use the connection itself to limit the bandwidth used without everything backing up elsewhere.
I think we can most easily affect this by setting the
receive_window
to our desired bandwidth times the RTT, but that only gives us control over inbound bandwidth; we don't currently have a way to set thesend_window
after the connection is established.Looking through the implementation, the handling of
send_window
doesn't look to be nearly as complex asread_window
since it's a purely local control knob, so I feel like letting the user set it dynamically shouldn't cause any issues.I do have a question about how best to test this. I see there's tests for
set_receive_window
that I can copy, but I've only got an inkling of how thesend_window
tests should work:stream::State
with a setsend_window
send_window
bytessend_window
and see ifState::poll()
generates aWritable
event?How would I test the shrinkage of
send_window
? Write N bytes, ack them, setsend_window < N
and try to write the same amount again?