protocols/gossipsub: Make use of prost-codec (#3070)

This commit is contained in:
Nick Loadholtes
2022-11-04 06:12:08 -04:00
committed by GitHub
parent b528d336cd
commit 1ba9e4579d
4 changed files with 31 additions and 50 deletions

View File

@ -22,7 +22,7 @@
use libp2p_core::identity::error::SigningError;
use libp2p_core::upgrade::ProtocolError;
use std::fmt;
use thiserror::Error;
/// Error associated with publishing a gossipsub message.
#[derive(Debug)]
@ -87,20 +87,20 @@ impl From<SigningError> for PublishError {
}
/// Errors that can occur in the protocols handler.
#[derive(Debug)]
#[derive(Debug, Error)]
pub enum GossipsubHandlerError {
/// The maximum number of inbound substreams created has been exceeded.
#[error("The maximum number of inbound substreams created has been exceeded.")]
MaxInboundSubstreams,
/// The maximum number of outbound substreams created has been exceeded.
#[error("The maximum number of outbound substreams created has been exceeded.")]
MaxOutboundSubstreams,
/// The message exceeds the maximum transmission size.
#[error("The message exceeds the maximum transmission size.")]
MaxTransmissionSize,
/// Protocol negotiation timeout.
#[error("Protocol negotiation timeout.")]
NegotiationTimeout,
/// Protocol negotiation failed.
#[error("Protocol negotiation failed.")]
NegotiationProtocolError(ProtocolError),
/// IO error.
Io(std::io::Error),
#[error("Failed to encode or decode")]
Codec(#[from] prost_codec::Error),
}
#[derive(Debug, Clone, Copy)]
@ -136,7 +136,7 @@ impl std::error::Error for ValidationError {}
impl From<std::io::Error> for GossipsubHandlerError {
fn from(error: std::io::Error) -> GossipsubHandlerError {
GossipsubHandlerError::Io(error)
GossipsubHandlerError::Codec(prost_codec::Error::from(error))
}
}
@ -145,18 +145,3 @@ impl From<std::io::Error> for PublishError {
PublishError::TransformFailed(error)
}
}
impl fmt::Display for GossipsubHandlerError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}
impl std::error::Error for GossipsubHandlerError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
GossipsubHandlerError::Io(io) => Some(io),
_ => None,
}
}
}