Commit Graph

2646 Commits

Author SHA1 Message Date
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 9612a08b29 Note that tls-api is now async and can disable hostname verification
The other features we want aren't there yet.
2022-02-24 14:26:38 +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
Nick Mathewson 47f554cd40 Merge branch 'typos' into 'main'
Fix typos

See merge request tpo/core/arti!346
2022-02-23 20:29:24 +00: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
trinity-1686a 9a95bac10a better config for fuzz 2022-02-23 17:49:28 +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