Commit Graph

283 Commits

Author SHA1 Message Date
Ian Jackson 6da7a2e3e2 Use git source for derive_builder for now, for sub_builder feature
This commitid is the current head of my MR branch
  https://github.com/colin-kiegel/rust-derive-builder/pull/253
  https://github.com/ijackson/rust-derive-builder/tree/field-builder
Using the commitid prevents surprises if that branch is updated.

We will require this newer version of derive_builder.  The version
will need to be bumped again later, assuming the upstream MR is merged
and upstream do a release containing the needed changes.

We will need the new version of not only `derive_builder_core` (the
main macro implementation) but also`derive_builder` for a new error
type.
2022-04-21 14:07:28 +01:00
eta 41dd682552 Merge branch 'report-skew' into 'main'
Report skew estimates from arti-client

See merge request tpo/core/arti!455
2022-04-13 12:51:23 +00:00
Nick Mathewson 4582dddca8 circmgr: back off on preemptive circuits if they fail consistently
Rather than running preemptive circuit construction every 10
seconds, we change it to back off when it is "failing".  (We define
"failing" as creating no new circuits, and as giving at least one
error.)

This change means that we'll have one less reason to hammer the
network when our connectivity is failed for some reason.

Closes #437.
Part of #329.
2022-04-12 09:19:10 -04:00
Nick Mathewson 482c022e23 circmgr: Remove now-unused scheduled entry points.
Now that we have TaskSchedule, we don't need to expose these any
longer.
2022-04-12 09:04:10 -04:00
Nick Mathewson 3d5276a9cc circmgr: Report CircProvenance from AbstractCircMgr.
This feature is similar to ChanProvenance from ChanMgr, except that
we don't yet need to report it outside the crate.  I'm going to use
it to distinguish newly created circuits from existing circuits in
the preemptive circuit builder.
2022-04-12 08:41:32 -04:00
Nick Mathewson 72f00daf12 circmgr: re-export clock skew estimates. 2022-04-12 08:03:49 -04:00
Nick Mathewson c3c43b088e Create and use API to report guard/fallback skew.
(The information is not yet recorded.)
2022-04-07 10:47:45 -04:00
Nick Mathewson 0050045867 ChanMgr: Return provenance information from get_or_launch
We need this since we want to report certain conditions only when
they happen on a new channel, not if we observe them on a
preexisting channel.
2022-04-07 10:46:06 -04:00
Nick Mathewson 36440a957c Distinguish UsageMismatch cases by whether a race is possible
This lets us say that the UsageMismatch cases in some parts of the
code reflect a programming error (RetryTime::Never), whereas in
other case it reflects another circuit request getting to the
circuit first (RetryTime::Immediate).
2022-04-04 11:41:00 -04:00
Nick Mathewson 6d8a6b42e7 circmgr: Improve retry-and-or-delay logic.
Use the new RetryTime type and its associates to decide how long to
wait (if at all) between attempts to build a circuit.

Closes #421.

Part of #329.
2022-04-04 11:15:18 -04:00
Nick Mathewson c3b2bcc91e circmgr: implement HasRetryTime. 2022-04-04 11:15:18 -04:00
Nick Mathewson f7810d42eb circmgr: Improve reporting of error origins.
Previously we did not distinguish errors that came from pending
circuits from errors that came from the circuits we were
building.  We also reported errors as coming from "Left" or "Right",
instead of a more reasonable description.
2022-04-04 11:15:18 -04:00
Nick Mathewson 86c59dd1f3 circmgr: Avoid a race condition in circuit usage restriction
We were treating restrict_mut() failures as internal errors, and
using internal errors to represent them.  But in fact, these
failures are entirely possible based on timing.  Here's how it
happens:

* Two different circuit requests arrive at the same time, and both
  notice a pending circuit that they could use.
* The pending circuit completes; both pending requests are notified.
* The first request calls restrict_mut(), and restricts the request
  in such a way that the second couldn't use it.
* The second request calls restrict_mut(), and gets a failure.

Because of this issue, we treat these errors as transient failures
and just wait for another circuit.

Closes #427.

(This is not a breaking API change, since `AbstractSpec` is a
crate-private trait.)
2022-04-04 11:14:52 -04:00
Nick Mathewson 5b2fc118df Bump all arti*, tor* crates to 0.2.0
Not all of these strictly need to be bumped to 0.2.0; many could go
to 0.1.1 instead.  But since everything at the tor-rtcompat and
higher layers has had breaking API changes, it seems not so useful
to distinguish.  (It seems unlikely that anybody at this stage is
depending on e.g. tor-protover but not arti-client.)
2022-04-01 09:15:18 -04:00
Nick Mathewson 432bb5ce62 Use a lower default for max_retries.
The older default seems (experimentally) to be ridiculously high.
Generally, if we can't build a circuit within a handful attempts,
that circuit has already timed out... unless there is a fast-failure
condition, in which case we're just hammering the network (or our
view of it.)

Found with `arti-testing` for #329.
2022-03-30 14:22:28 -04:00
Nick Mathewson bd798764a4 circmgr: limit circuit attempts when launch_parallelism > 1.
Previously, if we had launch_parallelism > 1, and we were willing to
retry building a circuit max_retries times, then we'd launch up to
max_retries * launch_parallelism circuits before giving up.  Ouch!

With this patch, we try to keep the total number of circuits
planned and attempted to the actual max_retries limit.

Part of #329; found with arti-testing.
2022-03-30 14:14:52 -04:00
Nick Mathewson 2bb3ba7886 Run cargo fmt one more time for good measure. 2022-03-30 10:41:57 -04:00
Nick Mathewson 1feb7eecac Reformat several Cargo.toml files with 100-char-wide lines. 2022-03-30 10:41:40 -04:00
Nick Mathewson 6282df34fb Refactor FirstHopId into type-differentiated form
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.
2022-03-30 10:41:39 -04:00
Nick Mathewson 13af6134f6 Rename Guard=>FirstHop, GuardId=>FirstHopId
This is preparation for having separate GuardId and FirstHopId types
that distinguish which back-end they index.
2022-03-30 10:40:59 -04:00
Nick Mathewson 951b800988 DirPathBuilder::pick_path: re-order match cases for clarity. 2022-03-30 10:40:14 -04:00
Nick Mathewson bdd129f230 Rename ExternalFailure => ExternalActivity. 2022-03-30 10:40:12 -04:00
Nick Mathewson d88e9d676e Replace the fallback directories when they change in the config.
The code here uses a new iterator type, since I couldn't find one of
these on crates.io.  I tried writing the code without it, but it was
harder to follow and test.
2022-03-30 10:39:09 -04:00
Nick Mathewson bfb2353a8f Add status tracking to FallbackDir.
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.
2022-03-30 10:39:09 -04:00
Nick Mathewson ed6389acc7 circmgr: Use guard-manager's view of the fallbacks when possible.
If we're building a path with the guard manager involved, we now ask
the guard manager to pick our first hop no matter what.  We only
pick from the fallback list ourselves if we're using the API with no
guard manager.

This causes some follow-on changes where we have to remember an
OwnedChanTarget object in a TorPath we've built, and where we gain
the ability to say we're building a path "from nothing extra at
all."  Those are all internal to the crate, though.

Closes #220, by making sure that we use our guards to get a fresh
netdir (if we can) before falling back to any fallbacks, even if our
consensus is old.

Compilation should be fixed in the next commit.
2022-03-30 10:39:09 -04:00
Nick Mathewson 9da43189f3 Turn FallbackList into a real type, and store one in GuardMgr.
The guard manager is responsible for handing out the first hops of
tor circuits, keeping track of their successes and failures, and
remembering their states.  Given that, it makes sense to store this
information here.  It is not yet used; I'll be fixing that in
upcoming commits.

Arguably, this information no longer belongs in the directory
manager: I've added a todo about moving it.

This commit will break compilation on its own in a couple of places;
subsequent commits will fix it up.
2022-03-30 10:39:06 -04:00
Nick Mathewson 6397b56317 Reformat tor-circmgr/Cargo.toml 2022-03-30 10:34:50 -04:00
Nick Mathewson 80b65c3a4d Move fallback.rs into guardmgr.
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.
2022-03-30 10:34:48 -04:00
eta 5d27710ef1 Merge branch 'disallowed_lint' into 'main'
Remove allow(clippy::disallowed_methods) lint flag.

See merge request tpo/core/arti!437
2022-03-30 14:02:13 +00:00
eta ac64bdea27 Make daemon tasks self-contained; introduce NetDirProvider
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.
2022-03-30 14:26:43 +01:00
Nick Mathewson 700e491813 Remove allow(clippy::disallowed_methods) lint. 2022-03-30 08:55:58 -04:00
eta fd081742fa Merge branch 'no-system-time' into 'main'
Don't use SystemTime::now()

Closes #306

See merge request tpo/core/arti!365
2022-03-30 12:44:25 +00:00
Nick Mathewson 482b2e3256 Remove a now-irrelevant comment 2022-03-28 08:30:44 -04:00
trinity-1686a 219ad39eca remove usage of 'token' where it's no longer a token 2022-03-27 13:49:08 +02:00
trinity-1686a 85fb91deed implement IsolationHelper for StreamIsolation
but don't use it in a dyn Isolation context
2022-03-25 00:03:48 +01:00
trinity-1686a d2edf25733 move StreamIsolation to isolation module 2022-03-24 21:12:46 +01:00
trinity-1686a 5894a43d38 implement IsolationHelper for tuple of IsolationHelper 2022-03-24 20:34:21 +01:00
trinity-1686a 8dc6e958aa move isolation in separate module 2022-03-24 19:43:54 +01:00
trinity-1686a 70f71ac90b seal trait Isolation 2022-03-24 19:05:06 +01:00
trinity-1686a de5f517da6 rename *_isolation_group to *_isolation 2022-03-24 18:56:22 +01:00
eta c35bd79f5c Merge branch 'more_iso_docs' into 'main'
Expand documentation for isolation traits

See merge request tpo/core/arti!420
2022-03-23 11:42:51 +00:00
Nick Mathewson ee204328dd Expand some comments based on review from @diziet. 2022-03-21 15:16:00 -04:00
Nick Mathewson 4a644a9879 circmgr: When planning, only keep one error; log them all. 2022-03-21 15:06:05 -04:00
Nick Mathewson 1ec0ed45c8 dirmgr: Note errors and inform the circmgr about them.
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.
2022-03-21 10:27:53 -04:00
Nick Mathewson d38aafa054 Expose more peer information from circuit build failures
We already have the ability to get peer information from ChanMgr
errors, and therefore from any RetryErrors that contain ChanMgr
errors.

This commit adds optional peer information to tor-proto errors, and
a function to expose whatever peer information is available.
2022-03-21 09:06:32 -04:00
Nick Mathewson d778a92225 circmgr: Change API for using FallbackDirs
It'll soon more convenient to pass in FallbackDirs as a slice of
references, rather than just a slice of FallbackDirs: I'm going to
be changing how we handle these in tor-dirmgr.
2022-03-21 09:06:32 -04:00
Nick Mathewson 451a53a5bf circmgr: use AllGuardsDown to retry better
If all guards are down and they won't be retriable for a while, try
waiting that long to get whichever guard _is_ retriable.

Additionally, if we are making multiple circuit plans in parallel,
only report our planning as having failed if we failed at making
_all_ the plans.  Previously we treated any failure as fatal for the
other plans, which could lead to trouble in the case when guards
were all down or pending.

Part of #407.
2022-03-21 09:06:32 -04:00
Nick Mathewson cb29921e16 Expand documentation for isolation traits
These aren't complete yet; I'm just making this commit to capture
the notes we took on a pad when we were discussing these APIs.

Part of #414.
2022-03-17 13:49:32 -04:00
Nick Mathewson 85a20ae4ec Alternative API for set_isolation_group().
Instead of requiring a `Box<dyn Isolation>`, it now takes either a
`Box<dyn Isolation>`, or an arbitrary `T` that implements
`Isolation`.

This API still allows the user to pass in a `Box<dyn Isolation>` if
that's what they have, but it doesn't require them to Box the
isolation on their own.

Part of #414.
2022-03-17 09:07:08 -04:00
Nick Mathewson 2818a3cb35 Merge branch 'test-isolation' into 'main'
new api for isolation

See merge request tpo/core/arti!377
2022-03-17 12:46:13 +00:00