Commit Graph

167 Commits

Author SHA1 Message Date
Nick Mathewson 5735222691 Update README.md files from rustdoc. 2022-03-01 08:30:53 -05:00
Nick Mathewson 57a8fe5f55 Fix rustdoc errors. 2022-03-01 08:16:02 -05:00
eta 13ba0ea005 arti-client: use PreferredRuntime by default, doc cleanups
This makes using the `PreferredRuntime` the first-class option inside
`arti-client`, freeing users who don't want to think about runtimes from
having to do so.

`TorClient::create_unbootstrapped` and `builder` now automatically
use this runtime, leaving only `builder_custom` for users who wish to
manually specify a runtime.

This lets us clean up the docs a lot: mentions of using custom runtimes
are now relegated to nearer the end of the crate-level documentation,
and we mostly just link to `tor_rtcompat`'s docs to explain more there.
Instead, we take some more time to explain how you use the builder API
to create clients synchronously.

Other doc cleanups included getting rid of the explanation of `TorAddr`
in the main crate-level doc; this is already well-documented elsewhere,
and is something users should discover organically later.

fixes arti#326
2022-02-28 16:41:13 +00:00
trinity-1686a f06b256010 use wallclock where possible in tests 2022-02-26 00:33:44 +01:00
trinity-1686a f9a4f23e83 remove most usage of SystemTime::now 2022-02-25 20:34:27 +01:00
eta 387ebda740 tor-rtcompat: refactor PreferredRuntime, clean up docs
`PreferredRuntime` is now an opaque wrapper struct that contains the
"actual" preferred runtime as a type alias. The `current_user_runtime`
and `create_runtime` functions become `PreferredRuntime::current` and
`PreferredRuntime::create`, respectively.

This removes the dependence on `impl Trait`, meaning we can now name the
returned runtime (yay!).

In addition, the documentation was cleaned up a bit to make it
(hopefully) flow better. Items that don't make sense to publicize, like
testing implementation details, have been marked #[doc(hidden)] and
semver warnings added.
2022-02-25 17:34:05 +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 55416937cc Upgrade dependency to new version of tokio-util. 2022-02-25 08:48:00 -05:00
Ian Jackson 0ad45d437c Merge branch 'tls-trait' into 'main'
tor-rtcompat: Provide TLS wrapping for all streams

See merge request tpo/core/arti!349
2022-02-25 11:13:34 +00:00
eta d9df4d647d Merge branch 'http-layer' into 'main'
Initial cut of hyper bindings as a library crate

See merge request tpo/core/arti!342
2022-02-24 19:48:35 +00: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 5f83b2b7be Fix rustdoc "skip this" markup 2022-02-24 16:19:28 +00:00
Ian Jackson 2bbd01b060 tor-rtcompat: Provide TLS wrapping for all streams
Now all of the runtime types we provide all
  impl<S> TlsProvider<S> where S: ...
rather than merely TlsProvider<Self::TcpStream>.

And we document and intent to perhaps require this in the future.
2022-02-24 14:26:38 +00:00
Ian Jackson f8d17bce83 Add missing documentation for TLS features to two readmes 2022-02-23 13:53:45 +00:00
trinity-1686a 81d7747d7b add example of tcp hook
this required to make additional types public
2022-02-23 13:29:37 +00:00
Ian Jackson 1c301230e4 rename *.py scripts to bare name
Update all references.  There are three remaining hits for
  git-grep '\.py\b'
all of which are scripts in "little-t-tor", not here in arti.
2022-02-18 11:46:06 +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 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 19f878b3aa tor-rtcompat: remove some unused code.
Nothing actually used these accessor functions, and it's not clear
what would.  We can add them later if they're needed.
2022-01-27 15:52:59 -05:00
Nick Mathewson f7373f8b20 tor-rtcompat: Add some miscellaneous tests
These probably aren't for things that will fail IRL, but it's nice
to have coverage on the code, just in case.
2022-01-27 15:48:30 -05:00
Nick Mathewson af85262257 tor-rtcompat: Simplify test-declaration macros.
Now there's much less copy-and-paste.
2022-01-27 15:09:09 -05:00
Nick Mathewson 9435e4b36e Move tor-rtcompat tests to lib.rs
This makes our layout more similar to our other crates, and
successfully informs our grcov exclusion pattern that these tests
are indeed tests.

Doing this knocks down the reported coverage for the tor-rtcompat
crate, but that's okay: we hadn't earned it.

I hereby promise that this commit is only code-movement.
2022-01-27 14:45:00 -05:00
Nick Mathewson 9f3ad85d75 Document why {current,create}_runtime are type-erased 2022-01-27 10:31:45 -05:00
eta c4321289f2 Apply @eta's suggestions from review on !263
Comment-only.
2022-01-27 15:25:57 +00:00
Nick Mathewson 5dcc821146 Fix documentation references for tor-rtcompat refactoring. 2022-01-26 14:58:28 -05:00
Nick Mathewson bf8fa66d36 Rename `SpawnBlocking` trait to `BlockOn`.
This avoids a future confusion with the new `SpawnBlocking` trait in
async_executors v0.5, and better describes what the trait provides.
2022-01-26 14:06:58 -05:00
Nick Mathewson dec2c4ee63 Make test_with_all_runtimes cover _all_ the runtimes.
This took some refactoring, so that I wouldn't need to define 9
different versions of the function.  It also required that we change
the behavior of test_with_all_runtimes slightly, so that it asserts
on _any_ failure rather than asserting on most but returning Err()
for others.  That in turn required changes to a few of its callers.

There's probably a better way to do all of this macro business, but
this is the best I could find.
2022-01-26 14:06:58 -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 8af3528cd3 Define aliases for "the best enabled runtime".
This helps us simplify our code in a few ways, and will help even
more once native_tls is optional.
2022-01-26 14:06:58 -05:00
Nick Mathewson 6f29d485e4 Make current/create functions into runtime member functions.
This should help avoid some amount of temptation towards API
proliferation.
2022-01-26 14:06:58 -05:00
Nick Mathewson 2333d0466e Rename FooRuntime to FooNativeTlsRuntime for consistency. 2022-01-26 14:06:58 -05:00
Nick Mathewson 05a04220cc Limit the inner types in tor-rtcompat that have to implement Clone
If we implement our own clone on CompoundRuntime, we no longer need
Clone implementations on our TlsProvider implementations.
2022-01-26 14:06:58 -05:00
Nick Mathewson 99c59a8f2b Remove no-longer-needed tokio runtime helper macro 2022-01-26 14:06:58 -05:00
Nick Mathewson 668364d75d Unify TokioRuntime and TokioRuntimeHandle
Having separate types here doesn't justify the (very limited)
benefit of distinguishing between the case where we have created an
executor that we own and the case where we have a handle to an
already-running tokio executor.

Part of #301.
2022-01-26 14:06:58 -05:00
Nick Mathewson 5af8a1bf28 Remove misspellings of "rusttls". 2022-01-26 14:05:05 -05:00
Nick Mathewson e4e691a790 More comments on the limitations of tor-rtcompat's TLS API
Also, more comments on why these limitations are safe within the
context of Tor, but you wouldn't want to use them elsewhere.
2022-01-25 13:16:39 -05:00
Nick Mathewson 0898b485aa Comment-only: document sni_hostname more.
Previously we expected the reader to automatically know why it was
called "SNI", which really isn't fair.
2022-01-25 13:16:39 -05:00
Nick Mathewson d1d121aac6 Refactor native_tls usage into its own module
This change uses the async-native-tls crate for everything, and
deletes some duplicated code.
2022-01-25 13:16:39 -05:00
Nick Mathewson 8def5a0d89 tor-rtcompat: Add support for rustls.
This is based on @janimo's approach in !74, but diverges in a few
important ways.

1. It assumes that something like !251 will merge, so that we can
   have separate implementations for native_tls and rustls compiled
   at the same time.

2. It assumes that we can implement this for the futures::io traits
   only with no real penalty.

3. It uses the `x509-signature` crate to work around the pickiness of
   the `webpki` crate.  If webpki eventually solves their
   [bug 219](https://github.com/briansmith/webpki/issues/219), we
   can remove a lot of that workaround.

Closes #86.
2022-01-25 13:16:39 -05:00
Nick Mathewson 979cfb46d1 Add a C program to make Tor-style X509 link certificates
We should never use this for anything but making the testing
certificates we use for making sure our TLS implementation works.
2022-01-24 14:22:07 -05:00
Nick Mathewson 17920e43f8 Refactor Runtimes to use separate TLS implementations internally.
This will make it easier to implement them using some other TLS
provider as well, without having to duplicate all of our code.
2022-01-19 15:47:26 -05:00
Nick Mathewson 8d3e4576da Add a macro to help with opaque Runtime wrappers.
We're soon going to have our different Runtime types be built as
CompoundRuntime instances.  We don't want to expose that detail,
though, so we'll use this macro to make them implement the right
traits.
2022-01-19 15:47:26 -05:00
Nick Mathewson dd72607601 Add a CompoundRuntime type for runtime construction.
This type can solve two problems at once.

First, it lets users replace parts of an existing runtime
implementation without replacing the whole thing.  For example, you
can use it to override your TcpProvider implementation to solve
problems like #235.

Second, we can use it internally to tor-rtcompat to define Runtimes
piece-by-piece.  Mostly we'll use this to separate our Tls
implementations from our implementations of the rest of the Runtime.
2022-01-19 15:47:26 -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
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
Daniel Eades 592642a9e6 extend lints to include 'clippy::all' 2021-12-28 20:15:40 +00:00
eta b14c5f370e Make TlsConnector wrap TCP connections, not create its own
`tor-rtcompat`'s `TlsConnector` trait previously included a method to
create a TLS-over-TCP connection, which implied creating a TCP stream
inside that method. This commit changes that, and makes the function
wrap a TCP stream, as returned from the runtime's `TcpProvider` trait
implementation, instead.

This means you can actually override `TcpProvider` and have it apply to
*all* connections Arti makes, which is useful for issues like arti#235
and other cases where you want to have a custom TCP stream
implementation.

This required updating the mock TCP/TLS types in `tor-rtmock` slightly;
due to the change in API, we now store whether a `LocalStream` should
actually be a TLS stream inside the stream itself, and check this
property on reads/writes in order to detect misuse. The fake TLS wrapper
checks this property and removes it in order to "wrap" the stream,
making reads and writes work again.
2021-12-07 17:00:40 +00: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
Nick Mathewson eef81d9d57 Bump every crate by one patch version. 2021-11-29 15:21:58 -05:00
Daniel Eades db16d13df4 add semicolons if nothing returned 2021-11-25 13:20:37 +00:00
Trinity Pointard 03f8966f0d use 3des instead of rc2 in .pfx test fixture 2021-11-18 09:07:48 +01:00
Nick Mathewson 03cca4ddda Upgrade to async-native-tls 0.4.0 2021-11-12 08:36:41 -05:00
Nick Mathewson e6e740646a Bump all crate versions to 0.0.1 2021-10-29 11:05:51 -04:00
Nick Mathewson 1ee24ce653 Improve some documentation links
Instead of putting a fully qualified name in the text, in most cases
we should just use the short name of the type or function we're
referring to.

In other words, instead of saying [`crate::module::Foo`], we should
typically say [`Foo`](crate::module::Foo).
2021-10-29 08:39:04 -04:00
Nick Mathewson 9a10d4ae50 Clarify that new SleepProvider methods are testing-only. 2021-10-26 13:06:10 -04:00
eta e8419abd25 Overhaul the way WaitFor and the MockSleepProvider work
Instead of racily advancing time forward, this commit attempts to rework
how WaitFor works, such that it makes advances when all sleeper futures
that have been created have been polled (by handing the MockSleepRuntime
a Waker with which to wake up the WaitFor).

The above described mechanics work well enough for the double timeout
test, but fail in the presence of code that spawns asynchronous /
background tasks that must make progress before time is advanced for the
test to work properly. In order to deal with these cases, a set of APIs
are introduced in order to block time from being advanced until some
code has run, and a carveout added in order to permit small advances in
time where required.

(In some cases, code needed to be hacked up a bit in order to be made
properly testable using these APIs; the `MockablePlan` trait included in
here is somewhat unfortunate.)

This should fix arti#149.
2021-10-26 16:33:23 +01:00
Nick Mathewson dcca0ec366 Require up-to-date x25519-dalek, async_executors, and argh.
I tried using -Z minimal-versions to downgrade all first-level
dependencies to their oldest permitted versions, and found that we
were apparently depending on newer features of all three crates.

I'm kind of surprised there were only three.
2021-10-09 19:37:08 -04:00
Nick Mathewson af7c9d5a0b enable checked_conversions lint. 2021-10-09 16:53:13 -04:00
Nick Mathewson ab0c80de2b Fix/suppress a few more clippy lints in tests.
I'm alright with allowing cognitive-complexity violations in the
tests.
2021-09-08 14:20:47 -04:00
Daniel Eades fb3b8b84b5 fix/silence clippy lints in test modules 2021-09-08 17:28:31 +02:00
Nick Mathewson bd2c9fd8c1 Document every macro.
(The nightly version of clippy now includes macros for its
missing_docs_in_private_items lint.)
2021-09-07 08:44:47 -04: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