Skip to content

Commit

Permalink
deps(quic): update quinn to 0.11 and libp2p-tls to 0.4.0
Browse files Browse the repository at this point in the history
This PR updates the following dependencies `quic`:

* `quinn@0.10.2` -> `quinn@0.11.0`
* `rustls@0.21.9` -> `rustls@0.23.4`

Pull-Request: #5316.
  • Loading branch information
retrohacker committed May 23, 2024
1 parent 6aaf284 commit 94fef37
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 56 deletions.
72 changes: 31 additions & 41 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ libp2p-stream = { version = "0.1.0-alpha.1", path = "protocols/stream" }
libp2p-swarm = { version = "0.44.2", path = "swarm" }
libp2p-swarm-derive = { version = "=0.34.2", path = "swarm-derive" } # `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required.
libp2p-swarm-test = { version = "0.3.0", path = "swarm-test" }
libp2p-tls = { version = "0.4.0", path = "transports/tls" }
libp2p-tcp = { version = "0.41.1", path = "transports/tcp" }
libp2p-tls = { version = "0.4.0", path = "transports/tls" }
libp2p-uds = { version = "0.40.0", path = "transports/uds" }
libp2p-upnp = { version = "0.2.2", path = "protocols/upnp" }
libp2p-webrtc = { version = "0.7.1-alpha", path = "transports/webrtc" }
Expand Down
4 changes: 4 additions & 0 deletions transports/quic/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
## 0.10.3

- Update `quinn` to 0.11 and `libp2p-tls` to 0.4.0.
See [PR 5316](https://github.com/libp2p/rust-libp2p/pull/5316)

- Allow configuring MTU discovery upper bound.
See [PR 5386](https://github.com/libp2p/rust-libp2p/pull/5386).

Expand Down
8 changes: 4 additions & 4 deletions transports/quic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ futures = { workspace = true }
futures-timer = "3.0.3"
if-watch = "3.2.0"
libp2p-core = { workspace = true }
libp2p-tls = "0.3.0"
libp2p-tls = "0.4.0"
libp2p-identity = { workspace = true }
parking_lot = "0.12.2"
quinn = { version = "0.10.2", default-features = false, features = ["tls-rustls", "futures-io"] }
quinn = { version = "0.11.0", default-features = false, features = ["rustls", "futures-io"] }
rand = "0.8.5"
rustls = { version = "0.21.9", default-features = false }
rustls = { version = "0.23.5", default-features = false }
thiserror = "1.0.61"
tokio = { workspace = true, default-features = false, features = ["net", "rt", "time"], optional = true }
tracing = { workspace = true }
socket2 = "0.5.7"
ring = "0.16.20"
ring = { workspace = true }

[features]
tokio = ["dep:tokio", "if-watch/tokio", "quinn/runtime-tokio"]
Expand Down
18 changes: 13 additions & 5 deletions transports/quic/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

use quinn::{MtuDiscoveryConfig, VarInt};
use quinn::{
crypto::rustls::{QuicClientConfig, QuicServerConfig},
MtuDiscoveryConfig, VarInt,
};
use std::{sync::Arc, time::Duration};

/// Config for the transport.
Expand Down Expand Up @@ -58,9 +61,9 @@ pub struct Config {
pub support_draft_29: bool,

/// TLS client config for the inner [`quinn::ClientConfig`].
client_tls_config: Arc<rustls::ClientConfig>,
client_tls_config: Arc<QuicClientConfig>,
/// TLS server config for the inner [`quinn::ServerConfig`].
server_tls_config: Arc<rustls::ServerConfig>,
server_tls_config: Arc<QuicServerConfig>,
/// Libp2p identity of the node.
keypair: libp2p_identity::Keypair,

Expand All @@ -71,8 +74,13 @@ pub struct Config {
impl Config {
/// Creates a new configuration object with default values.
pub fn new(keypair: &libp2p_identity::Keypair) -> Self {
let client_tls_config = Arc::new(libp2p_tls::make_client_config(keypair, None).unwrap());
let server_tls_config = Arc::new(libp2p_tls::make_server_config(keypair).unwrap());
let client_tls_config = Arc::new(
QuicClientConfig::try_from(libp2p_tls::make_client_config(keypair, None).unwrap())
.unwrap(),
);
let server_tls_config = Arc::new(
QuicServerConfig::try_from(libp2p_tls::make_server_config(keypair).unwrap()).unwrap(),
);
Self {
client_tls_config,
server_tls_config,
Expand Down
3 changes: 2 additions & 1 deletion transports/quic/src/connection/connecting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use futures::{
};
use futures_timer::Delay;
use libp2p_identity::PeerId;
use quinn::rustls::pki_types::CertificateDer;
use std::{
pin::Pin,
task::{Context, Poll},
Expand Down Expand Up @@ -55,7 +56,7 @@ impl Connecting {
let identity = connection
.peer_identity()
.expect("connection got identity because it passed TLS handshake; qed");
let certificates: Box<Vec<rustls::Certificate>> =
let certificates: Box<Vec<CertificateDer>> =
identity.downcast().expect("we rely on rustls feature; qed");
let end_entity = certificates
.first()
Expand Down
4 changes: 3 additions & 1 deletion transports/quic/src/connection/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ impl AsyncWrite for Stream {
cx: &mut Context,
buf: &[u8],
) -> Poll<io::Result<usize>> {
Pin::new(&mut self.send).poll_write(cx, buf)
Pin::new(&mut self.send)
.poll_write(cx, buf)
.map_err(Into::into)
}

fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<io::Result<()>> {
Expand Down
14 changes: 12 additions & 2 deletions transports/quic/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ struct Listener<P: Provider> {
socket: UdpSocket,

/// A future to poll new incoming connections.
accept: BoxFuture<'static, Option<quinn::Connecting>>,
accept: BoxFuture<'static, Option<quinn::Incoming>>,
/// Timeout for connection establishment on inbound connections.
handshake_timeout: Duration,

Expand Down Expand Up @@ -583,10 +583,20 @@ impl<P: Provider> Stream for Listener<P> {
}

match self.accept.poll_unpin(cx) {
Poll::Ready(Some(connecting)) => {
Poll::Ready(Some(incoming)) => {
let endpoint = self.endpoint.clone();
self.accept = async move { endpoint.accept().await }.boxed();

let connecting = match incoming.accept() {
Ok(connecting) => connecting,
Err(error) => {
return Poll::Ready(Some(TransportEvent::ListenerError {
listener_id: self.listener_id,
error: Error::Connection(crate::ConnectionError(error)),
}))
}
};

let local_addr = socketaddr_to_multiaddr(&self.socket_addr(), self.version);
let remote_addr = connecting.remote_address();
let send_back_addr = socketaddr_to_multiaddr(&remote_addr, self.version);
Expand Down
2 changes: 1 addition & 1 deletion transports/quic/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ async fn write_after_peer_dropped_stream() {
.try_init();
let (stream_a, mut stream_b) = build_streams::<quic::async_std::Provider>().await;
drop(stream_a);
futures_timer::Delay::new(Duration::from_millis(1)).await;
futures_timer::Delay::new(Duration::from_millis(10)).await;

let data = vec![0; 10];
stream_b.write_all(&data).await.expect("Write failed.");
Expand Down

0 comments on commit 94fef37

Please sign in to comment.