Skip to content

Commit

Permalink
Replace IpAddress with NetAddress in externalip configuration
Browse files Browse the repository at this point in the history
Changes have been made to use NetAddress instead of IpAddress in the externalip field of the configuration module. The same adjustment was reflected in the addressmanager and kaspad components. This change aims to include port information along with IP for externalip, making the application more flexible and feature-rich in handling network addresses.
  • Loading branch information
biryukovmaxim committed Oct 22, 2023
1 parent 8f69632 commit d2c690a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 18 deletions.
14 changes: 4 additions & 10 deletions components/addressmanager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,12 @@ impl AddressManager {
fn configured_address(&self) -> Option<(NetAddress, Option<ExtendHelper>)> {
match self.config.externalip {
// An external IP was passed, we will try to bind that if it's valid
Some(local_net_address) if local_net_address.is_publicly_routable() => {
info!("External ip {} added to store", local_net_address);
Some((
NetAddress {
ip: local_net_address,
port: self.config.p2p_listen_address.normalize(self.config.default_p2p_port()).port,
},
None,
))
Some(local_net_address) if local_net_address.ip.is_publicly_routable() => {
info!("External address {} added to store", local_net_address);
Some((local_net_address, None))
}
Some(local_net_address) => {
info!("Non-publicly routable external ip {} not added to store", local_net_address);
info!("Non-publicly routable external address {} not added to store", local_net_address);
None
}
None if !self.config.disable_upnp => {
Expand Down
4 changes: 2 additions & 2 deletions consensus/core/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod constants;
pub mod genesis;
pub mod params;

use kaspa_utils::networking::{ContextualNetAddress, IpAddress};
use kaspa_utils::networking::{ContextualNetAddress, NetAddress};

#[cfg(feature = "devnet-prealloc")]
use crate::utxo::utxo_collection::UtxoCollection;
Expand Down Expand Up @@ -57,7 +57,7 @@ pub struct Config {
// If undefined, sets it to 0.0.0.0
pub p2p_listen_address: ContextualNetAddress,

pub externalip: Option<IpAddress>,
pub externalip: Option<NetAddress>,

pub block_template_cache_lifetime: Option<u64>,

Expand Down
13 changes: 7 additions & 6 deletions kaspad/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use kaspa_consensus_core::{

use kaspa_core::kaspad_env::version;

use kaspa_utils::networking::{ContextualNetAddress, IpAddress};
use kaspa_utils::networking::ContextualNetAddress;
use kaspa_wrpc_server::address::WrpcNetAddress;

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -52,7 +52,7 @@ pub struct Args {
pub archival: bool,
pub sanity: bool,
pub yes: bool,
pub externalip: Option<IpAddress>,
pub externalip: Option<ContextualNetAddress>,
pub perf_metrics: bool,
pub perf_metrics_interval_sec: u64,
pub block_template_cache_lifetime: Option<u64>,
Expand Down Expand Up @@ -126,8 +126,9 @@ impl Args {
config.enable_sanity_checks = true;
config.user_agent_comments = self.user_agent_comments.clone();
config.block_template_cache_lifetime = self.block_template_cache_lifetime;

config.p2p_listen_address = self.listen.unwrap_or(ContextualNetAddress::unspecified());
config.externalip = self.externalip.map(|v| v.normalize(config.default_p2p_port()));

#[cfg(feature = "devnet-prealloc")]
if let Some(num_prealloc_utxos) = self.num_prealloc_utxos {
config.initial_utxo_set = Arc::new(self.generate_prealloc_utxos(num_prealloc_utxos));
Expand Down Expand Up @@ -305,8 +306,8 @@ pub fn cli() -> Command {
.value_name("externalip")
.require_equals(true)
.default_missing_value(None)
.value_parser(clap::value_parser!(IpAddress))
.help("Add an ip to the list of local addresses we claim to listen on to peers"),
.value_parser(clap::value_parser!(ContextualNetAddress))
.help("Add an socket address(ip:port) to the list of local addresses we claim to listen on to peers"),
)
.arg(arg!(--"perf-metrics" "Enable performance metrics: cpu, memory, disk io usage"))
.arg(
Expand Down Expand Up @@ -360,7 +361,7 @@ pub fn parse_args() -> Args {
sanity: m.get_one::<bool>("sanity").cloned().unwrap_or(defaults.sanity),
yes: m.get_one::<bool>("yes").cloned().unwrap_or(defaults.yes),
user_agent_comments: m.get_many::<String>("user_agent_comments").unwrap_or_default().cloned().collect(),
externalip: m.get_one::<IpAddress>("externalip").cloned(),
externalip: m.get_one::<ContextualNetAddress>("externalip").cloned(),
perf_metrics: m.get_one::<bool>("perf-metrics").cloned().unwrap_or(defaults.perf_metrics),
perf_metrics_interval_sec: m
.get_one::<u64>("perf-metrics-interval-sec")
Expand Down

0 comments on commit d2c690a

Please sign in to comment.