From c623e5f232c16cc6bc9d99f1bae92253ef441ae9 Mon Sep 17 00:00:00 2001 From: debris Date: Tue, 5 Sep 2017 11:14:28 +0200 Subject: [PATCH] ethcore-network does not use UtilError --- util/network/src/error.rs | 13 +++---------- util/network/src/node_table.rs | 5 ++--- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/util/network/src/error.rs b/util/network/src/error.rs index 11cf8fdf0..54773d573 100644 --- a/util/network/src/error.rs +++ b/util/network/src/error.rs @@ -16,7 +16,6 @@ use io::IoError; use rlp::*; -use util::UtilError; use std::fmt; use ethkey::Error as KeyError; use crypto::Error as CryptoError; @@ -96,8 +95,8 @@ pub enum NetworkError { PeerNotFound, /// Peer is diconnected. Disconnect(DisconnectReason), - /// Util error. - Util(UtilError), + /// Invalid NodeId + InvalidNodeId, /// Socket IO error. Io(IoError), /// Error concerning the network address parsing subsystem. @@ -125,7 +124,7 @@ impl fmt::Display for NetworkError { AddressResolve(Some(ref err)) => format!("{}", err), AddressResolve(_) => "Failed to resolve network address.".into(), StdIo(ref err) => format!("{}", err), - Util(ref err) => format!("{}", err), + InvalidNodeId => "Invalid node id".into(), OversizedPacket => "Packet is too large".into(), }; @@ -151,12 +150,6 @@ impl From for NetworkError { } } -impl From for NetworkError { - fn from(err: UtilError) -> NetworkError { - NetworkError::Util(err) - } -} - impl From for NetworkError { fn from(_err: KeyError) -> Self { NetworkError::Auth diff --git a/util/network/src/node_table.rs b/util/network/src/node_table.rs index f9d4e9589..a98979b8d 100644 --- a/util/network/src/node_table.rs +++ b/util/network/src/node_table.rs @@ -26,7 +26,6 @@ use std::fmt; use std::fs; use std::io::{Read, Write}; use util::hash::*; -use util::UtilError; use rlp::*; use time::Tm; use error::NetworkError; @@ -58,7 +57,7 @@ impl NodeEndpoint { pub fn is_allowed(&self, filter: &IpFilter) -> bool { (self.is_allowed_by_predefined(&filter.predefined) || filter.custom_allow.iter().any(|ipnet| { self.address.ip().is_within(ipnet) - })) + })) && !filter.custom_block.iter().any(|ipnet| { self.address.ip().is_within(ipnet) }) @@ -175,7 +174,7 @@ impl FromStr for Node { type Err = NetworkError; fn from_str(s: &str) -> Result { let (id, endpoint) = if s.len() > 136 && &s[0..8] == "enode://" && &s[136..137] == "@" { - (s[8..136].parse().map_err(UtilError::from)?, NodeEndpoint::from_str(&s[137..])?) + (s[8..136].parse().map_err(|_| NetworkError::InvalidNodeId)?, NodeEndpoint::from_str(&s[137..])?) } else { (NodeId::new(), NodeEndpoint::from_str(s)?)