From 13a1e9e7da1e26a3aecdec695dc8e5cb0994d4b9 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Fri, 24 Mar 2023 16:12:01 +0100 Subject: [PATCH] fix: Rename `Protocol::WebRTC` to `Protocol::WebRTCDirect` (#78) See https://github.com/multiformats/multiaddr/pull/150#issuecomment-1468791586 for context. --- CHANGELOG.md | 8 +++++++- Cargo.toml | 1 - src/protocol.rs | 18 +++++++----------- tests/lib.rs | 26 +++----------------------- 4 files changed, 17 insertions(+), 36 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 776e542..971ba2e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,15 @@ -# 0.18.0 [unreleased] +# 0.18.0 - unreleased - Add `WebTransport` instance for `Multiaddr`. See [PR 70]. - Disable all features of `multihash`. See [PR 77]. - Mark `Protocol` as `#[non_exhaustive]`. See [PR 82]. +- Rename `Protocol::WebRTC` to `Protocol::WebRTCDirect`. + See [multiformats/multiaddr discussion] for context. + Remove deprecated support for `/webrtc` in favor of the existing `/webrtc-direct` string representation. + **Note that this is a breaking change.** + +[multiformats/multiaddr discussion]: https://github.com/multiformats/multiaddr/pull/150#issuecomment-1468791586 [PR 70]: https://github.com/multiformats/rust-multiaddr/pull/70 [PR 77]: https://github.com/multiformats/rust-multiaddr/pull/77 [PR 82]: https://github.com/multiformats/rust-multiaddr/pull/82 diff --git a/Cargo.toml b/Cargo.toml index a1a20ac..7ed04f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,6 @@ default = ["url"] arrayref = "0.3" byteorder = "1.3.1" data-encoding = "2.1" -log = "0.4" multibase = "0.9.1" multihash = { version = "0.18", default-features = false, features = ["std"] } percent-encoding = "2.1.0" diff --git a/src/protocol.rs b/src/protocol.rs index f3e96b1..53abb66 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -28,7 +28,7 @@ const IP4: u32 = 4; const IP6: u32 = 41; const P2P_WEBRTC_DIRECT: u32 = 276; const P2P_WEBRTC_STAR: u32 = 275; -const WEBRTC: u32 = 280; +const WEBRTC_DIRECT: u32 = 280; const CERTHASH: u32 = 466; const P2P_WEBSOCKET_STAR: u32 = 479; const MEMORY: u32 = 777; @@ -92,7 +92,7 @@ pub enum Protocol<'a> { Ip6(Ipv6Addr), P2pWebRtcDirect, P2pWebRtcStar, - WebRTC, + WebRTCDirect, Certhash(Multihash), P2pWebSocketStar, /// Contains the "port" to contact. Similar to TCP or UDP, 0 means "assign me a port". @@ -210,11 +210,7 @@ impl<'a> Protocol<'a> { } "p2p-websocket-star" => Ok(Protocol::P2pWebSocketStar), "p2p-webrtc-star" => Ok(Protocol::P2pWebRtcStar), - "webrtc" => { - log::warn!("Parsed deprecated /webrtc. Use /webrtc-direct instead."); - Ok(Protocol::WebRTC) - } - "webrtc-direct" => Ok(Protocol::WebRTC), + "webrtc-direct" => Ok(Protocol::WebRTCDirect), "certhash" => { let s = iter.next().ok_or(Error::InvalidProtocolString)?; let (_base, decoded) = multibase::decode(s)?; @@ -296,7 +292,7 @@ impl<'a> Protocol<'a> { } P2P_WEBRTC_DIRECT => Ok((Protocol::P2pWebRtcDirect, input)), P2P_WEBRTC_STAR => Ok((Protocol::P2pWebRtcStar, input)), - WEBRTC => Ok((Protocol::WebRTC, input)), + WEBRTC_DIRECT => Ok((Protocol::WebRTCDirect, input)), CERTHASH => { let (n, input) = decode::usize(input)?; let (data, rest) = split_at(n, input)?; @@ -479,7 +475,7 @@ impl<'a> Protocol<'a> { } Protocol::P2pWebSocketStar => w.write_all(encode::u32(P2P_WEBSOCKET_STAR, &mut buf))?, Protocol::P2pWebRtcStar => w.write_all(encode::u32(P2P_WEBRTC_STAR, &mut buf))?, - Protocol::WebRTC => w.write_all(encode::u32(WEBRTC, &mut buf))?, + Protocol::WebRTCDirect => w.write_all(encode::u32(WEBRTC_DIRECT, &mut buf))?, Protocol::Certhash(hash) => { w.write_all(encode::u32(CERTHASH, &mut buf))?; let bytes = hash.to_bytes(); @@ -511,7 +507,7 @@ impl<'a> Protocol<'a> { Ip6(a) => Ip6(a), P2pWebRtcDirect => P2pWebRtcDirect, P2pWebRtcStar => P2pWebRtcStar, - WebRTC => WebRTC, + WebRTCDirect => WebRTCDirect, Certhash(hash) => Certhash(hash), P2pWebSocketStar => P2pWebSocketStar, Memory(a) => Memory(a), @@ -549,7 +545,7 @@ impl<'a> Protocol<'a> { Ip6(_) => "ip6", P2pWebRtcDirect => "p2p-webrtc-direct", P2pWebRtcStar => "p2p-webrtc-star", - WebRTC => "webrtc-direct", + WebRTCDirect => "webrtc-direct", Certhash(_) => "certhash", P2pWebSocketStar => "p2p-websocket-star", Memory(_) => "memory", diff --git a/tests/lib.rs b/tests/lib.rs index c653d93..70227f8 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -102,7 +102,7 @@ impl Arbitrary for Proto { 8 => Proto(Ip6(Ipv6Addr::arbitrary(g))), 9 => Proto(P2pWebRtcDirect), 10 => Proto(P2pWebRtcStar), - 11 => Proto(WebRTC), + 11 => Proto(WebRTCDirect), 12 => Proto(Certhash(Mh::arbitrary(g).0)), 13 => Proto(P2pWebSocketStar), 14 => Proto(Memory(Arbitrary::arbitrary(g))), @@ -359,7 +359,7 @@ fn construct_success() { ma_valid( "/ip4/127.0.0.1/udp/1234/webrtc-direct", "047F000001910204D29802", - vec![Ip4(local), Udp(1234), WebRTC], + vec![Ip4(local), Udp(1234), WebRTCDirect], ); let (_base, decoded) = @@ -370,7 +370,7 @@ fn construct_success() { vec![ Ip4(local), Udp(1234), - WebRTC, + WebRTCDirect, Certhash(MultihashGeneric::from_bytes(&decoded).unwrap()), ], ); @@ -649,23 +649,3 @@ fn arbitrary_impl_for_all_proto_variants() { let variants = core::mem::variant_count::() as u8; assert_eq!(variants, Proto::IMPL_VARIANT_COUNT); } - -#[test] -fn webrtc_webrtc_direct_rename() { - assert_eq!( - Multiaddr::empty().with(Protocol::WebRTC), - "/webrtc".parse().unwrap(), - ); - assert_eq!( - Multiaddr::empty().with(Protocol::WebRTC), - "/webrtc-direct".parse().unwrap(), - ); - assert_eq!( - "/webrtc-direct", - Multiaddr::empty().with(Protocol::WebRTC).to_string(), - ); - assert_ne!( - "/webrtc", - Multiaddr::empty().with(Protocol::WebRTC).to_string(), - ); -}