Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -929,9 +928,9 @@ Options:
Listening port (0 for automatic selection)
[default: 0]

--ip-version <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 <ADDR>
Bootstrap peer socket addresses (can be specified multiple times)
Expand Down Expand Up @@ -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
Expand All @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions config/production.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down
2 changes: 1 addition & 1 deletion scripts/testnet/spawn-nodes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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} \\
Expand Down
4 changes: 2 additions & 2 deletions scripts/testnet/start-genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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 \
Expand Down
35 changes: 8 additions & 27 deletions src/bin/ant-node/cli.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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")]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -266,16 +257,6 @@ impl Cli {
}
}

impl From<CliIpVersion> for IpVersion {
fn from(v: CliIpVersion) -> Self {
match v {
CliIpVersion::Ipv4 => Self::Ipv4,
CliIpVersion::Ipv6 => Self::Ipv6,
CliIpVersion::Dual => Self::Dual,
}
}
}

impl From<CliUpgradeChannel> for UpgradeChannel {
fn from(c: CliUpgradeChannel) -> Self {
match c {
Expand Down
23 changes: 7 additions & 16 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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(),
Expand Down
22 changes: 19 additions & 3 deletions src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -151,12 +151,11 @@ impl NodeBuilder {

/// Build the saorsa-core `NodeConfig` from our config.
fn build_core_config(config: &NodeConfig) -> Result<CoreNodeConfig> {
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()
Expand Down Expand Up @@ -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 {
Expand Down
Loading