1
2use std::{fmt, io};
3
4use crate::PeerId;
5
6#[derive(Debug)]
7pub enum Error {
8 PeerDisconnected(PeerId),
10 Shutdown,
12 Io(io::Error),
14 PeerUnreachable(io::Error),
16 PeerHandshakePending,
18}
19
20impl From<io::Error> for Error {
21 fn from(e: io::Error) -> Error {
22 Error::Io(e)
23 }
24}
25
26impl fmt::Display for Error {
27 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
28 match *self {
29 Error::PeerDisconnected(id) => write!(f, "peer disconnected: {}", id),
30 Error::Shutdown => write!(f, "P2P is already shut down"),
31 Error::Io(ref e) => write!(f, "I/O error: {}", e),
32 Error::PeerUnreachable(ref e) => write!(f, "can't reach the peer: {}", e),
33 Error::PeerHandshakePending => write!(f, "peer didn't finish the handshake yet"),
34 }
35 }
36}
37impl std::error::Error for Error {}
38