Commit Graph

514 Commits

Author SHA1 Message Date
Ian Jackson 17002c7462 bridge non-support: Add doc notes to GuardMgrConfig::bridges_enabled 2022-11-21 16:46:19 +00:00
Ian Jackson 939d11c034 bridge non-support: Provide a better BridgeConfigBuilder
This type now does all the things people expect of it: you can (try
to) deserialize it, parse it from a string, and call build on it.
2022-11-21 16:46:19 +00:00
Ian Jackson c4a3b0b5c4 bridge config: Feature-gate the error variants
This leaves this enum empty of actual errors, when bridge-client is
disabled.

We're going to add the not supported variant in a moment.
2022-11-21 16:46:19 +00:00
Ian Jackson 5800b1cdc9 bridge config: Move error to its own file
The dummy module is going to need an error type just like this but
with only the disabled variant.  To avoid that dummy enum getting out
of step with the nontrivial one, we're going to make them the same.

So as a first step, break this out into its own file.
2022-11-21 16:46:19 +00:00
Ian Jackson f087c7121d bridge non-support: Move dummy bridge module into own file
A bit more stuff is going to appear here, so it's getting to be rather
much for an inline module.
2022-11-21 16:46:19 +00:00
Ian Jackson 2c37116149 tor-config: introduce ConfigBuildError::Unsupported
And use it in bridge configuration parsing.
2022-11-21 15:46:53 +00:00
Ian Jackson 681b4062ff bridge config builder: Introduce error constructor helpers (fmt noise) 2022-11-21 15:46:53 +00:00
Ian Jackson 85d7651827 bridge config builder: Introduce error constructor helpers
Prompted by
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/874/diffs?commit_id=12d13428d8fcc68b7b0f231bac9fc130b3eeb18b#d53209cbcd12771c549f3a130379ecb65dd60145_100_193
2022-11-21 15:46:53 +00:00
Ian Jackson b0bd9b3fb3 bridge config builder: Document one id of each type restriction
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/874/diffs?commit_id=620cc90f6dcdad20f49a001a9e04d191a323e904#d53209cbcd12771c549f3a130379ecb65dd60145_100_124
2022-11-21 14:58:24 +00:00
Ian Jackson 897d8a0ee3 bridge config builder: Document PT one address restriction
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/874/diffs?commit_id=620cc90f6dcdad20f49a001a9e04d191a323e904#d53209cbcd12771c549f3a130379ecb65dd60145_100_121
2022-11-21 14:58:24 +00:00
Ian Jackson 9aa1c56fc9 BridgeConfigBuilder: Allow (de)ser to/from bridge lines
That the *de*serialisation works as expected will be tested properly
in just a moment, because when we plumb this all the way through, it
will be what parses the bridge lines in the example config file.
2022-11-21 14:58:24 +00:00
Ian Jackson 345d8e130b BridgeConfigBuilder: Implement FromStr 2022-11-21 14:58:24 +00:00
Ian Jackson cd2070b3ba BridgeConfigBuilder: Introduce build() function
And test cases for it, and its errors.
2022-11-21 14:58:24 +00:00
Ian Jackson 589f74a78f BridgeConfigBuilder: Introduce the struct with the dictionary repr
This struct is going to be the principal "dictionary-style" serde
representation for a bridge, and the builder, making this all in
keeping with our usual approach.

In this commit:
 * Introduce the struct (defining the serialisation)
 * Provide the setters (defining the Rust API)
 * Add success test cases (not all of the data in which is used yet)
2022-11-21 14:58:24 +00:00
Ian Jackson 88b60a1fa7 BridgeAddr rename: update tor_guardmgr::bridge::config
Here is where my motivation is and I'm working on this code now, so do
this renaming cleanup now.
2022-11-21 14:54:39 +00:00
Ian Jackson 7ec52057dc tor-guardmgr: Fix visibility of TestConfig with no features enabled
Without this, tor-guardmgr tests don't build when run without the
crate's own testing feature enabled.
2022-11-18 16:30:46 +00:00
Nick Mathewson c666133be4 Merge branch 'mark-bridges-not-experimental' into 'main'
Mark bridge and PT-related APIs as non-experimental.

Closes #643

See merge request tpo/core/arti!865
2022-11-18 14:22:31 +00:00
Nick Mathewson 471cdc77f2 guardmgr: Make bridge-client and pt-client non-experimental 2022-11-18 08:53:47 -05:00
Nick Mathewson c441853cb8 Merge branch 'log_guard_status' into 'main'
GuardMgr: Log significant guard/bridge status changes at info/warn

Closes #627

See merge request tpo/core/arti!869
2022-11-18 13:51:42 +00:00
Nick Mathewson 8dfbbca4e5 GuardMgr: Log when a guard status changes (significantly).
We previously had a trace message on _every_ change.  That's fine,
but we also want to log more important changes where the user
can see them.  Namely:

  * If we go from any other status to Reachable, we want to tell
    the user. (We don't want to spam them if it was already
    reachable.)
  * If we go from Untried or Reachable to Unreachable, we want to
    tell the user. (We don't tell them about changes from Retriable
    to Unreachable, since that just means that a retry attempt
    was not successful.)

Closes #627.
2022-11-17 12:32:57 -05:00
Nick Mathewson 6c5dd05698 GuardMgr: split Reachable::Unknown into Untried and Retriable
There are two cases here, and we will want to log them
differently.

(By removing the "Unknown" variant entirely, we ensure that we
didn't miss any code that formerly checked for Unknown.)
2022-11-17 12:21:06 -05:00
Nick Mathewson 76a89fb178 GuardMgr: Add Instant to update().
This lets us avoid calling `Instant::now()`, when `Runtime::now()`
is what we want.

Unfortunately, there are a bunch of functions that called `update()`
that needed to change.  Fortunately, none of the changes were very
complicated.

Fixes a `TODO pt-client` comment.
2022-11-16 09:56:51 -05:00
Nick Mathewson fd2253cd44 GuardMgr: Rename "now" arg in update() to "wallclock"
I'm about to add an `Instant` argument. By convention, when we have
both, we call the Instant "now".

This commit is a pure renaming.
2022-11-16 09:40:25 -05:00
Nick Mathewson 4a1b3d8954 guardmgr: Remove a now-unneeded "allow(dead_code)" 2022-11-16 09:22:23 -05:00
Nick Mathewson d78cde7dea Allow a subset-only ChanMethod match when looking up a BridgeConfig
If we have a bridge guard that is using Direct connection and it
knows multiple addresses, our code to match it with a BridgeConfig
is wrong, because the BridgeConfig has only one address, and our
code looks for an exact match.

Fixes #642.
2022-11-15 13:53:14 -05:00
Ian Jackson 232e82491d guardmgr: Document that guardmgr only holds a Weak 2022-11-15 14:39:00 +00:00
Nick Mathewson 79a09ae379 Merge branch 'make_bridges_work' into 'main'
Bugfix: preserve active_set when loading guards

See merge request tpo/core/arti!848
2022-11-14 19:40:26 +00:00
Nick Mathewson 2f5f066d85 Merge branch 'report_missing_descs' into 'main'
GuardMgr: Update desired bridge descs from 'update' function.

Closes #622

See merge request tpo/core/arti!847
2022-11-14 19:15:12 +00:00
Nick Mathewson ec2e432bee Preserve active_set when loading guards. 2022-11-14 13:50:59 -05:00
Nick Mathewson 92115aa366 GuardMgr: Update desired bridge descs from 'update' function.
There are some new TODOs here for us to think about, but I think
this will give us something to test.
2022-11-14 13:36:10 -05:00
Nick Mathewson 0f4c7a477a GuardSet: Add a method to report which bridge descs we want. 2022-11-14 13:36:10 -05:00
Ian Jackson b41becec56 Merge branch 'guardmgr' into 'main'
Move guardmgr creation to arti-client, rather than within circmgr

See merge request tpo/core/arti!850
2022-11-14 17:01:31 +00:00
Ian Jackson 9ecda958a4 Document Clone semantics of GuardMgr and DirMgr 2022-11-11 16:55:56 +00:00
Ian Jackson 9a979cf2c4 cfg-ify an import 2022-11-11 16:54:01 +00:00
Nick Mathewson 9c9f9bbd25 Merge branch 'guardmgr-todo-misc' into 'main'
Resolve most "TODO pt-client" comments in GuardMgr

See merge request tpo/core/arti!840
2022-11-10 17:50:34 +00:00
Nick Mathewson b91f7d61b3 GuardMgr: Explain why we timestamp BridgeSets as we do. 2022-11-10 12:11:28 -05:00
Nick Mathewson f5a5e310a8 GuardMgr: Downgrade a pt-client TODO about an internal API 2022-11-10 12:11:28 -05:00
Nick Mathewson 8cf04d2a38 GuardMgr Document why a BridgeSet has trivial weight thresholds.
This is the only way I could find in which parameter interpretation
differs between bridge guards and relay guards; with it documented,
I can remove a TODO about identifying such ways.
2022-11-10 12:11:28 -05:00
Nick Mathewson 01def7cf86 GuardMgr: once more, fix our n_primary_dir_info check.
Have the check only apply to non-bridge universes, and explain why
in a bunch more comments.
2022-11-10 12:11:28 -05:00
Nick Mathewson 11e83d8069 GuardMgr: remove redundant call to extend_sample_as_needed
Previously we would call extend_sample_as_needed in only two places,
one of which called the other unconditionally.  That's obviously not
necessary.

I've selected just one of them (`update_guardset_internal`) since it
fits better with the theme if that function.  I've added comments
explaining what is going on.

This commit also introduces a yes/no enum for "were any guards added
while extending this set". Formerly we had a boolean, but it got
passed around so many times that I think its intent became obscure.
2022-11-10 12:11:28 -05:00
Nick Mathewson 1d4db04e4e GuardMgr: rename n_primary_without_dir_info
What this function actually does is return the number of primary
guards whose presence (by identity) is ambiguous in a current
universe.  The new name and documentation should help avoid
confusion.

The method's old name had led me astray when identifying whether it
should apply to bridges in one case.  This commit also removes the
corresponding `TODO pt-client`.
2022-11-10 12:11:28 -05:00
Nick Mathewson 1ad45f164e Remove TODO to rename for_circuit_usage in favor of #623 2022-11-10 12:11:28 -05:00
Nick Mathewson b8792307ac GuardMgr: Remove TODO to move `mod bridge` to another crate
The code seems happy enough here for now.
2022-11-10 12:11:28 -05:00
Nick Mathewson 942dfc8487 Resolve todo!()s and TODOs around BridgeRelay::HasAddrs.
Also, add a bunch of reminders around these implementations that
`HasAddrs` returns all the address associated with you for GeoIp or
family purposes, even if they are _not_ ones that we should actually
contact you at.
2022-11-10 12:11:28 -05:00
Nick Mathewson 936920b26e bump rust-version to 1.60 in every crate. 2022-11-10 10:57:33 -05:00
Nick Mathewson 9dcfc2bb65 GuardMgr: Docs for BridgeDescProvider 2022-11-08 11:35:35 -05:00
Nick Mathewson 91cfd7ea4a GuardMgr: Remove a TODO pt-client comment.
The BridgeSet type does not necessarily need further changes... and
if it gets them, it won't be because of this comment.
2022-11-08 11:35:35 -05:00
Nick Mathewson ec9e9c86e7 Merge branch 'store' into 'main'
Persistently cache bridge descriptors

Closes #619

See merge request tpo/core/arti!831
2022-11-08 15:10:21 +00:00
Ian Jackson ea369e8385 bridge descs: Rename BridgeDescMgr from BridgeDescManager
This is more consistent with our naming elsewhere.

Suggested-by: Nick Mathewson <nickm@torproject.org>
2022-11-08 14:40:28 +00:00
Nick Mathewson ada3acf6b8 Try to explain exactly what lookup_bridge_circ_target does 2022-11-08 08:10:15 -05:00
Nick Mathewson 0fd41a7faf GuardMgr: Try to explain what is going on with update()
This explanation is slightly complicated by the fact that I think
that one of the calls to update_guardset_internal() is possibly
unnecessary, and that one of the calls that it makes is potentially
ill-advised.

I'm not going to make those changes right now, however, because they
are potentially a little destabilizing.
2022-11-08 08:10:15 -05:00
Nick Mathewson 6591842458 Refactor configured_bridges
Now it is an Option, and is set to None if bridges aren't enabled.

This simplifies `replace_bridge_config` a bit, and forces us to
check for `None` in a few more places.
2022-11-08 08:10:15 -05:00
Nick Mathewson 2a5b4d21e3 GuardMgr: Document that providers should only be installed once.
Enforce this with assert!() and a documented panics section.
2022-11-08 08:10:15 -05:00
Nick Mathewson 9fda8d17c4 GuardMgr: Fix build with bridge-client disabled. 2022-11-08 08:10:15 -05:00
Nick Mathewson 6bcce19655 GuardMgr: Remove no-longer-relevant `TODO pt-client` comments
Also remove a bunch of now-unnecessary `allow(dead_code)`
annotations.
2022-11-08 08:10:15 -05:00
Nick Mathewson 1418ec13a8 GuardMgr: Rename an error variant 2022-11-08 08:10:15 -05:00
Nick Mathewson 3943c6cd1e GuardMgr: Spelling fixes and normalizations. 2022-11-08 08:10:15 -05:00
Nick Mathewson 3f3d82ee48 GuardMgr: do not use fallbacks when in bridge mode. 2022-11-08 08:10:15 -05:00
Nick Mathewson 5c3bb3d7e1 GuardMgr: When possible, return a FirstHop that can be a CircTarget
We do this by checking the FirstHops we're about to return, and when
they correspond to bridges, looking up an appropriate BridgeRelay
in the current BridgeSet (if we can).
2022-11-08 08:10:15 -05:00
Nick Mathewson 25d7924832 GuardMgr: Refactor UniverseRef to contains Arcs.
We already _have_ these Arc<>s whenever we construct a UniverseRef,
so there's no real point in using &refs and making these so
hard to construct.
2022-11-08 08:10:15 -05:00
Nick Mathewson 7fa08140cf GuardMgr: Remove an outdated "Limitations" comment.
Found while grepping for NetDir.
2022-11-08 08:10:15 -05:00
Nick Mathewson e1ef939ebd GuardMgr: do not block netdir if we are using bridges
The `GuardMgr` code has functionality to tell the DirMgr "Hey,
don't switch to the new NetDir yet: we still need more guard
information!"  But we never want to do that if we're selecting
bridges, since they don't come from the NetDir.
2022-11-08 08:10:15 -05:00
Nick Mathewson 1a4fbb2c3f GuardMgr: Add UniverseType to make code more explicit.
Instead of duplicating the logic about which guard sample uses which
universe, we explicitly ask it, and then use that universe.  This
will avoid trouble if/when we introduce more samples.
2022-11-08 08:10:15 -05:00
Nick Mathewson d395ae75a5 GuardMgr: Launch a background task to keep the list of bridge
descriptors updated as appropriate.
2022-11-08 08:10:15 -05:00
Nick Mathewson e93ee14270 GuardMgr: Exit keep-netdir-updated task early if GuardMgr disappears. 2022-11-08 08:10:15 -05:00
Nick Mathewson 697a355a21 GuardMgr: Pass correct universe to "Bridges" `GuardSet`.
This can probably be done in a simpler way, but for the moment I
would prefer to try to minimize the amount of code I'm changing
here.
2022-11-08 08:10:15 -05:00
Nick Mathewson f4149cd133 GuardMgr: Change BridgeSet, BridgeRelay to use more references
This will match our needs better and help avoid some `Arc<>`s.

It will be especially helpful for avoiding `Arc`s we don't
actually have.
2022-11-08 08:10:15 -05:00
Nick Mathewson 51a98883c8 GuardMgr: Store bridge configuration.
I'm using an Arc<[]> here though I think that there's a chance
that a simple Vec<> would suffice. Since it's an internal type,
nothing will break if we change it later.

Also, we now switch into and out of the Bridges guard sample
as needed.  However, that selection is not (yet) built from the
list of bridges.  That will come soon.
2022-11-08 08:10:15 -05:00
Nick Mathewson 188b9c0f86 GuardMgr: Remove duplicate code in set_filter 2022-11-08 08:10:15 -05:00
Nick Mathewson 04bcf69749 GuardMgr: Clarify intent with update_active_set.
Also fix its behavior when using bridges.
2022-11-08 08:10:15 -05:00
Nick Mathewson ad47b28f2f GuardMgr: Split `update_internal` into two functions.
The first part changes which guard set is active based on based on
the parameters, which always come from a NetDir; the second changes
the contents of the active guard set, based on a Universe.
2022-11-08 08:10:15 -05:00
Nick Mathewson 95a95076a7 Refactor external guardmgr APIs: Stop taking NetDir arguments.
These arguments were used only for legacy (testing) purposes; the
tests now use `TestNetDirProvider`.  This lets us simplify our
internal logic for passing a `NetDir` to our samples, and prepare
for having a `BridgeSet` to pass there instead.

This is a breaking change to `guardmgr` and `circmgr`.
2022-11-08 08:10:15 -05:00
Nick Mathewson 6b94bc5e4c Add an accessor for the latest BridgeDescList. 2022-11-08 08:10:15 -05:00
Nick Mathewson faf51702ac Implement GuardMgr::install_bridge_desc_provider 2022-11-08 08:10:15 -05:00
Nick Mathewson 5cb9e1987e Require Send+Sync for BridgeDescProvider
We require these for NetDirProvider, so this shouldn't be a big reach.
2022-11-08 08:10:11 -05:00
Ian Jackson 85035c7c5a bridge desc: Make BridgeDescProvider DynClone
This allows the use of Box<dyn BridgeDescProvider> in callers,
since Box<dyn BridgeDescProvider> is now Clone.
2022-11-07 11:56:41 +00:00
Dimitris Apostolou 9c7d1802f5
Fix typos 2022-11-06 06:51:58 +02:00
Nick Mathewson 7d079ade3b Merge branch 'warning' into 'main'
tor-guardmgr: use imported WeightThreshold in one place

See merge request tpo/core/arti!825
2022-11-03 16:25:37 +00:00
Ian Jackson 7d6f5d5eab guardmgr config: Provide bridge information to new and reconfigure 2022-11-03 15:48:07 +00:00
Ian Jackson aa375e2e09 tor-guardmgr: use imported WeightThreshold in one place
Without this, an unused import warning is generated when building
without features.
2022-11-03 15:44:32 +00:00
Ian Jackson 5bc3934fb4 bridges config: Provide uninhabited placeholder
This will avoid having to make bridge-related trait features in
GuardMgr conditional, which would be non-additive.
2022-11-03 15:43:41 +00:00
Ian Jackson 6c64be06a6 guardmgr config: Introduce and require new GuardMgrConfig trait
It doesn't seem to me like it makes sense to provide the backward
compatibility here.
2022-11-03 15:43:41 +00:00
Ian Jackson 2bfce54959 guardmgr config: Pass fallback list from config by reference
This does involve additional cloning.  However, soon it will mean that
we can pass the whole `TorClientConfig` by reference.
2022-11-03 15:43:41 +00:00
Nick Mathewson 932fe48eaf Run add_warnings. 2022-11-03 11:06:02 -04:00
Ian Jackson 48f48841e1 Require derive_more 0.99.3
0.99.[012] have a bug https://github.com/JelteF/derive_more/issues/114
which makes the Deref derive for bridgedesc::StateGuard not work
and therefore breaks minimal-versions CI.

It seems simpler to require the newer version everywhere.
2022-11-03 11:37:23 +00:00
Nick Mathewson 66f34ee774 Merge branch 'guards_as_bridges_part3' into 'main'
GuardMgr: decouple NetDir from guards and sample code.

See merge request tpo/core/arti!815
2022-11-02 12:41:03 +00:00
Nick Mathewson c2ed381c99 Refactor CandidateStatus API to simplify code in descs.
This removes some duplication.
2022-11-02 08:07:32 -04:00
Nick Mathewson fc0c12510a GuardMgr: Fix and improve comments based on review. 2022-11-02 08:07:32 -04:00
Nick Mathewson 6828178dec guardmgr: fix rustdoc references. 2022-11-02 08:07:32 -04:00
Nick Mathewson 08473872ab guardmgr: Refactor candidate info; add `full_dir_info`
Previously we always set `dir_info_missing` to `false` for new
guards, since new guards could only be taken from ones that were
present in the NetDir.  But for bridges, we don't download their
info until _after_ we have chosen them as guards.
2022-11-02 08:07:11 -04:00
Nick Mathewson 5867318a35 guardmgr: Implement Universe for bridges.
Now we can use a group of bridges as the basis for a sample of
guards.
2022-11-02 08:06:43 -04:00
Nick Mathewson 79dade342a guardmgr: Universe API should look up by ChanTarget
This will be necessary for bridges.
2022-11-02 08:06:43 -04:00
Nick Mathewson 82e9a57012 guardmgr: take sampled guards from Universe.
This is a trickier case, since we have to deal with weights.
2022-11-02 08:06:43 -04:00
Nick Mathewson 7733146c8c guardmgr: Continue porting porting code to use Universe.
Two more simple cases that can use Universe instead of Netdir.
2022-11-02 08:06:20 -04:00
Nick Mathewson fbcacea993 guardmgr: Begin to decouple guards from NetDir.
In this and the upcoming commits I'll be changing how guards related
to `NetDir` and to `Relay`.  Previously, a guard could only come
from (or be updated from) a `Relay` in a `NetDir`.  Soon it will be
able to be built from a bridge as well.

To do this, I'm defining a `Universe` trait (name negotiable) that
represents a set of things that may be guards.  I'm going to
continue extending its functionality until there are no more
methods in guard.rs or sample.rs that take `NetDir`.

This commit removes most of the usage of `NetDir` and `Relay` in
`guard.rs`.
2022-11-02 08:05:51 -04:00
Nick Mathewson b5f498021d guardmgr: Rename microdescriptor_missing to dir_info_missing 2022-11-02 07:59:56 -04:00
Nick Mathewson 39ea0518ee guardmgr: Allow guards to be constructed from any ChanTarget. 2022-11-02 07:59:56 -04:00
Nick Mathewson 1cb6ea1e77 guardmgr: Include PtTarget in guards.
Use a vector, since we may (someday) want to allow a Guard to have
multiple PtTargets.
2022-11-02 07:59:56 -04:00
trinity-1686a e6e064ac8a remove unused dependancies 2022-10-29 13:29:55 +02:00
Nick Mathewson 29c46d08b5 Merge branch 'guards_as_bridges_part2' into 'main'
Use ByRelayIds to hold guards in GuardSet

See merge request tpo/core/arti!808
2022-10-27 21:09:47 +00:00
Nick Mathewson 557a07677e guardmgr: Rename and clarify of non-persistent-state copy fns
These will need a bigger overhaul: see #612 and #611.
2022-10-27 16:40:35 -04:00
Ian Jackson 4f171acaf7 Clarify fix_consistency 2022-10-27 16:40:35 -04:00
Ian Jackson 7180079112 Clarify what it means to be "an identity" for a primary guard. 2022-10-27 16:40:35 -04:00
Ian Jackson 15d464a929 tor-guardmgr: Add big doc comment about guard id handling 2022-10-27 16:40:35 -04:00
Ian Jackson 26a7aa9aa6 BridgeDescProvider: Make BridgeDescEvent repr(u16) and derive traits
This will enable us to impl FlagEvent for it.
2022-10-27 15:57:54 +01:00
Ian Jackson a56efbfdf0 impl Hash for BridgeConfig and various PT information
The bridge descriptor manager wants to index data structures by the
BridgeConfig.
2022-10-27 15:57:54 +01:00
Ian Jackson a89daba1c8 tor-guardmgr: bridges: export BridgeDescError at toplevel 2022-10-27 15:57:54 +01:00
Nick Mathewson 20016df6fa guardmgr: Use new ambiguity-tolerant contains in state handling
This has subtleties; the comments try to explain them.
2022-10-25 11:15:53 -04:00
Nick Mathewson d65c351b33 guard sample: Change semantics of `contains` to handle ambiguity.
This is necessary for the (somewhat undesirable) lookup_ids function
to return an ID that the dirmgr can actually use to report successes
and failures.

As noted, lookup_ids will create problems down the road when we
implement relays. We should refactor it out before then.
2022-10-25 11:15:53 -04:00
Nick Mathewson 28f2e2997e Replace contains_relay with can_add_relay().
To see if we can add a relay as a guard, we need a conservative
test: any IDs in common with the given relay prevent us from adding
it.
2022-10-25 11:15:53 -04:00
Nick Mathewson 3a994c32dc Convert guard samples to use ByRelayIds.
This required a number of changes, which I've tried to document.
I've taken a conservative approach to modification, and I'm not
using any of the by_*_mut() functions (yet).  For cases which
potentially modify the whole set, I'm using into_values() and
collect() to ensure that it's re-indexed correctly, even though the
identities don't change.

I introduce some "TODO pt-client" comments here which I will resolve
in the next commit(s).
2022-10-25 11:15:53 -04:00
Ian Jackson f7e5892e40 BridgeDescEvent: Change the sole variant to SomethingChanged
And explain what this all means.
2022-10-25 15:32:56 +01:00
Nick Mathewson 8528d61a78 impl HasRelayIds for GuardId. 2022-10-25 09:23:28 -04:00
Nick Mathewson 40ec12b0cb Merge branch 'guards_as_bridges_part1' into 'main'
Allow GuardMgr to expose bridges as guards (part 1)

See merge request tpo/core/arti!785
2022-10-24 13:30:02 +00:00
Nick Mathewson bb117a4bd4 guardmgr: Refactor the interior of FirstHop.
Now it contains either an `OwnedChanTarget` or an `OwnedCircTarget`,
which will let `GuardMgr` return bridges that can be used to make
circuits.

As part of this change, it was necessary to revise some
address-modification functions that applied to filters and
`OwnedChanTarget`.  Now they do the smart thing, and remove only the
address that are in the `ChanMethod`.  This means that the addresses
from HasAddrs are still accurate about which addresses the relay
"has".
2022-10-24 08:59:12 -04:00
Ian Jackson 0924fb3623 tor-guardmgr: descs: Make BridgeDescError DynClone 2022-10-21 16:22:17 +01:00
Ian Jackson f4ec3e6cec tor-guardmgr: descs: Make BridgeDescError into a trait 2022-10-21 16:22:13 +01:00
Nick Mathewson fa1d2f453a guardmgr: Hold FallbackDir in fallback::set::Entry
This resolves an old TODO, and will simplify our work a little.
2022-10-21 09:21:43 -04:00
Nick Mathewson 19fdf196d8 guardmgr: Add bridges sample, encode sample ID in FirstHopId.
The most important part of this commit is to make sure that each
`FirstHopId` includes the `GuardSetSelector` from which the guard
was selected.  Doing this lets us be certain that when we report
that a guard has succeeded or failed, we're reporting it in the
right context.

Additionally, this commit uses strum to make an iterator over the
samples, so that we can make sure that our "for each sample" code is
robust against future changes, and we don't miss the bridge sample.
2022-10-21 09:21:43 -04:00
Ian Jackson 803131c1ea Merge branch 'bridge-internal-apis' into 'main'
Use BridgeConfig to identify bridges in two places

See merge request tpo/core/arti!781
2022-10-20 16:14:14 +00:00
Ian Jackson 9c7ea41322 impl ChanTarget etc. for BridgeConfig 2022-10-20 14:16:34 +01:00
Ian Jackson 11c61a3d7f bridge descriptors: Change types of the descriptor cache
Now keyed by Arc<BridgeConfig>, and the values can be errors.

Currently there is no implementation so there can't be any errors,
but the error enum will become nonempty.
2022-10-20 13:28:23 +01:00
Nick Mathewson 2845ee24bf fix a couple of spelling errors in guardmgr 2022-10-19 07:49:39 -04:00
Nick Mathewson b4cc98b21b Merge branch 'readmes' into 'main'
Abolish maint/readme and use doc include

Closes #603

See merge request tpo/core/arti!768
2022-10-12 15:16:18 +00:00
Ian Jackson f84d8777db cargo fmt to remove blank lines
Apparently cargo fmt doesn't like these, which my perl rune didn't
delete.

This commit is precisely the result of `cargo fmt`.
2022-10-12 15:29:04 +01:00
Ian Jackson d9910dba08 Replace all README copies in src/lib.rs with includes
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
2022-10-12 15:29:03 +01:00
Ian Jackson 19de971775 struct BridgeConfig: Rename from Bridge
Fixes #599
2022-10-12 13:54:25 +01:00
Ian Jackson 029a11c833 struct Bridge: add ref to ticket 2022-10-12 13:51:52 +01:00
Ian Jackson f9e841841a tor-guardmgr: Export BridgeParseError from toplevel
Callers could `use` it as `tor_guardmgr::config::BridgeParseError` but
it seems unecessary to force them to.
2022-10-12 13:50:29 +01:00
Ian Jackson 82ad9eea5f Allow "clippy::single_char_pattern" in tests.
This lint exists for perf reasons, and this is rarely relevant in
tests.

Using double quoted str is generally cognitively less burdensome.
2022-10-12 13:50:29 +01:00
Nick Mathewson 74d4c73d09 Change multiplicity of ChannelMethod and addresses
Now each `ChanTarget` has at most one `ChannelMethod`, and only
`Direct` `ChannelMethods` can have multiple addresses.

Closes #600.
2022-10-11 08:53:31 -04:00
Ian Jackson 85464bc770 tor-guardmgr: Fix build without pt-client feature 2022-10-11 12:22:46 +01:00
Nick Mathewson 299ebd729d tor-linkspec: Remove the old OwnedFoo::new() functions
These are now builders.
2022-10-06 15:13:05 -04:00
Nick Mathewson ce09b7c96f Begin revising HasAddr and its relationship to ChanTarget
HasAddr used to mean "Here are addresses that I have, at which I can
be contacted."  But "Where (and how) can I be contacted?" is now a
question for HasChannelMethod to answer.

(We still need to have "HasAddr", though, so we can answer things
like "what country is this relay in" and "are these relays in the
same /8?")

So this commit introduces:
  * A new trait for adding an implementation of HasChannelMethod in
    terms of HasAddr.
  * A requirement on ChanTarget that it needs to implement
    HasChannelMethod.

There is some temporary breakage here, marked with "TODO pt-client",
that I'll fix later in this branch.
2022-10-06 15:13:05 -04:00
Nick Mathewson 1d70bf4ddd Merge branch 'bridge_containers' into 'main'
Start implementing more data structures to hold Bridge descriptors.

See merge request tpo/core/arti!755
2022-10-06 17:16:44 +00:00
Nick Mathewson 3f419f7f65 Extend some comments about bridge descriptors 2022-10-06 12:56:28 -04:00
Nick Mathewson fac975ddfb Add a temporary HasAddrs for BridgeRelay
See comment for an explanation of the next issue here.
2022-10-04 17:53:40 -04:00
Nick Mathewson 23b3b0553f BridgeRelay: Implement more traits.
Also add a BridgeRelayWithDesc type (name tbd) to guarantee that
a bridge relay really does have a known descriptor before you
try to build a circuit with it.
2022-10-04 17:49:32 -04:00
Nick Mathewson d9e3d38bd6 Start on a new BridgeRelay type.
This is the one we'll actually use to connect to bridges. It
has a `Bridge` line, and an optional `BridgeDesc`.

Maybe this will turn into a `BridgeRelay<'a>` by analogy to `Relay`
some time; I'm not sure.
2022-10-04 17:49:32 -04:00
Nick Mathewson 013b9bff1b Implement HasRelayIds for Bridge. 2022-10-04 17:49:32 -04:00
Nick Mathewson d4f26581c0 Implement BridgeDesc and BridgeDescList.
BridgeDesc is a separate type to make sure that we do not confuse
bridges' descriptors with the descriptors from other routers down
the road.  (Bridges' descriptors need to be used differently, and
treated as more private.)

With this code, BridgerDescList is now just an alias for
`ByRelayIds<BridgeDesc>`, which is pretty keen.
2022-10-04 17:49:32 -04:00
Nick Mathewson 6341057129 Temporarily suppress a false positive from nightly.
Nightly rust gives a warning about this "pub use", but the warning
is a false positive.  Since it doesn't seem to be going away in a
hurry, let's suppress it for now.
2022-10-04 16:40:34 -04:00
Ian Jackson 9705ef3fea Merge branch 'bridge-parse' into 'main'
Parse (and format) bridge lines

See merge request tpo/core/arti!745
2022-10-03 20:13:02 +00:00
Ian Jackson 193d0f7007 pt: bridge line parsing: overhaul errors
Include the offending word in all the applicable errors.
Always print it with {word:?}.

As a consequence, there are no From impls any more and error
generation/conversion is by hand in all cases.

Clarify InvalidPtOrAddr vs InvalidIAddrorPt, and don't make the
attempted parse be a source error for those.

Where we still have source errors, don't print them in Display.
2022-10-03 20:45:54 +01:00
Ian Jackson 00fb96650b pt: Check PT key=value syntax
This is not perfect but it at least ensures that our own parsing and
printing code works correctly with all the values we accept.
2022-10-03 20:45:54 +01:00
Ian Jackson b67b5ac536 pt: Make PtTarget::push_setting fallible, and take Into
It has its own error type PtTargetInvalidSetting.

In check_doc_features, adjust suppression to new code.
2022-10-03 20:45:54 +01:00
Ian Jackson a237b80ad8 pt: bridge line parsing: Add commentary 2022-10-03 20:45:54 +01:00
Ian Jackson f6a6fe0d8e pt: Document Bridge line syntax 2022-10-03 20:45:54 +01:00
Nick Mathewson 88a06225b9 Remove semver.md files now that arti 1.0.1 is out. 2022-10-03 14:16:56 -04:00
Nick Mathewson 102e3c221d Bump minor version of tor-rtcompat and most of its dependents
(Since the APIs for the `Schedule::sleep*` functions changed, this
is a breaking change in tor-rtcompat.  Therefore, the Runtime trait
in tor-rtcompat is now a different trait.  Therefore, anything that
uses the Runtime trait in its APIs has also broken.)
2022-10-03 10:01:46 -04:00