mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-10 15:58:27 -05:00
fix: resolve external ip on launch (#16768)
This commit is contained in:
@@ -252,7 +252,12 @@ impl Discv4 {
|
||||
local_node_record.udp_port = local_addr.port();
|
||||
trace!(target: "discv4", ?local_addr,"opened UDP socket");
|
||||
|
||||
let service = Discv4Service::new(socket, local_addr, local_node_record, secret_key, config);
|
||||
let mut service =
|
||||
Discv4Service::new(socket, local_addr, local_node_record, secret_key, config);
|
||||
|
||||
// resolve the external address immediately
|
||||
service.resolve_external_ip();
|
||||
|
||||
let discv4 = service.handle();
|
||||
Ok((discv4, service))
|
||||
}
|
||||
@@ -620,6 +625,15 @@ impl Discv4Service {
|
||||
self.lookup_interval = tokio::time::interval(duration);
|
||||
}
|
||||
|
||||
/// Sets the external Ip to the configured external IP if [`NatResolver::ExternalIp`].
|
||||
fn resolve_external_ip(&mut self) {
|
||||
if let Some(r) = &self.resolve_external_ip_interval {
|
||||
if let Some(external_ip) = r.resolver().as_external_ip() {
|
||||
self.set_external_ip_addr(external_ip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the given ip address as the node's external IP in the node record announced in
|
||||
/// discovery
|
||||
pub fn set_external_ip_addr(&mut self, external_ip: IpAddr) {
|
||||
|
||||
@@ -161,6 +161,11 @@ impl ResolveNatInterval {
|
||||
Self::with_interval(resolver, interval)
|
||||
}
|
||||
|
||||
/// Returns the resolver used by this interval
|
||||
pub const fn resolver(&self) -> &NatResolver {
|
||||
&self.resolver
|
||||
}
|
||||
|
||||
/// Completes when the next [`IpAddr`] in the interval has been reached.
|
||||
pub async fn tick(&mut self) -> Option<IpAddr> {
|
||||
poll_fn(|cx| self.poll_tick(cx)).await
|
||||
|
||||
Reference in New Issue
Block a user