From 9d421abb2450b1295083ca33fe33c5482e31be82 Mon Sep 17 00:00:00 2001 From: niklasad1 Date: Tue, 27 Mar 2018 14:09:37 +0200 Subject: [PATCH] address review comments --- parity/cli/usage.rs | 10 +++++----- parity/configuration.rs | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/parity/cli/usage.rs b/parity/cli/usage.rs index 1ea4973609c..2bdeaaed1a5 100644 --- a/parity/cli/usage.rs +++ b/parity/cli/usage.rs @@ -317,16 +317,16 @@ macro_rules! usage { pub fn parse>(command: &[S]) -> Result { let raw_args = RawArgs::parse(command)?; - // Invalid configuration pattern `mix_peers` > `max_peers` if let (Some(max_peers), Some(min_peers)) = (raw_args.arg_max_peers, raw_args.arg_min_peers) { + // Invalid configuration pattern `mix_peers` > `max_peers` if min_peers > max_peers { - return Err(ArgsError::PeerConfiguration) + return Err(ArgsError::PeerConfiguration); } - } + } // Skip loading config file if no_config flag is specified - else if raw_args.flag_no_config { - return Ok(raw_args.into_args(Config::default())) + if raw_args.flag_no_config { + return Ok(raw_args.into_args(Config::default())); } let config_file = raw_args.arg_config.clone().unwrap_or_else(|| raw_args.clone().into_args(Config::default()).arg_config); diff --git a/parity/configuration.rs b/parity/configuration.rs index b6fd17484ca..e8dd4568baa 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +use std::cmp::{max, min}; use std::time::Duration; use std::io::Read; use std::net::SocketAddr; @@ -471,7 +472,7 @@ impl Configuration { fn max_peers(&self) -> u32 { self.args.arg_max_peers - .or(self.args.arg_min_peers) + .or(max(self.args.arg_min_peers, Some(DEFAULT_MAX_PEERS))) .unwrap_or(DEFAULT_MAX_PEERS) as u32 } @@ -484,7 +485,7 @@ impl Configuration { fn min_peers(&self) -> u32 { self.args.arg_min_peers - .or(self.args.arg_max_peers) + .or(min(self.args.arg_max_peers, Some(DEFAULT_MIN_PEERS))) .unwrap_or(DEFAULT_MIN_PEERS) as u32 }