aboutsummaryrefslogtreecommitdiff
path: root/crates/tor-proto/src/stream
Commit message (Collapse)AuthorAgeFilesLines
...
* Improve the layout of crate exports; add runtime convenience functionseta2022-01-111-5/+35
| | | | | | | | | | | | | | | | | | | | 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...
* tor-proto: document an infelicitous behavior.Nick Mathewson2021-12-161-3/+4
| | | | | This was an XXXX before. Now it explains why the behavior is safe for now, but maybe not forever.
* Get rid of unbounded stream sender, and RawCellStreameta2021-11-123-76/+47
| | | | | | | | | | | | | | | | | | | | | 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
* Completely overhaul the tor-proto circuit reactoreta2021-11-121-22/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Rather like e8e9699c3c239d6c30f9ad414f15d3bad6ec03fd ("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.
* Merge IpVersionPreferences and the optimistic flag into one type.Nick Mathewson2021-11-101-0/+58
| | | | | It seems like a good time to do this, before we add a zillion other arguments to begin_stream.
* Refactor wait_for_connection a bit.Nick Mathewson2021-11-101-12/+14
| | | | | | | * 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.
* Implement optimistic streamYuan Lyu2021-11-091-2/+33
|
* Improve docs of more (potentially re-exported) arti-client typeseta2021-10-291-16/+48
| | | | | | | | | | | | | | | | | | | | | 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.
* Use correct link for AsyncWriteExt::flushNick Mathewson2021-10-281-1/+1
|
* DataStream: document the importance of flush().Nick Mathewson2021-10-281-3/+12
|
* Replace references to arti-client in the documentation.Nick Mathewson2021-10-211-1/+1
|
* Also implement tokio Async{Read,Write} on Data{Reader,Writer}.Nick Mathewson2021-10-191-5/+31
| | | | | | | | 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.)
* Add a little documentation about when you'll need the tokio trait.Nick Mathewson2021-10-191-0/+7
|
* tor-proto: implement tokio Async{Read, Write} traits conditionallyeta2021-10-191-0/+33
| | | | | | | | | 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.
* Use append in place of extend_from_slice in DataReaderImpl::add_data.Nick Mathewson2021-10-171-2/+2
| | | | Suggested by @cheako.
* Fix typosJani Monoses2021-09-071-1/+1
|
* Move all crates into a `crates` subdirectory.Nick Mathewson2021-08-273-0/+586
This will cause some pain for now, but now is really the best time to do this kind of thing.