summaryrefslogtreecommitdiff
path: root/crates/tor-guardmgr/src/guard.rs
Commit message (Collapse)AuthorAgeFilesLines
* tor-netdir: Collapse by_id and by_relay_id into a single fn.Nick Mathewson2022-08-101-1/+2
| | | | | | There are some downstream changes required for this to work, but they are all just unit tests that could no longer infer the type of an Ed25519 key.
* Final (?) API revisions for tor-linkspecNick Mathewson2022-08-101-8/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With this change, each individual identity type becomes optional. The functions that expose them unconditionally are now in a "legacy" trait that only some downstream types are expected to implement. There are new convenience APIs in HasRelayIds: * to return Option<&keytype>, * to see if one identity-set contains another. This commit will break several downstream crates! For the reviewer's convenience, I will put the fixes for those crates into a series of squash! commits on this one. tor-netdir ---------- Revise tor-netdir to accept optional identities. This required some caveats and workarounds about the cases where we have to deal with a key type that the tor-netdir code does not currently recognize at all. If we start to add more identity types in the future, we may well want more internal indices in this code. tor-proto --------- In order to make tor-proto support optional identities, there were fewer changes than I thought. Some "check" functions needed to start looking at "all the ids we want" rather than at "the two known IDs"; they also needed to accommodate that case where we don't have an ID that we demand. This change will also help with bridges, since we want to be able to connect to a bridge without knowing all of its IDs up front. The protocol currently _requires_ the two current ID types in some places. To deal with that, I added a new `MissingId` error. I also removed a couple of unconditional identity accessors for chanmgr; code should use `target().identity(...)` instead. tor-chanmgr ----------- This is an incomplete conversion: it does not at all handle channel targets without Ed25519 identities yet. It still uses those identities to index its internal map from identity to channel; but it gives a new `MissingId` error type if it's given a channel target that doesn't have one. We'll want to revise the map type again down the road when we implement bridges, but I'd rather not step on the channel-padding work in progress right now. tor-guardmgr ------------ This change is mostly a matter of constructing owned identity types more sensibly, rather than unwrapping them directly. There are some places marked with TODOs where we still depend on particular identity types, because of how the directory protocol works. This will need revisiting when we add bridge support here. tor-circmgr ----------- These changes are just relatively simple API changes in the tests.
* Introduce a RelayIdSet and use it in place of HashSet<RelayId>.Nick Mathewson2022-08-101-6/+1
| | | | | This makes lookups a little more efficient. I do with that HashSet just supported this use-case, but for now this seems our best option.
* Teach guard restrictions about RelayId.Nick Mathewson2022-08-101-11/+20
| | | | | This implementation is (sadly) too copy-heavy or now, because HashSet<RelayId> can't be indexed with RelayIdRef.
* netdir: Add and use a new ids_listed() function.Nick Mathewson2022-08-021-1/+1
|
* Introduce HasRelayIds::same_relay_ids.Nick Mathewson2022-08-021-5/+3
| | | | | This method tells if two HasRelayIds contain exactly the same set of Relay identities, and is generally useful for debugging.
* guardmgr: Replace IdPair with RelayIdsNick Mathewson2022-08-021-9/+9
| | | | I believe that this was the original motivation behind #428.
* tor-linkspec: Refactor out traits to represent a relay's ID set.Nick Mathewson2022-08-021-2/+8
| | | | | | | | | | | | | | We want the set of identities supported by a relay to be extensible in the future with minimal fuss; we'd also like to make working with these ID sets more convenient. To handle that, this commit adds a new trait for "Something that has the same IDs as a relay" and a new object for "an owned representation of a relay's IDs." This commit introduces a similar trait for "Something with a list of SocketAddr, like a relay has." There's no owned equivelent for that, since Vec<SocketAddr> is already a thing. Closes #428.
* tor-netdir: testnet: Make construct_netdir infallible (rustfmt)Ian Jackson2022-06-131-6/+2
| | | | | Run rustfmt. Separate commit to make review of the substantive commit easier.
* tor-netdir: testnet: Make construct_netdir infallibleIan Jackson2022-06-131-2/+0
| | | | | This is a *lot* of unwraps. The function takes no parameters and is used only for testing. It ought to be infallible.
* GuardUsage: restrictions: Use list builderIan Jackson2022-05-041-27/+30
| | | | | | | | | | | | | | Although these do not appear in the config, it does have a builder. It seems sensible to get rid of this ad-hoc list manipulation site, and replace it with our standard list builder API. define_list_builder_helper requires that the builder element type be Deserialize. Currently GuardUsageRestriction is a transparent, public enum, so we aren't really exposing anything. We could introduce GuardUsageRestrictionBuilder now, but since it's not in the config and thereofore only in the public API of the lower crates, we can definitely put that off.
* Initial functions to determine and expose a clock skew estimate.Nick Mathewson2022-04-071-0/+6
| | | | | (This is just a placeholder; I'm going to make the functions smarter in the next commit.)
* GuardMgr: record clock skew information.Nick Mathewson2022-04-071-0/+12
| | | | (It is not yet actually used.)
* GuardMgr: Tests for copy_status_from.Nick Mathewson2022-04-051-0/+6
|
* Rewrite and fix Guard::copy_status_from.Nick Mathewson2022-04-051-11/+28
| | | | | | | | | | | | | | The old version of this function was error-prone, and in fact had errors: it was too easy to forget to add non-persistent fields, and that's exactly what we forgot in a few cases (`microdescriptor_missing`, `circ_history`, and `suspicious_behavior_warned`). The new version of this function consumes both of the incoming Guards, and constructs every field explicitly so that we can't forget to list any. Closes #429.
* GuardMgr: Track directory status and circuit status separately.Nick Mathewson2022-04-051-5/+127
| | | | | | | | | | | | | Previously, we treated successfully building a circuit to a guard as a "success", and any failure, including a directory cache failure, as a failure. With this change, guards now have separate success/failure and retry status for circuit usage and directory usage. This change is needed for guard-as-directory retry to have reasonable behavior. Otherwise, when a guard succeeds at building a circuit, that clears the directory-is-failing status and makes us retry the guards to quickly.
* Fix some Rustdoc links.Nick Mathewson2022-03-301-1/+1
|
* Refactor FirstHopId into type-differentiated formNick Mathewson2022-03-301-35/+29
| | | | | | | | | | | 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-13/+21
| | | | | This is preparation for having separate GuardId and FirstHopId types that distinguish which back-end they index.
* Remove allow(clippy::disallowed_methods) lint.Nick Mathewson2022-03-301-6/+0
|
* Merge branch 'no-system-time' into 'main'eta2022-03-301-2/+9
|\ | | | | | | | | | | | | Don't use SystemTime::now() Closes #306 See merge request tpo/core/arti!365
| * use wallclock where possible in teststrinity-1686a2022-02-261-2/+9
| |
* | GuardMgr:: generalize GuardId::from_relay.Nick Mathewson2022-03-211-1/+5
| |
* | GuardMgr: revise handling of "all guards are down".Nick Mathewson2022-03-211-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When all guards are down, we would previously mark them all as up, and retry aggressively. But that's far too aggressive: if there's something wrong with our ability to connect to guards, it makes us hammer the network over and over, ignoring all the guard retry timeouts in practice. Instead, * We now allow the `pick_guard()` function to fail without automatically retrying. * We give different errors in the cases when all our guards are down, and when all of the guards selected by our active usage are down. * Our "guards are down" error includes the time at which a guard will next be retriable. This is part of #407.
* | GuardMgr: use decorrelated-jitter backoff for retrying guards.Nick Mathewson2022-03-211-80/+34
| | | | | | | | | | | | | | | | | | | | | | | | C tor used one schedule, and guard-spec specified another. But in reality we should probably use a randomized schedule to retry guards, for the reasons explained in the documentation for RetrySchedule. I've chosen the minima to be not too far from our previous minima for primary and non-primary guards. This is part of #407.
* | Replace manual Default impls with educe in tor-guardmgrIan Jackson2022-03-021-7/+4
|/
* Tests for new guardmgr functionality.Nick Mathewson2022-01-061-0/+51
|
* Add API to check if primary MDs are missing.Nick Mathewson2022-01-061-1/+11
| | | | | | | We need this information to know if it's okay to migrate to a new NetDir, or if we need to download more information first. Part of #178.
* guardmgr: Don't use no-md guards for data circs.Nick Mathewson2022-01-061-5/+31
| | | | | | | If we don't know a current microdescriptor for a guard, we can't use it for multihop circuits, since we don't know its onion keys. This is part of a fix for #178.
* Tests for new family-related functions.Nick Mathewson2021-12-061-0/+23
|
* Use hashset _inside_ GuardRestriction.Nick Mathewson2021-12-061-0/+1
| | | | This approach saves us from a linear search when picking guards.
* Change GuardUsage to have Vec of restrictions.Nick Mathewson2021-12-061-25/+13
| | | | | | | | There's not much reason to use a HashSet here, since we're just going over the whole list. This reverts commit 16e8489abbea1581b8e2 and does a little more refactoring.
* Implement guard family restriction codeNeel Chauhan2021-12-061-6/+20
|
* Fix a clippy issue on nightlyNick Mathewson2021-11-241-0/+1
|
* Fix a few typos.Nick Mathewson2021-11-241-3/+3
| | | | Also fix some commonwealth spellings that had slipped in.
* Fix typo in tor-guardmgr comment related to suspicious guardsNeel Chauhan2021-11-221-1/+1
|
* Remove all remaining dbg! instances.Nick Mathewson2021-11-041-2/+0
|
* tor-guardmgr: Add tests for a few functions.Nick Mathewson2021-11-021-0/+18
|
* Add Futureproof<T> wrapper type, use for GuardDisabled enumeta2021-10-271-6/+4
| | | | | | | | | | | The Futureproof<T> type lets you serialize and deserialize types whose representations might change (most useful for enums that might grow additional variants). It uses #[serde(untagged)] to accomplish this. This gets used in order to make the `disabled` field of `Guard` more robust against future guard disablement reasons being added. A test was also added to verify correct behaviour of the new type.
* Add #[serde(flatten)] HashMap fields to serializable objectseta2021-10-271-2/+8
| | | | | | | | | | As per arti#175, we'd like to be able to handle newer Arti versions storing additional state in the persisted state files, without dropping this data on the floor when we write out changes to these files. Use the #[serde(flatten)] mechanism to achieve this, by adding catch-all HashMap<String, JsonValue> fields to all structs that are at risk of this happening to them.
* Implement a "lightweight" form of pathbias detection.Nick Mathewson2021-10-261-4/+178
| | | | | | | | | | | | | | | | | | | | | | | | | | | We now track, for every guard: the total number of successful circuits we've built through it, along with the total number of "indeterminate" circuits. Recall that a circuit's status is "indeterminate" if it has failed for a reason that _might_ be the guard's fault, or might not be the guard's fault. For example, if extending to the second hop of the circuit fails, we have no way to know whether the guard deliberately refused to connect there, or whether the second hop is just offline. But we don't want to forgive all indeterminate circuit failures: if we did, then a malicious guard could simply reject any second hops that it didn't like, thereby filtering the client into a chosen set of circuits. As a stopgap solution, this patch now makes guards become permanently disabled if the fraction of their circuit failures becomes too high. See also general-purpose path bias selection (arti#65), and Mike's idea for changing the guard reachability definition (torspec#67). This patch doesn't do either of those. Closes #185.
* guardmgr: Don't use guards that are marked as unlisted.Nick Mathewson2021-10-251-0/+5
| | | | Closes #202.
* Implement the guard side of shared state directories.Nick Mathewson2021-10-211-0/+14
|
* Remove Guard::get_relay(); use Guard::guard_id().get_relay().Nick Mathewson2021-10-191-12/+4
| | | | | | | | | The `get_relay` function was confusing, since it would return None if the relay was present, but wasn't actually a guard. We only used it in one place, and in that one place we used it wrong, leading to a panic bug. Fixes #193.
* Make the guard selection function return a more useful type.Nick Mathewson2021-10-111-0/+8
|
* Add a few tracing calls to tor-guardmgr.Nick Mathewson2021-10-081-5/+26
|
* Resolve small issues and XXXX/TODO comments in GuardMgr.Nick Mathewson2021-10-071-1/+1
| | | | | By the time I merge this, most of the comments should have tickets to go with them.
* Initial tests for tor_guardmgr::guardNick Mathewson2021-10-071-0/+295
|
* Initial backend implementation for guard node manager.Nick Mathewson2021-10-071-0/+481
There are some missing parts here (like persistence and tests) and some incorrect parts (I am 90% sure that the "exploratory circuit" flag is bogus). Also it is not integrated with the circuit manager code.