Commit Graph

2387 Commits

Author SHA1 Message Date
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
Nick Mathewson 13f39ed896 Minimal compilation fix: InternalError=>Bug
This is a followup for !314 and !310 to fix compilation on main.
2022-02-15 10:13:08 -05:00
Nick Mathewson 7b6a7a57d3 Merge branch 'doc-errors' into 'main'
Refactor errors in tor-netdoc

See merge request tpo/core/arti!314
2022-02-15 15:09:48 +00:00
eta cb7f068c3b Typo fix from@eta 2022-02-15 14:34:59 +00:00
Ian Jackson e6e4ea25c0 Merge branch 'error-kind-badargument' into 'main'
New name and semantics for Bug (was BadArgument)

See merge request tpo/core/arti!310
2022-02-15 14:21:28 +00:00
Ian Jackson 8688069add tor_error::Bug: change Display impl to use kind
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/310#note_2777626

The message from the kind is precisely right.
2022-02-15 13:58:54 +00:00
Ian Jackson ad6cb60d8a BadApiUsage: change Display impl capitalisation
Now it maches the others
2022-02-15 13:58:52 +00:00
Ian Jackson 5d636738eb Rename BadApiUsage from BadAPIUsage
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/310#note_2777519
mutatis mutandi.

And, fix a leftover instance with an old idea of what this was called.
2022-02-15 11:46:54 +00:00
Ian Jackson 97a0a7359b tor-socksproto: Use bad_api_usage! rather than ad-hoc Invalid error 2022-02-15 11:40:24 +00:00
Ian Jackson b8f928e4f5 Make Bug from InternalError, add bad_api_usage! and into_bad_api_usage!
Including supporting machinery, new kind field, etc.
2022-02-15 11:40:24 +00:00
Ian Jackson 5d87ca8ad7 New name and semantics for BadAPIUsage (was BadArgument) 2022-02-15 11:32:19 +00:00
Nick Mathewson e80d472beb Merge branch 'error-socksproto-autoconvert' into 'main'
Provide, and use From impl for InternalError

See merge request tpo/core/arti!315
2022-02-14 20:57:24 +00: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
Nick Mathewson 31075e8046 Run rustfmt. 2022-02-14 14:47:42 -05: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
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 e4321bbae2 Merge remote-tracking branch 'origin/mr/313' 2022-02-14 14:25:28 -05:00
Ian Jackson 8db7ab8148 Merge branch 'error-kind-protocol' into 'main'
Split up ErrorKind::ProtocolViolation

See merge request tpo/core/arti!312
2022-02-14 19:07:00 +00:00
Ian Jackson 4774cbd18d Provide, and use From impl for InternalError
Adding this autoconversion is quite safe since every error generation
site is explicit and has its own context, and we don't really need to
add more.

This simplifies the code and will simplify future work.
2022-02-14 18:48:35 +00:00
Ian Jackson 65e2deaf29 Merge branch 'error-kind-notimp' into 'main'
Split up ErrorKind::NoSupport

See merge request tpo/core/arti!311
2022-02-14 18:31:56 +00:00
Nick Mathewson b6d23c36be Refactor tor_netdoc::Error
This error type doesn't impement HasKind, since the kind will depend
on context.

However, the existing implementation was pretty messy and inconsistent:
Some errors had positions, some didn't.
Some took messages as str, some as String.
Some had internal errors that were somewhat orthogonal to their actual
types.

This commit refactors tor_netdoc::Error to use a ParseErrorKind, and
adds a set of convenience functions to add positions and
messages to the errors that need them.
2022-02-14 13:08:28 -05:00
Ian Jackson 4d14398fe1 Split up ErrorKind::ProtocolViolation 2022-02-14 17:55:56 +00:00
Ian Jackson b74f3a3c10 ErrorKind::NotImplemented: fix two tests 2022-02-14 17:54:05 +00:00
Ian Jackson 02959576bb tor_socksproto::Error HasKind fix two delegations
We should not generally explicitly specify a kind for errors which
contain a more detailed error which itself has a kind.  Stating the
kind literally is a latent bug, which becomes a real bug if the
contained type's kind changes or starts to vary.

(There may be exceptions to this principle but this isn't one of
them.)
2022-02-14 17:46:19 +00:00
Nick Mathewson 9e88f279d9 Merge branch 'error-kind-config-transition' into 'main'
Clarify ErrorKind::InvalidConfigTransition

See merge request tpo/core/arti!309
2022-02-14 16:51:32 +00:00
Ian Jackson 30ebb1358a Split up ErrorKind::NoSupport 2022-02-14 16:06:45 +00:00
Nick Mathewson b27c51d3a2 netdoc: Make doc-build errors a separate type
Every other case of tor_netdoc::Error means a parse failure.  This one,
though, means a failure to construct  a document.
2022-02-14 10:46:04 -05:00
Nick Mathewson eeab17f811 Merge branch 'useless_qm' into 'main'
dirmgr: Remove a useless Ok(x?)

See merge request tpo/core/arti!307
2022-02-14 15:42:51 +00:00
Ian Jackson 3a9a4b6532 Clarify ErrorKind::InvalidConfigTransition 2022-02-14 15:41:40 +00:00
Nick Mathewson 61867613a2 netdoc: remove Error::Untimely.
Nothing creates this.
2022-02-14 10:28:58 -05:00
Nick Mathewson 9e3d0bc817 Merge branch 'update_if_zero' into 'main'
Use atomic set-and-check to update OptTimestamps if none.

See merge request tpo/core/arti!297
2022-02-14 15:18:28 +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 2cd4f0c872 dirmgr: Remove a useless Ok(x?)
Found by nightly clippy.
2022-02-14 09:30:18 -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
eta 5981fa7932 Merge branch 'connect_examples' into 'main'
Write some examples for TorClient::connect()

See merge request tpo/core/arti!303
2022-02-11 16:40:02 +00:00
Nick Mathewson c268e54dd0 Merge branch 'socksproto-errors' into 'main'
tor-socksproto: Implement HasKind

See merge request tpo/core/arti!299
2022-02-11 15:15: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 0b020e64b4 socksproto: fix one more error type. 2022-02-11 09:36:57 -05:00
Nick Mathewson 4e8db2b836 socksproto: Simplify Truncated handling
Refactor the Error type to remove the yucky internal hidden Truncated
variant.  Instead, there's now an embedded tor_bytes::Error value.

If that tor_bytes::Error is Truncated, we bubble it up when we convert our
handshake result to the nested error struct.

Thus there is still (sadly) a variant of tor_socksproto::Error
that shouldn't be exposed to user code.  But refactoring every
inner method under handshake.rs seemed like a bad idea: once we're using
Result<Result<..>>, the ? operator no longer helps us much.
2022-02-11 09:36:57 -05:00
Nick Mathewson f62b2600c7 Move the Truncated error into tor-errors. 2022-02-11 09:36:57 -05:00
Nick Mathewson 22141d2516 Try to resolve the "Truncated" error in tor-socksproto
I'm not in love with this solution; the others just seem a bit ugly
too.
2022-02-11 09:36:57 -05:00
Nick Mathewson f6189e174b tor-socksproto: Implement HasKind
(This error isn't yet wrapped in TorError, but it will be eventually
when we implement socks proxy and PT support.)
2022-02-11 09:36:57 -05:00
Nick Mathewson 10293ca57e Merge branch 'typos' into 'main'
Fix typos

See merge request tpo/core/arti!301
2022-02-10 13:06:04 +00:00
eta 8e2e81d534 Merge branch 'bytes-err' into 'main'
tor-bytes: Use InternalError.

See merge request tpo/core/arti!300
2022-02-10 12:50:47 +00:00
Dimitris Apostolou 1690e877ed
Fix typos 2022-02-10 14:25:56 +02:00
Nick Mathewson 7670a26d9c tor-bytes: Use InternalError.
This crate's Error type is too low-level to have an ErrorKind, but
it does make sense to use InternalError for the internal errors
here.
2022-02-09 14:39:04 -05:00