aboutsummaryrefslogtreecommitdiff
path: root/crates/tor-dirmgr/src/bootstrap.rs
Commit message (Collapse)AuthorAgeFilesLines
...
* DirMgr:: Remove Error::NoChange as redundant.Nick Mathewson2022-05-251-22/+7
| | | | | | | | 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.
* DirMgr: Stop load-from-cache process when there is no change.Nick Mathewson2022-05-241-9/+28
| | | | | | | | | | | | 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.
* Simplify advance and reset functions with mem::replace.Nick Mathewson2022-05-191-8/+4
|
* Explain why we call update_status unconditionally.Nick Mathewson2022-05-191-0/+3
|
* Remove BootstrapAction::ImpossibleNick Mathewson2022-05-191-1/+1
| | | | It does nothing that Fatal does not. Suggested by @eta in review.
* DirMgr: Remove blocking_error return path.Nick Mathewson2022-05-171-27/+7
|
* DirMgr: Unify error return pathsNick Mathewson2022-05-171-73/+106
| | | | | | | | | | | | | | | | | 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: Remove special handling of "changed" booleanNick Mathewson2022-05-171-31/+26
|
* DirMgr: Blame the correct cache for consensus validation failureNick Mathewson2022-05-161-2/+15
|
* On a blocking error, blame the appropriate directory cacheNick Mathewson2022-05-161-0/+10
| | | | | Fortunately, the only error type that we need to handle blocking errors with actually has a DirSource in it already.
* DirMgr: Add a way for a state to report a blocking error.Nick Mathewson2022-05-161-7/+21
| | | | | (A blocking error is one that means that the current bootstrap attempt has failed, and must be restarted.)
* DirMgr: Let add_from_* distinguish non-fatal errorsNick Mathewson2022-05-161-24/+32
| | | | | | | Previously all errors were treated as non-fatal. The add_from_* implementations don't yet behave properly; I'll fix them in subsequent commits.
* DirMgr: make DocSource useful by having it include dirserver info.Nick Mathewson2022-05-161-1/+7
| | | | | | | | | 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.
* dirmgr: use set_skew_limit.Nick Mathewson2022-05-111-0/+9
| | | | | | | | | | 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.
* Adjust if-modified-since field on the basis of tolerated skewNick Mathewson2022-05-111-3/+16
| | | | | | | | | | 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.
* tor-dirmgr: move apply_netdir_changes() to be a DirMgr methodeta2022-05-101-76/+5
|
* tor-dirmgr: small fixups for the bootstrapping refactoreta2022-05-101-5/+3
| | | | | | | - 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.
* tor-dirmgr/bootstrap.rs: error on older netdirs, add log lineeta2022-05-101-0/+21
| | | | | | | | - 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.)
* tor-dirmgr/state.rs: use the NetDirChange API instead of WriteNetDireta2022-05-101-17/+14
| | | | | | | | | | | - 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: add new NetDirChange API, consume iteta2022-05-101-3/+72
| | | | | | | | | | | | | - 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.
* tor-dirmgr/state.rs: feed through additional parameters, use themeta2022-05-101-6/+5
| | | | | | | | | | | | | | - 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.)
* tor-dirmgr: move DirState to state.rseta2022-05-101-1/+2
| | | | | | - 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/bootstrap.rs: refactor fetch_singleeta2022-05-101-31/+34
| | | | | | | - 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.
* tor-dirmgr: make note_request_* functions standaloneeta2022-05-101-8/+80
| | | | | - 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-11/+13
| | | | | | | - 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-1/+63
| | | | | | | - 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-7/+14
| | | | | | | | - 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-1/+1
| | | | | Move the function out of DirMgr, giving it a new &Mutex<DynStore> argument instead.
* squash! Bump every crate's edition to 2021.Nick Mathewson2022-04-251-1/+0
| | | | | Remove all `use` statements for `TryFrom` and `TryInto`. These are now redundant in Rust 2021.
* Treat expired/not-yet-valid directory objects as Errors.Nick Mathewson2022-04-051-1/+10
| | | | | | | | | | | | | 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.
* dirmgr: Use a different idiom in retry loopNick Mathewson2022-03-311-3/+2
| | | | | Replace the next delay field immediately rather than taking it and _then_ setting it. This way, it's never in an incorrect state.
* dirmgr: fix bugs in algorithm for retrying downloadsNick Mathewson2022-03-301-13/+22
| | | | | | | | | | 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.
* Add status tracking to FallbackDir.Nick Mathewson2022-03-301-1/+6
| | | | | | | | | | | 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.
* dirmgr: do not pass fallbacks to the CircMgr.Nick Mathewson2022-03-301-6/+1
| | | | | | | This is the final step in allowing the CircMgr to use the GuardMgr's view of the fallbacks. Compilation is restored and tests pass.
* Remove allow(clippy::disallowed_methods) lint.Nick Mathewson2022-03-301-1/+0
|
* Merge branch 'no-system-time' into 'main'eta2022-03-301-12/+15
|\ | | | | | | | | | | | | Don't use SystemTime::now() Closes #306 See merge request tpo/core/arti!365
| * use wallclock where possible in teststrinity-1686a2022-02-261-6/+6
| |
| * remove most usage of SystemTime::nowtrinity-1686a2022-02-251-6/+9
| |
* | dirmgr: Note errors and inform the circmgr about them.Nick Mathewson2022-03-211-7/+26
| | | | | | | | | | | | 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.
* | circmgr: Change API for using FallbackDirsNick Mathewson2022-03-211-1/+5
|/ | | | | | 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.
* dirmgr: add Store traittharvik2022-02-231-5/+6
|
* dirclient: Remove HttpStatus error variantNick Mathewson2022-02-171-2/+11
| | | | | | | Getting a non-200 status is no longer a failure condition; it's just a different kind of answer. Closes #349.
* dirmgr: eliminate StringParsingError.Nick Mathewson2022-02-161-1/+2
| | | | | | | | 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.
* tor-dirmgr: Create a bootstrap-status exporting mechanism.Nick Mathewson2022-01-181-0/+12
| | | | | | | | | | | | | | | | | | | | | | The interface is similar to the one exposed by `arti-client`: it internally uses postage::watch to give a series of events showing when a bootstrap status is changing. Thanks to the existing state/driver separation in the DirMgr design we don't need much new logic: each download state needs to expose (internally) how far along it is in its download, which the bootstrap code passes to the DirMgr if it has changed. I believe that in the long run, we'll probably want to expose more (or different) information here, and we'll want to process it differently. With that in mind, I've made the API for `DirBootstrapStatus` deliberately narrow, so that we can change its of its internal later on without breaking code that depends on it. (The information exposed by this commit is not yet summarized in `arti-client`.) Part of #96.
* Refactor directory events to use a FlagPublisher mechanism.Nick Mathewson2021-12-141-4/+0
| | | | | | | | This approach tries to preserve the current interface, but uses a counter-based event backend to implement a coalescing stream of events that can be represented as small integers. The advantage here is that publishing events no longer needs to be a blocking operation, since there is no queue to fill up.
* Make much of DirMgrConfig reconfigurable.Nick Mathewson2021-12-071-1/+2
| | | | | | | | | | We can't change the authorities while in-flight: that would be pretty miserable to implement. Similarly we can't change the cache while in-flight. Everything else should be fair game, though there are a couple of tricky bits. I've tried to document those.
* add semicolons if nothing returnedDaniel Eades2021-11-251-2/+2
|
* deglob some enums, use concise iteration syntaxDaniel Eades2021-11-251-1/+1
|
* Rename RetryConfig to DownloadSchedule, fold in parallelism.Nick Mathewson2021-11-181-5/+6
|
* Fix typosDimitris Apostolou2021-11-121-2/+2
|