openethereum/util/src/network/error.rs

71 lines
1.6 KiB
Rust
Raw Normal View History

2016-02-05 13:40:41 +01:00
// Copyright 2015, 2016 Ethcore (UK) Ltd.
// This file is part of Parity.
// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
2016-01-15 16:36:08 +01:00
use io::IoError;
2016-02-12 09:52:32 +01:00
use crypto::CryptoError;
2016-01-15 16:36:08 +01:00
use rlp::*;
#[derive(Debug, Copy, Clone)]
pub enum DisconnectReason
{
DisconnectRequested,
2016-02-02 14:54:46 +01:00
_TCPError,
_BadProtocol,
2016-01-15 16:36:08 +01:00
UselessPeer,
2016-02-02 14:54:46 +01:00
_TooManyPeers,
_DuplicatePeer,
_IncompatibleProtocol,
_NullIdentity,
_ClientQuit,
_UnexpectedIdentity,
_LocalIdentity,
2016-02-02 20:58:12 +01:00
PingTimeout,
2016-01-15 16:36:08 +01:00
}
#[derive(Debug)]
/// Network error.
2016-01-15 16:36:08 +01:00
pub enum NetworkError {
/// Authentication error.
2016-01-15 16:36:08 +01:00
Auth,
/// Unrecognised protocol.
2016-01-15 16:36:08 +01:00
BadProtocol,
/// Peer not found.
2016-01-15 16:36:08 +01:00
PeerNotFound,
/// Peer is diconnected.
2016-01-15 16:36:08 +01:00
Disconnect(DisconnectReason),
/// Socket IO error.
2016-01-15 16:36:08 +01:00
Io(IoError),
}
impl From<DecoderError> for NetworkError {
fn from(_err: DecoderError) -> NetworkError {
NetworkError::Auth
}
}
impl From<IoError> for NetworkError {
fn from(err: IoError) -> NetworkError {
NetworkError::Io(err)
}
}
2016-02-12 09:52:32 +01:00
impl From<CryptoError> for NetworkError {
fn from(_err: CryptoError) -> NetworkError {
NetworkError::Auth
}
}