Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

Commit

Permalink
Use public-ip as fallback (#295)
Browse files Browse the repository at this point in the history
  • Loading branch information
shalzz authored Sep 14, 2022
1 parent 49aaa08 commit 5938dad
Show file tree
Hide file tree
Showing 3 changed files with 215 additions and 9 deletions.
214 changes: 206 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ hashbrown = { version = "0.12.0", features = [
"ahash-compile-time-rng",
] }
dashmap = "5.3"
public-ip = "0.2.2"

[target.'cfg(target_os = "linux")'.dependencies]
e2p-fileflags = { git = "https://github.com/michaellass/e2p-fileflags" }
Expand Down
9 changes: 8 additions & 1 deletion src/sentry/devp2p/disc/v4/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,14 @@ impl Node {
node_endpoint.write().address = Ip(v);
}
Err(e) => {
debug!("Failed to get public IP: {}", e);
debug!("Failed to get public IP via UPNP: {}", e);
debug!("Trying with public_ip DNS/HTTP resolvers");
if let Some(v) = public_ip::addr().await {
debug!("Discovered public IP: {}", v);
node_endpoint.write().address = Ip(v);
} else {
debug!("Failed to get public IP via DNS/HTTP resolvers");
}
}
}
sleep(UPNP_INTERVAL).await;
Expand Down

0 comments on commit 5938dad

Please sign in to comment.