This implements a basic typed event broadcast mechanism, as described in
arti#230: consumers of the new `tor-events` crate can emit `TorEvent`
events, which others can consume via the `TorEventReceiver`.
Under the hood, the crate uses the `async-broadcast`
(https://github.com/smol-rs/async-broadcast) crate, and a
`futures::mpsc::UnboundedSender` for the event emitters; these are glued
together in the `EventReactor`, which must be run in a background thread
for things to work. (This is done so event sending is always cheap and
non-blocking, since `async-broadcast` senders don't have this
functionality.)
Additionally, the `TorEventKind` type is used to implement selective
event reception / emission: receivers can subscribe to certain event
types (and in fact start out receiving nothing), which filters the set
of events they receive. Having no subscribers for a given event type
means it won't even be emitted in the first place, making things more
efficient.
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.
By enabling link-time optimization, setting 'opt-level=s', and
setting compilation-units=1, we can get a much smaller download
size, which is one of our objectives.
Making these changes reduces the binary size for me (on x86_64) by about
42%. If you also run "strip --strip-debug" on the resulting binary,
the resulting size is 55% smaller than the original binary size.
These effects persist if you compress the binary. Supposing that we
use xz compression, these options make save 32% of compressed binary
size. If we also "strip --strip-debug" before compressing, the compressed
binary saves 43% from the original binary size.
With all of these options applied, on x86_64 linux with xz
compression, we're at a nice 1.5 MiB download. If we statically link
to openssl and sqlite, we're still only at a 2.8 MiB download.
There is a build time cost to these changes: for me, it comes to
a 10%-25% build time increase.
This is part of arti#172.
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.
This commit defines a crate (tor-persist) that describes an abstract
key-value store using serde, plus an on-disk implementation using
Toml and fslock.
This code can now bootstrap from the network, cache the results, and
reload from cache.
There's lots more work to do here, including a big pile of tidying
and refactoring and testing and documentation.
It can send a GET request on a circuit, get an answer, and
decompress it with zlib.
It will need documentation and tests eventually, as well as serious
refactoring.
For now, it's set up to just use a chutney network, so I don't
cause major drama with the real network.
I'll be working on this in parallel with proto and netdir
improvements, until it works.
Too often I've been writing code that defers timeliness checking to
an is_valid_at() method [which you'd better call or else whoops] and
which does signature checking while parsing [not great for
performance].
Instead, let's make return types where you can't get at the interior
object without first either checking the signatures/timeliness, or
declaring that (dangerously) you don't care.
Unlike caret_enum!, these types are for use with things like cell
commands or certificate types, where the entire space of integer
values is possible, and only some are recognized.
Arti is a rust tor implementation. It's project I've been working
on for a few months now, in weekends and in spare time. It doesn't
speak the tor protocol yet, and it doesn't connect to the network at
all.
It needs much more documentation and testing, but I'm just about
ready to show it to others. See the README.md for a description of
what is there and what isn't.