fix(discv5): no address cli arg (#8130)

This commit is contained in:
Emilia Hane
2024-05-06 21:51:02 +02:00
committed by GitHub
parent 077f7310c7
commit c79c188745
2 changed files with 29 additions and 5 deletions

View File

@ -141,11 +141,16 @@ impl<C> NetworkConfig<C> {
self
}
/// Sets the address for the incoming connection listener.
/// Sets the address for the incoming RLPx connection listener.
pub fn set_listener_addr(mut self, listener_addr: SocketAddr) -> Self {
self.listener_addr = listener_addr;
self
}
/// Returns the address for the incoming RLPx connection listener.
pub fn listener_addr(&self) -> &SocketAddr {
&self.listener_addr
}
}
impl<C> NetworkConfig<C>

View File

@ -27,7 +27,7 @@ use reth_provider::{
use reth_tasks::TaskExecutor;
use secp256k1::SecretKey;
use std::{
net::{SocketAddr, SocketAddrV4, SocketAddrV6},
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6},
path::PathBuf,
sync::Arc,
};
@ -482,13 +482,14 @@ impl NodeConfig {
return config
}
let rlpx_addr = config.listener_addr().ip();
// work around since discv5 config builder can't be integrated into network config builder
// due to unsatisfied trait bounds
config.discovery_v5_with_config_builder(|builder| {
let DiscoveryArgs {
discv5_addr: discv5_addr_ipv4,
discv5_addr,
discv5_addr_ipv6,
discv5_port: discv5_port_ipv4,
discv5_port,
discv5_port_ipv6,
discv5_lookup_interval,
discv5_bootstrap_lookup_interval,
@ -496,7 +497,9 @@ impl NodeConfig {
..
} = self.network.discovery;
let discv5_port_ipv4 = discv5_port_ipv4 + self.instance - 1;
let discv5_addr_ipv4 = discv5_addr.or_else(|| ipv4(rlpx_addr));
let discv5_addr_ipv6 = discv5_addr_ipv6.or_else(|| ipv6(rlpx_addr));
let discv5_port_ipv4 = discv5_port + self.instance - 1;
let discv5_port_ipv6 = discv5_port_ipv6 + self.instance - 1;
builder
@ -548,3 +551,19 @@ impl Default for NodeConfig {
}
}
}
/// Returns the address if this is an [`Ipv4Addr`].
pub fn ipv4(ip: IpAddr) -> Option<Ipv4Addr> {
match ip {
IpAddr::V4(ip) => Some(ip),
IpAddr::V6(_) => None,
}
}
/// Returns the address if this is an [`Ipv6Addr`].
pub fn ipv6(ip: IpAddr) -> Option<Ipv6Addr> {
match ip {
IpAddr::V4(_) => None,
IpAddr::V6(ip) => Some(ip),
}
}