* Allow disabling rpc by passing 0 for rpc-port
* review: make a special enum so rpc port can be disabled with "disabled"
* pr: impl Into<Option> instead of having a named fn
* ref: use separate alpn for rpc calls
* feat: pass errors to the client
* Add comment about path
* feat: copy over the watch and version stuff from iroh
This is so we can detect if the sendme server is running
* docs: add todo about better way to check the server is available
* refactor: update to new quic-rpc
* refactor: move RpcError and RpcResult to util
* refactor: prettify the code a bit
* feat: print peer id and address and stuff on startup
* refactor: make a constant for RPC port
* refactor: Put RPC_ALPN into a const
* fix: use Ipv4Addr::LOCALHOST on server
* fix: ipv6
* refactor: Use RwLock instead of mutex
Should help a bit, so why not?
* feature: make rpc port configurable
* add ability to talk to provider internally via the RPC interface
* adapt cli tests
* review comments
* docs: Add some docs for why we need to wait when closing a rpc client
* feat: nicer output for add and provide
* clippy
* fix: better output for list
* refactor: remove the delay when dropping the client
This now gets taken care of in quic-rpc. The shutdown_timeout is good to
limit the time for a clean shutdown so we don't have to wait indefinitely.
Before going into the loop we may as well make sure to reserve enough
space for the entire buffer. Otherwise we could be allocating
multiple times.
This does not change the total allocated size. Though this does add a
missing limit to the allocated size.
This simply delegates to eprintln! for writing output. This ensures
writes happen more synchronously and the flaky integration tests are
fixed.
While in theory these are blocking operations on the async executor,
this is acceptable because:
- We already use println!() without any problems. Arguably this is
more of an issue since we also write data to stdout but it isn't
because we don't do that at the same time.
- We print a small number of messages, not large amounts of data. Any
blocking from this will be small.
- This acquires a sync mutex while writing, that's fine because it is
acquired and released in the same chunk of async code and not held
across await points. This is unlikely to block much as only main
writes and only one write happens at a time.
- When logging via tracing is enabled this will also end up logging on
here and will compete for the lock. This is slightly higher
contention but doesn't really interfere with the logging here.
Seems like we ended up with two bits of code doing exactly the same.
Clean it up.
This settles on read_lp() as name since this is symmetric with
write_lp() which writes bytes. This implementation inlines the
functions a bit more as well, the entire function is still small and
it is used often.
* refactor: replace out_writer with a out_println! macro
* refactor: rename out_println! to progress!
It does not really write to stdout but to stderr, so out...anything is a
bit misleading.
Tests the provide-get loop, transferring a single file, a folder of multiple files, and data from stdin of the provider to stdout if the better, ensuring that the content is transferred successfully.
The tests also test the stdout of the provider and stderr of the getter, using regex matching on each line of the respective output.
This fixes the log message output which had an extraneous newline in
it and needlessly used debug output.
It also adds the listening address to the normal provider output: This
is universally useful since you can specify addresses with -a but
don't otherwise know which one is used if using OS-allocated ports.
This can also be useful for testing.
This makes sure the OutWriter writes the newline as part of the same
buffer as the output. This makes it less likely that the output will
be interrupted between the content and the newline. E.g. without this
and enabling logging, log messages will be injected between the
content and the newline, making the output garbled.
Unfortunately this isn't entirely correct and is more of a heuristic
because most of our output is small enough that they fit in a single
write. In the blocking world you'd lock Stderr while printing the
messages, in the tokio world however I don't know how to safely do
this.
Since we now only issue a single request per stream this field was not
used. Using it in the provider to identify requests would introduce
complexity and overhead for the bookkeeping of request IDs. Instead
remove the field from the protocol.
The provider still has a use-case for identifying which request events
relate to. It now uses the QUIC stream ID for this, but does not
promise so on an API-level. This also simplifies the events since
this new request_id is always known, while previously it was only
known after having decoded the request message.
We used to limit the maximum amount of data that can be transferred,
both the total size as well as single blob size. There is no real
benefit to this, we pass through the reader and do not buffer all this
data at once. And avoiding to fill up the user's disk space is not
our concern.
The implementation uses a BytesMut buffer to efficiently read protocol
messages from the network connections. The way read_lp was combining
both reading the length-prefixed message and decoding it resulted in
the caller having to remember to advance the BytesMut buffer before
using it again. That is error prone.
This reduces the function of the read_lp() function to only read the
raw message from the network. It returns a new Bytes object and the
passed in BytesMut is in a safe state with all internal indexes
correctly advanced.
The caller is now responsible for calling postcard::from_bytes using
the returned Bytes, read_lp() can not both create the Bytes and return
a parsed struct from it due to lifetimes. Overall this isn't any more
complicated to use and results in less error-prone code.
This adds support for the SSLKEYLOGFILE environment variable which is
a common standard used by browsers to log the TLS keys used for
connections. It allows traffic inspectors like tcpdump and wireshark
to use the logged keys and decrypt the traffic. Using this is a first
step to allowing us to observe our protocol on the wire.
The support is still hidden behind a commandline option so that it can
not be accidentally enabled by only having an environment variable
set.
This refactor splits the `handle_stream` function up into smaller
(logical) functions. If these functions error, we can emit a
`TransferAborted` event before returning the error.
This has the added benefit of making the `handle_stream` function a bit
easier to take in. None of these new functions have any code changes,
the only difference is how errors are handled and when we return.
When finished with a stream you have to read to EOF. Sometimes the
sender could be sending the FIN bit in an empty STREAM frame after all
the data is sent, if the receiver did not read EOF in this case the
receiver will still implicitly call `RecvStream::stop` on drop, making
the stream error for the sender.
Co-authored-by: Floris Bruynooghe <flub@devork.be>
Sending a STOP_STREAM frame from the receiver is the way for a receiver
to go to the reset state. It involves sending an extra frame, the
receiver will then send its own RESET_STREAM frame and the stream is
considered ended in an error state.
Instead the right way to end a stream is to set the FIN bit on the final
STREAM frame, ideally not even resulting in an extra frame or packet
sent. This is done on the sender side.
This adds a generic utility which can be used to track progress of
data transfers by emitting progress via a tokio broadcast channel.
This is extracted from the deltachat PR:
https://github.com/deltachat/deltachat-core-rust/pull/4007
This makes it so that the provider is allowed to close the connection
after a transfer is completed, without the getter resulting in an
error.
It modifies the provider to only emit the transfer completed once the
data has actually reached the client.
The tokio feature of tracing-futures seems crazy outdated and not
needed. Enabling it pulls in an ancient version of tokio for no
reason whatsoever. Get rid of it.