Network-specific nodes file (#2569)
* network-specific nodes.json * save nodes.json periodically * squash warnings
This commit is contained in:
parent
5e24a35272
commit
ea68546616
@ -31,7 +31,7 @@ use ethcore_rpc::NetworkSettings;
|
|||||||
use cache::CacheConfig;
|
use cache::CacheConfig;
|
||||||
use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, replace_home,
|
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, to_gas_limit};
|
geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address, to_gas_limit};
|
||||||
use params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras, SpecType};
|
use params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras};
|
||||||
use ethcore_logger::Config as LogConfig;
|
use ethcore_logger::Config as LogConfig;
|
||||||
use dir::Directories;
|
use dir::Directories;
|
||||||
use dapps::Configuration as DappsConfiguration;
|
use dapps::Configuration as DappsConfiguration;
|
||||||
@ -459,23 +459,12 @@ impl Configuration {
|
|||||||
ret.min_peers = self.min_peers();
|
ret.min_peers = self.min_peers();
|
||||||
let mut net_path = PathBuf::from(self.directories().db);
|
let mut net_path = PathBuf::from(self.directories().db);
|
||||||
net_path.push("network");
|
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.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.reserved_nodes = try!(self.init_reserved_nodes());
|
||||||
ret.allow_non_reserved = !self.args.flag_reserved_only;
|
ret.allow_non_reserved = !self.args.flag_reserved_only;
|
||||||
Ok(ret)
|
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> {
|
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());
|
let net_id = self.args.flag_network_id.as_ref().or(self.args.flag_networkid.as_ref());
|
||||||
match net_id {
|
match net_id {
|
||||||
|
@ -110,6 +110,13 @@ impl DatabaseDirectories {
|
|||||||
dir.push("snapshot");
|
dir.push("snapshot");
|
||||||
dir
|
dir
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the path for the network directory.
|
||||||
|
pub fn network_path(&self) -> PathBuf {
|
||||||
|
let mut dir = self.fork_path();
|
||||||
|
dir.push("network");
|
||||||
|
dir
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -179,7 +179,7 @@ pub fn default_network_config() -> ::ethsync::NetworkConfiguration {
|
|||||||
use ethsync::NetworkConfiguration;
|
use ethsync::NetworkConfiguration;
|
||||||
NetworkConfiguration {
|
NetworkConfiguration {
|
||||||
config_path: Some(replace_home("$HOME/.parity/network")),
|
config_path: Some(replace_home("$HOME/.parity/network")),
|
||||||
net_config_path: Some(replace_home("$HOME/.parity/network/1")),
|
net_config_path: None,
|
||||||
listen_address: Some("0.0.0.0:30303".into()),
|
listen_address: Some("0.0.0.0:30303".into()),
|
||||||
public_address: None,
|
public_address: None,
|
||||||
udp_port: None,
|
udp_port: None,
|
||||||
|
@ -27,7 +27,7 @@ use ethcore::service::ClientService;
|
|||||||
use ethcore::account_provider::AccountProvider;
|
use ethcore::account_provider::AccountProvider;
|
||||||
use ethcore::miner::{Miner, MinerService, ExternalMiner, MinerOptions};
|
use ethcore::miner::{Miner, MinerService, ExternalMiner, MinerOptions};
|
||||||
use ethcore::snapshot;
|
use ethcore::snapshot;
|
||||||
use ethsync::{SyncConfig, SyncProvider};
|
use ethsync::SyncConfig;
|
||||||
use informant::Informant;
|
use informant::Informant;
|
||||||
|
|
||||||
use rpc::{HttpServer, IpcServer, HttpConfiguration, IpcConfiguration};
|
use rpc::{HttpServer, IpcServer, HttpConfiguration, IpcConfiguration};
|
||||||
@ -201,6 +201,9 @@ pub fn execute(cmd: RunCmd) -> Result<(), String> {
|
|||||||
net_conf.boot_nodes = spec.nodes.clone();
|
net_conf.boot_nodes = spec.nodes.clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set network path.
|
||||||
|
net_conf.net_config_path = Some(db_dirs.network_path().to_string_lossy().into_owned());
|
||||||
|
|
||||||
// create supervisor
|
// create supervisor
|
||||||
let mut hypervisor = modules::hypervisor(&cmd.dirs.ipc_path());
|
let mut hypervisor = modules::hypervisor(&cmd.dirs.ipc_path());
|
||||||
|
|
||||||
@ -302,7 +305,7 @@ pub fn execute(cmd: RunCmd) -> Result<(), String> {
|
|||||||
let sync = sync_provider.clone();
|
let sync = sync_provider.clone();
|
||||||
let watcher = Arc::new(snapshot::Watcher::new(
|
let watcher = Arc::new(snapshot::Watcher::new(
|
||||||
service.client(),
|
service.client(),
|
||||||
move || sync.status().is_major_syncing(),
|
move || ::ethsync::SyncProvider::status(&*sync).is_major_syncing(),
|
||||||
service.io().channel(),
|
service.io().channel(),
|
||||||
SNAPSHOT_PERIOD,
|
SNAPSHOT_PERIOD,
|
||||||
SNAPSHOT_HISTORY,
|
SNAPSHOT_HISTORY,
|
||||||
|
@ -47,7 +47,24 @@ type Slab<T> = ::slab::Slab<T, usize>;
|
|||||||
const MAX_SESSIONS: usize = 1024 + MAX_HANDSHAKES;
|
const MAX_SESSIONS: usize = 1024 + MAX_HANDSHAKES;
|
||||||
const MAX_HANDSHAKES: usize = 80;
|
const MAX_HANDSHAKES: usize = 80;
|
||||||
const MAX_HANDSHAKES_PER_ROUND: usize = 32;
|
const MAX_HANDSHAKES_PER_ROUND: usize = 32;
|
||||||
|
|
||||||
|
// Tokens
|
||||||
|
const TCP_ACCEPT: usize = SYS_TIMER + 1;
|
||||||
|
const IDLE: usize = SYS_TIMER + 2;
|
||||||
|
const DISCOVERY: usize = SYS_TIMER + 3;
|
||||||
|
const DISCOVERY_REFRESH: usize = SYS_TIMER + 4;
|
||||||
|
const DISCOVERY_ROUND: usize = SYS_TIMER + 5;
|
||||||
|
const NODE_TABLE: usize = SYS_TIMER + 6;
|
||||||
|
const FIRST_SESSION: usize = 0;
|
||||||
|
const LAST_SESSION: usize = FIRST_SESSION + MAX_SESSIONS - 1;
|
||||||
|
const USER_TIMER: usize = LAST_SESSION + 256;
|
||||||
|
const SYS_TIMER: usize = LAST_SESSION + 1;
|
||||||
|
|
||||||
|
// Timeouts
|
||||||
const MAINTENANCE_TIMEOUT: u64 = 1000;
|
const MAINTENANCE_TIMEOUT: u64 = 1000;
|
||||||
|
const DISCOVERY_REFRESH_TIMEOUT: u64 = 7200;
|
||||||
|
const DISCOVERY_ROUND_TIMEOUT: u64 = 300;
|
||||||
|
const NODE_TABLE_TIMEOUT: u64 = 300_000;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
/// Network service configuration
|
/// Network service configuration
|
||||||
@ -122,18 +139,6 @@ impl NetworkConfiguration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tokens
|
|
||||||
const TCP_ACCEPT: usize = SYS_TIMER + 1;
|
|
||||||
const IDLE: usize = SYS_TIMER + 2;
|
|
||||||
const DISCOVERY: usize = SYS_TIMER + 3;
|
|
||||||
const DISCOVERY_REFRESH: usize = SYS_TIMER + 4;
|
|
||||||
const DISCOVERY_ROUND: usize = SYS_TIMER + 5;
|
|
||||||
const NODE_TABLE: usize = SYS_TIMER + 6;
|
|
||||||
const FIRST_SESSION: usize = 0;
|
|
||||||
const LAST_SESSION: usize = FIRST_SESSION + MAX_SESSIONS - 1;
|
|
||||||
const USER_TIMER: usize = LAST_SESSION + 256;
|
|
||||||
const SYS_TIMER: usize = LAST_SESSION + 1;
|
|
||||||
|
|
||||||
/// Protocol handler level packet id
|
/// Protocol handler level packet id
|
||||||
pub type PacketId = u8;
|
pub type PacketId = u8;
|
||||||
/// Protocol / handler id
|
/// Protocol / handler id
|
||||||
@ -564,11 +569,11 @@ impl Host {
|
|||||||
discovery.init_node_list(self.nodes.read().unordered_entries());
|
discovery.init_node_list(self.nodes.read().unordered_entries());
|
||||||
discovery.add_node_list(self.nodes.read().unordered_entries());
|
discovery.add_node_list(self.nodes.read().unordered_entries());
|
||||||
*self.discovery.lock() = Some(discovery);
|
*self.discovery.lock() = Some(discovery);
|
||||||
io.register_stream(DISCOVERY).expect("Error registering UDP listener");
|
try!(io.register_stream(DISCOVERY));
|
||||||
io.register_timer(DISCOVERY_REFRESH, 7200).expect("Error registering discovery timer");
|
try!(io.register_timer(DISCOVERY_REFRESH, DISCOVERY_REFRESH_TIMEOUT));
|
||||||
io.register_timer(DISCOVERY_ROUND, 300).expect("Error registering discovery timer");
|
try!(io.register_timer(DISCOVERY_ROUND, DISCOVERY_ROUND_TIMEOUT));
|
||||||
}
|
}
|
||||||
try!(io.register_timer(NODE_TABLE, 300_000));
|
try!(io.register_timer(NODE_TABLE, NODE_TABLE_TIMEOUT));
|
||||||
try!(io.register_stream(TCP_ACCEPT));
|
try!(io.register_stream(TCP_ACCEPT));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -982,6 +987,7 @@ impl IoHandler<NetworkIoMessage> for Host {
|
|||||||
NODE_TABLE => {
|
NODE_TABLE => {
|
||||||
trace!(target: "network", "Refreshing node table");
|
trace!(target: "network", "Refreshing node table");
|
||||||
self.nodes.write().clear_useless();
|
self.nodes.write().clear_useless();
|
||||||
|
self.nodes.write().save();
|
||||||
},
|
},
|
||||||
_ => match self.timers.read().get(&token).cloned() {
|
_ => match self.timers.read().get(&token).cloned() {
|
||||||
Some(timer) => match self.handlers.read().get(&timer.protocol).cloned() {
|
Some(timer) => match self.handlers.read().get(&timer.protocol).cloned() {
|
||||||
|
@ -266,7 +266,8 @@ impl NodeTable {
|
|||||||
self.useless_nodes.clear();
|
self.useless_nodes.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save(&self) {
|
/// Save the nodes.json file.
|
||||||
|
pub fn save(&self) {
|
||||||
if let Some(ref path) = self.path {
|
if let Some(ref path) = self.path {
|
||||||
let mut path_buf = PathBuf::from(path);
|
let mut path_buf = PathBuf::from(path);
|
||||||
if let Err(e) = fs::create_dir_all(path_buf.as_path()) {
|
if let Err(e) = fs::create_dir_all(path_buf.as_path()) {
|
||||||
@ -292,7 +293,7 @@ impl NodeTable {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Err(e) = file.write(&json.into_bytes()) {
|
if let Err(e) = file.write(&json.into_bytes()) {
|
||||||
warn!("Error writing node table file: {:?}", e);
|
warn!("Error writing node table file: {:?}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user