Commit Graph

144 Commits

Author SHA1 Message Date
Nick Mathewson 932fe48eaf Run add_warnings. 2022-11-03 11:06:02 -04:00
Ian Jackson 48f48841e1 Require derive_more 0.99.3
0.99.[012] have a bug https://github.com/JelteF/derive_more/issues/114
which makes the Deref derive for bridgedesc::StateGuard not work
and therefore breaks minimal-versions CI.

It seems simpler to require the newer version everywhere.
2022-11-03 11:37:23 +00:00
Ian Jackson 9796d615f8 tor-basic-utils: Provide an implementation of BinaryHeap::retain
This is currently nightly-only and is blocked on an unresolved API
question:
  https://github.com/rust-lang/rust/issues/71503
2022-10-27 10:46:03 +01:00
Nick Mathewson 15ac14a5d9 n_key_set: clean up some wide lines 2022-10-24 08:08:56 -04:00
Nick Mathewson ef1c0cd282 n_key_set: Re-insert by_foo_mut() accessors, but make them unsafe. 2022-10-24 08:04:02 -04:00
Nick Mathewson d648446201 Fix some litter in a doc comment. 2022-10-24 07:59:42 -04:00
Nick Mathewson 24e62d3197 n_key_set: Add ability to modify entries in the map.
The keys can change: if they do, then the entry is removed from its
previous position and inserted at the new one, possibly displacing
others.
2022-10-24 07:58:45 -04:00
Ian Jackson f84d8777db cargo fmt to remove blank lines
Apparently cargo fmt doesn't like these, which my perl rune didn't
delete.

This commit is precisely the result of `cargo fmt`.
2022-10-12 15:29:04 +01:00
Ian Jackson d9910dba08 Replace all README copies in src/lib.rs with includes
The feature we want is `#[doc = include_str!("README.md")]`, which is
stable since 1.54 and our MSRV is now 1.56.

This commit is precisely the result of the following Perl rune:
  perl -i~ -0777 -pe 's{(^//!(?!.*\@\@).*\n)+}{#![doc = include_str!("../README.md")]\n}m' crates/*/src/lib.rs
2022-10-12 15:29:03 +01:00
Ian Jackson 82ad9eea5f Allow "clippy::single_char_pattern" in tests.
This lint exists for perf reasons, and this is rarely relevant in
tests.

Using double quoted str is generally cognitively less burdensome.
2022-10-12 13:50:29 +01:00
Nick Mathewson 5a5f96aa37 n_key_set: Fix bugs in API documentation.
For whatever reason, rustdoc didn't like these multiline strings
in `doc` attributes.
2022-10-04 16:05:40 -04:00
Nick Mathewson f8382d4978 n_key_set: Wrap "where" clauses in square brackets too.
Otherwise, there is a parsing ambiguity. :(
2022-10-04 16:05:40 -04:00
Nick Mathewson 8475d3ab39 n_key_set: Rename generic parameters on functions.
Previously we used `<T>` in a bunch of places.  But that fails
if you try to declare `T` as a parameter on the structure itself.
2022-10-04 16:05:40 -04:00
Nick Mathewson bf7c0bb2ba n_key_set: Add a try_insert().
I am finding as I use this that I want a variant that can't panic.
2022-10-04 16:05:40 -04:00
Nick Mathewson 7402578af4 Merge branch 'multi_keyed_set' into 'main'
Include a HashSet variant that can be keyed on multiple keys.

See merge request tpo/core/arti!747
2022-10-03 18:16:10 +00:00
Nick Mathewson 1329f2c8f3 n_key_set: fix doctest compilation. 2022-10-03 13:31:03 -04:00
Nick Mathewson 8ab2a88923 n_key_set: Update generic syntax
Doing this lets us work with defaults and const generics.
2022-10-03 13:31:01 -04:00
Nick Mathewson 857272bc7a n_key_set: rename map elements.
This prevents an explosion if somebody has a key called "values".
2022-10-03 13:31:01 -04:00
Nick Mathewson 9c08fdb865 n_key_set: Add support for generic lifetimes.
It doesn't work for const generics yet, since they can't be repeated
in quite the same way.
2022-10-03 13:31:01 -04:00
Nick Mathewson 48a15d5627 Tweaks and improvements in documentation.
Most of these were suggested by Ian
2022-10-03 13:31:01 -04:00
Nick Mathewson 4724639d7c Require slab 0.4.4
The `try_remove()` method, which we need, was introduced there.
2022-10-03 13:31:01 -04:00
Nick Mathewson 59f1f7c11d Repair rustdoc.
The previous indentation was making it think that we had rust code
where none existed.
2022-10-03 13:31:01 -04:00
Nick Mathewson 9fd072a4d4 n_key_set: Add a function to check invariant violations
Also, document another invariant.
2022-10-03 13:31:01 -04:00
Nick Mathewson 0dc1573268 n_key_set: Use remove_by_foo to implement insert. 2022-10-03 13:31:01 -04:00
Nick Mathewson e06ae79009 n_key_set: Panic on more invariant and constraint violations. 2022-10-03 13:31:01 -04:00
Nick Mathewson 43fd594819 n_key_set: Remove by_$key_mut.
This can't be used in a consistency-preserving way.
2022-10-03 13:31:01 -04:00
Nick Mathewson 7043df0241 n_key_set: Add flags to keys rather than inferring from Option<T>
Using Option<T> as an alias for T was too clever indeed, and it
meant that our HashMaps were declared with the wrong types.

Putting flags here instead gives us an extension point that we can
use in the future.
2022-10-03 13:31:01 -04:00
Nick Mathewson f0d74db38e n_key_set: Use to_owned to permit &str accessors. 2022-10-03 13:31:01 -04:00
Nick Mathewson 47c9ae0e4b n_key_set: Add some tests, and notes on infelicities. 2022-10-03 13:31:01 -04:00
Nick Mathewson 4e3a390c5b n_key_set: Fix a bug in function access. 2022-10-03 13:31:01 -04:00
Nick Mathewson 0321912ad0 n_key_set: add FromIterator. 2022-10-03 13:30:54 -04:00
Nick Mathewson c2d4b4ed3b Include a HashSet variant that can be keyed on multiple keys.
Every element in the set has up to N keys, each of which may have differnt
types.  No value for any key may correspond to more than one element in
the set.

These properties can be provided, via a macro, for values of N between 1
and $BIG_ENOUGH.

We'll use this to implement a type that holds HasRelayIds.
2022-10-03 13:30:37 -04:00
Nick Mathewson f5389b53e9 Bump crates that have had no API changes. 2022-10-03 09:47:09 -04:00
trinity-1686a 8e7a904260 fix clippy::needless_borrow 2022-09-10 14:39:47 +02:00
Nick Mathewson a5f704f443 Remove semver.md from arti-1.0.0 2022-09-07 09:17:00 -04:00
Nick Mathewson 96875ea208 Bump crate versions in preparation for Arti 1.0.0 release.
Because we want to work more on ensuring that our semver stability
story is solid, we are _not_ bumping arti-client to 1.0.0 right now.

Here are the bumps we _are_ doing.  Crates with "minor" bumps have
had API breaks; crates with "patch" bumps have had new APIs added.

Note that `tor-congestion` is not bumped here: it's a new crate, and
hasn't been published before.

```
tor-basic-utils         minor
fs-mistrust             minor
tor-config              minor
tor-rtcompat            minor
tor-rtmock              minor
tor-llcrypto            patch
tor-bytes               patch
tor-linkspec            minor
tor-cell                minor
tor-proto               minor
tor-netdoc              patch
tor-netdir              minor
tor-persist             patch
tor-chanmgr             minor
tor-guardmgr            minor
tor-circmgr             minor
tor-dirmgr              minor
arti-client             minor
arti-hyper              minor
arti                    major
arti-bench              minor
arti-testing            minor
```
2022-09-01 08:59:49 -04:00
Ian Jackson 2fa75be660 tor-basic-utils: Provide IoErrorExt is_not_a_directory()
We're going to want this functionality, which isn't in the stable
stdlib.
2022-08-25 15:58:29 +01:00
trinity-1686a 7f939fa480 enable doc_auto_cfg feature on every crate when documenting for docs.rs 2022-08-24 18:22:41 +02:00
Nick Mathewson 859ae4acd0 Bump patch versions on crates that have new APIs.
Do _not_ bump the dependency versions on crates that have had no
changes since arti 0.0.5, since those crates do not depend on the
new APIs.

```
cargo set-version -p tor-basic-utils   --bump patch
cargo set-version -p tor-llcrypto      --bump patch
git restore crates/tor-checkable
git restore crates/tor-consdiff
git restore crates/tor-rtmock
```
2022-08-01 09:56:29 -04:00
Ian Jackson 44402f722e tor-basic-utils: Add a test for DropNotifyWatchSender 2022-07-19 19:04:34 +01:00
Ian Jackson c7933de0ab tor-basic-utils: Add ref to upstream issue re drop 2022-07-19 19:00:23 +01:00
Ian Jackson bd41e29f33 tor-basic-utils: Add comment about lack of race
In answer to
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/632#note_2822107

I think this is subtle enough that it deserves a comment.
2022-07-19 17:21:22 +01:00
Ian Jackson bc498bc7a0 arti-client: Provide DropNotifyWatchSender
There are going to be some tasks (well, right away, one task) which
will want to go away when the sender is dropped.

The docs in postage are silent, but postage::Sender does not
have a Drop impl so I don't think we can rely on the Receivers getting
None from their Stream impl.

So we're going to have the watch send Options, which are None only
when the sender is dropped.
2022-07-18 18:13:13 +01:00
Ian Jackson 7acdd21750 Provide maybe_send on postage::Sender, via extension trait
We need to replace the AtomicBool for dormant mode with something that
can wake up tasks.  postage::watch is the right shape.

But we want to be able to update it but suppress no-op updates.
(There is going to be a call site where no-op updates can occur.)

In the absence of a suitable upstream method as requested here
  https://github.com/austinjones/postage-rs/issues/56
we introduce this facility via an extension trait.
2022-07-18 18:13:13 +01:00
Ian Jackson 44f37b2d07 Merge branch 'cirmgr_error_cleanup' into 'main'
Clean-ups in circmgr errors

See merge request tpo/core/arti!625
2022-07-15 15:58:44 +00:00
Nick Mathewson ad87cdcf27 tor-basic-utils: Add a new interface to FilterCount
This interface allows using FilterCount with functions that expect
predicates rather than iterator chains.

I'm about to use it to get meaningful FilterCount results in the
path-selection code in circmgr.
2022-07-12 11:35:41 -04:00
Ian Jackson 1fc86e3ea9 Fix two rustdoc links
This type must have been renamed, I guess.
2022-07-12 15:14:47 +01:00
Nick Mathewson 51a59e8c8b Add a semver note to FilterCount 2022-07-08 09:29:09 -04:00
Nick Mathewson fecc57fbef FilterCount: Add a simple Display helper.
This is a helper rather than a Display implementation because it
isn't the only logical way to display these values.  (In fact,
without context, it isn't even the _most_ logical way)
2022-07-06 15:39:30 -04:00
Nick Mathewson b6e0eea2b0 New "counting filter" iterator helper in tor-basic-utils.
This is going to make it simpler to write the code in guardmgr (and
later in circmgr) that keeps track of how many relays were rejected
for what reason.  The latter, in turn, should improve error messages
when we're unable to pick a guard or a path.
2022-07-06 15:39:14 -04:00
Nick Mathewson 20435aea75 Bump crate and dependency versions.
These were done with the following commands:

```
cargo set-version -p tor-basic-utils   --bump patch
cargo set-version -p fs-mistrust       --bump minor
cargo set-version -p tor-error         --bump patch
cargo set-version -p tor-config        --bump patch
cargo set-version -p tor-units         --bump patch
cargo set-version -p tor-rtcompat      --bump minor
cargo set-version -p tor-llcrypto      --bump patch
cargo set-version -p tor-bytes         --bump minor
cargo set-version -p tor-socksproto    --bump minor
cargo set-version -p tor-cert          --bump minor
cargo set-version -p tor-cell          --bump minor
cargo set-version -p tor-proto         --bump minor
cargo set-version -p tor-netdoc        --bump patch
cargo set-version -p tor-netdir        --bump minor
cargo set-version -p tor-persist       --bump patch
cargo set-version -p tor-chanmgr       --bump minor
cargo set-version -p tor-guardmgr      --bump minor
cargo set-version -p tor-circmgr       --bump patch
cargo set-version -p tor-dirclient     --bump patch
cargo set-version -p tor-dirmgr        --bump minor
cargo set-version -p arti-client       --bump patch
cargo set-version -p arti              --bump minor
cargo set-version -p arti-bench        --bump minor
cargo set-version -p arti-testing      --bump minor
```
2022-06-24 12:00:22 -04:00
Ian Jackson 23c352b96b clippy: Consolidate many lints in maint/add_warning
Found these by disabling the nightly dbg macro special case.  Now, we
have a mechanism for globally adding suppressions to tests, we can use
that instead.
2022-06-24 14:23:38 +01:00
Ian Jackson 589c6e52bb Run maint/add_warning crates/*/src/{lib,main}.rs
Update all lint blocks
2022-06-23 19:15:42 +01:00
Nick Mathewson 47a8c05ff3 Fix a rustdoc link. 2022-06-07 19:19:53 -04:00
Nick Mathewson 5854e4bbd9 Merge branch 'use-testing-rng' 2022-06-07 19:02:12 -04:00
Nick Mathewson 018fda4f73 Merge branch 'testing-rng' into 'main'
New facility for deterministic and reproducible test PRNGs.

See merge request tpo/core/arti!561
2022-06-02 21:11:36 +00:00
Nick Mathewson 967ea67b7d Use testing_rng() in tests throughout our crates.
This only affects uses of thread_rng(), and affects them all more or
less indiscriminately.  One test does not work with
ARTI_TEST_PRNG=deterministic; the next commit will fix it.
2022-06-02 14:56:42 -04:00
Nick Mathewson 69d352a7c7 New facility for deterministic and reproducible test PRNGs.
The new `testing_rng()` function is meant as a replacement for
thread_rng() for use in unit tests.  By default, it uses a randomly
seeded RNG, but prints the seed before the test so that you can
reproduce any failures that occur.  You can override this via the
environment to use a previous seed, or by using a deterministic
seed for all your tests.

Backend for #486.
2022-06-02 14:51:51 -04:00
Ian Jackson 4f42101554 lints: Add let_unit_value allow to all crates
From running add_warning, with manual picking of the right
hunks/lines.
2022-05-31 15:23:52 +01:00
Ian Jackson ba0843da4a lints: Add lint block delimiters to every crate
This was the result of:
  maint/add_warning crates/*/src/{lib,main}.rs
and then manually curating the results.
2022-05-31 13:00:31 +01:00
Orhun Parmaksız bfd41ddb5f
Lexically sort Cargo.toml dependencies
Utilize cargo-sort: https://github.com/DevinR528/cargo-sort

Signed-off-by: Orhun Parmaksız <orhunparmaksiz@gmail.com>
2022-05-28 20:05:51 +03:00
Nick Mathewson b232365a75 Semantic version changes for Arti 0.4.0 release
I followed the following procedure to make these changes:

* I used maint/changed_crates to find out which crates had changed
  since 0.3.0.
* I used grep and maint/list_crates to sort those crates in
  topological (dependency) order.
* I looked through semver_status to find which crates were listed as
  having semver-relevant changes (new APIs and breaking changes).
* I scanned through the git logs of the crates with no
  semver-relevant changes listed to confirm that, indeed, they had
  no changes.  For those crates, I incremented their patch-level
  version _without_ changing the version that other crates depend on.
* I scanned through the git logs of the crates with no
  semver-relevant changes listed to confirm that, indeed, they had
  no obvious breaking changes.
* I treated all crates that depend on `arti` and/or `arti-client` as
  having breaking changes.
* I identified crates that depend on crates that have changed, even
  if they have not changed themselves, and identified them as having
  a non-breaking change.
* For all of the crates, I used `cargo set-version -p $CRATE --bump
  $STATUS` (where `STATUS` is `patch` or `minor`) to update the
  versions, and the depended-upon versions.
2022-05-27 09:01:20 -04:00
Nick Mathewson 3b837eb7f4 Typo fixes (automated with "typos"). 2022-05-24 19:21:12 -04:00
Nick Mathewson 2f1803f4c6 Suppress clippy warnings in tor-basic-utils.
These are warnings that we've decided it's okay to suppress elsewhere.
2022-05-23 12:55:37 -04:00
Ian Jackson 86d5768c05 prepare_send_from: clippy: Have dprintln explicitly return () 2022-05-23 11:28:05 +01:00
Ian Jackson d3f261d5ef prepare_send_from: clippy: Avoid a lint
I think this is worse code, but it's not *significantly* worse.
2022-05-23 11:28:05 +01:00
Ian Jackson 24dde5ddf1 prepare_send_from: clippy: Add missing docs
I intend to reintroduce this in its own MR.
2022-05-23 11:28:05 +01:00
Ian Jackson 739e5b52b1 prepare_send_from: clippy: Replace two unwraps 2022-05-23 11:28:05 +01:00
Ian Jackson 94038a9227 prepare_send_from: Break out get_output! macro
So we can change unwrap to expect, which makes this too long to repeat.
2022-05-23 11:28:05 +01:00
Ian Jackson 9fd0050acf prepare_send_from: docs and comments improvements
Apropos review.
2022-05-23 11:28:05 +01:00
Ian Jackson 426ff28b73 prepare_send_from: Add tests
When I added these tests, they didn't find any bugs in my own
implementation, but I did find a bug in futures::future::unfold.
See the in-code comment.
2022-05-23 11:28:05 +01:00
Ian Jackson 793782acc8 channel: Provide and use Sink::prepare_send_from
This is a general-purpose implementation of the ad-hoc approach
currently taken in (eg) crates/tor-proto/src/channel/reactor.rs,
with an API intended to defned against the more obvious mistakes.

This allows us to separate the two concerns: the channel reactor can
focus on handling channel cells and control messages and is over 2.5x
shorter.

The complexity of the manual sink implementation, and the machinery
needed to avoid having to suspend while holding an item, are dealt
with separately.  That separate implemenation now has proper
documentation.  (Tests are in the nest commit to avoid this one being
even more unwieldy.)

We use `extend` to define this as an extension trait.  A competitor is
`ext` but in my personal projects I have found `extend` slightly
better.
2022-05-23 11:28:05 +01:00
Nick Mathewson 7b93091f57 Bump the version of every* crate to 0.3.0
* Except for safelog and fs-mistrust, which are new.
2022-05-06 10:03:15 -04:00
Nick Mathewson c1ea419477 Merge branch 'main' into 'msrv_1_56'
# Conflicts:
#   crates/tor-config/Cargo.toml
#   crates/tor-dirmgr/src/state.rs
#   doc/semver_status.md
2022-04-26 12:45:16 +00:00
Ian Jackson 8664766270 Rename macro_first_nonempty (from macro_coalesce_args)
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/471#note_2798026
2022-04-25 18:15:25 +01:00
Nick Mathewson b60b0a266a Bump every crate's edition to 2021.
This is an automated change made with a perl one-liner and verified
with grep -L and grep -l.

Some warnings are introduced with this change; they will be removed
in subsequent commits.

See arti#208 for older discussion on this issue.
2022-04-25 13:05:31 -04:00
Nick Mathewson ca05b0904c Add 'rust-version = "1.56"' to every Cargo.toml file.
This change was made automatically with a perl one-liner, and
confirmed with `grep -L`.

The `rust-version` field itself was introduced in 1.56.0.
2022-04-25 13:04:31 -04:00
Ian Jackson d98d7a60bd macro_coalesce_args: New helper macro 2022-04-25 17:04:05 +01:00
Samanta Navarro d3b1a93474 tor-basic-utils: Add RetryDelay::reset test 2022-04-23 12:04:15 +00:00
Nick Mathewson 57608f9609 Add RetrySchedule::reset()
Previously the code would do stuff like

```
    schedule = RetrySchedule::new(INITIAL_DELAY);
```

which is needlessly verbose, since the schedule already keeps track
of its initial delay.
2022-04-04 12:32:18 -04:00
Nick Mathewson 5b2fc118df Bump all arti*, tor* crates to 0.2.0
Not all of these strictly need to be bumped to 0.2.0; many could go
to 0.1.1 instead.  But since everything at the tor-rtcompat and
higher layers has had breaking API changes, it seems not so useful
to distinguish.  (It seems unlikely that anybody at this stage is
depending on e.g. tor-protover but not arti-client.)
2022-04-01 09:15:18 -04:00
Nick Mathewson 6d7dcdc621 Update README.md files using readmes script 2022-03-29 13:30:17 -04:00
Ian Jackson 9de0c024bf Adjust a comment
Noticed this while reviewing !426
2022-03-21 17:44:50 +00:00
Ian Jackson 82aa4b902a Provide define_accessor_trait and use it to generate CircMgrConfig 2022-03-16 19:31:05 +00:00
Nick Mathewson 09f750c2c8 RetryDelay: remove accessors.
Instead, check initial_delay in dirmgr directly.
2022-03-16 10:50:13 -04:00
Nick Mathewson 90c48dc1b0 Fix up documentation on RetryDelay.
It's no longer about downloads; it's about whatever you need to
retry.
2022-03-16 08:42:46 -04:00
Nick Mathewson 67645473d5 Move RetryDelay from dirmgr to basic-utils.
This (almost) a pure code-movement commit: it also makes one public
function private in order to suppress a warning.
2022-03-16 08:31:54 -04:00
Nick Mathewson e8c63fe3e8 tor-basic-utils/Cargo.toml: reformat.
This is a separate commit to avoid putting format changes in the
next commit.
2022-03-16 08:21:44 -04:00
Ian Jackson 8f5d089f53 Revert "humantime_serde_option: New module in tor-basic-utils"
We have upstreamed this code.

This reverts commit 6193c9d974.
2022-03-14 10:33:59 +00:00
Ian Jackson 6193c9d974 humantime_serde_option: New module in tor-basic-utils
This will be used to allow our config *builder* structs to be
Deserialize.
2022-03-07 12:38:30 +00:00
Ian Jackson 0cfb6a0e0f tor-basic-utils: copy the README into lib.rs
The doc include rune does not work with our MSRV; it needs 1.54.

The alternative would be some kind of cfg() but that would
  - not provide the crate-level doc on Rust 1.53
  - involve the use of cfg_attr

Instead, just do it the old way.
2022-03-04 16:54:54 +00:00
Ian Jackson 6e1da0145b Remove now-obsolete note about location of skip_fmt
Now the diff from the merge base does not contain any hits for ^\+.*bytes
2022-03-04 11:45:24 +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 aba68088d1 Introduce tor-basic-utils
Empty crate right now
2022-03-04 11:45:24 +00:00