Commit Graph

989 Commits

Author SHA1 Message Date
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 dcca0ec366 Require up-to-date x25519-dalek, async_executors, and argh.
I tried using -Z minimal-versions to downgrade all first-level
dependencies to their oldest permitted versions, and found that we
were apparently depending on newer features of all three crates.

I'm kind of surprised there were only three.
2021-10-09 19:37:08 -04:00
Nick Mathewson 58da76c6c4 Lock down some dirmgr config functions. 2021-10-09 17:30:06 -04:00
Nick Mathewson 58355d7d54 Re-export configuration types from tor-client. 2021-10-09 17:30:06 -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 4a7c563b79 Fix some typos (via the "typos" tool) 2021-10-08 09:42:54 -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
Nick Mathewson 520396bd2d Update total_weight to use UncheckedRelay. 2021-10-07 09:30:08 -04:00
Nick Mathewson 2b0ecec041 Make UncheckedRelay public in tor-netdir.
This will let us provide a couple of better APIs for use in tor-guardmgr
2021-10-07 09:30:08 -04:00
Nick Mathewson 565b396b86 Add From<u64> for RelayWeight. 2021-10-07 09:30:08 -04:00
Nick Mathewson 7e68883a27 Change tor-persist to use json instead of toml.
The limitations with toml seemed to be reaching a head, and I wasn't
able to refactor the guardmgr code enough to actually have its state
be serializable as toml.  Json's limitations are much narrower.
2021-10-07 09:30:08 -04:00
Nick Mathewson 6c6785c04d Fix a type inference complaint in tor-dirmgr's tests.
I have no idea why this just turned up now.
2021-10-07 09:30:08 -04:00
Neel Chauhan 2e4f5e2d10 Formatting fixes 2021-10-06 12:32:17 -07:00
Neel Chauhan 31cf7e4d56 Make is_valid_hostname() global 2021-10-06 12:32:17 -07:00
Neel Chauhan 0e98e4a033 Add unit tests for hostnames 2021-10-06 12:32:17 -07:00
Neel Chauhan e76988738a Introduce ClientConfig for is_localhost config parameter 2021-10-06 12:32:17 -07:00
Neel Chauhan f4caae3569 Hostname corrections and add IPv6 hostname validation support 2021-10-06 12:32:17 -07:00
Neel Chauhan 0edafc76fa Reject bad hostnames and internal addresses in Arti 2021-10-06 12:32:17 -07:00
Nick Mathewson 7bdb6e7633 Update cargo.lock; upgrade to newer rusqlite. 2021-10-05 08:10:04 -04:00
Nick Mathewson 10bedd925c Use subtle and some refactoring to remove branches in ntor
Closes #163
2021-10-01 12:27:24 -04:00
Nick Mathewson 1d64e88d67 Implement ConstantTimeEq for key ids. 2021-10-01 10:53:18 -04:00
Jani Monoses f7e114c833 Allow building tor-persist for WASM 2021-10-01 14:22:31 +03:00
Nick Mathewson 83b03a20a3 Clarify why we use a dyn pointer for StorageHandle. 2021-09-30 15:36:11 -04:00
Nick Mathewson f1d6779218 Use StorageHandle in tor_circmgr. 2021-09-30 15:36:11 -04:00
Nick Mathewson 37bec4997d remote unused tor-persist/src/config.rs 2021-09-30 15:36:11 -04:00
Nick Mathewson 37040d06d1 Add tests for tor-persist object-safe wrapper. 2021-09-30 15:36:11 -04:00
Nick Mathewson fa9e64e27b tor-persist: Add a testing-only state manager that doesn't use disk 2021-09-30 15:36:11 -04:00
Nick Mathewson eef06efea6 Move FsStatemgr to an inner module. 2021-09-30 15:36:11 -04:00
Nick Mathewson f3d29b5006 Add an object-safe wrapper for StateMgr.
This is an attempt to uplift the trick that tor-circgmr is currently
using, since we'll want it in tor-guardmgr too.
2021-09-30 15:36:11 -04:00
Nick Mathewson ed44d7d968 Ensure pick_n_relays returns relays in random order.
(Also, fix a test)
2021-09-29 13:49:07 -04:00
Nick Mathewson 932924b733 tor-netdir: Add RelayWeight type and accessors.
I'm not thrilled with this code, but I think it's needed to
implement guards correctly.
2021-09-29 13:49:07 -04:00
Nick Mathewson 9114a9ed6e tor_netdir::testnet: Correct a documentation error. 2021-09-29 13:49:07 -04:00
Nick Mathewson d6e5d1b5a1 tor-netdir: Add some accessor that guardmgr will need.
We'll need `id_pair_is_listed()` to track whether a sampled guard is
(or is not) listed in the consensus.

We'll need `missing_descriptor_for` to see whether we've downloaded
enough microdescs to use a consensus.
2021-09-29 13:49:07 -04:00
Nick Mathewson d78b25f2b0 Typo fix in comment. 2021-09-29 13:49:07 -04:00
Trinity Pointard 954395573a update fslock to compile android 2021-09-25 12:01:45 +02:00
Nick Mathewson b51e2ff5b3 Upgrade memmap2, directories, and dirs dependencies. 2021-09-23 08:26:29 -04:00
Daniel Eades 9a3b183679 remove unused dep 2021-09-19 09:47:57 +01:00
Jani Monoses 5f1f239d51 Enable js feature for getrandom for WASM.
By default rand does not build for WASM browser targets.
2021-09-17 06:43:02 +03:00
Jani Monoses 08c9edfc54 Stop using anyhow in tor-dirclient. 2021-09-16 14:27:04 -04:00
Nick Mathewson 039601f179 tor-netdir: Add a by_id_pair() function to look up a relay by both IDs. 2021-09-16 10:19:35 -04:00
Jani Monoses b0bb7bd100 Do not use set_ prefix on derive_builder setters 2021-09-16 08:41:04 +03:00
Daniel Eades 27cca71978 derive 'Default' where possible 2021-09-11 20:02:33 +01:00
Nick Mathewson 1c08bb44c8 Add identity-based accessors (and indices) to NetDir.
(Thank goodness for rust; we messed up the coherency in C here so
many times, but I'm pretty sure that this time around we can't have
gotten it wrong.)
2021-09-10 15:13:57 -04:00
Nick Mathewson e5ef19962b Merge remote-tracking branch 'origin/mr/77' 2021-09-10 10:26:14 -04:00
Nick Mathewson 0949582fab Use derive_builder for Authority and FallbackDir. 2021-09-10 10:03:33 -04:00
Nick Mathewson 8bfb04f562 Suppress a cognitive-complexity lint in tests 2021-09-09 14:20:55 -04:00
Nick Mathewson 1c97918d67 Typo fixes 2021-09-09 13:06:05 -04:00
Nick Mathewson 9b2df3edd8 Add guard-related network parameters. 2021-09-09 13:01:52 -04:00
Nick Mathewson 0635ec6721 Add an IntegerDays numeric type. 2021-09-09 12:32:13 -04:00
Nick Mathewson 41f96c4f2f Use macros and traits to simplify the declaration of parameters.
Previously, we'd have to declare the field for a parameter in one
place, its default in a second, and its consensus key in a third.
That's error-prone and not so fun!  This patch changes the
way we declare parameters so that we declare a structure once,
and macros expand it to all do the right thing.

This required a few new traits and implementations to ensure
uniformity across the types that can go in parameters: We need every
parameter type to implement TryFrom<i32> and to implement
SaturatingFromInt32.

Eventually we might want SaturatingFromInt32 to be a more generic
SaturatingFrom, but that's not for now.
2021-09-09 09:29:04 -04:00
Nick Mathewson a00248723d Use derive_builder for the rest of tor_dirmgr::config 2021-09-09 07:38:12 -04:00
Jani Monoses 4d52f99020 Create a separate logging section in config. 2021-09-09 10:38:29 +03:00
Nick Mathewson 372c38e041 Use derive_builder for DownloadScheduleConfig 2021-09-08 17:55:18 -04:00
Nick Mathewson d42d910a4f Use derive_builder for NetworkConfig. 2021-09-08 17:46:00 -04:00
Nick Mathewson 6996c0f1b5 Merge remote-tracking branch 'origin/mr/73' 2021-09-08 16:04:58 -04:00
Nick Mathewson d9dc6f9d5c Fix clippy warnings in tests with --all-features 2021-09-08 14:28:38 -04:00
Nick Mathewson ab0c80de2b Fix/suppress a few more clippy lints in tests.
I'm alright with allowing cognitive-complexity violations in the
tests.
2021-09-08 14:20:47 -04:00
Nick Mathewson 949313e288 Merge remote-tracking branch 'origin/mr/71' 2021-09-08 14:14:39 -04:00
Nick Mathewson 9ba16a3104 Check for correct-ish decoding of all parameters. 2021-09-08 13:46:24 -04:00
Nick Mathewson 929cf84073 Add validation function to WeightSet
Our relay selection code can give wrong answers if we overflow
u64::MAX, so let's make sure we never do that.
2021-09-08 12:38:20 -04:00
Nick Mathewson 0468b41f33 Replace weighted-choice code with rand::seq::SliceRandom.
Doing this makes the code faster, lets us throw away some code, and
makes it easier to add a "choose-N-disjoint relays" implementation.

See large comment about plusses and minuses of new code.  (Note that
the old implementation wasn't constant-time either.)
2021-09-08 12:22:56 -04:00
Daniel Eades fb3b8b84b5 fix/silence clippy lints in test modules 2021-09-08 17:28:31 +02:00
Nick Mathewson 9cf1fa36f4 More tests in pareto.rs 2021-09-08 09:18:23 -04:00
Nick Mathewson 74fa18458e Use same defaults for abandon and close times in timeout code.
On torspec!40, Mike says:

    I don't think there is a practical difference here. As per
    Section 2.4.5, if 60 seconds is not enough and causes the
    liveness test to fail due to too many timeouts, we will double
    the initial timeout.

This makes our behavior the same as C tor.
2021-09-07 14:53:50 -04:00
Nick Mathewson 5d7b08993e Stop making abandoned/successful circuit counts persistent
The C Tor implementation doesn't do this, and Mike says:

   I think it is a reasonable enough assumption that if Tor has
   restarted, this kind data is no longer fresh enough to be
   accurate for this purpose. This is also only 20 circuits here,
   and typical timeouts are now around 1-2 seconds or less.. So a
   restarted client with a timeout that is too low for a new
   internet connection will figure this out pretty quickly. I think
   that is OK.

(from torspec!40)
2021-09-07 14:50:36 -04:00
Nick Mathewson e5cb5de223 A little more test coverage in tor-circmgr::mgr 2021-09-07 14:43:55 -04:00
Nick Mathewson 6c37f78e58 tor_circmgr::mgr -- refactor some duplicate code. 2021-09-07 14:24:16 -04:00
Nick Mathewson 45e880f507 Rename pick_action to clarify that it can modify self 2021-09-07 14:14:31 -04:00
Jani Monoses 39e39cd277 Make journald an optional feature. 2021-09-07 20:56:37 +03:00
Nick Mathewson 353a16ce7e Exclude tor-bytes fuzzing helper code from tarpaulin coverage. 2021-09-07 13:30:53 -04:00
Nick Mathewson 358b3e1ea0 Update corpus and links. 2021-09-07 12:32:50 -04:00
Nick Mathewson f0de653af1 Fix bugs in last fuzzer code. 2021-09-07 12:29:28 -04:00
Nick Mathewson 97692e3cc2 Improvements to array-of-u8 handling in tor-bytes.
Now that we have const generics, we can use them.  We can also avoid
an extra clone in the implementation for [u8; N].

Nothing in our codebase requires that we use Reader or Writer on a
GenericArray holding anything other than u8, so I've switched back
to the more efficient implementation there.

I've added a fuzzer case for the new method, but apparently rustc nightly isn't working too
well with fuzzers for me; I'm going to try it tomorrow.
2021-09-07 09:46:54 -04:00
Jani Monoses d5b0d76435 Do not log to journald by default 2021-09-07 15:56:17 +03:00
Jani Monoses 92d0ae26a9 Allow logging to journald.
Log to journald when available, add journald config option.
Separate logging setup into its own function.
2021-09-07 15:54:42 +03:00
Nick Mathewson bd2c9fd8c1 Document every macro.
(The nightly version of clippy now includes macros for its
missing_docs_in_private_items lint.)
2021-09-07 08:44:47 -04:00
Jani Monoses 25b4421fa6 Fix typos 2021-09-07 07:52:00 +03:00
Nick Mathewson 781dc4bd64 Light refactoring and documentation improvements in proxy.rs 2021-08-27 14:22:15 -04:00
Nick Mathewson 557a0ff40b Move all crates into a `crates` subdirectory.
This will cause some pain for now, but now is really the best time
to do this kind of thing.
2021-08-27 09:53:09 -04:00