summaryrefslogtreecommitdiff
path: root/crates/tor-proto/src/circuit.rs
Commit message (Collapse)AuthorAgeFilesLines
* proto: Add a test helper function for building a CircNetParametersDavid Goulet2026-04-141-0/+17
| | | | | | | | | We can't access `NetParameters` in this crate to build from consensus default value so instead add a `defaults_for_tests()` gated function for each parameters object which puts in the defaults from the spec. We'll need CircNetParameters in order to build create request handler for unit tests hence why it is in src/circuit.rs.
* proto: Rename CircSyncView to CircHopSyncViewGabriela Moldovan2026-02-161-1/+1
| | | | And update the docs
* proto: Move CREATE helpers to a shared moduleGabriela Moldovan2026-02-051-0/+1
| | | | These will be used by the relay code too (for circuit extension).
* proto: Avoid locking in CircHopOutbound::ccontrol()Gabriela Moldovan2026-01-291-1/+1
| | | | | | | | This is just because the generic reactor will soon need a clone of the CC object, so I am preemptively making this function return a ref to the underlying `Arc` instead. Technically, it would've been fine to just kept this method and add a separate one returning `&Arc<Mutex<..>>`, but I'd prefer keeping the API small.
* proto: Add a new module for the generic circuit reactorGabriela Moldovan2026-01-291-0/+1
| | | | Currently empty, will be fleshed out in a future commit.
* proto; Factor HOPS constant out of maybenot_paddingGabriela Moldovan2026-01-291-0/+3
| | | | I am about to use this in other places too.
* proto: Move CircPaddingDisposition to a new moduleGabriela Moldovan2026-01-291-0/+1
| | | | Relays will need to use it too.
* proto: #[macro_use] be gone!Gabriela Moldovan2025-12-101-1/+0
|
* proto: Client circuit reactor now handles AnyChanMsgDavid Goulet2025-12-101-0/+12
| | | | | | | | | | | | | | | This commit removes the CircuitRx* based solely on the client circuit message and moves it into the top level of the crate so all reactors can use them. The client reactor then upon receiving the message, it converts the AnyChanMsg into a ClientCircChanMsg. On error, this leads to a shutdown of the entire reactor due to a fatal error. In order to pull this off, we added a CircuitAction::Shutdown that is handled as a priority. Signed-off-by: David Goulet <[email protected]>
* proto: Move ClientCircChanMsg into client moduleDavid Goulet2025-12-101-0/+1
| | | | | | | | Next commit will also move the Relay specific set into the relay module. These two sets are becoming specific to the reactor as the circuit reactor communication channel will use AnyChanMsg instead. Signed-off-by: David Goulet <[email protected]>
* Merge branch 'cell-sender' into 'main'Alexander Hansen Færøy2025-11-101-0/+1
|\ | | | | | | | | proto: Move cell_sender out of the client module See merge request tpo/core/arti!3407
| * proto: Move cell_sender out of the client moduleGabriela Moldovan2025-10-281-0/+1
| | | | | | | | | | | | | | Soon we'll use CircuitCellSender in the relay reactor too (we need to, because it provides a useful abstraction for handling block/unblock padding actions, and because it has some handy helper functions such as `congestion_signals()`).
* | proto: Add a new CircSyncView typeGabriela Moldovan2025-10-301-0/+2
|/ | | | | | This will replace ClientCircView in the IncomingStreamRequestFilter APIs, which will enable us to use IncomingStreamRequestFilter for incoming streams on the exit side too.
* proto: Fix doc links post-refactoringGabriela Moldovan2025-10-211-2/+2
|
* proto: Move hop settings into a shared moduleGabriela Moldovan2025-10-211-0/+72
|
* proto: Move celltypes out of clientGabriela Moldovan2025-10-131-0/+1
| | | | | Some of these are relay-specific, so it makes more sense to pull this into a top-level module.
* proto: Add a circuit module shared between client and relay impls.Gabriela Moldovan2025-08-281-0/+8
| | | | | | | This is just code motion (I suggest reviewing with `--color-moved`). This also moves the implementation-agnostic parts from `tor_proto::client::circuit` to a new `tor_proto::circuit` module.
* tor-proto: Add a tunnel module.David Goulet2025-02-201-2563/+0
| | | | | | | | | | | | | Move StreamTarget to the tunnel module and the circuit module. From now on streams will be implemented on tunnels, not circuits. This moves `StreamTarget` to the tunnel module. A future change will replace `ClientCirc` with `ClientTunnel` inside `StreamTarget`. This is mostly code motion, best reviewed with `--color-moved`. Signed-off-by: David Goulet <[email protected]>
* tor-proto: Change the visibility of a series of structGabriela Moldovan2025-02-201-7/+7
| | | | | | | We're about to need this in `tor_proto::tunnel` which is from the Conflux work. In the spirit of upstreaming as much as possible, it is done now.
* tor-proto: Move CreateHandshakeWrap to reactor module.Gabriela Moldovan2025-02-181-56/+1
| | | | | This moves the `CreateHandshakeWrap` and its implementors to `reactor::create` (none of these are used outside of the reactor).
* tor-proto: remove `ClientCirc::channel`Steven Engler2025-02-101-26/+2
|
* tor-proto: add `ClientCirc::first_hop_clock_skew`Steven Engler2025-02-101-0/+14
|
* conflux: Split off `time_provider` from `channel` in `ClientCirc`Neel Chauhan2025-02-101-2/+7
|
* tor-proto: Turn some CtrlMsgs into CtrlCmds.Gabriela Moldovan2025-02-061-10/+10
| | | | | | | All `CtrlMsg`s to which the reactor did not respond by sending a cell down the channel are now `CtrlCmd`s. Most of this is code motion, best reviewed with `--color-moved`.
* tor-proto: Make shutdown a CtrlCmd.Gabriela Moldovan2025-02-061-5/+6
|
* proto: Remove ConversationInHandlerDavid Goulet2025-02-041-41/+1
| | | | | | | | | | | | | | | | | | | It is unused but most importantly it allows any RELAY cell to be sent from anywhere in the code which is really not desirable because it is skipping congestion control. It also allows us to remove the `control_tx` from the reactor which is one less channel to track/understand/think about. This opens up the door to all sorts of problems especially side channel that can be exploited if we are not careful. We can always bring this back if we need it but for now, it is unused and allows us to remove the `CtrlMsg::SendRelayCell` control message. No code behavior change. Signed-off-by: David Goulet <[email protected]>
* tor-proto: Ensure rx end of chan reactor output sink is not dropped in test.Gabriela Moldovan2025-02-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This hopefully fixes #1832. I haven't been able to repro the failure from #1832 locally, but judging from the logs, I suspect it's triggered by interleavings like: - `extend_fut` executes up until `circ.extend_ntor(..).await`, where it's blocked `await`ing a completion notification from the circuit reactor - `reply_fut` starts running: * `CircuitExtender` installs a meta-handler in the circuit reactor, and waits for an `EXTENDED2` cell * `test_extend()` reads a cell from the receiving end of the fake channel's output sink (`rx`) * `test_extend()` sends the `EXTENDED2` cell to the circuit reactor over `CircuitRxSender` * `rx` is dropped - `reply_fut` completes - in the channel reactor's `run_once()`, `select_biased!` resolves to an error, because the receiving end of the `output` sink (`rx`) was dropped. The reactor logs `got sink error: SendError { kind: Disconnected }` (see [`SendError`]), and exits - the circuit reactor exits too, because the receiving end of its `chan_sender` (which was in the channel reactor) was dropped Returning the `rx` of the fake channel's output sink from `reply_fut` *should* stop it from being dropped, and fix #1832. [`SendError`]: https://docs.rs/futures/latest/futures/channel/mpsc/struct.SendError.html#method.is_disconnected
* tor-proto: Rewrite circuit reactor run_once() loop to use select!.Gabriela Moldovan2025-01-291-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This 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 `RunOnceCmdInner` commands to `run_once()` via a channel (instead of returning them). This would enable the reactor to stop reading the commands (except for handle `Sendme`, which would be handled separately) if it's blocked on congestion control.
* tor-proto: Use SendRelayCell within CtrlMsg::SendRelayCell.Gabriela Moldovan2025-01-291-2/+3
|
* tor-proto: Derive Default for MutableState.Gabriela Moldovan2025-01-281-1/+1
| | | | | This enables us to get rid of two lines from the circuit reactor constructor.
* tor-proto: Replace sleep() in test with advance_until_stalled().Gabriela Moldovan2025-01-161-15/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This test spuriously failed on my !2720 branch (https://gitlab.torproject.org/gabi-250/arti/-/jobs/811495): ``` failures: ---- circuit::test::invalid_circ_sendme stdout ---- E tor_proto::channel::reactor: UniqId(71): Running reactor E tor_proto::circuit::reactor: Circ 23.17: Running circuit reactor E tor_proto::circuit::reactor: Circ 23.17: reactor received AddFakeHop { relay_cell_format: V0, fwd_lasthop: false, rev_lasthop: false, params: CircParameters { extend_by_ed25519_id: true, ccontrol: CongestionControlParams { alg: FixedWindow(FixedWindowParams { circ_window_start: 1000, circ_window_min: 100, circ_window_max: 1000 }), cwnd_params: CongestionWindowParams { cwnd_init: 124, cwnd_inc_pct_ss: Percentage { value: 100 }, cwnd_inc: 1, cwnd_inc_rate: 31, cwnd_min: 124, cwnd_max: 4294967295, sendme_inc: 31 }, rtt_params: RoundTripEstimatorParams { ewma_cwnd_pct: Percentage { value: 50 }, ewma_max: 10, ewma_ss_max: 2, rtt_reset_pct: Percentage { value: 100 } } } }, done: Sender { complete: false } } E tor_proto::circuit::reactor: Circ 23.17: reactor received AddFakeHop { relay_cell_format: V0, fwd_lasthop: true, rev_lasthop: true, params: CircParameters { extend_by_ed25519_id: true, ccontrol: CongestionControlParams { alg: FixedWindow(FixedWindowParams { circ_window_start: 1000, circ_window_min: 100, circ_window_max: 1000 }), cwnd_params: CongestionWindowParams { cwnd_init: 124, cwnd_inc_pct_ss: Percentage { value: 100 }, cwnd_inc: 1, cwnd_inc_rate: 31, cwnd_min: 124, cwnd_max: 4294967295, sendme_inc: 31 }, rtt_params: RoundTripEstimatorParams { ewma_cwnd_pct: Percentage { value: 50 }, ewma_max: 10, ewma_ss_max: 2, rtt_reset_pct: Percentage { value: 100 } } } }, done: Sender { complete: false } } E tor_proto::circuit::reactor: Circ 23.17: reactor received BeginStream { hop_num: HopNum(2), message: Begin(Begin { addr: [119, 119, 119, 46, 101, 120, 97, 109, 112, 108, 101, 46, 99, 111, 109], port: 443, flags: BeginFlags(IPV6_OKAY) }), sender: Sender { tx: Sender { closed: false }, mq: TypedParticipation(Participation(Noop)) }, rx: Receiver { inner: ReceiverInner { state: Mutex { data: Ok(ReceiverState { rx: StreamUnobtrusivePeeker { buffered: None, poll_waker: None, inner: Some(Receiver { closed: false }) }, mq: TypedParticipation(Participation(Noop)), collapse_callbacks: 0 }), poisoned: false, .. } } }, done: Sender { complete: false }, cmd_checker: DataCmdChecker { expecting_connected: true } } Using RNG seed ARTI_TEST_PRNG=62d085c0fb1213c4f41d1a0a5c3f92dd10223a27c42bfda3caedfe60e011e95d E tor_proto::circuit::reactor: Circ 23.17: handling cell: Relay(Relay { body: .. }) Using RNG seed ARTI_TEST_PRNG=fd2f2f045a7340f1189972b13645346943efa2c42f43afd2161420c692bb4ff0 E tor_proto::circuit::reactor: Circ 23.17: handling cell: Relay(Relay { body: .. }) E tor_proto::circuit::reactor: Circ 23.17: Circuit reactor stopped: Err(CircProto("Mismatched tag on circuit SENDME")) E tor_proto::channel::reactor: UniqId(71): reactor received CloseCircuit(CircId(128)) E tor_proto::channel::reactor: UniqId(71): Circuit 128 is gone; sending DESTROY thread 'circuit::test::invalid_circ_sendme' panicked at crates/tor-proto/src/circuit.rs:2262:21: reactor continued running after invalid sendme failures: circuit::test::invalid_circ_sendme test result: FAILED. 142 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out; finished in 4.93s ``` This is probably because of the `sleep()`-based check. This branch changes the test to use `MockRuntime`, replacing the `sleep()` with `advance_until_stalled()`.
* congestion: Remove FixedWindow start window default valueDavid Goulet2025-01-161-1/+1
| | | | | | | | In unit tests, we set a 1000 by default but else, we don't set a default so our implementation doesn't forget to set the right value from the consensus. Signed-off-by: David Goulet <[email protected]>
* test: Fix circuit unit testsDavid Goulet2025-01-161-0/+1
| | | | Signed-off-by: David Goulet <[email protected]>
* proto: Remove unused circuit/sendme.rsDavid Goulet2025-01-161-1/+0
| | | | Signed-off-by: David Goulet <[email protected]>
* proto: Use congestion control in circuit reactorDavid Goulet2025-01-161-1/+1
| | | | | | | | | | It is official, congestion control is now used at this commit by the circuit reactor making circuit/sendme.rs unused. Will be removed with another commit. Related #534 Signed-off-by: David Goulet <[email protected]>
* circmgr: Modify CircParameters for congestion controlDavid Goulet2025-01-161-50/+21
| | | | | | | | | | | | | | The congestion control parameters are created from the consensus parameters (netparams) and then put into the CircParameters object that is then passed down the tor-proto crate. Because different parameters are selected depending on the circuit type (onion vs exit vs sbws), a CircuitType enum is introduced for the sole purpose of being used to select the right parameters. Related #534 Signed-off-by: David Goulet <[email protected]>
* tor-proto: Add traced_test to test casesIan Jackson2025-01-151-0/+21
| | | | (We don't add it to the handful of unit tests that don't use an executor.)
* Resolve clippy::empty_line_after_doc_comments warnings.Nick Mathewson2024-12-031-1/+1
| | | | These are new in Rust 1.83.
* Merge branch 'mq-fix' into 'main'Ian Jackson2024-10-221-14/+24
|\ | | | | | | | | memquota: Fix account lifetime bugs, and arrange to test mq in shadow See merge request tpo/core/arti!2560
| * memquota: Fix resolve stream account lifetimeIan Jackson2024-10-211-6/+5
| | | | | | | | | | | | | | | | | | We need the mq account for the stream not to collapse. The ResolveStream object needs to contain a strong reference to it. Have begin_stream_impl return the StreamAccount, rather than taking it as a parameter. That makes this bug a little more obvious. It also centralises the StreamAccount creation.
| * memquota: Fix circuit account lifetime (fmt)Ian Jackson2024-10-211-4/+16
| |
| * memquota: Fix circuit account lifetime (clippy churn)Ian Jackson2024-10-211-4/+4
| | | | | | | | | | | | Now that it doesn't call CircuitAccount::new() it has no error paths, and clippy demands we remove the Result, so it must once again become infallible.
| * memquota: Fix circuit account lifetimeIan Jackson2024-10-211-4/+3
| | | | | | | | | | | | | | | | We foolishly made *two* CircuitAccounts, one of which gets immediately dropped. But we need to hold onto the account somewhere, because an mq_queue doesn't keep the account alive. Otherwise everything breaks when mq tracking is enabled.
* | tor-proto: Reinstate circuit hop check in test_create()Neel Chauhan2024-10-161-4/+1
|/
* Replace _ => panic!() in tor-protoIan Jackson2024-10-151-14/+14
|
* Merge branch 'mq-circ' into 'main'David Goulet2024-10-101-9/+11
|\ | | | | | | | | | | | | Use memquota queue for channel->circuit RX data Closes #1682 See merge request tpo/core/arti!2518
| * Apply deferred rustfmt churnIan Jackson2024-10-091-4/+1
| |
| * memquota: Use an mq_queue for channel->circuit RX queueIan Jackson2024-10-091-4/+4
| | | | | | | | | | | | Fixes #1682. (This involves some noise in the tests.)
| * memquota: Introduce type aliases for channel->circuit RX queueIan Jackson2024-10-091-4/+9
| | | | | | | | | | This is neater and will make changing the type (in a moment) less noisy.
* | tor-proto: Fix flaky circuit::test::accept_valid_sendme test.Wesley Aptekar-Cassels2024-10-071-4/+3
|/ | | | Fixes: #628