diff --git a/substrate/substrate/cli/src/cli.yml b/substrate/substrate/cli/src/cli.yml index ace575e6760e533c2686803e2e0222a728a5e5c4..0d6fd8795ad88312e50338e9b29df409cb6cb435 100644 --- a/substrate/substrate/cli/src/cli.yml +++ b/substrate/substrate/cli/src/cli.yml @@ -70,6 +70,12 @@ args: help: Specify a list of bootnodes takes_value: true multiple: true + - reserved-nodes: + long: reserved-nodes + value_name: URL + help: Specify a list of reserved node addresses + takes_value: true + multiple: true - chain: long: chain value_name: CHAIN_SPEC diff --git a/substrate/substrate/cli/src/lib.rs b/substrate/substrate/cli/src/lib.rs index 14f7caca0d5510c32e9b987702530f770e93b739..801e808c51d1ff158b3b4204c242da1006e6276c 100644 --- a/substrate/substrate/cli/src/lib.rs +++ b/substrate/substrate/cli/src/lib.rs @@ -61,6 +61,7 @@ use service::{ ServiceFactory, FactoryFullConfiguration, RuntimeGenesis, FactoryGenesis, PruningMode, ChainSpec, }; +use network::NonReservedPeerMode; use std::io::{Write, Read, stdin, stdout}; use std::iter; @@ -278,6 +279,12 @@ where .map_or(Default::default(), |v| v.map(|n| n.to_owned()).collect::<Vec<_>>())); config.network.config_path = Some(network_path(&base_path, config.chain_spec.id()).to_string_lossy().into()); config.network.net_config_path = config.network.config_path.clone(); + config.network.reserved_nodes.extend(matches + .values_of("reserved-nodes") + .map_or(Default::default(), |v| v.map(|n| n.to_owned()).collect::<Vec<_>>())); + if !config.network.reserved_nodes.is_empty() { + config.network.non_reserved_mode = NonReservedPeerMode::Deny; + } let port = match matches.value_of("port") { Some(port) => port.parse().map_err(|_| "Invalid p2p port value specified.")?, diff --git a/substrate/substrate/network-libp2p/src/service.rs b/substrate/substrate/network-libp2p/src/service.rs index f84e64b637f6a7abaefbded4ce460dd485a2c3b5..d47a024f74c66a42b3b57f46243632bc581fefc8 100644 --- a/substrate/substrate/network-libp2p/src/service.rs +++ b/substrate/substrate/network-libp2p/src/service.rs @@ -506,6 +506,16 @@ fn init_thread( } } + shared.network_state.set_non_reserved_mode(shared.config.non_reserved_mode.clone()); + for reserved in shared.config.reserved_nodes.iter() { + match shared.network_state.add_reserved_peer(reserved) { + Ok(who) => { + trace!(target: "sub-libp2p", "Added reseved peer {:?}", who); + }, + Err(err) => warn!(target:"sub-libp2p", "Couldn't parse reserved address: {}", err), + } + } + // Start connecting to nodes now. connect_to_nodes(shared.clone(), transport.clone(), &swarm_controller);