Merge pull request #189 from ethcore/regtest_user_agent

do not wait idiotic 30 seconds when running regtests
This commit is contained in:
Svyatoslav Nikolsky 2016-11-25 14:47:48 +03:00 committed by GitHub
commit 61ec18897d
3 changed files with 12 additions and 2 deletions

View File

@ -2,7 +2,7 @@ use std::net::SocketAddr;
use sync::create_sync_connection_factory;
use message::Services;
use util::{open_db, init_db, node_table_path};
use {config, p2p, PROTOCOL_VERSION, PROTOCOL_MINIMUM, USER_AGENT};
use {config, p2p, PROTOCOL_VERSION, PROTOCOL_MINIMUM};
pub fn start(cfg: config::Config) -> Result<(), String> {
let mut el = p2p::event_loop();
@ -22,7 +22,7 @@ pub fn start(cfg: config::Config) -> Result<(), String> {
magic: cfg.magic,
local_address: SocketAddr::new("127.0.0.1".parse().unwrap(), cfg.port),
services: Services::default().with_network(true),
user_agent: USER_AGENT.into(),
user_agent: cfg.user_agent,
start_height: 0,
relay: false,
},

View File

@ -1,6 +1,7 @@
use std::net;
use clap;
use message::Magic;
use {USER_AGENT, REGTEST_USER_AGENT};
pub struct Config {
pub magic: Magic,
@ -13,6 +14,7 @@ pub struct Config {
pub p2p_threads: usize,
pub db_cache: usize,
pub data_dir: Option<String>,
pub user_agent: String,
}
pub const DEFAULT_DB_CACHE: usize = 512;
@ -36,6 +38,12 @@ pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
Magic::Regtest => 1,
};
// to skip idiotic 30 seconds delay in test-scripts
let user_agent = match magic {
Magic::Testnet | Magic::Mainnet => USER_AGENT,
Magic::Regtest => REGTEST_USER_AGENT,
};
let port = match matches.value_of("port") {
Some(port) => try!(port.parse().map_err(|_| "Invalid port".to_owned())),
None => magic.port(),
@ -77,6 +85,7 @@ pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
p2p_threads: p2p_threads,
db_cache: db_cache,
data_dir: data_dir,
user_agent: user_agent.to_string(),
};
Ok(config)

View File

@ -26,6 +26,7 @@ pub const APP_INFO: AppInfo = AppInfo { name: "pbtc", author: "Parity" };
pub const PROTOCOL_VERSION: u32 = 70_014;
pub const PROTOCOL_MINIMUM: u32 = 70_001;
pub const USER_AGENT: &'static str = "pbtc";
pub const REGTEST_USER_AGENT: &'static str = "/Satoshi:0.12.1/";
fn main() {
env_logger::init().unwrap();