summaryrefslogtreecommitdiff
path: root/crates/tor-dirmgr/src/lib.rs
Commit message (Collapse)AuthorAgeFilesLines
* 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.
* Move fallback.rs into guardmgr.Nick Mathewson2022-03-301-1/+1
| | | | | | | 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.
* Make daemon tasks self-contained; introduce NetDirProvidereta2022-03-301-16/+9
| | | | | | | | | | | | | | | 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.
* Merge branch 'no-system-time' into 'main'eta2022-03-301-8/+10
|\ | | | | | | | | | | | | Don't use SystemTime::now() Closes #306 See merge request tpo/core/arti!365
| * use wallclock where possible in teststrinity-1686a2022-02-261-8/+10
| |
* | Abolish filter::DynFilter in favour of transparent DirFilterIan Jackson2022-03-251-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* | dirmgr: Initial DirFilter code.Nick Mathewson2022-03-241-0/+11
| | | | | | | | | | | | 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.
* | Expand some comments based on review from @diziet.Nick Mathewson2022-03-211-0/+4
| |
* | Fix build with Rust 1.53.Nick Mathewson2022-03-211-6/+9
| | | | | | | | Pattern bindings after `@` weren't stabilized then :/
* | dirmgr: Note errors and inform the circmgr about them.Nick Mathewson2022-03-211-0/+48
| | | | | | | | | | | | 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.
* | Merge branch 'config-partials-transparent' into 'main'Ian Jackson2022-03-171-6/+6
|\ \ | | | | | | | | | | | | Absolish builders for CircMgrConfig and DirMgrConfig See merge request tpo/core/arti!417
| * | DirMgrConfig: abolish builder; make it transparent and exhaustiveIan Jackson2022-03-161-6/+6
| | | | | | | | | | | | See rationale in the comment.
* | | dirmgr: Always send if-modified-since on consensus documents.Nick Mathewson2022-03-161-10/+49
|/ / | | | | | | | | | | | | | | | | | | 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
* | Follow-up from arti!318Nick Mathewson2022-03-111-1/+1
| | | | | | | | Make update_config only conditionally exported; add semver-status update.
* | Expose APIs for external DirProviderChristian Grigis2022-03-111-1/+4
| |
* | Merge branch 'dir-provider-redux' into 'main'Ian Jackson2022-03-021-1/+63
|\ \ | | | | | | | | | | | | Alternative DirProvider setup See merge request tpo/core/arti!347
| * | DirProvider: Fix infinite recursion bugNick Mathewson2022-02-251-4/+4
| | |
| * | Un-parameterize DirProvider.Nick Mathewson2022-02-231-15/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| * | Add basic DirProvider trait, use it in clientChristian Grigis2022-02-231-0/+68
| | |
* | | Disable clippy::clone_on_ref_ptrIan Jackson2022-02-241-1/+0
| |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | dirmgr: add Store traittharvik2022-02-231-8/+9
|/
* Merge branch 'remaining-errors'Nick Mathewson2022-02-171-0/+18
|\
| * dirmgr: Remember where netdocs came from.Nick Mathewson2022-02-161-0/+18
| | | | | | | | | | This isn't complete (see TODO), but it's enough to let us report the right ErrorKind if something fails to parse.
* | arti-client: add ability to automatically bootstrapeta2022-02-161-2/+2
|/ | | | | | | | | | | | | 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
* Merge branch 'warn_not_deny' into 'main'eta2022-02-141-1/+1
|\ | | | | | | | | | | | | Change deny(clippy::all) to warn(clippy::all). Closes #338 See merge request tpo/core/arti!306
| * Change deny(clippy::all) to warn(clippy::all).Nick Mathewson2022-02-141-1/+1
| | | | | | | | Closes #338.
* | dirmgr: Remove a useless Ok(x?)Nick Mathewson2022-02-141-1/+1
|/ | | | Found by nightly clippy.
* Allow creating unbootstrapped `TorClient`s (and `DirMgr`s)eta2022-02-111-24/+156
| | | | | | | | | | | | | | | 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
* Make SpawnError wrappers contain a 'spawning' stringNick Mathewson2022-02-041-17/+19
| | | | | (By our convention, these errors should say what we were trying to spawn when the error occurred.)
* tor-dirmgr: Create a bootstrap-status exporting mechanism.Nick Mathewson2022-01-181-1/+43
| | | | | | | | | | | | | | | | | | | | | | 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.
* extend lints to include 'clippy::all'Daniel Eades2021-12-281-0/+1
|
* Refactor directory events to use a FlagPublisher mechanism.Nick Mathewson2021-12-141-44/+12
| | | | | | | | 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.
* Add a few tests to tor-config.Nick Mathewson2021-12-071-3/+2
|
* Make override_net_params take effect sooner.Nick Mathewson2021-12-071-3/+15
| | | | | This is still not as soon as I'd like: a real change here will require refactoring DirMgr::notify().
* Make much of DirMgrConfig reconfigurable.Nick Mathewson2021-12-071-17/+28
| | | | | | | | | | 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.
* Sketch API for reconfiguration.Nick Mathewson2021-12-071-0/+27
| | | | | | | This patch doesn't actually make anything reconfigurable, but it does create an API that will tell you "you can't change the value of that!" If the API looks reasonable, I can start making it possible to change the values of individual items.
* Resolve roughly half of the XXXXs.Nick Mathewson2021-12-061-1/+1
| | | | | | | | We want to only use TODO in the codebase for non-blockers, and open tickets for anything that is a bigger blocker than a TODO. These XXXXs seem like definite non-blockers to me. Part of arti#231.
* dont warn on bootstrap error when error == manager droppeddagon2021-11-301-3/+9
|
* Merge branch 'config-updates-and-tests'Nick Mathewson2021-11-291-1/+1
|\
| * Add basic tests for high-level buildersNick Mathewson2021-11-251-1/+1
| | | | | | | | | | Make sure that we can change elements, and we can reconstruct builders that give us the same thing.
* | add semicolons if nothing returnedDaniel Eades2021-11-251-5/+6
|/
* Rename RetryConfig to DownloadSchedule, fold in parallelism.Nick Mathewson2021-11-181-5/+3
|