aboutsummaryrefslogtreecommitdiff
path: root/crates/tor-dirmgr/src/lib.rs
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* tor-dirmgr: put routerdesc storage behind a feature.Nick Mathewson2021-11-121-5/+16
| | | | | | | (We keep routerdescs in the schema, since we don't want _that_ to fragment.) Part of #125.
* Tests for tor-dirmgr::bootstrapNick Mathewson2021-11-111-1/+1
|
* Minor tests for DirMgr::query_into_requestsNick Mathewson2021-11-111-0/+39
|
* tor-dirmgr: tests for making and expanding consensus requests.Nick Mathewson2021-11-101-0/+125
|
* tor-dirmgr: Tests for high-level loading functions.Nick Mathewson2021-11-101-3/+152
|
* More tests on tor-dirmgr::stateNick Mathewson2021-11-081-1/+1
| | | | | These test our download schedules, resetting to the original state, and storing downloaded objects.
* Mark consensus as "not-pending" even if its microdescs come from cache.Nick Mathewson2021-10-201-3/+23
| | | | | | | Previously our code would clear the 'pending' flag on a consensus only when a _downloaded_ md made it become usable. Closes #199.
* Move tor-dirmgr to use a sync::Mutex.Nick Mathewson2021-10-201-24/+22
| | | | | The futures::lock::Mutex was unnecessary, since we never held it when we were suspending.
* Reverse two swapped log messagesNick Mathewson2021-10-191-2/+2
|
* Improve logging when trying to get the lock on the directory cache.Nick Mathewson2021-10-191-3/+20
| | | | | | Previously we'd say that we were "waiting for the other process to bootstrap" even if it was already bootstrapped: and we wouldn't actually declare success when it was done.
* Remove useless into() conversions caught by clippy.Jani Monoses2021-10-181-11/+11
|
* Remove anyhow dependency from tor-dirmgr.Jani Monoses2021-10-181-5/+4
|
* Add a few tracing directives to tor-dirmgr.Nick Mathewson2021-10-131-1/+3
|
* tor-dirmgr: report bootstrap success on all successful cases.Nick Mathewson2021-10-131-0/+5
| | | | | Previously we would sometimes fail to report that we had successfully bootstrapped.
* Don't report the bootstrap as completed unless it actually succeeds.Nick Mathewson2021-10-131-4/+10
| | | | | (Previously we'd report it as successful even if the inner download task was a failure.)
* Notify guard manager on network change and state flush.Nick Mathewson2021-10-101-0/+12
|
* Re-export configuration types from tor-client.Nick Mathewson2021-10-091-1/+2
|
* enable checked_conversions lint.Nick Mathewson2021-10-091-0/+1
|
* Move all crates into a `crates` subdirectory.Nick Mathewson2021-08-271-0/+690
This will cause some pain for now, but now is really the best time to do this kind of thing.