1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
use std::{error, io, net::SocketAddr, result, sync::Arc};
use casper_types::SecretKey;
use datasize::DataSize;
use openssl::{error::ErrorStack, ssl};
use serde::Serialize;
use thiserror::Error;
use crate::{
crypto,
tls::ValidationError,
utils::{LoadError, Loadable, ResolveAddressError},
};
pub(super) type Result<T> = result::Result<T, Error>;
#[derive(Debug, Error, Serialize)]
pub enum Error {
#[error("could not resolve at least one known host (or none provided)")]
EmptyKnownHosts,
#[error("consensus keys provided, but could not be loaded")]
LoadConsensusKeys(
#[serde(skip_serializing)]
#[source]
LoadError<<Arc<SecretKey> as Loadable>::Error>,
),
#[error("own certificate invalid")]
OwnCertificateInvalid(#[source] ValidationError),
#[error("failed to create listener on {1}")]
ListenerCreation(
#[serde(skip_serializing)]
#[source]
io::Error,
SocketAddr,
),
#[error("failed to get listener addr")]
ListenerAddr(
#[serde(skip_serializing)]
#[source]
io::Error,
),
#[error("failed to set listener to non-blocking")]
ListenerSetNonBlocking(
#[serde(skip_serializing)]
#[source]
io::Error,
),
#[error("failed to convert listener to tokio")]
ListenerConversion(
#[serde(skip_serializing)]
#[source]
io::Error,
),
#[error("failed to resolve network address")]
ResolveAddr(
#[serde(skip_serializing)]
#[source]
ResolveAddressError,
),
#[error(transparent)]
MetricsError(
#[serde(skip_serializing)]
#[from]
prometheus::Error,
),
}
impl DataSize for Error {
const IS_DYNAMIC: bool = false;
const STATIC_HEAP_SIZE: usize = 0;
fn estimate_heap_size(&self) -> usize {
0
}
}
impl DataSize for ConnectionError {
const IS_DYNAMIC: bool = false;
const STATIC_HEAP_SIZE: usize = 0;
fn estimate_heap_size(&self) -> usize {
0
}
}
#[derive(Debug, Error, Serialize)]
pub enum ConnectionError {
#[error("failed to create TLS acceptor/connector")]
TlsInitialization(
#[serde(skip_serializing)]
#[source]
ErrorStack,
),
#[error("TCP connection failed")]
TcpConnection(
#[serde(skip_serializing)]
#[source]
io::Error,
),
#[error("TLS handshake error")]
TlsHandshake(
#[serde(skip_serializing)]
#[source]
ssl::Error,
),
#[error("no client certificate presented")]
NoPeerCertificate,
#[error("TLS validation error of peer certificate")]
PeerCertificateInvalid(#[source] ValidationError),
#[error("handshake send failed")]
HandshakeSend(
#[serde(skip_serializing)]
#[source]
IoError<io::Error>,
),
#[error("handshake receive failed")]
HandshakeRecv(
#[serde(skip_serializing)]
#[source]
IoError<io::Error>,
),
#[error("peer is on different network: {0}")]
WrongNetwork(String),
#[error("peer did not send handshake")]
DidNotSendHandshake,
#[error("invalid consensus certificate")]
InvalidConsensusCertificate(
#[serde(skip_serializing)]
#[source]
crypto::Error,
),
}
#[derive(Debug, Error)]
pub enum IoError<E>
where
E: error::Error + 'static,
{
#[error("io timeout")]
Timeout,
#[error(transparent)]
Error(#[from] E),
#[error("closed unexpectedly")]
UnexpectedEof,
}