Skip to content

Commit

Permalink
fix: Rename Protocol::WebRTC to Protocol::WebRTCDirect (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden authored Mar 24, 2023
1 parent 38fddf7 commit 13a1e9e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 36 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 7 additions & 11 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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".
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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",
Expand Down
26 changes: 3 additions & 23 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))),
Expand Down Expand Up @@ -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) =
Expand All @@ -370,7 +370,7 @@ fn construct_success() {
vec![
Ip4(local),
Udp(1234),
WebRTC,
WebRTCDirect,
Certhash(MultihashGeneric::from_bytes(&decoded).unwrap()),
],
);
Expand Down Expand Up @@ -649,23 +649,3 @@ fn arbitrary_impl_for_all_proto_variants() {
let variants = core::mem::variant_count::<Protocol>() 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(),
);
}

0 comments on commit 13a1e9e

Please sign in to comment.