Skip to content

Commit 8734480

Browse files
committed
Improve external IP detection for Docker compatibility
- Add multiple IP detection services for better reliability - Filter out Docker internal IPs (172.x, 192.168.x) - Increase timeout and add connection timeout for curl - Better fallback mechanisms for containerized environments
1 parent 3be7597 commit 8734480

1 file changed

Lines changed: 25 additions & 12 deletions

File tree

development/qnet-integration/src/unified_p2p.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,18 +1555,31 @@ impl SimplifiedP2P {
15551555
async fn get_our_ip_address() -> Result<String, Box<dyn std::error::Error>> {
15561556
use std::process::Command;
15571557

1558-
// Try to get public IP first
1559-
if let Ok(output) = Command::new("curl")
1560-
.arg("-s")
1561-
.arg("--max-time")
1562-
.arg("3")
1563-
.arg("https://api.ipify.org")
1564-
.output() {
1565-
if output.status.success() {
1566-
if let Ok(ip) = String::from_utf8(output.stdout) {
1567-
let ip = ip.trim();
1568-
if !ip.is_empty() && ip != "0.0.0.0" {
1569-
return Ok(ip.to_string());
1558+
// PRODUCTION FIX: Try multiple IP detection services for Docker compatibility
1559+
let ip_services = vec![
1560+
"https://api.ipify.org",
1561+
"https://ipv4.icanhazip.com",
1562+
"https://checkip.amazonaws.com",
1563+
"https://ident.me",
1564+
];
1565+
1566+
// Try to get public IP from multiple services
1567+
for service in ip_services {
1568+
if let Ok(output) = Command::new("curl")
1569+
.arg("-s")
1570+
.arg("--max-time")
1571+
.arg("5")
1572+
.arg("--connect-timeout")
1573+
.arg("3")
1574+
.arg(service)
1575+
.output() {
1576+
if output.status.success() {
1577+
if let Ok(ip) = String::from_utf8(output.stdout) {
1578+
let ip = ip.trim();
1579+
if !ip.is_empty() && ip != "0.0.0.0" && !ip.starts_with("172.") && !ip.starts_with("192.168.") {
1580+
println!("[P2P] 🔍 External IP detected via {}: {}", service, ip);
1581+
return Ok(ip.to_string());
1582+
}
15701583
}
15711584
}
15721585
}

0 commit comments

Comments
 (0)