Skip to content

Mark Protocol::Wss as deprecated #126

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
7 changes: 6 additions & 1 deletion src/from_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ fn from_url_inner_http_ws(
) -> std::result::Result<Multiaddr, FromUrlErr> {
let (protocol, lost_path, default_port) = match url.scheme() {
"ws" => (Protocol::Ws(url.path().to_owned().into()), false, 80),
"wss" => (Protocol::Wss(url.path().to_owned().into()), false, 443),
"wss" => (
#[allow(deprecated)]
Protocol::Wss(url.path().to_owned().into()),
false,
443,
),
"http" => (Protocol::Http, true, 80),
"https" => (Protocol::Https, true, 443),
_ => unreachable!("We only call this function for one of the given schemes; qed"),
Expand Down
29 changes: 25 additions & 4 deletions src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ pub enum Protocol<'a> {
Utp,
WebTransport,
Ws(Cow<'a, str>),
#[deprecated]
Wss(Cow<'a, str>),
Ip6zone(Cow<'a, str>),
Ipcidr(u8),
Expand Down Expand Up @@ -215,7 +216,10 @@ impl<'a> Protocol<'a> {
"quic-v1" => Ok(Protocol::QuicV1),
"webtransport" => Ok(Protocol::WebTransport),
"ws" => Ok(Protocol::Ws(Cow::Borrowed("/"))),
"wss" => Ok(Protocol::Wss(Cow::Borrowed("/"))),
"wss" => Ok(
#[allow(deprecated)]
Protocol::Wss(Cow::Borrowed("/")),
),
"x-parity-ws" => {
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
let decoded = percent_encoding::percent_decode(s.as_bytes()).decode_utf8()?;
Expand All @@ -224,7 +228,10 @@ impl<'a> Protocol<'a> {
"x-parity-wss" => {
let s = iter.next().ok_or(Error::InvalidProtocolString)?;
let decoded = percent_encoding::percent_decode(s.as_bytes()).decode_utf8()?;
Ok(Protocol::Wss(decoded))
Ok(
#[allow(deprecated)]
Protocol::Wss(decoded),
)
}
"p2p-websocket-star" => Ok(Protocol::P2pWebSocketStar),
"p2p-webrtc-star" => Ok(Protocol::P2pWebRtcStar),
Expand Down Expand Up @@ -429,11 +436,19 @@ impl<'a> Protocol<'a> {
let (data, rest) = split_at(n, input)?;
Ok((Protocol::Ws(Cow::Borrowed(str::from_utf8(data)?)), rest))
}
WSS => Ok((Protocol::Wss(Cow::Borrowed("/")), input)),
WSS => Ok((
#[allow(deprecated)]
Protocol::Wss(Cow::Borrowed("/")),
input,
)),
WSS_WITH_PATH => {
let (n, input) = decode::usize(input)?;
let (data, rest) = split_at(n, input)?;
Ok((Protocol::Wss(Cow::Borrowed(str::from_utf8(data)?)), rest))
Ok((
#[allow(deprecated)]
Protocol::Wss(Cow::Borrowed(str::from_utf8(data)?)),
rest,
))
}
IP6ZONE => {
let (n, input) = decode::usize(input)?;
Expand Down Expand Up @@ -569,7 +584,9 @@ impl<'a> Protocol<'a> {
w.write_all(encode::usize(bytes.len(), &mut encode::usize_buffer()))?;
w.write_all(bytes)?
}
#[allow(deprecated)]
Protocol::Wss(ref s) if s == "/" => w.write_all(encode::u32(WSS, &mut buf))?,
#[allow(deprecated)]
Protocol::Wss(s) => {
w.write_all(encode::u32(WSS_WITH_PATH, &mut buf))?;
let bytes = s.as_bytes();
Expand Down Expand Up @@ -664,6 +681,7 @@ impl<'a> Protocol<'a> {
Utp => Utp,
WebTransport => WebTransport,
Ws(cow) => Ws(Cow::Owned(cow.into_owned())),
#[allow(deprecated)]
Wss(cow) => Wss(Cow::Owned(cow.into_owned())),
Ip6zone(cow) => Ip6zone(Cow::Owned(cow.into_owned())),
Ipcidr(mask) => Ipcidr(mask),
Expand Down Expand Up @@ -711,7 +729,9 @@ impl<'a> Protocol<'a> {
WebTransport => "webtransport",
Ws(ref s) if s == "/" => "ws",
Ws(_) => "x-parity-ws",
#[allow(deprecated)]
Wss(ref s) if s == "/" => "wss",
#[allow(deprecated)]
Wss(_) => "x-parity-wss",
Ip6zone(_) => "ip6zone",
Ipcidr(_) => "ipcidr",
Expand Down Expand Up @@ -761,6 +781,7 @@ impl fmt::Display for Protocol<'_> {
percent_encoding::percent_encode(s.as_bytes(), PATH_SEGMENT_ENCODE_SET);
write!(f, "/{encoded}")
}
#[allow(deprecated)]
Wss(s) if s != "/" => {
let encoded =
percent_encoding::percent_encode(s.as_bytes(), PATH_SEGMENT_ENCODE_SET);
Expand Down
7 changes: 5 additions & 2 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ impl Arbitrary for Proto {
28 => Proto(Utp),
29 => Proto(WebTransport),
30 => Proto(Ws("/".into())),
31 => Proto(Wss("/".into())),
31 => Proto(
#[allow(deprecated)]
Wss("/".into()),
),
32 => Proto(Ip6zone(Cow::Owned(SubString::arbitrary(g).0))),
33 => Proto(Ipcidr(Arbitrary::arbitrary(g))),
34 => {
Expand Down Expand Up @@ -367,7 +370,7 @@ fn construct_success() {
]);
ma_valid("/ip6/2001:8a0:7ac5:4201:3ac9:86ff:fe31:7095/tcp/8000/wss/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC",
"29200108A07AC542013AC986FFFE317095061F40DE03A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B",
vec![Ip6(addr6), Tcp(8000), Wss("/".into()), P2p(peer_id("QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"))]);
vec![Ip6(addr6), Tcp(8000), #[allow(deprecated)] Wss("/".into()), P2p(peer_id("QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"))]);
ma_valid("/ip4/127.0.0.1/tcp/9090/p2p-circuit/p2p/QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC",
"047F000001062382A202A503221220D52EBB89D85B02A284948203A62FF28389C57C9F42BEEC4EC20DB76A68911C0B",
vec![Ip4(local), Tcp(9090), P2pCircuit, P2p(peer_id("QmcgpsyWgH8Y8ajJz1Cu72KnS5uo2Aa2LpzU7kinSupNKC"))]);
Expand Down