Skip to content

Commit 38fddf7

Browse files
authored
fix: Rename Protocol::WebRTC string rep /webrtc to /webrtc-direct (#84) (#87)
Considered non-breaking change as `/webrtc` will still be parsed to `Protocol::WebRTC` and no known production deployment of `libp2p-webrtc` known. See multiformats/multiaddr#150 (comment) for context.
1 parent 89deac2 commit 38fddf7

File tree

4 files changed

+59
-8
lines changed

4 files changed

+59
-8
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,32 @@
88
[PR 77]: https://github.com/multiformats/rust-multiaddr/pull/77
99
[PR 82]: https://github.com/multiformats/rust-multiaddr/pull/82
1010

11+
# 0.17.1
12+
13+
- Rename string representation of `WebRTC` protocol from `/webrtc` to `/webrt-direct`.
14+
For backwards compatibility `/webrtc` will still be decoded to `Protocol::WebRTC`, but `Protocol::WebRTC` will from now on always be encoded as `/webrtc-direct`.
15+
See [multiformats/multiaddr discussion] and [PR 84] for context.
16+
``` rust
17+
assert_eq!(
18+
Multiaddr::empty().with(Protocol::WebRTC),
19+
"/webrtc".parse().unwrap(),
20+
);
21+
assert_eq!(
22+
Multiaddr::empty().with(Protocol::WebRTC),
23+
"/webrtc-direct".parse().unwrap(),
24+
);
25+
assert_eq!(
26+
"/webrtc-direct",
27+
Multiaddr::empty().with(Protocol::WebRTC).to_string(),
28+
);
29+
assert_ne!(
30+
"/webrtc",
31+
Multiaddr::empty().with(Protocol::WebRTC).to_string(),
32+
);
33+
```
34+
35+
[PR 84]: https://github.com/multiformats/rust-multiaddr/pull/84
36+
1137
# 0.17.0
1238

1339
- Update to multihash `v0.17`. See [PR 63].

Cargo.toml

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

src/protocol.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,11 @@ impl<'a> Protocol<'a> {
210210
}
211211
"p2p-websocket-star" => Ok(Protocol::P2pWebSocketStar),
212212
"p2p-webrtc-star" => Ok(Protocol::P2pWebRtcStar),
213-
"webrtc" => Ok(Protocol::WebRTC),
213+
"webrtc" => {
214+
log::warn!("Parsed deprecated /webrtc. Use /webrtc-direct instead.");
215+
Ok(Protocol::WebRTC)
216+
}
217+
"webrtc-direct" => Ok(Protocol::WebRTC),
214218
"certhash" => {
215219
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
216220
let (_base, decoded) = multibase::decode(s)?;
@@ -545,7 +549,7 @@ impl<'a> Protocol<'a> {
545549
Ip6(_) => "ip6",
546550
P2pWebRtcDirect => "p2p-webrtc-direct",
547551
P2pWebRtcStar => "p2p-webrtc-star",
548-
WebRTC => "webrtc",
552+
WebRTC => "webrtc-direct",
549553
Certhash(_) => "certhash",
550554
P2pWebSocketStar => "p2p-websocket-star",
551555
Memory(_) => "memory",

tests/lib.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -357,15 +357,15 @@ fn construct_success() {
357357
);
358358

359359
ma_valid(
360-
"/ip4/127.0.0.1/udp/1234/webrtc",
360+
"/ip4/127.0.0.1/udp/1234/webrtc-direct",
361361
"047F000001910204D29802",
362362
vec![Ip4(local), Udp(1234), WebRTC],
363363
);
364364

365365
let (_base, decoded) =
366366
multibase::decode("uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g").unwrap();
367367
ma_valid(
368-
"/ip4/127.0.0.1/udp/1234/webrtc/certhash/uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g",
368+
"/ip4/127.0.0.1/udp/1234/webrtc-direct/certhash/uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g",
369369
"047F000001910204D29802D203221220C3AB8FF13720E8AD9047DD39466B3C8974E592C2FA383D4A3960714CAEF0C4F2",
370370
vec![
371371
Ip4(local),
@@ -429,8 +429,8 @@ fn construct_fail() {
429429
"/ip4/127.0.0.1/p2p",
430430
"/ip4/127.0.0.1/p2p/tcp",
431431
"/p2p-circuit/50",
432-
"/ip4/127.0.0.1/udp/1234/webrtc/certhash",
433-
"/ip4/127.0.0.1/udp/1234/webrtc/certhash/b2uaraocy6yrdblb4sfptaddgimjmmp", // 1 character missing from certhash
432+
"/ip4/127.0.0.1/udp/1234/webrtc-direct/certhash",
433+
"/ip4/127.0.0.1/udp/1234/webrtc-direct/certhash/b2uaraocy6yrdblb4sfptaddgimjmmp", // 1 character missing from certhash
434434
];
435435

436436
for address in &addresses {
@@ -602,7 +602,7 @@ fn protocol_stack() {
602602
"/ip4/127.0.0.1/tcp/127/tls",
603603
"/ip4/127.0.0.1/tcp/127/tls/ws",
604604
"/ip4/127.0.0.1/tcp/127/noise",
605-
"/ip4/127.0.0.1/udp/1234/webrtc",
605+
"/ip4/127.0.0.1/udp/1234/webrtc-direct",
606606
];
607607
let argless = std::collections::HashSet::from([
608608
"http",
@@ -617,7 +617,7 @@ fn protocol_stack() {
617617
"tls",
618618
"udt",
619619
"utp",
620-
"webrtc",
620+
"webrtc-direct",
621621
"ws",
622622
"wss",
623623
]);
@@ -649,3 +649,23 @@ 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)