Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Rename Protocol::WebRTC to Protocol::WebRTCDirect #78

Merged
merged 3 commits into from
Mar 24, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means we can then later add WebRTC in a non-breaking way right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct


- Rename `Protocol::WebRTC` to `Protocol::WebRTC`.
mxinden marked this conversation as resolved.
Show resolved Hide resolved
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),
Copy link
Contributor

@melekes melekes Mar 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must say having both webrtc-direct and p2p-webrtc-direct is confusing, but I guess nothing we can do about it other than adding clear documentation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could as well deprecate p2p-webrtc-direct. I am not aware of anyone using it. Though intuitively, that decision should happen on https://github.com/multiformats/multiaddr.

"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(),
);
}