Commit Graph

300 Commits

Author SHA1 Message Date
Ian Jackson 89074a1326 Replace manual Default and new with std derive in tor-proto 2022-03-02 18:01:08 +00:00
Nick Mathewson 83c8b11c2c Merge branch 'clippy-allow-arc-clone' into 'main'
Disable clippy::clone_on_ref_ptr

See merge request tpo/core/arti!352
2022-03-01 20:38:05 +00:00
Nick Mathewson e8e9791a97 Bump all crates to 0.1.0 2022-03-01 08:59:34 -05:00
trinity-1686a 55a1433499 remove usage of dbg!(..)
it's making rust-nightly job fail
2022-02-28 18:20:34 +01:00
eta 1276f71e9a Merge branch 'always-coarsetime' into 'main'
Make coarsetime dependency and traffic-timestamping non-optional.

See merge request tpo/core/arti!358
2022-02-28 13:39:10 +00:00
Nick Mathewson 6755648f6b Merge branch 'upgrade-dependencies' into 'main'
Upgrade a few dependencies to newer versions

See merge request tpo/core/arti!357
2022-02-25 16:30:00 +00:00
Nick Mathewson 4becaa01b9 Bump minimum tokio to 1.7, since tokio-util now needs that. 2022-02-25 11:09:24 -05:00
Nick Mathewson 3d7d609922 Make coarsetime dependency and traffic-timestamping non-optional.
Previously coarsetime and the traffic-timestamp feature were
enabled, since they were only required for a small corner of the
guardmgr algorithm.

But in 1.0 and beyond we'll be adding a bunch of other features (eg,
netflow padding, DoS prevention) that will need coarsetime all over
the place.

And since we're going to be doing coarsetime all over the place, the
previous justification for making traffic-timestamping optional (the
tiny performance hit) is no longer relevant.
2022-02-25 10:31:01 -05:00
Nick Mathewson 55416937cc Upgrade dependency to new version of tokio-util. 2022-02-25 08:48:00 -05:00
Ian Jackson 3903900461 tor-proto datastream: Fix typo in Debug impl
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/353#note_2781632
2022-02-25 12:23:49 +00:00
eta 3e37d7e105 Merge branch 'debug-datastream' into 'main'
tor-proto datastream: Do not dump packet data in DataWriterImpl

See merge request tpo/core/arti!353
2022-02-24 21:30:52 +00:00
Ian Jackson 78ab634ed9 Fix rustfmt 2022-02-24 19:45:58 +00:00
Nick Mathewson 7f3ea03e58 Merge branch 'proto_handshake_err' into 'main'
tor-proto: Split up a couple of handshake-based errors

Closes #359 and #358

See merge request tpo/core/arti!344
2022-02-24 19:44:34 +00:00
Ian Jackson f3520478b1 tor-proto datastream: Do not dump packet data in DataWriterImpl 2022-02-24 19:39:18 +00:00
Ian Jackson 097c852e58 tor-proto datastream: import std::fmt::Debug trait name 2022-02-24 19:39:18 +00:00
eta 3e4358c5d3 Merge branch 'remote_stream_err' into 'main'
Give specific error kinds to different END reasons

Closes #360

See merge request tpo/core/arti!343
2022-02-24 19:31:41 +00:00
eta b5cd85b401 Merge branch 'debug-datastream' into 'main'
impl Debug for DataStream (and its components)

See merge request tpo/core/arti!351
2022-02-24 18:36:19 +00:00
Nick Mathewson d8120e1649 proto: Refactor conversion from CodecError to Error
Remove default conversion; instead use a specific conversion in each
of the two modules that need to do it.
2022-02-24 13:23:42 -05:00
Ian Jackson afb50fe735 Disable clippy::clone_on_ref_ptr
This lint is IMO inherently ill-conceived.

I have looked for the reasons why this might be thought to be a good
idea and there were basically two (and they are sort of contradictory):

I. "Calling ‘.clone()` on an Rc, Arc, or Weak can obscure the fact
    that only the pointer is being cloned, not the underlying data."

This is the wording from
  https://rust-lang.github.io/rust-clippy/v0.0.212/#clone_on_ref_ptr

It is a bit terse; we are left to infer why it is a bad idea to
obscure this fact.  It seems to me that if it is bad to obscure some
fact, that must be because the fact is a hazard.  But why would it be
a hazard to not copy the underlying data ?

In other languages, faliing to copy the underlying data is a serious
correctness hazard.  There is a whose class of bugs where things were
not copied, and then mutated and/or reused in multiple places in ways
that were not what the programmer intended.  In my experience, this is
a very common bug when writing Python and Javascript.  I'm told it's
common in golang too.

But in Rust this bug is much much harder to write.  The data inside an
Arc is immutable.  To have this bug you'd have use interior mutability
- ie mess around with Mutex or RefCell.  That provides a good barrier
to these kind of accidents.

II. "The reason for writing Rc::clone and Arc::clone [is] to make it
     clear that only the pointer is being cloned, as opposed to the
     underlying data. The former is always fast, while the latter can
     be very expensive depending on what is being cloned."

This is the reasoning found here
  https://github.com/rust-lang/rust-clippy/issues/2048

This is saying that *not* using Arc::clone is hazardous.
Specifically, that a deep clone is a performance hazard.

But for this argument, the lint is precisely backwards.  It's linting
the "good" case and asking for it to be written in a more explicit
way; while the supposedly bad case can be written conveniently.

Also, many objects (in our codebase, and in all the libraries we use)
that are Clone are in fact simply handles.  They contain Arc(s) (or
similar) and are cheap to clone.  Indeed, that is the usual case.

It does not make sense to distinguish in the syntax we use to clone
such a handle, whether the handle is a transparent Arc, or an opaque
struct containing one or more other handles.

Forcing Arc::clone to be written as such makes for code churn when a
type is changed from Arc<Something> to Something: Clone, or vice
versa.
2022-02-24 18:15:44 +00:00
Ian Jackson b56115a04f impl Debug for DataStream (and its components)
My proximate motivation is that tls-api wants its inner streams to be
Debug.  But in general, I agree with the Rust API Guidelines notion
that almost everything should be Debug.

I have gone for the "dump all the things" approach.  A more nuanced
approach would be possible too.
2022-02-24 17:49:34 +00:00
Nick Mathewson 74a5ce8635 tor-proto: refactor handshake protocol errors to a different type
This helps the user distinguish between protocol violations that
happen when connecting to the tor network from those that happen
while connected.

Closes #358.
2022-02-23 10:39:08 -05:00
Nick Mathewson d42b932ed9 tor-proto: Rename BadHandshake to BadCircHandshake
(We'll have a BadChanHandshake soon.)
2022-02-23 10:39:08 -05:00
Nick Mathewson afa49eac8f tor-proto: Split IoErr based on when it occurs
We want to distinguish handshake failures from errors later on in
the channel's lifetime.

Closes #359.
2022-02-23 10:38:48 -05:00
Nick Mathewson 6c615898e4 Give specific error kinds to different END reasons
Closes #360.
2022-02-23 09:35:28 -05:00
Nick Mathewson 92141c6d72 Merge remote-tracking branch 'origin/mr/340' 2022-02-23 09:29:40 -05:00
Nick Mathewson a2e2663e90 Eliminate RequestedResourceAbsent kind.
There was only one use of this, and it was in as-yet-unused relay-only
code.

Removing this type required refactoring the relay onion handshake code
to use its own error type, which is probably clever anyway.
2022-02-22 16:00:25 -05:00
Nick Mathewson 789e6c87b8 Fold NamespaceFull into BadApiUsage. 2022-02-22 15:44:49 -05:00
Nick Mathewson 4cedc1a190 Rename RemoteNameError to RemoteHostNotFound
This is a bit ugly but we need it to work around the problem where
exits aren't always clear about _why_ a hostname lookup failed.
2022-02-22 15:43:27 -05:00
Nick Mathewson 0d079071fe Replace RemoteRefused with CircuitRefused.
Also document that it's a lower-level error kind.
2022-02-22 15:34:46 -05:00
Nick Mathewson f018d0c74b Rename RemoteIdMismatch to RelayIdMismatch. 2022-02-22 15:32:08 -05:00
Nick Mathewson 5351aaa308 Fold AlreadyClosed into BadApiUsage 2022-02-22 15:25:24 -05:00
Nick Mathewson dd55f5ce2d Remove clippy::needless_borrow exception in CI.
This exception is no longer necessary now that the underlying CI bug
is fixed.
2022-02-20 09:09:38 -05:00
Yuan Lyu 7ab840785e Replace as_mut with deref impl for MutCircEnt 2022-02-16 17:23:16 -05:00
Yuan Lyu cc7023fb75 Make CircMap open_ent_count O(1) 2022-02-16 16:48:49 -05:00
Nick Mathewson 62a62b6dfd tor_proto::Error: Fix an incomplete sentence. 2022-02-16 11:09:59 -05:00
Nick Mathewson 6b611d6dea Update tor-proto errors to latest API. 2022-02-15 09:57:03 -05:00
Nick Mathewson 4af279b173 Make tor-proto::Error implement HasKind.
This took some refactoring, and gave an opportunity to notice
a few error variants that weren't being used, or didn't mean
what they said on the tin.
2022-02-15 09:41:47 -05:00
Nick Mathewson f23f375e42 tor-proto: use InternalError for internal errors. 2022-02-15 09:41:11 -05:00
Nick Mathewson da0e9e456c tor-cell: provide HasKind.
Additionally, refactor the IoError out of tor_cell::Error:
nothing in TorCell created this; it was only used by tor_proto.

This required refactoring in tor_proto to use a new error type. Here I
decided to use a new CodecError for now, though we may refactor that
away soon too.
2022-02-15 09:41:10 -05:00
eta 29daf5a74a Merge branch 'warn_not_deny' into 'main'
Change deny(clippy::all) to warn(clippy::all).

Closes #338

See merge request tpo/core/arti!306
2022-02-14 19:45:18 +00:00
Nick Mathewson 1cecc7e45a Change deny(clippy::all) to warn(clippy::all).
Closes #338.
2022-02-14 09:24:06 -05:00
Nick Mathewson dc9f1afeb3 Use atomic set-and-check to update OptTimestamps if none.
This fixes a tiny race condition in the previous code, where we
checked whether an OptTimestamp is None a bit before we set it.
Since std::atomic gives us compare_exchange, we might as well use
it.
2022-02-09 10:24:31 -05:00
Yuan Lyu 595fe1ab88 Remove the use of Mutex in channel unused_since timestamp 2022-02-08 18:28:45 -05:00
Yuan Lyu f6f732a478 Expire channels that have been unused for too long 2022-02-04 22:52:51 -05:00
eta e9087e1fed Merge branch 'eta/reactor-2.5' into 'main'
Fix severe reactor ordering problems

See merge request tpo/core/arti!282
2022-02-03 16:27:57 +00:00
Nick Mathewson 03755a5c7b Merge branch 'dirclient-testing' into 'main'
dir-client: bug fix and more tests

See merge request tpo/core/arti!271
2022-02-03 15:09:06 +00:00
eta 24d12163f2 Fix severe reactor ordering problems
A number of severe problems with the circuit reactor were fixed which
could cause reordering of cells (which causes relays to terminate the
circuit with a protocol violation, as they become unable to decrypt
them). These mostly revolve around improper usage of queues:

- The code assumed that a failure to place cells onto the channel would
  persist for the duration of a reactor cycle run. However, under high
  contention, this wouldn't always be the case.
  - This leads to some cells getting enqueued while others go straight
    through, before the enqueued cells.
  - To fix this, we block sending cells out of the channel while there
    are still some enqueued.
- The hop-specific queues queued after encryption, not before. This was
  very brittle, and led to frequent mis-ordering.
  - This was fixed by making them not do that.

This is arti!264 / 5bce9db562 without the
refactor part.
2022-02-03 15:04:28 +00:00
eta cc37c8f5b5 Merge branch 'typos' into 'main'
Fix typos

See merge request tpo/core/arti!285
2022-02-03 13:12:38 +00:00
Ian Jackson 7be3bf6339 Temporarily disable some clippy lints on nightly 2022-02-02 21:57:30 +00:00
Ian Jackson b7fec1c8a4 Remove many needless borrows and slices
Found via clippy::needless_borrow.  In some cases I removed needless
`[..]` too.  See also:
  needless_borrow suggestion doesn't go far enough
  https://github.com/rust-lang/rust-clippy/issues/8389
2022-02-02 18:34:26 +00:00
Dimitris Apostolou 6526321851
Fix typos 2022-02-02 20:18:22 +02:00
Nick Mathewson c8dd73d55f Upgrade required version of futures crate to 0.3.14
Earlier versions have a bug in UnboundedReceiver that make our new
dirclient tests fail.
2022-02-01 09:54:47 -05:00
Nick Mathewson 01d9937308 Bump the patch version of every crate that changed since 0.0.3 2022-01-31 10:30:52 -05:00
Nick Mathewson 5187b05c19 Use script to update README.md files. 2022-01-28 08:36:34 -05:00
Nick Mathewson 30b3818a9e Make the native-tls crate optional.
This commit puts the native-tls crate behind a feature.  The feature
is off-by-default in the tor-rtcompat crate, but can be enabled
either from arti or arti-client.

There is an included script that I used to test that tor-rtcompat
could build and run its tests with all subsets of its features.

Closes #300
2022-01-26 14:06:58 -05:00
Nick Mathewson 884d614a61 Remove a now-incorrect comment in tor-proto. 2022-01-26 14:06:58 -05:00
Ian Jackson 9a77b23cdd clippy: Rename a `decode_chanmsg` from `handle_`
As per https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/249#note_2771025

It doens't really handle it.
2022-01-19 18:46:13 +00:00
Ian Jackson 6c5e099be9 handshake: Use read_exact, not read and checking len
read_exact has a loop in it, which we need.

This means we end up separating the two sites that generate the "not a
relay" error, so we need to fish out the error construction.

As per https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/249#note_2771023
2022-01-19 18:45:53 +00:00
Ian Jackson c433899948 clippy: Rename a `from_foo` method that doesn't do conversion 2022-01-19 17:26:09 +00:00
Ian Jackson 1d5a480f79 Fix two bugs related to incomplete read/write
Discovered by clippy
2022-01-19 17:17:56 +00:00
eta c003fde04d Merge branch 'channel-arc-rework-5' into 'main'
chanmgr: get rid of Arc around Channel

See merge request tpo/core/arti!236
2022-01-13 13:12:30 +00:00
Ian Jackson 9b723cba53 chanmgr: get rid of Arc around Channel 2022-01-13 13:12:29 +00:00
Nick Mathewson bbf7c59b2d Describe when we will need SendmeAcceptMinVersion
(spoiler: not until we have a relay implementation)

Closes #53.
2022-01-12 15:52:24 -05:00
Nick Mathewson e335f6c75a Change RequireSendmeAuth to an enum.
This is a fine example of why booleans are risky:
it's far to easy to pass "animate:bool" into "inanimate:bool" like
we did here.

This is a followup from our fix to #294.
2022-01-12 15:46:36 -05:00
Nick Mathewson 1e915c3946 Fix a boolean inversion in auth_sendme_optional.
Previously we were requiring authenticated sendme cells exactly when we
should be permitting the old format, and vice versa.

This bug was caused by using a boolean to represent one property, but
with giving that boolean two different senses without inverting at the
right time.

The next commit will prevent a recurrence.

Closes #294
2022-01-12 15:36:55 -05:00
Nick Mathewson d49a490d4a Document SendmeEmitMinVersion status
(We don't need to look at SendmeEmitMinVersion since higher
values are not yet defined.)
2022-01-12 15:13:19 -05:00
Nick Mathewson b4761f8cfd Merge branch 'eta/182' into 'main'
Improve the layout of crate exports; add runtime convenience functions

See merge request tpo/core/arti!235
2022-01-11 18:42:15 +00:00
Ian Jackson cfcd3ea689 Add a blank line between doc and comment. 2022-01-11 18:23:58 +00:00
eta 41e202a3a4 Improve the layout of crate exports; add runtime convenience functions
This commit addresses multiple problems highlighted by arti#182:

- `arti-client` had some types in its public API that weren't accessible
  without importing another crate (`CfgPath`, `DataReader`,
  `DataWriter`). This has been fixed.
  - In addition, the doc comments for `DataReader` and `DataWriter` were
    cleaned up to be of better quality, now that they're public.
- It was impossible to use `arti-client` without also importing
  `tor-rtcompat`. This is now fixed by the addition of two convenience
  methods: `TorClient::bootstrap_with_tokio` and
  `TorClient::bootstrap_with_async_std`.
- Potentially controversially: `tor-rtcompat` now returns *concrete*
  types from methods like `current_runtime`, instead of `impl Runtime`.
  - This was needed in order to actually be able to name the `TorClient`
    type that results from using these methods.
  - This does mean we lose API flexibility, but on balance I think this
    is a good thing, because the API we *do* have is actually usable...
2022-01-11 15:16:03 +00:00
Nick Mathewson 7d3482ca1a Bump all crate versions to 0.0.3. 2022-01-11 09:40:32 -05:00
Nick Mathewson 4841b50c9f Minimize the required version for each dependency.
I found these versions empirically, by using the following process:

First, I used `cargo tree --depth 1 --kind all` to get a list of
every immediate dependency we had.

Then, I used `cargo upgrade --workspace package@version` to change
each dependency to the earliest version with which (in theory) the
current version is semver-compatible.  IOW, if the current version
was 3.2.3, I picked "3".  If the current version was 0.12.8, I
picked "0.12".

Then, I used `cargo +nightly upgrade -Z minimal-versions` to
downgrade Cargo.lock to the minimal listed version for each
dependency.  (I had to override a few packages; see .gitlab-ci.yml
for details).

Finally, I repeatedly increased the version of each of our
dependencies until our code compiled and the tests passed.  Here's
what I found that we need:

anyhow >= 1.0.5: Earlier versions break our hyper example.

async-broadcast >= 0.3.2: Earlier versions fail our tests.

async-compression 0.3.5: Earlier versions handled futures and tokio
    differently.

async-trait >= 0.1.2: Earlier versions are too buggy to compile our
    code.

clap 2.33.0: For Arg::default_value_os().

coarsetime >= 0.1.20: exposed as_ticks() function.

curve25519-dalek >= 3.2: For is_identity().

generic-array 0.14.3: Earlier versions don't implement
    From<&[T; 32]>

httparse >= 1.2: Earlier versions didn't implement Error.

itertools at 0.10.1: For at_most_once.

rusqlite >= 0.26.3: for backward compatibility with older rustc.

serde 1.0.103: Older versions break our code.

serde_json >= 1.0.50: Since we need its Value type to implement Eq.

shellexpand >= 2.1: To avoid a broken dirs crate version.

tokio >= 1.4: For Handle::block_on().

tracing >= 0.1.18: Previously, tracing_core and tracing had separate
    LevelFilter types.

typenum >= 1.12: Compatibility with rust-crypto crates

x25519-dalek >= 1.2.0: For was_contributory().

Closes #275.
2022-01-07 19:08:58 -05:00
Nick Mathewson 0151ceceb0 ClientCirc: change some methods to take &self
Previously they took Arc<Self>, and then Self, but &self is perfectly
fine here.
2022-01-07 13:55:26 -05:00
Ian Jackson d63a251afc tor-circmgr: Remove Arc around ClientCirc
See the new commentary text on `ClientCirc` for the rationale.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2022-01-07 18:19:20 +00:00
eta ea41fa3346 Merge branch 'refactor/unwrap-or-default' into 'main'
prefer 'unwrap_or_default' to manual constructor

See merge request tpo/core/arti!215
2022-01-06 15:36:12 +00:00
Nick Mathewson 5c3300867d Merge remote-tracking branch 'origin/mr/214' 2022-01-06 09:02:09 -05:00
Nick Mathewson c15168be61 Merge remote-tracking branch 'origin/mr/212' 2022-01-06 08:28:13 -05:00
Daniel Eades d68e934716 prefer 'unwrap_or_default' to manual constructor 2022-01-01 19:14:29 +00:00
Daniel Eades 592642a9e6 extend lints to include 'clippy::all' 2021-12-28 20:15:40 +00:00
Neel Chauhan 383843f0d7 tor-circmgr: Don't clone parameters in create_chantarget() 2021-12-25 17:22:38 -08:00
Neel Chauhan 7dba3d8c51 tor-proto: In begin_stream_impl(), if number of hops is zero, don't continue 2021-12-25 16:01:22 -08:00
Nick Mathewson 6303a71d58 tor-proto: Replace XXXs with references to arti#269
These will require thought; should we ignore them, act on them, or
continue to  treat them as internal errors?
2021-12-20 10:56:24 -05:00
Nick Mathewson 64257a10fa tor-proto: Allow one meta-cell handler at a time.
Previously the code would let us try to install a meta-cell handler
before the old one was done, leading to possible confusion.
2021-12-16 16:01:50 -05:00
eta 6a12f388f2 Merge branch 'ct_sendme_tags' into 'main'
tor-proto: use const-time eq on sendme tags.

See merge request tpo/core/arti!201
2021-12-16 20:29:01 +00:00
Nick Mathewson 51c4ca73f2 tor-proto: set HalfStream::connected_ok right.
Previously we'd always set it to true, allowing one CONNECTED per
half-closed stream even if the stream had already received a
CONNECTED  cell.

This resolves an XXXX.
2021-12-16 11:48:39 -05:00
Nick Mathewson a09fbc9f27 tor-proto: replace a streammap XXXX with a ticket. 2021-12-16 11:33:50 -05:00
Nick Mathewson d794355b07 tor-proto: use const-time eq on sendme tags.
There's no known attack here, but it's best practice to always compare
digests using a constant-time comparison operator.

This resolves an XXXX comment.
2021-12-16 11:06:30 -05:00
Nick Mathewson e2dd418c84 tor-proto: document an infelicitous behavior.
This was an XXXX before. Now it explains why the behavior is safe for
now, but maybe not forever.
2021-12-16 10:39:00 -05:00
Nick Mathewson f73840544c Extend trace messages for destroy/truncated reasons.
It makes sense to put the method for human-readable strings onto the
type itself, so that we can format these whenever they occur.

I'm choosing the "human_str" method name here, since caret-generated
types already have a to_str.  I was thinking about using Display,
but caret types already implement that.

I've also moved the message from "warn!" to "debug!", since these
aren't necessarily a problem condition.
2021-12-15 11:33:48 -05:00
Nick Mathewson 1cf0b87eb7 Merge remote-tracking branch 'origin/mr/191' 2021-12-15 10:46:58 -05:00
eta 2e0ff665bb Merge branch 'check_put_return' into 'main'
Always check whether stream-level SENDMEs are expected.

Closes #261

See merge request tpo/core/arti!192
2021-12-15 15:45:08 +00:00
Neel Chauhan 043b97fecf In reactor, use enums on whether to destroy circuits 2021-12-14 14:36:30 -08:00
Neel Chauhan b601d8b147 Methodize the destroy circuit reason 2021-12-14 14:26:45 -08:00
Nick Mathewson d5c2361d3f Always check whether stream-level SENDMEs are expected.
(It's a protocol violation to get a SENDME when our send window is
already full.)

This patch makes SendWindow::put return a Result, so that it's
easier to do the right thing with it.

Closes #261.
2021-12-14 17:11:48 +00:00
eta 8d660cbcf1 Actually decrement the stream-level SENDME window
arti!126 overhauled the `tor-proto` circuit reactor, but left out one
very important thing: actually decrementing the SENDME window for
streams (not circuits) when we send cells along them.

Since the circuit-level SENDME window would often prevent us from
running into a problem, this wasn't caught until my benchmarking efforts
noticed it (in the form of Tor nodes aborting the circuit for a protocol
violation).

fixes arti#260
2021-12-14 16:37:56 +00:00
Neel Chauhan 2595f3f8c1 Handle TRUNCATED cells 2021-12-13 12:21:25 -08:00
Neel Chauhan b6ef659311 Log on TRUNCATED cell 2021-12-13 12:21:19 -08:00
Trinity Pointard 9753a7ee06 fix nightly clippy errors 2021-12-09 12:16:23 +01:00
Nick Mathewson d0b217d1a5 Beautify some Vec->array code in tor-proto.
[T;N] supports TryFrom<Vec<T>>, and has since Rust 1.48: we can just
use that.

This resolves an XXXX comment.
2021-12-08 14:01:06 -05:00
Nick Mathewson 9a8c91bdf8 Merge remote-tracking branch 'origin/mr/180' 2021-12-08 12:39:02 -05:00
Neel Chauhan 2d915ed684 In CryptInit, return a Result in initialize() 2021-12-08 08:38:56 -08:00
Nick Mathewson 4536c2ac87 Upgrade to digest v0.10.0
We generally try to track the latest rust-crypto traits when we can:
fortunately, this upgrade didn't break much, considering.
2021-12-07 20:33:46 -05:00
Nick Mathewson 36f6a61f05 Remove some XXXs about zeroizing from tor-proto.
There is now a ticket about this issue in general, at arti#254.
2021-12-07 11:21:48 -05:00
Nick Mathewson 31b385c5b2 Resolve roughly half of the XXXXs.
We want to only use TODO in the codebase for non-blockers, and open
tickets for anything that is a bigger blocker than a TODO.  These
XXXXs seem like definite non-blockers to me.

Part of arti#231.
2021-12-06 15:11:03 -05:00
dagon 0c10f4ea0b add constructors 2021-11-30 23:51:03 +10:00
Nick Mathewson eef81d9d57 Bump every crate by one patch version. 2021-11-29 15:21:58 -05:00
Nick Mathewson efe165acf3 Mark a test as #[ignore]
This test seems unreliable on CI: we've got to disable them for now
so that we have a working CI system.  The CI failure is #238; the
ticket to repair them is #244.
2021-11-29 11:10:51 -05:00
Daniel Eades db16d13df4 add semicolons if nothing returned 2021-11-25 13:20:37 +00:00
Nick Mathewson 3e7e599a22 More typo fixes that I forgot to save :( 2021-11-24 18:23:12 -05:00
Nick Mathewson 54de7f5cfd Remove a couple more eprintln! calls. 2021-11-23 17:40:13 -05:00
Nick Mathewson 672b111262 Try to make the tor_proto::circuit::begindir test more reliable.
I traced the problem here to the fact that sometimes "rx" in this
test would be dropped before the test was done.  When "rx" is
dropped, the channel reactor shuts down, which in turn kills off the
circuit reactor.

This bug may exist in other cases in these tests.  This patch may
fix one case of #238.
2021-11-23 10:50:20 -05:00
eta 075e663dcd Make unreliable tor-proto tests more reliable (arti#238).
The `bad_extend_*` failures were caused by bad test code in
`bad_extend_test_impl` that used `futures::join!`; this meant that the
reactor could receive the `Extended2` cell before it actually got the
`ExtendNtor` request, which caused it to get (quite rightly) confused
and close the circuit. Spawning a background thread which has a short
delay before sending the `Extended2` cell seems to have alleviated this
problem.

`new_circ_create_failure` is similar; I think the reactor was getting
dropped before it had a chance to flush out its `CreateFast` cell
properly, because it had already gotten the result back (since the test
code sends it indiscriminately). This was "fixed" in much the same
manner as the other test: making it wait a bit before sending the result
cell back.

There seem to be other tests that use `futures::join!` (like
`begindir`?), and use similarly erroneous patterns; I haven't gotten any
to fail reliably enough to be able to debug them, though.
2021-11-18 16:06:53 +00:00
Nick Mathewson cc3efccdcc Always use optimistic data for begindir connections.
Closes #226.
2021-11-16 15:20:44 -05:00
Nick Mathewson f92ad644c9 tor-proto: Use tor-rtcompat macros for testing, not tokio.
Closes #222.
2021-11-15 12:57:01 -05:00
Nick Mathewson 787a995458 tor-proto: Stop using async_test in halfstream.rs and sendme.rs
Thanks to eta's refactoring, these tests no longer need to be async.
2021-11-15 12:12:53 -05:00
Nick Mathewson c6d188869f A few more eprintln!() removals that I missed. 2021-11-13 11:22:08 -05:00
Nick Mathewson 20b179bfa9 Replace or remove testing eprintln!()s.
The clippy code for warning about these on nightly CI can't tell the
difference between cfg(test) and no cfg(test).
2021-11-13 11:17:49 -05:00
Nick Mathewson b26fbdb24f Resolve a dead-code warning on nightly.
The `circid` field in `ClientCirc` is now testing-only.
2021-11-13 11:14:11 -05:00
eta c559754116 Get rid of unbounded stream sender, and RawCellStream
Previously, the reactor would use an `UnboundedSender` to send things to
the `RawCellStream`, in order that the reactor wouldn't block if you
failed to read from the latter. This is bad, though, since it means
people can just run us out of memory by sending lots of things.

To fix this, we make the new `StreamReader` type (which does the reading
parts from `RawCellStream`) keep track of the stream's receive window
and issue SENDMEs once *it* has consumed enough data to require it, thus
meaning that we shouldn't get sent enough data to fill the channel
between reactor and `StreamReader` (and, if we do, that's someone trying
to flood us, and we abort the circuit).

As hinted to above, the `RawCellStream` was removed and its reading
functionalities replaced by `StreamReader`; its writing functionalities
are handled by `StreamTarget` anyway, so we just give out one of those
for the write end. This now means we don't need any mutexes!

note: this commit introduces a known issue, arti#230
2021-11-12 15:04:27 +00:00
eta 197816d14c Completely overhaul the tor-proto circuit reactor
Rather like e8e9699c3c ("Get rid of
tor-proto's ChannelImpl, and use the reactor more instead"), this
admittedly rather large commit refactors the way circuits in `tor-proto`
work, centralising all of the logic in one large nonblocking reactor
which other things send messages into and out of, instead of having a
bunch of `-Impl` types that are protected by mutexes.

Congestion control becomes a lot simpler with this refactor, since the
reactor can manage both stream- and circuit-level congestion control
unilaterally without having to share this information with consumers,
meaning we can get rid of some locks.

The way streams work also changes, in order to facilitate better
handling of backpressure / fairness between streams: each stream now has
a set of channels to send and receive messages over, instead of sending
relay cells directly onto the channel (now, the reactor pulls messages
off each stream in each map, and tries to avoid doing so if it won't be
able to forward them yet).

Additionally, a lot of "close this circuit / stream" messages aren't
required any more, since that state is simply indicated by one end of a
channel going away. This should make cleanup a lot less brittle.

Getting all of this to work involved writing a fair deal of intricate
nonblocking code in Reactor::run_once that tries very hard to be mindful
of making backpressure work correctly (and congestion control); the old
code could get away with having tasks .await on things, but the new
reactor can't really do this (as it'd lock the reactor up), so has to do
everything in a nonblocking manner.
2021-11-12 15:04:24 +00:00
Nick Mathewson 5287ac1858 Merge IpVersionPreferences and the optimistic flag into one type.
It seems like a good time to do this, before we add a zillion other
arguments to begin_stream.
2021-11-10 11:04:55 -05:00
Nick Mathewson 428b19c121 Refactor wait_for_connection a bit.
* Make it crate-visible only.
* Make it idempotent
* Have it be an internal error if it's called at the wrong time.
* Simplify the return logic.
2021-11-10 10:33:31 -05:00
Yuan Lyu 7f799c956b Implement optimistic stream 2021-11-09 21:36:12 -05:00
Nick Mathewson 83d9f2299e Replace all println/eprintln calls outside of arti CLI with trace. 2021-11-04 11:04:59 -04:00
eta db6b91164e tor-proto: Use a dedicated sender for channel cells, make full-duplex
@nickm pointed out that refactoring tor_proto::channel's Reactor to do
sending as well meant that it could only send or receive, but not both,
simultaneously, which was bad!

To fix this, rewrite Reactor::run_once to use a handcrafted future (with
futures::future::poll_fn) that can handle the logic required to push
items onto the sink asynchronously (i.e. checking that it can be written
to before trying to do that, and then flushing it).

This also means we don't use select_biased! any more, and just handroll
that logic ourselves; as a small bonus, we can now process all 3 kinds
of message in one run_once() call, instead of having to do only one of
them.
2021-11-03 16:48:54 +00:00
eta e8e9699c3c Get rid of tor-proto's ChannelImpl, and use the reactor more instead
Instead of awkwardly sharing the internals of a `tor-proto` `Channel`
between the reactor task and any other tasks, move most of the internals
into the reactor and have other tasks communicate with the reactor via
message-passing to allocate circuits and send cells.

This makes a lot of things simple, and has convenient properties like
not needing to wrap the `Channel` in an `Arc` (though some places in the
code still do this for now).

A lot of test code required tweaking in order to deal with the refactor;
in fact, fixing the tests probably took longer than writing the mainline
code (!). Importantly, we now use `tokio`'s `tokio::test` annotation
instead of `async_test`, so that we can run things in the background
(which is required to have reactors running for the circuit tests).

This is an instance of #205, and also kind of #217.
2021-11-03 13:19:45 +00:00
Nick Mathewson 656a8e5f48 Merge branch 'timestamp' 2021-11-02 12:17:15 -04:00
Nick Mathewson dddf67a902 Use coarsetime to build an incoming traffic timestamp.
We need this for the circuit timeout estimator (#57).  It needs to
know "how recently have we got some incoming traffic", so that it
can tell whether a circuit has truly timed out, or whether the
entire network is down.

I'm implementing this with coarsetime, since we need to update these
in response to every single incoming cell, and we need the timestamp
operation to be _fast_.

(This reinstates an earlier commit, f30b2280, which I reverted
because we didn't need it at the time.)

Closes #179.
2021-11-02 12:17:11 -04:00
eta 2979bb22a2 Refactor tor_proto::circuit::Reactor to use an UnboundedSender
Basically the same thing as 371437d338
("Refactor tor_proto::channel::Reactor to use an UnboundedSender"), but
for tor_proto::circuit's Reactor instead.

(part of arti#217)
2021-11-02 14:26:25 +00:00
Nick Mathewson 118fddb15f Merge remote-tracking branch 'origin/mr/118' 2021-11-02 10:14:58 -04:00
eta 371437d338 Refactor tor_proto::channel::Reactor to use an UnboundedSender
There wasn't any good reason for tor-proto's channel reactor to use a
shedload of oneshot channels instead of just an mpsc UnboundedSender,
and the whole `CtrlResult` thing made even less sense.

Straighten this code out by replacing all of that machinery with a
simple UnboundedSender, instead.

(part of arti#218)
2021-11-02 14:02:58 +00:00
Nick Mathewson cdae4c033c Remove some dbg!() calls in real code. 2021-11-02 09:50:55 -04:00
Nick Mathewson e6e740646a Bump all crate versions to 0.0.1 2021-10-29 11:05:51 -04:00
eta a12fffc66a Improve docs of more (potentially re-exported) arti-client types
Most of the structs in `arti-client` have example code now, to give a
clearer idea of how they're used.

Annoyingly, a lot of the types exposed in `arti-client` are actually
re-exports, which makes documentation a bit harder: example code that
references other parts of `arti-client` can't actually be run as a
doctest, since the crate it's in is a dependency of `arti-client`.

We might be able to fix this in future by doing the documentation in
`arti-client` itself, but rustdoc seems to have some weird behaviours
there that need to be investigated first (for example, it seems to merge
the re-export and original documentation, and also put the re-export
documentation on the `impl` block for some reason).

For now, though, this commit just writes the docs from the point of view
of an `arti-client` consumer, removing notes specific to the crate in
which they're defined. It's not ideal, but at least the end user
experience is decent.
2021-10-29 14:06:06 +01:00
Nick Mathewson 2057142671 Use correct link for AsyncWriteExt::flush 2021-10-28 20:48:54 -04:00
Nick Mathewson c8f65e532e DataStream: document the importance of flush(). 2021-10-28 20:21:35 -04:00
Nick Mathewson 134c04a67a Update our disclaimers and limitations sections. 2021-10-27 11:13:46 -04:00
Nick Mathewson b477f12d83 s/arti-arti-client/arti-client/ and regenerate readme files 2021-10-25 08:40:00 -04:00
Nick Mathewson 730be38867 Replace references to arti-client in the documentation. 2021-10-21 14:22:21 -04:00
Nick Mathewson e9a29b4523 Remove #![allow(clippy::unnecessary_wraps)] in tor-proto. 2021-10-21 14:03:32 -04:00
Nick Mathewson fb2c7cb85a Also implement tokio Async{Read,Write} on Data{Reader,Writer}.
This will let callers use the tokio traits on these types too, if
they call `split()` on the DataStream.

(Tokio also has a `tokio::io::split()` method, but it requires a
lock whereas `DataStream::split()` doesn't.)
2021-10-19 15:49:49 -04:00
Nick Mathewson a9a9f70eb9 Add a little documentation about when you'll need the tokio trait. 2021-10-19 15:48:55 -04:00
eta ccd1d36e90 tor-proto: implement tokio Async{Read, Write} traits conditionally
futures::io::AsyncRead (and Write) isn't the same thing as tokio::io::AsyncRead,
which is a somewhat annoying misfeature of the Rust async ecosystem (!).

To mitigate this somewhat for people trying to use the `DataStream` struct with
tokio, implement the tokio versions of the above traits using `tokio-util`'s
compat layer, if a crate feature (`tokio`) is enabled.
2021-10-19 19:59:29 +01:00
Nick Mathewson 9df9706010 Use append in place of extend_from_slice in DataReaderImpl::add_data.
Suggested by @cheako.
2021-10-17 12:31:10 -04:00
Nick Mathewson af7c9d5a0b enable checked_conversions lint. 2021-10-09 16:53:13 -04:00
Nick Mathewson 10bedd925c Use subtle and some refactoring to remove branches in ntor
Closes #163
2021-10-01 12:27:24 -04:00
Nick Mathewson 1c97918d67 Typo fixes 2021-09-09 13:06:05 -04:00
Nick Mathewson d9dc6f9d5c Fix clippy warnings in tests with --all-features 2021-09-08 14:28:38 -04:00
Daniel Eades fb3b8b84b5 fix/silence clippy lints in test modules 2021-09-08 17:28:31 +02:00
Jani Monoses 25b4421fa6 Fix typos 2021-09-07 07:52:00 +03:00
Nick Mathewson 557a0ff40b Move all crates into a `crates` subdirectory.
This will cause some pain for now, but now is really the best time
to do this kind of thing.
2021-08-27 09:53:09 -04:00