Commit Graph

568 Commits

Author SHA1 Message Date
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
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
Gabriela Moldovan 4edff7e670
tor-proto: Update the stream map if we get an END message.
This handles the previously not handled `message_closes_stream == true`
case.
2023-08-03 16:39:42 +01:00
Gabriela Moldovan 907d8cf255
tor-proto: Add TODO regarding allow_stream_requests corner case. 2023-08-03 16:38:19 +01:00
Gabriela Moldovan f30c5897cc
tor-proto: Remove outdated comments. 2023-08-03 16:36:58 +01:00
Gabriela Moldovan 0f9bed5160
tor-proto: Add a test for allow_stream_requests. 2023-08-03 16:35:43 +01:00
Gabriela Moldovan 37154dca95
tor-proto: Implement allow_stream_requests. 2023-08-03 16:34:09 +01:00
Gabriela Moldovan ffa8056437
tor-proto: Handle RELAY_BEGIN cells if we have an incoming req handler. 2023-08-03 16:33:58 +01:00
Gabriela Moldovan f06e0e2df0
tor-proto: Implement IncomingStream::{accept_data, request, reject}. 2023-08-03 16:32:29 +01:00
Gabriela Moldovan 445c052420
tor-proto: Add StreamTarget function for sending CtrlMsg::CloseStream .
This will be used by `IncomingStream` to implement `reject()`.
2023-08-03 16:31:05 +01:00
Gabriela Moldovan b9daaa245c
tor-proto: Add reactor control commands for accepting/closing incoming streams.
This adds a new `AwaitIncomingStream` control message for registering an
interest in an incoming stream.

This also adds a `ClosePendingStream` control message for explicitly
closing a stream with a given END message (needed for implementing
`IncomingStream::reject`).
2023-08-03 16:29:26 +01:00
Gabriela Moldovan 950d0da0b5
tor-proto: Add types for sharing stream request info with the reactor. 2023-08-03 16:27:48 +01:00
Gabriela Moldovan 18b01f94cc
tor-proto: Add a helper for adding a stream entry with a specific stream ID.
This adds a new `add_ent_with_id` function for adding a new entry to the
`StreamMap`. The existing `add_ent` function auto-generates a new stream
ID, which is not good if we're a hidden service, as stream IDs are
supposed to be chosen by the OP (client). When accepting a new stream,
services, exit relays, and dir auths need to use the stream ID received
in the BEGIN cell (instead of generating a new stream ID).
2023-08-03 16:25:46 +01:00
Gabriela Moldovan 4abfe30f41
tor-proto: Remove extraneous space. 2023-08-03 16:24:30 +01:00
Gabriela Moldovan f6745d31a9
tor-proto: Add constructors for pre-connected DataStreams.
When accepting a new stream, hidden services, exit relays and dirauths
don't wait for a `CONNECTED` cell from the initiator.

This commit adds constructors for building `DataStream`s and
`DataCmdChecker`s that can immediately receive data cells (and don't
expect to receive `CONNECTED` cells at all).
2023-08-03 16:23:11 +01:00
Gabriela Moldovan 4133a9464e
tor-proto: Add a constructor for IncomingStream. 2023-08-03 16:21:55 +01:00
Gabriela Moldovan dc0b904492
tor-proto: Add imports for commonly used types. 2023-08-03 16:20:45 +01:00
Gabriela Moldovan 3d5c712c55
tor-proto: Add IncomingCmdChecker for IncomingStream. 2023-08-03 16:18:35 +01:00
Nick Mathewson 1e96d1b95a Remove semver.md files now that 1.1.7 is out. 2023-08-01 12:55:52 -04:00