Commit Graph

989 Commits

Author SHA1 Message Date
Nick Mathewson 9e88f279d9 Merge branch 'error-kind-config-transition' into 'main'
Clarify ErrorKind::InvalidConfigTransition

See merge request tpo/core/arti!309
2022-02-14 16:51:32 +00:00
Ian Jackson 30ebb1358a Split up ErrorKind::NoSupport 2022-02-14 16:06:45 +00:00
Nick Mathewson b27c51d3a2 netdoc: Make doc-build errors a separate type
Every other case of tor_netdoc::Error means a parse failure.  This one,
though, means a failure to construct  a document.
2022-02-14 10:46:04 -05:00
Nick Mathewson eeab17f811 Merge branch 'useless_qm' into 'main'
dirmgr: Remove a useless Ok(x?)

See merge request tpo/core/arti!307
2022-02-14 15:42:51 +00:00
Ian Jackson 3a9a4b6532 Clarify ErrorKind::InvalidConfigTransition 2022-02-14 15:41:40 +00:00
Nick Mathewson 61867613a2 netdoc: remove Error::Untimely.
Nothing creates this.
2022-02-14 10:28:58 -05:00
Nick Mathewson 9e3d0bc817 Merge branch 'update_if_zero' into 'main'
Use atomic set-and-check to update OptTimestamps if none.

See merge request tpo/core/arti!297
2022-02-14 15:18:28 +00:00
Nick Mathewson 8ea95aee7a Simplify wait_for_bootstrap to use a Mutex.
Since the only purpose of this function is to make sure that no
bootstrapping task is running, a simple futures:🔒:Mutex
should do the job just fine.

Closes #337.
2022-02-14 09:59:37 -05:00
Nick Mathewson 2cd4f0c872 dirmgr: Remove a useless Ok(x?)
Found by nightly clippy.
2022-02-14 09:30:18 -05:00
Nick Mathewson 1cecc7e45a Change deny(clippy::all) to warn(clippy::all).
Closes #338.
2022-02-14 09:24:06 -05:00
Nick Mathewson 7da5d557bf Rename bootstrap_existing to bootstrap.
(Looks like this one got missed.)
2022-02-11 12:58:25 -05:00
Nick Mathewson 7885db406a Merge branch 'eta/unbootstrapped-clients' into 'main'
Allow creating unbootstrapped `TorClient`s (and `DirMgr`s)

Closes #293

See merge request tpo/core/arti!298
2022-02-11 17:43:46 +00:00
eta 882e75cd28 Allow creating unbootstrapped `TorClient`s (and `DirMgr`s)
This commit changes how the `TorClient` type works, enabling it to be
constructed synchronously without initiating the bootstrapping process.
Daemon tasks are still started on construction (although some of them
won't do anything if the client isn't bootstrapped).

The old bootstrap() methods are now reimplemented in terms of the new
create_unbootstrapped() and bootstrap_existing() methods.

This required refactoring how the `DirMgr` works to enable the same sort
of thing there.

closes #293
2022-02-11 16:42:19 +00:00
eta 5981fa7932 Merge branch 'connect_examples' into 'main'
Write some examples for TorClient::connect()

See merge request tpo/core/arti!303
2022-02-11 16:40:02 +00:00
Nick Mathewson f7a0228a81 Write some examples for TorClient::connect()
These should explain better what you can pass as an address, and
what you should do if you _really need_ to provide a SocketAddr or
something.
2022-02-11 10:11:46 -05:00
Nick Mathewson 0b020e64b4 socksproto: fix one more error type. 2022-02-11 09:36:57 -05:00
Nick Mathewson 4e8db2b836 socksproto: Simplify Truncated handling
Refactor the Error type to remove the yucky internal hidden Truncated
variant.  Instead, there's now an embedded tor_bytes::Error value.

If that tor_bytes::Error is Truncated, we bubble it up when we convert our
handshake result to the nested error struct.

Thus there is still (sadly) a variant of tor_socksproto::Error
that shouldn't be exposed to user code.  But refactoring every
inner method under handshake.rs seemed like a bad idea: once we're using
Result<Result<..>>, the ? operator no longer helps us much.
2022-02-11 09:36:57 -05:00
Nick Mathewson f62b2600c7 Move the Truncated error into tor-errors. 2022-02-11 09:36:57 -05:00
Nick Mathewson 22141d2516 Try to resolve the "Truncated" error in tor-socksproto
I'm not in love with this solution; the others just seem a bit ugly
too.
2022-02-11 09:36:57 -05:00
Nick Mathewson f6189e174b tor-socksproto: Implement HasKind
(This error isn't yet wrapped in TorError, but it will be eventually
when we implement socks proxy and PT support.)
2022-02-11 09:36:57 -05:00
Nick Mathewson 10293ca57e Merge branch 'typos' into 'main'
Fix typos

See merge request tpo/core/arti!301
2022-02-10 13:06:04 +00:00
Dimitris Apostolou 1690e877ed
Fix typos 2022-02-10 14:25:56 +02:00
Nick Mathewson 7670a26d9c tor-bytes: Use InternalError.
This crate's Error type is too low-level to have an ErrorKind, but
it does make sense to use InternalError for the internal errors
here.
2022-02-09 14:39:04 -05:00
Nick Mathewson cb6de69ef6 tor-config: Add HasKind support.
This required a few new ErrorKinds.
2022-02-09 12:30:20 -05:00
Nick Mathewson dc9f1afeb3 Use atomic set-and-check to update OptTimestamps if none.
This fixes a tiny race condition in the previous code, where we
checked whether an OptTimestamp is None a bit before we set it.
Since std::atomic gives us compare_exchange, we might as well use
it.
2022-02-09 10:24:31 -05:00
Nick Mathewson 3c342ae5d7 Add TODOs on uncertain points about time_since_last_traffic
This edge-case was there even before the migration of
595fe1ab88, but now it's more explicit and ought to be
revisited.
2022-02-09 10:06:53 -05:00
Yuan Lyu 595fe1ab88 Remove the use of Mutex in channel unused_since timestamp 2022-02-08 18:28:45 -05:00
Nick Mathewson ff33faf984 Update launch of chan expiration task to new API
This fixes a compilation error.
2022-02-08 10:41:14 -05:00
Nick Mathewson 3f39737817 ErrorDetail Simplify visibility macros a bit.
Instead of declaring a macro that takes vis as an argument, we now
conditionally declare a macro that applies an appropriate visibility.

There's a long comment explaining the rationale here, along with a
couple of other solutions that don't work.
2022-02-08 10:37:46 -05:00
Nick Mathewson d00f00dd41 Rename TorResult to Result.
This is closer to common usage.

(Not that we all agree with common usage, but it's closer to what
people expect.)
2022-02-08 10:37:46 -05:00
Nick Mathewson 80716a294b arti_client: Rename Error to ErrorDetail.
This is closer to what we described in Errors.md.

Also, remove the (sometimes private) Result alias: it was only used in
one or two places, and never exposed in public.
2022-02-08 10:37:46 -05:00
Nick Mathewson 929bcc6c86 TorError: Make detail() an accessor function.
This change lets us make TorError's members unconditionally hidden,
and makes our API a little more consistent (since basically nothing
else is a public field).
2022-02-08 10:37:46 -05:00
eta 109515ecfe Merge branch 'error-improvements' into 'main'
Hopefully uncontroversial improvements to new Error code

See merge request tpo/core/arti!291
2022-02-08 14:42:30 +00:00
Yuan Lyu 3552a49652 Clean up ChannelState ready_to_expire 2022-02-06 15:25:52 -05:00
Yuan Lyu f6f732a478 Expire channels that have been unused for too long 2022-02-04 22:52:51 -05:00
Nick Mathewson f08c0268bc Tests for TargetPorts::display() 2022-02-04 16:41:32 -05:00
Nick Mathewson c43f494b44 tests for tor-error::internal
These tests turned up a need for using the #[track_caller]
annotation in order to get accurate locations, which is fortunately
stable since Rust 1.46.0.
2022-02-04 16:33:43 -05:00
Nick Mathewson 1166977975 Docs and clarification for a bunch of Error stuff 2022-02-04 16:06:11 -05:00
Nick Mathewson 070e52653d Make SpawnError wrappers contain a 'spawning' string
(By our convention, these errors should say what we were trying to
spawn when the error occurred.)
2022-02-04 16:06:11 -05:00
Nick Mathewson 9bd7419c20 Make the Error detail type non-exported from arti-client
At least by default, we should have Error be private, and not expose
it as part of our APIs.

To keep functionality in `arti`, I had to add an `ExitTimeout` error
kind.

For interface consistency, I also re-exported ErrorKind and HasError
from `arti_client`.
2022-02-04 16:06:11 -05:00
Nick Mathewson 7462971c1b Test that TorError implements the right traits.
I had planned to use assert_impl, but that can't check for
the 'static lifetime.
2022-02-04 16:06:11 -05:00
Nick Mathewson 645dc10148 Make TorError implement Clone.
This patch makes only minimal changes in lower-level error types:
we have more refactoring to do.
2022-02-04 16:06:11 -05:00
Nick Mathewson cf4edcac82 Fix a doc link. 2022-02-04 16:03:39 -05:00
Nick Mathewson 8effe24855 Merge branch 'error-poc' into 'main'
New error handling proof of concept

See merge request tpo/core/arti!262
2022-02-04 19:14:10 +00:00
Nick Mathewson f973fe5060 Require backtrace 0.3.8.
This is the first version that builds correctly on our CI.  It's
from back in 2018, so requiring it shouldn't cause any major
problems.
2022-02-04 13:52:46 -05:00
Ian Jackson a49889f116 Properly linkify two doc comment xrefs to issues
Fixes these messages:

  warning: this URL is not a hyperlink
   --> crates/arti/src/watch_cfg.rs:115:5
    |
115 | /// https://github.com/notify-rs/notify/issues/165 and
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://github.com/notify-rs/notify/issues/165>`
    |
    = note: `#[warn(rustdoc::bare_urls)]` on by default
    = note: bare URLs are not automatically turned into clickable links

warning: this URL is not a hyperlink
   --> crates/arti/src/watch_cfg.rs:116:5
    |
116 | /// https://github.com/notify-rs/notify/pull/166 .
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<https://github.com/notify-rs/notify/pull/166>`
    |
    = note: bare URLs are not automatically turned into clickable links
2022-02-04 15:11:44 +00:00
Ian Jackson 6c2f9dac16 channel errors: Include what we were doing 2022-02-04 15:03:19 +00:00
Ian Jackson 5b54d3e08e errors: Add some TODOs as per discussion comments 2022-02-04 14:52:30 +00:00
Ian Jackson 87270415f0 errors: ErrorKind::TODO: Fix typo in message
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/262#note_2772816
2022-02-04 14:46:35 +00:00
Ian Jackson ca960df6b1 errors: Change docs for ErrorKind to refer to Arti
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/262#note_2772810
2022-02-04 14:43:58 +00:00
Ian Jackson f5e874cf91 errors: Drop "Error" and "Failed" from various enum variants 2022-02-04 14:42:37 +00:00
Ian Jackson 0462533863 Box the Error in a TorError
This will get quite large and boxing it here is very convenient.

This also avoids us exposing a large error type to our callers.
2022-02-04 14:42:37 +00:00
Ian Jackson 43fc900284 errors: Handle exit circuit creation failure the new way 2022-02-04 14:42:37 +00:00
Ian Jackson b3cebf163f errors: Handle circmgr setup errors differently
The motivation for doing this now is to remove the `#[from]` so we
would spot where operationsl circuit setup failures were handled.
(But it turns out that they are turned into internal errors!)

Perhaps this will want to become a different error type from circmgr
in due course, but for now we simply use a bespoke variant of
TorError.

It will want its own Kind.  The TODO in the HasKind impl marks
this (amongst much else here).
2022-02-04 14:42:37 +00:00
Ian Jackson d21b2cc6f5 tor-circmgr: Introduce TargetPorts with a pretty Display impl 2022-02-04 14:42:37 +00:00
Ian Jackson 09116d7b4d tor-circmgr::Error: impl HasKind 2022-02-04 14:42:37 +00:00
Ian Jackson f4813e249c tor-circmgr: Handle channel creation errors in the new style 2022-02-04 14:42:37 +00:00
Ian Jackson 0a1cda6886 tor-chanmgr::Error: impl HasKind 2022-02-04 14:42:37 +00:00
Ian Jackson 2a471ffd1a tor-chanmgr: Handle IO errora in the new style
Two ? in the tests become expects, which will do.  That avoids having
to construct a proper error with context here.
2022-02-04 14:42:37 +00:00
Ian Jackson 2101dd5e39 errors: Introduce error_detail feature
Right now we must always expose the `Error` type since we haven't
converted everything.
2022-02-04 14:42:37 +00:00
Ian Jackson 9a293a1f6f errors: Refer to err::Error in some bits of arti_client
We are going to make the top-level Error type conditionally hidden.
2022-02-04 14:42:37 +00:00
Ian Jackson 9e577f9a17 errors: Introduce TorError
Still much to do here.
2022-02-04 14:42:37 +00:00
Ian Jackson 14f67609f7 errors: Initial impl HasKind in arti-client, ErrorKind::TODO
This involves making a temporary ErrorKind::TODO.  That will continue
to exist until all errors (at least, the ones that make it out to
here) can be properly categorised.

Introducing this will let us work from the top and bottom towards the
middle.
2022-02-04 14:42:37 +00:00
Ian Jackson bdd58bb6b7 errors: impl HasKind for GuardMgrError 2022-02-04 14:42:37 +00:00
Ian Jackson a779c1f1dd spawn errors: tor-guardmgr: Use formulaic pattern
This makes this like all the others, and is marginally shorter
2022-02-04 14:42:37 +00:00
Ian Jackson 2f1d98403b spawn errors: Fix tor-dirmgr 2022-02-04 14:42:37 +00:00
Ian Jackson de17c64412 spawn errors: Fix arti-client, tor-chanmgr, tor-circmgr
Provide an enum variant to contain the SpawnError and a From impl.

We use `#[from]` here because it doesn't really make sense to attach
any context, as it's not likely to be very relevant.
2022-02-04 14:42:37 +00:00
Ian Jackson 68d0ec437f spawn errors: impl HasKind for futures::SpawnError
This needs two kinds.  We have decided to treat a non-shutdown
SpawnError as "unexplained" rather than as an InternalError.

There are many crates whose
  From<futures::task::SpawnError> for Error
erroneously treat it as an internal error.  We will fix them in a moment.
2022-02-04 14:42:37 +00:00
Ian Jackson a623982197 tor_persist::Error: impl HasKind and adjust comments
And change the comments to slightly reinterpret these errors, to
relate to the circumstances rather than error generation site.
2022-02-04 14:42:37 +00:00
Ian Jackson 6e1dc612cc tor-error: Add as a ddpendency to many crates
Doing this here makes it easier when I rebase/reorder things
2022-02-04 14:42:37 +00:00
Ian Jackson 89b0c108d7 tor-error: provide into_internal! 2022-02-04 14:42:37 +00:00
Ian Jackson 776270fee2 tor-error: Allow making an `InternalError` from some other error
This can be used in call sites where an error is thought not to be
possible.

The `source` will be used only for formatting messages.
2022-02-04 14:42:37 +00:00
Ian Jackson c963bd648b tor-error: Introduce InternalError as a type and a kind
This can contain a backtrace, which will be printed.
2022-02-04 14:42:37 +00:00
Ian Jackson 9e5b6fa820 tor-error: Skeleton for new crate
As per doc/Errors.md.

Currently there are no error kinds.  Some will be added as we go along.
2022-02-04 14:33:09 +00:00
Ian Jackson a4765717da tor-persist: Distinguish load vs. store json errors
Serialisation errors ought not to occur, since they would represent an
attempt to store malformed data, or something.  (We always convert to
a string, so the JSON error never contains IO errors or the like.)

Deserialisation errors mean the persistent state is corrupt.
2022-02-04 14:33:09 +00:00
Ian Jackson a7e6caa731 tor-circmgr: impl Display for TargetPort
This will be used for error handling, and perhaps other things.
2022-02-04 14:33:09 +00:00
Ian Jackson 5edd031b97 tor-linkspec: impl Display for OwnedChanTarget and OwnedCircTarget 2022-02-04 14:33:09 +00:00
Ian Jackson eaa449d373 tor-circmgr: Turn a type annotation comment into code
The type annotation may not be necessary for inference, but as a
comment it risks becoming false.  So it should be uncommented, or
deleted.

Error types round here are not entirely trivial so uncomment it.
2022-02-04 14:33:09 +00:00
Nick Mathewson e332aa2716 Merge branch 'ticket270' into 'main'
Watch configuration files and reload them when they change

Closes #270

See merge request tpo/core/arti!280
2022-02-03 16:56:37 +00:00
eta e9087e1fed Merge branch 'eta/reactor-2.5' into 'main'
Fix severe reactor ordering problems

See merge request tpo/core/arti!282
2022-02-03 16:27:57 +00:00
Nick Mathewson 49431f5442 Document that `notify` behavior is strange with symlinks
(More specifically, `notify` behaves differently on different
platforms.  On some, it can watch specific directory objects on the
filesystem, and so it only notices when _those_ directories change.
If you change a symlink so that the canonical configuration file
location is now in some other directory, `notify` won't notice.  But
on other platforms, notify just does "stat()" in a loop. On those,
it _will_ notice if the configuration file changes.)
2022-02-03 11:11:21 -05:00
Nick Mathewson 73bb6f342e Merge branch 'add-final-newline-force' into 'main'
Add editorconfig to force some rules (Final Newline)

See merge request tpo/core/arti!289
2022-02-03 15:27:13 +00:00
Daniel Schischkin 3a7412f4cf Add editorconfig to force some rules (Final Newline) 2022-02-03 15:27:13 +00:00
Nick Mathewson 03755a5c7b Merge branch 'dirclient-testing' into 'main'
dir-client: bug fix and more tests

See merge request tpo/core/arti!271
2022-02-03 15:09:06 +00:00
eta 24d12163f2 Fix severe reactor ordering problems
A number of severe problems with the circuit reactor were fixed which
could cause reordering of cells (which causes relays to terminate the
circuit with a protocol violation, as they become unable to decrypt
them). These mostly revolve around improper usage of queues:

- The code assumed that a failure to place cells onto the channel would
  persist for the duration of a reactor cycle run. However, under high
  contention, this wouldn't always be the case.
  - This leads to some cells getting enqueued while others go straight
    through, before the enqueued cells.
  - To fix this, we block sending cells out of the channel while there
    are still some enqueued.
- The hop-specific queues queued after encryption, not before. This was
  very brittle, and led to frequent mis-ordering.
  - This was fixed by making them not do that.

This is arti!264 / 5bce9db562 without the
refactor part.
2022-02-03 15:04:28 +00:00
Nick Mathewson 656ad08d65 Avoid a potential infinite loop in configuration-watching
Since the user can put their logfiles and configuration files in the
same directory, writing to the log can trigger an event from
`notify`.  If we log every non-interesting event from `notify`, then
we'll trigger the logs every time we log, and fill up the disk.

This commit removes the offending log and adds a comment about why.
If we someday decide we do need to log here, maybe we can rate-limit
the messages or something.
2022-02-03 09:38:58 -05:00
Nick Mathewson d90bc353ba Treat rescan events as meaning "reload configuration". 2022-02-03 09:36:12 -05:00
Nick Mathewson 7b8ad0ca2c Explain a testing oddity in tor-dirclient. 2022-02-03 09:17:34 -05:00
Nick Mathewson c302c6a8bd Fix a stale comment in tor-dirclient. 2022-02-03 09:17:10 -05:00
eta cc37c8f5b5 Merge branch 'typos' into 'main'
Fix typos

See merge request tpo/core/arti!285
2022-02-03 13:12:38 +00:00
Ian Jackson 7be3bf6339 Temporarily disable some clippy lints on nightly 2022-02-02 21:57:30 +00:00
Nick Mathewson ea6458c9bd Add a couple of TODOs about configuration-watching. 2022-02-02 15:43:42 -05:00
Nick Mathewson 42ce00091f Before reloading configuration, drain all pending file changes
This way, if there are a bunch of changes at once, we only reload
one time.
2022-02-02 15:43:42 -05:00
Nick Mathewson fd53c9ddb5 Refactor file-watching code to watch parent directories.
Due to limitations in notify and the OS APIs it uses, it isn't
actually so useful to watch a single file.  Instead, we have to
watch the directories that contain the files, and filter out any
events that aren't about the specific files we care about.

I've put the logic here into a new type, but I've left the type
un-exported: its API is pretty ugly, inasmuch as the caller needs to
jump through hoops to only get the events that they want.  That's
not too bad so long as the API is private, but we'd want better if
we were exposing this.
2022-02-02 15:43:39 -05:00
Ian Jackson 5bfe94eb0e Untangle two needless Ok(r?) into just r
Prompted by clippy::needless_question_mark.  Sometimes Ok(r?) is
needed to do automatic error conversion.  I assume the lint checks for
that.  Anyway, in these cases it's not needed.
2022-02-02 18:35:28 +00:00
Ian Jackson b7fec1c8a4 Remove many needless borrows and slices
Found via clippy::needless_borrow.  In some cases I removed needless
`[..]` too.  See also:
  needless_borrow suggestion doesn't go far enough
  https://github.com/rust-lang/rust-clippy/issues/8389
2022-02-02 18:34:26 +00:00
Ian Jackson b695ebd039 clippy: Pass simply &output to fs::write
clippy::needless_borrow quibbles here, IMO correctly.  Its suggestion
didn't go far enough: output is a String and a &String can be passed
to write as-is for identical effect.
2022-02-02 18:33:23 +00:00
Dimitris Apostolou 6526321851
Fix typos 2022-02-02 20:18:22 +02:00
Nick Mathewson fc33ab273f arti: Limit mut-ness of cfg_sources to one block. 2022-02-02 13:09:54 -05:00
Nick Mathewson e9f1198701 arti-config: add blank lines between functions. 2022-02-02 13:08:03 -05:00
Nick Mathewson 636d88b06d arti-config: Small type and comment refactoring from review. 2022-02-02 13:05:57 -05:00
Ian Jackson 1c31399356 Merge branch 'reload-config-prep' into 'main'
Preparatory work for auto config reload

See merge request tpo/core/arti!284
2022-02-02 17:31:23 +00:00
Nick Mathewson bf7f7dfbbf Detect changes in non-client configuration sections too
We don't yet do much with these, but we can avoid discarding them.
2022-02-01 16:04:59 -05:00
Nick Mathewson 1fbea7cd1e Make configuration-watching configurable and off-by-default.
I'm slightly concerned about whether this is behavior people would
expect to have on-by-default, so let's make this off-by-default for
now.

Maybe the `application` and `system` sections should merge?
2022-02-01 16:04:59 -05:00
Nick Mathewson b4c3aaf362 Reload configuration when our configuration files change.
Closes #270
2022-02-01 16:04:53 -05:00
Nick Mathewson 610ccb3040 Un-Arc<> TorClient in the arti crate
TorClient doesn't need to be wrapped in an Arc any longer, thanks
to other refactoring.
2022-02-01 14:43:31 -05:00
Nick Mathewson feab848509 arti_config: Refactor configuration sources into a struct
This is by no means our final API, but should represent an
improvement.  Here instead of having to specify a list of files and
their is-this-optional status, along with a list of command-line
options, we have a single structure that encapsulates all of that
information.

Two advantages here:

 - Callers no longer have to remember what the boolean means.
 - We can "reload" more easily, by keeping the source object around.

This change also implements the correct behavior for our default
configuration file in `arti::main`: if the file is absent and the
user doesn't list a config file, that's no problem.  But if the user
lists _that very same config file, we should insist that it be
present.
2022-02-01 14:26:39 -05:00
Nick Mathewson 487f3be6de Expose Reconfigure enum from arti-client.
This enum is required to use `TorClient::reconfigure` correctly, and
as such ought to be re-exported.
2022-02-01 14:26:39 -05:00
eta 5b14008a82 arti-bench: summarize statistics with a new `Statistic` type (#298)
This implements the proposal from arti#298, making the
`BenchmarkResults` type be made out of a bunch of new `Statistic` types
(which summarize the mean, median, range, and standard deviation of an
arbitrary value) instead of overloading `TimingSummary` for this
purpose.
2022-02-01 16:09:24 +00:00
Nick Mathewson c8dd73d55f Upgrade required version of futures crate to 0.3.14
Earlier versions have a bug in UnboundedReceiver that make our new
dirclient tests fail.
2022-02-01 09:54:47 -05:00
Nick Mathewson 582f1463d6 dirclient: refactor and test "should-i-retire-the-circuit" code. 2022-02-01 09:54:47 -05:00
Nick Mathewson 36069fc2d0 dirclient: Add tests for a number of failing cases.
These bring the case a tiny improvement in test coverage, and also
manage to turn up a few bugs.
2022-02-01 09:54:47 -05:00
Nick Mathewson 7fdde559d4 dirclient: don't return too-long responses on decompression failure
There are a couple of places where we forgot to truncate our
return-buffer to its actual size, and instead returned a big bunch
of zeros.  Found while writing the tests in the next commit.

Someday, we'll have ReadBuf and won't have to worry about these
things.
2022-02-01 09:54:47 -05:00
Michael 334bba2ef2 Fix invalid path character on windows 2022-01-31 20:53:13 +00:00
Nick Mathewson 329bde58dd Bump tor-netdir and tor-guardmgr versions
tor-netdir needs to bump because tor-netdoc bumped, even though
there were no other changes in tor-netdir.  Whoops.

tor-guardmgr needs to bump because it already published, with the
older tor-netdir.
2022-01-31 11:05:34 -05:00
Nick Mathewson 01d9937308 Bump the patch version of every crate that changed since 0.0.3 2022-01-31 10:30:52 -05:00
Nick Mathewson 5187b05c19 Use script to update README.md files. 2022-01-28 08:36:34 -05:00
Ian Jackson 427e07ec8a Merge branch 'bug299' into 'main'
Make max_file_limit configurable

Closes #299

See merge request tpo/core/arti!261
2022-01-28 11:17:49 +00:00
Neel Chauhan 417809123c Make max_file_limit configurable 2022-01-28 11:17:49 +00:00
Nick Mathewson 98d8171610 Fix test failure in tor_dirmgr::state::test::get_microdescs_state
This failure occurred because our tests use canned data to exercise
the directory state functionality, and the canned consensus has
suddenly become very expired.

There are better fixes possible, but this is a minimal one that
should get CI working on main again.
2022-01-27 17:13:38 -05:00
Nick Mathewson 19f878b3aa tor-rtcompat: remove some unused code.
Nothing actually used these accessor functions, and it's not clear
what would.  We can add them later if they're needed.
2022-01-27 15:52:59 -05:00
Nick Mathewson f7373f8b20 tor-rtcompat: Add some miscellaneous tests
These probably aren't for things that will fail IRL, but it's nice
to have coverage on the code, just in case.
2022-01-27 15:48:30 -05:00
Nick Mathewson af85262257 tor-rtcompat: Simplify test-declaration macros.
Now there's much less copy-and-paste.
2022-01-27 15:09:09 -05:00
Nick Mathewson 9435e4b36e Move tor-rtcompat tests to lib.rs
This makes our layout more similar to our other crates, and
successfully informs our grcov exclusion pattern that these tests
are indeed tests.

Doing this knocks down the reported coverage for the tor-rtcompat
crate, but that's okay: we hadn't earned it.

I hereby promise that this commit is only code-movement.
2022-01-27 14:45:00 -05:00
Nick Mathewson 9f3ad85d75 Document why {current,create}_runtime are type-erased 2022-01-27 10:31:45 -05:00
eta c4321289f2 Apply @eta's suggestions from review on !263
Comment-only.
2022-01-27 15:25:57 +00:00
Nick Mathewson 5dcc821146 Fix documentation references for tor-rtcompat refactoring. 2022-01-26 14:58:28 -05:00
Nick Mathewson 9c043a648a arti: be more careful to use the user-selected runtime 2022-01-26 14:31:49 -05:00
Nick Mathewson bf8fa66d36 Rename `SpawnBlocking` trait to `BlockOn`.
This avoids a future confusion with the new `SpawnBlocking` trait in
async_executors v0.5, and better describes what the trait provides.
2022-01-26 14:06:58 -05:00
Nick Mathewson dec2c4ee63 Make test_with_all_runtimes cover _all_ the runtimes.
This took some refactoring, so that I wouldn't need to define 9
different versions of the function.  It also required that we change
the behavior of test_with_all_runtimes slightly, so that it asserts
on _any_ failure rather than asserting on most but returning Err()
for others.  That in turn required changes to a few of its callers.

There's probably a better way to do all of this macro business, but
this is the best I could find.
2022-01-26 14:06:58 -05:00
Nick Mathewson 30b3818a9e Make the native-tls crate optional.
This commit puts the native-tls crate behind a feature.  The feature
is off-by-default in the tor-rtcompat crate, but can be enabled
either from arti or arti-client.

There is an included script that I used to test that tor-rtcompat
could build and run its tests with all subsets of its features.

Closes #300
2022-01-26 14:06:58 -05:00
Nick Mathewson 8af3528cd3 Define aliases for "the best enabled runtime".
This helps us simplify our code in a few ways, and will help even
more once native_tls is optional.
2022-01-26 14:06:58 -05:00
Nick Mathewson 6f29d485e4 Make current/create functions into runtime member functions.
This should help avoid some amount of temptation towards API
proliferation.
2022-01-26 14:06:58 -05:00
Nick Mathewson 2333d0466e Rename FooRuntime to FooNativeTlsRuntime for consistency. 2022-01-26 14:06:58 -05:00
Nick Mathewson 05a04220cc Limit the inner types in tor-rtcompat that have to implement Clone
If we implement our own clone on CompoundRuntime, we no longer need
Clone implementations on our TlsProvider implementations.
2022-01-26 14:06:58 -05:00
Nick Mathewson 99c59a8f2b Remove no-longer-needed tokio runtime helper macro 2022-01-26 14:06:58 -05:00
Nick Mathewson 668364d75d Unify TokioRuntime and TokioRuntimeHandle
Having separate types here doesn't justify the (very limited)
benefit of distinguishing between the case where we have created an
executor that we own and the case where we have a handle to an
already-running tokio executor.

Part of #301.
2022-01-26 14:06:58 -05:00
Nick Mathewson 884d614a61 Remove a now-incorrect comment in tor-proto. 2022-01-26 14:06:58 -05:00
Nick Mathewson 5af8a1bf28 Remove misspellings of "rusttls". 2022-01-26 14:05:05 -05:00
Nick Mathewson e4e691a790 More comments on the limitations of tor-rtcompat's TLS API
Also, more comments on why these limitations are safe within the
context of Tor, but you wouldn't want to use them elsewhere.
2022-01-25 13:16:39 -05:00
Nick Mathewson 0898b485aa Comment-only: document sni_hostname more.
Previously we expected the reader to automatically know why it was
called "SNI", which really isn't fair.
2022-01-25 13:16:39 -05:00
Nick Mathewson d1d121aac6 Refactor native_tls usage into its own module
This change uses the async-native-tls crate for everything, and
deletes some duplicated code.
2022-01-25 13:16:39 -05:00
Nick Mathewson 8def5a0d89 tor-rtcompat: Add support for rustls.
This is based on @janimo's approach in !74, but diverges in a few
important ways.

1. It assumes that something like !251 will merge, so that we can
   have separate implementations for native_tls and rustls compiled
   at the same time.

2. It assumes that we can implement this for the futures::io traits
   only with no real penalty.

3. It uses the `x509-signature` crate to work around the pickiness of
   the `webpki` crate.  If webpki eventually solves their
   [bug 219](https://github.com/briansmith/webpki/issues/219), we
   can remove a lot of that workaround.

Closes #86.
2022-01-25 13:16:39 -05:00
Nick Mathewson 979cfb46d1 Add a C program to make Tor-style X509 link certificates
We should never use this for anything but making the testing
certificates we use for making sure our TLS implementation works.
2022-01-24 14:22:07 -05:00
eta 146fbbaaa8 Merge branch 'ticket255' into 'main'
Refactor our Runtime implementations to allow replacement parts

Closes #255

See merge request tpo/core/arti!251
2022-01-24 14:09:51 +00:00
Ian Jackson a79a2e87be Rename TorClient::set_stream_prefs
In line with the rest of the renaming.

As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/256#note_2771617
2022-01-21 17:12:08 +00:00
Ian Jackson dcf26466f3 StreamPrefs: Re-alphabetise imports following rename
Placates rustfmt
2022-01-21 11:07:21 +00:00
Ian Jackson aa4d8de16e StreamPrefs: rename from ConnectPrefs
The docs even say this is about stream.

As @nickm writes in
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/252#note_2771289

  we generally call end-to-end connections that are tunneled over Tor
  "Streams" to distinguish them from everything else in the Tor
  protocols that could possibly be called a "Connection".

That seems to apply here too.
2022-01-21 11:07:15 +00:00
Ian Jackson 695a33c1fd Merge branch 'always-isolate' into 'main'
Provide isolate-all-streams function

Closes #279

See merge request tpo/core/arti!252
2022-01-20 19:08:05 +00:00
Ian Jackson 7bc8941742 isolation: Rename isolate_every_stream from ..._connection
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/252#note_2771291
2022-01-20 17:53:09 +00:00
Ian Jackson 23c1fc8c56 isolation: Rename (internal) EveryStream enum variant
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/252#note_2771289
2022-01-20 17:53:09 +00:00
Nick Mathewson 06c15f21b4 isolation: Much better wording for always isolate setting 2022-01-20 17:52:10 +00:00
Nick Mathewson a58e4e3688 Test for PathConfig::at_least_as_permissive_as().
This is totally not just an exercise to get combined test coverage
for tor-circmgr over 90% because I needed something to do that
wouldn't distract anybody else. :)
2022-01-20 09:57:19 -05:00
Nick Mathewson a5288aa15f Rename PathConfig::more_permissive_than()
Since it implements a "<=" type relationship, it should be called
"at_least_as_permissive_as()."  Since it's a crate-private function,
the long name isn't too bad.
2022-01-20 09:55:54 -05:00
Nick Mathewson b0ea74aa60 Remove "self" arg from PathConfig::builder()
This was added by mistake.
2022-01-20 09:53:12 -05:00
Nick Mathewson a57b4962b3 Merge branch 'stuff-prefs' into 'main'
Provide TorClient::set_default_prefs and clone_with_prefs

Closes #290

See merge request tpo/core/arti!250
2022-01-20 14:36:41 +00:00
Ian Jackson ced24b1974 connection preferences: Make `set_default_prefs` private for now 2022-01-20 13:52:30 +00:00
Ian Jackson e04e41a1db connection preferences: Make `clone_with_prefs` must_use
As per
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/250#note_2771239
2022-01-20 13:50:12 +00:00
Ian Jackson 9e904167e4 isolation: Provide isolate-every-connection option 2022-01-20 12:08:22 +00:00
Ian Jackson a5356aed65 isolation: Provide new_isolation_group method
In the usual case, set_isolation_group is awkward.

This is perhaps slightly duplicative with TorClient::isolated_client().
If so then perhaps the *latter* should be abolished.
2022-01-20 12:08:22 +00:00
Ian Jackson 639db26d58 isolation: Refactor to introduce a bespoke enum
No functional change.

This will grow a new variant shortly.
2022-01-20 12:08:22 +00:00
Nick Mathewson 17920e43f8 Refactor Runtimes to use separate TLS implementations internally.
This will make it easier to implement them using some other TLS
provider as well, without having to duplicate all of our code.
2022-01-19 15:47:26 -05:00
Nick Mathewson 8d3e4576da Add a macro to help with opaque Runtime wrappers.
We're soon going to have our different Runtime types be built as
CompoundRuntime instances.  We don't want to expose that detail,
though, so we'll use this macro to make them implement the right
traits.
2022-01-19 15:47:26 -05:00
Nick Mathewson dd72607601 Add a CompoundRuntime type for runtime construction.
This type can solve two problems at once.

First, it lets users replace parts of an existing runtime
implementation without replacing the whole thing.  For example, you
can use it to override your TcpProvider implementation to solve
problems like #235.

Second, we can use it internally to tor-rtcompat to define Runtimes
piece-by-piece.  Mostly we'll use this to separate our Tls
implementations from our implementations of the rest of the Runtime.
2022-01-19 15:47:26 -05:00
Ian Jackson 9a77b23cdd clippy: Rename a `decode_chanmsg` from `handle_`
As per https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/249#note_2771025

It doens't really handle it.
2022-01-19 18:46:13 +00:00
Ian Jackson 6c5e099be9 handshake: Use read_exact, not read and checking len
read_exact has a loop in it, which we need.

This means we end up separating the two sites that generate the "not a
relay" error, so we need to fish out the error construction.

As per https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/249#note_2771023
2022-01-19 18:45:53 +00:00
Ian Jackson 7ff16fc252 connection preferences: Provide `clone_with_prefs` method 2022-01-19 17:45:59 +00:00
Ian Jackson 4ddbb3daeb connection preferences: Provide `set_connect_prefs` method 2022-01-19 17:45:59 +00:00
Ian Jackson dec0e1e756 connection preferences: Take ConnectPrefs by reference
This may save quite a bit of copying.  The callees don't need to copy
the whole struct; they copy the bits they need.
2022-01-19 17:42:43 +00:00
Ian Jackson 1437f953b6 connection preferences: Rename variable and docs to not say "flags"
These aren't flags.  Eg, there's an isolation token in there.
2022-01-19 17:39:29 +00:00
Ian Jackson e84ff24d11 isolation: Document orthogonality of isolated_client and isolation_group 2022-01-19 17:39:29 +00:00
Ian Jackson c433899948 clippy: Rename a `from_foo` method that doesn't do conversion 2022-01-19 17:26:09 +00:00
Ian Jackson 1d5a480f79 Fix two bugs related to incomplete read/write
Discovered by clippy
2022-01-19 17:17:56 +00:00
Ian Jackson 5e16a52e1c clippy: Suppress a warning 2022-01-19 17:12:26 +00:00
Nick Mathewson db2ca6ebc4 Merge branch 'bootstrap_reporting' 2022-01-19 08:40:36 -05:00
eta ca35873654 Merge branch 'eta/292-2' into 'main'
arti-bench: add concurrency, write benchmark results out to JSON

See merge request tpo/core/arti!243
2022-01-19 13:28:23 +00:00
Nick Mathewson d1c362f308 bootstrap reporting: Documentation fixups from review. 2022-01-19 08:22:42 -05:00
eta a768e7fd8f Merge branch 'correct-cache' into 'main'
Put our cache files in the right place.

Closes #297

See merge request tpo/core/arti!244
2022-01-19 12:56:49 +00:00
Nick Mathewson 79e6dc1d4b Put our cache files in the right place.
This resolves a copy-and-paste error where we were putting
everything in our state directory.

Closes #297.
2022-01-18 13:32:06 -05:00
Nick Mathewson 41e3498f8a Integrate status information at arti-client
This commit combines status update information from tor-dirmgr and
tor-chanmgr in the arti-client crate, so that the user can get to
it; it represents a high-level view of the client's ability to reach
the network and route traffic.

I have omitted the tor-circmgr support for now; it's mostly not
needed.

At present it's not so useful, since there's no way for a client to
get a TorClient that _isn't_ completely bootstrapped, and therefore
there's no way to actually watch these events until they're no
longer interesting.  That should change with arti#293.

This is part of #96.
2022-01-18 13:27:56 -05:00
Nick Mathewson c162e57e29 tor-chanmgr: Add bootstrap/status reporting.
The information is pretty basic here: we use "have we been able to
connect/TLS-handshake/Tor-handshake" as a proxy for "are we on the
internet? Are we on a reasonably unfiltered part of the internet?"

Eventually we'll want to make the information gathered and exported
more detailed: I've noted a few places in the code.  For now,
however, this is about as good as C Tor does today, and it should be
a good starting point.

This uses a slightly different design from tor-dirmgr.  Instead of
exporting an entire state structure via `postage::watch`, it exports
only the parts of that structure which the user is supposed to
read.  I think that's more reasonable in this case because most of
the possible internal transitions in the tor-chanmgr state don't
cause a change in the exposed status.
2022-01-18 13:06:08 -05:00
Nick Mathewson f34faec7d9 tor-dirmgr: Create a bootstrap-status exporting mechanism.
The interface is similar to the one exposed by `arti-client`: it
internally uses postage::watch to give a series of events showing
when a bootstrap status is changing.

Thanks to the existing state/driver separation in the DirMgr design
we don't need much new logic: each download state needs to expose
(internally) how far along it is in its download, which the
bootstrap code passes to the DirMgr if it has changed.

I believe that in the long run, we'll probably want to expose more
(or different) information here, and we'll want to process it
differently.  With that in mind, I've made the API for
`DirBootstrapStatus` deliberately narrow, so that we can change its
of its internal later on without breaking code that depends on it.

(The information exposed by this commit is not yet summarized in
`arti-client`.)

Part of #96.
2022-01-18 13:06:08 -05:00
eta 2aeac45f49 arti-bench: add concurrency, write benchmark results out to JSON
We now conduct benchmark tests with multiple concurrent streams (by
default; this is configurable by passing `-p` to `arti-bench`).
Currently, these results just get "flattened" for the purposes of
statistical analysis (as in, results_raw contains the results of each
connection's timing summary, across all benchmark runs). This might be
something we wish to change in future.

The stats summary now also records "best" and "worst" values for each
metric, to give a rough idea of the range of values encountered.

Additionally, we now support writing the benchmark results out to a JSON
file. A future commit may integrate this with CI, so that we have
benchmark results for every commit as a build artefact.

(some documentation was also fixed)

part of arti#292
2022-01-18 13:46:36 +00:00
eta 51ddac646b Merge branch 'eta/292-1' into 'main'
arti-bench: add support for multiple samples & averaging

See merge request tpo/core/arti!240
2022-01-14 15:18:58 +00:00
eta 82beb52fca arti-bench: add support for multiple samples & averaging
We now do multiple samples (configurable; default 3) per type of
`arti-bench` benchmark run, and take a mean and median average of all
data collected, in order to hopefully be a bit more resilient to random
outliers / variation.

This uses some `futures::stream::Stream` hacks, which might result in
more connections being made than required (and might impact the TTFB
metrics somewhat, at least for downloading).

Results now get collected into a `BenchmarkResults` struct per type of
benchmark, which will be in turn placed into a `BenchmarkSummary` in a
later commit; this will also add the ability to serialize the latter
struct out to disk, for future reference.

part of arti#292
2022-01-14 15:00:11 +00:00
Nick Mathewson ae9bea5d94 Merge branch 'bootstrap_reporting_api' into 'main'
Implement the basics of a bootstrap-status API.

See merge request tpo/core/arti!237
2022-01-13 15:42:50 +00:00
Nick Mathewson 1bd2790d51 Implement the basics of a bootstrap-status API.
The purpose of a this API is to tell the user how far along Arti is
in getting bootstrapped, and if it's stuck, what it's stuck on.

This API doesn't yet expose any useful information: by the time it's
observable to a client, it's always "100% bootstrapped."  But I'm
putting it in a MR now so that we can review the basic idea, and to
avoid conflicts with later work on tickets like #293 and #278.

This is part of #96.
2022-01-13 10:29:49 -05:00
daniel.eades 1ecf383e8f refactor `arti-bench` 2022-01-13 14:16:01 +00:00
eta c003fde04d Merge branch 'channel-arc-rework-5' into 'main'
chanmgr: get rid of Arc around Channel

See merge request tpo/core/arti!236
2022-01-13 13:12:30 +00:00
Ian Jackson 9b723cba53 chanmgr: get rid of Arc around Channel 2022-01-13 13:12:29 +00:00
Nick Mathewson bbf7c59b2d Describe when we will need SendmeAcceptMinVersion
(spoiler: not until we have a relay implementation)

Closes #53.
2022-01-12 15:52:24 -05:00
Nick Mathewson e335f6c75a Change RequireSendmeAuth to an enum.
This is a fine example of why booleans are risky:
it's far to easy to pass "animate:bool" into "inanimate:bool" like
we did here.

This is a followup from our fix to #294.
2022-01-12 15:46:36 -05:00
Nick Mathewson 1e915c3946 Fix a boolean inversion in auth_sendme_optional.
Previously we were requiring authenticated sendme cells exactly when we
should be permitting the old format, and vice versa.

This bug was caused by using a boolean to represent one property, but
with giving that boolean two different senses without inverting at the
right time.

The next commit will prevent a recurrence.

Closes #294
2022-01-12 15:36:55 -05:00
Nick Mathewson d49a490d4a Document SendmeEmitMinVersion status
(We don't need to look at SendmeEmitMinVersion since higher
values are not yet defined.)
2022-01-12 15:13:19 -05:00
Nick Mathewson e0ee3b5049 Explain that CfgPath can look at the environment.
Closes #246.
2022-01-12 14:59:13 -05:00
Nick Mathewson b4761f8cfd Merge branch 'eta/182' into 'main'
Improve the layout of crate exports; add runtime convenience functions

See merge request tpo/core/arti!235
2022-01-11 18:42:15 +00:00
Ian Jackson cfcd3ea689 Add a blank line between doc and comment. 2022-01-11 18:23:58 +00:00
Nick Mathewson 08d3ed978f Merge branch 'ticket_176_v2' into 'main'
guardmgr: Use a better persistent data format

Closes #176

See merge request tpo/core/arti!233
2022-01-11 17:52:00 +00:00
Nick Mathewson b89ce48490 Remove now-unused GuardSet::new(). 2022-01-11 12:00:09 -05:00
Nick Mathewson 70a2e2e751 guardmgr: Use a better persistent data format
Previously we stored only one guard sample, in a state file called
"default_guards".  That's not future-proof, since we want to have
multiple samples in the future.  (`guard-spec.txt` specifies
separate samples for highly restrictive filters, and for bridge
usage.)

This patch changes our behavior so that we can store multiple
samples in a new "guards" file.

I had thought about automatically migrating from the previous file
format and location, but I don't think that's necessary given our
current (lack of) stability guarantees.

Closes #176.
2022-01-11 12:00:09 -05:00
Nick Mathewson f89b0bc752 guardmgr::..::sample_test: Fix intermittent failure.
This test should only fail very rarely (around 1/2.4e8) when guards
are chosen from a list of 20 with uniform probability.  But that
wasn't what we were doing on the mock test network: we were choosing
from a list of 10 viable guards, with nonuniform probability.

As a fix, we change the test network probabilities so that the
guards _are_ chosen with a uniform probability for this test, and we
use a modified version of the test network where there are indeed 20
Guard-flagged relays with the required DirCache=2 protocol.

Closes #276.
2022-01-11 11:35:16 -05:00
eta 41e202a3a4 Improve the layout of crate exports; add runtime convenience functions
This commit addresses multiple problems highlighted by arti#182:

- `arti-client` had some types in its public API that weren't accessible
  without importing another crate (`CfgPath`, `DataReader`,
  `DataWriter`). This has been fixed.
  - In addition, the doc comments for `DataReader` and `DataWriter` were
    cleaned up to be of better quality, now that they're public.
- It was impossible to use `arti-client` without also importing
  `tor-rtcompat`. This is now fixed by the addition of two convenience
  methods: `TorClient::bootstrap_with_tokio` and
  `TorClient::bootstrap_with_async_std`.
- Potentially controversially: `tor-rtcompat` now returns *concrete*
  types from methods like `current_runtime`, instead of `impl Runtime`.
  - This was needed in order to actually be able to name the `TorClient`
    type that results from using these methods.
  - This does mean we lose API flexibility, but on balance I think this
    is a good thing, because the API we *do* have is actually usable...
2022-01-11 15:16:03 +00:00
Nick Mathewson 7d3482ca1a Bump all crate versions to 0.0.3. 2022-01-11 09:40:32 -05:00
Nick Mathewson c5f50b7d41 Update README.md files (automated) 2022-01-11 09:37:45 -05:00
Ian Jackson 821091ae95 Apply suggestions to better describe the purpose of LogGuards. 2022-01-10 13:23:11 -05:00
Nick Mathewson 1a16f5a7d6 Tracing configuration for logfiles, per-target filters
Previously we could only configure one global tracing filter that
applied to stdout and journald.  There was no support for log files,
either.

This patch fixes both issues, by substantially revising the
configuration format: There are now separate filters for each log
file, for journald, and for the console log.  Because we want to
allow multiple logfiles, they have to go into an array in the
configuration.

The configuration logic has grown a bit complicated in its types,
since the tracing_subscriber crate would prefer to have the complete
structure of tracing Layers known statically. That's fine when you
know how many you have, and which kinds there will be, but for
the runtime-configuration case we need to mess around with
`Box<dyn Layer ...>`.

I also had to switch from tracing_subscriber's EnvFilter to its
Targets filter.  It seems "EnvFilter" can only be applied as a Layer
in itself, and won't work as a Filter on an individual Layer.

Closes #166.

Closes #170.
2022-01-10 13:23:11 -05:00
Nick Mathewson 736763fb51 Move tracing setup into a separate module.
No code changes here yet.
2022-01-10 13:17:02 -05:00
eta de1b19c22a Fixup broken doc comment from arti!220
That's what I get for blindly trusting @nickm :p
2022-01-10 15:10:41 +00:00
eta c42fac09a5 Merge branch 'ticket_281' into 'main'
Expose and rename stream timeout config.

Closes #281

See merge request tpo/core/arti!231
2022-01-10 15:05:31 +00:00
Nick Mathewson 01c851ad46 Expose and rename stream timeout config.
Previously we kept this in an ambiguously named type,
`ClientTimeoutConfig`. But everything we do right now is client
related! So `StreamTimeoutConfig` is a better name.

Also, we'd previously neglected to expose the builder for this type
from `TorClientConfigBuilder`. Now we do.

Closes #281.
2022-01-10 09:46:43 -05:00
Nick Mathewson 7819dd7bac Make the arti_client::Result type public.
Closes #280.
2022-01-10 09:33:26 -05:00
eta da848a1b9c Merge branch 'ticket_178' into 'main'
Fix ticket 178: Don't use a NetDir until we have microdescriptors for all of our primary guards.

Closes #178

See merge request tpo/core/arti!220
2022-01-10 14:02:24 +00:00
eta 4b1a3976cb Merge branch 'bug274' into 'main'
Fix busy-loop when consensus is near expiring.

Closes #274

See merge request tpo/core/arti!223
2022-01-10 13:47:52 +00:00
eta e6e65d6574 Merge branch 'minimize_deps' into 'main'
Minimize the required version for each dependency.

Closes #275

See merge request tpo/core/arti!228
2022-01-10 13:44:53 +00:00
Neel Chauhan 439b8b3e64 Use *_with_prefs() for Option<ConnectPrefs> callers in TorClient::connect 2022-01-08 13:36:49 -08:00
Nick Mathewson 4841b50c9f Minimize the required version for each dependency.
I found these versions empirically, by using the following process:

First, I used `cargo tree --depth 1 --kind all` to get a list of
every immediate dependency we had.

Then, I used `cargo upgrade --workspace package@version` to change
each dependency to the earliest version with which (in theory) the
current version is semver-compatible.  IOW, if the current version
was 3.2.3, I picked "3".  If the current version was 0.12.8, I
picked "0.12".

Then, I used `cargo +nightly upgrade -Z minimal-versions` to
downgrade Cargo.lock to the minimal listed version for each
dependency.  (I had to override a few packages; see .gitlab-ci.yml
for details).

Finally, I repeatedly increased the version of each of our
dependencies until our code compiled and the tests passed.  Here's
what I found that we need:

anyhow >= 1.0.5: Earlier versions break our hyper example.

async-broadcast >= 0.3.2: Earlier versions fail our tests.

async-compression 0.3.5: Earlier versions handled futures and tokio
    differently.

async-trait >= 0.1.2: Earlier versions are too buggy to compile our
    code.

clap 2.33.0: For Arg::default_value_os().

coarsetime >= 0.1.20: exposed as_ticks() function.

curve25519-dalek >= 3.2: For is_identity().

generic-array 0.14.3: Earlier versions don't implement
    From<&[T; 32]>

httparse >= 1.2: Earlier versions didn't implement Error.

itertools at 0.10.1: For at_most_once.

rusqlite >= 0.26.3: for backward compatibility with older rustc.

serde 1.0.103: Older versions break our code.

serde_json >= 1.0.50: Since we need its Value type to implement Eq.

shellexpand >= 2.1: To avoid a broken dirs crate version.

tokio >= 1.4: For Handle::block_on().

tracing >= 0.1.18: Previously, tracing_core and tracing had separate
    LevelFilter types.

typenum >= 1.12: Compatibility with rust-crypto crates

x25519-dalek >= 1.2.0: For was_contributory().

Closes #275.
2022-01-07 19:08:58 -05:00
Nick Mathewson e9a507af67 Merge branch 'circ_self_by_ref' 2022-01-07 14:48:21 -05:00
Nick Mathewson c123138f74 Merge branch 'remove-type-annotation' into 'main'
tor-circmgr: Remove a type annotation in a method call

See merge request tpo/core/arti!225
2022-01-07 19:33:04 +00:00
Nick Mathewson 0151ceceb0 ClientCirc: change some methods to take &self
Previously they took Arc<Self>, and then Self, but &self is perfectly
fine here.
2022-01-07 13:55:26 -05:00
Nick Mathewson debac8b973 circmgr: Fix a pair of clippy warnings. 2022-01-07 13:53:21 -05:00
Ian Jackson d63a251afc tor-circmgr: Remove Arc around ClientCirc
See the new commentary text on `ClientCirc` for the rationale.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2022-01-07 18:19:20 +00:00
Ian Jackson 14d7edc5f8 tor-circmgr: tests: Do fake circuit equality by id
We are going to get rid of the Arc.  Happily there is an id which is
always constructed uniquely and preserved by clone.

(auto-deref lets us make the function take &Self instead of &Arc)

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2022-01-07 18:16:43 +00:00
Ian Jackson 7c55141e3f tor-circmgr: tests: Introduce and use FakeCirc::eq()
This removes a lot of open-coded Arc::ptr_eq() calls

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2022-01-07 18:16:43 +00:00
Ian Jackson a034ef3526 tor-circmgr: Replace some Arc::clone with .clone()
This will make the code work when it's not an Arc any more.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2022-01-07 18:16:39 +00:00
Nick Mathewson d9b423c17f Fix busy-loop when consensus is near expiring.
When our current consensus is getting close to being invalid (but
it isn't invalid yet), we try to get a new one. So far, so good.

But we had a bug: when we went to get a new consensus, we'd see that we
had a perfectly fine not-yet-invalid consensus in our cache, reload it,
find that it was ready, and continue!

This patch fixes our behavior: If we have a usable consensus, then
when we reset the bootstrapping process, we ignore any cached consensus.

Fixes bug #274.
2022-01-07 13:16:06 -05:00
Ian Jackson 5469579ca9 tor-circmgr: Remove a type annotation in a method call
This is a method, so the resolution is automatic.  It's not clear to
me why this was written out this way, given that extend_ntor is right
above.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2022-01-07 18:12:27 +00:00
Ian Jackson 19a104e2cc tor-circmgr: Require that AbstractCirc are Clone
We are going to get rid of a lot of Arc, so we need the underlying
thing to be Clone.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2022-01-07 18:12:15 +00:00
Nick Mathewson e8e0f67336 Only replace netdir once we have enough guard MDs.
This prevents a security-failure condition that could happen if our
directory caches don't give us these microdescriptors, but we
nevertheless decide that the directory is usable.

Closes #178
2022-01-06 15:58:43 -05:00
Nick Mathewson 723894b9ea Tests for new guardmgr functionality. 2022-01-06 15:58:36 -05:00
Nick Mathewson 5ac0fcb7ef Add API to check if primary MDs are missing.
We need this information to know if it's okay to migrate to a new
NetDir, or if we need to download more information first.

Part of #178.
2022-01-06 15:58:23 -05:00
Neel Chauhan 5dfedb4c6f De-Arc-ify Buildable for ClientCirc 2022-01-06 12:22:49 -08:00
eta f08854bc69 Merge branch 'main' into 'remove_unused_rngs'
# Conflicts:
#   crates/tor-circmgr/src/build.rs
2022-01-06 15:48:42 +00:00
eta ea41fa3346 Merge branch 'refactor/unwrap-or-default' into 'main'
prefer 'unwrap_or_default' to manual constructor

See merge request tpo/core/arti!215
2022-01-06 15:36:12 +00:00
Nick Mathewson db65fdd04e guardmgr: Don't use no-md guards for data circs.
If we don't know a current microdescriptor for a guard, we can't use it
for multihop circuits, since we don't know its onion keys.

This is part of a fix for #178.
2022-01-06 09:52:21 -05:00
Nick Mathewson 214ac17eed Move a comment to the right place. 2022-01-06 09:05:08 -05:00
Nick Mathewson 5c3300867d Merge remote-tracking branch 'origin/mr/214' 2022-01-06 09:02:09 -05:00
Nick Mathewson 3a456100a8 Merge remote-tracking branch 'origin/mr/217' 2022-01-06 08:30:25 -05:00
Nick Mathewson c15168be61 Merge remote-tracking branch 'origin/mr/212' 2022-01-06 08:28:13 -05:00
Ian Jackson 1e70d56737 arti-bench: Remove a FIXME by saying it's OK for this program to panic 2022-01-06 11:58:01 +00:00
Daniel Eades d68e934716 prefer 'unwrap_or_default' to manual constructor 2022-01-01 19:14:29 +00:00
Daniel Eades 592642a9e6 extend lints to include 'clippy::all' 2021-12-28 20:15:40 +00:00
Neel Chauhan d72d37ff4a Remove a bunch of unused RNGs 2021-12-25 18:44:55 -08:00
Neel Chauhan 383843f0d7 tor-circmgr: Don't clone parameters in create_chantarget() 2021-12-25 17:22:38 -08:00
Neel Chauhan 7dba3d8c51 tor-proto: In begin_stream_impl(), if number of hops is zero, don't continue 2021-12-25 16:01:22 -08:00
Nick Mathewson efe74e8c9b Only count timeouts when we've seen net activity.
This closes arti#256.  It makes our behavior match Tor's more closely,
though it has a simpler implementation than Tor. I think that the extra
complexity in Tor's logic is because we used to record timeouts in
the histogram as well as in the success/failure log.
2021-12-20 15:34:17 -05:00
Nick Mathewson 09d0c20c94 Merge branch 'eta/instant-checked-add' into 'main'
preemptive.rs: Use Instant::checked_add instead of raw subtraction

See merge request tpo/core/arti!206
2021-12-20 20:07:59 +00:00
eta 091065454e preemptive.rs: Use Instant::checked_add instead of raw subtraction
The implementations of `Add` / `Sub` (et al.) on `std::time::Instant`
can panic if the underlying OS structure can't represent the result
(like arti#266). Use Instant::checked_add and print a warning instead,
to prevent panicking.

Also, we now add instead of subtracting; I suspect it's reasonable that
you might not be able to go backward past the first `Instant` created on
some platforms, but going *forward* should probably work?
2021-12-20 19:27:55 +00:00
eta 0cdf65c256 Merge branch 'refactor/must-use-self' into 'main'
address clippy's latest lint

See merge request tpo/core/arti!205
2021-12-20 18:38:18 +00:00
Nick Mathewson 6303a71d58 tor-proto: Replace XXXs with references to arti#269
These will require thought; should we ignore them, act on them, or
continue to  treat them as internal errors?
2021-12-20 10:56:24 -05:00
Nick Mathewson 26fc8073f2 Remove XXXs from tor-circmgr::mgr
IIUC, these anticipatd a need to store min_exit_circs_per_port in
CircMgr.  But the current design, where it goes into preemptive.rs and
thence to usage, seems to work fine.
2021-12-20 10:46:13 -05:00
Nick Mathewson f73f6a4e80 arti-client: Change an XXXX to a TODO.
We _do_ reject bad hostnames: just not where I once thought we might.
We need to decide if the current behavior is what we want (and I think
it is, probably?).
2021-12-20 10:02:24 -05:00
Nick Mathewson a2afb29806 Change an UTF-8 XXX to a TODO.
We're assuming that prop285 is accepted in some form.
2021-12-20 09:54:41 -05:00
Nick Mathewson 8cf143217e tor-netdoc: Change an XXX to a TODO.
Our behavior in handling not-yet-valid router descriptors doesn't match
the C Tor implementation, but it's not a big deal:
we don't currently use router descriptors at all.
2021-12-20 09:46:56 -05:00
Nick Mathewson 6299ca70b4 tor-netdoc: Use a more correct error type
If we fail to convert a curve25519 key to an ed25519 key for checking
the onion-key crosscert, don't call that an internal error: it means
that something is wrong with the provided ntor key.
2021-12-20 08:58:30 -05:00
Nick Mathewson 92e53bff62 Remove an XXXX about ed25519 signatures.
As of tor-spec commit 01122c5bd7d2f0f, the spec is no longer ambiguous
on this point.
2021-12-20 08:53:42 -05:00
Daniel Eades 9b51a52b53 address clippy's latest lint 2021-12-20 09:46:41 +00:00
eta 0577eac0bf Merge branch 'one_metahandler_at_a_time' into 'main'
tor-proto: Allow one meta-cell handler at a time.

See merge request tpo/core/arti!204
2021-12-16 21:43:33 +00:00
Nick Mathewson 64257a10fa tor-proto: Allow one meta-cell handler at a time.
Previously the code would let us try to install a meta-cell handler
before the old one was done, leading to possible confusion.
2021-12-16 16:01:50 -05:00
eta b01f695f53 Merge branch 'arti-bench' into 'main'
Introduce an experimental benchmarking utility for Arti

See merge request tpo/core/arti!195
2021-12-16 20:47:47 +00:00
eta 7921a88f8d Merge branch 'fallbackdirs-15-12-2021' into 'main'
fallbackdir: Update list generated on December 15, 2021

See merge request tpo/core/arti!202
2021-12-16 20:30:16 +00:00
eta 6a12f388f2 Merge branch 'ct_sendme_tags' into 'main'
tor-proto: use const-time eq on sendme tags.

See merge request tpo/core/arti!201
2021-12-16 20:29:01 +00:00
Tor CI Release e17359bc18 fallbackdir: Update list generated on December 15, 2021
Signed-off-by: Tor CI Release <no-email@torproject.org>
2021-12-16 11:52:22 -05:00
Nick Mathewson 51c4ca73f2 tor-proto: set HalfStream::connected_ok right.
Previously we'd always set it to true, allowing one CONNECTED per
half-closed stream even if the stream had already received a
CONNECTED  cell.

This resolves an XXXX.
2021-12-16 11:48:39 -05:00
Nick Mathewson a09fbc9f27 tor-proto: replace a streammap XXXX with a ticket. 2021-12-16 11:33:50 -05:00
eta 06a94288ca Introduce an experimental benchmarking utility for Arti
The new `arti-bench` crate does a simple end-to-end benchmark test
embedding Arti: it generates some random data (of configurable amount,
depending on command-line parameters), and then sends said data back and
forth via Arti (which should be configured to use a local Chutney
network).

Additionally, the benchmark can also be run via a local SOCKS5 server
(in order to benchmark the performance via a local Chutney node, for
comparison).

The `tests/chutney/arti-bench.sh` sets up and tears down Chutney as
required to make this work.

This is very much a first cut; there are many things that should
eventually get added, such as support for multiple connections, JSON
output capabilities, running multiple tests, ...
2021-12-16 16:12:59 +00:00
Nick Mathewson d794355b07 tor-proto: use const-time eq on sendme tags.
There's no known attack here, but it's best practice to always compare
digests using a constant-time comparison operator.

This resolves an XXXX comment.
2021-12-16 11:06:30 -05:00
Nick Mathewson e2dd418c84 tor-proto: document an infelicitous behavior.
This was an XXXX before. Now it explains why the behavior is safe for
now, but maybe not forever.
2021-12-16 10:39:00 -05:00
Nick Mathewson de45ee41a4 tor-cell: replace an XXXX with a TODO.
The original comment was a gnomic question about what to box; the real
issue is that we want to avoid copying data in our critical path.
2021-12-16 10:29:30 -05:00
Nick Mathewson 9f6e09b4d1 tor-dirmgr: retain cache_usage on reset.
Previously we didn't retain the value of our cache_usage field when
calling reset() from GetMicrodescsState.

This resolves an XXXX comment.
2021-12-16 09:31:23 -05:00
eta 49be908feb Merge branch 'more_destroyreason' into 'main'
Extend trace messages for destroy/truncated reasons.

See merge request tpo/core/arti!200
2021-12-16 14:29:38 +00:00
eta e62212112c Merge branch 'flag-publish-2' into 'main'
Refactor directory events to use a new FlagPublisher mechanism.

See merge request tpo/core/arti!188
2021-12-16 14:28:51 +00:00
Nick Mathewson b5672cb2c7 tor-dirmgr: Warn on a bug case.
This warning occurs if we ask for microdescriptors from our local
cache, and our cache gives us something we didn't ask for.  It
shouldn't be possible, so let's warn when it occurs.

This patch resolves an XXXX.
2021-12-16 08:51:34 -05:00
Nick Mathewson a0870f8f79 Adjust comment to be accurate wrt #263. 2021-12-16 08:37:50 -05:00
Nick Mathewson d1d541142f Do not treat spawn failure as a fatal error. 2021-12-15 15:35:04 -05:00
Nick Mathewson 70dc6913e0 Expand some comments about circuit expiration.
Emphasize that circuit expiration functions _decide whether to
expire the circuit_, and don't expire it automatically.
2021-12-15 15:27:33 -05:00
Nick Mathewson 2fc6bc1fca Merge remote-tracking branch 'origin/mr/169' 2021-12-15 15:18:52 -05:00
Nick Mathewson f73840544c Extend trace messages for destroy/truncated reasons.
It makes sense to put the method for human-readable strings onto the
type itself, so that we can format these whenever they occur.

I'm choosing the "human_str" method name here, since caret-generated
types already have a to_str.  I was thinking about using Display,
but caret types already implement that.

I've also moved the message from "warn!" to "debug!", since these
aren't necessarily a problem condition.
2021-12-15 11:33:48 -05:00
Nick Mathewson 1cf0b87eb7 Merge remote-tracking branch 'origin/mr/191' 2021-12-15 10:46:58 -05:00
eta 2e0ff665bb Merge branch 'check_put_return' into 'main'
Always check whether stream-level SENDMEs are expected.

Closes #261

See merge request tpo/core/arti!192
2021-12-15 15:45:08 +00:00
eta 855b53762d Merge branch 'mfrw/proxy-flush-conns' into 'main'
proxy: introduce new functions to write_all & flush/close

Closes #262

See merge request tpo/core/arti!199
2021-12-15 14:27:12 +00:00
eta c9ec3cb324 Merge branch 'PendingRequest_remove_started_at' into 'main'
Remove unused started_at in PendingRequest

See merge request tpo/core/arti!196
2021-12-15 14:25:34 +00:00
Muhammad Falak R Wani e1452b4f21
proxy: introduce new functions to write_all & flush/close
Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
2021-12-15 11:00:47 +05:30
Yuan Lyu a346893065 Add spawn_expiration_task function in circuit manager 2021-12-15 00:22:09 -05:00
Neel Chauhan 043b97fecf In reactor, use enums on whether to destroy circuits 2021-12-14 14:36:30 -08:00
Neel Chauhan b601d8b147 Methodize the destroy circuit reason 2021-12-14 14:26:45 -08:00
Nick Mathewson 7f4578bec1 Refactor directory events to use a FlagPublisher mechanism.
This approach tries to preserve the current interface, but uses a
counter-based event backend to implement a coalescing stream of
events that can be represented as small integers.  The advantage
here is that publishing events no longer needs to be a blocking
operation, since there is no queue to fill up.
2021-12-14 14:05:02 -05:00
Neel Chauhan e67d4e0821 tor-chanmgr: Fix happy eyeballs comment grammar in builder.rs 2021-12-14 10:45:19 -08:00
Neel Chauhan ee16c69075 Remove unused started_at PendingRequest 2021-12-14 10:33:47 -08:00
Nick Mathewson d5c2361d3f Always check whether stream-level SENDMEs are expected.
(It's a protocol violation to get a SENDME when our send window is
already full.)

This patch makes SendWindow::put return a Result, so that it's
easier to do the right thing with it.

Closes #261.
2021-12-14 17:11:48 +00:00
eta 8d660cbcf1 Actually decrement the stream-level SENDME window
arti!126 overhauled the `tor-proto` circuit reactor, but left out one
very important thing: actually decrementing the SENDME window for
streams (not circuits) when we send cells along them.

Since the circuit-level SENDME window would often prevent us from
running into a problem, this wasn't caught until my benchmarking efforts
noticed it (in the form of Tor nodes aborting the circuit for a protocol
violation).

fixes arti#260
2021-12-14 16:37:56 +00:00
Nick Mathewson 5e63afe597 Merge remote-tracking branch 'origin/mr/189' 2021-12-14 09:11:23 -05:00
Nick Mathewson eadada1941 Merge remote-tracking branch 'origin/mr/186' 2021-12-14 09:04:10 -05:00
Neel Chauhan d621166c80 s/hidden/onion/g in code comments 2021-12-13 13:18:53 -08:00
Neel Chauhan 2595f3f8c1 Handle TRUNCATED cells 2021-12-13 12:21:25 -08:00
Neel Chauhan b6ef659311 Log on TRUNCATED cell 2021-12-13 12:21:19 -08:00
eta 8040f7afb2 Merge branch 'reconfigure' into 'main'
Make most arti-client fields reconfigurable.

See merge request tpo/core/arti!181
2021-12-13 14:49:23 +00:00
Neel Chauhan 52cae03621 Don't create circuits if the consensus is stale by over 72 hours 2021-12-12 20:29:53 -08:00
Muhammad Falak R Wani c3df9cd735
proxy: send SOCKS5 reply on failure cases
Signed-off-by: Muhammad Falak R Wani <falakreyaz@gmail.com>
2021-12-11 13:05:33 +05:30
Daniel Eades e7bbe9e7a1 address lint warnings 2021-12-09 13:51:42 +00:00
Daniel Eades 47554556ec address lint warnings 2021-12-09 13:47:59 +00:00