Skip to content

Commit f113f4b

Browse files
authored
Merge pull request #52 from grumbach/claude/remove-ip-version-flag-SFH7m
2 parents ca47dc7 + 202f41a commit f113f4b

File tree

7 files changed

+40
-58
lines changed

7 files changed

+40
-58
lines changed

README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -907,7 +907,6 @@ You can also specify bootstrap peers explicitly:
907907
./target/release/ant-node \
908908
--root-dir ~/.ant-node \
909909
--port 12000 \
910-
--ip-version dual \
911910
--upgrade-channel stable \
912911
--migrate-ant-data auto \
913912
--log-level info
@@ -929,9 +928,9 @@ Options:
929928
Listening port (0 for automatic selection)
930929
[default: 0]
931930
932-
--ip-version <VERSION>
933-
IP version to use: ipv4, ipv6, or dual
934-
[default: dual]
931+
--ipv4-only
932+
Force IPv4-only mode (disable dual-stack).
933+
Use on hosts without working IPv6.
935934
936935
--bootstrap <ADDR>
937936
Bootstrap peer socket addresses (can be specified multiple times)
@@ -1003,7 +1002,6 @@ peers = [
10031002
```bash
10041003
export ANT_ROOT_DIR=~/.ant-node
10051004
export ANT_PORT=12000
1006-
export ANT_IP_VERSION=dual
10071005
export ANT_LOG_LEVEL=info
10081006
export ANT_AUTO_UPGRADE=true
10091007
export ANT_UPGRADE_CHANNEL=stable
@@ -1016,7 +1014,6 @@ export ANT_UPGRADE_CHANNEL=stable
10161014
```toml
10171015
root_dir = "~/.ant-node"
10181016
port = 0 # Auto-select
1019-
ip_version = "dual"
10201017
bootstrap = [
10211018
"10.0.0.1:10000",
10221019
"10.0.0.2:10000",

config/production.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ root_dir = "/var/lib/ant"
99
# Listening port (10000-10999 for production)
1010
port = 10000
1111

12-
# IP version: "ipv4", "ipv6", or "dual"
13-
ip_version = "dual"
14-
1512
# Bootstrap peer addresses (socket addrs)
1613
bootstrap = []
1714

scripts/testnet/spawn-nodes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Type=simple
5858
ExecStart=/usr/local/bin/ant-node \\
5959
--root-dir ${NODE_DIR} \\
6060
--port ${PORT} \\
61-
--ip-version ipv4 \\
61+
--ipv4-only \\
6262
--network-mode testnet \\
6363
${BOOTSTRAP_FLAGS} \\
6464
--metrics-port ${METRICS} \\

scripts/testnet/start-genesis.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Type=simple
2323
ExecStart=/usr/local/bin/ant-node \
2424
--root-dir /var/lib/ant/nodes/node-0 \
2525
--port 12000 \
26-
--ip-version ipv4 \
26+
--ipv4-only \
2727
--metrics-port 9100 \
2828
--log-level info \
2929
--upgrade-channel stable \
@@ -64,7 +64,7 @@ Type=simple
6464
ExecStart=/usr/local/bin/ant-node \
6565
--root-dir /var/lib/ant/nodes/node-50 \
6666
--port 12000 \
67-
--ip-version ipv4 \
67+
--ipv4-only \
6868
-b 142.93.52.129:12000 \
6969
--metrics-port 9100 \
7070
--log-level info \

src/bin/ant-node/cli.rs

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Command-line interface definition.
22
33
use ant_node::config::{
4-
BootstrapCacheConfig, BootstrapPeersConfig, BootstrapSource, EvmNetworkConfig, IpVersion,
5-
NetworkMode, NodeConfig, PaymentConfig, UpgradeChannel,
4+
BootstrapCacheConfig, BootstrapPeersConfig, BootstrapSource, EvmNetworkConfig, NetworkMode,
5+
NodeConfig, PaymentConfig, UpgradeChannel,
66
};
77
use clap::{Parser, ValueEnum};
88
use std::net::SocketAddr;
@@ -21,9 +21,11 @@ pub struct Cli {
2121
#[arg(long, short, default_value = "0", env = "ANT_PORT")]
2222
pub port: u16,
2323

24-
/// IP version to use.
25-
#[arg(long, value_enum, default_value = "dual", env = "ANT_IP_VERSION")]
26-
pub ip_version: CliIpVersion,
24+
/// Force IPv4-only mode (disable dual-stack).
25+
/// Use on hosts without working IPv6 to avoid advertising
26+
/// unreachable addresses to the DHT.
27+
#[arg(long, env = "ANT_IPV4_ONLY")]
28+
pub ipv4_only: bool,
2729

2830
/// Bootstrap peer addresses.
2931
#[arg(long, short, env = "ANT_BOOTSTRAP")]
@@ -112,17 +114,6 @@ pub struct Cli {
112114
pub bootstrap_cache_capacity: usize,
113115
}
114116

115-
/// IP version CLI enum.
116-
#[derive(Debug, Clone, Copy, ValueEnum)]
117-
pub enum CliIpVersion {
118-
/// IPv4 only.
119-
Ipv4,
120-
/// IPv6 only.
121-
Ipv6,
122-
/// Dual-stack (both IPv4 and IPv6).
123-
Dual,
124-
}
125-
126117
/// Upgrade channel CLI enum.
127118
#[derive(Debug, Clone, Copy, ValueEnum)]
128119
pub enum CliUpgradeChannel {
@@ -215,7 +206,7 @@ impl Cli {
215206
}
216207

217208
config.port = self.port;
218-
config.ip_version = self.ip_version.into();
209+
config.ipv4_only = self.ipv4_only;
219210
config.log_level = self.log_level.into();
220211
config.network_mode = self.network_mode.into();
221212

@@ -266,16 +257,6 @@ impl Cli {
266257
}
267258
}
268259

269-
impl From<CliIpVersion> for IpVersion {
270-
fn from(v: CliIpVersion) -> Self {
271-
match v {
272-
CliIpVersion::Ipv4 => Self::Ipv4,
273-
CliIpVersion::Ipv6 => Self::Ipv6,
274-
CliIpVersion::Dual => Self::Dual,
275-
}
276-
}
277-
}
278-
279260
impl From<CliUpgradeChannel> for UpgradeChannel {
280261
fn from(c: CliUpgradeChannel) -> Self {
281262
match c {

src/config.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,6 @@ pub const NODE_IDENTITY_FILENAME: &str = "node_identity.key";
1010
/// Subdirectory under the root dir that contains per-node data directories.
1111
pub const NODES_SUBDIR: &str = "nodes";
1212

13-
/// IP version configuration.
14-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
15-
#[serde(rename_all = "lowercase")]
16-
pub enum IpVersion {
17-
/// IPv4 only.
18-
Ipv4,
19-
/// IPv6 only.
20-
Ipv6,
21-
/// Dual-stack (both IPv4 and IPv6).
22-
#[default]
23-
Dual,
24-
}
25-
2613
/// Upgrade channel for auto-updates.
2714
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
2815
#[serde(rename_all = "lowercase")]
@@ -99,9 +86,13 @@ pub struct NodeConfig {
9986
#[serde(default)]
10087
pub port: u16,
10188

102-
/// IP version to use.
89+
/// Force IPv4-only mode.
90+
///
91+
/// When true, the node binds only on IPv4 instead of dual-stack.
92+
/// Use this on hosts without working IPv6 to avoid advertising
93+
/// unreachable addresses to the DHT.
10394
#[serde(default)]
104-
pub ip_version: IpVersion,
95+
pub ipv4_only: bool,
10596

10697
/// Bootstrap peer addresses.
10798
#[serde(default)]
@@ -249,7 +240,7 @@ impl Default for NodeConfig {
249240
Self {
250241
root_dir: default_root_dir(),
251242
port: 0,
252-
ip_version: IpVersion::default(),
243+
ipv4_only: false,
253244
bootstrap: Vec::new(),
254245
network_mode: NetworkMode::default(),
255246
testnet: TestnetConfig::default(),

src/node.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::ant_protocol::{CHUNK_PROTOCOL_ID, MAX_CHUNK_SIZE};
44
use crate::config::{
5-
default_nodes_dir, default_root_dir, EvmNetworkConfig, IpVersion, NetworkMode, NodeConfig,
5+
default_nodes_dir, default_root_dir, EvmNetworkConfig, NetworkMode, NodeConfig,
66
NODE_IDENTITY_FILENAME,
77
};
88
use crate::error::{Error, Result};
@@ -151,12 +151,11 @@ impl NodeBuilder {
151151

152152
/// Build the saorsa-core `NodeConfig` from our config.
153153
fn build_core_config(config: &NodeConfig) -> Result<CoreNodeConfig> {
154-
let ipv6 = matches!(config.ip_version, IpVersion::Ipv6 | IpVersion::Dual);
155154
let local = matches!(config.network_mode, NetworkMode::Development);
156155

157156
let mut core_config = CoreNodeConfig::builder()
158157
.port(config.port)
159-
.ipv6(ipv6)
158+
.ipv6(!config.ipv4_only)
160159
.local(local)
161160
.max_message_size(config.max_message_size)
162161
.build()
@@ -862,6 +861,23 @@ mod tests {
862861
assert!(core.diversity_config.is_some());
863862
}
864863

864+
#[test]
865+
fn test_build_core_config_ipv4_only() {
866+
let config = NodeConfig {
867+
ipv4_only: true,
868+
..Default::default()
869+
};
870+
let core = NodeBuilder::build_core_config(&config).expect("core config");
871+
assert!(!core.ipv6, "ipv4_only should disable IPv6");
872+
}
873+
874+
#[test]
875+
fn test_build_core_config_dual_stack_by_default() {
876+
let config = NodeConfig::default();
877+
let core = NodeBuilder::build_core_config(&config).expect("core config");
878+
assert!(core.ipv6, "dual-stack should be the default");
879+
}
880+
865881
#[test]
866882
fn test_build_core_config_sets_development_mode_permissive() {
867883
let config = NodeConfig {

0 commit comments

Comments
 (0)