Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Rename *-private-ipv4 to *-private-ip CLI args (#13208)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bkchr authored Jan 23, 2023
1 parent ed3f055 commit d0a2c4a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 29 deletions.
18 changes: 9 additions & 9 deletions client/cli/src/params/network_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ pub struct NetworkParams {
#[arg(long, value_name = "PORT", conflicts_with_all = &[ "listen_addr" ])]
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
/// `--reserved-nodes` or `--bootnodes`. Enabled by default for chains marked as "live" in
/// their chain specifications.
#[arg(long, conflicts_with_all = &["allow_private_ipv4"])]
pub no_private_ipv4: bool,
#[arg(long, alias = "no-private-ipv4", conflicts_with_all = &["allow_private_ip"])]
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
/// "local" in their chain specifications, or when `--dev` is passed.
#[arg(long, conflicts_with_all = &["no_private_ipv4"])]
pub allow_private_ipv4: bool,
#[arg(long, alias = "allow-private-ipv4", conflicts_with_all = &["no_private_ip"])]
pub allow_private_ip: bool,

/// Specify the number of outgoing connections we're trying to maintain.
#[arg(long, value_name = "COUNT", default_value_t = 15)]
Expand Down Expand Up @@ -200,8 +200,8 @@ impl NetworkParams {
self.discover_local ||
is_dev || matches!(chain_type, ChainType::Local | ChainType::Development);

let allow_private_ipv4 = match (self.allow_private_ipv4, self.no_private_ipv4) {
(true, true) => unreachable!("`*_private_ipv4` flags are mutually exclusive; qed"),
let allow_private_ip = match (self.allow_private_ip, self.no_private_ip) {
(true, true) => unreachable!("`*_private_ip` flags are mutually exclusive; qed"),
(true, false) => true,
(false, true) => false,
(false, false) =>
Expand Down Expand Up @@ -231,7 +231,7 @@ impl NetworkParams {
client_version: client_id.to_string(),
transport: TransportConfig::Normal {
enable_mdns: !is_dev && !self.no_mdns,
allow_private_ipv4,
allow_private_ip,
},
max_parallel_downloads: self.max_parallel_downloads,
enable_dht_random_walk: !self.reserved_only,
Expand Down
4 changes: 2 additions & 2 deletions client/network/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ pub enum TransportConfig {
/// and connect to them if they support the same chain.
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
/// been passed in `::sc_network::config::NetworkConfiguration::boot_nodes`.
allow_private_ipv4: bool,
allow_private_ip: bool,
},

/// Only allow connections within the same process.
Expand Down
2 changes: 1 addition & 1 deletion client/network/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ impl NetworkConfiguration {
extra_sets: Vec::new(),
client_version: client_version.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,
sync_mode: SyncMode::Full,
enable_dht_random_walk: true,
Expand Down
26 changes: 13 additions & 13 deletions client/network/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub struct DiscoveryConfig {
local_peer_id: PeerId,
permanent_addresses: Vec<(PeerId, Multiaddr)>,
dht_random_walk: bool,
allow_private_ipv4: bool,
allow_private_ip: bool,
allow_non_globals_in_dht: bool,
discovery_only_if_under_num: u64,
enable_mdns: bool,
Expand All @@ -111,7 +111,7 @@ impl DiscoveryConfig {
local_peer_id: local_public_key.to_peer_id(),
permanent_addresses: Vec::new(),
dht_random_walk: true,
allow_private_ipv4: true,
allow_private_ip: true,
allow_non_globals_in_dht: false,
discovery_only_if_under_num: std::u64::MAX,
enable_mdns: false,
Expand Down Expand Up @@ -142,9 +142,9 @@ impl DiscoveryConfig {
self
}

/// Should private IPv4 addresses be reported?
pub fn allow_private_ipv4(&mut self, value: bool) -> &mut Self {
self.allow_private_ipv4 = value;
/// Should private IPv4/IPv6 addresses be reported?
pub fn allow_private_ip(&mut self, value: bool) -> &mut Self {
self.allow_private_ip = value;
self
}

Expand Down Expand Up @@ -189,7 +189,7 @@ impl DiscoveryConfig {
local_peer_id,
permanent_addresses,
dht_random_walk,
allow_private_ipv4,
allow_private_ip,
allow_non_globals_in_dht,
discovery_only_if_under_num,
enable_mdns,
Expand Down Expand Up @@ -231,7 +231,7 @@ impl DiscoveryConfig {
pending_events: VecDeque::new(),
local_peer_id,
num_connections: 0,
allow_private_ipv4,
allow_private_ip,
discovery_only_if_under_num,
mdns: if enable_mdns {
match TokioMdns::new(mdns::Config::default()) {
Expand Down Expand Up @@ -278,9 +278,9 @@ pub struct DiscoveryBehaviour {
local_peer_id: PeerId,
/// Number of nodes we're currently connected to.
num_connections: u64,
/// If false, `addresses_of_peer` won't return any private IPv4 address, except for the ones
/// stored in `permanent_addresses` or `ephemeral_addresses`.
allow_private_ipv4: bool,
/// If false, `addresses_of_peer` won't return any private IPv4/IPv6 address, except for the
/// ones stored in `permanent_addresses` or `ephemeral_addresses`.
allow_private_ip: bool,
/// Number of active connections over which we interrupt the discovery process.
discovery_only_if_under_num: u64,
/// Should non-global addresses be added to the DHT?
Expand Down Expand Up @@ -506,7 +506,7 @@ impl NetworkBehaviour for DiscoveryBehaviour {
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() {
Some(Protocol::Ip4(addr)) if !IpNetwork::from(addr).is_global() => false,
Some(Protocol::Ip6(addr)) if !IpNetwork::from(addr).is_global() => false,
Expand Down Expand Up @@ -947,7 +947,7 @@ mod tests {
let mut config = DiscoveryConfig::new(keypair.public());
config
.with_permanent_addresses(first_swarm_peer_id_and_addr.clone())
.allow_private_ipv4(true)
.allow_private_ip(true)
.allow_non_globals_in_dht(true)
.discovery_limit(50)
.with_kademlia(genesis_hash, fork_id, &protocol_id);
Expand Down Expand Up @@ -1065,7 +1065,7 @@ mod tests {
let keypair = Keypair::generate_ed25519();
let mut config = DiscoveryConfig::new(keypair.public());
config
.allow_private_ipv4(true)
.allow_private_ip(true)
.allow_non_globals_in_dht(true)
.discovery_limit(50)
.with_kademlia(supported_genesis_hash, None, &supported_protocol_id);
Expand Down
10 changes: 7 additions & 3 deletions client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,11 +291,15 @@ where
match params.network_config.transport {
TransportConfig::MemoryOnly => {
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.allow_private_ipv4(allow_private_ipv4);
config.allow_private_ip(allow_private_ipv4);
},
}

Expand Down
2 changes: 1 addition & 1 deletion client/service/test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ fn node_config<
);

network_config.transport =
TransportConfig::Normal { enable_mdns: false, allow_private_ipv4: true };
TransportConfig::Normal { enable_mdns: false, allow_private_ip: true };

Configuration {
impl_name: String::from("network-test-impl"),
Expand Down

0 comments on commit d0a2c4a

Please sign in to comment.