1use p2p::{
3 SessionId,
4 error::{
5 DialerErrorKind, ListenErrorKind, ProtocolHandleErrorKind, SendErrorKind,
6 TransportErrorKind,
7 },
8 secio::PeerId,
9};
10use std::fmt;
11use std::fmt::Display;
12use std::io::Error as IoError;
13
14pub type Result<T> = ::std::result::Result<T, Error>;
16
17#[derive(Debug)]
19pub enum Error {
20 Peer(PeerError),
22 Io(IoError),
24 P2P(P2PError),
26 Dial(String),
28 PeerStore(PeerStoreError),
30 Config(String),
32}
33
34#[derive(Debug)]
36pub enum P2PError {
37 Transport(TransportErrorKind),
39 Protocol(ProtocolHandleErrorKind),
41 Dail(DialerErrorKind),
43 Listen(ListenErrorKind),
45 Send(SendErrorKind),
47}
48
49#[derive(Debug)]
51pub enum PeerStoreError {
52 EvictionFailed,
54 Serde(serde_json::Error),
56}
57
58#[derive(Debug, Eq, PartialEq)]
60pub enum PeerError {
61 SessionExists(SessionId),
63 PeerIdExists(PeerId),
65 NonReserved,
67 Banned,
69 ReachMaxInboundLimit,
71 ReachMaxOutboundLimit,
73}
74
75impl From<PeerStoreError> for Error {
76 fn from(err: PeerStoreError) -> Error {
77 Error::PeerStore(err)
78 }
79}
80
81impl From<PeerError> for Error {
82 fn from(err: PeerError) -> Error {
83 Error::Peer(err)
84 }
85}
86
87impl From<IoError> for Error {
88 fn from(err: IoError) -> Error {
89 Error::Io(err)
90 }
91}
92
93impl From<P2PError> for Error {
94 fn from(err: P2PError) -> Error {
95 Error::P2P(err)
96 }
97}
98
99impl From<TransportErrorKind> for Error {
100 fn from(err: TransportErrorKind) -> Error {
101 Error::P2P(P2PError::Transport(err))
102 }
103}
104
105impl From<ProtocolHandleErrorKind> for Error {
106 fn from(err: ProtocolHandleErrorKind) -> Error {
107 Error::P2P(P2PError::Protocol(err))
108 }
109}
110
111impl From<DialerErrorKind> for Error {
112 fn from(err: DialerErrorKind) -> Error {
113 Error::P2P(P2PError::Dail(err))
114 }
115}
116
117impl From<ListenErrorKind> for Error {
118 fn from(err: ListenErrorKind) -> Error {
119 Error::P2P(P2PError::Listen(err))
120 }
121}
122
123impl From<SendErrorKind> for Error {
124 fn from(err: SendErrorKind) -> Error {
125 Error::P2P(P2PError::Send(err))
126 }
127}
128
129impl Display for Error {
130 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
131 write!(f, "{self:?}")
132 }
133}
134
135impl Display for PeerError {
136 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
137 write!(f, "{self:?}")
138 }
139}
140
141impl Display for P2PError {
142 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
143 write!(f, "{self:?}")
144 }
145}