Commit Graph

3500 Commits

Author SHA1 Message Date
Nick Mathewson 05be12e4d8 Give CfgPath an alternative inner representation.
In order to handle explicitly specified path buffers directly, we now
let CfgPath be either a string (that gets expanded) or a PathBuf
(that doesn't).

This simplifies TorClientConfig::with_directories()
2021-11-21 11:17:56 -05:00
Nick Mathewson 97f5a7a357 Give every ConfigBuilder a From<Config> implementation.
This will make it more convenient to reconfigure things.
2021-11-21 10:54:34 -05:00
Nick Mathewson aa83a5e38a Ensure that every section-level config type has a builder() function. 2021-11-21 10:54:34 -05:00
Nick Mathewson 0372d24eed Make arti-client config object match arti config better.
Now every section that the two configuration objects share has the
same type and name.  This should help us in documenting our configuration
in a way that doesn't confuse people.

There is still lots of API work to go.
2021-11-21 10:54:34 -05:00
Nick Mathewson 065d3dc104 Lower StorageConfig to arti-client crate 2021-11-21 10:54:34 -05:00
Nick Mathewson a7f5b9aefe Allow type-complexity in hyper.rs example
This isn't the prettiest, but suppressing the warning does make
the example warning free.
2021-11-21 10:53:06 -05:00
Nick Mathewson 0c2048de60 Document (and allow) behavior for weird values of subnet masks.
Chutney needs this, to avoid putting every relay in the same family.
2021-11-18 14:39:48 -05:00
Nick Mathewson 934412586e Use named fields for the elements of ConfigBuildError 2021-11-18 14:31:34 -05:00
Nick Mathewson 96659a850b Rename RetryConfig to DownloadSchedule, fold in parallelism. 2021-11-18 12:33:08 -05:00
Nick Mathewson a1a620e451 Move the socks_port option into a new proxy section.
Now there are no options that aren't in a toml section.
2021-11-18 11:48:14 -05:00
Nick Mathewson 44f6da5f38 Rename the "network" configuration section to "tor_network".
This is more accurate, since it describes the details of the tor
network that we're connecting to.
2021-11-18 11:37:48 -05:00
Nick Mathewson d83fd2d181 Rename addr_config to address_filter; clarify its usage. 2021-11-18 11:37:48 -05:00
Nick Mathewson eba35e789c Flatten enforce_distance into path_rules.
Also use the path_rules name consistently throughout the code.
2021-11-18 11:37:48 -05:00
Nick Mathewson d592e86f9c Fold "circuit_timing" and "request_timing" into a single section. 2021-11-18 11:37:48 -05:00
Nick Mathewson 5184f5ba84 Move top-level configuration downwards from `arti` to `arti-config`.
To do this at all neatly, I had to split out `tor-config` from
`arti-config` again, and putting the lower level stuff (paths,
builder errors) into tor-config.  I also changed our use of
derive_builder to always use a common error type, to avoid
error type proliferation.
2021-11-18 11:37:48 -05:00
Nick Mathewson 763c993e1c Merge remote-tracking branch 'origin/mr/134' 2021-11-18 11:34:35 -05:00
eta 075e663dcd Make unreliable tor-proto tests more reliable (arti#238).
The `bad_extend_*` failures were caused by bad test code in
`bad_extend_test_impl` that used `futures::join!`; this meant that the
reactor could receive the `Extended2` cell before it actually got the
`ExtendNtor` request, which caused it to get (quite rightly) confused
and close the circuit. Spawning a background thread which has a short
delay before sending the `Extended2` cell seems to have alleviated this
problem.

`new_circ_create_failure` is similar; I think the reactor was getting
dropped before it had a chance to flush out its `CreateFast` cell
properly, because it had already gotten the result back (since the test
code sends it indiscriminately). This was "fixed" in much the same
manner as the other test: making it wait a bit before sending the result
cell back.

There seem to be other tests that use `futures::join!` (like
`begindir`?), and use similarly erroneous patterns; I haven't gotten any
to fail reliably enough to be able to debug them, though.
2021-11-18 16:06:53 +00:00
Trinity Pointard 03f8966f0d use 3des instead of rc2 in .pfx test fixture 2021-11-18 09:07:48 +01:00
Nick Mathewson 15d1645bbd Typo fix from reddit thread. 2021-11-17 09:14:32 -05:00
Nick Mathewson e5c5519f7b Remove dependency from arti-client to tor-config.
I'm about to make tor-config a higher-level module, so it can't be a
dependency for tor-config.
2021-11-16 16:01:55 -05:00
Nick Mathewson 727e420d5c Remove unused "dirs" dependency from tor-persist. 2021-11-16 15:51:35 -05:00
Nick Mathewson cc3efccdcc Always use optimistic data for begindir connections.
Closes #226.
2021-11-16 15:20:44 -05:00
eta a85e83c807 Merge branch 'ticket125' into 'main'
Put most non-universally-needed functionality behind features

Closes #125

See merge request tpo/core/arti!129
2021-11-16 18:31:00 +00:00
Nick Mathewson f92ad644c9 tor-proto: Use tor-rtcompat macros for testing, not tokio.
Closes #222.
2021-11-15 12:57:01 -05:00
Nick Mathewson 787a995458 tor-proto: Stop using async_test in halfstream.rs and sendme.rs
Thanks to eta's refactoring, these tests no longer need to be async.
2021-11-15 12:12:53 -05:00
Nick Mathewson 236255514a Update to simple_asn1 0.6.1.
This is a security fix for a panic.

Closes #236
2021-11-14 18:00:45 -05:00
Nick Mathewson c6d188869f A few more eprintln!() removals that I missed. 2021-11-13 11:22:08 -05:00
Nick Mathewson 20b179bfa9 Replace or remove testing eprintln!()s.
The clippy code for warning about these on nightly CI can't tell the
difference between cfg(test) and no cfg(test).
2021-11-13 11:17:49 -05:00
Nick Mathewson b26fbdb24f Resolve a dead-code warning on nightly.
The `circid` field in `ClientCirc` is now testing-only.
2021-11-13 11:14:11 -05:00
Nick Mathewson 69bb6313fd Remove the unused `published` field from GenericRouterStatus.
This field isn't used in modern Tor, and has never been used in
Arti.  If tor!489 is merged, then it will no longer contain a useful
value in future consensuses.  We shouldn't store it, or else
somebody else will get the smart idea of using it for something.

This commit breaks API compatibility for tor-netdoc with the
`build_docs` feature enabled.  I haven't entered that into the
semver_status.md file, since we already have a pending tor-netdoc
API breaker in !129.
2021-11-12 13:54:03 -05:00
Nick Mathewson 2439129899 tor-dirclient: Put routerdesc download behind a feature.
Part of #125
2021-11-12 13:38:02 -05:00
Nick Mathewson e9ea7515bc tor-dirmgr: put routerdesc storage behind a feature.
(We keep routerdescs in the schema, since we don't want _that_ to
fragment.)

Part of #125.
2021-11-12 12:15:48 -05:00
Nick Mathewson 773c0dc332 tor-netdoc: put NS consensus documents behind a feature.
Clients never need these.

Part of #125.
2021-11-12 12:15:34 -05:00
Nick Mathewson 84fbff54a5 tor-netdoc: Split the two kinds of routerstatus into their own modules 2021-11-12 12:15:34 -05:00
Nick Mathewson 7b12b54d40 tor-netdoc: Put the "routerdesc" document type behind a feature.
Nothing in arti currently uses this document type.  Eventually it
will be useful for relays and for bridge clients.

I've left the "SHA1 digest of a router descriptor" type available
unconditinoally, however, since it does get used in a few places.

Part of #125.
2021-11-12 12:15:30 -05:00
Nick Mathewson 1a3292daea Remove unused tor-consdiff/src/cmd.rs file.
(Found while looking for unused features for #125)
2021-11-12 11:56:15 -05:00
Nick Mathewson fb591c51b4 tor-llcrypto: Put currently unused functions behind features.
We don't currently need a couple of the key manipulation features
that we have, since we aren't yet doing relays or onion service
clients.

Part of #125
2021-11-12 11:56:05 -05:00
eta c559754116 Get rid of unbounded stream sender, and RawCellStream
Previously, the reactor would use an `UnboundedSender` to send things to
the `RawCellStream`, in order that the reactor wouldn't block if you
failed to read from the latter. This is bad, though, since it means
people can just run us out of memory by sending lots of things.

To fix this, we make the new `StreamReader` type (which does the reading
parts from `RawCellStream`) keep track of the stream's receive window
and issue SENDMEs once *it* has consumed enough data to require it, thus
meaning that we shouldn't get sent enough data to fill the channel
between reactor and `StreamReader` (and, if we do, that's someone trying
to flood us, and we abort the circuit).

As hinted to above, the `RawCellStream` was removed and its reading
functionalities replaced by `StreamReader`; its writing functionalities
are handled by `StreamTarget` anyway, so we just give out one of those
for the write end. This now means we don't need any mutexes!

note: this commit introduces a known issue, arti#230
2021-11-12 15:04:27 +00:00
eta 197816d14c Completely overhaul the tor-proto circuit reactor
Rather like e8e9699c3c ("Get rid of
tor-proto's ChannelImpl, and use the reactor more instead"), this
admittedly rather large commit refactors the way circuits in `tor-proto`
work, centralising all of the logic in one large nonblocking reactor
which other things send messages into and out of, instead of having a
bunch of `-Impl` types that are protected by mutexes.

Congestion control becomes a lot simpler with this refactor, since the
reactor can manage both stream- and circuit-level congestion control
unilaterally without having to share this information with consumers,
meaning we can get rid of some locks.

The way streams work also changes, in order to facilitate better
handling of backpressure / fairness between streams: each stream now has
a set of channels to send and receive messages over, instead of sending
relay cells directly onto the channel (now, the reactor pulls messages
off each stream in each map, and tries to avoid doing so if it won't be
able to forward them yet).

Additionally, a lot of "close this circuit / stream" messages aren't
required any more, since that state is simply indicated by one end of a
channel going away. This should make cleanup a lot less brittle.

Getting all of this to work involved writing a fair deal of intricate
nonblocking code in Reactor::run_once that tries very hard to be mindful
of making backpressure work correctly (and congestion control); the old
code could get away with having tasks .await on things, but the new
reactor can't really do this (as it'd lock the reactor up), so has to do
everything in a nonblocking manner.
2021-11-12 15:04:24 +00:00
eta 4765cafd35 Merge branch 'typos' into 'main'
Fix typos

See merge request tpo/core/arti!127
2021-11-12 14:14:08 +00:00
Nick Mathewson 03cca4ddda Upgrade to async-native-tls 0.4.0 2021-11-12 08:36:41 -05:00
Dimitris Apostolou ad3c18a456
Fix typos 2021-11-12 13:54:50 +02:00
Nick Mathewson 99aefe4bb8 Remove usage of tracing-test 0.1
It requires tracing-subscriber 0.2, which is a lower version than we
want, and which causes trouble with our minimal-versions CI test.

There is a pending issue to fix this; we can reinstate tracing-test
once it is merged:  https://github.com/dbrgn/tracing-test/pull/11
2021-11-11 11:01:32 -05:00
Nick Mathewson 24b6a2455d Document that the "experimental-api" feature is not semver-covered. 2021-11-11 10:44:24 -05:00
Nick Mathewson a940679672 Document that the "testing" feature is not semver-covered. 2021-11-11 10:38:23 -05:00
Nick Mathewson 4717bb270f Tests for tor-dirmgr::bootstrap 2021-11-11 08:58:48 -05:00
Nick Mathewson 3609aff10e Minor tests for DirMgr::query_into_requests 2021-11-11 07:31:23 -05:00
Nick Mathewson 5287ac1858 Merge IpVersionPreferences and the optimistic flag into one type.
It seems like a good time to do this, before we add a zillion other
arguments to begin_stream.
2021-11-10 11:04:55 -05:00
Nick Mathewson 428b19c121 Refactor wait_for_connection a bit.
* Make it crate-visible only.
* Make it idempotent
* Have it be an internal error if it's called at the wrong time.
* Simplify the return logic.
2021-11-10 10:33:31 -05:00
Nick Mathewson 94950468dd Merge remote-tracking branch 'origin/mr/116' 2021-11-10 10:23:29 -05:00
Nick Mathewson 82120aff6b Require consensus-diff line 2 to start with "hash "
Previously we didn't check for the space.

Closes #225.
2021-11-10 09:34:38 -05:00
Nick Mathewson 585c6c4f9e tor-dirmgr: tests for making and expanding consensus requests. 2021-11-10 09:04:21 -05:00
Nick Mathewson 248aca98f1 tor-dirmgr: Tests for high-level loading functions. 2021-11-10 08:18:30 -05:00
Yuan Lyu 7f799c956b Implement optimistic stream 2021-11-09 21:36:12 -05:00
eta 6b2530d81b Merge branch 'S0AndS0/arti-cargo-husky' into HEAD 2021-11-09 12:59:32 +00:00
Nick Mathewson ee030260fb Add a couple of pieces of missing documentation. 2021-11-08 16:06:08 -05:00
Nick Mathewson 6899b2599b More tests on tor-dirmgr::state
These test our download schedules, resetting to the original state,
and storing downloaded objects.
2021-11-08 08:21:44 -05:00
Nick Mathewson 753cbc9626 In rust-nightly CI, forbid debugging prints.
This patch makes the rust-nightly CI task fail if it detects any
dbg!(), println!(), or eprintln!() calls in production code.

Because of clippy limitations, it may also gripe about calls to
these macros in our tests.  The preferred workarounds are to either
instead.  Both are acceptable.

We're doing this check in CI rather than unconditionally with clippy
directives, since we often want to have these calls in our code
temporarily while we're developing.  Some day we might want this
test to go into a pre-push hook.

This patch also adds #![allow()] directives for println!() and
eprintln!() in the arti crate.  Since that one isn't a library, it's
okay for it to speak to stdout/stderr.

Closes #218.
2021-11-04 11:13:29 -04:00
Nick Mathewson 8833f7a3a2 Remove one more test println!(). 2021-11-04 11:11:26 -04:00
Nick Mathewson 83d9f2299e Replace all println/eprintln calls outside of arti CLI with trace. 2021-11-04 11:04:59 -04:00
Nick Mathewson dae8cdb463 Remove all remaining dbg! instances. 2021-11-04 10:54:47 -04:00
Nick Mathewson e3f8a9f94f tor-dirmgr: tests for docid module. 2021-11-04 09:47:13 -04:00
Nick Mathewson cb63449aeb Basic tests for readonly estimators, and estimator migration.
Also add a comment about a possible problem behavior in read-only
estimators.
2021-11-03 13:58:51 -04:00
Nick Mathewson 619ae65064 Change how TestingStateMgr handles locking.
Previously it was either all-locked or all-not-locked.  Now you can
simulate having the same shared storage opened by multiple managers,
only one of which has the lock.
2021-11-03 13:27:01 -04:00
eta db6b91164e tor-proto: Use a dedicated sender for channel cells, make full-duplex
@nickm pointed out that refactoring tor_proto::channel's Reactor to do
sending as well meant that it could only send or receive, but not both,
simultaneously, which was bad!

To fix this, rewrite Reactor::run_once to use a handcrafted future (with
futures::future::poll_fn) that can handle the logic required to push
items onto the sink asynchronously (i.e. checking that it can be written
to before trying to do that, and then flushing it).

This also means we don't use select_biased! any more, and just handroll
that logic ourselves; as a small bonus, we can now process all 3 kinds
of message in one run_once() call, instead of having to do only one of
them.
2021-11-03 16:48:54 +00:00
eta e8e9699c3c Get rid of tor-proto's ChannelImpl, and use the reactor more instead
Instead of awkwardly sharing the internals of a `tor-proto` `Channel`
between the reactor task and any other tasks, move most of the internals
into the reactor and have other tasks communicate with the reactor via
message-passing to allocate circuits and send cells.

This makes a lot of things simple, and has convenient properties like
not needing to wrap the `Channel` in an `Arc` (though some places in the
code still do this for now).

A lot of test code required tweaking in order to deal with the refactor;
in fact, fixing the tests probably took longer than writing the mainline
code (!). Importantly, we now use `tokio`'s `tokio::test` annotation
instead of `async_test`, so that we can run things in the background
(which is required to have reactors running for the circuit tests).

This is an instance of #205, and also kind of #217.
2021-11-03 13:19:45 +00:00
Nick Mathewson 03cf83b2cc Disable a check in exitpath
This check relies on families being enforced correctly, which is not
the case when specifying a fixed exit and using guards.  (See #183)
2021-11-02 16:43:58 -04:00
Nick Mathewson b9849788cd Allow clone-on-copy in tor-circmgr tests to fix a nightly-only clippy warning. 2021-11-02 16:17:51 -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 ad132602ae tor-circmgr: testing for NoUsage and TimeoutTesting usage
This doesn't add much to coverage, but it's important.
2021-11-02 13:30:04 -04:00
Nick Mathewson 656a8e5f48 Merge branch 'timestamp' 2021-11-02 12:17:15 -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 dddf67a902 Use coarsetime to build an incoming traffic timestamp.
We need this for the circuit timeout estimator (#57).  It needs to
know "how recently have we got some incoming traffic", so that it
can tell whether a circuit has truly timed out, or whether the
entire network is down.

I'm implementing this with coarsetime, since we need to update these
in response to every single incoming cell, and we need the timestamp
operation to be _fast_.

(This reinstates an earlier commit, f30b2280, which I reverted
because we didn't need it at the time.)

Closes #179.
2021-11-02 12:17:11 -04:00
Nick Mathewson b0df80dae4 Merge remote-tracking branch 'origin/mr/119' 2021-11-02 11:27:01 -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 5b1b87c896 tor-circmgr: tests for netwoks with no exits 2021-11-02 10:58:28 -04:00
eta 2979bb22a2 Refactor tor_proto::circuit::Reactor to use an UnboundedSender
Basically the same thing as 371437d338
("Refactor tor_proto::channel::Reactor to use an UnboundedSender"), but
for tor_proto::circuit's Reactor instead.

(part of arti#217)
2021-11-02 14:26:25 +00:00
Nick Mathewson 118fddb15f Merge remote-tracking branch 'origin/mr/118' 2021-11-02 10:14:58 -04:00
eta 371437d338 Refactor tor_proto::channel::Reactor to use an UnboundedSender
There wasn't any good reason for tor-proto's channel reactor to use a
shedload of oneshot channels instead of just an mpsc UnboundedSender,
and the whole `CtrlResult` thing made even less sense.

Straighten this code out by replacing all of that machinery with a
simple UnboundedSender, instead.

(part of arti#218)
2021-11-02 14:02:58 +00:00
Nick Mathewson cdae4c033c Remove some dbg!() calls in real code. 2021-11-02 09:50:55 -04:00
Nick Mathewson b547cdb7ff tor-circmgr::usage: Add a few more tests. 2021-11-02 09:42:56 -04:00
Nick Mathewson f5d042115a tor-persist: serde usage now requires derive feature. 2021-10-29 11:41:26 -04:00
Nick Mathewson e6e740646a Bump all crate versions to 0.0.1 2021-10-29 11:05:51 -04:00
Nick Mathewson 9d3256ec83 Update README.md files 2021-10-29 09:37:15 -04:00
Nick Mathewson 19a61249f8 Merge remote-tracking branch 'origin/mr/112' 2021-10-29 09:16:44 -04:00
eta a12fffc66a Improve docs of more (potentially re-exported) arti-client types
Most of the structs in `arti-client` have example code now, to give a
clearer idea of how they're used.

Annoyingly, a lot of the types exposed in `arti-client` are actually
re-exports, which makes documentation a bit harder: example code that
references other parts of `arti-client` can't actually be run as a
doctest, since the crate it's in is a dependency of `arti-client`.

We might be able to fix this in future by doing the documentation in
`arti-client` itself, but rustdoc seems to have some weird behaviours
there that need to be investigated first (for example, it seems to merge
the re-export and original documentation, and also put the re-export
documentation on the `impl` block for some reason).

For now, though, this commit just writes the docs from the point of view
of an `arti-client` consumer, removing notes specific to the crate in
which they're defined. It's not ideal, but at least the end user
experience is decent.
2021-10-29 14:06:06 +01: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 c11fe200d1 Try writing a bit more documentation for configuration types. 2021-10-28 20:49:17 -04:00
Nick Mathewson 2057142671 Use correct link for AsyncWriteExt::flush 2021-10-28 20:48:54 -04:00
Nick Mathewson 4107533d77 Typo fix in an expect() message. 2021-10-28 20:22:49 -04:00
Nick Mathewson 6cba1acef4 Encourage the use of TorClient::clone(). 2021-10-28 20:21:35 -04:00
Nick Mathewson c8f65e532e DataStream: document the importance of flush(). 2021-10-28 20:21:35 -04:00
Nick Mathewson bf3bfdf62d arti-client example: Try to make the comments a little more clear.
I'm not 100% sure this is better, but it might help the user
understand how Arti works a bit better.
2021-10-28 20:20:23 -04:00
Nick Mathewson 672335ccf6 Update README.md files 2021-10-28 19:59:22 -04:00
Nick Mathewson 19d3c34729 Merge remote-tracking branch 'origin/mr/111' 2021-10-28 19:54:03 -04:00
Nick Mathewson b160177b63 Oops: add missing data files 2021-10-28 19:51:16 -04:00
Nick Mathewson 4a721da54c tor-dirmgr: tests for GetMicrodescsState 2021-10-28 14:21:21 -04:00
eta dcdd8c59df Improve top-level arti-client documentation, add example code
This overhauls the top-level `arti-client` documentation significantly:

- the "Using arti-client" section walks the user through all of the
  necessary steps to initiate a Torified TCP connection, and then
  provides a code example
  - this example is also available as `examples/readme.rs`; it's not run
    as a doctest, since it involves connecting to Tor
  - a "More advanced usage" subheading provides information about stream
    isolation (and can potentially be used for other interesting
    features once we get them).
- a new "Multiple runtime support" section was added to explain the
  purpose and usage of the `tor-rtcompat` crate
- the section on design and privacy considerations was removed; this is
  probably okay to keep in a README, but users of the crate aren't going
  to be interested in this (at least I don't think)

(also, the doc comment for `arti_client::Error` was fixed to make actual
sense)
2021-10-28 19:20:42 +01:00
Nick Mathewson 2f149621fd tor-dirmgr: tests for download schedules. 2021-10-28 13:08:46 -04:00
Nick Mathewson e6c0fbaa10 tor-chanmgr: remove PendingChanError as unnecessary. 2021-10-28 12:41:08 -04:00
Nick Mathewson dcc1acb2fc Merge branch 'test_dirmgr' 2021-10-28 11:56:41 -04:00
Nick Mathewson a730478fd0 Fix clippy warnings in tests. 2021-10-28 11:44:09 -04:00
Nick Mathewson 6dde31f328 Merge remote-tracking branch 'origin/mr/110' 2021-10-28 11:40:18 -04:00
Nick Mathewson 0979e60293 Mark request_retried test as ignored 2021-10-28 11:30:16 -04:00
Nick Mathewson 7e8891b861 tor-dirmgr: Test for GetCertsState 2021-10-28 10:21:56 -04:00
Nick Mathewson 8956e6cd8b tor-dirmgr: Tests for GetConsensusState.
This test uses a consensus that I've copied from
tor-netdoc/testdata.  I would include it directly, but I think that
will cause trouble when it comes time to run "cargo package".
2021-10-28 09:35:18 -04:00
Nick Mathewson 5e27c46d24 tor-dirmgr::state: Mock the view of current time.
This will let us test the state processing code without having to
give it up-to-date directory objects.
2021-10-28 08:41:59 -04:00
Nick Mathewson b7c7c8ba13 tor_circmgr: Refactor and re-enable build_timeout() test
The previous version of this test used the old, racy version of
wait_for (see #149).  The new version is refactored so that
simulated time is only allowed to advance after each step is done,
so that we can actually be sure that each step in the process will
happen as it should.

In order to get the time-advances to proceed properly, and avoid
polluting state between tests, I've had to introduce some machinery
to encode the proper amount for time to advance.  It isn't something
I'd want to use for a whole bunch of tests, but for just one set,
it's fine.

These tests now pass reliably for me.

I wonder if a discrete-event-simulation approach (hello, Shadow)
would let us write tests like these to our hearts' content?
2021-10-27 16:31:31 -04:00
Nick Mathewson 2fae63b5ae Upgrade to fslock version 0.2
This version makes all locks per-handle rather than per-process, by
moving from lockf() to flock() on unix.
2021-10-27 14:52:09 -04:00
eta 4fa0122dde Improve and future-proof the `arti` CLI
This switches out `arti`'s argument-parsing library with `clap`, which
is a lot more featureful (and very widely used within the Rust
ecosystem). We also now use a lot of `clap`'s features to improve the
CLI experience:

- The CLI now expects a subcommand (currently, either "help", or "proxy"
  for the existing SOCKS proxy behaviour). This should let us add
  additional non-SOCKS-proxy features to arti in future.
- `clap` supports default values determined at runtime, so the way the
  default config file is loaded was changed: now, we determine the
  OS-specific path for said file before invoking `clap`, so the help
  command can show it properly.
  - The behaviour of `tor_config` was also changed; now, one simply
    specifies a list of configuration files to load, together with
    whether they're required.
  - That function also way overused generics; this has been fixed.
- Instead of using the ARTI_LOG environment variable to configure
  logging, one now uses the `-l, --log-level` CLI option.
  (The intent is for this option to be more discoverable by users.)
- The `proxy` subcommand allows the user to override the SOCKS port used
  on the CLI without editing the config file.
2021-10-27 19:11:48 +01: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 e64177d97e Fix some clippy-nightly warnings.
These are my fault; I merged the wrong version of !102. :p
2021-10-26 13:13:46 -04:00
Nick Mathewson 9a10d4ae50 Clarify that new SleepProvider methods are testing-only. 2021-10-26 13:06:10 -04:00
Nick Mathewson c6a1bcaa69 circmgr: Split request_timeout test into two.
There seems to be some issue here with the new WaitFor code,
where using the same MockSleepProvider with both of these wait_for()
calls gives questionable behavior under some circumstances (like
when running under Tarpaulin with the wrong set of flags).
2021-10-26 13:01:13 -04:00
Nick Mathewson b0fd7cff8e Merge remote-tracking branch 'origin/mr/102' 2021-10-26 13:01:01 -04:00
Nick Mathewson da45008644 Merge branch 'pb_lite_squashed' 2021-10-26 12:03:51 -04: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
eta e8419abd25 Overhaul the way WaitFor and the MockSleepProvider work
Instead of racily advancing time forward, this commit attempts to rework
how WaitFor works, such that it makes advances when all sleeper futures
that have been created have been polled (by handing the MockSleepRuntime
a Waker with which to wake up the WaitFor).

The above described mechanics work well enough for the double timeout
test, but fail in the presence of code that spawns asynchronous /
background tasks that must make progress before time is advanced for the
test to work properly. In order to deal with these cases, a set of APIs
are introduced in order to block time from being advanced until some
code has run, and a carveout added in order to permit small advances in
time where required.

(In some cases, code needed to be hacked up a bit in order to be made
properly testable using these APIs; the `MockablePlan` trait included in
here is somewhat unfortunate.)

This should fix arti#149.
2021-10-26 16:33:23 +01:00
Nick Mathewson a3c472c67f Tests and refactoring for IsolationMap. 2021-10-26 09:58:09 -04:00
Nick Mathewson be4823818e TorClient::resolve_ptr should take an IpAddr. 2021-10-26 09:42:25 -04:00
Nick Mathewson 1b6098d00f More tests for arti_client::address 2021-10-26 09:32:41 -04:00
Nick Mathewson fadb6727d6 Merge branch 'isolate_clients' 2021-10-26 08:00:27 -04:00
Nick Mathewson 5f2d2c1cac Upgrade curve25519-dalek requirement to 3.2.0
We need this now that we check for contributory behavior.
2021-10-25 14:06:57 -04:00
Nick Mathewson 47234655ce Turn StreamIsolation into a separate type.
Now that we have two kinds of isolation tokens (those set on a
stream, and those set by the stream's associated TorClient), we
need a more sophisticated kind of isolation.

This fixes the bug introduced with the previous commit, where
per-stream tokens would override per-TorClient tokens.
2021-10-25 12:32:18 -04:00
Nick Mathewson 16f6ee4b54 Add an isolate_client() function to create an isolated TorClient.
When two TorClients are isolated, their streams shouldn't share
circuits, even though they share internal circuit and guard state.
2021-10-25 12:02:44 -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 b477f12d83 s/arti-arti-client/arti-client/ and regenerate readme files 2021-10-25 08:40:00 -04:00
Nick Mathewson 529d5d5efb Fix a typo in a comment. 2021-10-25 08:25:59 -04:00
Nick Mathewson 968ffa3d6c Migrate tor-dirmgr from chrono to time 0.3
(This appears to be the emerging consensus of how to handle
RUSTSEC-2020-0159.)
2021-10-24 11:12:06 -04:00
Nick Mathewson 4893e9a15f Migrate tor-netdoc from chrono to time 0.3
(This appears to be the emerging consensus of how to handle
RUSTSEC-2020-0159.)
2021-10-24 10:50:21 -04:00
Nick Mathewson 89de07686d Upgrade to latest tracing-{subscriber,journald} 2021-10-23 22:23:26 -04:00
Nick Mathewson fa266c5644 Upgrade to new version of simple_asn1. 2021-10-22 15:44:37 -04:00
Nick Mathewson e00a1c59ae Run "cargo fix --edition-idioms=2018". 2021-10-22 09:05:45 -04:00
Nick Mathewson 730be38867 Replace references to arti-client in the documentation. 2021-10-21 14:22:21 -04:00
Nick Mathewson 7c7a388e28 Rename tor_client/arti_tor_client to arti_client.
Solves a name conflict with the existing tor_client create.

Closes #130.
2021-10-21 14:22:11 -04:00
Nick Mathewson e9a29b4523 Remove #![allow(clippy::unnecessary_wraps)] in tor-proto. 2021-10-21 14:03:32 -04:00
Nick Mathewson 6af5700c5d Remove #![allow(unreachable_pub)] in shared_ref.rs 2021-10-21 14:00:38 -04:00
Nick Mathewson babd0b53ae Remove #![allow(clippy::unwrap_used)] in cmdline.rs 2021-10-21 13:59:37 -04:00
Nick Mathewson 55ef69724c Remove #![allow_unused] in tor_chanmgr::mgr 2021-10-21 13:48:06 -04:00
Nick Mathewson 7159941ae1 Remove #![allow(dead_code)] in timeouts.rs 2021-10-21 13:42:53 -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
David Goulet b863e63a21 fallbackdir: Regenerate list for October 2021
Closes #200

Signed-off-by: David Goulet <dgoulet@torproject.org>
2021-10-21 09:18:03 -04:00
Nick Mathewson fdddb74de4 Mark consensus as "not-pending" even if its microdescs come from cache.
Previously our code would clear the 'pending' flag on a consensus
only when a _downloaded_ md made it become usable.

Closes #199.
2021-10-20 14:04:54 -04:00
Nick Mathewson 43506601dc Move tor-dirmgr to use a sync::Mutex.
The futures:🔒:Mutex was unnecessary, since we never held it
when we were suspending.
2021-10-20 13:46:44 -04:00
Nick Mathewson c8cfbda339 Finish the timeout-inference side of shared state. 2021-10-20 13:13:15 -04:00
Nick Mathewson db0921fd7e Add a timeout estimator to take estimates from another process. 2021-10-20 12:41:59 -04:00
Nick Mathewson 16ec1d21f2 Allow type of timeout estimator to change at runtime.
This is a big change, but it does simplify the type of Builder a
little, and isolates locking across different (potential) timeout
estimator types.
2021-10-20 12:06:58 -04:00
Nick Mathewson fe85f44fd0 Remove try_lock from StorageHandle. 2021-10-20 09:42:34 -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 650c5a358c Remove unused d_pre from DiffResult. 2021-10-20 08:17:37 -04:00
Nick Mathewson b53abdb67e Implement the "request_loyalty" configuration option 2021-10-19 16:25:52 -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 fc1556461f Fix a broken rustdoc link. 2021-10-19 16:07:13 -04:00
eta e4a3ae492a tor-client/examples: add `hyper` example
The new `hyper` tor-client example demonstrates integrating arti with the
popular Rust `hyper` HTTP library by implementing a custom Hyper "connector"
(a type that can initiate connections to HTTP servers) that proxies said
connections via the Tor network.
2021-10-19 15:59:02 -04:00
Nick Mathewson fb2c7cb85a Also implement tokio Async{Read,Write} on Data{Reader,Writer}.
This will let callers use the tokio traits on these types too, if
they call `split()` on the DataStream.

(Tokio also has a `tokio::io::split()` method, but it requires a
lock whereas `DataStream::split()` doesn't.)
2021-10-19 15:49:49 -04:00
Nick Mathewson a9a9f70eb9 Add a little documentation about when you'll need the tokio trait. 2021-10-19 15:48:55 -04:00
Nick Mathewson f5a7916717 Merge remote-tracking branch 'origin/mr/97' 2021-10-19 15:39:18 -04:00
Nick Mathewson ed6ca1bc18 Move TorClientBuilder into tor_client::config, for consistency. 2021-10-19 15:34:27 -04:00
Nick Mathewson d245147c7f Make elements of TorClientConfig private. 2021-10-19 15:29:36 -04:00
eta ccd1d36e90 tor-proto: implement tokio Async{Read, Write} traits conditionally
futures::io::AsyncRead (and Write) isn't the same thing as tokio::io::AsyncRead,
which is a somewhat annoying misfeature of the Rust async ecosystem (!).

To mitigate this somewhat for people trying to use the `DataStream` struct with
tokio, implement the tokio versions of the above traits using `tokio-util`'s
compat layer, if a crate feature (`tokio`) is enabled.
2021-10-19 19:59:29 +01:00
eta b42a6712c9 tor-client: refactor TorClient::bootstrap's args into a config object
The three arguments TorClient::bootstrap requires by way of configuration
have been factored into a new TorClientConfig object.

This object gains two associated functions: one which uses `tor_config`'s
`CfgPath` machinery to generate sane defaults for the state and cache
directories, and one that accepts said directories in order to create a
config object with those inserted.

(this commit was inspired by trying to use arti as a library and being somewhat
overwhelmed by the amount of config stuff there was to do :p)
2021-10-19 19:59:25 +01: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 6b26ae20a1 On startup, try to lock the state file, and log whether we succeed.
Previously we'd try to grab the lock the first time we wrote to the
file.
2021-10-19 10:41:44 -04:00
Nick Mathewson 36353aacd8 Fix some typos in comments.
Also, tell the "typos" tool to ignore Cargo.lock.
2021-10-19 10:40:32 -04:00
Nick Mathewson 457e7f064c Reverse two swapped log messages 2021-10-19 10:24:19 -04:00
Nick Mathewson 26e1b6fb72 Improve logging when trying to get the lock on the directory cache.
Previously we'd say that we were "waiting for the other process to
bootstrap" even if it was already bootstrapped: and we wouldn't
actually declare success when it was done.
2021-10-19 10:18:02 -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 45fb7022df Remove special-case for ipv6 in is_valid_hostname 2021-10-18 14:56:12 -04:00
Nick Mathewson b63fee25b2 Use a proper RFC5737 address in tests. 2021-10-18 14:53:01 -04:00
Nick Mathewson 539982bf8e Add the "clock" feature to chrono in netdoc.
This seems to fix a bug when running cargo check on netdoc individually.

Reported by @janimo
2021-10-18 14:40:02 -04:00
Nick Mathewson 0750199a8c Move hostname enforcement into TorAddr. 2021-10-18 14:32:05 -04:00
Nick Mathewson 5ae433c747 Change how we connect to target addresses.
Now we all both address:port, (address, port), and more.

We also allow SocketAddr and IpAddr, but only via a trait
labeled as "Dangerous".
2021-10-18 14:03:38 -04:00
Nick Mathewson 26aa0f8e25 Remove "internal" address checking to its own function. 2021-10-18 12:28:50 -04:00
Nick Mathewson a91884389d Merge branch 'reject_bad_hostnames' 2021-10-18 12:19:12 -04:00
Nick Mathewson 36febf7c14 Rename is_localhost to allow_local_addrs, and apply it to IPs too. 2021-10-18 12:07:18 -04:00
Jani Monoses 7fb88307b5 Do not use downcast_ref, use tor-client error. 2021-10-18 13:43:06 +03:00
Jani Monoses 12da3f0771 Remove anyhow usage in tor-client. 2021-10-18 13:43:01 +03:00
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
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