fix: prevent node info zero address (#4268)

This commit is contained in:
Matthias Seitz
2023-08-18 17:07:30 +02:00
committed by GitHub
parent 2904745650
commit 849a47efb8

View File

@ -186,7 +186,17 @@ impl PeersInfo for NetworkHandle {
fn local_node_record(&self) -> NodeRecord {
let id = *self.peer_id();
let socket_addr = *self.inner.listener_address.lock();
let mut socket_addr = *self.inner.listener_address.lock();
if socket_addr.ip().is_unspecified() {
// zero address is invalid
if socket_addr.ip().is_ipv4() {
socket_addr.set_ip(std::net::IpAddr::V4(std::net::Ipv4Addr::LOCALHOST));
} else {
socket_addr.set_ip(std::net::IpAddr::V6(std::net::Ipv6Addr::LOCALHOST));
}
}
NodeRecord::new(socket_addr, id)
}
}