pub(crate) fn channel(
cell_tx: Sender<AnyChanMsg, MpscSpec>,
cell_rx: Receiver<AnyChanMsg, MpscSpec>,
) -> (CircuitRxSender, CircuitRxReceiver)Expand description
Wrap the sender and receiver of an mq_queue channel
into CircuitRxSender and CircuitRxReceiver.
The returned channel will ensure any DESTROY messages sent
over the CircuitRxSender will be delivered
by the CircuitRxReceiver immediately,
ahead of any other messages that might already be queued,
which will be discarded.
We are fine with the resulting data loss, because inbound DESTROY
can be indicative of malicious activity on the circuit.
We choose to err on the safe side, and free up the resources associated
with such circuits as soon as possible.
DESTROY messages are also sent by relays when they’re about to hibernate,
and by clients once they’ve decided to stop using a circuit.
In the latter case, the lack of an RELAY_COMMAND_END_ACK
does mean that this prioritization can cause data loss
(if the client closes the circuit immediately after END-ing a stream).
However, this is a deficiency in the protocol,
and not something we want to fix by implementing custom flushing logic
in the reactor. See torspec#196 and the discussion in #2490.
Note: the underlying buffer of the mq_queue will only be freed
once both the CircuitRxSender and CircuitRxReceiver are dropped;
in other words, after a DESTROY cell has been obtained from the CircuitRxReceiver,
via its Stream implementation