limit number of inbound and outbound connections for regtests
This commit is contained in:
parent
e07dfbb6c1
commit
56e2dc02b1
|
@ -20,6 +20,6 @@ pub struct Config {
|
|||
pub peers: Vec<SocketAddr>,
|
||||
/// Connect to these nodes to retrieve peer addresses, and disconnect.
|
||||
pub seeds: Vec<String>,
|
||||
/// p2p module cache directory.
|
||||
/// p2p/nodes.csv file path
|
||||
pub node_table_path: PathBuf,
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use std::net::SocketAddr;
|
||||
use sync::create_sync_connection_factory;
|
||||
use message::{Services, Magic};
|
||||
use message::Services;
|
||||
use util::{open_db, init_db, node_table_path};
|
||||
use {config, p2p};
|
||||
|
||||
|
@ -10,17 +10,12 @@ pub fn start(cfg: config::Config) -> Result<(), String> {
|
|||
let db = open_db(&cfg);
|
||||
try!(init_db(&cfg, &db));
|
||||
|
||||
let p2p_threads = match cfg.magic {
|
||||
Magic::Regtest => 1,
|
||||
Magic::Testnet | Magic::Mainnet => 4,
|
||||
};
|
||||
|
||||
let p2p_cfg = p2p::Config {
|
||||
threads: p2p_threads,
|
||||
threads: cfg.p2p_threads,
|
||||
protocol_minimum: 70001,
|
||||
protocol_maximum: 70017,
|
||||
inbound_connections: 10,
|
||||
outbound_connections: 10,
|
||||
inbound_connections: cfg.inbound_connections,
|
||||
outbound_connections: cfg.outbound_connections,
|
||||
connection: p2p::NetConfig {
|
||||
magic: cfg.magic,
|
||||
local_address: SocketAddr::new("127.0.0.1".parse().unwrap(), cfg.port),
|
||||
|
|
|
@ -8,6 +8,9 @@ pub struct Config {
|
|||
pub connect: Option<net::SocketAddr>,
|
||||
pub seednode: Option<String>,
|
||||
pub print_to_console: bool,
|
||||
pub inbound_connections: u32,
|
||||
pub outbound_connections: u32,
|
||||
pub p2p_threads: usize,
|
||||
}
|
||||
|
||||
pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
|
||||
|
@ -19,6 +22,16 @@ pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
|
|||
(true, true) => return Err("Only one testnet option can be used".into()),
|
||||
};
|
||||
|
||||
let (in_connections, out_connections) = match magic {
|
||||
Magic::Testnet | Magic::Mainnet => (10, 10),
|
||||
Magic::Regtest => (1, 0),
|
||||
};
|
||||
|
||||
let p2p_threads = match magic {
|
||||
Magic::Testnet | Magic::Mainnet => 4,
|
||||
Magic::Regtest => 1,
|
||||
};
|
||||
|
||||
let port = match matches.value_of("port") {
|
||||
Some(port) => try!(port.parse().map_err(|_| "Invalid port".to_owned())),
|
||||
None => magic.port(),
|
||||
|
@ -45,6 +58,9 @@ pub fn parse(matches: &clap::ArgMatches) -> Result<Config, String> {
|
|||
port: port,
|
||||
connect: connect,
|
||||
seednode: seednode,
|
||||
inbound_connections: in_connections,
|
||||
outbound_connections: out_connections,
|
||||
p2p_threads: p2p_threads,
|
||||
};
|
||||
|
||||
Ok(config)
|
||||
|
|
|
@ -31,7 +31,6 @@ fn main() {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
fn run() -> Result<(), String> {
|
||||
let yaml = load_yaml!("cli.yml");
|
||||
let matches = clap::App::from_yaml(yaml).get_matches();
|
||||
|
|
Loading…
Reference in New Issue