Commit Graph

291 Commits

Author SHA1 Message Date
Nick Mathewson dae8cdb463 Remove all remaining dbg! instances. 2021-11-04 10:54:47 -04:00
Nick Mathewson b0265c490e Merge branch 'bug219' 2021-11-02 15:32:44 -04:00
Nick Mathewson 78fbb141be tor-circmgr: test ExitPathBuilder with guards. 2021-11-02 14:17:18 -04:00
Nick Mathewson 3b41933b67 tor-circmgr: test DirPathBuilder with GuardMgr. 2021-11-02 13:50:08 -04:00
Nick Mathewson b2567a6d88 Add a comment to explain the computation of net_has_been_down. 2021-11-02 12:17:11 -04:00
Nick Mathewson c979a2f83a tor-guardmgr: Add tests for a few functions. 2021-11-02 12:17:11 -04:00
Nick Mathewson 876a569f6c Mark primary guards as retriable when we come back online.
We define "coming back online" as happening when a guard attempt
succeeds, if that attempt that was launched when we seemed to be
offline.

We define "seeming to be offline" as having all of our primary
guards marked unreachable, and having received no incoming network
traffic in a while.

Closes #216.
2021-11-02 12:17:11 -04:00
Nick Mathewson 453855693b Refactor tor-guardmgr's inter-task communication.
This is based on @eta's patches for !118 and !119: Since we already
have an unbounded channel, we don't need to use an elaborate mess of
one-shot senders.  We can just use the unbounded_send() method,
which also lets us enqueue a message without having to await.

Closes #219.
2021-11-02 11:19:57 -04:00
Nick Mathewson e6e740646a Bump all crate versions to 0.0.1 2021-10-29 11:05:51 -04:00
Nick Mathewson 1ee24ce653 Improve some documentation links
Instead of putting a fully qualified name in the text, in most cases
we should just use the short name of the type or function we're
referring to.

In other words, instead of saying [`crate::module::Foo`], we should
typically say [`Foo`](crate::module::Foo).
2021-10-29 08:39:04 -04:00
Nick Mathewson 134c04a67a Update our disclaimers and limitations sections. 2021-10-27 11:13:46 -04:00
eta 5a4db67b16 Add Futureproof<T> wrapper type, use for GuardDisabled enum
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.
2021-10-27 15:10:44 +01:00
eta 7a931b4de3 Add #[serde(flatten)] HashMap fields to serializable objects
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.
2021-10-27 13:31:52 +01:00
Nick Mathewson 682f31b1bf Avoid a strange borrow syntax in tor_guardmgr::sample
I'm not sure what I was thinking here.
2021-10-26 12:03:23 -04:00
Nick Mathewson 72ebaed16b Do not blame a guard for failures on non-random circuits.
We must not apply our new path-bias behavior (where we blame a guard
if it gives us too many indeterminate circuit failures) if the path
was not chosen at random.  If too many random paths fail, we know
that's suspicious, since the other relays are a random sample.  But
if a bunch of user-provided paths fail, that could simply be because
the user's chosen exit is down.
2021-10-26 12:03:23 -04:00
Nick Mathewson 8c69b5d389 Implement a "lightweight" form of pathbias detection.
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.
2021-10-26 12:03:23 -04:00
Nick Mathewson 84f81d14eb guardmgr: Don't use guards that are marked as unlisted.
Closes #202.
2021-10-25 10:27:13 -04:00
Nick Mathewson f3dc66d964 Merge branch 'share_state' 2021-10-21 13:34:38 -04:00
Nick Mathewson 8a99833777 Implement the guard side of shared state directories. 2021-10-21 13:31:38 -04:00
Nick Mathewson c8cfbda339 Finish the timeout-inference side of shared state. 2021-10-20 13:13:15 -04:00
Nick Mathewson 7b6ed9dab6 Replace the return type of StorageMgr::try_lock with a tristate
It's useful to know now only if we now have the lock, but also if we
just got it for the first time.
2021-10-20 09:37:53 -04:00
Nick Mathewson 445ec6d220 Fix most warnings from nightly.
(One represents code that I forgot to write.)
2021-10-19 16:21:12 -04:00
Nick Mathewson 89d1fb1767 Initial work on periodically reloading state.
We can use this in the case where we don't get the lock on the
state file, because another process is running.
2021-10-19 11:26:22 -04:00
Nick Mathewson 193148c12d Remove Guard::get_relay(); use Guard::guard_id().get_relay().
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.
2021-10-19 08:33:55 -04:00
Nick Mathewson f15cde80de Use better reporting for guard status.
The previous code would report all failures to build a circuit as
failures of the guard.  But of course that's not right:  If we
fail to extend to the second or third hop, that might or might not
be the guard's fault.

Now we use the "pending status" feature of the GuardMonitor type so
that an early failure is attributed to the guard, but a later
failure is attributed as "Indeterminate".  Only a complete circuit
is called a success.  We use a new "GuardStatusHandle" type here so
that we can report the status early if there is a timeout.
2021-10-13 11:24:37 -04:00
Nick Mathewson e625b2cff5 Rename GuardStatusMsg, make it public, add an `Indeterminate` case. 2021-10-13 10:55:44 -04:00
Nick Mathewson fd893f750c Actually select guards for directory circuits. 2021-10-13 09:30:50 -04:00
Nick Mathewson 73669fa05e Make the guard selection function return a more useful type. 2021-10-11 15:23:12 -04:00
Nick Mathewson 91cca2183e Change the GuardMgr APIs to no longer be async. 2021-10-10 12:14:33 -04:00
Nick Mathewson 34c10feae4 Use an mpsc::unbounded() channel in GuardMgr.
The advantage here is that we no longer have to use a futures-aware
Mutex, or a blocking send operation, and therefore can simplify a
bunch of the GuardMgr APIs to no longer be async.  That'll avoid
having to propagate the asyncness up the stack.

The disadvantage is that unbounded channels are just that: nothing
in the channel prevents us from overfilling it.  Fortunately, the
process that consumes from the channel shouldn't block much, and
the channel only gets filled when we're planning a circuit path.
2021-10-10 12:08:31 -04:00
Nick Mathewson af7c9d5a0b enable checked_conversions lint. 2021-10-09 16:53:13 -04:00
Nick Mathewson 2fa6f5dbb0 Normalize tor-guardmgr warnings 2021-10-09 16:17:54 -04:00
Nick Mathewson a0bcec5863 Note a possible heisenbug in a unit test. 2021-10-08 10:03:38 -04:00
Nick Mathewson aed9572c03 Add a few tracing calls to tor-guardmgr. 2021-10-08 09:14:36 -04:00
Nick Mathewson 29112e0729 Update the tor-guardmgr README.md. 2021-10-07 15:36:26 -04:00
Nick Mathewson 0ff56a3138 Resolve small issues and XXXX/TODO comments in GuardMgr.
By the time I merge this, most of the comments should have tickets
to go with them.
2021-10-07 14:03:21 -04:00
Nick Mathewson 00acc5c5b8 Tests for top-level GuardMgr.
Also, refactor our message handling to be more like the tor_proto
reactors.  The previous code had a bug where, once the stream of
events was exhausted, we wouldn't actually get any more
notifications.
2021-10-07 12:09:29 -04:00
Nick Mathewson 7ef33b7afa Tests for tor_guardmgr::sample. 2021-10-07 10:45:42 -04:00
Nick Mathewson 0710fb2102 Initial tests for tor_guardmgr::guard 2021-10-07 10:45:42 -04:00
Nick Mathewson 6cdce3dee6 Implement persistent state for guard mgr 2021-10-07 10:45:42 -04:00
Nick Mathewson 0779923d64 Initial backend implementation for guard node manager.
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.
2021-10-07 10:45:42 -04:00