-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Honor --max-peers if --min-peers is not specified #8087
Changes from 4 commits
e8e259e
044b329
25af5b5
9d421ab
549b3c8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,12 +14,12 @@ | |
// You should have received a copy of the GNU General Public License | ||
// along with Parity. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
use std::cmp::{max, min}; | ||
use std::time::Duration; | ||
use std::io::Read; | ||
use std::net::SocketAddr; | ||
use std::path::{Path, PathBuf}; | ||
use std::collections::BTreeMap; | ||
use std::cmp::max; | ||
use std::str::FromStr; | ||
use cli::{Args, ArgsError}; | ||
use hash::keccak; | ||
|
@@ -55,6 +55,9 @@ use account::{AccountCmd, NewAccount, ListAccounts, ImportAccounts, ImportFromGe | |
use snapshot::{self, SnapshotCommand}; | ||
use network::{IpFilter}; | ||
|
||
const DEFAULT_MAX_PEERS: u16 = 50; | ||
const DEFAULT_MIN_PEERS: u16 = 25; | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub enum Cmd { | ||
Run(RunCmd), | ||
|
@@ -468,8 +471,9 @@ impl Configuration { | |
} | ||
|
||
fn max_peers(&self) -> u32 { | ||
let peers = self.args.arg_max_peers as u32; | ||
max(self.min_peers(), peers) | ||
self.args.arg_max_peers | ||
.or(max(self.args.arg_min_peers, Some(DEFAULT_MAX_PEERS))) | ||
.unwrap_or(DEFAULT_MAX_PEERS) as u32 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yepp, I'll buy that |
||
} | ||
|
||
fn ip_filter(&self) -> Result<IpFilter, String> { | ||
|
@@ -480,7 +484,9 @@ impl Configuration { | |
} | ||
|
||
fn min_peers(&self) -> u32 { | ||
self.args.arg_peers.unwrap_or(self.args.arg_min_peers) as u32 | ||
self.args.arg_min_peers | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above but with |
||
.or(min(self.args.arg_max_peers, Some(DEFAULT_MIN_PEERS))) | ||
.unwrap_or(DEFAULT_MIN_PEERS) as u32 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here! |
||
|
||
fn max_pending_peers(&self) -> u32 { | ||
|
@@ -1945,4 +1951,30 @@ mod tests { | |
assert_eq!(std.directories().cache, dir::helpers::replace_home_and_local(&base_path, &local_path, ::dir::CACHE_PATH)); | ||
assert_eq!(base.directories().cache, "/test/cache"); | ||
} | ||
|
||
#[test] | ||
fn should_respect_only_max_peers() { | ||
let args = vec!["parity", "--max-peers=5"]; | ||
let conf = Configuration::parse(&args, None).unwrap(); | ||
match conf.into_command().unwrap().cmd { | ||
Cmd::Run(c) => { | ||
assert!(c.net_conf.min_peers <= 5); | ||
assert_eq!(c.net_conf.max_peers, 5); | ||
}, | ||
_ => panic!("Should be Cmd::Run"), | ||
} | ||
} | ||
|
||
#[test] | ||
fn should_respect_only_min_peers() { | ||
let args = vec!["parity", "--min-peers=500"]; | ||
let conf = Configuration::parse(&args, None).unwrap(); | ||
match conf.into_command().unwrap().cmd { | ||
Cmd::Run(c) => { | ||
assert_eq!(c.net_conf.min_peers, 500); | ||
assert!(c.net_conf.max_peers >= 500); | ||
}, | ||
_ => panic!("Should be Cmd::Run"), | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will always return
T
as long at least one of the arguments isSome
but I keptunwrap_or
if somebody reacts if we useraw unwrapping