Skip to content

Commit

Permalink
fix: Rename /webrtc to /webrtc-direct
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed Mar 17, 2023
1 parent 76bcb76 commit 79d3c7b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# 0.18.0 [unreleased]
# 0.18.0 - unreleased

- Add `WebTransport` instance for `Multiaddr`. See [PR 70].

- Rename `/webrtc` to `/webrt-direct`. See [multiformats/multiaddr discussion] for context. **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

# 0.17.0
Expand Down
14 changes: 7 additions & 7 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 @@ -84,7 +84,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 @@ -202,7 +202,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::WebRTCDirect),
"certhash" => {
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
let (_base, decoded) = multibase::decode(s)?;
Expand Down Expand Up @@ -284,7 +284,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 @@ -467,7 +467,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 @@ -499,7 +499,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 @@ -537,7 +537,7 @@ impl<'a> Protocol<'a> {
Ip6(_) => "ip6",
P2pWebRtcDirect => "p2p-webrtc-direct",
P2pWebRtcStar => "p2p-webrtc-star",
WebRTC => "webrtc",
WebRTCDirect => "webrtc-direct",
Certhash(_) => "certhash",
P2pWebSocketStar => "p2p-websocket-star",
Memory(_) => "memory",
Expand Down
16 changes: 8 additions & 8 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,20 +360,20 @@ 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],
vec![Ip4(local), Udp(1234), WebRTCDirect],
);

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),
Udp(1234),
WebRTC,
WebRTCDirect,
Certhash(Multihash::from_bytes(&decoded).unwrap()),
],
);
Expand Down Expand Up @@ -432,8 +432,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 @@ -605,7 +605,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 @@ -620,7 +620,7 @@ fn protocol_stack() {
"tls",
"udt",
"utp",
"webrtc",
"webrtc-direct",
"ws",
"wss",
]);
Expand Down

0 comments on commit 79d3c7b

Please sign in to comment.