From e567f470325146fd1ef4c0632788de278e3b46fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Fri, 9 Dec 2022 12:55:08 +0000 Subject: [PATCH 1/3] src/protocol.rs: Add /webtransport --- CHANGELOG.md | 6 ++++++ src/protocol.rs | 7 +++++++ tests/lib.rs | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 33d7983..3f6fb78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.18.0 [unreleased] + +- Add `WebTransport` instance for `Multiaddr`. See [PR 70]. + +[PR 70]: https://github.com/multiformats/rust-multiaddr/pull/70 + # 0.17.0 - Update to multihash `v0.17`. See [PR 63]. diff --git a/src/protocol.rs b/src/protocol.rs index 006962d..e39228a 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -46,6 +46,7 @@ const UDP: u32 = 273; const UDT: u32 = 301; const UNIX: u32 = 400; const UTP: u32 = 302; +const WEBTRANSPORT: u32 = 465; const WS: u32 = 477; const WS_WITH_PATH: u32 = 4770; // Note: not standard const WSS: u32 = 478; @@ -102,6 +103,7 @@ pub enum Protocol<'a> { Udt, Unix(Cow<'a, str>), Utp, + WebTransport, Ws(Cow<'a, str>), Wss(Cow<'a, str>), } @@ -185,6 +187,7 @@ impl<'a> Protocol<'a> { .map(|(a, p)| Protocol::Onion3((a, p).into())), "quic" => Ok(Protocol::Quic), "quic-v1" => Ok(Protocol::QuicV1), + "webtransport" => Ok(Protocol::WebTransport), "ws" => Ok(Protocol::Ws(Cow::Borrowed("/"))), "wss" => Ok(Protocol::Wss(Cow::Borrowed("/"))), "x-parity-ws" => { @@ -345,6 +348,7 @@ impl<'a> Protocol<'a> { Ok((Protocol::Unix(Cow::Borrowed(str::from_utf8(data)?)), rest)) } UTP => Ok((Protocol::Utp, input)), + WEBTRANSPORT => Ok((Protocol::WebTransport, input)), WS => Ok((Protocol::Ws(Cow::Borrowed("/")), input)), WS_WITH_PATH => { let (n, input) = decode::usize(input)?; @@ -446,6 +450,7 @@ impl<'a> Protocol<'a> { Protocol::Udt => w.write_all(encode::u32(UDT, &mut buf))?, Protocol::Http => w.write_all(encode::u32(HTTP, &mut buf))?, Protocol::Https => w.write_all(encode::u32(HTTPS, &mut buf))?, + Protocol::WebTransport => w.write_all(encode::u32(WEBTRANSPORT, &mut buf))?, Protocol::Ws(ref s) if s == "/" => w.write_all(encode::u32(WS, &mut buf))?, Protocol::Ws(s) => { w.write_all(encode::u32(WS_WITH_PATH, &mut buf))?; @@ -512,6 +517,7 @@ impl<'a> Protocol<'a> { Udt => Udt, Unix(cow) => Unix(Cow::Owned(cow.into_owned())), Utp => Utp, + WebTransport => WebTransport, Ws(cow) => Ws(Cow::Owned(cow.into_owned())), Wss(cow) => Wss(Cow::Owned(cow.into_owned())), } @@ -549,6 +555,7 @@ impl<'a> Protocol<'a> { Udt => "udt", Unix(_) => "unix", Utp => "utp", + WebTransport => "webtransport", Ws(ref s) if s == "/" => "ws", Ws(_) => "x-parity-ws", Wss(ref s) if s == "/" => "wss", diff --git a/tests/lib.rs b/tests/lib.rs index fa88221..981784d 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -359,6 +359,25 @@ fn construct_success() { Certhash(Multihash::from_bytes(&decoded).unwrap()), ], ); + + ma_valid( + "/ip4/127.0.0.1/udp/1234/quic/webtransport", + "047F000001910204D2CC03D103", + vec![Ip4(local), Udp(1234), Quic, WebTransport], + ); + + let (_base, decoded) = + multibase::decode("uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g").unwrap(); + ma_valid( + "/ip4/127.0.0.1/udp/1234/webtransport/certhash/uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g", + "047F000001910204D2D103D203221220C3AB8FF13720E8AD9047DD39466B3C8974E592C2FA383D4A3960714CAEF0C4F2", + vec![ + Ip4(local), + Udp(1234), + WebTransport, + Certhash(Multihash::from_bytes(&decoded).unwrap()), + ], + ); } #[test] From b730f17b0fe4984a76ca2670624177cf02446edc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Thu, 15 Dec 2022 12:20:06 +0000 Subject: [PATCH 2/3] review: update Proto Arbitrary implementation with WebTransport --- tests/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/lib.rs b/tests/lib.rs index 981784d..9e37577 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -88,7 +88,7 @@ struct Proto(Protocol<'static>); impl Arbitrary for Proto { fn arbitrary(g: &mut G) -> Self { use Protocol::*; - match u8::arbitrary(g) % 27 { + match u8::arbitrary(g) % 28 { 0 => Proto(Dccp(Arbitrary::arbitrary(g))), 1 => Proto(Dns(Cow::Owned(SubString::arbitrary(g).0))), 2 => Proto(Dns4(Cow::Owned(SubString::arbitrary(g).0))), @@ -133,6 +133,7 @@ impl Arbitrary for Proto { } 25 => Proto(Tls), 26 => Proto(QuicV1), + 27 => Proto(WebTransport), _ => panic!("outside range"), } } From f87914f96ce35d4d7f5e1177937ffee28ad3e0ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Thu, 15 Dec 2022 15:13:08 +0000 Subject: [PATCH 3/3] review: add missing entry on Cargo.toml --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 7de2404..2b309ff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ keywords = ["multiaddr", "ipfs"] license = "MIT" name = "multiaddr" readme = "README.md" -version = "0.17.0" +version = "0.18.0" [features] default = ["url"]