Commit Graph

694 Commits

Author SHA1 Message Date
eta 3d623f5a1f Merge branch 'tcp-hook-new-tls' into 'main'
use runtime TlsProvider in tcp-hook example

See merge request tpo/core/arti!356
2022-02-25 14:15:59 +00:00
Nick Mathewson 55416937cc Upgrade dependency to new version of tokio-util. 2022-02-25 08:48:00 -05:00
Ian Jackson 0ebab3df0b Merge branch 'get-runtime' into 'main'
TorClient: Add get_runtime() convenience method

See merge request tpo/core/arti!350
2022-02-25 13:36:34 +00:00
trinity-1686a f633276a91 use runtime TlsProvider in tcp-hook example 2022-02-25 13:42:14 +01:00
Ian Jackson 310779c39d TorClient:runtime(): rename from get_runtime
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/350#note_2781368
2022-02-25 10:45:30 +00:00
eta c6fdd7c003 arti-client: Unlock the state manager on failure to bootstrap
`StateMgr` got a new `unlock()` method that does what it says on the
tin. We now call it from `bootstrap()` using the new
`util::StateMgrUnlockGuard`, which works in a manner similar to the
`BoolResetter` from `tor_dirmgr`.

(A decent small little task in future might be to unify these types in
some sort of general arti utility crate?)

closes arti#335
2022-02-24 19:55:59 +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 82af514926 TorClient: Add get_runtime() convenience method 2022-02-24 14:33:30 +00:00
Nick Mathewson ed2a5de9b4 Add a builder function for replacing a DirProvider.
Put it behind experimental_api.
2022-02-23 15:23:09 -05:00
Nick Mathewson 9aeb967010 Un-parameterize DirProvider.
This patch removes the EventStream associated type and the Runtime
parameter.  The Runtime parameter wasn't actually used for anything,
and the EventStream was easy enough to replace with a BoxStream in
this case.

Also replaced DirBootstrapEvents with a BoxStream to avoid tying
anything to our backend.
2022-02-23 14:46:17 -05:00
Christian Grigis 279b5978b7 Add basic DirProvider trait, use it in client 2022-02-23 14:11:21 -05:00
Dimitris Apostolou a3c1ba4b1a
Fix typos 2022-02-23 21:07:05 +02:00
eta 8603a90fb2 Merge branch 'custom-tcp-hook' into 'main'
add example of tcp hook

See merge request tpo/core/arti!341
2022-02-23 18:02:08 +00:00
trinity-1686a 078a91c591 add one more comment to hook-tcp 2022-02-23 18:00:35 +01:00
Ian Jackson fe864c17c6 impl From<TorAddrError> for tor_error::Error
It auto-converts to ErrorDetail but add this for convenience of
callers which don't want to look into that unstable API.
2022-02-23 14:34:53 +00:00
Nick Mathewson 6ea0df166a Merge branch 'client_builder' into 'main'
Make a TorClientBuilder API.

Closes #350

See merge request tpo/core/arti!337
2022-02-23 14:14:32 +00:00
eta 9960064720 examples/hook-tcp: add some comments, rework lifetimes a bit
Try to make the `hook-tcp` example a bit easier to read by
adding/changing comments, and renaming the lifetimes for
`async_trait`-generated trait methods.
2022-02-23 13:59:03 +00:00
Ian Jackson 0cf9751d7f arti-hyper: Move hyper example from arti-client
Code motion and consequential dependency adjustments.
2022-02-23 13:55:17 +00:00
Ian Jackson f8d17bce83 Add missing documentation for TLS features to two readmes 2022-02-23 13:53:45 +00:00
trinity-1686a ce679ad72a implement correct handling of connection close and add comment explaining goal of the example 2022-02-23 13:29:37 +00:00
trinity-1686a b5707a98e7 add drop on CustomTcpStream to catch disconnection without close 2022-02-23 13:29:37 +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 fd288f90f9 Documentation suggestion from review. 2022-02-23 13:19:10 +00:00
Nick Mathewson c910226b55 Make a TorClientBuilder API.
This is a defensive API choice to protect against the possibility
that we'll want to add a bunch of other non-config options in
the future.

Closes #350
2022-02-18 15:28:31 -05:00
Ian Jackson f9d2ecad27 Bump anyhow minimal version to 1.0.23
This is the first one where anyhow::Error impl AsRef<dyn StdError>

We want this because we want to add error reporting functionality
which works with all kinds of errors, which means we need an
anyhow::Error which can be vieweed as a StdError.

(The alternative would be to deref at the call sites of
report_and_exit, making it less ergonomic.)

anyhow 1.0.23 is from November 2019.
2022-02-18 17:04:57 +00:00
Nick Mathewson 83d001d661 Merge branch 'remaining-errors' 2022-02-17 14:22:47 -05:00
Nick Mathewson 034c5ba9f5 Rename ExitTimeout to RemoteNetworkTimeout. 2022-02-17 12:19:33 -05:00
Nick Mathewson 0bdef96897 arti_client: provide Kinds for all errors. 2022-02-16 16:38:22 -05:00
eta 30439f9dc2 Merge branch 'eta/lazy-init' into 'main'
arti-client: add ability to automatically bootstrap

Closes #278

See merge request tpo/core/arti!322
2022-02-16 20:08:38 +00:00
eta 790ea4af4b arti-client: add ability to automatically bootstrap
The new `BootstrapBehavior` enum controls whether an unbootstrapped
`TorClient` will bootstrap itself automatically (`Ondemand`) when an
attempt is made to use it, or whether the user must perform
bootstrapping themselves (`Manual`).

The `lazy-init` example shows how you could write a simple
`get_tor_client()` function that used a global `OnceCell` to share
a Tor client across an entire application with this API.

closes arti#278
2022-02-16 19:29:16 +00:00
Yuan Lyu 98b1a5a279 Move persistent state flush from client to circmgr 2022-02-15 20:04:45 -05:00
Nick Mathewson 72221b0b77 Merge branch 'explain_into_tor_addr' into 'main'
More docs for IntoTorAddr

Closes #253

See merge request tpo/core/arti!305
2022-02-14 20:34:50 +00:00
Nick Mathewson a44b13c93a More docs for IntoTorAddr 2022-02-14 20:34:50 +00:00
eta d7478e2675 Merge branch 'ticket_337' into 'main'
Simplify wait_for_bootstrap to use a Mutex.

Closes #337

See merge request tpo/core/arti!308
2022-02-14 19:46:23 +00:00
Nick Mathewson 8ea95aee7a Simplify wait_for_bootstrap to use a Mutex.
Since the only purpose of this function is to make sure that no
bootstrapping task is running, a simple futures:🔒:Mutex
should do the job just fine.

Closes #337.
2022-02-14 09:59:37 -05:00
Nick Mathewson 1cecc7e45a Change deny(clippy::all) to warn(clippy::all).
Closes #338.
2022-02-14 09:24:06 -05:00
Nick Mathewson 7da5d557bf Rename bootstrap_existing to bootstrap.
(Looks like this one got missed.)
2022-02-11 12:58:25 -05:00
Nick Mathewson 7885db406a Merge branch 'eta/unbootstrapped-clients' into 'main'
Allow creating unbootstrapped `TorClient`s (and `DirMgr`s)

Closes #293

See merge request tpo/core/arti!298
2022-02-11 17:43:46 +00:00
eta 882e75cd28 Allow creating unbootstrapped `TorClient`s (and `DirMgr`s)
This commit changes how the `TorClient` type works, enabling it to be
constructed synchronously without initiating the bootstrapping process.
Daemon tasks are still started on construction (although some of them
won't do anything if the client isn't bootstrapped).

The old bootstrap() methods are now reimplemented in terms of the new
create_unbootstrapped() and bootstrap_existing() methods.

This required refactoring how the `DirMgr` works to enable the same sort
of thing there.

closes #293
2022-02-11 16:42:19 +00:00
Nick Mathewson f7a0228a81 Write some examples for TorClient::connect()
These should explain better what you can pass as an address, and
what you should do if you _really need_ to provide a SocketAddr or
something.
2022-02-11 10:11:46 -05:00
Nick Mathewson ff33faf984 Update launch of chan expiration task to new API
This fixes a compilation error.
2022-02-08 10:41:14 -05:00
Nick Mathewson 3f39737817 ErrorDetail Simplify visibility macros a bit.
Instead of declaring a macro that takes vis as an argument, we now
conditionally declare a macro that applies an appropriate visibility.

There's a long comment explaining the rationale here, along with a
couple of other solutions that don't work.
2022-02-08 10:37:46 -05:00
Nick Mathewson d00f00dd41 Rename TorResult to Result.
This is closer to common usage.

(Not that we all agree with common usage, but it's closer to what
people expect.)
2022-02-08 10:37:46 -05:00
Nick Mathewson 80716a294b arti_client: Rename Error to ErrorDetail.
This is closer to what we described in Errors.md.

Also, remove the (sometimes private) Result alias: it was only used in
one or two places, and never exposed in public.
2022-02-08 10:37:46 -05:00
Nick Mathewson 929bcc6c86 TorError: Make detail() an accessor function.
This change lets us make TorError's members unconditionally hidden,
and makes our API a little more consistent (since basically nothing
else is a public field).
2022-02-08 10:37:46 -05:00
eta 109515ecfe Merge branch 'error-improvements' into 'main'
Hopefully uncontroversial improvements to new Error code

See merge request tpo/core/arti!291
2022-02-08 14:42:30 +00:00
Yuan Lyu f6f732a478 Expire channels that have been unused for too long 2022-02-04 22:52:51 -05:00
Nick Mathewson 1166977975 Docs and clarification for a bunch of Error stuff 2022-02-04 16:06:11 -05:00
Nick Mathewson 070e52653d Make SpawnError wrappers contain a 'spawning' string
(By our convention, these errors should say what we were trying to
spawn when the error occurred.)
2022-02-04 16:06:11 -05:00
Nick Mathewson 9bd7419c20 Make the Error detail type non-exported from arti-client
At least by default, we should have Error be private, and not expose
it as part of our APIs.

To keep functionality in `arti`, I had to add an `ExitTimeout` error
kind.

For interface consistency, I also re-exported ErrorKind and HasError
from `arti_client`.
2022-02-04 16:06:11 -05:00
Nick Mathewson 7462971c1b Test that TorError implements the right traits.
I had planned to use assert_impl, but that can't check for
the 'static lifetime.
2022-02-04 16:06:11 -05:00
Nick Mathewson 645dc10148 Make TorError implement Clone.
This patch makes only minimal changes in lower-level error types:
we have more refactoring to do.
2022-02-04 16:06:11 -05:00
Ian Jackson 5b54d3e08e errors: Add some TODOs as per discussion comments 2022-02-04 14:52:30 +00:00
Ian Jackson f5e874cf91 errors: Drop "Error" and "Failed" from various enum variants 2022-02-04 14:42:37 +00:00
Ian Jackson 0462533863 Box the Error in a TorError
This will get quite large and boxing it here is very convenient.

This also avoids us exposing a large error type to our callers.
2022-02-04 14:42:37 +00:00
Ian Jackson 43fc900284 errors: Handle exit circuit creation failure the new way 2022-02-04 14:42:37 +00:00
Ian Jackson b3cebf163f errors: Handle circmgr setup errors differently
The motivation for doing this now is to remove the `#[from]` so we
would spot where operationsl circuit setup failures were handled.
(But it turns out that they are turned into internal errors!)

Perhaps this will want to become a different error type from circmgr
in due course, but for now we simply use a bespoke variant of
TorError.

It will want its own Kind.  The TODO in the HasKind impl marks
this (amongst much else here).
2022-02-04 14:42:37 +00:00
Ian Jackson 2101dd5e39 errors: Introduce error_detail feature
Right now we must always expose the `Error` type since we haven't
converted everything.
2022-02-04 14:42:37 +00:00
Ian Jackson 9a293a1f6f errors: Refer to err::Error in some bits of arti_client
We are going to make the top-level Error type conditionally hidden.
2022-02-04 14:42:37 +00:00
Ian Jackson 9e577f9a17 errors: Introduce TorError
Still much to do here.
2022-02-04 14:42:37 +00:00
Ian Jackson 14f67609f7 errors: Initial impl HasKind in arti-client, ErrorKind::TODO
This involves making a temporary ErrorKind::TODO.  That will continue
to exist until all errors (at least, the ones that make it out to
here) can be properly categorised.

Introducing this will let us work from the top and bottom towards the
middle.
2022-02-04 14:42:37 +00:00
Ian Jackson de17c64412 spawn errors: Fix arti-client, tor-chanmgr, tor-circmgr
Provide an enum variant to contain the SpawnError and a From impl.

We use `#[from]` here because it doesn't really make sense to attach
any context, as it's not likely to be very relevant.
2022-02-04 14:42:37 +00:00
Ian Jackson 6e1dc612cc tor-error: Add as a ddpendency to many crates
Doing this here makes it easier when I rebase/reorder things
2022-02-04 14:42:37 +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
Dimitris Apostolou 6526321851
Fix typos 2022-02-02 20:18:22 +02:00
Nick Mathewson 487f3be6de Expose Reconfigure enum from arti-client.
This enum is required to use `TorClient::reconfigure` correctly, and
as such ought to be re-exported.
2022-02-01 14:26:39 -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
Neel Chauhan 417809123c Make max_file_limit configurable 2022-01-28 11:17:49 +00:00
Nick Mathewson 5dcc821146 Fix documentation references for tor-rtcompat refactoring. 2022-01-26 14:58:28 -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 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 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
Ian Jackson a79a2e87be Rename TorClient::set_stream_prefs
In line with the rest of the renaming.

As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/256#note_2771617
2022-01-21 17:12:08 +00:00
Ian Jackson aa4d8de16e StreamPrefs: rename from ConnectPrefs
The docs even say this is about stream.

As @nickm writes in
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/252#note_2771289

  we generally call end-to-end connections that are tunneled over Tor
  "Streams" to distinguish them from everything else in the Tor
  protocols that could possibly be called a "Connection".

That seems to apply here too.
2022-01-21 11:07:15 +00:00
Ian Jackson 695a33c1fd Merge branch 'always-isolate' into 'main'
Provide isolate-all-streams function

Closes #279

See merge request tpo/core/arti!252
2022-01-20 19:08:05 +00:00
Ian Jackson 7bc8941742 isolation: Rename isolate_every_stream from ..._connection
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/252#note_2771291
2022-01-20 17:53:09 +00:00
Ian Jackson 23c1fc8c56 isolation: Rename (internal) EveryStream enum variant
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/252#note_2771289
2022-01-20 17:53:09 +00:00
Nick Mathewson 06c15f21b4 isolation: Much better wording for always isolate setting 2022-01-20 17:52:10 +00:00
Ian Jackson ced24b1974 connection preferences: Make `set_default_prefs` private for now 2022-01-20 13:52:30 +00:00
Ian Jackson e04e41a1db connection preferences: Make `clone_with_prefs` must_use
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/250#note_2771239
2022-01-20 13:50:12 +00:00
Ian Jackson 9e904167e4 isolation: Provide isolate-every-connection option 2022-01-20 12:08:22 +00:00
Ian Jackson a5356aed65 isolation: Provide new_isolation_group method
In the usual case, set_isolation_group is awkward.

This is perhaps slightly duplicative with TorClient::isolated_client().
If so then perhaps the *latter* should be abolished.
2022-01-20 12:08:22 +00:00
Ian Jackson 639db26d58 isolation: Refactor to introduce a bespoke enum
No functional change.

This will grow a new variant shortly.
2022-01-20 12:08:22 +00:00
Ian Jackson 7ff16fc252 connection preferences: Provide `clone_with_prefs` method 2022-01-19 17:45:59 +00:00
Ian Jackson 4ddbb3daeb connection preferences: Provide `set_connect_prefs` method 2022-01-19 17:45:59 +00:00
Ian Jackson dec0e1e756 connection preferences: Take ConnectPrefs by reference
This may save quite a bit of copying.  The callees don't need to copy
the whole struct; they copy the bits they need.
2022-01-19 17:42:43 +00:00
Ian Jackson 1437f953b6 connection preferences: Rename variable and docs to not say "flags"
These aren't flags.  Eg, there's an isolation token in there.
2022-01-19 17:39:29 +00:00
Ian Jackson e84ff24d11 isolation: Document orthogonality of isolated_client and isolation_group 2022-01-19 17:39:29 +00:00
Nick Mathewson db2ca6ebc4 Merge branch 'bootstrap_reporting' 2022-01-19 08:40:36 -05:00
Nick Mathewson 79e6dc1d4b Put our cache files in the right place.
This resolves a copy-and-paste error where we were putting
everything in our state directory.

Closes #297.
2022-01-18 13:32:06 -05:00
Nick Mathewson 41e3498f8a Integrate status information at arti-client
This commit combines status update information from tor-dirmgr and
tor-chanmgr in the arti-client crate, so that the user can get to
it; it represents a high-level view of the client's ability to reach
the network and route traffic.

I have omitted the tor-circmgr support for now; it's mostly not
needed.

At present it's not so useful, since there's no way for a client to
get a TorClient that _isn't_ completely bootstrapped, and therefore
there's no way to actually watch these events until they're no
longer interesting.  That should change with arti#293.

This is part of #96.
2022-01-18 13:27:56 -05:00
Nick Mathewson 1bd2790d51 Implement the basics of a bootstrap-status API.
The purpose of a this API is to tell the user how far along Arti is
in getting bootstrapped, and if it's stuck, what it's stuck on.

This API doesn't yet expose any useful information: by the time it's
observable to a client, it's always "100% bootstrapped."  But I'm
putting it in a MR now so that we can review the basic idea, and to
avoid conflicts with later work on tickets like #293 and #278.

This is part of #96.
2022-01-13 10:29:49 -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 c5f50b7d41 Update README.md files (automated) 2022-01-11 09:37:45 -05:00
eta c42fac09a5 Merge branch 'ticket_281' into 'main'
Expose and rename stream timeout config.

Closes #281

See merge request tpo/core/arti!231
2022-01-10 15:05:31 +00:00
Nick Mathewson 01c851ad46 Expose and rename stream timeout config.
Previously we kept this in an ambiguously named type,
`ClientTimeoutConfig`. But everything we do right now is client
related! So `StreamTimeoutConfig` is a better name.

Also, we'd previously neglected to expose the builder for this type
from `TorClientConfigBuilder`. Now we do.

Closes #281.
2022-01-10 09:46:43 -05:00
Nick Mathewson 7819dd7bac Make the arti_client::Result type public.
Closes #280.
2022-01-10 09:33:26 -05:00
eta e6e65d6574 Merge branch 'minimize_deps' into 'main'
Minimize the required version for each dependency.

Closes #275

See merge request tpo/core/arti!228
2022-01-10 13:44:53 +00:00
Neel Chauhan 439b8b3e64 Use *_with_prefs() for Option<ConnectPrefs> callers in TorClient::connect 2022-01-08 13:36:49 -08: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
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
Daniel Eades 592642a9e6 extend lints to include 'clippy::all' 2021-12-28 20:15:40 +00:00
eta 0cdf65c256 Merge branch 'refactor/must-use-self' into 'main'
address clippy's latest lint

See merge request tpo/core/arti!205
2021-12-20 18:38:18 +00:00
Nick Mathewson f73f6a4e80 arti-client: Change an XXXX to a TODO.
We _do_ reject bad hostnames: just not where I once thought we might.
We need to decide if the current behavior is what we want (and I think
it is, probably?).
2021-12-20 10:02:24 -05:00
Daniel Eades 9b51a52b53 address clippy's latest lint 2021-12-20 09:46:41 +00:00
eta 8040f7afb2 Merge branch 'reconfigure' into 'main'
Make most arti-client fields reconfigurable.

See merge request tpo/core/arti!181
2021-12-13 14:49:23 +00:00
Trinity Pointard 2339370a85 drop arcs before awaiting 2021-12-09 13:11:09 +01:00
Trinity Pointard 9753a7ee06 fix nightly clippy errors 2021-12-09 12:16:23 +01:00
Nick Mathewson 1ff5a513ae Oops: MutCfg shouldn't implement Clone.
We don't want MutCfg to be automatially coneable, or we'll wind up with
surprises like the one that this patch fixes in TorClient.

(The "surprise" is that reconfigure() would only apply its
client-specific options  to one client instance.)
2021-12-07 17:54:24 -05:00
Nick Mathewson 953ee93533 Sequence reconfiguration requests.
If we allow overlapping reconfiguration requests, we introduce all
kinds of "fun" bugs.  For example, we could wind up with a configuration
made up of parts of one reconfiguration attempt, and parts of another.
2021-12-07 17:49:03 -05:00
Nick Mathewson 7ac6870a0d Improve documentation of which config can change.
It no longer makes sense to say "most things can't change", now that
most things can.
2021-12-07 17:41:05 -05:00
Nick Mathewson 2689d810bf Make TorClient reconfigurable.
This covers ClientAddrConfig and ClientTimeoutConfig.
2021-12-07 16:58:41 -05:00
Nick Mathewson 99fb41218d Add new configuration objects to reconfigure.
(These weren't in the codebase when I started the first version of
this branch.)
2021-12-07 15:47:25 -05:00
Nick Mathewson 11210124da Allow on-the-fly changing of path_rules
And now the complexity begins: when the user changes the path_rules,
they not only want new circuits to obey those rules: they want
_all new requests_ to be put onto circuits that obey those rules.

That means that when the path rules become more restrictive, we need
to retire all the circuits, and make sure that currently pending
circuits aren't used for any requests.

If it's any comfort, doing this was even more complicated in C tor. ;)
2021-12-07 15:42:14 -05:00
Nick Mathewson 606d64eac5 Sketch API for reconfiguration.
This patch doesn't actually make anything reconfigurable, but it
does create an API that will tell you "you can't change the value of
that!"  If the API looks reasonable, I can start making it possible
to change the values of individual items.
2021-12-07 15:42:14 -05:00
Nick Mathewson 2337d14ecf Make ClientTimeoutConfig members crate-private.
We shouldn't have pub members in these config objects.
2021-12-07 14:05:41 -05:00
Nick Mathewson 46c917d127 Rename timeout_rules to stream_timeouts.
(There are other timeout rules, after all.)

Also, rename stream_timeout to connect_timeout, to make it more clear
when it applies.
2021-12-07 14:03:14 -05:00
eta 2614fb736e Merge branch 'revised_preemptive_config' into 'main'
Usability: renaming and documentation in preemptive circuit config

See merge request tpo/core/arti!176
2021-12-07 17:51:42 +00:00
eta 47c3163ce5 Merge branch 'bug252' into 'main'
Make DNS fields in arti-client/src/client.rs configurable

Closes #252

See merge request tpo/core/arti!171
2021-12-07 17:27:38 +00:00
Nick Mathewson c2e20a242a Rename circuits_preemptive to preemptive_circuits
This obeys a few conventions:
  * adjective before noun
  * config objects end with "config"
2021-12-07 12:06:53 -05:00
Neel Chauhan 9c66b68c5a Rename ClientDNSConfig -> ClientTimeoutConfig 2021-12-07 08:43:58 -08:00
eta 45b96579b8 Merge branch 'preemptive-config' into 'main'
Allow configurability on preemptive circuits

Closes #245

See merge request tpo/core/arti!164
2021-12-07 15:04:42 +00:00
Neel Chauhan 0e9c2d274e Allow configurability on preemptive circuits 2021-12-07 15:04:41 +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
Neel Chauhan ac1afe92cc Improve ClientDNSConfig field comments 2021-12-03 10:34:24 -08:00
Neel Chauhan f32a10865e Make DNS fields in arti-client/src/client.rs configurable 2021-12-03 10:28:42 -08:00
Nick Mathewson c2804419ab Add constructor for TorAddr, to enforce port != 0
This makes sure that we're checking for a nonzero port in all cases.
2021-11-30 15:41:19 -05:00
Nick Mathewson 08267147ec Merge remote-tracking branch 'origin/mr/156' 2021-11-30 15:21:02 -05:00
Nick Mathewson c733374693 Merge remote-tracking branch 'origin/mr/154' 2021-11-30 14:12:08 -05:00
Nick Mathewson 3b072c5420 Merge branch 'readme_fixes' 2021-11-30 09:12:51 -05:00
dagon 0162ea8210 Example needs to be the same as the readme 2021-11-30 09:09:42 -05:00
dagon bd1c37fe8a MR review feedback 2021-11-30 09:09:42 -05:00
dagon e0489328f6 fix arti-client doc example 2021-11-30 09:09:42 -05:00
Nick Mathewson b9ad2f917c Fix a documentation link. 2021-11-30 08:37:21 -05:00
Nick Mathewson c5181dc7f0 Fix a bad rustdoc reference. 2021-11-29 21:04:40 -05:00
eta 2920a4d084 Merge branch 'simplify_config_helpers' into 'main'
Change sane_defaults() and with_directories()

See merge request tpo/core/arti!155
2021-11-29 20:42:28 +00:00
Nick Mathewson eef81d9d57 Bump every crate by one patch version. 2021-11-29 15:21:58 -05:00
Nick Mathewson f107794b74 Change sane_defaults() and with_directories()
The sane_defaults() call is now the same as you get from a default
builder: by convention, we just call that method Default::default().

The with_directories() constructor makes more sense as a constructor
for the TorClientConfigBuilder than for TorClientConfig.
2021-11-29 14:20:34 -05:00
Neel Chauhan 36dc690ada arti-client: Reject Port 0 when parsing address:port combos 2021-11-29 11:09:38 -08:00
Nick Mathewson eb861b7edd Merge branch 'config-updates-and-tests' 2021-11-29 13:59:41 -05:00
Nick Mathewson 098547f735 Document StorageConfig defaults better.
(Also fix a couple of typos)
2021-11-29 13:55:33 -05:00
eta ca42139944 Actually build preemptive circuits (and minor fixes)
The new CircMgr::build_circuits_preemptively function actually causes
preemptive circuits to be built; it gets called from arti-client, like
the other daemon tasks the CircMgr has.
2021-11-29 14:47:09 +00:00
dagon d5c48c616f run ./maint/readmes.sh 2021-11-29 21:29:28 +10:00
Nick Mathewson f2034ac6e2 Add basic tests for high-level builders
Make sure that we can change elements, and we can reconstruct builders
that give us the same thing.
2021-11-25 09:40:16 -05:00
Nick Mathewson 75d977a259 Impl and test Default for high-level configs 2021-11-25 09:39:11 -05:00
Nick Mathewson 17266305e2 Ensure that all config sections have deny_unknown_fields
When we deserialize a configuration, we should reject unknown variables
(except when we have an explicit reason to allow them).
2021-11-25 09:39:11 -05:00
Nick Mathewson ecf462e4ef Make directory accessors crate-private.
These don't need to be exposed any longer.
2021-11-25 09:39:10 -05:00
Nick Mathewson 53d5f647b2 Define defaults for StorageConfig
I'm still not 100% sure this is the right move: should we encourage
app developers to always pick their own directories? Or should we
make it easy for them to use, well, `sane_defaults`?

This patch takes the second approach.
2021-11-25 09:39:09 -05:00
Daniel Eades db16d13df4 add semicolons if nothing returned 2021-11-25 13:20:37 +00:00
Daniel Eades 052f51ff71 deglob some enums, use concise iteration syntax 2021-11-25 12:39:52 +00:00
Nick Mathewson fbf72fd5af Resolve a pair of rustdoc warnings. 2021-11-24 18:24:47 -05:00
Nick Mathewson 3e7e599a22 More typo fixes that I forgot to save :( 2021-11-24 18:23:12 -05:00
Nick Mathewson f55950ab8d Fix a few typos.
Also fix some commonwealth spellings that had slipped in.
2021-11-24 18:12:44 -05:00
Nick Mathewson 307ca9b4d0 Implement meta-builder pattern for TorClientConfig
This should be ergonomic than having to construct every section of the
configuration separately.
2021-11-22 14:53:52 +00:00
Nick Mathewson 40ff7113d4 Make every Config type implement Eq.
Doing this is necessary for reconfiguration support, and will help a lot
with testing, too.
2021-11-21 12:06:15 -05:00
Nick Mathewson e7fdf05f50 For every* config type, make defaults consistent.
This patch makes sure that for every* config type we have, the defaults
you get from a Builder match those you get from Serde, and that both
match the value that you get from arti_defaults.toml. Later down the
line I'll be adding some tests to keep these in sync.

* StorageConfig still has no defaults of its own, since we aren't so
sure we want other applications to use Arti's directories by default.
2021-11-21 11:52:43 -05:00
Nick Mathewson efdd327569 Rename .gitignore APP_FOO to ARTI_FOO.
Since these shell-variables are hardwired to use org.torproject.Arti as
the program name, it isn't appropriate to call them "app-specific".

If we someday reinstate APP_FOO, it should be based on a user-provided
application name.
2021-11-21 11:29:10 -05:00
Nick Mathewson 05be12e4d8 Give CfgPath an alternative inner representation.
In order to handle explicitly specified path buffers directly, we now
let CfgPath be either a string (that gets expanded) or a PathBuf
(that doesn't).

This simplifies TorClientConfig::with_directories()
2021-11-21 11:17:56 -05:00
Nick Mathewson 97f5a7a357 Give every ConfigBuilder a From<Config> implementation.
This will make it more convenient to reconfigure things.
2021-11-21 10:54:34 -05:00
Nick Mathewson aa83a5e38a Ensure that every section-level config type has a builder() function. 2021-11-21 10:54:34 -05:00
Nick Mathewson 0372d24eed Make arti-client config object match arti config better.
Now every section that the two configuration objects share has the
same type and name.  This should help us in documenting our configuration
in a way that doesn't confuse people.

There is still lots of API work to go.
2021-11-21 10:54:34 -05:00
Nick Mathewson 065d3dc104 Lower StorageConfig to arti-client crate 2021-11-21 10:54:34 -05:00
Nick Mathewson a7f5b9aefe Allow type-complexity in hyper.rs example
This isn't the prettiest, but suppressing the warning does make
the example warning free.
2021-11-21 10:53:06 -05:00
Nick Mathewson d592e86f9c Fold "circuit_timing" and "request_timing" into a single section. 2021-11-18 11:37:48 -05:00
Nick Mathewson 5184f5ba84 Move top-level configuration downwards from `arti` to `arti-config`.
To do this at all neatly, I had to split out `tor-config` from
`arti-config` again, and putting the lower level stuff (paths,
builder errors) into tor-config.  I also changed our use of
derive_builder to always use a common error type, to avoid
error type proliferation.
2021-11-18 11:37:48 -05:00
Nick Mathewson 15d1645bbd Typo fix from reddit thread. 2021-11-17 09:14:32 -05:00
Nick Mathewson e5c5519f7b Remove dependency from arti-client to tor-config.
I'm about to make tor-config a higher-level module, so it can't be a
dependency for tor-config.
2021-11-16 16:01:55 -05:00
Dimitris Apostolou ad3c18a456
Fix typos 2021-11-12 13:54:50 +02:00
Nick Mathewson 24b6a2455d Document that the "experimental-api" feature is not semver-covered. 2021-11-11 10:44:24 -05: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
Yuan Lyu 7f799c956b Implement optimistic stream 2021-11-09 21:36:12 -05:00
Nick Mathewson e6e740646a Bump all crate versions to 0.0.1 2021-10-29 11:05:51 -04:00
Nick Mathewson 9d3256ec83 Update README.md files 2021-10-29 09:37:15 -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 c11fe200d1 Try writing a bit more documentation for configuration types. 2021-10-28 20:49:17 -04:00
Nick Mathewson 6cba1acef4 Encourage the use of TorClient::clone(). 2021-10-28 20:21:35 -04:00
Nick Mathewson bf3bfdf62d arti-client example: Try to make the comments a little more clear.
I'm not 100% sure this is better, but it might help the user
understand how Arti works a bit better.
2021-10-28 20:20:23 -04:00
Nick Mathewson 672335ccf6 Update README.md files 2021-10-28 19:59:22 -04:00
eta dcdd8c59df Improve top-level arti-client documentation, add example code
This overhauls the top-level `arti-client` documentation significantly:

- the "Using arti-client" section walks the user through all of the
  necessary steps to initiate a Torified TCP connection, and then
  provides a code example
  - this example is also available as `examples/readme.rs`; it's not run
    as a doctest, since it involves connecting to Tor
  - a "More advanced usage" subheading provides information about stream
    isolation (and can potentially be used for other interesting
    features once we get them).
- a new "Multiple runtime support" section was added to explain the
  purpose and usage of the `tor-rtcompat` crate
- the section on design and privacy considerations was removed; this is
  probably okay to keep in a README, but users of the crate aren't going
  to be interested in this (at least I don't think)

(also, the doc comment for `arti_client::Error` was fixed to make actual
sense)
2021-10-28 19:20:42 +01:00
Nick Mathewson 134c04a67a Update our disclaimers and limitations sections. 2021-10-27 11:13:46 -04:00
Nick Mathewson be4823818e TorClient::resolve_ptr should take an IpAddr. 2021-10-26 09:42:25 -04:00
Nick Mathewson 1b6098d00f More tests for arti_client::address 2021-10-26 09:32:41 -04:00
Nick Mathewson 47234655ce Turn StreamIsolation into a separate type.
Now that we have two kinds of isolation tokens (those set on a
stream, and those set by the stream's associated TorClient), we
need a more sophisticated kind of isolation.

This fixes the bug introduced with the previous commit, where
per-stream tokens would override per-TorClient tokens.
2021-10-25 12:32:18 -04:00
Nick Mathewson 16f6ee4b54 Add an isolate_client() function to create an isolated TorClient.
When two TorClients are isolated, their streams shouldn't share
circuits, even though they share internal circuit and guard state.
2021-10-25 12:02:44 -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 89de07686d Upgrade to latest tracing-{subscriber,journald} 2021-10-23 22:23:26 -04:00
Nick Mathewson e00a1c59ae Run "cargo fix --edition-idioms=2018". 2021-10-22 09:05:45 -04:00
Nick Mathewson 7c7a388e28 Rename tor_client/arti_tor_client to arti_client.
Solves a name conflict with the existing tor_client create.

Closes #130.
2021-10-21 14:22:11 -04:00