Skip to content

Commit

Permalink
fix: Rename Protocol::WebRTC string rep /webrtc to /webrtc-direct
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mxinden committed Mar 22, 2023
1 parent 3d247d7 commit 58dc341
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
# 0.17.1

- Rename string representation of `WebRTC` protocol from `/webrtc` to `/webrt-direct`.
For backwards compatibility `/webrtc` will still be decoded to `Protocol::WebRTC`, but `Protocol::WebRTC` will from now on always be encoded as `/webrtc-direct`.
See [multiformats/multiaddr discussion] for context.
``` rust
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.17.0

- Update to multihash `v0.17`. See [PR 63].
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ keywords = ["multiaddr", "ipfs"]
license = "MIT"
name = "multiaddr"
readme = "README.md"
version = "0.17.0"
version = "0.17.1"

[features]
default = ["url"]
Expand Down
3 changes: 2 additions & 1 deletion src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ impl<'a> Protocol<'a> {
"p2p-websocket-star" => Ok(Protocol::P2pWebSocketStar),
"p2p-webrtc-star" => Ok(Protocol::P2pWebRtcStar),
"webrtc" => Ok(Protocol::WebRTC),
"webrtc-direct" => Ok(Protocol::WebRTC),
"certhash" => {
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
let (_base, decoded) = multibase::decode(s)?;
Expand Down Expand Up @@ -531,7 +532,7 @@ impl<'a> Protocol<'a> {
Ip6(_) => "ip6",
P2pWebRtcDirect => "p2p-webrtc-direct",
P2pWebRtcStar => "p2p-webrtc-star",
WebRTC => "webrtc",
WebRTC => "webrtc-direct",
Certhash(_) => "certhash",
P2pWebSocketStar => "p2p-websocket-star",
Memory(_) => "memory",
Expand Down
32 changes: 26 additions & 6 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,15 +342,15 @@ fn construct_success() {
);

ma_valid(
"/ip4/127.0.0.1/udp/1234/webrtc",
"/ip4/127.0.0.1/udp/1234/webrtc-direct",
"047F000001910204D29802",
vec![Ip4(local), Udp(1234), WebRTC],
);

let (_base, decoded) =
multibase::decode("uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g").unwrap();
ma_valid(
"/ip4/127.0.0.1/udp/1234/webrtc/certhash/uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g",
"/ip4/127.0.0.1/udp/1234/webrtc-direct/certhash/uEiDDq4_xNyDorZBH3TlGazyJdOWSwvo4PUo5YHFMrvDE8g",
"047F000001910204D29802D203221220C3AB8FF13720E8AD9047DD39466B3C8974E592C2FA383D4A3960714CAEF0C4F2",
vec![
Ip4(local),
Expand Down Expand Up @@ -395,8 +395,8 @@ fn construct_fail() {
"/ip4/127.0.0.1/p2p",
"/ip4/127.0.0.1/p2p/tcp",
"/p2p-circuit/50",
"/ip4/127.0.0.1/udp/1234/webrtc/certhash",
"/ip4/127.0.0.1/udp/1234/webrtc/certhash/b2uaraocy6yrdblb4sfptaddgimjmmp", // 1 character missing from certhash
"/ip4/127.0.0.1/udp/1234/webrtc-direct/certhash",
"/ip4/127.0.0.1/udp/1234/webrtc-direct/certhash/b2uaraocy6yrdblb4sfptaddgimjmmp", // 1 character missing from certhash
];

for address in &addresses {
Expand Down Expand Up @@ -568,7 +568,7 @@ fn protocol_stack() {
"/ip4/127.0.0.1/tcp/127/tls",
"/ip4/127.0.0.1/tcp/127/tls/ws",
"/ip4/127.0.0.1/tcp/127/noise",
"/ip4/127.0.0.1/udp/1234/webrtc",
"/ip4/127.0.0.1/udp/1234/webrtc-direct",
];
let argless = std::collections::HashSet::from([
"http",
Expand All @@ -583,7 +583,7 @@ fn protocol_stack() {
"tls",
"udt",
"utp",
"webrtc",
"webrtc-direct",
"ws",
"wss",
]);
Expand All @@ -606,3 +606,23 @@ fn protocol_stack() {
assert_eq!(ps, toks);
}
}

#[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 58dc341

Please sign in to comment.