MCPcopy Create free account
hub / github.com/SeismicSystems/summit / resolve_external_ip

Function resolve_external_ip

node/src/nat.rs:13–36  ·  view source on GitHub ↗

Resolves the node's external IP by querying well-known services. Returns the first successful result, or `None` if all fail.

()

Source from the content-addressed store, hash-verified

11/// Resolves the node's external IP by querying well-known services.
12/// Returns the first successful result, or `None` if all fail.
13pub async fn resolve_external_ip() -> Option<IpAddr> {
14 let client = reqwest::Client::builder()
15 .timeout(std::time::Duration::from_secs(10))
16 .build()
17 .ok()?;
18
19 for &url in EXTERNAL_IP_SERVICES {
20 match client.get(url).send().await {
21 Ok(resp) => match resp.text().await {
22 Ok(body) => match body.trim().parse::<IpAddr>() {
23 Ok(ip) => {
24 debug!(%ip, service = url, "resolved external IP");
25 return Some(ip);
26 }
27 Err(e) => warn!(service = url, error = %e, "failed to parse IP response"),
28 },
29 Err(e) => warn!(service = url, error = %e, "failed to read response body"),
30 },
31 Err(e) => warn!(service = url, error = %e, "failed to query IP service"),
32 }
33 }
34
35 None
36}

Callers 1

get_node_ipFunction · 0.85

Calls 3

sendMethod · 0.80
getMethod · 0.80
buildMethod · 0.45

Tested by

no test coverage detected