bitcoin_p2p/
error.rs

1
2use std::{fmt, io};
3
4use crate::PeerId;
5
6#[derive(Debug)]
7pub enum Error {
8	/// No peer with given ID known. He must have been disconnected.
9	PeerDisconnected(PeerId),
10	/// We have already shut down.
11	Shutdown,
12	/// An I/O error.
13	Io(io::Error),
14	/// Can't reach the peer.
15	PeerUnreachable(io::Error),
16	/// The handshake with the peer is not finished.
17	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