mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 04:01:10 +00:00
Rename *-private-ipv4 to *-private-ip CLI args (#13208)
* Rename `*-private-ipv4` to `*-private-ip` CLI args Renames the `*-private-ipv4` to `*-private-ip` in the CLI interface. The old names are staying as alias, thus it will not break for anyone. Besides that it also fixes the naming in the rest of the code. * FMT
This commit is contained in:
@@ -68,18 +68,18 @@ pub struct NetworkParams {
|
|||||||
#[arg(long, value_name = "PORT", conflicts_with_all = &[ "listen_addr" ])]
|
#[arg(long, value_name = "PORT", conflicts_with_all = &[ "listen_addr" ])]
|
||||||
pub port: Option<u16>,
|
pub port: Option<u16>,
|
||||||
|
|
||||||
/// Always forbid connecting to private IPv4 addresses (as specified in
|
/// Always forbid connecting to private IPv4/IPv6 addresses (as specified in
|
||||||
/// [RFC1918](https://tools.ietf.org/html/rfc1918)), unless the address was passed with
|
/// [RFC1918](https://tools.ietf.org/html/rfc1918)), unless the address was passed with
|
||||||
/// `--reserved-nodes` or `--bootnodes`. Enabled by default for chains marked as "live" in
|
/// `--reserved-nodes` or `--bootnodes`. Enabled by default for chains marked as "live" in
|
||||||
/// their chain specifications.
|
/// their chain specifications.
|
||||||
#[arg(long, conflicts_with_all = &["allow_private_ipv4"])]
|
#[arg(long, alias = "no-private-ipv4", conflicts_with_all = &["allow_private_ip"])]
|
||||||
pub no_private_ipv4: bool,
|
pub no_private_ip: bool,
|
||||||
|
|
||||||
/// Always accept connecting to private IPv4 addresses (as specified in
|
/// Always accept connecting to private IPv4/IPv6 addresses (as specified in
|
||||||
/// [RFC1918](https://tools.ietf.org/html/rfc1918)). Enabled by default for chains marked as
|
/// [RFC1918](https://tools.ietf.org/html/rfc1918)). Enabled by default for chains marked as
|
||||||
/// "local" in their chain specifications, or when `--dev` is passed.
|
/// "local" in their chain specifications, or when `--dev` is passed.
|
||||||
#[arg(long, conflicts_with_all = &["no_private_ipv4"])]
|
#[arg(long, alias = "allow-private-ipv4", conflicts_with_all = &["no_private_ip"])]
|
||||||
pub allow_private_ipv4: bool,
|
pub allow_private_ip: bool,
|
||||||
|
|
||||||
/// Specify the number of outgoing connections we're trying to maintain.
|
/// Specify the number of outgoing connections we're trying to maintain.
|
||||||
#[arg(long, value_name = "COUNT", default_value_t = 15)]
|
#[arg(long, value_name = "COUNT", default_value_t = 15)]
|
||||||
@@ -200,8 +200,8 @@ impl NetworkParams {
|
|||||||
self.discover_local ||
|
self.discover_local ||
|
||||||
is_dev || matches!(chain_type, ChainType::Local | ChainType::Development);
|
is_dev || matches!(chain_type, ChainType::Local | ChainType::Development);
|
||||||
|
|
||||||
let allow_private_ipv4 = match (self.allow_private_ipv4, self.no_private_ipv4) {
|
let allow_private_ip = match (self.allow_private_ip, self.no_private_ip) {
|
||||||
(true, true) => unreachable!("`*_private_ipv4` flags are mutually exclusive; qed"),
|
(true, true) => unreachable!("`*_private_ip` flags are mutually exclusive; qed"),
|
||||||
(true, false) => true,
|
(true, false) => true,
|
||||||
(false, true) => false,
|
(false, true) => false,
|
||||||
(false, false) =>
|
(false, false) =>
|
||||||
@@ -231,7 +231,7 @@ impl NetworkParams {
|
|||||||
client_version: client_id.to_string(),
|
client_version: client_id.to_string(),
|
||||||
transport: TransportConfig::Normal {
|
transport: TransportConfig::Normal {
|
||||||
enable_mdns: !is_dev && !self.no_mdns,
|
enable_mdns: !is_dev && !self.no_mdns,
|
||||||
allow_private_ipv4,
|
allow_private_ip,
|
||||||
},
|
},
|
||||||
max_parallel_downloads: self.max_parallel_downloads,
|
max_parallel_downloads: self.max_parallel_downloads,
|
||||||
enable_dht_random_walk: !self.reserved_only,
|
enable_dht_random_walk: !self.reserved_only,
|
||||||
|
|||||||
@@ -301,10 +301,10 @@ pub enum TransportConfig {
|
|||||||
/// and connect to them if they support the same chain.
|
/// and connect to them if they support the same chain.
|
||||||
enable_mdns: bool,
|
enable_mdns: bool,
|
||||||
|
|
||||||
/// If true, allow connecting to private IPv4 addresses (as defined in
|
/// If true, allow connecting to private IPv4/IPv6 addresses (as defined in
|
||||||
/// [RFC1918](https://tools.ietf.org/html/rfc1918)). Irrelevant for addresses that have
|
/// [RFC1918](https://tools.ietf.org/html/rfc1918)). Irrelevant for addresses that have
|
||||||
/// been passed in `::sc_network::config::NetworkConfiguration::boot_nodes`.
|
/// been passed in `::sc_network::config::NetworkConfiguration::boot_nodes`.
|
||||||
allow_private_ipv4: bool,
|
allow_private_ip: bool,
|
||||||
},
|
},
|
||||||
|
|
||||||
/// Only allow connections within the same process.
|
/// Only allow connections within the same process.
|
||||||
|
|||||||
@@ -223,7 +223,7 @@ impl NetworkConfiguration {
|
|||||||
extra_sets: Vec::new(),
|
extra_sets: Vec::new(),
|
||||||
client_version: client_version.into(),
|
client_version: client_version.into(),
|
||||||
node_name: node_name.into(),
|
node_name: node_name.into(),
|
||||||
transport: TransportConfig::Normal { enable_mdns: false, allow_private_ipv4: true },
|
transport: TransportConfig::Normal { enable_mdns: false, allow_private_ip: true },
|
||||||
max_parallel_downloads: 5,
|
max_parallel_downloads: 5,
|
||||||
sync_mode: SyncMode::Full,
|
sync_mode: SyncMode::Full,
|
||||||
enable_dht_random_walk: true,
|
enable_dht_random_walk: true,
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ pub struct DiscoveryConfig {
|
|||||||
local_peer_id: PeerId,
|
local_peer_id: PeerId,
|
||||||
permanent_addresses: Vec<(PeerId, Multiaddr)>,
|
permanent_addresses: Vec<(PeerId, Multiaddr)>,
|
||||||
dht_random_walk: bool,
|
dht_random_walk: bool,
|
||||||
allow_private_ipv4: bool,
|
allow_private_ip: bool,
|
||||||
allow_non_globals_in_dht: bool,
|
allow_non_globals_in_dht: bool,
|
||||||
discovery_only_if_under_num: u64,
|
discovery_only_if_under_num: u64,
|
||||||
enable_mdns: bool,
|
enable_mdns: bool,
|
||||||
@@ -111,7 +111,7 @@ impl DiscoveryConfig {
|
|||||||
local_peer_id: local_public_key.to_peer_id(),
|
local_peer_id: local_public_key.to_peer_id(),
|
||||||
permanent_addresses: Vec::new(),
|
permanent_addresses: Vec::new(),
|
||||||
dht_random_walk: true,
|
dht_random_walk: true,
|
||||||
allow_private_ipv4: true,
|
allow_private_ip: true,
|
||||||
allow_non_globals_in_dht: false,
|
allow_non_globals_in_dht: false,
|
||||||
discovery_only_if_under_num: std::u64::MAX,
|
discovery_only_if_under_num: std::u64::MAX,
|
||||||
enable_mdns: false,
|
enable_mdns: false,
|
||||||
@@ -142,9 +142,9 @@ impl DiscoveryConfig {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Should private IPv4 addresses be reported?
|
/// Should private IPv4/IPv6 addresses be reported?
|
||||||
pub fn allow_private_ipv4(&mut self, value: bool) -> &mut Self {
|
pub fn allow_private_ip(&mut self, value: bool) -> &mut Self {
|
||||||
self.allow_private_ipv4 = value;
|
self.allow_private_ip = value;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -189,7 +189,7 @@ impl DiscoveryConfig {
|
|||||||
local_peer_id,
|
local_peer_id,
|
||||||
permanent_addresses,
|
permanent_addresses,
|
||||||
dht_random_walk,
|
dht_random_walk,
|
||||||
allow_private_ipv4,
|
allow_private_ip,
|
||||||
allow_non_globals_in_dht,
|
allow_non_globals_in_dht,
|
||||||
discovery_only_if_under_num,
|
discovery_only_if_under_num,
|
||||||
enable_mdns,
|
enable_mdns,
|
||||||
@@ -231,7 +231,7 @@ impl DiscoveryConfig {
|
|||||||
pending_events: VecDeque::new(),
|
pending_events: VecDeque::new(),
|
||||||
local_peer_id,
|
local_peer_id,
|
||||||
num_connections: 0,
|
num_connections: 0,
|
||||||
allow_private_ipv4,
|
allow_private_ip,
|
||||||
discovery_only_if_under_num,
|
discovery_only_if_under_num,
|
||||||
mdns: if enable_mdns {
|
mdns: if enable_mdns {
|
||||||
match TokioMdns::new(mdns::Config::default()) {
|
match TokioMdns::new(mdns::Config::default()) {
|
||||||
@@ -278,9 +278,9 @@ pub struct DiscoveryBehaviour {
|
|||||||
local_peer_id: PeerId,
|
local_peer_id: PeerId,
|
||||||
/// Number of nodes we're currently connected to.
|
/// Number of nodes we're currently connected to.
|
||||||
num_connections: u64,
|
num_connections: u64,
|
||||||
/// If false, `addresses_of_peer` won't return any private IPv4 address, except for the ones
|
/// If false, `addresses_of_peer` won't return any private IPv4/IPv6 address, except for the
|
||||||
/// stored in `permanent_addresses` or `ephemeral_addresses`.
|
/// ones stored in `permanent_addresses` or `ephemeral_addresses`.
|
||||||
allow_private_ipv4: bool,
|
allow_private_ip: bool,
|
||||||
/// Number of active connections over which we interrupt the discovery process.
|
/// Number of active connections over which we interrupt the discovery process.
|
||||||
discovery_only_if_under_num: u64,
|
discovery_only_if_under_num: u64,
|
||||||
/// Should non-global addresses be added to the DHT?
|
/// Should non-global addresses be added to the DHT?
|
||||||
@@ -506,7 +506,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
|
|||||||
list_to_filter.extend(mdns.addresses_of_peer(peer_id));
|
list_to_filter.extend(mdns.addresses_of_peer(peer_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !self.allow_private_ipv4 {
|
if !self.allow_private_ip {
|
||||||
list_to_filter.retain(|addr| match addr.iter().next() {
|
list_to_filter.retain(|addr| match addr.iter().next() {
|
||||||
Some(Protocol::Ip4(addr)) if !IpNetwork::from(addr).is_global() => false,
|
Some(Protocol::Ip4(addr)) if !IpNetwork::from(addr).is_global() => false,
|
||||||
Some(Protocol::Ip6(addr)) if !IpNetwork::from(addr).is_global() => false,
|
Some(Protocol::Ip6(addr)) if !IpNetwork::from(addr).is_global() => false,
|
||||||
@@ -947,7 +947,7 @@ mod tests {
|
|||||||
let mut config = DiscoveryConfig::new(keypair.public());
|
let mut config = DiscoveryConfig::new(keypair.public());
|
||||||
config
|
config
|
||||||
.with_permanent_addresses(first_swarm_peer_id_and_addr.clone())
|
.with_permanent_addresses(first_swarm_peer_id_and_addr.clone())
|
||||||
.allow_private_ipv4(true)
|
.allow_private_ip(true)
|
||||||
.allow_non_globals_in_dht(true)
|
.allow_non_globals_in_dht(true)
|
||||||
.discovery_limit(50)
|
.discovery_limit(50)
|
||||||
.with_kademlia(genesis_hash, fork_id, &protocol_id);
|
.with_kademlia(genesis_hash, fork_id, &protocol_id);
|
||||||
@@ -1065,7 +1065,7 @@ mod tests {
|
|||||||
let keypair = Keypair::generate_ed25519();
|
let keypair = Keypair::generate_ed25519();
|
||||||
let mut config = DiscoveryConfig::new(keypair.public());
|
let mut config = DiscoveryConfig::new(keypair.public());
|
||||||
config
|
config
|
||||||
.allow_private_ipv4(true)
|
.allow_private_ip(true)
|
||||||
.allow_non_globals_in_dht(true)
|
.allow_non_globals_in_dht(true)
|
||||||
.discovery_limit(50)
|
.discovery_limit(50)
|
||||||
.with_kademlia(supported_genesis_hash, None, &supported_protocol_id);
|
.with_kademlia(supported_genesis_hash, None, &supported_protocol_id);
|
||||||
|
|||||||
@@ -291,11 +291,15 @@ where
|
|||||||
match params.network_config.transport {
|
match params.network_config.transport {
|
||||||
TransportConfig::MemoryOnly => {
|
TransportConfig::MemoryOnly => {
|
||||||
config.with_mdns(false);
|
config.with_mdns(false);
|
||||||
config.allow_private_ipv4(false);
|
config.allow_private_ip(false);
|
||||||
},
|
},
|
||||||
TransportConfig::Normal { enable_mdns, allow_private_ipv4, .. } => {
|
TransportConfig::Normal {
|
||||||
|
enable_mdns,
|
||||||
|
allow_private_ip: allow_private_ipv4,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
config.with_mdns(enable_mdns);
|
config.with_mdns(enable_mdns);
|
||||||
config.allow_private_ipv4(allow_private_ipv4);
|
config.allow_private_ip(allow_private_ipv4);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -220,7 +220,7 @@ fn node_config<
|
|||||||
);
|
);
|
||||||
|
|
||||||
network_config.transport =
|
network_config.transport =
|
||||||
TransportConfig::Normal { enable_mdns: false, allow_private_ipv4: true };
|
TransportConfig::Normal { enable_mdns: false, allow_private_ip: true };
|
||||||
|
|
||||||
Configuration {
|
Configuration {
|
||||||
impl_name: String::from("network-test-impl"),
|
impl_name: String::from("network-test-impl"),
|
||||||
|
|||||||
Reference in New Issue
Block a user