Extended network options (#2845)

* More network configuration options

* Filter UDP requests

* Fixed tests

* Fixed test warning
This commit is contained in:
Arkadiy Paronyan
2016-10-24 18:25:27 +02:00
committed by Gav Wood
parent 7f210b05bb
commit 1a5bae8ef1
14 changed files with 204 additions and 46 deletions

View File

@@ -29,6 +29,9 @@ id = "0x1"
bootnodes = []
discovery = true
warp = true
allow_ips = "all"
snapshot_peers = 0
max_pending_peers = 64
reserved_only = false
reserved_peers = "./path_to_file"

View File

@@ -18,6 +18,9 @@ discovery = true
nat = "any"
min_peers = 10
max_peers = 20
max_pending_peers = 30
snapshot_peers = 40
allow_ips = "public"
reserved_only = true
reserved_peers = "./path/to/reserved_peers"

View File

@@ -114,8 +114,14 @@ usage! {
or |c: &Config| otry!(c.network).min_peers.clone(),
flag_max_peers: u16 = 50u16,
or |c: &Config| otry!(c.network).max_peers.clone(),
flag_max_pending_peers: u16 = 64u16,
or |c: &Config| otry!(c.network).max_pending_peers.clone(),
flag_snapshot_peers: u16 = 0u16,
or |c: &Config| otry!(c.network).snapshot_peers.clone(),
flag_nat: String = "any",
or |c: &Config| otry!(c.network).nat.clone(),
flag_allow_ips: String = "all",
or |c: &Config| otry!(c.network).allow_ips.clone(),
flag_network_id: Option<String> = None,
or |c: &Config| otry!(c.network).id.clone().map(Some),
flag_bootnodes: Option<String> = None,
@@ -307,7 +313,10 @@ struct Network {
port: Option<u16>,
min_peers: Option<u16>,
max_peers: Option<u16>,
snapshot_peers: Option<u16>,
max_pending_peers: Option<u16>,
nat: Option<String>,
allow_ips: Option<String>,
id: Option<String>,
bootnodes: Option<Vec<String>>,
discovery: Option<bool>,
@@ -494,6 +503,9 @@ mod tests {
flag_port: 30303u16,
flag_min_peers: 25u16,
flag_max_peers: 50u16,
flag_max_pending_peers: 64u16,
flag_snapshot_peers: 0u16,
flag_allow_ips: "all".into(),
flag_nat: "any".into(),
flag_network_id: Some("0x1".into()),
flag_bootnodes: Some("".into()),
@@ -653,6 +665,9 @@ mod tests {
port: None,
min_peers: Some(10),
max_peers: Some(20),
max_pending_peers: Some(30),
snapshot_peers: Some(40),
allow_ips: Some("public".into()),
nat: Some("any".into()),
id: None,
bootnodes: None,

View File

@@ -71,7 +71,9 @@ Networking Options:
--port PORT Override the port on which the node should listen
(default: {flag_port}).
--min-peers NUM Try to maintain at least NUM peers (default: {flag_min_peers}).
--max-peers NUM Allow up to that many peers (default: {flag_max_peers}).
--max-peers NUM Allow up to NUM peers (default: {flag_max_peers}).
--snapshot-peers NUM Allow additional NUM peers for a snapshot sync
(default: {flag_snapshot_peers}).
--nat METHOD Specify method to use for determining public
address. Must be one of: any, none, upnp,
extip:<IP> (default: {flag_nat}).
@@ -86,6 +88,12 @@ Networking Options:
These nodes will always have a reserved slot on top
of the normal maximum peers. (default: {flag_reserved_peers:?})
--reserved-only Connect only to reserved nodes. (default: {flag_reserved_only})
--allow-ips FILTER Filter outbound connections. Must be one of:
private - connect to private network IP addresses only;
public - connect to public network IP addresses only;
all - connect to any IP address.
(default: {flag_allow_ips})
--max-pending-peers NUM Allow up to NUM pending connections. (default: {flag_max_pending_peers})
API and Console Options:
--no-jsonrpc Disable the JSON-RPC API server. (default: {flag_no_jsonrpc})

View File

@@ -22,7 +22,7 @@ use std::cmp::max;
use cli::{Args, ArgsError};
use util::{Hashable, U256, Uint, Bytes, version_data, Secret, Address};
use util::log::Colour;
use ethsync::{NetworkConfiguration, is_valid_node_url};
use ethsync::{NetworkConfiguration, is_valid_node_url, AllowIP};
use ethcore::client::{VMType, Mode};
use ethcore::miner::MinerOptions;
@@ -332,10 +332,27 @@ impl Configuration {
max(self.min_peers(), peers)
}
fn allow_ips(&self) -> Result<AllowIP, String> {
match self.args.flag_allow_ips.as_str() {
"all" => Ok(AllowIP::All),
"public" => Ok(AllowIP::Public),
"private" => Ok(AllowIP::Private),
_ => Err("Invalid IP filter value".to_owned()),
}
}
fn min_peers(&self) -> u32 {
self.args.flag_peers.unwrap_or(self.args.flag_min_peers) as u32
}
fn max_pending_peers(&self) -> u32 {
self.args.flag_max_pending_peers as u32
}
fn snapshot_peers(&self) -> u32 {
self.args.flag_snapshot_peers as u32
}
fn work_notify(&self) -> Vec<String> {
self.args.flag_notify_work.as_ref().map_or_else(Vec::new, |s| s.split(',').map(|s| s.to_owned()).collect())
}
@@ -474,6 +491,9 @@ impl Configuration {
ret.discovery_enabled = !self.args.flag_no_discovery && !self.args.flag_nodiscover;
ret.max_peers = self.max_peers();
ret.min_peers = self.min_peers();
ret.snapshot_peers = self.snapshot_peers();
ret.allow_ips = try!(self.allow_ips());
ret.max_pending_peers = self.max_pending_peers();
let mut net_path = PathBuf::from(self.directories().db);
net_path.push("network");
ret.config_path = Some(net_path.to_str().unwrap().to_owned());

View File

@@ -185,7 +185,7 @@ pub fn to_bootnodes(bootnodes: &Option<String>) -> Result<Vec<String>, String> {
#[cfg(test)]
pub fn default_network_config() -> ::ethsync::NetworkConfiguration {
use ethsync::NetworkConfiguration;
use ethsync::{NetworkConfiguration, AllowIP};
NetworkConfiguration {
config_path: Some(replace_home("$HOME/.parity/network")),
net_config_path: None,
@@ -198,6 +198,9 @@ pub fn default_network_config() -> ::ethsync::NetworkConfiguration {
use_secret: None,
max_peers: 50,
min_peers: 25,
snapshot_peers: 0,
max_pending_peers: 64,
allow_ips: AllowIP::All,
reserved_nodes: Vec::new(),
allow_non_reserved: true,
}