Commit Graph

994 Commits

Author SHA1 Message Date
Ian Jackson 51c9cec1f1 arti-hyper: Clarify what the TLS features do. 2022-02-28 13:07:44 +00:00
Ian Jackson c24c3af81b arti-hyper: Actually support TLS 2022-02-28 13:07:44 +00:00
Ian Jackson c397c772e6 arti-hyper: Provide TLS connector and make space for TLS stream
Add tls_conn field to ArtiHttpConnector (and argument to constructor).
Introduce MaybeHttpsStream and use it in ArtiHttpConnection.
Have the example program pass the native TLS connector.

Currently the TLS connector and the HTTPS variant are not used, but
this commit is very noisy and fomrulaic, so I have split out the code
to use them into a separate commit for easier preparation and review.
2022-02-28 13:07:44 +00:00
Ian Jackson 148cd61f2b Manually implement Clone for ArtiHttpConnector
This will be needed in a moment and doing it now makes the next patch
smaller and hence easier to read.
2022-02-28 13:07:44 +00:00
Ian Jackson c08a317093 Introduce ErrorKind::OtherRemote
arti-hyper wants to be able to have a kind for TLS failure.

Given that arti-hyper is above arti-client, this shows that callers
above arti-client might need to invent kinds for their own errors.

Possibly this means we need other Other errors for other locations.
If we have pluggable components we might even want OtherTorError.
2022-02-28 13:07:44 +00:00
Ian Jackson 9a729aa2f8 arti-hyper: Disable clippy::clone_on_ref_ptr
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/355#note_2781816
disable this here for now, pending a decision on !352
2022-02-28 13:07:08 +00:00
Ian Jackson 23f8d33d4d Add a debug! log message for source cancellation 2022-02-28 12:52:38 +00:00
Ian Jackson 6d01c60925 Fix rustfmt 2022-02-28 12:36:48 +00:00
Nick Mathewson 76d8338640 Fix two typos 2022-02-28 11:21:52 +00:00
trinity-1686a 5323825964 don't return already errored pending circuit when searching new circuit matching spec 2022-02-27 13:16:03 +01:00
Ian Jackson dbf019e426 tor-circmgr: take_action: Handle Cancelled from the oneshot
Fixes #365

Inspection of the code and logs shows that:
 * One of the plan futures' oneshots must be returning Cancelled
 * This means that the corresponding sender must have been dropped
 * The sender is owned by the task spawned by spawn_launch
Presumably that entire task gets dropped as part of executor shutdown,
or something.

The correct response in this situation is to declare that we are
shutting down, and stop trying to do stuff.

Unfortunately, despite trying quite hard by putting sleeps in various
strategic places, I have not been able to reproduce the problem.  So I
can't be 100% sure that the new behaviour is correct.

But I am reasonably confident that this ought not to be able to occur
unless either 1. the task from spawn_launch is dropped, or 2. that
task somehow panics despite its attempts to trap panics and report
them as errors through the oneshot.

So this "burn it all down" action ought only to occur in actually
serious situations.

I observe that
  3ff9b187ea
  Handle panics from circuit construction.
changed the EK for PendingCanceled to EK::ReactorShuttingDown,
and there's From impl.  I think, therefore, that it is right
to reuse this Error variant.

I don't quite understand why when take_action gets an actual error it
doesn't push it, but just logs it.  But I am not changing that for
now.

Arguably the two instances of retry_error.push are a sign of an
inferior flow control pattern - maybe the loop body including the code
I am adding ought to be an IEFE returning
`Result<Option<circ>, crate::Error>`.
2022-02-25 18:10:36 +00:00
Nick Mathewson 489da37fe4 Split "static" into sqlite and native-tls features.
Otherwise, it's impossible to get a static sqlite linkage without
also getting native-tls, even if you wanted rustls.

Closes #302.
2022-02-25 13:05:25 -05:00
Ian Jackson 6b615b4766 impl Debug for various internal types
I wanted this while debugging something.

The ad-hoc impl Debug with f.debug_struct is getting repetitive
and I've already perpetrated one copy-paste mistake.
We should consider using something like the `educe` crate's Clone.
2022-02-25 17:37:10 +00: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 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 326e77c66c Update minimum backtrace version to 0.3.39
This is needed to make the backtrace test pass on Rust 1.53 with
minimum-version libraries.
2022-02-25 11:09:24 -05: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 a3bc59918d Upgrade to newer version of config crate. 2022-02-25 09:20:48 -05:00
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
eta d549844c1a Merge branch 'debug-datastream' into 'main'
tor-proto datastream: Fix typo in Debug impl

See merge request tpo/core/arti!354
2022-02-25 14:15:45 +00:00
Nick Mathewson 55416937cc Upgrade dependency to new version of tokio-util. 2022-02-25 08:48:00 -05:00
Nick Mathewson c627f50544 Upgrade dependency to new version of rlimit. 2022-02-25 08:45:24 -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 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
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
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 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
eta 3ac6ee71c8 Merge branch 'eta/335' into 'main'
arti-client: Unlock the state manager on failure to bootstrap

Closes #335

See merge request tpo/core/arti!334
2022-02-24 21:00:33 +00:00
eta 8f9831b219 Merge branch 'socks-version-is-http' into 'main'
make arti return a web page when receiving http request on socks port

See merge request tpo/core/arti!348
2022-02-24 20:48:28 +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 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
trinity-1686a 65b71a190f use less magic in http check 2022-02-24 20:03:42 +01: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
Ian Jackson 5f83b2b7be Fix rustdoc "skip this" markup 2022-02-24 16:19:28 +00:00
Ian Jackson 82af514926 TorClient: Add get_runtime() convenience method 2022-02-24 14:33:30 +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
Nick Mathewson 0600613110 Merge branch 'dir-store-redux' into 'main'
Dir store redux

See merge request tpo/core/arti!345
2022-02-24 13:58:54 +00:00
trinity-1686a e9b42938ec make arti return a web page when receiving http request on socks port 2022-02-23 23:03:42 +01:00
Dimitris Apostolou a3c1ba4b1a
Fix typos 2022-02-23 21:07:05 +02:00
tharvik b28803d861 dirmgr::Store.expire_all takes config 2022-02-23 13:56:52 -05:00
tharvik 8658052ce3 dirmgr: add Store trait 2022-02-23 13:50:33 -05: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
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
Ian Jackson fc35ffd6cd arti-hyper: impl HasKind for ConnectionError 2022-02-23 14:35:41 +00:00
Ian Jackson d7d0f52ef6 arti-hyper: Add note about missing https support 2022-02-23 14:35:41 +00:00
Ian Jackson 89146f37fb arti-hyper: Add vacuous doc comments to placate clippy 2022-02-23 14:35:41 +00:00
Ian Jackson 03de9f727c arti-hyper: Move support code into library
Pure code motion.  (Including motion/copying of "use" lines.)
2022-02-23 14:35:40 +00:00
Nick Mathewson 6c615898e4 Give specific error kinds to different END reasons
Closes #360.
2022-02-23 09:35:28 -05:00
Ian Jackson 80d8edc51f arti-hyper: Introduce new ConnectionError type
We need this not to use anyhow because we don't want our libraries to
expose anyhow, and this is about to go into the library.
2022-02-23 14:34:53 +00: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 92141c6d72 Merge remote-tracking branch 'origin/mr/340' 2022-02-23 09:29:40 -05: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 0f80be6b35 arti-hyper: empty crate skeleton 2022-02-23 13:55:14 +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
Ian Jackson 05bf12edfa Cleanups on !340 from @diziet 2022-02-23 13:17:27 +00:00
eta 05257da72d Merge branch 'restore_needless_borrow_check' into 'main'
Remove clippy::needless_borrow exception in CI.

Closes #310

See merge request tpo/core/arti!338
2022-02-23 13:15:15 +00:00
Nick Mathewson 784f1531bb Make NoLock into BadApiUsage.
To implement this, we had to refactor the tor_circmgr api for
flushing state changes to disk, so that it checks if it has the lock,
and only then tries to store.
2022-02-22 16:13:37 -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 0ce4a12976 Replace TorNetworkError with TorDirectoryError
This is still not as specific as we want; but there's already a TODO
comment in tor-dirclient::err about fixing that at some point in the
future.
2022-02-22 15:41:01 -05:00
Nick Mathewson 7d4a57d5fa Rename TorConnectionFailed to TorAccessFailed 2022-02-22 15:38:13 -05:00
Nick Mathewson 3f0d50e08f Fold UnexplainedTaskSpawnFailure into Internal. 2022-02-22 15:37:22 -05:00
Nick Mathewson 0e242831b2 Rename TorShuttingDown to ArtiShuttingDown 2022-02-22 15:36:09 -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 04ca1f662f Fold EK::Canceled into TransientFailure
Also add some TODO comments in circmgr for future work.
2022-02-22 15:30:12 -05:00
Nick Mathewson 5351aaa308 Fold AlreadyClosed into BadApiUsage 2022-02-22 15:25:24 -05:00
Nick Mathewson a02737be1c Add TODOs for errorkinds we mean to fix later
Per #348, These are the cases that we meant to fix down the road, but
not in 0.1.0.
2022-02-22 15:22:49 -05:00
Nick Mathewson e62afdf79a Merge remote-tracking branch 'origin/mr/335' 2022-02-22 12:46:51 -05:00
Nick Mathewson 4d4c7f47a7 Merge branch 'error-report' into 'main'
Improve error messages from arti cli

See merge request tpo/core/arti!331
2022-02-22 17:31:18 +00:00
Ian Jackson be2bb0ccfb tor_error::Report: add tests 2022-02-22 14:57:16 +00:00
Ian Jackson 01c5e07087 tor_error::Report: Add bound to struct
This is more typing in the definition but it produces much better
error messages if you try to Report(foo).to_string()
2022-02-22 14:53:17 +00:00
Ian Jackson 06964bbfbb Move program name printing to report_and_exit 2022-02-22 14:52:47 +00:00
Ian Jackson d1f4e9f3c6 Merge branch 'pending_error' into 'main'
Handle panics from circuit construction

Closes #347

See merge request tpo/core/arti!336
2022-02-22 10:58:09 +00: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
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
Nick Mathewson 3ff9b187ea Handle panics from circuit construction.
We handle them by reporting them to task that's waiting for the
circuit, then relaying the panic.

Doing so allows the waiting task to distinguish panics
(EK::Internal) from cases where the reactor dropped the task
entirely (EK::ReactorShuttingDown).  And doing _that_ removes one
case of EK::Canceled, which helps us on our goals towards #348.

Closes #347.
2022-02-18 14:22:38 -05:00
Ian Jackson 7d403b42fe Placate clippy on nightly, properly
I c&p this lint suppression but from a cli option printed by clippy,
and I didn't notice the need to change the - to _.
2022-02-18 18:07:43 +00:00
Nick Mathewson 0513a1d8a6 Edit tor-error comment to reflect shared ideas 2022-02-18 12:51:05 -05:00
Ian Jackson 4182c30b63 Placate clippy on nightly 2022-02-18 17:37:21 +00:00