snarkos_errors/network/protocol/ping_protocol.rs
1// Copyright (C) 2019-2020 Aleo Systems Inc.
2// This file is part of the snarkOS library.
3
4// The snarkOS library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The snarkOS library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the snarkOS library. If not, see <https://www.gnu.org/licenses/>.
16
17use crate::network::{ConnectError, SendError};
18
19use std::net::SocketAddr;
20
21#[derive(Debug, Error)]
22pub enum PingProtocolError {
23 #[error("{}: {}", _0, _1)]
24 Crate(&'static str, String),
25
26 #[error("{}", _0)]
27 Message(String),
28
29 #[error("{}", _0)]
30 ConnectError(ConnectError),
31
32 #[error("Expected nonce: {}, got {}", _0, _1)]
33 InvalidNonce(u64, u64),
34
35 #[error("No stored ping for peer {:?}", _0)]
36 PingProtocolMissing(SocketAddr),
37
38 #[error("{}", _0)]
39 SendError(SendError),
40}
41
42impl From<ConnectError> for PingProtocolError {
43 fn from(error: ConnectError) -> Self {
44 PingProtocolError::ConnectError(error)
45 }
46}
47
48impl From<SendError> for PingProtocolError {
49 fn from(error: SendError) -> Self {
50 PingProtocolError::SendError(error)
51 }
52}