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

Return unknown short IDs when deserializing #93

Merged
merged 2 commits into from
Nov 13, 2024
Merged
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
4 changes: 2 additions & 2 deletions protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1291,7 +1291,7 @@ impl AsyncProtocolReader {

/// Consume the protocol reader in exchange for the underlying packet decoder.
pub fn decoder(self) -> PacketReader {
return self.packet_reader;
self.packet_reader
}
}

Expand Down Expand Up @@ -1332,7 +1332,7 @@ impl AsyncProtocolWriter {

/// Consume the protocol writer in exchange for the underlying packet encoder.
pub fn encoder(self) -> PacketWriter {
return self.packet_writer;
self.packet_writer
}
}

Expand Down
5 changes: 4 additions & 1 deletion protocol/src/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ pub use bitcoin::p2p::message::{CommandString, NetworkMessage};
pub enum Error {
Serialize,
Deserialize,
UnknownShortID(u8),
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Serialize => write!(f, "Unable to serialize"),
Error::Deserialize => write!(f, "Unable to deserialize"),
Error::UnknownShortID(b) => write!(f, "Unrecognized short ID when deserializing {b}"),
}
}
}
Expand All @@ -36,6 +38,7 @@ impl std::error::Error for Error {
match self {
Error::Serialize => None,
Error::Deserialize => None,
Error::UnknownShortID(_) => None,
}
}
}
Expand Down Expand Up @@ -283,7 +286,7 @@ pub fn deserialize(buffer: &[u8]) -> Result<NetworkMessage, Error> {
)),

// Unsupported short ID.
_ => Err(Error::Deserialize),
unknown => Err(Error::UnknownShortID(unknown)),
}
}

Expand Down
Loading