mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-29 17:18:08 -05:00
feat(cli): add missing --port argument (#1917)
This commit is contained in:
@@ -44,6 +44,10 @@ pub struct NetworkArgs {
|
||||
/// NAT resolution method.
|
||||
#[arg(long, default_value = "any")]
|
||||
pub nat: NatResolver,
|
||||
|
||||
/// Network listening port. default: 30303
|
||||
#[arg(long = "port", value_name = "PORT")]
|
||||
pub port: Option<u16>,
|
||||
}
|
||||
|
||||
impl NetworkArgs {
|
||||
@@ -82,18 +86,18 @@ impl NetworkArgs {
|
||||
pub struct DiscoveryArgs {
|
||||
/// Disable the discovery service.
|
||||
#[arg(short, long)]
|
||||
disable_discovery: bool,
|
||||
pub disable_discovery: bool,
|
||||
|
||||
/// Disable the DNS discovery.
|
||||
#[arg(long, conflicts_with = "disable_discovery")]
|
||||
disable_dns_discovery: bool,
|
||||
pub disable_dns_discovery: bool,
|
||||
|
||||
/// Disable Discv4 discovery.
|
||||
#[arg(long, conflicts_with = "disable_discovery")]
|
||||
disable_discv4_discovery: bool,
|
||||
pub disable_discv4_discovery: bool,
|
||||
|
||||
/// The UDP port to use for P2P discovery/networking.
|
||||
#[arg(long = "discovery.port")]
|
||||
/// The UDP port to use for P2P discovery/networking. default: 30303
|
||||
#[arg(long = "discovery.port", name = "discovery.port", value_name = "DISCOVERY_PORT")]
|
||||
pub port: Option<u16>,
|
||||
}
|
||||
|
||||
|
||||
@@ -482,6 +482,10 @@ impl Command {
|
||||
.with_task_executor(Box::new(executor))
|
||||
.set_head(head)
|
||||
.listener_addr(SocketAddr::V4(SocketAddrV4::new(
|
||||
Ipv4Addr::UNSPECIFIED,
|
||||
self.network.port.unwrap_or(DEFAULT_DISCOVERY_PORT),
|
||||
)))
|
||||
.discovery_addr(SocketAddr::V4(SocketAddrV4::new(
|
||||
Ipv4Addr::UNSPECIFIED,
|
||||
self.network.discovery.port.unwrap_or(DEFAULT_DISCOVERY_PORT),
|
||||
)))
|
||||
@@ -611,4 +615,18 @@ mod tests {
|
||||
assert_eq!(args.chain.chain, chain.parse().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_discovery_port() {
|
||||
let cmd = Command::try_parse_from(["reth", "--discovery.port", "300"]).unwrap();
|
||||
assert_eq!(cmd.network.discovery.port, Some(300));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_port() {
|
||||
let cmd =
|
||||
Command::try_parse_from(["reth", "--discovery.port", "300", "--port", "99"]).unwrap();
|
||||
assert_eq!(cmd.network.discovery.port, Some(300));
|
||||
assert_eq!(cmd.network.port, Some(99));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,6 +231,16 @@ impl NetworkConfigBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the discovery and listener address
|
||||
///
|
||||
/// This is a convenience function for both [NetworkConfigBuilder::listener_addr] and
|
||||
/// [NetworkConfigBuilder::discovery_addr].
|
||||
///
|
||||
/// By default, both are on the same port: [DEFAULT_DISCOVERY_PORT]
|
||||
pub fn set_addrs(self, addr: SocketAddr) -> Self {
|
||||
self.listener_addr(addr).discovery_addr(addr)
|
||||
}
|
||||
|
||||
/// Sets the socket address the network will listen on
|
||||
pub fn listener_addr(mut self, listener_addr: SocketAddr) -> Self {
|
||||
self.listener_addr = Some(listener_addr);
|
||||
|
||||
Reference in New Issue
Block a user