use tet_libp2p_core::identity::error::SigningError;
use tet_libp2p_core::upgrade::ProtocolError;
use std::fmt;
#[derive(Debug)]
pub enum PublishError {
Duplicate,
SigningError(SigningError),
InsufficientPeers,
MessageTooLarge,
TransformFailed(std::io::Error),
}
#[derive(Debug)]
pub enum SubscriptionError {
PublishError(PublishError),
NotAllowed,
}
impl From<SigningError> for PublishError {
fn from(error: SigningError) -> Self {
PublishError::SigningError(error)
}
}
#[derive(Debug)]
pub enum GossipsubHandlerError {
MaxInboundSubstreams,
MaxOutboundSubstreams,
MaxTransmissionSize,
NegotiationTimeout,
NegotiationProtocolError(ProtocolError),
Io(std::io::Error),
}
#[derive(Debug, Clone, Copy)]
pub enum ValidationError {
InvalidSignature,
EmptySequenceNumber,
InvalidSequenceNumber,
InvalidPeerId,
SignaturePresent,
SequenceNumberPresent,
MessageSourcePresent,
TransformFailed,
}
impl From<std::io::Error> for GossipsubHandlerError {
fn from(error: std::io::Error) -> GossipsubHandlerError {
GossipsubHandlerError::Io(error)
}
}
impl From<std::io::Error> for PublishError {
fn from(error: std::io::Error) -> 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,
}
}
}