Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

transports/quic: Add implementation based on quinn-proto #2289

Merged
merged 260 commits into from
Nov 14, 2022

Conversation

kpp
Copy link
Contributor

@kpp kpp commented Oct 14, 2021

Inital PR description A continuation of https://github.com//pull/2159.

Adds support for tls, removes the UnboundedSenders from the endpoint. The endpoint still has UnboundedReceivers, but that's not different than having a VecDeque. The transport dial api for example doesn't allow applying backpressure.

Closes paritytech/substrate#1334

Todo: transfer unresolved comments from the previous PR


Updated PR description:

Description

Add QUIC as transport to rust-libp2p, using the quinn-proto QUIC implementation.
Initially a continuation of paritytech/substrate#2159, later switched to use the code from paritytech/substrate#1334 (see 4a317df).

Links to any relevant issues

Open TODOs

  • Fix docs
  • Review / document how backpressure is enforced
  • Add more tests

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

Commit message body

Add experimental QUIC implementation based on quinn-proto

Co-authored-by: Demi Marie Obenour [email protected]
Co-authored-by: Pierre Krieger [email protected]
Co-authored-by: Thomas Eizinger [email protected]
Co-authored-by: Max Inden [email protected]
Co-authored-by: Marco Munizaga [email protected]
Co-authored-by: Elena Frank [email protected]

kpp and others added 10 commits September 8, 2021 13:40
* protocols/gossipsub: Fix inconsistency in mesh peer tracking (libp2p#2189)

Co-authored-by: Age Manning <[email protected]>

* misc/metrics: Add auxiliary crate to record events as OpenMetrics (libp2p#2063)

This commit adds an auxiliary crate recording protocol and Swarm events
and exposing them as metrics in the OpenMetrics format.

* README: Mention [email protected]

* examples/: Add file sharing example (libp2p#2186)

Basic file sharing application with peers either providing or locating
and getting files by name.

While obviously showcasing how to build a basic file sharing
application, the actual goal of this example is **to show how to
integrate rust-libp2p into a larger application**.

Architectural properties

- Clean clonable async/await interface ([`Client`]) to interact with the
network layer.

- Single task driving the network layer, no locks required.

* examples/README: Give an overview over the many examples (libp2p#2194)

* protocols/kad: Enable filtering of (provider) records (libp2p#2163)

Introduce `KademliaStoreInserts` option, which allows to filter records.

Co-authored-by: Max Inden <[email protected]>

* swarm/src/protocols_handler: Impl ProtocolsHandler on either::Either (libp2p#2192)

Implement ProtocolsHandler on either::Either representing either of two
ProtocolsHandler implementations.

Co-authored-by: Thomas Eizinger <[email protected]>

* *: Make libp2p-core default features optional (libp2p#2181)

Co-authored-by: Max Inden <[email protected]>

* core/: Remove DisconnectedPeer::set_connected and Pool::add (libp2p#2195)

This logic seems to be a leftover of
libp2p#889 and unused today.

* protocols/gossipsub: Use ed25519 in tests (libp2p#2197)

With f2905c0 the secp256k1 feature is
disabled by default. Instead of enabling it in the dev-dependency,
simply use ed25519.

* build(deps): Update minicbor requirement from 0.10 to 0.11 (libp2p#2200)

Updates the requirements on [minicbor](https://gitlab.com/twittner/minicbor) to permit the latest version.
- [Release notes](https://gitlab.com/twittner/minicbor/tags)
- [Changelog](https://gitlab.com/twittner/minicbor/blob/master/CHANGELOG.md)
- [Commits](https://gitlab.com/twittner/minicbor/compare/minicbor-v0.10.0...minicbor-v0.11.0)

---
updated-dependencies:
- dependency-name: minicbor
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* build(deps): Update salsa20 requirement from 0.8 to 0.9 (libp2p#2206)

* build(deps): Update salsa20 requirement from 0.8 to 0.9

Updates the requirements on [salsa20](https://github.com/RustCrypto/stream-ciphers) to permit the latest version.
- [Release notes](https://github.com/RustCrypto/stream-ciphers/releases)
- [Commits](RustCrypto/stream-ciphers@ctr-v0.8.0...salsa20-v0.9.0)

---
updated-dependencies:
- dependency-name: salsa20
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>

* *: Bump pnet to v0.22

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Max Inden <[email protected]>

* *: Dial with handler and return handler on error and closed (libp2p#2191)

Require `NetworkBehaviourAction::{DialPeer,DialAddress}` to contain a
`ProtocolsHandler`. This allows a behaviour to attach custom state to its
handler. The behaviour would no longer need to track this state separately
during connection establishment, thus reducing state required in a behaviour.
E.g. in the case of `libp2p-kad` the behaviour can include a `GetRecord` request
in its handler, or e.g. in the case of `libp2p-request-response` the behaviour
can include the first request in the handler.

Return `ProtocolsHandler` on connection error and close. This allows a behaviour
to extract its custom state previously included in the handler on connection
failure and connection closing. E.g. in the case of `libp2p-kad` the behaviour
could extract the attached `GetRecord` from the handler of the failed connection
and then start another connection attempt with a new handler with the same
`GetRecord` or bubble up an error to the user.

Co-authored-by: Thomas Eizinger <[email protected]>

* core/: Remove deprecated read/write functions (libp2p#2213)

Co-authored-by: Max Inden <[email protected]>

* protocols/ping: Revise naming of symbols (libp2p#2215)

Co-authored-by: Max Inden <[email protected]>

* protocols/rendezvous: Implement protocol (libp2p#2107)

Implement the libp2p rendezvous protocol.

> A lightweight mechanism for generalized peer discovery. It can be used for
bootstrap purposes, real time peer discovery, application specific routing, and
so on.

Co-authored-by: rishflab <[email protected]>
Co-authored-by: Daniel Karzel <[email protected]>

* core/src/network/event.rs: Fix typo (libp2p#2218)

* protocols/mdns: Do not fire all timers at the same time. (libp2p#2212)

Co-authored-by: Max Inden <[email protected]>

* misc/metrics/src/kad: Set query_duration lowest bucket to 0.1 sec (libp2p#2219)

Probability for a Kademlia query to return in less than 100 milliseconds
is low, thus increasing the lower bucket to improve accuracy within the
higher ranges.

* misc/metrics/src/swarm: Expose role on connections_closed (libp2p#2220)

Expose whether closed connection was a Dialer or Listener.

* .github/workflows/ci.yml: Use clang 11 (libp2p#2233)

* protocols/rendezvous: Update prost (libp2p#2226)

Co-authored-by: Max Inden <[email protected]>

* *: Fix clippy warnings (libp2p#2227)

* swarm-derive/: Make event_process = false the default (libp2p#2214)

Co-authored-by: Max Inden <[email protected]>

Co-authored-by: Max Inden <[email protected]>
Co-authored-by: Age Manning <[email protected]>
Co-authored-by: Ruben De Smet <[email protected]>
Co-authored-by: Thomas Eizinger <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: rishflab <[email protected]>
Co-authored-by: Daniel Karzel <[email protected]>
Co-authored-by: David Craven <[email protected]>
@mxinden
Copy link
Member

mxinden commented Oct 14, 2021

Thanks @kpp for driving this forward. I will take a look.

Copy link
Contributor Author

@kpp kpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Linked discussions from the previous PR

transports/quic/src/endpoint.rs Outdated Show resolved Hide resolved
transports/quic/src/endpoint.rs Outdated Show resolved Hide resolved
transports/quic/src/endpoint.rs Outdated Show resolved Hide resolved
transports/quic/src/crypto.rs Outdated Show resolved Hide resolved
transports/quic/src/endpoint.rs Outdated Show resolved Hide resolved
transports/quic/src/muxer.rs Outdated Show resolved Hide resolved
transports/quic/src/muxer.rs Outdated Show resolved Hide resolved
transports/quic/src/muxer.rs Outdated Show resolved Hide resolved
transports/quic/src/tls/verifier.rs Outdated Show resolved Hide resolved
transports/quic/tests/smoke.rs Outdated Show resolved Hide resolved
@kpp kpp marked this pull request as ready for review October 14, 2021 14:38
Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Short update: I am currently testing this pull request with https://github.com/mxinden/libp2p-perf. Still need a bit more time before I can share any results.

Small comment below.

transports/quic/Cargo.toml Outdated Show resolved Hide resolved
transports/quic/src/transport.rs Outdated Show resolved Hide resolved
transports/quic/src/endpoint.rs Outdated Show resolved Hide resolved
transports/quic/src/tls/certificate.rs Outdated Show resolved Hide resolved
transports/quic/src/tls/verifier.rs Outdated Show resolved Hide resolved
transports/quic/tests/smoke.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@dvc94ch dvc94ch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of this? @marten-seemann is not a contributor or even user of rust-libp2p, so don't know why his opinion is relevant here.

Test will be removed completely from the test harness in libp2p#3108.
Make `IfWatcher` a `Provider` item.
Use `if_watch::smol::IfWatcher` in `async-std::Provider` and
`if_watch::tokio::IfWatcher` in `tokio::Provider`.
Depending on what the remote sent in the initial packet, a new inbound
connection may directly be marked as closed.
Block on sending `pending_to_endpoint` before polling `from_endpoint`.
If the endpoint is blocked on writing to the udp socket it will
backpressure the connection, which will in return then stop polling for
events from the endpoint. The endpoint will drop new inbound packets
if the channel to the connection is full, thus eventually backpressuring
remote peers.
@elenaf9
Copy link
Contributor

elenaf9 commented Nov 12, 2022

Only missing pieces from my end:
...

  • Co-author lines on squash merge commit

I added co-author lines to the "# Commit message body" section of this PR.
If I understand it correctly this will add them to the squash merge commit @thomaseizinger? I might still merge manually though, but in that case those would be the co-authors that I include. Since @kpp is the author of the PR I think I don't have to add an extra line for him, right?
Let me know in case I missed anybody!

@thomaseizinger
Copy link
Contributor

thomaseizinger commented Nov 12, 2022

Only missing pieces from my end:
...

  • Co-author lines on squash merge commit

I added co-author lines to the "# Commit message body" section of this PR.
If I understand it correctly this will add them to the squash merge commit @thomaseizinger?

Correct. See #3106 for a recent example and c32f03c for the resulting commit!

@mergify
Copy link
Contributor

mergify bot commented Nov 13, 2022

This pull request has merge conflicts. Could you please resolve them @kpp? 🙏

@mxinden
Copy link
Member

mxinden commented Nov 13, 2022

For the record multiformats/rust-multiaddr#64 has been released with multiaddr v0.16.0. See multiformats/rust-multiaddr#62.

@mxinden
Copy link
Member

mxinden commented Nov 13, 2022

Only missing pieces from my end:
...

  • Co-author lines on squash merge commit

I added co-author lines to the "# Commit message body" section of this PR.
If I understand it correctly this will add them to the squash merge commit @thomaseizinger?

Correct. See paritytech/substrate#3106 for a recent example and c32f03c for the resulting commit!

Note that this is no longer the case with #3082 merged.

@thomaseizinger
Copy link
Contributor

Only missing pieces from my end:
...

  • Co-author lines on squash merge commit

I added co-author lines to the "# Commit message body" section of this PR.
If I understand it correctly this will add them to the squash merge commit @thomaseizinger?

Correct. See paritytech/substrate#3106 for a recent example and c32f03c for the resulting commit!

Note that this is no longer the case with #3082 merged.

Yes, needs to be at the end of ## Description now.

With multiformats/multiaddr#145 the `quic` codepoint should be
interpreted as QUIC draft-29. For QUIC v1 (RFC9000) the new codepoint
`quic-v1` should be used.

Quinn supports both, draft-29 and v1 as server, for clients however the
version has to be set when dialing. Right now we use the default, v1.
Proper support for `Protocol::QUIC` / draft-29 will be added in a
follow-up PR.

matches!(first, Ip4(_) | Ip6(_) | Dns(_) | Dns4(_) | Dns6(_))
&& matches!(second, Udp(_))
&& matches!(third, QuicV1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now we only support the new quic-v1 codepoint. Support for quic/ draft-29 will be added in a follow-up PR. See multiformats/multiaddr#145 (comment) for more info. cc @marten-seemann

@elenaf9
Copy link
Contributor

elenaf9 commented Nov 13, 2022

Unless there are any objections I will merge this PR tomorrow 🎉

@elenaf9 elenaf9 merged commit 0f5c491 into libp2p:master Nov 14, 2022
@elenaf9
Copy link
Contributor

elenaf9 commented Nov 14, 2022

🎉 We finally have a QUIC transport.
Huge thanks to @kpp, @DemiMarie, @thomaseizinger, and everyone else that contributed to this!

@DemiMarie
Copy link
Contributor

Glad that I could help @elenaf9!!!

@kpp kpp deleted the libp2p-quic branch November 14, 2022 21:54
mxinden added a commit to mxinden/rust-libp2p that referenced this pull request Jan 20, 2023
- Implementation based on `quinn-proto` was added in libp2p#2289
- Add new entry to evaluate using `quinn` directly
mergify bot pushed a commit that referenced this pull request Jan 23, 2023
- Implementation based on `quinn-proto` was added in #2289
- Add new entry to evaluate using `quinn` directly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Have the decl_storage! macro import rstd::prelude::*