Commit Graph

164 Commits

Author SHA1 Message Date
Jani Monoses f683d4f3cd Remove useless into() conversions caught by clippy. 2021-10-18 13:22:53 +03:00
Jani Monoses 8b8228190d Remove anyhow dependency from tor-dirmgr. 2021-10-18 13:22:53 +03:00
Jani Monoses 6181e623f8 Use unwrap in tests.
For now, this avoids having to separately handle
AuthorityBuilderError, DirMgrConfigBuilderError, DownloadScheduleConfigBuilderError,
NetworkConfigBuilderError and FallbackDirBuilderError when anyhow is not
used.

Turn off a clippy warning.
2021-10-18 13:22:39 +03:00
Nick Mathewson 9df9706010 Use append in place of extend_from_slice in DataReaderImpl::add_data.
Suggested by @cheako.
2021-10-17 12:31:10 -04:00
Nick Mathewson 3b7b43ae5f Turn off default-features in chrono where possible. 2021-10-17 10:37:30 -04:00
Nick Mathewson 37234548e2 Add a cast to correct a type error about WSAEMFILE 2021-10-15 08:08:19 -04:00
Nick Mathewson 81a5675c1b arti: On startup, increase the NOFILE resource limit.
The default soft limit is typically enough for process usage on most
Unixes, but OSX has a pretty low default (256), which you can run
into easily under heavy usage.

With this patch, we're going to aim for as much as 16384, if we're
allowed.

Fixes part of #188.
2021-10-14 13:25:19 -04:00
Nick Mathewson 0cb7231649 proxy: Mark ENFILES and EMFILES as survivable.
I don't love this approach, but those errors aren't distinguished by
ErrorKind, so we have to use libc or winapi, apparently.  At least
nothing here is unsafe.

Addresses part of #188.
2021-10-14 13:12:58 -04:00
Nick Mathewson 02b20edeb3 Add a few tracing directives to tor-dirmgr. 2021-10-13 13:37:18 -04:00
Nick Mathewson e9399ec6c0 tor-dirmgr: report bootstrap success on all successful cases.
Previously we would sometimes fail to report that we had
successfully bootstrapped.
2021-10-13 13:01:55 -04:00
Nick Mathewson 16767fb517 Fix a documentation link error. 2021-10-13 12:56:00 -04:00
Nick Mathewson 13769dbc56 Report errors in logging configuration a bit more usefully 2021-10-13 12:53:17 -04:00
Nick Mathewson 7dd8af55d9 Document trace_filter example in main.rs too. 2021-10-13 12:37:33 -04:00
Nick Mathewson 8113a8ba12 Don't report the bootstrap as completed unless it actually succeeds.
(Previously we'd report it as successful even if the inner download
task was a failure.)
2021-10-13 12:19:40 -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 733aa3a4e2 Implement guards for multihop paths.
There are some limitations here, as noted in the comments.
2021-10-13 10:27:46 -04:00
Nick Mathewson fd893f750c Actually select guards for directory circuits. 2021-10-13 09:30:50 -04:00
Nick Mathewson 5b06b3c64a Pass the guard manager down to the path selection functions. 2021-10-11 15:59:45 -04:00
Nick Mathewson ad851c43c6 WIP 2021-10-11 15:37:59 -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 19038ae39a Add a function to look up a Relay by ChanTarget. 2021-10-11 15:21:46 -04:00
Nick Mathewson 34b576a815 Integrate GuardUsability and GuardMonitor into CircuitBuilder.
(When we're building a path with a guard, we need to tell the guard
manager whether the path succeeded, and we need to wait to hear
whether the guard is usable.)
2021-10-10 13:48:58 -04:00
Nick Mathewson 33ba697b5d Notify guard manager on network change and state flush. 2021-10-10 12:38:50 -04:00
Nick Mathewson c41dd01a14 Add a GuardMgr member to CircuitBuilder 2021-10-10 12:24:48 -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 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