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}
31
32#[derive(Debug)]
34pub enum P2PError {
35 Transport(TransportErrorKind),
37 Protocol(ProtocolHandleErrorKind),
39 Dail(DialerErrorKind),
41 Listen(ListenErrorKind),
43 Send(SendErrorKind),
45}
46
47#[derive(Debug)]
49pub enum PeerStoreError {
50 EvictionFailed,
52 Serde(serde_json::Error),
54}
55
56#[derive(Debug, Eq, PartialEq)]
58pub enum PeerError {
59 SessionExists(SessionId),
61 PeerIdExists(PeerId),
63 NonReserved,
65 Banned,
67 ReachMaxInboundLimit,
69 ReachMaxOutboundLimit,
71}
72
73impl From<PeerStoreError> for Error {
74 fn from(err: PeerStoreError) -> Error {
75 Error::PeerStore(err)
76 }
77}
78
79impl From<PeerError> for Error {
80 fn from(err: PeerError) -> Error {
81 Error::Peer(err)
82 }
83}
84
85impl From<IoError> for Error {
86 fn from(err: IoError) -> Error {
87 Error::Io(err)
88 }
89}
90
91impl From<P2PError> for Error {
92 fn from(err: P2PError) -> Error {
93 Error::P2P(err)
94 }
95}
96
97impl From<TransportErrorKind> for Error {
98 fn from(err: TransportErrorKind) -> Error {
99 Error::P2P(P2PError::Transport(err))
100 }
101}
102
103impl From<ProtocolHandleErrorKind> for Error {
104 fn from(err: ProtocolHandleErrorKind) -> Error {
105 Error::P2P(P2PError::Protocol(err))
106 }
107}
108
109impl From<DialerErrorKind> for Error {
110 fn from(err: DialerErrorKind) -> Error {
111 Error::P2P(P2PError::Dail(err))
112 }
113}
114
115impl From<ListenErrorKind> for Error {
116 fn from(err: ListenErrorKind) -> Error {
117 Error::P2P(P2PError::Listen(err))
118 }
119}
120
121impl From<SendErrorKind> for Error {
122 fn from(err: SendErrorKind) -> Error {
123 Error::P2P(P2PError::Send(err))
124 }
125}
126
127impl Display for Error {
128 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
129 write!(f, "{self:?}")
130 }
131}
132
133impl Display for PeerError {
134 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
135 write!(f, "{self:?}")
136 }
137}
138
139impl Display for P2PError {
140 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
141 write!(f, "{self:?}")
142 }
143}