summaryrefslogtreecommitdiff
path: root/crates/tor-dirmgr/src/state.rs
Commit message (Collapse)AuthorAgeFilesLines
* dirmgr: use voting_period.Nick Mathewson2023-06-291-4/+1
|
* Downgrade and clarify message about dir replacment time.Nick Mathewson2023-05-081-8/+12
| | | | Closes #839
* Merge branch 'fix_802_core' into 'main'Ian Jackson2023-04-181-1/+6
|\ | | | | | | | | | | | | DirMgr: Detect that directory state is ready if it begins with all MDs Closes #802 See merge request tpo/core/arti!1126
| * DirMgr: Detect that directory state is ready if it begins with all MDsNick Mathewson2023-04-101-1/+6
| | | | | | | | | | | | | | | | | | | | | | Previously, we'd only call PendingNetDir::upgrade_if_necesessary when adding a microdescriptor. But if it began already having all of its descriptors (because we found them in the cache), we wouldn't actually upgrade it to a PendingNetDir::Yielding, which would make it unusable, and would make us schedule its reset time too far in the future. Fixes #802.
* | Use bool::then_some() as appropriateNick Mathewson2023-04-111-1/+1
|/ | | | | | Now that we require a version of Rust that allows `b.then_some(v)`, clippy complains about our use of `b.then(|| v)`.
* tor-netdoc: Change fill_from_previous_netdirIan Jackson2023-02-091-1/+1
| | | | | | | | | | | | | | | | * Remove the return value, which was not used anywhere. Also remove the code to calculate the return value. * Take an Arc<NetDir> rather than a reference. We are going to want this for HS support. This has no overall effect on the lifetime of the4 Arc, which was owned at the one call site and then imediately dropped. * Change the documentation to explain what the function's role is in the netdir API, rather than the fiddly details of what it actually does internally. Relegate the latter to a code comment. (When we have HS, this will do more, or, at least, make further arrangements.)
* Use ErrorReport - run rustfmtIan Jackson2023-01-301-1/+5
| | | | Split off for ease of review and possible rebase.
* Use ErrorReport for errors in warn! in tor-dirmgrIan Jackson2023-01-301-2/+2
|
* Allow clippy::unchecked_duration_subtraction in testsNick Mathewson2023-01-271-0/+1
| | | | | This panics on error, and we're fine with a panic on misbehavior in tests.
* Complete our migration to base64ct.Nick Mathewson2023-01-201-1/+2
| | | | | | | | | This is in lieu of upgrading to the latest base64 crate, which has a different API from the old one. Since we have to migrate either way, we might as well use base64ct everywhere. I don't think that most of these cases _require_ constant-time base64, but it won't hurt.
* test lint blocks: Do some semi-manuallyIan Jackson2022-12-121-0/+8
| | | | | | | This is the hunks from running the rune in maint/adhoc-add-lint-blocks but which require some subsequent manual fixup: usually, deleting now-superfluous outer allows, but in some cases manually putting back lints that the adhoc script deleted.
* Rename DirSkewTolerance to DirToleranceNick Mathewson2022-07-221-1/+1
| | | | | | 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.
* Refactor most DirStatus users to use DirProgress.Nick Mathewson2022-06-131-16/+17
| | | | This is all crate-internal APIs, fortunately.
* Rename DirStatusInner to DirProgress.Nick Mathewson2022-06-131-4/+4
| | | | | | 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.
* DirMgr:: Remove Error::NoChange as redundant.Nick Mathewson2022-05-251-38/+16
| | | | | | | | 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.
* Merge branch 'bug482' into 'main'eta2022-05-241-20/+105
|\ | | | | | | | | | | | | DirMgr: Stop load-from-cache process when there is no change. Closes #482 See merge request tpo/core/arti!527
| * DirMgr: Stop load-from-cache process when there is no change.Nick Mathewson2022-05-241-20/+105
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* | fs-mistrust: make Mistrust have a corresponding Builder type.Nick Mathewson2022-05-241-1/+1
|/ | | | | This is an approximately minimal revision to get Builder in place; subsequent commits will clean up the API.
* Fix compilation with Rust 1.56.Nick Mathewson2022-05-171-3/+2
|
* DirMgr: Remove blocking_error return path.Nick Mathewson2022-05-171-26/+22
|
* DirMgr: Unify error return pathsNick Mathewson2022-05-171-84/+133
| | | | | | | | | | | | | | | | | 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-53/+43
|
* DirMgr: Start refactoring error handling.Nick Mathewson2022-05-171-1/+4
| | | | | | 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.
* Give an error if the cache violates If-Modified-Since.Nick Mathewson2022-05-161-7/+24
| | | | | This should be sufficient to detect several kinds of nefariousness that we'd previously overlooked.
* Add missing extend_tolerance to add_consensus_text.Nick Mathewson2022-05-161-0/+1
| | | | This should have gone in when we fixed #412
* Move consensus signature verification to add-document code.Nick Mathewson2022-05-161-22/+95
| | | | | | | | | | | 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.
* DirMgr: Add a way for a state to report a blocking error.Nick Mathewson2022-05-161-0/+5
| | | | | (A blocking error is one that means that the current bootstrap attempt has failed, and must be restarted.)
* Implement nonfatal errors in add_from_*Nick Mathewson2022-05-161-52/+91
|
* DirMgr: Let add_from_* distinguish non-fatal errorsNick Mathewson2022-05-161-30/+47
| | | | | | | 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-17/+35
| | | | | | | | | 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.
* tor-dirmgr: update status reporting to consider skew toleranceNick Mathewson2022-05-111-0/+6
| | | | | | In our status reporting code, we consider an expired-but-still-usable directory still bootstrapped, but not 100% bootstrapped.
* Make reset_time() for incomplete directories more generous.Nick Mathewson2022-05-111-10/+35
| | | | | | | | | | | 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
* Add DirSkewTolerance section to DirMgr configuration.Nick Mathewson2022-05-111-0/+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: small fixups for the bootstrapping refactoreta2022-05-101-11/+6
| | | | | | | - 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/state.rs: take an object to get a netdir, not a netdireta2022-05-101-9/+24
| | | | | | | | | - 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-37/+12
| | | | - (Also fixes up some dirfilter stuff, whoops.)
* tor-dirmgr/state.rs: remove WriteNetDir, use filters directlyeta2022-05-101-97/+79
| | | | | - The only purpose of WriteNetDir was to provide a filter, which isn't necessary any more. Refactor to provide the filter directly.
* tor-dirmgr/state.rs: use the NetDirChange API instead of WriteNetDireta2022-05-101-243/+164
| | | | | | | | | | | - 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-0/+25
| | | | | | | | | | | | | - 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-236/+217
| | | | | | | | | | | | | | - 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/state.rs: refactor GetConsensusState::neweta2022-05-101-217/+281
| | | | | | | | | | | | | - 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-2/+77
| | | | | | - 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)
* Update tor-dirmgr to use fs-mistrust.Nick Mathewson2022-05-091-1/+6
|
* Change builder list APIIan Jackson2022-05-041-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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).
* Merge branch 'download-schedule' into 'main'Nick Mathewson2022-04-261-9/+9
|\ | | | | | | | | DownloadSchedule: Introduce Builder See merge request tpo/core/arti!473
| * DirMgrConfig: Remove unnecessary accessorsIan Jackson2022-04-261-5/+5
| | | | | | | | | | | | | | These fields are pub. Retain two convenience accessor functions that access sub-fields of network.
| * DirMgrConfig: Rename two fields that contained a _configIan Jackson2022-04-261-1/+1
| | | | | | | | This entire struct is config. This is otiose.
| * DownloadSchedule: Abolish accessors in DownloadScheduleConfigIan Jackson2022-04-261-6/+6
| | | | | | | | We can just make the fields pub(crate).
* | Merge branch 'main' into 'msrv_1_56'Nick Mathewson2022-04-261-11/+7
|\| | | | | | | | | | | # Conflicts: # crates/tor-config/Cargo.toml # crates/tor-dirmgr/src/state.rs # doc/semver_status.md
| * Rename ThingListBuilder::replace (from set)Ian Jackson2022-04-251-2/+2
| | | | | | | | | | As per https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/471#note_2798024