Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Create network-specific nodes files (#1970)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomusdrw authored and gavofyork committed Aug 21, 2016
1 parent fcfacc7 commit f69b3f8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
14 changes: 12 additions & 2 deletions parity/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use ethcore_rpc::NetworkSettings;
use cache::CacheConfig;
use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, replace_home,
geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address};
use params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras};
use params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras, SpecType};
use ethcore_logger::Config as LogConfig;
use dir::Directories;
use dapps::Configuration as DappsConfiguration;
Expand Down Expand Up @@ -440,13 +440,23 @@ impl Configuration {
ret.min_peers = self.min_peers();
let mut net_path = PathBuf::from(self.directories().db);
net_path.push("network");
let net_specific_path = net_path.join(&try!(self.network_specific_path()));
ret.config_path = Some(net_path.to_str().unwrap().to_owned());
ret.net_config_path = Some(net_specific_path.to_str().unwrap().to_owned());
ret.reserved_nodes = try!(self.init_reserved_nodes());

ret.allow_non_reserved = !self.args.flag_reserved_only;
Ok(ret)
}

fn network_specific_path(&self) -> Result<PathBuf, String> {
let spec_type : SpecType = try!(self.chain().parse());
let spec = try!(spec_type.spec());
let id = try!(self.network_id());
let mut path = PathBuf::new();
path.push(format!("{}", id.unwrap_or_else(|| spec.network_id())));
Ok(path)
}

fn network_id(&self) -> Result<Option<U256>, String> {
let net_id = self.args.flag_network_id.as_ref().or(self.args.flag_networkid.as_ref());
match net_id {
Expand Down
1 change: 1 addition & 0 deletions parity/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ pub fn default_network_config() -> ::ethsync::NetworkConfiguration {
use ethsync::NetworkConfiguration;
NetworkConfiguration {
config_path: Some(replace_home("$HOME/.parity/network")),
net_config_path: Some(replace_home("$HOME/.parity/network/1")),
listen_address: Some("0.0.0.0:30303".into()),
public_address: None,
udp_port: None,
Expand Down
6 changes: 5 additions & 1 deletion sync/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,10 @@ impl ManageNetwork for EthSync {
#[derive(Binary, Debug, Clone, PartialEq, Eq)]
/// Network service configuration
pub struct NetworkConfiguration {
/// Directory path to store network configuration. None means nothing will be saved
/// Directory path to store general network configuration. None means nothing will be saved
pub config_path: Option<String>,
/// Directory path to store network-specific configuration. None means nothing will be saved
pub net_config_path: Option<String>,
/// IP address to listen for incoming connections. Listen to all connections by default
pub listen_address: Option<String>,
/// IP address to advertise. Detected automatically if none.
Expand Down Expand Up @@ -264,6 +266,7 @@ impl NetworkConfiguration {

Ok(BasicNetworkConfiguration {
config_path: self.config_path,
net_config_path: self.net_config_path,
listen_address: match self.listen_address { None => None, Some(addr) => Some(try!(SocketAddr::from_str(&addr))) },
public_address: match self.public_address { None => None, Some(addr) => Some(try!(SocketAddr::from_str(&addr))) },
udp_port: self.udp_port,
Expand All @@ -283,6 +286,7 @@ impl From<BasicNetworkConfiguration> for NetworkConfiguration {
fn from(other: BasicNetworkConfiguration) -> Self {
NetworkConfiguration {
config_path: other.config_path,
net_config_path: other.net_config_path,
listen_address: other.listen_address.and_then(|addr| Some(format!("{}", addr))),
public_address: other.public_address.and_then(|addr| Some(format!("{}", addr))),
udp_port: other.udp_port,
Expand Down
7 changes: 5 additions & 2 deletions util/network/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ const MAINTENANCE_TIMEOUT: u64 = 1000;
#[derive(Debug, PartialEq, Clone)]
/// Network service configuration
pub struct NetworkConfiguration {
/// Directory path to store network configuration. None means nothing will be saved
/// Directory path to store general network configuration. None means nothing will be saved
pub config_path: Option<String>,
/// Directory path to store network-specific configuration. None means nothing will be saved
pub net_config_path: Option<String>,
/// IP address to listen for incoming connections. Listen to all connections by default
pub listen_address: Option<SocketAddr>,
/// IP address to advertise. Detected automatically if none.
Expand Down Expand Up @@ -90,6 +92,7 @@ impl NetworkConfiguration {
pub fn new() -> Self {
NetworkConfiguration {
config_path: None,
net_config_path: None,
listen_address: None,
public_address: None,
udp_port: None,
Expand Down Expand Up @@ -367,7 +370,7 @@ impl Host {
},
|s| KeyPair::from_secret(s).expect("Error creating node secret key"))
};
let path = config.config_path.clone();
let path = config.net_config_path.clone();
// Setup the server socket
let tcp_listener = try!(TcpListener::bind(&listen_address));
listen_address = SocketAddr::new(listen_address.ip(), try!(tcp_listener.local_addr()).port());
Expand Down

0 comments on commit f69b3f8

Please sign in to comment.