Commit Graph

33 Commits

Author SHA1 Message Date
Ian Jackson b095265257 Merge branch 'educe-traits' into 'main'
Replace many manual trait impls with use of educe

See merge request tpo/core/arti!375
2022-03-04 18:00:17 +00:00
Ian Jackson ebfd734956 Move skip_fmt into tor-basic-utils
Code motion and the minimal mechanical changes.

As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/375#note_2783078
2022-03-04 11:45:24 +00:00
Ian Jackson bb1d59e073 Replace manual Default impl with educe in tor-cell 2022-03-02 18:06:37 +00:00
Ian Jackson 1c44dfa595 Replace manual Debug impl with educe in tor-cell 2022-03-02 18:03:00 +00:00
Ian Jackson 2becfcf894 Replace manual Default impl with std derive in tor-cell 2022-03-02 18:01:08 +00:00
Nick Mathewson 83c8b11c2c Merge branch 'clippy-allow-arc-clone' into 'main'
Disable clippy::clone_on_ref_ptr

See merge request tpo/core/arti!352
2022-03-01 20:38:05 +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
Nick Mathewson 6c615898e4 Give specific error kinds to different END reasons
Closes #360.
2022-02-23 09:35:28 -05: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 80be59497e Merge branch 'clippy-followup' into 'main'
Remove some needless refs and slicing

See merge request tpo/core/arti!327
2022-02-17 18:25:54 +00:00
Ian Jackson bbcc871105 Remove some needless refs and slicing
Prompted by nightly's clippy (which has some false positives, so is
currently disabled).
2022-02-17 11:16:27 +00:00
Ian Jackson 95e081ab44 Merge branch 'ptr_arg_fix' into 'main'
Re-enable clippy::ptr_arg where it had been disabled.

See merge request tpo/core/arti!323
2022-02-17 11:07:45 +00:00
Nick Mathewson ed57157d84 Re-enable clippy::ptr_arg where it had been disabled.
In one of the two places, nightly no longer warns.  In the other
place, it's fine for nightly to warn: I just fixed the code to take
a slice instead.

Partial revert of 856aca8791.

Resolves part of #310.
2022-02-16 11:33:12 -05:00
Nick Mathewson 8b9b42514a Update tor-cell errors to latest API 2022-02-15 09:56:53 -05:00
Nick Mathewson da0e9e456c tor-cell: provide HasKind.
Additionally, refactor the IoError out of tor_cell::Error:
nothing in TorCell created this; it was only used by tor_proto.

This required refactoring in tor_proto to use a new error type. Here I
decided to use a new CodecError for now, though we may refactor that
away soon too.
2022-02-15 09:41:10 -05:00
Nick Mathewson 1cecc7e45a Change deny(clippy::all) to warn(clippy::all).
Closes #338.
2022-02-14 09:24:06 -05:00
Ian Jackson 7be3bf6339 Temporarily disable some clippy lints on nightly 2022-02-02 21:57:30 +00:00
Daniel Eades 592642a9e6 extend lints to include 'clippy::all' 2021-12-28 20:15:40 +00:00
Nick Mathewson de45ee41a4 tor-cell: replace an XXXX with a TODO.
The original comment was a gnomic question about what to box; the real
issue is that we want to avoid copying data in our critical path.
2021-12-16 10:29:30 -05:00
Nick Mathewson f73840544c Extend trace messages for destroy/truncated reasons.
It makes sense to put the method for human-readable strings onto the
type itself, so that we can format these whenever they occur.

I'm choosing the "human_str" method name here, since caret-generated
types already have a to_str.  I was thinking about using Display,
but caret types already implement that.

I've also moved the message from "warn!" to "debug!", since these
aren't necessarily a problem condition.
2021-12-15 11:33:48 -05:00
Nick Mathewson 1cf0b87eb7 Merge remote-tracking branch 'origin/mr/191' 2021-12-15 10:46:58 -05:00
Neel Chauhan b601d8b147 Methodize the destroy circuit reason 2021-12-14 14:26:45 -08:00
eta 8d660cbcf1 Actually decrement the stream-level SENDME window
arti!126 overhauled the `tor-proto` circuit reactor, but left out one
very important thing: actually decrementing the SENDME window for
streams (not circuits) when we send cells along them.

Since the circuit-level SENDME window would often prevent us from
running into a problem, this wasn't caught until my benchmarking efforts
noticed it (in the form of Tor nodes aborting the circuit for a protocol
violation).

fixes arti#260
2021-12-14 16:37:56 +00:00
Neel Chauhan d621166c80 s/hidden/onion/g in code comments 2021-12-13 13:18:53 -08:00
Neel Chauhan b6ef659311 Log on TRUNCATED cell 2021-12-13 12:21:19 -08:00
Nick Mathewson a49c1c1f1e Treat unrecognized SENDME versions as an error.
We should never get one of these unless we have opted in to get it.

(This behavior is the same as C tor.)
2021-12-08 13:03:20 -05: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
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 134c04a67a Update our disclaimers and limitations sections. 2021-10-27 11:13:46 -04:00
Nick Mathewson af7c9d5a0b enable checked_conversions lint. 2021-10-09 16:53:13 -04: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
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