Skip to content

Commit

Permalink
fix(quic): Identify /quic as QUIC address (#3288)
Browse files Browse the repository at this point in the history
Identify multiaddress with `/quic` (draft 29) as QUIC address in case `support_draft_29` is `true`.

Without this patch the Rust punchr client would discard any QUIC addresses with `/quic` in its `Transport::address_translation`. Thus `/quic` based observed addresses from `libp2p-identify` would not be added to the local set of external addresses and thus QUIC would not be available as a transport for hole punching.
  • Loading branch information
mxinden authored Jan 6, 2023
1 parent a124258 commit 5b8c3d2
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions transports/quic/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ impl<P: Provider> Transport for GenTransport<P> {
}

fn address_translation(&self, listen: &Multiaddr, observed: &Multiaddr) -> Option<Multiaddr> {
if !is_quic_addr(listen) || !is_quic_addr(observed) {
if !is_quic_addr(listen, self.support_draft_29)
|| !is_quic_addr(observed, self.support_draft_29)
{
return None;
}
Some(observed.clone())
Expand Down Expand Up @@ -597,7 +599,7 @@ fn multiaddr_to_socketaddr(
}

/// Whether an [`Multiaddr`] is a valid for the QUIC transport.
fn is_quic_addr(addr: &Multiaddr) -> bool {
fn is_quic_addr(addr: &Multiaddr, support_draft_29: bool) -> bool {
use Protocol::*;
let mut iter = addr.iter();
let first = match iter.next() {
Expand All @@ -617,7 +619,11 @@ fn is_quic_addr(addr: &Multiaddr) -> bool {

matches!(first, Ip4(_) | Ip6(_) | Dns(_) | Dns4(_) | Dns6(_))
&& matches!(second, Udp(_))
&& matches!(third, QuicV1)
&& if support_draft_29 {
matches!(third, QuicV1 | Quic)
} else {
matches!(third, QuicV1)
}
&& matches!(fourth, Some(P2p(_)) | None)
&& matches!(fifth, None)
}
Expand Down

0 comments on commit 5b8c3d2

Please sign in to comment.