diff --git a/README.md b/README.md index 95463e4..33c47f4 100644 --- a/README.md +++ b/README.md @@ -907,7 +907,6 @@ You can also specify bootstrap peers explicitly: ./target/release/ant-node \ --root-dir ~/.ant-node \ --port 12000 \ - --ip-version dual \ --upgrade-channel stable \ --migrate-ant-data auto \ --log-level info @@ -929,9 +928,9 @@ Options: Listening port (0 for automatic selection) [default: 0] - --ip-version - IP version to use: ipv4, ipv6, or dual - [default: dual] + --ipv4-only + Force IPv4-only mode (disable dual-stack). + Use on hosts without working IPv6. --bootstrap Bootstrap peer socket addresses (can be specified multiple times) @@ -1003,7 +1002,6 @@ peers = [ ```bash export ANT_ROOT_DIR=~/.ant-node export ANT_PORT=12000 -export ANT_IP_VERSION=dual export ANT_LOG_LEVEL=info export ANT_AUTO_UPGRADE=true export ANT_UPGRADE_CHANNEL=stable @@ -1016,7 +1014,6 @@ export ANT_UPGRADE_CHANNEL=stable ```toml root_dir = "~/.ant-node" port = 0 # Auto-select -ip_version = "dual" bootstrap = [ "10.0.0.1:10000", "10.0.0.2:10000", diff --git a/config/production.toml b/config/production.toml index 3e83ed0..bbcb1a2 100644 --- a/config/production.toml +++ b/config/production.toml @@ -9,9 +9,6 @@ root_dir = "/var/lib/ant" # Listening port (10000-10999 for production) port = 10000 -# IP version: "ipv4", "ipv6", or "dual" -ip_version = "dual" - # Bootstrap peer addresses (socket addrs) bootstrap = [] diff --git a/scripts/testnet/spawn-nodes.sh b/scripts/testnet/spawn-nodes.sh index 15ba852..90610ef 100755 --- a/scripts/testnet/spawn-nodes.sh +++ b/scripts/testnet/spawn-nodes.sh @@ -58,7 +58,7 @@ Type=simple ExecStart=/usr/local/bin/ant-node \\ --root-dir ${NODE_DIR} \\ --port ${PORT} \\ - --ip-version ipv4 \\ + --ipv4-only \\ --network-mode testnet \\ ${BOOTSTRAP_FLAGS} \\ --metrics-port ${METRICS} \\ diff --git a/scripts/testnet/start-genesis.sh b/scripts/testnet/start-genesis.sh index 913e901..bd1ca1c 100755 --- a/scripts/testnet/start-genesis.sh +++ b/scripts/testnet/start-genesis.sh @@ -23,7 +23,7 @@ Type=simple ExecStart=/usr/local/bin/ant-node \ --root-dir /var/lib/ant/nodes/node-0 \ --port 12000 \ - --ip-version ipv4 \ + --ipv4-only \ --metrics-port 9100 \ --log-level info \ --upgrade-channel stable \ @@ -64,7 +64,7 @@ Type=simple ExecStart=/usr/local/bin/ant-node \ --root-dir /var/lib/ant/nodes/node-50 \ --port 12000 \ - --ip-version ipv4 \ + --ipv4-only \ -b 142.93.52.129:12000 \ --metrics-port 9100 \ --log-level info \ diff --git a/src/bin/ant-node/cli.rs b/src/bin/ant-node/cli.rs index 861c78c..0d6509c 100644 --- a/src/bin/ant-node/cli.rs +++ b/src/bin/ant-node/cli.rs @@ -1,8 +1,8 @@ //! Command-line interface definition. use ant_node::config::{ - BootstrapCacheConfig, BootstrapPeersConfig, BootstrapSource, EvmNetworkConfig, IpVersion, - NetworkMode, NodeConfig, PaymentConfig, UpgradeChannel, + BootstrapCacheConfig, BootstrapPeersConfig, BootstrapSource, EvmNetworkConfig, NetworkMode, + NodeConfig, PaymentConfig, UpgradeChannel, }; use clap::{Parser, ValueEnum}; use std::net::SocketAddr; @@ -21,9 +21,11 @@ pub struct Cli { #[arg(long, short, default_value = "0", env = "ANT_PORT")] pub port: u16, - /// IP version to use. - #[arg(long, value_enum, default_value = "dual", env = "ANT_IP_VERSION")] - pub ip_version: CliIpVersion, + /// Force IPv4-only mode (disable dual-stack). + /// Use on hosts without working IPv6 to avoid advertising + /// unreachable addresses to the DHT. + #[arg(long, env = "ANT_IPV4_ONLY")] + pub ipv4_only: bool, /// Bootstrap peer addresses. #[arg(long, short, env = "ANT_BOOTSTRAP")] @@ -112,17 +114,6 @@ pub struct Cli { pub bootstrap_cache_capacity: usize, } -/// IP version CLI enum. -#[derive(Debug, Clone, Copy, ValueEnum)] -pub enum CliIpVersion { - /// IPv4 only. - Ipv4, - /// IPv6 only. - Ipv6, - /// Dual-stack (both IPv4 and IPv6). - Dual, -} - /// Upgrade channel CLI enum. #[derive(Debug, Clone, Copy, ValueEnum)] pub enum CliUpgradeChannel { @@ -215,7 +206,7 @@ impl Cli { } config.port = self.port; - config.ip_version = self.ip_version.into(); + config.ipv4_only = self.ipv4_only; config.log_level = self.log_level.into(); config.network_mode = self.network_mode.into(); @@ -266,16 +257,6 @@ impl Cli { } } -impl From for IpVersion { - fn from(v: CliIpVersion) -> Self { - match v { - CliIpVersion::Ipv4 => Self::Ipv4, - CliIpVersion::Ipv6 => Self::Ipv6, - CliIpVersion::Dual => Self::Dual, - } - } -} - impl From for UpgradeChannel { fn from(c: CliUpgradeChannel) -> Self { match c { diff --git a/src/config.rs b/src/config.rs index 2c478f1..47cfbeb 100644 --- a/src/config.rs +++ b/src/config.rs @@ -10,19 +10,6 @@ pub const NODE_IDENTITY_FILENAME: &str = "node_identity.key"; /// Subdirectory under the root dir that contains per-node data directories. pub const NODES_SUBDIR: &str = "nodes"; -/// IP version configuration. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)] -#[serde(rename_all = "lowercase")] -pub enum IpVersion { - /// IPv4 only. - Ipv4, - /// IPv6 only. - Ipv6, - /// Dual-stack (both IPv4 and IPv6). - #[default] - Dual, -} - /// Upgrade channel for auto-updates. #[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)] #[serde(rename_all = "lowercase")] @@ -99,9 +86,13 @@ pub struct NodeConfig { #[serde(default)] pub port: u16, - /// IP version to use. + /// Force IPv4-only mode. + /// + /// When true, the node binds only on IPv4 instead of dual-stack. + /// Use this on hosts without working IPv6 to avoid advertising + /// unreachable addresses to the DHT. #[serde(default)] - pub ip_version: IpVersion, + pub ipv4_only: bool, /// Bootstrap peer addresses. #[serde(default)] @@ -249,7 +240,7 @@ impl Default for NodeConfig { Self { root_dir: default_root_dir(), port: 0, - ip_version: IpVersion::default(), + ipv4_only: false, bootstrap: Vec::new(), network_mode: NetworkMode::default(), testnet: TestnetConfig::default(), diff --git a/src/node.rs b/src/node.rs index 7c833f8..2a2e724 100644 --- a/src/node.rs +++ b/src/node.rs @@ -2,7 +2,7 @@ use crate::ant_protocol::{CHUNK_PROTOCOL_ID, MAX_CHUNK_SIZE}; use crate::config::{ - default_nodes_dir, default_root_dir, EvmNetworkConfig, IpVersion, NetworkMode, NodeConfig, + default_nodes_dir, default_root_dir, EvmNetworkConfig, NetworkMode, NodeConfig, NODE_IDENTITY_FILENAME, }; use crate::error::{Error, Result}; @@ -151,12 +151,11 @@ impl NodeBuilder { /// Build the saorsa-core `NodeConfig` from our config. fn build_core_config(config: &NodeConfig) -> Result { - let ipv6 = matches!(config.ip_version, IpVersion::Ipv6 | IpVersion::Dual); let local = matches!(config.network_mode, NetworkMode::Development); let mut core_config = CoreNodeConfig::builder() .port(config.port) - .ipv6(ipv6) + .ipv6(!config.ipv4_only) .local(local) .max_message_size(config.max_message_size) .build() @@ -862,6 +861,23 @@ mod tests { assert!(core.diversity_config.is_some()); } + #[test] + fn test_build_core_config_ipv4_only() { + let config = NodeConfig { + ipv4_only: true, + ..Default::default() + }; + let core = NodeBuilder::build_core_config(&config).expect("core config"); + assert!(!core.ipv6, "ipv4_only should disable IPv6"); + } + + #[test] + fn test_build_core_config_dual_stack_by_default() { + let config = NodeConfig::default(); + let core = NodeBuilder::build_core_config(&config).expect("core config"); + assert!(core.ipv6, "dual-stack should be the default"); + } + #[test] fn test_build_core_config_sets_development_mode_permissive() { let config = NodeConfig {