summaryrefslogtreecommitdiff
path: root/crates/tor-dirmgr/src/lib.rs
Commit message (Collapse)AuthorAgeFilesLines
* enable doc_auto_cfg feature on every crate when documenting for docs.rstrinity-1686a2022-08-241-0/+1
|
* Finish implementation of params() for DirMgr.Nick Mathewson2022-08-021-0/+36
| | | | | | | Now it maintains an up-to-date set of default parameters to be handed out if there is no directory. Closes #528.
* tor-dirmgr: Remove opt_netdir entirely.Nick Mathewson2022-07-261-8/+5
| | | | Its existence tended to hide bugs, and was just asking for trouble.
* Remove unused DirMgr::netdir method, make opt_netdir private.Nick Mathewson2022-07-261-11/+1
|
* Add new APIs to NetDirProvider to better support timeliness.Nick Mathewson2022-07-261-3/+24
| | | | | | | | | | | | | | | | | Over the years we've found that most callers who want a netdir want what C Tor calls a "reasonably live" network directory: One that is not expired by too much, or too far in the future. But a few want a _strictly_ live directory: one that says it is valid now, with no tolerances. And a few want _any_ directory, no matter how expired it is. This commit adds net methods to NetDirProvider to provide these directories. I think that most use cases will want to explicitly think about what kind of directory they want, so I've made `netdir` the simplest method. I might remove `timely_netdir` by the end of this branch; see TODO comments. Part of #518.
* Rename DirSkewTolerance to DirToleranceNick Mathewson2022-07-221-3/+3
| | | | | | This name is more accurate because we aren't only dealing with clock skew here: we're also trying to tolerate the case where the authorities fail to reach consensus for a while.
* Run maint/add_warning crates/*/src/{lib,main}.rsIan Jackson2022-06-231-0/+3
| | | | Update all lint blocks
* Merge branch 'stalled_directory' into 'main'Ian Jackson2022-06-211-14/+51
|\ | | | | | | | | | | | | Detect and report stalled directory downloads Closes #468 See merge request tpo/core/arti!587
| * tor-dirmgr: Make DirStatus non-public.Nick Mathewson2022-06-141-1/+1
| | | | | | | | | | I believe this type was made public in error: No other crate uses it, and no API exposes it.
| * Add a blockage-reporting mechanism to tor-dirmgr.Nick Mathewson2022-06-141-1/+1
| | | | | | | | | | | | | | | | | | 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.
| * DirMgr: Track errors, stalls, and resets as part of status.Nick Mathewson2022-06-131-0/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * Refactor our logic for distinguishing download attemptsNick Mathewson2022-06-131-12/+24
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * Refactor most DirStatus users to use DirProgress.Nick Mathewson2022-06-131-3/+4
| | | | | | | | This is all crate-internal APIs, fortunately.
* | Fix clippy::significant_drop_in_scrutinee warningsNick Mathewson2022-06-151-5/+8
|/ | | | | | | | | 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.
* Merge branch 'dormant_directory' into 'main'Nick Mathewson2022-06-131-70/+59
|\ | | | | | | | | | | | | Use TaskSchedule to sleep in directory bootstrapping Closes #497 See merge request tpo/core/arti!571
| * DirMgr: Use scopeguard crate in place of ad hoc RAII substitutesNick Mathewson2022-06-131-68/+18
| |
| * Put the task schedule back when the dl task exits.Nick Mathewson2022-06-131-2/+9
| | | | | | | | | | This will allow somebody else to call bootstrap() if bootstrap() fails the first time.
| * New API to expose and use TaskHandle from DirMgr.Nick Mathewson2022-06-131-2/+31
| | | | | | | | | | | | 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.
| * DirMgr: Refactor bootstrap to use a TaskSchedule for sleeping.Nick Mathewson2022-06-101-14/+17
| | | | | | | | | | | | 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.
* | Merge branch 'use-testing-rng'Nick Mathewson2022-06-071-1/+2
|\ \ | |/ |/|
| * Use testing_rng() in tests throughout our crates.Nick Mathewson2022-06-021-1/+2
| | | | | | | | | | | | 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.
* | lints: Add let_unit_value allow to all cratesIan Jackson2022-05-311-0/+1
| | | | | | | | | | From running add_warning, with manual picking of the right hunks/lines.
* | lints: Add lint block delimiters to every crateIan Jackson2022-05-311-0/+2
|/ | | | | | This was the result of: maint/add_warning crates/*/src/{lib,main}.rs and then manually curating the results.
* Remove BootstrapAction::ImpossibleNick Mathewson2022-05-191-1/+1
| | | | It does nothing that Fatal does not. Suggested by @eta in review.
* DirMgr: Unify error return pathsNick Mathewson2022-05-171-13/+23
| | | | | | | | | | | | | | | | | 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.
* DirMgr: Improve display for DocSourceNick Mathewson2022-05-161-3/+11
| | | | (Also, implement Display for tor_dirclient::SourceInfo).
* DirMgr: make DocSource useful by having it include dirserver info.Nick Mathewson2022-05-161-4/+5
| | | | | | | | | 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.
* Resolve DOCDOC comments in tor-dirmgr.Nick Mathewson2022-05-121-4/+2
|
* Adjust if-modified-since field on the basis of tolerated skewNick Mathewson2022-05-111-26/+68
| | | | | | | | | | 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.
* Add DirSkewTolerance section to DirMgr configuration.Nick Mathewson2022-05-111-2/+2
| | | | | | | | | | | | | | | | | | | | 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.
* tor-dirmgr: move apply_netdir_changes() to be a DirMgr methodeta2022-05-101-3/+75
|
* tor-dirmgr/state.rs: take an object to get a netdir, not a netdireta2022-05-101-3/+5
| | | | | | | | | - 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.)
* tor-dirmgr/state.rs: remove GetConsensusState::bodge_neweta2022-05-101-6/+24
| | | | - (Also fixes up some dirfilter stuff, whoops.)
* tor-dirmgr/state.rs: use the NetDirChange API instead of WriteNetDireta2022-05-101-0/+1
| | | | | | | | | | | - 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)
* tor-dirmgr/state.rs: refactor GetConsensusState::neweta2022-05-101-2/+3
| | | | | | | | | | | | | - 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.
* tor-dirmgr: move DirState to state.rseta2022-05-101-75/+1
| | | | | | - 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)
* tor-dirmgr: make note_request_* functions standaloneeta2022-05-101-64/+0
| | | | | - DirMgr::note_request_outcome and friends are now just standalone functions, taking a CircMgr.
* tor-dirmgr/bootstrap.rs: refactor query_into_requests, make it usedeta2022-05-101-49/+43
| | | | | | | - 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.
* tor-dirmgr: move query_into_requests into bootstrap.rseta2022-05-101-43/+8
| | | | | | | - 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.
* tor-dirmgr/bootstrap.rs: refactor load_all -> load_documents_from_storeeta2022-05-101-2/+5
| | | | | | | | - 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
* tor-dirmgr/lib.rs: move DirMgr::load_documents_into to DocQueryeta2022-05-101-55/+3
| | | | | Move the function out of DirMgr, giving it a new &Mutex<DynStore> argument instead.
* tor-dirmgr: make DownloadScheduleBuilder publicIan Jackson2022-05-041-1/+1
| | | | | | 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.
* Change builder list APIIan Jackson2022-05-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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).
* DirMgrConfig: Remove unnecessary accessorsIan Jackson2022-04-261-4/+4
| | | | | | | These fields are pub. Retain two convenience accessor functions that access sub-fields of network.
* DownloadSchedule: Abolish accessors in DownloadScheduleConfigIan Jackson2022-04-261-1/+1
| | | | We can just make the fields pub(crate).
* Introduce AuthorityListBuilder in NetworkConfigBuilderIan Jackson2022-04-251-1/+1
| | | | | | | | | 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.
* Refactor FirstHopId into type-differentiated formNick Mathewson2022-03-301-6/+4
| | | | | | | | | | | 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.
* Rename Guard=>FirstHop, GuardId=>FirstHopIdNick Mathewson2022-03-301-4/+4
| | | | | This is preparation for having separate GuardId and FirstHopId types that distinguish which back-end they index.
* Rename ExternalFailure => ExternalActivity.Nick Mathewson2022-03-301-4/+4
|
* Add status tracking to FallbackDir.Nick Mathewson2022-03-301-0/+11
| | | | | | | | | | | 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.