summaryrefslogtreecommitdiff
path: root/crates/tor-dirmgr/src/lib.rs
Commit message (Collapse)AuthorAgeFilesLines
* Fix a couple of rustdoc issues.Nick Mathewson2022-11-181-1/+2
| | | | These slipped in while nightly was broken.
* dirmgr Store: Have constructors take DirMgrStoreIan Jackson2022-11-141-6/+13
| | | | | | | Now the Store is constructed by arti_client, solving the problem described here https://gitlab.torproject.org/tpo/core/arti/-/issues/631#note_2853665 but in a different way.
* dirmgr Store: Introduce DirMgrStore and use for BridgeDescMgrIan Jackson2022-11-141-0/+25
| | | | We are going to change DirMgr's constructors to also take a DirMgrStore.
* dirmgr Store: Use `**` syntax and deref to trait objectsIan Jackson2022-11-141-23/+14
| | | | This will allow us to get rid of a needless trait impl.
* bridge desc: Drop a done TODOIan Jackson2022-11-081-1/+0
| | | | | We have a separate BridgeDescMgr, rather than reusing DirMgr, so we will not be implementing BridgeDescProvider for DirMgr.
* dirmgr: Make store be in an ArcIan Jackson2022-11-041-2/+2
| | | | | This will let us share it with the bridge descriptor manager. (As discussed with Nick.)
* Run add_warnings.Nick Mathewson2022-11-031-0/+1
|
* bridge descriptors: Provide an implementation of BridgeDescProviderIan Jackson2022-11-031-0/+2
| | | | Tests will come in a moment.
* Fix clippy false positiveIan Jackson2022-10-251-0/+5
|
* FlagEvent trait: Implement using macrosIan Jackson2022-10-251-0/+3
| | | | | | | | | | | The explicit list of variant names, that needs to be kept in sync, and is a test failure semver break hazard, is now gone. All the necessary code is now generated automatically, and cannot be wrong. I want this because I find myself wanting to add a second implementation of FlagEvent, for another type.
* cargo fmt to remove blank linesIan Jackson2022-10-121-1/+0
| | | | | | | Apparently cargo fmt doesn't like these, which my perl rune didn't delete. This commit is precisely the result of `cargo fmt`.
* Replace all README copies in src/lib.rs with includesIan Jackson2022-10-121-51/+1
| | | | | | | | The feature we want is `#[doc = include_str!("README.md")]`, which is stable since 1.54 and our MSRV is now 1.56. This commit is precisely the result of the following Perl rune: perl -i~ -0777 -pe 's{(^//!(?!.*\@\@).*\n)+}{#![doc = include_str!("../README.md")]\n}m' crates/*/src/lib.rs
* Mark all bridge and pt features as experimental for now.Nick Mathewson2022-09-291-0/+26
| | | | | | Also, document the features. Closes #588.
* GuardMgr/DirMgr: Add APIs for bridge descriptor listsNick Mathewson2022-09-261-0/+1
|
* `TaskSchedule`: give error on `sleep*()` if last handle is droppedNick Mathewson2022-09-071-3/+3
| | | | | | | | | | | | | | | | | | This fixes an busy-loop. When the last `TaskHandle` on a `TaskSchedule` is dropped, the schedule is permanently canceled: whatever operation it was scheduling should no longer be performed. But our code was broken: the `sleep()` and `sleep_until_wallclock()` functions don't verify whether the handles are dropped or not. This breakage caused an CPU-eating busy-loop in `sleep_until_wallclock`. With this patch, we now return a `Result<(), SleepError>` from these functions. Fixes #572.
* 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.