use std::{fmt, io};
use crate::{transport::TransportError, Multiaddr, PeerId};
#[derive(Debug)]
pub enum ConnectionError {
IO(io::Error),
KeepAliveTimeout,
}
impl fmt::Display for ConnectionError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ConnectionError::IO(err) => write!(f, "Connection error: I/O error: {err}"),
ConnectionError::KeepAliveTimeout => {
write!(f, "Connection closed due to expired keep-alive timeout.")
}
}
}
}
impl std::error::Error for ConnectionError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
ConnectionError::IO(err) => Some(err),
ConnectionError::KeepAliveTimeout => None,
}
}
}
impl From<io::Error> for ConnectionError {
fn from(error: io::Error) -> Self {
ConnectionError::IO(error)
}
}
#[derive(Debug)]
pub(crate) enum PendingOutboundConnectionError {
Transport(Vec<(Multiaddr, TransportError<io::Error>)>),
Aborted,
WrongPeerId {
obtained: PeerId,
address: Multiaddr,
},
LocalPeerId { address: Multiaddr },
}
#[derive(Debug)]
pub(crate) enum PendingInboundConnectionError {
Transport(TransportError<io::Error>),
Aborted,
LocalPeerId { address: Multiaddr },
}