Commit Graph

547 Commits

Author SHA1 Message Date
Nick Mathewson 8cbc740d90 dirmgr: Add an instance of BadUtf8InCache 2022-07-14 09:32:01 -04:00
Nick Mathewson d1e9d4ce84 dirmgr: Clarify disk IO errors. 2022-07-14 09:27:29 -04:00
Nick Mathewson c1101f13f3 dirmgr: style edits to error messages. 2022-07-14 08:40:42 -04:00
feelingnothing 171dd5eb63 Fix illegal formatting in cache filenames 2022-07-14 15:27:52 +03:00
Nick Mathewson 1dda69af2b Remove semver.md files now that 0.5.0 is out 2022-06-24 13:31:38 -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 4831f9d38c Merge branch 'clippy' into 'main'
Fix clippy nightly again

See merge request tpo/core/arti!603
2022-06-24 14:13:58 +00:00
Nick Mathewson 1f8f24dbcb Merge branch 'dirmgr' into 'main'
dirmgr: followups to !587, mostly using iterators

Closes #468

See merge request tpo/core/arti!599
2022-06-24 13:46:52 +00:00
Nick Mathewson ea3160737c Fix a couple of typos in rustdoc comments. 2022-06-24 08:18:15 -04: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
Ian Jackson 6c110a232c dirmgr: Use ... .find().is_none() rather than clippy's suggestion 2022-06-23 18:42:33 +01:00
Ian Jackson d2bd71c5f0 dirmgr: DirBootstrapStatus: Refactor mut_status_for using entries_mut
IMO this is rather less confusing.
2022-06-22 10:53:02 +01:00
Ian Jackson d36c433b36 dirmgr: Use new statuses() helper method
The two call sites become clearer, IMO.
2022-06-22 10:53:02 +01:00
Ian Jackson 24d43f83fd dirmgr: DirBootstrapStatus: Provide statuses and entries_mut
We're going to use these in a moment.

One returns entries and the other statuses simply because that's
what's actually going to be wanted.
2022-06-22 10:53:02 +01:00
Ian Jackson 5c51d03efb dirmgr: Remove a TODO comment
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/587#note_2815945
2022-06-22 10:53:02 +01:00
eta 4e3537746f Merge branch 'display_source_cleanup' into 'main'
Do not include error source() in display() format.

See merge request tpo/core/arti!598
2022-06-21 19:34:27 +00:00
Ian Jackson 9b4ba4893e Merge branch 'stalled_directory' into 'main'
Detect and report stalled directory downloads

Closes #468

See merge request tpo/core/arti!587
2022-06-21 19:13:40 +00:00
Nick Mathewson 08d9bbf33b Do not include error source() in display() format.
According to doc/Errors.md, and in keeping with current best
practices, we should not include display an error's `source()` as
part of that error's display method.  Instead, we should let the
caller decide to call source() and display that error in turn.

Part of #323.
2022-06-21 14:14:14 -04:00
Nick Mathewson 9b7849a293 Refactor DirStatus data structures.
AttemptId is now linked to DirStatus in StatusEntry.

DirBootstrapStatus now has an inner enum to make invalid status
unrepresentable.
2022-06-21 10:26:53 -04:00
Nick Mathewson 5509bd0269 Merge branch 'config-fix2' into 'main'
Use impl_standard_builder more and remove manual Default/builder impls

See merge request tpo/core/arti!594
2022-06-16 20:30:34 +00:00
Ian Jackson db51bdcbc1 Merge branch 'config-fix' into 'main'
Config handling and logging fixes

Closes #480

See merge request tpo/core/arti!589
2022-06-16 15:46:18 +00:00
Ian Jackson 2ca2c03059 impl_standard_builder: Use for tor_dirmgr::Authority 2022-06-16 15:42:06 +01:00
Ian Jackson 17caebd284 impl_standard_builder: Use for tor_dirmgr::DownloadSchedule 2022-06-16 15:42:06 +01:00
Ian Jackson 8b724d40f8 impl_standard_builder: Use for tor_dirmgr::DownloadScheduleConfig 2022-06-16 15:27:00 +01:00
Ian Jackson 2ab5c0861e impl_standard_builder: Use for tor_dirmgr::NetworkConfig 2022-06-16 15:27:00 +01:00
Ian Jackson e32210a398 impl_standard_builder: Use for tor_dirmgr::DirSkewTolerance 2022-06-16 15:27:00 +01:00
Nick Mathewson 0223c91b26 Merge branch 'high-level-features' into 'main'
Add "full" and "experimental" features to arti, arti-client, and below.

Closes #499

See merge request tpo/core/arti!584
2022-06-16 12:24:47 +00:00
Ian Jackson 4c65e9994d Add some missing `serde(default)` to uses of humantime_serde::option
Without this, if the substructure is provided, these fields are
mandatory within it.
2022-06-16 11:08:16 +01:00
Nick Mathewson 647d4410bb Fix clippy::significant_drop_in_scrutinee warnings
This is apparently a new warning from clippy nightly, documented in
https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_in_scrutinee .

I'm not in love with the temporary variables that this warning wants
me to introduce, but it does seem like a decent way to avoid some
kinds of deadlock.
2022-06-15 11:52:30 -04:00
Nick Mathewson 425af9db91 Work around an erroneous warning from nightly clippy 2022-06-15 11:52:30 -04:00
Nick Mathewson 331578d19c Make display formats work with older derive_more. 2022-06-14 14:10:18 -04:00
Nick Mathewson c74c268c8b tor-dirmgr: Make DirStatus non-public.
I believe this type was made public in error: No other crate uses it,
and no API exposes it.
2022-06-14 11:02:29 -04:00
Nick Mathewson e3dced360b Add a blockage-reporting mechanism to tor-dirmgr.
The `DirBootstrapStatus` type now exposes a blockage() method to
return an `Option<DirBlockage>`.

The blockage types reported are more low-level than I'd like, but
they are IMO good enough for now: we'll want to get experience with
actual vs hypothetical problems before we refine them.
2022-06-14 10:42:18 -04:00
Nick Mathewson 25bbdd5f25 Add a couple of TODO items. 2022-06-14 10:05:27 -04:00
Nick Mathewson 660b3104a9 Do not update_progress on load if nothing happened.
If there was no partial information, then calling update_progress
will now report a stall in this case, which is not what we want.
2022-06-14 09:58:58 -04:00
Nick Mathewson 13c152d2ac DirMgr: Track errors, stalls, and resets as part of status.
A "reset" happens whenever we have to start a download attempt over
-- either because we ran out of retries, or we found something wrong
with the consensus after fetching certificates.

An "error" happens when we have a recoverable error from one or more
directory sources.

A "stall" happens whenever a round of downloads or cache loads leads
to no change in the status.

We don't yet use this as part of our status reporting.
2022-06-13 13:58:31 -04:00
Nick Mathewson 2a2afaa7c2 Refactor our logic for distinguishing download attempts
Previously we used the "if-modified-since" time associated with the
consensus download, and/or the "valid-after" time in the consensus
attempt, to put multiple attempts into sequence, and to tell one
from another.  But that approach was always a kludge, and will soon
get more unreliable as the DirStatus logic gets a bit more complex.

With this commit, we change separate download attempts to be
identified with an AttemptId that increments whenever we decide to
get a different directory from the one we have.  IMO this new code
is _much_ cleaner.
2022-06-13 13:21:09 -04:00
Nick Mathewson 68ea880b84 Refactor most DirStatus users to use DirProgress.
This is all crate-internal APIs, fortunately.
2022-06-13 12:22:04 -04:00
Nick Mathewson 238f2b5637 Move `at_least_as_new_as` to DirProgress. 2022-06-13 12:02:30 -04:00
Nick Mathewson 6c9d30681f Turn the DirProgress in DirStatus into a named field. 2022-06-13 10:53:46 -04:00
Nick Mathewson f581feb0ac Rename DirStatusInner to DirProgress.
This is about to become only a _part_ of what defines a DirStatus: a
DirStatus will also include a reset count, and some kind of info
about how long we've gone without progress.
2022-06-13 10:49:09 -04:00
Nick Mathewson d44dd6f44f Merge branch 'dormant_directory' into 'main'
Use TaskSchedule to sleep in directory bootstrapping

Closes #497

See merge request tpo/core/arti!571
2022-06-13 13:59:26 +00:00
Nick Mathewson 2129aee6cd DirMgr: Use scopeguard crate in place of ad hoc RAII substitutes 2022-06-13 08:28:41 -04:00
Nick Mathewson a7b406e69f Put the task schedule back when the dl task exits.
This will allow somebody else to call bootstrap() if bootstrap() fails
the first time.
2022-06-13 08:28:41 -04:00
Nick Mathewson 430f4ffb86 New API to expose and use TaskHandle from DirMgr.
This change also means that we need to create the handle and scheduler
earlier in the process of creating the DirMgr.  If we don't, we won't
have a way to manage the task before bootstrap() returns.
2022-06-13 08:28:41 -04:00
Nick Mathewson 8a586a40fa Add "full" and "experimental" features to arti-client and below.
The "full" feature is a catch-all for all features, _except_:

   * Those that select a particular implementation (like
     tor-llcrypto/with-openssl) or build flag (like "static")
   * Those that are experimental or unstable (like "experimental-api")
   * Those that are testing-only.
2022-06-10 15:32:21 -04:00
Nick Mathewson 171b406b00 DirMgr: Refactor bootstrap to use a TaskSchedule for sleeping.
This change (not yet exposed as an API) will let the TorClient have
a `TaskHandle` corresponding to the directory task, letting it
make the directory task dormant as needed.
2022-06-10 13:59:30 -04:00
Nick Mathewson 5854e4bbd9 Merge branch 'use-testing-rng' 2022-06-07 19:02:12 -04:00
Nick Mathewson 7f785b66c2 Upgrade float_eq dev-dependency to 1.0.0 2022-06-07 08:03:55 -04: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
Ian Jackson 98ccd7e7e2 Merge branch 'lint' into 'main'
lints: Make lint blocks consistent and ensure they stay that way

Closes #469

See merge request tpo/core/arti!557
2022-05-31 18:27:53 +00: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
Ian Jackson 017906cdc7 tor-dirmgr: Fix DirSkewTolerance
This was upposed to be one day, I presume!

Also complete a truncated sentence in the docs.
2022-05-30 16:00:45 +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 4326aa1de9 Regenerate version bump from previous commit.
This commit was made by reverting the previous commit, then
re-running the script I used to generate it.  In theory there should
be no semantic changes: only changes due to improved formatting from
cargo edit.
2022-05-27 10:18:52 -04: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 0caa5bcba5 DirMgr:: Remove Error::NoChange as redundant.
Now that the relevant functions now report changed/not-changed
status via a boolean out-parameter (see !527), there's no reason to
have a separate NoChanged error case.

Closes #484.
2022-05-25 08:58:37 -04:00
eta 608d0cbcc2 Merge branch 'bug482' into 'main'
DirMgr: Stop load-from-cache process when there is no change.

Closes #482

See merge request tpo/core/arti!527
2022-05-24 19:33:42 +00:00
Nick Mathewson 95200383b5 fs-mistrust: make Mistrust have a corresponding Builder type.
This is an approximately minimal revision to get Builder in place;
subsequent commits will clean up the API.
2022-05-24 10:54:02 -04:00
Nick Mathewson 8e15c97f56 DirMgr: Stop load-from-cache process when there is no change.
Previously in !511 I had introduced a bug where, if there was an
error more serious than "no change", that error would keep us from
noticing that we had no change, and we'd loop until the safety
counter ran out.  Then we'd panic.

This commit fixes the bug by reintroducing the `changed` boolean --
this time as an outparam for the add_from_* methods.

Fixes #482.
2022-05-24 08:50:20 -04:00
Nick Mathewson 5b5b4bbbea Simplify advance and reset functions with mem::replace. 2022-05-19 08:09:05 -04:00
Nick Mathewson eab0046d0e Explain why we call update_status unconditionally. 2022-05-19 08:04:57 -04:00
Nick Mathewson 6aebb18e64 Remove BootstrapAction::Impossible
It does nothing that Fatal does not.  Suggested by @eta in review.
2022-05-19 08:00:41 -04:00
Nick Mathewson c70916c0d9 Fix compilation with Rust 1.56. 2022-05-17 14:58:36 -04:00
Nick Mathewson 5de1b93195 DirMgr: Remove blocking_error return path. 2022-05-17 12:25:32 -04:00
Nick Mathewson 53ed5f40cf DirMgr: Unify error return paths
We no longer have separate return paths for recoverable and fatal
errors; instead, they are merged, and distinguished based on
recovery actions.

Since it is now possible for download() to give an error that should
_not_ destroy the previous state, it takes `&mut Box<dyn DirState>`.
This change unfortunately means that we can no longer call `state =
state.advance()`, but instead have to do some mem::swap junk with
poisoned values.  Any better solution would be a good thing.

Additionally, the reset() and advance() methods can no longer fail.

There is still a separate return path for reset-triggering errors;
I'm about to fix that.
2022-05-17 12:25:32 -04:00
Nick Mathewson d7a3fd2c17 DirMgr: Remove special handling of "changed" boolean 2022-05-17 10:16:15 -04:00
Nick Mathewson 6bacf3b303 DirMgr: Start refactoring error handling.
This commit adds a couple of new error types that we will soon want
to distinguish, and a new way of classifying errors.  These are not
yet all used.
2022-05-17 09:52:44 -04:00
Nick Mathewson e37e37a31c Give an error if the cache violates If-Modified-Since.
This should be sufficient to detect several kinds of nefariousness
that we'd previously overlooked.
2022-05-16 12:49:49 -04:00
Nick Mathewson 37f6730077 Add missing extend_tolerance to add_consensus_text.
This should have gone in when we fixed #412
2022-05-16 12:49:49 -04:00
Nick Mathewson ffc864015a DirMgr: Blame the correct cache for consensus validation failure 2022-05-16 12:49:49 -04:00
Nick Mathewson c55738e745 Move consensus signature verification to add-document code.
Previously, we did this in `advance()`, but that wasn't so great: it
meant that we could fail in the advance() code, whereas the calls to
`advance()` treated errors as fatal.

This treats failed verification as a blocking error that requires a
reset.

Fixes one aspect of #439.
2022-05-16 12:49:49 -04:00
Nick Mathewson d1af40e638 On a blocking error, blame the appropriate directory cache
Fortunately, the only error type that we need to handle blocking
errors with actually has a DirSource in it already.
2022-05-16 12:49:49 -04:00
Nick Mathewson 40539cb25e DirMgr: Add a way for a state to report a blocking error.
(A blocking error is one that means that the current bootstrap
attempt has failed, and must be restarted.)
2022-05-16 12:42:25 -04:00
Nick Mathewson b94f56d6f5 Implement nonfatal errors in add_from_* 2022-05-16 12:42:25 -04:00
Nick Mathewson d8bd862f2b DirMgr: Let add_from_* distinguish non-fatal errors
Previously all errors were treated as non-fatal.

The add_from_* implementations don't yet behave properly;
I'll fix them in subsequent commits.
2022-05-16 12:42:25 -04:00
Nick Mathewson f70ad60e65 DirMgr: Improve display for DocSource
(Also, implement Display for tor_dirclient::SourceInfo).
2022-05-16 12:42:25 -04:00
Nick Mathewson ef2640acfa DirMgr: make DocSource useful by having it include dirserver info.
Previously DocSource would tell you whether the document was from
a local store or a cache server, but it wouldn't tell you _which_
server it came from.

This change required adding DocSource as an argument to
DirState::add_from_download.
2022-05-16 12:42:25 -04:00
Nick Mathewson fb432924a3 Merge branch 'main' into 'ticket_466'
# Conflicts:
#   doc/semver_status.md
2022-05-16 15:10:00 +00:00
Nick Mathewson f0eac61838 Merge branch 'network-config-error' into 'main'
Delete tor_dirmgr::Error::BadNetworkConfig

See merge request tpo/core/arti!506
2022-05-12 16:43:26 +00:00
Ian Jackson d847d49858 Delete tor_dirmgr::Error::BadNetworkConfig
This was anomalous, in that it contains &'static str, rather than a
proper nested error (eg a config::ConfigError, maybe).

But in fact it tursn out it is now not constructed.  The last
construction site was removed a long time ago in
  Use derive_builder for Authority and FallbackDir.
2022-05-12 16:49:06 +01:00
Nick Mathewson 24c7dea38d Resolve DOCDOC comments in tor-dirmgr. 2022-05-12 09:45:05 -04:00
Nick Mathewson 2e99c9fe64 dirmgr: use set_skew_limit.
With this API we can now stop consensus download attempts early if
any consensus that the directory cache gave us would be necessarily
too far in the future or in the past.

This saves wasted bandwidth for clients with skewed clocks.

Closes #466.
2022-05-11 13:52:07 -04:00
Nick Mathewson 9e040e7809 Adjust if-modified-since field on the basis of tolerated skew
If we're happy with a directory from 3 days ago, we should say
"if-modified-since 3 days ago".

This patch is larger than I'd like, since I had to add &DirMgrConfig
as an argument to the functions that make a  consensus request.

Closes #467.
2022-05-11 12:36:51 -04:00
Nick Mathewson db8bdbf924 tor-dirmgr: update status reporting to consider skew tolerance
In our status reporting code, we consider an
expired-but-still-usable directory still bootstrapped, but not 100%
bootstrapped.
2022-05-11 12:11:30 -04:00
Nick Mathewson 1dafba706d Make reset_time() for incomplete directories more generous.
Since we want to be willing to use older consensuses, we don't
necessarily want to reset a download just because the consensus is
expired.

This new behavior isn't ideal either; I've added a TODO that relates
to #433.

Related of #412
2022-05-11 12:11:17 -04:00
Nick Mathewson 7dec007d63 Add DirSkewTolerance section to DirMgr configuration.
This new section describes how much variance we accept when it comes
to expired and not-yet-valid directory documents.  (Currently, the
only ones where this matters for are consensus documents and
authority certificates.)  A document that is invalid by no more than
these tolerances is not _live_, but it can still be used.

These tolerances serve two purposes:

 * First, they allow clients to run with a little more clock skew
   than they would tolerate otherwise.
 * Second, they allow clients to survive the situation where the
   authorities are unable to reach a consensus for a day or two.

Compare with Tor's REASONABLY_LIVE_TIME and NETWORKSTATUS_ALLOW_SKEW
constants; also compare with proposal 212.

Closes #412.
2022-05-11 12:11:17 -04:00
eta 33b2b428bd tor-dirmgr: move apply_netdir_changes() to be a DirMgr method 2022-05-10 13:29:39 +01:00
eta 27f4657ff1 tor-dirmgr: small fixups for the bootstrapping refactor
- Some FIXMEs got removed or amended.
- AddMicrodescs now yields a mutable reference, so we can use .drain()
  and reuse the allocation.
- Some panics were downgraded to debug_asserts.
2022-05-10 13:29:39 +01:00
eta 8347f8cb7e tor-dirmgr/bootstrap.rs: error on older netdirs, add log line
- We don't want to inadvertently replace our netdir with one that's
  actually older, so detect and error on this condition.
- Also, print a debug line when we get a new netdir without enough
  guards.
- (An unrelated TODO was also added.)
2022-05-10 13:29:39 +01:00
eta 2c28e217dd tor-dirmgr/state.rs: take an object to get a netdir, not a netdir
- Taking a previous netdir directly and keeping it around before we need
  it is a bit of a waste of memory, and also doesn't mesh well with how
  SharedMutArc works.
- To remedy this, introduce a new trait `PreviousNetDir` and have the
  state machines take that instead. (I was a bit tempted to just pass in
  the SharedMutArc directly. Maybe I should've done that.)
2022-05-10 13:29:39 +01:00
eta 27073a5d23 tor-dirmgr/state.rs: remove GetConsensusState::bodge_new
- (Also fixes up some dirfilter stuff, whoops.)
2022-05-10 11:50:07 +01:00
eta 7b5fad3130 tor-dirmgr/state.rs: remove WriteNetDir, use filters directly
- The only purpose of WriteNetDir was to provide a filter, which isn't
  necessary any more. Refactor to provide the filter directly.
2022-05-10 11:50:07 +01:00
eta 8b0166970e tor-dirmgr/state.rs: use the NetDirChange API instead of WriteNetDir
- GetMicrodescsState now uses the NetDirChange API to propagate netdir
  changes, instead of modifying the netdir directly.
- PendingNetDir was refactored in order to support this use case.
- As a result, the netdir-related methods in WriteNetDir can be removed,
  leaving only the DirFilter for now.
- add_from_cache() no longer takes a store, because nothing uses it.
- (bodge: apply_netdir_changes() was put in a few places missed
  previously)
2022-05-10 11:50:06 +01:00
eta 7a52e77e45 tor-dirmgr/state.rs: add new NetDirChange API, consume it
- The new DirState::get_netdir_change() API lets the state machine
  export a NetDirChange: a request to either replace the current netdir,
  or add microdescs to it.
- bootstrap.rs now consumes this new API, even though nothing implements
  it yet.
- This will let us implement GetMicrodescsState without having to
  directly mutate the netdir. The calling code also handles checking the
  netdir against the circmgr for sufficiency, and updating the consensus
  metadata in the store, meaning the revised GetMicrodescsState will not
  have to perform these tasks.
2022-05-10 11:48:57 +01:00
eta cad815e31d tor-dirmgr/state.rs: feed through additional parameters, use them
- The additional parameters passed to GetConsensusState are now passed
  through all the states, and used as well.
- WriteNetDir doesn't have a now() or config() method any more, since
  the states now get this from the runtime or the config parameters.
- This required modifying the tests to make a mocked runtime and custom
  config directly, instead of using DirRcv for this purpose.
- Additionally, because we don't have to upgrade a weak reference for
  DirState::dl_config(), that function no longer wraps its return value
  in Result.
- (A bunch of the FIXMEs from the previous commit that introduced the
  additional parameters have now been rectified as a result.)
2022-05-10 11:48:56 +01:00
eta a9bae9adfe tor-dirmgr/state.rs: refactor GetConsensusState::new
- GetConsensusState::new now takes a set of parameters matching what it
  actually needs, instead of just taking a writedir. (It still *does*
  take a writedir, and indeed still uses it for basically everything,
  but that will eventually go away.)
- Its call sites were updated.
  - Some tests now need to take a runtime, and got indented a lot as a
    result.
  - Resetting was made non-functional, because we need to thread through
    the parameters passed to GetConsensusState to all of the other
    states, too. This will happen in a later commit.
2022-05-10 11:42:50 +01:00
eta 62ece0ea21 tor-dirmgr: move DirState to state.rs
- Given that this is effectively an implementation detail, it doesn't
  really make sense to have it be in the crate root...
- (also, we're going to change it a bunch now)
2022-05-10 11:39:32 +01:00
eta 72ea9e3438 tor-dirmgr/bootstrap.rs: refactor fetch_single
- fetch_single now takes what it needs, instead of an Arc<DirMgr<R>>.
- This required refactoring the CANNED_RESPONSE mechanism, given the
  test would otherwise fail due to not having a CircMgr to pass to
  fetch_single.
2022-05-10 11:39:32 +01:00
eta 2fd03564b9 tor-dirmgr: make note_request_* functions standalone
- DirMgr::note_request_outcome and friends are now just standalone
  functions, taking a CircMgr.
2022-05-10 11:39:32 +01:00
eta 8b44569b5f tor-dirmgr/bootstrap.rs: refactor query_into_requests, make it used
- query_into_requests is now called make_requests_for_documents, and
  does the &[DocId] -> DocQuery conversion internally instead.
- DirMgr::make_consensus_request and DirMgr::query_into_requests are now
  gone. The tests use the new functions, as does fetch_multiple.
2022-05-10 11:39:32 +01:00
eta 4a98ed1301 tor-dirmgr: move query_into_requests into bootstrap.rs
- There's no good reason these functions needed to be part of the
  dirmgr, apart from needing a runtime and a store.
- However, we can just add those as arguments and copy them over. This
  commit does that.
2022-05-10 11:39:32 +01:00
eta 13446ac65a tor-dirmgr/bootstrap.rs: refactor load_all -> load_documents_from_store
- Function renamed & docs tidied up a bit
- Function signature now takes what it needs (immutable &dyn Store
  instead of mutex, slice instead of Vec) and nothing more
- DocQuery::load_documents_into was also renamed
  DocQuery::load_from_store_into and given similar treatment
2022-05-10 11:39:32 +01:00
eta 0dfac00842 tor-dirmgr/storage.rs: impl Store for Box<dyn Store>
Annoyingly, Rust doesn't automatically generate this sort of `impl` for
you, and I'd like to reduce the usage of Mutex<DynStore> everywhere else
in favour of either &dyn Store or &mut dyn Store.

(This is for two reasons: firstly, we might have a Store implementation
that doesn't use a mutex as above, or similar refactors; secondly,
passing the raw trait object reference lets us encode mutability into
the function signature, which I believe is quite valuable.)
2022-05-10 11:39:30 +01:00
eta d7f2718a8b tor-dirmgr/lib.rs: move DirMgr::load_documents_into to DocQuery
Move the function out of DirMgr, giving it a new &Mutex<DynStore>
argument instead.
2022-05-10 11:38:00 +01:00
Nick Mathewson 4262e9d0ec Merge branch 'use-fs-mistrust' 2022-05-09 15:27:25 -04:00
Nick Mathewson 20a85061b6 Update tor-dirmgr to use fs-mistrust. 2022-05-09 14:40:29 -04: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
Ian Jackson 030289481f Switch to derive_builder_arti_fork
For reference, the git source for this crate (and the others in its
workspace) currently lives in my personal github account (ijackson).
If this fork turns out to be long-lived and gains features and/or
users, it would be good to move it to a gitlab somewhere.

I have granted Nick crate ownership on the crates.io system.
2022-05-06 13:36:40 +01:00
Ian Jackson d47e94b459 config derive attrs: Make builders serde, and validated structs not
* Builders additionally derive: Debug, Serialize, Deserialize.

 * Validated structs no longer derive: Serialize, Deserialize
   and all related attributes deleted.

 * As a consequence, all the `#[serde(deny_unknown_fields)]`
   are gone.  That means that right now unknown fields are totally
   ignored.  This is good for compatibility but poor for useability.
   Doing something better here is arti#417, in progress.

 * As a consequence, delete tor_dirmgr::retry::default_parallelism.
   (The default value was already duplicated into a builder attr.)
2022-05-05 10:35:52 +01:00
Ian Jackson 4ad4cae418 FallbackDir: Use VecBuilder for orports
And drop the ad-hoc orport() method.  This brings FallbackDir's
orports field in line with our list builder API.

The general semver note in "configuation" seems to cover most of this.
2022-05-04 17:18:55 +01:00
Ian Jackson 9214eb5db2 tor-dirmgr: make DownloadScheduleBuilder public
This type was returned by the public DownloadSchedule::builder
function.  But the only thing that seems to have noticed that the type
name itself wasn't exported, was rustdoc.  Hmmm.
2022-05-04 13:50:12 +01:00
Ian Jackson 4bca912715 Change builder list API
The new API is (roughly) as discussed in
  https://gitlab.torproject.org/tpo/core/arti/-/issues/451

This is quite a large commit and it is not convenient to split it up.
It contains the following changes:

 * Redo the list builder and accessor macros implemnetation,
   including docs and tests.

 * Change uses of define_list_config_builder.  In each case:
   - Move the docs about the default value to the containing field.
   - Remove the other docs (which were just recapitulations, and
     are now not needed since the ListBuilder is no longer public).
   - Rewmove or replace `pub` in the define_list_builder_helper call,
     so that the builder is no longer public.
   - Change the main macro call site to use define_list_builder_helper.
   - Add a call to define_list_builder_accessors.

 * Make the module `list_builder` pub so that we have somewhere to
   put the overview documentation.

 * Consequential changes:
   - Change `outer.inner().replace(X)` to `outer.set_inner(X)`
   - Consequential changes to imports (`use` statements).
2022-05-04 13:50:10 +01:00
Ian Jackson ff624f6081 Rename NetworkConfig.fallback_caches
Previously this field was differently named to its serde and to its
accessors.  We are about to introduce a macro_rules macro which will
provide list accessors and we don't want that macro to have a field
renaming feature.

So stop renaming the field.
2022-05-04 13:41:39 +01:00
eta 6f787e1e77 Merge branch 'derive-builder-git-fixup' into 'main'
derive_builder: Use git dep everywhere, rather than cargo patch

See merge request tpo/core/arti!477
2022-04-27 14:31:08 +00:00
Ian Jackson a97ad69855 derive_builder: Use git dep everywhere, rather than cargo patch
The `[patch]` approach causes the tree not to build when used as a
dependency, unless the `[patch]` is replicated into the depending
project.

Instead, replace our `derive_builer =` dependencies with a reference
to a specific git commit:

  perl -i~ -pe 'next unless m/^derive_builder/; s#"(0\.11\.2)"#{ version = "$1", git = "https://github.com/ijackson/rust-derive-builder", rev = "ba0c1a5311bd9f93ddf5f5b8ec2a5f6f03b22fbe" }#' crates/*/Cargo.toml

Note that the commitid has changed.  This is because derive_builder is
in fact a workspace of 4 crates.  3 of them are of interest to arti
itself (the 4th exists only for testing).  So the same "add git
revision" treatment had to be done to the `derive_builder` and
`derive_builder_macro` crates.  Each dependency edge involves a new
commit in the derive_builder workspace, since we can't create a git
commit containing its own commitid.  (We want to use commits, rather
than a branch, so that what we are depending on is actually properly
defined, and not subject to the whims of my personal github
namespace.)

There are no actual code changes in derive_builder.
2022-04-27 14:57:59 +01:00
Samanta Navarro c53818d496 Fix grammar and typos 2022-04-27 13:52:13 +01:00
eta 8509dbc920 Merge branch 'upgrade_dependencies' into 'main'
Upgrade various dependencies, now that we are MSRV 1.56

Closes #313 and #334

See merge request tpo/core/arti!476
2022-04-27 12:27:28 +00:00
Nick Mathewson 5484bcc21f Merge branch 'download-schedule' into 'main'
DownloadSchedule: Introduce Builder

See merge request tpo/core/arti!473
2022-04-26 18:47:08 +00:00
Ian Jackson 4a32bcd4d3 Make DownloadScheduleBuilder "alternative" defaults pub(crate)
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/473#note_2798464
2022-04-26 19:01:20 +01:00
Nick Mathewson 4643e1dd24 Fix typo in message 2022-04-26 17:40:05 +00:00
Nick Mathewson 5586f0d039 Upgrade to Postage 0.5.0 2022-04-26 12:16:22 -04:00
Ian Jackson 72eaa9fc30 DirMgrConfig: Remove unnecessary accessors
These fields are pub.

Retain two convenience accessor functions that access sub-fields of
network.
2022-04-26 15:32:20 +01:00
Ian Jackson 20d61dd4d4 DirMgrConfig: Rename two fields that contained a _config
This entire struct is config.  This is otiose.
2022-04-26 15:29:33 +01:00
Ian Jackson ed71858123 DownloadSchedule: Rename field to "attempts"
This is actually a number of *attempts* not a number of *retries*.
The setter method was already called "attempts".

This chnages the deserialisation of the config.
2022-04-26 15:16:32 +01:00
Ian Jackson cb303cefb3 DownloadSchedule: Abolish accessors in DownloadScheduleConfig
We can just make the fields pub(crate).
2022-04-26 15:16:32 +01:00
Ian Jackson eb35555330 DownloadSchudule: Have NetworkConfig contain Builders
Use sub_builder.  We must do something special for defaults.

This involves moving the actual default values for retry_bootstrap and
retry_microdescs into config.rs, since they need to access the fields
of the un-built version of the structure.  (An alternative would be to
generate "weak setters" which do not override previous settings, but
derive_builder does not offer to generate them and that seems
overkill.)
2022-04-26 15:16:32 +01:00
Ian Jackson f4a1e34bee DownloadSchedule: Abolish new() method
Instead, everyone should use DownloadScheduleBuilder.

The new() method would in any case be useless in a moment, since we're
going to embed DownloadScheduleBuilder in the NetworkConfig, not
DownloadSchedule.

The call sites in the tests are all about to change again.
2022-04-26 15:16:32 +01:00
Ian Jackson e1d1fe6569 DownloadSchedule: tests: Do not try to set parallelism to 0
The current behaviour is to treat 0 as indicating "use the default",
which is quite strange.  We are going to get rid of that.

The new way will be to reject zero, during
DownloadScheduleBuilder::build, Add a test case for that.
2022-04-26 15:16:03 +01:00
Ian Jackson a720205d35 DownloadSchedule: Provide builder 2022-04-26 15:16:03 +01: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 ce877e4421 Document defaults for all the config lists
And add an imprecation in define_list_config_builder's doc comment do
do so in future for other invocations of the macro.

Add add the missing full stops.
2022-04-25 18:22:54 +01:00
Ian Jackson 1f215da1a3 Rename ThingListBuilder::replace (from set)
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/471#note_2798024
2022-04-25 18:15:25 +01:00
Nick Mathewson 2f6bc6bdc4 squash! Bump every crate's edition to 2021.
Remove all `use` statements for `TryFrom` and `TryInto`.  These are
now redundant in Rust 2021.
2022-04-25 13:06:26 -04: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
Nick Mathewson 0069fd2206 Reformat all not-yet-reformatted Cargo.toml files.
There are no semantic changes here; only formatting.  This is in
preparation for other changes (wrt MSRV and edition)
2022-04-25 13:04:31 -04:00
Ian Jackson dca4f3ede1 Use better syntax for doc comment attribute
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/471#note_2798020
2022-04-25 17:05:30 +01:00
Ian Jackson 4ad9e5e4b0 Introduce AuthorityListBuilder in NetworkConfigBuilder
NetworkConfigBuilder needs to not contain any validated structs, so
that its serde does not expose the validated details.

AuthorityListBuilder is what ought to go here - and it contains
Vec<AuthorityBuilder>, not Vec<Authority>.  As a consequence, many
places now deal with AuthorityBuilder, rather than Authority.
2022-04-25 12:54:51 +01:00
Ian Jackson 166af2c3f6 Fix error return type of AuthorityBuilder 2022-04-25 12:41:39 +01:00
Ian Jackson 0d4c53bb2d Merge branch 'experimental-v3ident-public' into 'main'
Authority: make v3ident public under experimental-api

See merge request tpo/core/arti!463
2022-04-25 09:31:05 +00:00
Christian Grigis 08bce9b6db
Authority: make v3ident public under experimental-api 2022-04-22 19:33:36 +02:00
Ian Jackson 962b6c32e1 fallback list: Introduce and use FallbackListBuilder
Now the network fallbacks configuration wants to Deserialize
a Vec<FallbackDirBuilder>, rather than validated Vec<FallbackDir>.

Methods on FallbackListBuilder are as per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/462#note_2797697
mutatis mutandi for the fact that this struct has only fallbacks in it.
2022-04-22 17:48:03 +01:00
Ian Jackson 61425a96bd fallback list: Move default list into tor-guardmgr
This is where the FallbackList type is.  We are going to want to
provide a builder too, which ought to impl Default.

This means that the default value for the type must be next to the
type.  In any case, it was anomalous that it wasn't.

This commit is pure code motion.
2022-04-22 17:39:58 +01:00
Ian Jackson 6da7a2e3e2 Use git source for derive_builder for now, for sub_builder feature
This commitid is the current head of my MR branch
  https://github.com/colin-kiegel/rust-derive-builder/pull/253
  https://github.com/ijackson/rust-derive-builder/tree/field-builder
Using the commitid prevents surprises if that branch is updated.

We will require this newer version of derive_builder.  The version
will need to be bumped again later, assuming the upstream MR is merged
and upstream do a release containing the needed changes.

We will need the new version of not only `derive_builder_core` (the
main macro implementation) but also`derive_builder` for a new error
type.
2022-04-21 14:07:28 +01:00
Samanta Navarro 142e57b03a Fix typos
Typos found with codespell.
2022-04-20 11:48:43 +00:00
Nick Mathewson d05022dea4 Treat expired/not-yet-valid directory objects as Errors.
Doing this will make us treat caches that send us these objects as
not-working, and close circuits to them instead of trying over and
over.

The case where we add a document from the cache requires special
handling: it isn't actually a error to find an expired document in
our cache (unless the passage of time itself is erroneous, which is
a debatable proposition at best).

Fixes #431.
2022-04-05 15:54:37 -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 c5e5fc1553 dirmgr: Use a different idiom in retry loop
Replace the next delay field immediately rather than taking it and
_then_ setting it.  This way, it's never in an incorrect state.
2022-03-31 08:07:50 -04:00
Nick Mathewson 6e8c982ab5 dirmgr: fix bugs in algorithm for retrying downloads
The previous algorithm had two flaws:

  * It would wait even after the final attempt, when there were no
    more retries to do.
  * It would fail to wait between attempts if an error occurred.

This refactoring fixes both of these issues, and adds some comments.
2022-03-30 13:56:36 -04:00
Nick Mathewson 1feb7eecac Reformat several Cargo.toml files with 100-char-wide lines. 2022-03-30 10:41:40 -04:00
Nick Mathewson 6282df34fb Refactor FirstHopId into type-differentiated form
The FirstHopId type now records an enum that stores whether the hop
is a guard or a fallback.  This change addresses concerns about
remembering to check the type or source of an Id before passing it
down to the FallbackState or GuardSet.

Making this change required an API change, so that dirmgr can
report success/failure status without actually knowing whether it's
using a fallback or a guard.
2022-03-30 10:41:39 -04:00
Nick Mathewson 13af6134f6 Rename Guard=>FirstHop, GuardId=>FirstHopId
This is preparation for having separate GuardId and FirstHopId types
that distinguish which back-end they index.
2022-03-30 10:40:59 -04:00
Nick Mathewson bdd129f230 Rename ExternalFailure => ExternalActivity. 2022-03-30 10:40:12 -04:00
Nick Mathewson bfb2353a8f Add status tracking to FallbackDir.
We do this by creating a new FallbackSet type that includes status
information, and updating the GuardMgr APIs to record success and
failure about it when appropriate.  We can use this to mark
FallbackDirs retriable (or not).

With this change, FallbackDir is now stored internally as a Guard in
the GuardMgr crate.  That's fine: the FallbackDir type really only
matters for configuration.
2022-03-30 10:39:09 -04:00
Nick Mathewson e48f4f3a93 dirmgr: do not pass fallbacks to the CircMgr.
This is the final step in allowing the CircMgr to use the GuardMgr's
view of the fallbacks.

Compilation is restored and tests pass.
2022-03-30 10:39:09 -04:00
Nick Mathewson 9da43189f3 Turn FallbackList into a real type, and store one in GuardMgr.
The guard manager is responsible for handing out the first hops of
tor circuits, keeping track of their successes and failures, and
remembering their states.  Given that, it makes sense to store this
information here.  It is not yet used; I'll be fixing that in
upcoming commits.

Arguably, this information no longer belongs in the directory
manager: I've added a todo about moving it.

This commit will break compilation on its own in a couple of places;
subsequent commits will fix it up.
2022-03-30 10:39:06 -04:00
Nick Mathewson 80b65c3a4d Move fallback.rs into guardmgr.
This is the logical place for it, I think: the GuardMgr's job is to
pick the first hop for a circuit depending on remembered status for
possible first hops.  Making this change will let us streamline the
code that interacts with these objects.
2022-03-30 10:34:48 -04:00
eta 5d27710ef1 Merge branch 'disallowed_lint' into 'main'
Remove allow(clippy::disallowed_methods) lint flag.

See merge request tpo/core/arti!437
2022-03-30 14:02:13 +00:00
eta ac64bdea27 Make daemon tasks self-contained; introduce NetDirProvider
The various background daemon tasks that `arti-client` used to spawn are
now handled inside their respective crates instead, with functions
provided to spawn them that return `TaskHandle`s.

This required introducing a new trait, `NetDirProvider`, which steals
some functionality from the `DirProvider` trait to enable `tor-circmgr`
to depend on it (`tor-circmgr` is a dependency of `tor-dirmgr`, so it
can't depend on `DirProvider` directly).

While we're at it, we also make some of the tasks wait for events from
the `NetDirProvider` instead of sleeping, slightly increasing
efficiency.
2022-03-30 14:26:43 +01:00
Nick Mathewson 700e491813 Remove allow(clippy::disallowed_methods) lint. 2022-03-30 08:55:58 -04:00
eta fd081742fa Merge branch 'no-system-time' into 'main'
Don't use SystemTime::now()

Closes #306

See merge request tpo/core/arti!365
2022-03-30 12:44:25 +00:00
Nick Mathewson 3bab96f064 Upgrade to rusqlite 0.27.0 2022-03-29 13:27:08 -04:00
Ian Jackson 3c17b42794 DirFilter: Move nil default impls to trait default methods
This means you can write a DirFilter and only write code to mess with
the bits you want to.

Also, it is less code here.
2022-03-25 13:11:28 +00:00
Ian Jackson 678504d9f9 Abolish filter::DynFilter in favour of transparent DirFilter
There are two reasons why the DynFilter newtype might be needed:

1. To impl Default.  But we don't need it to impl Default since we can
have an accessor which does the defaulting.

2. To hide the API.  But this is usrely an unstable API.

Just writing Arc<dyn> gets rid of a lot of unnecessary boilerplate and
conversion code.
2022-03-25 13:08:56 +00:00
Ian Jackson 0846ebd6d1 Make DirFilter be Debug + Send + Sync
Abolish the handwritten Debug impl for DynFilter, which is no longer
needed.
2022-03-25 13:08:33 +00:00
Nick Mathewson c0399fc6c1 dirmgr: Initial DirFilter code.
This code sits behind a feature flag, and can be used to modify
directories before storing them.  This is part of the implementation
for #397.
2022-03-24 12:10:46 -04:00
Nick Mathewson 4354415999 Reformat {arti-client,tor-dirmgr}/Cargo.toml 2022-03-24 12:10:35 -04:00
Nick Mathewson ee204328dd Expand some comments based on review from @diziet. 2022-03-21 15:16:00 -04:00
Nick Mathewson 9ee502cbec Fix build with Rust 1.53.
Pattern bindings after `@` weren't stabilized then :/
2022-03-21 12:15:23 -04:00
Nick Mathewson 1ec0ed45c8 dirmgr: Note errors and inform the circmgr about them.
Some error types indicate that the guard has failed as a dircache.
We should treat these errors as signs to close the circuit, and to
mark the guard as having failed.
2022-03-21 10:27:53 -04:00
Nick Mathewson d778a92225 circmgr: Change API for using FallbackDirs
It'll soon more convenient to pass in FallbackDirs as a slice of
references, rather than just a slice of FallbackDirs: I'm going to
be changing how we handle these in tor-dirmgr.
2022-03-21 09:06:32 -04:00
Ian Jackson d651a894de dirmgr: Authority: Abolish v3ident accessor
This makes this information crate-private.  The crate can reasonably
just access it.
2022-03-18 16:49:25 -04:00
Ian Jackson d1a9ed62f7 dirmgr: Authority: Move a method used only for testing 2022-03-18 16:49:25 -04:00
Ian Jackson 23cac566e1 dirmgr: Authority: Abolish two unused accessors 2022-03-18 16:49:25 -04:00
Ian Jackson 9c5480480a dirmgr: NetworkConfig: Abolish accessors
Using accessors for crate-only fields is otiose.
2022-03-18 16:49:25 -04:00
Ian Jackson a6d4109414 dirmgr: NetworkConfig: Rename fallbacks struct field
Rename this to be named the same as its accessor, and use the rename
feature of builder and serde.  (The shorter name is nicer in the code
IMO.)
2022-03-18 16:49:25 -04:00
Nick Mathewson 9b7663b4ba Merge branch 'md_allocation' into 'main'
Use less space in hashtables for microdescriptors

Closes #386

See merge request tpo/core/arti!415
2022-03-17 16:45:38 +00:00
Ian Jackson 0c0133dcc6 Run rustfmt 2022-03-17 16:22:15 +00:00
Ian Jackson 955e3a3e40 GetMicrodescsState: Abolish separate n_missing field in 2022-03-17 15:49:31 +00:00
Ian Jackson 3a1e599d5a GetMicrodescsState: Break out with_mdreceiver_for_missing 2022-03-17 15:49:29 +00:00
Ian Jackson 1c6f4aaa9b GetMicrodescsState: Dedupe slightly 2022-03-17 15:29:10 +00:00
Ian Jackson 40bede587c Merge branch 'config-partials-transparent' into 'main'
Absolish builders for CircMgrConfig and DirMgrConfig

See merge request tpo/core/arti!417
2022-03-17 12:30:46 +00:00
eta dd967e66b9 Merge branch 'always-ims' into 'main'
dirmgr: Always send if-modified-since on consensus documents.

Closes #403

See merge request tpo/core/arti!412
2022-03-16 21:32:48 +00:00
Ian Jackson a020f82de2 DirMgrConfig: abolish builder; make it transparent and exhaustive
See rationale in the comment.
2022-03-16 19:31:10 +00:00
Ian Jackson fb4111f524 Merge branch 'derive-builder' into 'main'
derive_builder: Switch to upstream 0.11

See merge request tpo/core/arti!414
2022-03-16 17:54:53 +00:00
Ian Jackson da787d074a derive_builder: Switch to upstream 0.11
This has the different syntax for builder field attributes than what I
originally proposed in my MR, and which therefore is in the pinned
branch.

My upstream MR for the field attributes feature was morged:
  https://github.com/colin-kiegel/rust-derive-builder/issues/239
2022-03-16 16:34:44 +00:00
Nick Mathewson 76df9e4014 tor-dirmgr: Remove redundant hashtable.
We were using a hashtable to keep track of missing microdescriptor
digests.  But this information is redundant with the NetDir state,
and there's now no longer any performance benefit to keeping a
separate copy.

Part of #386.
2022-03-16 11:33:19 -04:00
Nick Mathewson 09f750c2c8 RetryDelay: remove accessors.
Instead, check initial_delay in dirmgr directly.
2022-03-16 10:50:13 -04:00
Nick Mathewson 4ccc3af423 dirmgr: Always send if-modified-since on consensus documents.
We never want a consensus document that's super-old, since we would
reject it immediately for being too old.

Also, never send an if-modified-since that's so old that we'd reject
the response.

Closes #403
2022-03-16 09:48:37 -04:00
Nick Mathewson 11883b9e8d Remove re-export of retry-schedule in tor-dirmgr.
It wasn't necessary.
2022-03-16 08:47:02 -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 ef619ba70a RetryDelay: add accessors for state
We'll need these for our unit tests in tor-dirmgr once we move
RetryDelay into tor-basic-utils.
2022-03-16 08:26:14 -04:00
eta c0baf86e52 Merge branch 'missing_shrink_to_fit' into 'main'
dirmgr: Call shrink_to_fit on missing-microdesc hashtable

Closes #388

See merge request tpo/core/arti!399
2022-03-14 13:20:57 +00:00
Ian Jackson 8b8c2a426e humantime: Update to humantime-serde 1.1.1
This has the humantime_serde::option module, which we have upstreamed
and are about to switch to.

The remaining dependency with  version = "1"  is going to be removed
in a moment.
2022-03-14 10:33:59 +00:00
Nick Mathewson 837c7d717b Follow-up from arti!318
Make update_config only conditionally exported; add semver-status update.
2022-03-11 11:34:51 -05:00
Nick Mathewson d95dce7c70 Merge branch 'add-flatfile-dirmgr' into 'main'
Add flatfile DirMgr

See merge request tpo/core/arti!318
2022-03-11 16:34:26 +00:00
Christian Grigis 65486b185a
Expose APIs for external DirProvider 2022-03-11 13:44:48 +01:00
Nick Mathewson d9c1555229 dirmgr: Call shrink_to_fit on missing-microdesc hashtable
This hashtable starts out pretty large, but it can spend most of our
runtime (when we aren't downloading) being small.  To avoid doing
too much work, I've made it so we only call shrink_to_fit twice per
consensus: once when we're no longer pending, and once when we're
complete.

Closes #388.
2022-03-10 11:48:58 -05:00
Ian Jackson 1b1ce8cc82 Drop remaining conversion from FooConfig to FooConfigBuilder 2022-03-07 15:58:53 +00:00
Ian Jackson 5203311a97 Derive Deserialize for derive-builder-generated config builders
I used
  git-grep -P '\#\[serde\((?!default|deny_unknown)'
to find places where I needed to add additional attributes on the
builder method fields.

This is currently a bit duplicative, but when #371 is completely done,
the validated (non-builder) configs won't need to be Deserialize any
more.

This is part of #371 and #372.
2022-03-07 15:58:53 +00:00
Ian Jackson 416b56d852 Use git source for derive_builder for now, for attrs feature
We are going to want to specify custom attributes on fields of the
builder struct.  This feature was missing from derive_builder.

This commitid is the current head of my MR branch
  https://github.com/colin-kiegel/rust-derive-builder/pull/237
  https://github.com/ijackson/rust-derive-builder/tree/builder-field-attrs
Using the commitid prevents surprises if that branch is updated.

We will require this newer version of derive_builder.  The version
will need to be bumped again later, assuming the upstream MR is merged
and upstream do a release containing the needed changes.
2022-03-07 15:56:57 +00:00
Nick Mathewson 994a8f7cfa Merge branch 'errors-for-dirprovider' into 'main'
Errors for dirprovider

Closes #370

See merge request tpo/core/arti!385
2022-03-04 19:51:23 +00:00
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 4bff33c397 Provide an error variant for external directory providers 2022-03-04 17:35:34 +00:00
Nick Mathewson c23dad8c2d Use RsaIdentity::from_hex() and hex::decode_to_slice in more places
These aren't critical-path, but they do make the code a little nicer.
2022-03-04 09:23:26 -05: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 b27ffe14fb Merge branch 'dir-provider-redux' into 'main'
Alternative DirProvider setup

See merge request tpo/core/arti!347
2022-03-02 18:41:50 +00:00
Ian Jackson 738f7efa3d Replace manual Default impl with educe in tor-dirmgr 2022-03-02 18:06:37 +00:00
Ian Jackson 4fbb088907 Replace manual Default impl with educe+std in tor-dirmgr 2022-03-02 18:06:37 +00:00
Ian Jackson 210b9b70a8 Replace manual Debug impl with educe in tor-dirmgr 2022-03-02 18:06:37 +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
Nick Mathewson e8e9791a97 Bump all crates to 0.1.0 2022-03-01 08:59:34 -05:00
trinity-1686a f06b256010 use wallclock where possible in tests 2022-02-26 00:33:44 +01:00
trinity-1686a f9a4f23e83 remove most usage of SystemTime::now 2022-02-25 20:34:27 +01:00
Nick Mathewson 2f2ba8db5f DirProvider: Fix infinite recursion bug 2022-02-25 09:41:45 -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
Nick Mathewson 9aeb967010 Un-parameterize DirProvider.
This patch removes the EventStream associated type and the Runtime
parameter.  The Runtime parameter wasn't actually used for anything,
and the EventStream was easy enough to replace with a BoxStream in
this case.

Also replaced DirBootstrapEvents with a BoxStream to avoid tying
anything to our backend.
2022-02-23 14:46:17 -05:00
Christian Grigis 279b5978b7 Add basic DirProvider trait, use it in client 2022-02-23 14:11:21 -05: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
Nick Mathewson 7d4a57d5fa Rename TorConnectionFailed to TorAccessFailed 2022-02-22 15:38:13 -05:00
Nick Mathewson 0e242831b2 Rename TorShuttingDown to ArtiShuttingDown 2022-02-22 15:36:09 -05:00
Nick Mathewson 64a0d4dce5 dirclient: Remove HttpStatus error variant
Getting a non-200 status is no longer a failure condition; it's just
a different kind of answer.

Closes #349.
2022-02-17 15:12:00 -05:00
Nick Mathewson 83d001d661 Merge branch 'remaining-errors' 2022-02-17 14:22:47 -05:00
Nick Mathewson a5e4e24537 Use TorConnectionFailed for failure to download directory. 2022-02-17 12:37:07 -05:00
Ian Jackson c9aa3b9937 tor-dirmgr: Use Bug type for sqlite-detected bugs
So we get a stack trace
2022-02-17 13:32:47 +00:00
Ian Jackson 1a9a209771 tor-dirmgr: Make sqlite_error_kind take rusqlite::Error
We're about to reuse this and we'll want it to take the higher-level
type.  Also it seems more proper like this.
2022-02-17 13:31:36 +00:00
Nick Mathewson 2a7087ff93 dirmgr: Remember where netdocs came from.
This isn't complete (see TODO), but it's enough to let us report the
right ErrorKind if something fails to parse.
2022-02-16 16:28:23 -05:00
Nick Mathewson 4bb7c97399 dirmgr: eliminate StringParsingError.
It had too many possible Kinds depending on what kind of string had
failed to parse.

I decided to use #[source] here instead of #[from], so that we
would have to explicitly convert these errors where they show up.
2022-02-16 16:02:28 -05:00
Nick Mathewson f71473cf73 dirmgr: HasKind for internal and sqlite errors
At first I had thought that all sqlite errors would be internal, but that's
not the case.
2022-02-16 15:48:24 -05:00
Nick Mathewson 9e03643f65 dirmgr: implement HasKind for the easier variants 2022-02-16 15:22:21 -05:00
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
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 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
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
Nick Mathewson 070e52653d Make SpawnError wrappers contain a 'spawning' string
(By our convention, these errors should say what we were trying to
spawn when the error occurred.)
2022-02-04 16:06:11 -05:00
Nick Mathewson 645dc10148 Make TorError implement Clone.
This patch makes only minimal changes in lower-level error types:
we have more refactoring to do.
2022-02-04 16:06:11 -05:00
Ian Jackson 2f1d98403b spawn errors: Fix tor-dirmgr 2022-02-04 14:42:37 +00:00
Ian Jackson 6e1dc612cc tor-error: Add as a ddpendency to many crates
Doing this here makes it easier when I rebase/reorder things
2022-02-04 14:42:37 +00:00
Nick Mathewson 03755a5c7b Merge branch 'dirclient-testing' into 'main'
dir-client: bug fix and more tests

See merge request tpo/core/arti!271
2022-02-03 15:09:06 +00:00
Nick Mathewson c8dd73d55f Upgrade required version of futures crate to 0.3.14
Earlier versions have a bug in UnboundedReceiver that make our new
dirclient tests fail.
2022-02-01 09:54:47 -05:00
Michael 334bba2ef2 Fix invalid path character on windows 2022-01-31 20:53:13 +00:00
Nick Mathewson 329bde58dd Bump tor-netdir and tor-guardmgr versions
tor-netdir needs to bump because tor-netdoc bumped, even though
there were no other changes in tor-netdir.  Whoops.

tor-guardmgr needs to bump because it already published, with the
older tor-netdir.
2022-01-31 11:05:34 -05:00
Nick Mathewson 01d9937308 Bump the patch version of every crate that changed since 0.0.3 2022-01-31 10:30:52 -05:00
Nick Mathewson 98d8171610 Fix test failure in tor_dirmgr::state::test::get_microdescs_state
This failure occurred because our tests use canned data to exercise
the directory state functionality, and the canned consensus has
suddenly become very expired.

There are better fixes possible, but this is a minimal one that
should get CI working on main again.
2022-01-27 17:13:38 -05:00
Nick Mathewson 30b3818a9e Make the native-tls crate optional.
This commit puts the native-tls crate behind a feature.  The feature
is off-by-default in the tor-rtcompat crate, but can be enabled
either from arti or arti-client.

There is an included script that I used to test that tor-rtcompat
could build and run its tests with all subsets of its features.

Closes #300
2022-01-26 14:06:58 -05:00