Skip to main content

tor_proto/
conflux.rs

1//! Conflux-related functionality
2
3pub(crate) mod msghandler;
4
5use tor_cell::relaycell::RelayCmd;
6
7/// Whether the specified `cmd` counts towards the conflux sequence numbers.
8pub(crate) fn cmd_counts_towards_seqno(cmd: RelayCmd) -> bool {
9    // Note: copy-pasted from c-tor
10    match cmd {
11        // These are all fine to multiplex, and must be so that ordering is preserved
12        RelayCmd::BEGIN | RelayCmd::DATA | RelayCmd::END | RelayCmd::CONNECTED => true,
13
14        // We can't multiplex these because they are circuit-specific
15        RelayCmd::SENDME
16        | RelayCmd::EXTEND
17        | RelayCmd::EXTENDED
18        | RelayCmd::TRUNCATE
19        | RelayCmd::TRUNCATED
20        | RelayCmd::DROP => false,
21
22        //  We must multiplex RESOLVEs because their ordering impacts begin/end.
23        RelayCmd::RESOLVE | RelayCmd::RESOLVED => true,
24
25        // These are all circuit-specific
26        RelayCmd::BEGIN_DIR
27        | RelayCmd::EXTEND2
28        | RelayCmd::EXTENDED2
29        | RelayCmd::ESTABLISH_INTRO
30        | RelayCmd::ESTABLISH_RENDEZVOUS
31        | RelayCmd::INTRODUCE1
32        | RelayCmd::INTRODUCE2
33        | RelayCmd::RENDEZVOUS1
34        | RelayCmd::RENDEZVOUS2
35        | RelayCmd::INTRO_ESTABLISHED
36        | RelayCmd::RENDEZVOUS_ESTABLISHED
37        | RelayCmd::INTRODUCE_ACK
38        | RelayCmd::PADDING_NEGOTIATE
39        | RelayCmd::PADDING_NEGOTIATED => false,
40
41        // Flow control cells must be ordered (see prop 329).
42        RelayCmd::XOFF | RelayCmd::XON => true,
43
44        // These two are not multiplexed, because they must be processed immediately
45        // to update sequence numbers before any other cells are processed on the circuit
46        RelayCmd::CONFLUX_SWITCH
47        | RelayCmd::CONFLUX_LINK
48        | RelayCmd::CONFLUX_LINKED
49        | RelayCmd::CONFLUX_LINKED_ACK => false,
50
51        _ => {
52            tracing::warn!("Conflux asked to multiplex unknown relay command {cmd}");
53            false
54        }
55    }
56}