Skip to content

Commit 1b363b0

Browse files
authored
fix: Rename Protocol::WebRTC string rep /webrtc to /webrtc-direct (#84)
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 3d247d7 commit 1b363b0

File tree

4 files changed

+60
-9
lines changed

4 files changed

+60
-9
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,29 @@
1+
# 0.17.1
2+
3+
- Rename string representation of `WebRTC` protocol from `/webrtc` to `/webrt-direct`.
4+
For backwards compatibility `/webrtc` will still be decoded to `Protocol::WebRTC`, but `Protocol::WebRTC` will from now on always be encoded as `/webrtc-direct`.
5+
See [multiformats/multiaddr discussion] and [PR 84] for context.
6+
``` rust
7+
assert_eq!(
8+
Multiaddr::empty().with(Protocol::WebRTC),
9+
"/webrtc".parse().unwrap(),
10+
);
11+
assert_eq!(
12+
Multiaddr::empty().with(Protocol::WebRTC),
13+
"/webrtc-direct".parse().unwrap(),
14+
);
15+
assert_eq!(
16+
"/webrtc-direct",
17+
Multiaddr::empty().with(Protocol::WebRTC).to_string(),
18+
);
19+
assert_ne!(
20+
"/webrtc",
21+
Multiaddr::empty().with(Protocol::WebRTC).to_string(),
22+
);
23+
```
24+
25+
[PR 84]: https://github.com/multiformats/rust-multiaddr/pull/84
26+
127
# 0.17.0
228

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

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ keywords = ["multiaddr", "ipfs"]
77
license = "MIT"
88
name = "multiaddr"
99
readme = "README.md"
10-
version = "0.17.0"
10+
version = "0.17.1"
1111

1212
[features]
1313
default = ["url"]
@@ -16,6 +16,7 @@ default = ["url"]
1616
arrayref = "0.3"
1717
byteorder = "1.3.1"
1818
data-encoding = "2.1"
19+
log = "0.4"
1920
multibase = "0.9.1"
2021
multihash = { version = "0.17", default-features = false, features = ["std", "multihash-impl", "identity"] }
2122
percent-encoding = "2.1.0"

src/protocol.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@ impl<'a> Protocol<'a> {
199199
}
200200
"p2p-websocket-star" => Ok(Protocol::P2pWebSocketStar),
201201
"p2p-webrtc-star" => Ok(Protocol::P2pWebRtcStar),
202-
"webrtc" => Ok(Protocol::WebRTC),
202+
"webrtc" => {
203+
log::warn!("Parsed deprecated /webrtc. Use /webrtc-direct instead.");
204+
Ok(Protocol::WebRTC)
205+
}
206+
"webrtc-direct" => Ok(Protocol::WebRTC),
203207
"certhash" => {
204208
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
205209
let (_base, decoded) = multibase::decode(s)?;
@@ -531,7 +535,7 @@ impl<'a> Protocol<'a> {
531535
Ip6(_) => "ip6",
532536
P2pWebRtcDirect => "p2p-webrtc-direct",
533537
P2pWebRtcStar => "p2p-webrtc-star",
534-
WebRTC => "webrtc",
538+
WebRTC => "webrtc-direct",
535539
Certhash(_) => "certhash",
536540
P2pWebSocketStar => "p2p-websocket-star",
537541
Memory(_) => "memory",

tests/lib.rs

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

344344
ma_valid(
345-
"/ip4/127.0.0.1/udp/1234/webrtc",
345+
"/ip4/127.0.0.1/udp/1234/webrtc-direct",
346346
"047F000001910204D29802",
347347
vec![Ip4(local), Udp(1234), WebRTC],
348348
);
349349

350350
let (_base, decoded) =
351351
multibase::decode("uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g").unwrap();
352352
ma_valid(
353-
"/ip4/127.0.0.1/udp/1234/webrtc/certhash/uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g",
353+
"/ip4/127.0.0.1/udp/1234/webrtc-direct/certhash/uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g",
354354
"047F000001910204D29802D203221220C3AB8FF13720E8AD9047DD39466B3C8974E592C2FA383D4A3960714CAEF0C4F2",
355355
vec![
356356
Ip4(local),
@@ -395,8 +395,8 @@ fn construct_fail() {
395395
"/ip4/127.0.0.1/p2p",
396396
"/ip4/127.0.0.1/p2p/tcp",
397397
"/p2p-circuit/50",
398-
"/ip4/127.0.0.1/udp/1234/webrtc/certhash",
399-
"/ip4/127.0.0.1/udp/1234/webrtc/certhash/b2uaraocy6yrdblb4sfptaddgimjmmp", // 1 character missing from certhash
398+
"/ip4/127.0.0.1/udp/1234/webrtc-direct/certhash",
399+
"/ip4/127.0.0.1/udp/1234/webrtc-direct/certhash/b2uaraocy6yrdblb4sfptaddgimjmmp", // 1 character missing from certhash
400400
];
401401

402402
for address in &addresses {
@@ -568,7 +568,7 @@ fn protocol_stack() {
568568
"/ip4/127.0.0.1/tcp/127/tls",
569569
"/ip4/127.0.0.1/tcp/127/tls/ws",
570570
"/ip4/127.0.0.1/tcp/127/noise",
571-
"/ip4/127.0.0.1/udp/1234/webrtc",
571+
"/ip4/127.0.0.1/udp/1234/webrtc-direct",
572572
];
573573
let argless = std::collections::HashSet::from([
574574
"http",
@@ -583,7 +583,7 @@ fn protocol_stack() {
583583
"tls",
584584
"udt",
585585
"utp",
586-
"webrtc",
586+
"webrtc-direct",
587587
"ws",
588588
"wss",
589589
]);
@@ -606,3 +606,23 @@ fn protocol_stack() {
606606
assert_eq!(ps, toks);
607607
}
608608
}
609+
610+
#[test]
611+
fn webrtc_webrtc_direct_rename() {
612+
assert_eq!(
613+
Multiaddr::empty().with(Protocol::WebRTC),
614+
"/webrtc".parse().unwrap(),
615+
);
616+
assert_eq!(
617+
Multiaddr::empty().with(Protocol::WebRTC),
618+
"/webrtc-direct".parse().unwrap(),
619+
);
620+
assert_eq!(
621+
"/webrtc-direct",
622+
Multiaddr::empty().with(Protocol::WebRTC).to_string(),
623+
);
624+
assert_ne!(
625+
"/webrtc",
626+
Multiaddr::empty().with(Protocol::WebRTC).to_string(),
627+
);
628+
}

0 commit comments

Comments
 (0)