Commit Graph

524 Commits

Author SHA1 Message Date
Matthias Einwag 31109bd16f Make owned bytes write APIs available in quinn
This extends the public quinn API to offer support for writing owned buffers.
Besides the universal `write_chunks` API which supports a variable amount
of buffers the API also offers convenience methods for writing either a
single buffer completely or an arbitrary amount of buffers completely.
2021-03-02 06:49:34 +01:00
Dirkjan Ochtman 971265d9ff quinn-proto: provide datagrams API access through special-purpose type 2021-03-01 13:06:10 -08:00
Dirkjan Ochtman 5a7b888934 quinn-proto: extract separate RecvStream interface type 2021-03-01 13:06:10 -08:00
Dirkjan Ochtman 0b350e5d11 quinn-proto: extract separate SendStream interface type 2021-03-01 13:06:10 -08:00
Dirkjan Ochtman d4bfc25d6a quinn-proto: move API logic into Streams 2021-03-01 13:06:10 -08:00
Dirkjan Ochtman 8bbe908dbd quinn-proto: add public Streams interface 2021-03-01 13:06:10 -08:00
Dirkjan Ochtman 14db88562d quinn: split streams module in send/recv parts 2021-02-25 12:06:38 -08:00
Dirkjan Ochtman 24cf82ef83 Expose iterator-like read API 2021-02-25 12:06:38 -08:00
Matthias Einwag 9cb0c7b1c9 Update CMSG_LEN
Wit GSO activated, encoding cmsgs paniced since not enough
space was available. We need a minimum of 88 bytes.
2021-02-22 13:24:38 +01:00
Benjamin Saunders 08d094c153 Reexport ReadChunk(s) 2021-02-21 21:11:20 +01:00
Matthias Einwag 2a8c93bf0f Lock tracking
This change adds an optional feature which allows to track how much
time was spent inside locks on connections, as well as which other
tasks held the lock (in case there is lock contention).

This makes it easier to determine which code path are currently not
as non-blocking as they should be.

Examples of output:
```
Feb 04 22:05:42.293  WARN quinn::mutex: Utilizing the connection for poll took 165.2318ms
```

```
Feb 04 22:05:42.128  WARN quinn::mutex: Locking the connection for poll took 1.1284ms. Last owners: [("SendStream::poll_write", 7.6µs), ("SendStream::poll_write", 46.4µs), ("SendStream::poll_write", 792.8µs), ("drop", 100ns), ("clone", 100ns), ("OpenUni::next", 1.3µs), ("clone", 295.2µs), ("poll", 14.1546ms), ("drop", 100ns), ("drop", 100ns), ("drop", 439.2µs), ("poll", 9.7657ms), ("clone", 0ns), ("clone", 0ns), ("clone", 100ns), ("connecting", 308.3µs), ("poll", 30.402ms), ("poll", 4.1406ms), ("clone", 100ns)]
```
2021-02-05 12:21:09 -08:00
Edgar Geier 05bb6cdd5f Implement stream prioritization (fix #165) 2021-01-31 19:28:22 -08:00
Edgar Geier 78573de130 Only wake up the connection driver if necessary
Add a has_pending_retransmits method to
quinn_proto::connection::Connection and use it inside of
quinn::RecvStream::poll_read_generic to decide if we should wake up the
connection driver.
2021-01-30 10:09:09 +01:00
Dirkjan Ochtman 6a7f861a1e quinn-proto: yield read data as Chunks 2021-01-30 10:09:09 +01:00
Dirkjan Ochtman a280b7770f quinn: unify ordered and unordered read APIs 2021-01-30 10:09:09 +01:00
Dirkjan Ochtman 07db694a54 quinn-proto: unify API for ordered and unordered reads 2021-01-30 10:09:09 +01:00
Dirkjan Ochtman 8b8f6401bf quinn: properly await client connection setup in benchmarks 2021-01-28 11:58:15 -08:00
est31 29d37aa6d8 Don't assume representation of SocketAddr 2021-01-28 09:53:42 +01:00
est31 f3d82d79a6 Don't assume representation of Ipv*Addr types
Also, remove two uses of unsafe :)
2021-01-28 09:53:42 +01:00
Benjamin Saunders 612c9ac2b8 Remove unnecessary dropping in client/server examples 2021-01-26 06:46:32 +01:00
Benjamin Saunders 03de1d0374 Ensure graceful close in client example 2021-01-26 06:46:32 +01:00
Dirkjan Ochtman f569495b71 quinn-proto: rename read_chunk() to read() 2021-01-25 13:27:52 -08:00
Dirkjan Ochtman ab98859756 quinn-proto: remove read() methods in favor of read_chunk() 2021-01-25 13:27:52 -08:00
Dirkjan Ochtman 6a58b3f542 quinn: remove unused field RecvStream::any_data_read 2021-01-25 13:27:52 -08:00
Dirkjan Ochtman 0654eb254e Forward max_length argument from high-level API 2021-01-25 13:27:52 -08:00
Dirkjan Ochtman ac029a55d9 Fix compatibility with MSRV 2021-01-25 01:08:02 -08:00
Dirkjan Ochtman 51685fb760 Upgrade to tokio 1, bytes 1 and rustls 0.19 2021-01-25 08:53:00 +01:00
Dirkjan Ochtman 22fa31d571 quinn: move UdpExt functionality into platform-specific UdpSocket types 2021-01-25 08:53:00 +01:00
Dirkjan Ochtman 3dddfca8ff Simplify error propagation for ReadExact 2021-01-25 08:53:00 +01:00
Benjamin Saunders 1e5a538221 Limit concurrent streams rather than accept queue size
Previously, we limited the number of streams that could be opened by
the peer but not `accept`ed by the application. However, to guarantee
bounded resource use, applications will typically want to limit the
number of streams they process concurrently. While this could
be *approximately* implemented at the application layer by controlling
calls to accept, that approach has a significant drawback: If streams
are slow to process, the worst-case per-stream latency observed by a
peer who opens the maximum number of streams can be arbitrarily bad,
because streams may be opened above the limit the local application is
willing to process. Reducing the number of unaccepted streams
tolerated can reduce the proportion of streams affected, but reducing
it too low will increase the number of round trips required to open
any given number of streams, increasing average latency significantly.

As a side benefit, this reduces the effort needed for applications to
limit concurrency to a fixed quantity, which is expected to be the
overwhelmingly common case. Should a use case for dynamic concurrency
limits arise, we can expose a setter.
2021-01-22 11:39:00 -08:00
Jean-Christophe BEGUE 69c620ac8f Read multiple chunks into a slice of Bytes 2021-01-06 21:51:17 +01:00
Jean-Christophe BEGUE d19fee11fe Read ordered chunks from RecvStream 2021-01-06 21:51:17 +01:00
Matthias Einwag 1ca7149de1 Allow to use the incoming IP address for sending outgoing packets
This is a follow-up for #943. When a socket is bound to a wildcard
IP address, sending the outgoing IP might use a different source IP
address than the one the packet was received on, since the OS might
not be able to identify the necessary route. This would lead packets
not allowing to reach the client.

This change adds a setting which will set an explicit source address
in all outgoing packets. The source address which will be used is
the local IP address which was used to receive the initial incoming
packet.
2021-01-06 09:57:13 +01:00
Matthias Einwag 115fe2349c GSO platform support
This splits out the platform/socket parts for UDP GSO support
from #953 to reduce the amount of code to review.

This change mainly implements setting the segment size
socket option, and adds a runtime detection mechanism for
GSO support.
2021-01-05 13:42:23 +01:00
Dirkjan Ochtman 17fe82b598 Apply clippy fixes for 1.49 2021-01-01 11:16:05 -08:00
Benjamin Saunders 70ba6b78a1 Add missing traits to UnknownStream errors 2021-01-01 14:25:50 +01:00
Benjamin Saunders bd1c5b34d5 Tweak unknown stream error docs 2021-01-01 14:25:50 +01:00
Benjamin Saunders 61a72a3836 Limit concurrent connections rather than accept queue size
Enables stronger latency guarantees, along the same lines as the
nearby change to streams.
2021-01-01 08:22:16 +01:00
Matthias Einwag 62a88008a7 Make connection stats public
So far those haven't been consumable by applications.
This makes the struct public, and adds an accessor
for `quinn_proto::Connection` and `quinn::Connection`.
2020-12-31 12:03:20 -08:00
Matthias Einwag 3c55123a9c Use initialized CMSG data on sending
The outgoing cmsgs can't be uninit because it breaks `CMSG_NXTHDR`.
The function will try to access the next cmsg in the buffer at
https://github.com/rust-lang/libc/blob/ae65df55fe2d0e1348fed575bfc8c0c3e4744c65/src/unix/linux_like/linux/mod.rs#L2585-L2589

This will yield an undefined result, and can let `CMSG_NEXT` return `None`.
This prevents more than 1 CMSG to be encoded. 0-initializing the
messages makes sure a length of 0 is read, and fixes the issue.

In addition this change improves an assert in the cmsg encoder, which
makes it easier to determine the required CMSG space.
2020-12-30 07:33:12 +01:00
Matthias Einwag 1bc75aa014 Allow to lookup the initial local IP address
When a listener is bound to multiple network interfaces (e.g. `::0`),
it is not obvious which IP the peer used to send a packet. We however
might need this information to send packets back to the peer with the
same source address.

This problem is described in #508.

This change makes the destination IP address which was used to send
the initial packet available in the `Conneting` and `Connection` types.

The information is far available only on Linux due to missing test on
other platforms.
2020-12-29 14:53:39 +01:00
Matthias Einwag 64c97b6af0 Extend benchmark for concurrent streams
This extends the "cargo bench" benchmark to test transmission of data
on multiple streams in parallel.

Ideally we would want all transmission to take a similar amount of time
(bandwidth shared fairly), and the overall throughput to stay the same
or increase (but never degrade) when multiple streams are in use.

The benchmark can not show the fairness aspect very well, since it only
prints an overall throughput. But it shows that performance with
multiple streams stays similar.

Output:

```
running 4 tests
test large_data_10_streams  ... bench: 180,761,260 ns/iter (+/- 12,090,679) = 58 MB/s
test large_data_1_stream    ... bench:  18,459,500 ns/iter (+/- 3,804,219) = 56 MB/s
test small_data_100_streams ... bench:   4,600,890 ns/iter (+/- 373,842)
test small_data_1_stream    ... bench:      71,019 ns/iter (+/- 34,298)
```

I also increased the size of the LARGE_DATA payload from 128kB to
1MB, since 128kB didn't show quinn peak performance.
2020-12-28 14:05:12 +01:00
Benjamin Saunders 4e6f946423 Clarify example path behavior 2020-12-22 07:42:34 +01:00
Benjamin Saunders a92e070fab Note address family gotcha 2020-12-22 07:42:34 +01:00
Benjamin Saunders 36de1c2385 Fix errors in example README 2020-12-22 07:42:34 +01:00
Dirkjan Ochtman 120c8157ae Update futures-* to 0.3.8
Prevents security issues in futures older than 0.3.5.

Specifically RUSTSEC-2020-0059 and RUSTSEC-2020-0060.
2020-12-21 14:22:18 -08:00
Dirkjan Ochtman 3b8730d651 Upgrade to directories-next 2 2020-12-21 14:22:18 -08:00
Dirkjan Ochtman 4935f58b25 Update rand to 0.8 2020-12-21 14:22:18 -08:00
Benjamin Saunders cd229d342e Always preserve outer type when converting to io::Error
Ensures that the resulting io::Error's dynamic type is constant and
its Display impl includes the "connection closed: " clarifying
context.
2020-12-20 13:38:23 -08:00
Benjamin Saunders 47232c83d1 Sanity-check remote addresses before trying to connect
Catches some common user errors that would otherwise manifest as
difficult-to-diagnose I/O errors.
2020-12-18 06:54:11 +01:00