summaryrefslogtreecommitdiff
path: root/crates/tor-proto/src/util
Commit message (Collapse)AuthorAgeFilesLines
* Run maint/add_warning to add lint block everywhereIan Jackson2023-08-233-0/+3
|
* tor-proto: Add a helper for adding a stream entry with a specific stream ID.Gabriela Moldovan2023-08-031-2/+12
| | | | | | | | | This adds a new `add_ent_with_id` function for adding a new entry to the `StreamMap`. The existing `add_ent` function auto-generates a new stream ID, which is not good if we're a hidden service, as stream IDs are supposed to be chosen by the OP (client). When accepting a new stream, services, exit relays, and dir auths need to use the stream ID received in the BEGIN cell (instead of generating a new stream ID).
* Run maint/add_warning to actually apply new lint allowsIan Jackson2023-07-103-0/+3
|
* Lower tor-proto::util::ct::lookup to tor-llcryptoNick Mathewson2023-06-161-56/+1
| | | | | | | | This is mostly code movement; you may want to review it with `--color-moved`. I'm doing this so we can also use the function in netdoc for looking up hsdesc authentication.
* Allow clippy::unchecked_duration_subtraction in testsNick Mathewson2023-01-273-0/+3
| | | | | This panics on error, and we're fine with a panic on misbehavior in tests.
* test lint blocks: Add many many automaticallyIan Jackson2022-12-123-0/+25
| | | | | This is precisely the result of running the rune in maint/adhoc-add-lint-blocks.
* Final (?) API revisions for tor-linkspecNick Mathewson2022-08-101-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With this change, each individual identity type becomes optional. The functions that expose them unconditionally are now in a "legacy" trait that only some downstream types are expected to implement. There are new convenience APIs in HasRelayIds: * to return Option<&keytype>, * to see if one identity-set contains another. This commit will break several downstream crates! For the reviewer's convenience, I will put the fixes for those crates into a series of squash! commits on this one. tor-netdir ---------- Revise tor-netdir to accept optional identities. This required some caveats and workarounds about the cases where we have to deal with a key type that the tor-netdir code does not currently recognize at all. If we start to add more identity types in the future, we may well want more internal indices in this code. tor-proto --------- In order to make tor-proto support optional identities, there were fewer changes than I thought. Some "check" functions needed to start looking at "all the ids we want" rather than at "the two known IDs"; they also needed to accommodate that case where we don't have an ID that we demand. This change will also help with bridges, since we want to be able to connect to a bridge without knowing all of its IDs up front. The protocol currently _requires_ the two current ID types in some places. To deal with that, I added a new `MissingId` error. I also removed a couple of unconditional identity accessors for chanmgr; code should use `target().identity(...)` instead. tor-chanmgr ----------- This is an incomplete conversion: it does not at all handle channel targets without Ed25519 identities yet. It still uses those identities to index its internal map from identity to channel; but it gives a new `MissingId` error type if it's given a channel target that doesn't have one. We'll want to revise the map type again down the road when we implement bridges, but I'd rather not step on the channel-padding work in progress right now. tor-guardmgr ------------ This change is mostly a matter of constructing owned identity types more sensibly, rather than unwrapping them directly. There are some places marked with TODOs where we still depend on particular identity types, because of how the directory protocol works. This will need revisiting when we add bridge support here. tor-circmgr ----------- These changes are just relatively simple API changes in the tests.
* tor-proto: Stop using write_infallible in handshake code.Nick Mathewson2022-07-111-0/+21
| | | | | | | | This change was a bit annoying, since most of this code _can't_ fail, and so the only reasonable response is to wrap the input in an internal error... except for one case where we're actually encoding a caller-provided message, so we _do_ want to wrap the EncodeError from tor_bytes.
* tor-proto: split and elaborate tor_bytes::Error instancesNick Mathewson2022-06-231-6/+26
| | | | | | | | | Some of these were for decoding particular objects (we now say what kind of objects), and some were unrelated tor_cert errors that for some reason we had shoved into a tor_bytes::Error. There is now a separate tor_cert::CertError type, independent from tor_cert's use of `tor_bytes::Error` for parsing errors.
* tor-proto: Split CellErr based on activity.Nick Mathewson2022-06-231-9/+33
| | | | | | Failing to encode is fundamentally different from failing to decode. We now treat those separately, and describe _what_ we failed to encode or decode.
* tor-proto: clean up error names and messagesNick Mathewson2022-06-231-37/+42
| | | | | This avoids adding additional information for now; that will come on the next commits.
* Merge branch 'display_source_cleanup' into 'main'eta2022-06-211-7/+7
|\ | | | | | | | | Do not include error source() in display() format. See merge request tpo/core/arti!598
| * Do not include error source() in display() format.Nick Mathewson2022-06-211-7/+7
| | | | | | | | | | | | | | | | | | According to doc/Errors.md, and in keeping with current best practices, we should not include display an error's `source()` as part of that error's display method. Instead, we should let the caller decide to call source() and display that error in turn. Part of #323.
* | tor-proto: err: Provide ChannelClosed as a separate unit errorIan Jackson2022-06-211-4/+22
|/
* Change to exhaustive match.Ian Jackson2022-06-081-1/+2
|
* try to differentiate transient from nontransient errortrinity-1686a2022-06-081-2/+18
|
* Use testing_rng() in tests throughout our crates.Nick Mathewson2022-06-021-1/+2
| | | | | | This only affects uses of thread_rng(), and affects them all more or less indiscriminately. One test does not work with ARTI_TEST_PRNG=deterministic; the next commit will fix it.
* More tests for ClockSkew.Nick Mathewson2022-05-251-0/+40
|
* Fix typos (using the typos-cli tool).Nick Mathewson2022-05-041-1/+1
|
* Implement a better clock skew estimator.Nick Mathewson2022-04-111-8/+75
| | | | | | | | This time, our estimator discards outliers, takes the mean of what's left, and uses the standard deviation to try to figure out how seriously to take our report of skew/not-skew. These estimates are still not actually used.
* Initial functions to determine and expose a clock skew estimate.Nick Mathewson2022-04-071-4/+13
| | | | | (This is just a placeholder; I'm going to make the functions smarter in the next commit.)
* chanmgr: bubble ClockSkew up through the Error object.Nick Mathewson2022-04-071-2/+0
| | | | | | | | Fortunately, we don't need a separate type here: authenticated clock skew can only come attached to a `tor_proto::Error`. We also remove skew from `tor_proto::Error::HandshakeCertsExpired`, since it would now be redundant.
* tor-proto: better errors when handshake fails due to untimely certsNick Mathewson2022-03-231-5/+23
| | | | | | | | | | | | | | | | | | We now check the handshake certificates unconditionally, and only report them as _expired_ as a last resort. (Rationale: if somebody is presenting the wrong identity from a year ago, it is more interesting that they are presenting the wrong ID than it is that they are doing so with an expired cert. We also now report a different error if the certificate is expired, but its expiration is within the range of reported clock skew. (Rationale: it's helpful to distinguish this case, so that we can blame the failure on possible clock skew rather than definitely attributing it to a misbehaving relay.) Part of #405.
* tor-proto: add a backend to detect reported clock skew.Nick Mathewson2022-03-231-0/+102
| | | | | | | | | | | | | | | | NETINFO cells, which are sent in every handshake, may contain timestamps. This patch adds an accessor for the timestamp in the Netinfo messages, and teaches the tor-proto code how to compute the minimum clock skew in the code. The computation isn't terribly precise, but it doesn't need to be: Tor should work fine if your clock is accurate to within a few hours. This patch also notes a Y2038 problem in the protocol: see torspec#80. Part of #405.
* Merge branch 'proto_handshake_err' into 'main'Nick Mathewson2022-02-241-16/+23
|\ | | | | | | | | | | | | tor-proto: Split up a couple of handshake-based errors Closes #359 and #358 See merge request tpo/core/arti!344
| * tor-proto: refactor handshake protocol errors to a different typeNick Mathewson2022-02-231-3/+11
| | | | | | | | | | | | | | | | This helps the user distinguish between protocol violations that happen when connecting to the tor network from those that happen while connected. Closes #358.
| * tor-proto: Rename BadHandshake to BadCircHandshakeNick Mathewson2022-02-231-4/+4
| | | | | | | | (We'll have a BadChanHandshake soon.)
| * tor-proto: Split IoErr based on when it occursNick Mathewson2022-02-231-11/+10
| | | | | | | | | | | | | | We want to distinguish handshake failures from errors later on in the channel's lifetime. Closes #359.
* | Give specific error kinds to different END reasonsNick Mathewson2022-02-231-3/+1
|/ | | | Closes #360.
* Eliminate RequestedResourceAbsent kind.Nick Mathewson2022-02-221-6/+2
| | | | | | | | There was only one use of this, and it was in as-yet-unused relay-only code. Removing this type required refactoring the relay onion handshake code to use its own error type, which is probably clever anyway.
* Fold NamespaceFull into BadApiUsage.Nick Mathewson2022-02-221-1/+1
|
* Rename RemoteNameError to RemoteHostNotFoundNick Mathewson2022-02-221-2/+2
| | | | | This is a bit ugly but we need it to work around the problem where exits aren't always clear about _why_ a hostname lookup failed.
* Replace RemoteRefused with CircuitRefused.Nick Mathewson2022-02-221-1/+1
| | | | Also document that it's a lower-level error kind.
* Rename RemoteIdMismatch to RelayIdMismatch.Nick Mathewson2022-02-221-1/+1
|
* Fold AlreadyClosed into BadApiUsageNick Mathewson2022-02-221-1/+1
|
* tor_proto::Error: Fix an incomplete sentence.Nick Mathewson2022-02-161-1/+2
|
* Update tor-proto errors to latest API.Nick Mathewson2022-02-151-21/+17
|
* Make tor-proto::Error implement HasKind.Nick Mathewson2022-02-151-16/+42
| | | | | | This took some refactoring, and gave an opportunity to notice a few error variants that weren't being used, or didn't mean what they said on the tin.
* tor-proto: use InternalError for internal errors.Nick Mathewson2022-02-151-2/+3
|
* Use atomic set-and-check to update OptTimestamps if none.Nick Mathewson2022-02-091-0/+36
| | | | | | | 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.
* Remove the use of Mutex in channel unused_since timestampYuan Lyu2022-02-081-26/+43
|
* fix nightly clippy errorsTrinity Pointard2021-12-091-1/+1
|
* add semicolons if nothing returnedDaniel Eades2021-11-252-2/+2
|
* Get rid of unbounded stream sender, and RawCellStreameta2021-11-121-1/+6
| | | | | | | | | | | | | | | | | | | | | 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
* Use coarsetime to build an incoming traffic timestamp.Nick Mathewson2021-11-021-0/+99
| | | | | | | | | | | | | | | | 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.
* Use subtle and some refactoring to remove branches in ntorNick Mathewson2021-10-011-1/+8
| | | | Closes #163
* fix/silence clippy lints in test modulesDaniel Eades2021-09-081-0/+1
|
* Move all crates into a `crates` subdirectory.Nick Mathewson2021-08-272-0/+231
This will cause some pain for now, but now is really the best time to do this kind of thing.