tor-proto: Rewrite circuit reactor run_once() loop to use select!.
This branch contains multiple types of changes:
- code motion that makes the reactor impl a bit more readable
- API changes needed for the main
run_once()refactoring - new types for implementing the
run_once()changes - the main part of the branch is the
Reactorimpl refactoring in 2eb09f4f - post-refactoring cleanups
The main changes start at 2eb09f4f, which rewrites the circuit reactor main loop to use select_biased! to poll
multiple futures simultaneously.
The new run_once(), like the old, first waits for an initial
CtrlMsg::Create. Then, it uses a select_biased! to poll the
chan_sender sink and shutdown channel for readiness.
When the channel sink is ready, we poll the control and input
channels like before, as well as the new ready_streams Stream
(ready_streams is a futures::Stream that replaces the previous
send_outbound() function).
Most of the implementation remains unchanged, except the handle_input,
handle_cell and handle_control functions no longer send anything on
the chan_sender channel. Instead, they may do some (synchronous)
processing, and send instructions for the remaining work that needs to
be done (for example, for writing the cell to the chan_sender
channel). These instructions are handled at the end of run_once(),
and are encoded in the RunOnceCmdInner enum.
What this change does not do:
- the control channel still bypasses congestion control. We could
fix this by making the various reactor functions send the
RunOnceCmdInnercommands torun_once()via a channel (instead of returning them). This would enable the reactor to stop reading the commands (except for handleSendme, which would be handled separately) if it's blocked on congestion control.