Skip to content

Commit 13a1e9e

Browse files
authored
fix: Rename Protocol::WebRTC to Protocol::WebRTCDirect (#78)
See multiformats/multiaddr#150 (comment) for context.
1 parent 38fddf7 commit 13a1e9e

File tree

4 files changed

+17
-36
lines changed

4 files changed

+17
-36
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
# 0.18.0 [unreleased]
1+
# 0.18.0 - unreleased
22

33
- Add `WebTransport` instance for `Multiaddr`. See [PR 70].
44
- Disable all features of `multihash`. See [PR 77].
55
- Mark `Protocol` as `#[non_exhaustive]`. See [PR 82].
66

7+
- Rename `Protocol::WebRTC` to `Protocol::WebRTCDirect`.
8+
See [multiformats/multiaddr discussion] for context.
9+
Remove deprecated support for `/webrtc` in favor of the existing `/webrtc-direct` string representation.
10+
**Note that this is a breaking change.**
11+
12+
[multiformats/multiaddr discussion]: https://github.com/multiformats/multiaddr/pull/150#issuecomment-1468791586
713
[PR 70]: https://github.com/multiformats/rust-multiaddr/pull/70
814
[PR 77]: https://github.com/multiformats/rust-multiaddr/pull/77
915
[PR 82]: https://github.com/multiformats/rust-multiaddr/pull/82

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ default = ["url"]
1717
arrayref = "0.3"
1818
byteorder = "1.3.1"
1919
data-encoding = "2.1"
20-
log = "0.4"
2120
multibase = "0.9.1"
2221
multihash = { version = "0.18", default-features = false, features = ["std"] }
2322
percent-encoding = "2.1.0"

src/protocol.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const IP4: u32 = 4;
2828
const IP6: u32 = 41;
2929
const P2P_WEBRTC_DIRECT: u32 = 276;
3030
const P2P_WEBRTC_STAR: u32 = 275;
31-
const WEBRTC: u32 = 280;
31+
const WEBRTC_DIRECT: u32 = 280;
3232
const CERTHASH: u32 = 466;
3333
const P2P_WEBSOCKET_STAR: u32 = 479;
3434
const MEMORY: u32 = 777;
@@ -92,7 +92,7 @@ pub enum Protocol<'a> {
9292
Ip6(Ipv6Addr),
9393
P2pWebRtcDirect,
9494
P2pWebRtcStar,
95-
WebRTC,
95+
WebRTCDirect,
9696
Certhash(Multihash),
9797
P2pWebSocketStar,
9898
/// Contains the "port" to contact. Similar to TCP or UDP, 0 means "assign me a port".
@@ -210,11 +210,7 @@ impl<'a> Protocol<'a> {
210210
}
211211
"p2p-websocket-star" => Ok(Protocol::P2pWebSocketStar),
212212
"p2p-webrtc-star" => Ok(Protocol::P2pWebRtcStar),
213-
"webrtc" => {
214-
log::warn!("Parsed deprecated /webrtc. Use /webrtc-direct instead.");
215-
Ok(Protocol::WebRTC)
216-
}
217-
"webrtc-direct" => Ok(Protocol::WebRTC),
213+
"webrtc-direct" => Ok(Protocol::WebRTCDirect),
218214
"certhash" => {
219215
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
220216
let (_base, decoded) = multibase::decode(s)?;
@@ -296,7 +292,7 @@ impl<'a> Protocol<'a> {
296292
}
297293
P2P_WEBRTC_DIRECT => Ok((Protocol::P2pWebRtcDirect, input)),
298294
P2P_WEBRTC_STAR => Ok((Protocol::P2pWebRtcStar, input)),
299-
WEBRTC => Ok((Protocol::WebRTC, input)),
295+
WEBRTC_DIRECT => Ok((Protocol::WebRTCDirect, input)),
300296
CERTHASH => {
301297
let (n, input) = decode::usize(input)?;
302298
let (data, rest) = split_at(n, input)?;
@@ -479,7 +475,7 @@ impl<'a> Protocol<'a> {
479475
}
480476
Protocol::P2pWebSocketStar => w.write_all(encode::u32(P2P_WEBSOCKET_STAR, &mut buf))?,
481477
Protocol::P2pWebRtcStar => w.write_all(encode::u32(P2P_WEBRTC_STAR, &mut buf))?,
482-
Protocol::WebRTC => w.write_all(encode::u32(WEBRTC, &mut buf))?,
478+
Protocol::WebRTCDirect => w.write_all(encode::u32(WEBRTC_DIRECT, &mut buf))?,
483479
Protocol::Certhash(hash) => {
484480
w.write_all(encode::u32(CERTHASH, &mut buf))?;
485481
let bytes = hash.to_bytes();
@@ -511,7 +507,7 @@ impl<'a> Protocol<'a> {
511507
Ip6(a) => Ip6(a),
512508
P2pWebRtcDirect => P2pWebRtcDirect,
513509
P2pWebRtcStar => P2pWebRtcStar,
514-
WebRTC => WebRTC,
510+
WebRTCDirect => WebRTCDirect,
515511
Certhash(hash) => Certhash(hash),
516512
P2pWebSocketStar => P2pWebSocketStar,
517513
Memory(a) => Memory(a),
@@ -549,7 +545,7 @@ impl<'a> Protocol<'a> {
549545
Ip6(_) => "ip6",
550546
P2pWebRtcDirect => "p2p-webrtc-direct",
551547
P2pWebRtcStar => "p2p-webrtc-star",
552-
WebRTC => "webrtc-direct",
548+
WebRTCDirect => "webrtc-direct",
553549
Certhash(_) => "certhash",
554550
P2pWebSocketStar => "p2p-websocket-star",
555551
Memory(_) => "memory",

tests/lib.rs

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ impl Arbitrary for Proto {
102102
8 => Proto(Ip6(Ipv6Addr::arbitrary(g))),
103103
9 => Proto(P2pWebRtcDirect),
104104
10 => Proto(P2pWebRtcStar),
105-
11 => Proto(WebRTC),
105+
11 => Proto(WebRTCDirect),
106106
12 => Proto(Certhash(Mh::arbitrary(g).0)),
107107
13 => Proto(P2pWebSocketStar),
108108
14 => Proto(Memory(Arbitrary::arbitrary(g))),
@@ -359,7 +359,7 @@ fn construct_success() {
359359
ma_valid(
360360
"/ip4/127.0.0.1/udp/1234/webrtc-direct",
361361
"047F000001910204D29802",
362-
vec![Ip4(local), Udp(1234), WebRTC],
362+
vec![Ip4(local), Udp(1234), WebRTCDirect],
363363
);
364364

365365
let (_base, decoded) =
@@ -370,7 +370,7 @@ fn construct_success() {
370370
vec![
371371
Ip4(local),
372372
Udp(1234),
373-
WebRTC,
373+
WebRTCDirect,
374374
Certhash(MultihashGeneric::from_bytes(&decoded).unwrap()),
375375
],
376376
);
@@ -649,23 +649,3 @@ fn arbitrary_impl_for_all_proto_variants() {
649649
let variants = core::mem::variant_count::<Protocol>() as u8;
650650
assert_eq!(variants, Proto::IMPL_VARIANT_COUNT);
651651
}
652-
653-
#[test]
654-
fn webrtc_webrtc_direct_rename() {
655-
assert_eq!(
656-
Multiaddr::empty().with(Protocol::WebRTC),
657-
"/webrtc".parse().unwrap(),
658-
);
659-
assert_eq!(
660-
Multiaddr::empty().with(Protocol::WebRTC),
661-
"/webrtc-direct".parse().unwrap(),
662-
);
663-
assert_eq!(
664-
"/webrtc-direct",
665-
Multiaddr::empty().with(Protocol::WebRTC).to_string(),
666-
);
667-
assert_ne!(
668-
"/webrtc",
669-
Multiaddr::empty().with(Protocol::WebRTC).to_string(),
670-
);
671-
}

0 commit comments

Comments
 (0)