|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use libp2p_identity::SigningError; |
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
pub enum PublishError { |
|
|
|
|
|
Duplicate, |
|
|
|
|
|
SigningError(SigningError), |
|
|
|
|
|
InsufficientPeers, |
|
|
|
|
|
|
|
|
MessageTooLarge, |
|
|
|
|
|
TransformFailed(std::io::Error), |
|
|
} |
|
|
|
|
|
impl std::fmt::Display for PublishError { |
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
|
|
write!(f, "{self:?}") |
|
|
} |
|
|
} |
|
|
|
|
|
impl std::error::Error for PublishError { |
|
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
|
|
match self { |
|
|
Self::SigningError(err) => Some(err), |
|
|
Self::TransformFailed(err) => Some(err), |
|
|
_ => None, |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
pub enum SubscriptionError { |
|
|
|
|
|
PublishError(PublishError), |
|
|
|
|
|
NotAllowed, |
|
|
} |
|
|
|
|
|
impl std::fmt::Display for SubscriptionError { |
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
|
|
write!(f, "{self:?}") |
|
|
} |
|
|
} |
|
|
|
|
|
impl std::error::Error for SubscriptionError { |
|
|
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { |
|
|
match self { |
|
|
Self::PublishError(err) => Some(err), |
|
|
_ => None, |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
impl From<SigningError> for PublishError { |
|
|
fn from(error: SigningError) -> Self { |
|
|
PublishError::SigningError(error) |
|
|
} |
|
|
} |
|
|
|
|
|
#[derive(Debug, Clone, Copy)] |
|
|
pub enum ValidationError { |
|
|
|
|
|
InvalidSignature, |
|
|
|
|
|
EmptySequenceNumber, |
|
|
|
|
|
InvalidSequenceNumber, |
|
|
|
|
|
InvalidPeerId, |
|
|
|
|
|
|
|
|
SignaturePresent, |
|
|
|
|
|
|
|
|
SequenceNumberPresent, |
|
|
|
|
|
|
|
|
MessageSourcePresent, |
|
|
|
|
|
TransformFailed, |
|
|
} |
|
|
|
|
|
impl std::fmt::Display for ValidationError { |
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
|
|
write!(f, "{self:?}") |
|
|
} |
|
|
} |
|
|
|
|
|
impl std::error::Error for ValidationError {} |
|
|
|
|
|
impl From<std::io::Error> for PublishError { |
|
|
fn from(error: std::io::Error) -> PublishError { |
|
|
PublishError::TransformFailed(error) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
pub enum ConfigBuilderError { |
|
|
|
|
|
MaxTransmissionSizeTooSmall, |
|
|
|
|
|
HistoryLengthTooSmall, |
|
|
|
|
|
MeshParametersInvalid, |
|
|
|
|
|
MeshOutboundInvalid, |
|
|
|
|
|
UnsubscribeBackoffIsZero, |
|
|
|
|
|
InvalidProtocol, |
|
|
} |
|
|
|
|
|
impl std::error::Error for ConfigBuilderError {} |
|
|
|
|
|
impl std::fmt::Display for ConfigBuilderError { |
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { |
|
|
match self { |
|
|
Self::MaxTransmissionSizeTooSmall => { |
|
|
write!(f, "Maximum transmission size is too small") |
|
|
} |
|
|
Self::HistoryLengthTooSmall => write!(f, "History length less than history gossip length"), |
|
|
Self::MeshParametersInvalid => write!(f, "The ineauality doesn't hold mesh_outbound_min <= mesh_n_low <= mesh_n <= mesh_n_high"), |
|
|
Self::MeshOutboundInvalid => write!(f, "The inequality doesn't hold mesh_outbound_min <= self.config.mesh_n / 2"), |
|
|
Self::UnsubscribeBackoffIsZero => write!(f, "unsubscribe_backoff is zero"), |
|
|
Self::InvalidProtocol => write!(f, "Invalid protocol"), |
|
|
} |
|
|
} |
|
|
} |
|
|
|