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

yamux: Switch to upstream implementation while keeping the controller API #320

Merged
merged 9 commits into from
Jan 29, 2025
31 changes: 28 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ x25519-dalek = "2.0.0"
x509-parser = "0.16.0"
yasna = "0.5.0"
zeroize = "1.8.1"
nohash-hasher = "0.2.0"
static_assertions = "1.1.0"
yamux = "0.13.4"

# Exposed dependencies. Breaking changes to these are breaking changes to us.
[dependencies.rustls]
Expand Down
72 changes: 71 additions & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub enum ParseError {
InvalidData,
}

#[derive(Debug, thiserror::Error, PartialEq)]
#[derive(Debug, thiserror::Error)]
pub enum SubstreamError {
#[error("Connection closed")]
ConnectionClosed,
Expand All @@ -202,6 +202,76 @@ pub enum SubstreamError {
NegotiationError(#[from] NegotiationError),
}

// Libp2p yamux does not implement PartialEq for ConnectionError.
impl PartialEq for SubstreamError {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::ConnectionClosed, Self::ConnectionClosed) => true,
(Self::ChannelClogged, Self::ChannelClogged) => true,
(Self::PeerDoesNotExist(lhs), Self::PeerDoesNotExist(rhs)) => lhs == rhs,
(Self::IoError(lhs), Self::IoError(rhs)) => lhs == rhs,
(Self::YamuxError(lhs, lhs_1), Self::YamuxError(rhs, rhs_1)) => {
if lhs_1 != rhs_1 {
return false;
}

match (lhs, rhs) {
(
crate::yamux::ConnectionError::Io(lhs),
crate::yamux::ConnectionError::Io(rhs),
) => lhs.kind() == rhs.kind(),
(
crate::yamux::ConnectionError::Decode(lhs),
crate::yamux::ConnectionError::Decode(rhs),
) => match (lhs, rhs) {
(
crate::yamux::FrameDecodeError::Io(lhs),
crate::yamux::FrameDecodeError::Io(rhs),
) => lhs.kind() == rhs.kind(),
(
crate::yamux::FrameDecodeError::FrameTooLarge(lhs),
crate::yamux::FrameDecodeError::FrameTooLarge(rhs),
) => lhs == rhs,
(
crate::yamux::FrameDecodeError::Header(lhs),
crate::yamux::FrameDecodeError::Header(rhs),
) => match (lhs, rhs) {
(
crate::yamux::HeaderDecodeError::Version(lhs),
crate::yamux::HeaderDecodeError::Version(rhs),
) => lhs == rhs,
(
crate::yamux::HeaderDecodeError::Type(lhs),
crate::yamux::HeaderDecodeError::Type(rhs),
) => lhs == rhs,
_ => false,
},
_ => false,
},
(
crate::yamux::ConnectionError::NoMoreStreamIds,
crate::yamux::ConnectionError::NoMoreStreamIds,
) => true,
(
crate::yamux::ConnectionError::Closed,
crate::yamux::ConnectionError::Closed,
) => true,
(
crate::yamux::ConnectionError::TooManyStreams,
crate::yamux::ConnectionError::TooManyStreams,
) => true,
_ => false,
}
}

(Self::ReadFailure(lhs), Self::ReadFailure(rhs)) => lhs == rhs,
(Self::WriteFailure(lhs), Self::WriteFailure(rhs)) => lhs == rhs,
(Self::NegotiationError(lhs), Self::NegotiationError(rhs)) => lhs == rhs,
_ => false,
}
}
}

/// Error during the negotiation phase.
#[derive(Debug, thiserror::Error)]
pub enum NegotiationError {
Expand Down
111 changes: 0 additions & 111 deletions src/yamux/chunks.rs

This file was deleted.

Loading
Loading