Commit Graph

585 Commits

Author SHA1 Message Date
Ian Jackson d5fce95e1e tor-proto: Make some imports more precise
A warning is getting in my way when I run
  cargo clippy -p tor-hsservice --all-features

See also
  https://gitlab.torproject.org/tpo/core/arti/-/issues/1006#note_2932088
2023-08-23 14:59:02 +01:00
Ian Jackson 42df88d6bf Run maint/add_warning to add lint block everywhere 2023-08-23 10:34:00 +01:00
Nick Mathewson 7a37641aeb Use "typos-cli" to fix a bunch of typos. 2023-08-22 16:23:51 -04:00
Nick Mathewson 6021976466 proto: fix a comment to refer to circuits, not channels. 2023-08-22 10:50:43 -04:00
Nick Mathewson f248607119 Merge branch 'send_raw_msg' into 'main'
proto: new ClientCirc::send_raw_msg function.

Closes #1010

See merge request tpo/core/arti!1525
2023-08-22 14:19:54 +00:00
Nick Mathewson b4e0595f8d proto: Add crossrefs between start_conversation and send_raw_msg 2023-08-22 09:35:48 -04:00
Nick Mathewson 80c921c637 Resolve warnings about ambiguous/redundant doc links
Nightly rustdoc now warns if you have a link that isn't necessary,
and if you have a link that might refer to two different things.
2023-08-22 09:00:33 -04:00
Nick Mathewson e4373e88e2 proto: new ClientCirc::send_raw_msg function.
Closes #1010.
2023-08-21 09:23:46 -04:00
Gabriela Moldovan a1913e15f9
tor-proto: Add test where an incoming stream comes from an unexpect hop.
This adds a test that checks if the reactor is shut down if it receives
an incoming stream request from an unexpected hop.

Part of #1009
2023-08-18 12:14:16 +01:00
Gabriela Moldovan 67a77680dd
tor-proto: Make ClientCirc::allow_stream_requests take a HopNum.
For consistency with the other `ClientCirc` APIs,
`ClientCirc::allow_stream_requests` now takes a `HopNum` argument. Upon
receiving an incoming stream request, the reactor now checks if the
request came from the hop specified in `allow_stream_requests` (and if
it came from a different hop, the circuit is closed).

Part of #1009
2023-08-18 12:14:01 +01:00
gabi-250 4c2f8d5a9e Merge branch 'handshake-tests' into 'main'
test: add a test for missing NETINFO cells

See merge request tpo/core/arti!1501
2023-08-17 10:17:01 +00:00
Nick Mathewson c8b721aa5d Merge branch 'all_crates_warnings' into 'main'
Resolve all warnings that appear from `maint/every-crate`

See merge request tpo/core/arti!1507
2023-08-16 18:20:21 +00:00
Nick Mathewson e67152abb9 tor-proto: Fix dead_code when building without experimental-api 2023-08-16 13:41:40 -04:00
Ian Jackson 62c50bfe75 Apply some churn from rustfmt (beta) 2023-08-16 18:11:22 +01:00
Ian Jackson b2c37b0570 Merge branch 'remove-unused-import' into 'main'
tor-proto: remove unused import

See merge request tpo/core/arti!1493
2023-08-16 15:12:12 +00:00
Nick Mathewson d46e638ff0 proto: Fix a type-complexity warning. 2023-08-14 13:15:40 -04:00
Nick Mathewson 65a0ac5512 proto: API to expose the `CircuitBinding` type.
Closes #993
2023-08-14 13:15:29 -04:00
Nick Mathewson 61513de6d0 proto: Take CircuitBinding one step forward into Reactor::add_hop. 2023-08-14 13:15:29 -04:00
Nick Mathewson 0ffa6eddf5 proto: Add (not-yet-exposed) code to remember and use KH values
These values are computed as part of the circuit extension
handshake, and are used as MAC keys to bind `ESTABLISH_INTRO`
messages to a particular circuit so that they can't be replayed.

Part of #993.
2023-08-14 13:15:29 -04:00
Emil Engler 60ad15b4ff
test: add a test for missing NETINFO cells
This commit adds a unit test to the `tor_proto::handshake` module,
which tests the behavior when no NETINFO cell is present within a
channel.
2023-08-12 19:09:48 +02:00
Emil Engler 81eb87ef3e
tor-proto: remove unused import
This commit removes an unused import within the test module of the
`tor_proto::circuit` module.
2023-08-10 13:36:27 +02:00
Gabriela Moldovan 6073a4f767
tor-proto: Make update_state() and discard() return Result<(), Bug>.
These functions only ever return `Bug` errors.
2023-08-09 13:07:35 +01:00
Gabriela Moldovan a0daa9adb6
tor-proto: Implement IncomingStream::discard(). 2023-08-08 15:25:45 +01:00
Gabriela Moldovan 4507c33479
tor-proto: Replace boolean flags with an IncomingStreamState enum.
This commit introduces an `IncomingStreamState` enum, which indicates
whether the stream was accepted, discarded, or rejected, or if it is
still pending. The `is_rejected`/`is_accepted` boolean flags are no
longer needed.

Without this change, we'd need to introduce yet another boolean flag
when we implement `discard()` (for the "discarded" state).
2023-08-08 15:25:42 +01:00
gabi-250 fa595875ec Merge branch 'tor-proto-incoming-todo' into 'main'
tor-proto: Replace IncomingStreamMsg with IncomingStreamRequest.

See merge request tpo/core/arti!1477
2023-08-08 13:13:31 +00:00
Gabriela Moldovan 7446ed08b6
tor-proto: Fix broken docs. 2023-08-08 13:14:39 +01:00
Gabriela Moldovan a74e4cf661
tor-proto: Make it obvious that we're discarding a Result. 2023-08-08 13:07:45 +01:00
Gabriela Moldovan 4fb5121a77
tor-proto: Make StreamTarget::close return the oneshot::Receiver instead of blocking.
Instead of having 2 version of `StreamTarget::close` (a blocking one and
a nonblocking one), we can just return the `oneshot::Receiver` for
receiving the reactor's response and let the caller of
`StreamTarget::close` decide whether to block.

This allows us to reduce some code duplication in the `IncomingStream`
implementation.
2023-08-08 13:04:01 +01:00
Gabriela Moldovan 2b2f0f6065
tor-proto: Make take_inner() use mut_inner() to check the inner value. 2023-08-08 12:47:13 +01:00
Gabriela Moldovan 41fab65de1
tor-proto: Replace IncomingStreamMsg with IncomingStreamRequest.
The two enums essentially serve the same purpose, so we don't
need both of them.

This also addresses the TODO that says we should return an error if
`accept_data` is called for a RESOLVE stream.
2023-08-07 16:45:49 +01:00
Gabriela Moldovan ffb1360908
tor-proto: Implement `Drop` for `IncomingStream`. 2023-08-07 15:57:53 +01:00
Gabriela Moldovan df8a5b017e
tor-proto: Keep track of whether the `IncomingStream` was accepted.
The behaviour of `IncomingStream::drop` is going to depend on whether
the stream was accepted or not.
2023-08-07 15:57:50 +01:00
Gabriela Moldovan d856afe449
tor-proto: Add a function for closing a stream without waiting for the reactor to respond.
This will be used for implementing `Drop` for `IncomingStream` (it
needs to "reject" the stream on drop).
2023-08-07 15:57:36 +01:00
Gabriela Moldovan e61f1e8fbe
tor-proto: Rename misleading field in `DataCmdChecker`.
This is a follow-up from !1451.

This commit solves a `TODO HSS` introduced when `DataCmdChecker` got an
additional constructor (`new_connected`) for creating "pre-connected"
streams. See f6745d31 for more details.
2023-08-07 12:38:55 +01:00
gabi-250 9171080819 Merge branch 'proto-flaky-test' into 'main'
tor-proto: allow_stream_requests now waits until the control message is received.

Closes #994

See merge request tpo/core/arti!1474
2023-08-04 20:10:46 +00:00
Gabriela Moldovan 1a7c104d2e
tor-proto: Shut down the reactor if an error occurs in incoming stream init/close.
Propagating the error means will cause the reactor to shut down (there's
not much the control message sender can do about it, so there's no point
in sending it the error).
2023-08-04 20:46:05 +01:00
Gabriela Moldovan 2eaa0fa52b
tor-proto: reject() now waits until the control message is received.
As a result, by the time the `reject` future resolves, the stream has
been removed from the reactor's stream map and the corresponding END
cell has been sent.

Fixes #998.
2023-08-04 19:57:46 +01:00
Gabriela Moldovan f689e94f0f
tor-proto: allow_stream_requests now waits until the control message is received.
`ClientCirc::allow_stream_requests` is now `async` and waits until the
`AwaitIncomingStream` control message is processed by the reactor.

This guarantees that by the time the `allow_stream_requests` future
resolves, the reactor is ready to process BEGIN/BEGIN_DIR/RESOLVE cells.

Previously, the client tasks from allow_stream_requests tests had to
sleep before sending the BEGIN cell to give the reactor time to process
the `AwaitIncomingStream` control message (which tells the reactor to
expect incoming BEGIN/BEGIN_DIR/RESOLVE cells on the circuit).

Fixes #994
2023-08-04 19:22:45 +01:00
Nick Mathewson 64fca7e45f proto: methods to wait until a channel/circuit is shut down.
The implementation here is perhaps excessively simple: we put
a `oneshot::Sender` in the `Reactor` object, and a
`Shared<oneshot::Receiver>` in the circuit or channel.  When
the reactor is dropped, any copy of the `Shared<Receiver>` will
yield `Err(Cancelled)`.

I'm marking these methods as experimental because I'm not sure I've
thought of all the implications here, and we might want to change
things around.

Down the road, these methods might want to yield a `Result<>`
indicating why the reactor was shut down.

This feature was inspired by a request from Saksham Mittal, and a
felt need while working on !1472.
2023-08-04 13:37:28 -04:00
gabi-250 36056906ad Merge branch 'future_proof_lints' into 'main'
add_warning: Change missing_docs,unreachable_pub to warn

Closes #951

See merge request tpo/core/arti!1470
2023-08-04 14:20:54 +00:00
Gabriela Moldovan ed5a051ebe
tor-proto: Add ClientCirc::start_conversation().
This will enable hidden services to send `RENDEZVOUS1` messages to the
`N`th hop of the circuit rather than the `N + 1`th virtual one (which
can only used after the client and service have completed the
introduction handshake).

This also deprecates `start_conversation_last_hop`.

Closes #959
2023-08-04 13:08:31 +01:00
Gabriela Moldovan c23e85270e
tor-proto: Add method for getting the HopNum of the last hop. 2023-08-04 13:07:52 +01:00
Nick Mathewson cec6d0ce33 Run add_warnings on all files. 2023-08-04 07:45:04 -04:00
Gabriela Moldovan eee3bb8822
tor-proto: Make HopNum public.
`HopNum` will be used in `ClientCirc`'s public API when we refactor
`ClientCirc::start_conversation_last_hop` to use the provided hop rather
than always using the last one.
2023-08-04 10:51:05 +01:00
Gabriela Moldovan 71d99ce709
tor-proto: Bump test sleep to 200ms for now.
This `sleep` is to give the reactor task a chance to process the
`AwaitIncomingStream` message. With an 100ms, this test sometimes fails
because for some reason the reactor doesn't get a chance to process the
`AwaitIncomingStream` control command before the BEGIN cell from the
client task is received. This bumps the sleep time to 200ms for now
(TODO: follow-up with an MR with a less flaky approach).

While trying to repro the issue, I found another corner case for which
I've added a TODO HSS.
2023-08-03 18:50:34 +01:00
Gabriela Moldovan 0ec1303b9a
tor-proto: Handle new BEGIN cells for rejected stream.
This updates the reactor to call the incoming stream handler even for
streams for which we have a stream map entry of `EndSent`. If we've
sent an END message for a stream but have not yet received an END
message back from the other party, but we later receive a BEGIN from
them, it is safe to assume we cam remove the stream from the stream map
and handle the new incoming stream request.
2023-08-03 16:46:28 +01:00
Gabriela Moldovan 296abfddcc
tor-proto: Clarify what we mean by "stream" in allow_stream_requests. 2023-08-03 16:44:45 +01:00
Gabriela Moldovan 23f1f2ce47
tor-proto: Add note about making hop_num optional. 2023-08-03 16:43:26 +01:00
Gabriela Moldovan 2f21dc5a87
tor-proto: Add a TODO about checking if a hop is allowed to create streams. 2023-08-03 16:42:12 +01:00
Gabriela Moldovan ffe4771a83
tor-proto: Remove unnecessary else-branch.
We return early if `message_closes_stream == true`, so we can get rid of
the `else` to remove one level of indentation.
2023-08-03 16:40:57 +01:00