Created
September 19, 2023 00:51
-
-
Save jmcph4/17ba2dec780aedecb1b174acf04a0a95 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/beacon_node/lighthouse_network/src/config.rs b/beacon_node/lighthouse_network/src/config.rs | |
| index d8c3f619d..22ee558c0 100644 | |
| --- a/beacon_node/lighthouse_network/src/config.rs | |
| +++ b/beacon_node/lighthouse_network/src/config.rs | |
| @@ -16,6 +16,11 @@ use std::sync::Arc; | |
| use std::time::Duration; | |
| use types::{ForkContext, ForkName}; | |
| +pub const DEFAULT_IPV4_ADDRESS: Ipv4Addr = Ipv4Addr::UNSPECIFIED; | |
| +pub const DEFAULT_UDP_DISC_PORT: u16 = 9000; | |
| +pub const DEFAULT_UDP_QUIC_PORT: u16 = 9001; | |
| +pub const DEFAULT_TCP_PORT: u16 = 9000; | |
| + | |
| /// The cache time is set to accommodate the circulation time of an attestation. | |
| /// | |
| /// The p2p spec declares that we accept attestations within the following range: | |
| @@ -304,14 +309,14 @@ impl Default for Config { | |
| .expect("The total rate limit has been specified"), | |
| ); | |
| let listen_addresses = ListenAddress::V4(ListenAddr { | |
| - addr: Ipv4Addr::UNSPECIFIED, | |
| - disc_port: 9000, | |
| - quic_port: 9001, | |
| - tcp_port: 9000, | |
| + addr: DEFAULT_IPV4_ADDRESS, | |
| + disc_port: DEFAULT_UDP_DISC_PORT, | |
| + quic_port: DEFAULT_UDP_QUIC_PORT, | |
| + tcp_port: DEFAULT_TCP_PORT, | |
| }); | |
| let discv5_listen_config = | |
| - discv5::ListenConfig::from_ip(Ipv4Addr::UNSPECIFIED.into(), 9000); | |
| + discv5::ListenConfig::from_ip(DEFAULT_IPV4_ADDRESS.into(), DEFAULT_UDP_DISC_PORT); | |
| // discv5 configuration | |
| let discv5_config = Discv5ConfigBuilder::new(discv5_listen_config) | |
| diff --git a/beacon_node/lighthouse_network/src/discovery/mod.rs b/beacon_node/lighthouse_network/src/discovery/mod.rs | |
| index 4d8807336..35207b5a0 100644 | |
| --- a/beacon_node/lighthouse_network/src/discovery/mod.rs | |
| +++ b/beacon_node/lighthouse_network/src/discovery/mod.rs | |
| @@ -7,6 +7,7 @@ pub(crate) mod enr; | |
| pub mod enr_ext; | |
| // Allow external use of the lighthouse ENR builder | |
| +use crate::multiaddr::Protocol; | |
| use crate::service::TARGET_SUBNET_PEERS; | |
| use crate::{error, Enr, NetworkConfig, NetworkGlobals, Subnet, SubnetDiscovery}; | |
| use crate::{metrics, ClearDialError}; | |
| @@ -21,6 +22,7 @@ pub use libp2p::identity::{Keypair, PublicKey}; | |
| use enr::{ATTESTATION_BITFIELD_ENR_KEY, ETH2_ENR_KEY, SYNC_COMMITTEE_BITFIELD_ENR_KEY}; | |
| use futures::prelude::*; | |
| use futures::stream::FuturesUnordered; | |
| +use libp2p::multiaddr::Protocol; | |
| use libp2p::swarm::behaviour::{DialFailure, FromSwarm}; | |
| use libp2p::swarm::THandlerInEvent; | |
| pub use libp2p::{ | |
| @@ -34,6 +36,7 @@ pub use libp2p::{ | |
| use lru::LruCache; | |
| use slog::{crit, debug, error, info, trace, warn}; | |
| use ssz::Encode; | |
| +use std::net::{Ipv4Addr, SocketAddrV4, SocketAddrV6}; | |
| use std::{ | |
| collections::{HashMap, VecDeque}, | |
| net::{IpAddr, SocketAddr}, | |
| @@ -74,7 +77,7 @@ const DURATION_DIFFERENCE: Duration = Duration::from_millis(1); | |
| /// of the peer if it is specified. | |
| #[derive(Debug)] | |
| pub struct DiscoveredPeers { | |
| - pub peers: HashMap<Enr, Option<Instant>>, | |
| + pub peers: HashMap<PeerId, Option<Instant>>, | |
| } | |
| #[derive(Clone, PartialEq)] | |
| @@ -207,8 +210,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> { | |
| let local_node_id = local_enr.node_id(); | |
| info!(log, "ENR Initialised"; "enr" => local_enr.to_base64(), "seq" => local_enr.seq(), "id"=> %local_enr.node_id(), | |
| - "ip4" => ?local_enr.ip4(), "udp4"=> ?local_enr.udp4(), "tcp4" => ?local_enr.tcp4(), "tcp6" => ?local_enr.tcp6(), "udp6" => ?local_enr.udp6(), | |
| - "quic4" => ?local_enr.quic4(), "quic6" => ?local_enr.quic6() | |
| + "ip4" => ?local_enr.ip4(), "udp4"=> ?local_enr.udp4(), "tcp4" => ?local_enr.tcp4(), "tcp6" => ?local_enr.tcp6(), "udp6" => ?local_enr.udp6() | |
| ); | |
| // convert the keypair into an ENR key | |
| @@ -230,8 +232,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> { | |
| "peer_id" => %bootnode_enr.peer_id(), | |
| "ip" => ?bootnode_enr.ip4(), | |
| "udp" => ?bootnode_enr.udp4(), | |
| - "tcp" => ?bootnode_enr.tcp4(), | |
| - "quic" => ?bootnode_enr.quic4() | |
| + "tcp" => ?bootnode_enr.tcp4() | |
| ); | |
| let repr = bootnode_enr.to_string(); | |
| let _ = discv5.add_enr(bootnode_enr).map_err(|e| { | |
| @@ -282,8 +283,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> { | |
| "peer_id" => %enr.peer_id(), | |
| "ip" => ?enr.ip4(), | |
| "udp" => ?enr.udp4(), | |
| - "tcp" => ?enr.tcp4(), | |
| - "quic" => ?enr.quic4() | |
| + "tcp" => ?enr.tcp4() | |
| ); | |
| let _ = discv5.add_enr(enr).map_err(|e| { | |
| error!( | |
| @@ -385,6 +385,20 @@ impl<TSpec: EthSpec> Discovery<TSpec> { | |
| self.discv5.table_entries_enr() | |
| } | |
| + /// Returns the ENR of a known peer if it exists. | |
| + pub fn enr_of_peer(&mut self, peer_id: &PeerId) -> Option<Enr> { | |
| + // first search the local cache | |
| + if let Some(enr) = self.cached_enrs.get(peer_id) { | |
| + return Some(enr.clone()); | |
| + } | |
| + // not in the local cache, look in the routing table | |
| + if let Ok(node_id) = enr_ext::peer_id_to_node_id(peer_id) { | |
| + self.discv5.find_enr(&node_id) | |
| + } else { | |
| + None | |
| + } | |
| + } | |
| + | |
| /// Updates the local ENR TCP port. | |
| /// There currently isn't a case to update the address here. We opt for discovery to | |
| /// automatically update the external address. | |
| @@ -402,23 +416,6 @@ impl<TSpec: EthSpec> Discovery<TSpec> { | |
| Ok(()) | |
| } | |
| - // TODO: Group these functions here once the ENR is shared across discv5 and lighthouse and | |
| - // Lighthouse can modify the ENR directly. | |
| - // This currently doesn't support ipv6. All of these functions should be removed and | |
| - // addressed properly in the following issue. | |
| - // https://github.com/sigp/lighthouse/issues/4706 | |
| - pub fn update_enr_quic_port(&mut self, port: u16) -> Result<(), String> { | |
| - self.discv5 | |
| - .enr_insert("quic", &port) | |
| - .map_err(|e| format!("{:?}", e))?; | |
| - | |
| - // replace the global version | |
| - *self.network_globals.local_enr.write() = self.discv5.local_enr(); | |
| - // persist modified enr to disk | |
| - enr::save_enr_to_disk(Path::new(&self.enr_dir), &self.local_enr(), &self.log); | |
| - Ok(()) | |
| - } | |
| - | |
| /// Updates the local ENR UDP socket. | |
| /// | |
| /// This is with caution. Discovery should automatically maintain this. This should only be | |
| @@ -738,6 +735,23 @@ impl<TSpec: EthSpec> Discovery<TSpec> { | |
| target_peers: usize, | |
| additional_predicate: impl Fn(&Enr) -> bool + Send + 'static, | |
| ) { | |
| + // Make sure there are subnet queries included | |
| + let contains_queries = match &query { | |
| + QueryType::Subnet(queries) => !queries.is_empty(), | |
| + QueryType::FindPeers => true, | |
| + }; | |
| + | |
| + if !contains_queries { | |
| + debug!( | |
| + self.log, | |
| + "No subnets included in this request. Skipping discovery request." | |
| + ); | |
| + return; | |
| + } | |
| + | |
| + // Generate a random target node id. | |
| + let random_node = NodeId::random(); | |
| + | |
| let enr_fork_id = match self.local_enr().eth2() { | |
| Ok(v) => v, | |
| Err(e) => { | |
| @@ -761,8 +775,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> { | |
| // Build the future | |
| let query_future = self | |
| .discv5 | |
| - // Generate a random target node id. | |
| - .find_node_predicate(NodeId::random(), predicate, target_peers) | |
| + .find_node_predicate(random_node, predicate, target_peers) | |
| .map(|v| QueryResult { | |
| query_type: query, | |
| result: v, | |
| @@ -776,7 +789,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> { | |
| fn process_completed_queries( | |
| &mut self, | |
| query: QueryResult, | |
| - ) -> Option<HashMap<Enr, Option<Instant>>> { | |
| + ) -> Option<HashMap<PeerId, Option<Instant>>> { | |
| match query.query_type { | |
| QueryType::FindPeers => { | |
| self.find_peer_active = false; | |
| @@ -786,14 +799,12 @@ impl<TSpec: EthSpec> Discovery<TSpec> { | |
| } | |
| Ok(r) => { | |
| debug!(self.log, "Discovery query completed"; "peers_found" => r.len()); | |
| - let results = r | |
| - .into_iter() | |
| - .map(|enr| { | |
| - // cache the found ENR's | |
| - self.cached_enrs.put(enr.peer_id(), enr.clone()); | |
| - (enr, None) | |
| - }) | |
| - .collect(); | |
| + let mut results: HashMap<_, Option<Instant>> = HashMap::new(); | |
| + r.iter().for_each(|enr| { | |
| + // cache the found ENR's | |
| + self.cached_enrs.put(enr.peer_id(), enr.clone()); | |
| + results.insert(enr.peer_id(), None); | |
| + }); | |
| return Some(results); | |
| } | |
| Err(e) => { | |
| @@ -841,17 +852,17 @@ impl<TSpec: EthSpec> Discovery<TSpec> { | |
| let subnet_predicate = | |
| subnet_predicate::<TSpec>(vec![query.subnet], &self.log); | |
| - r.clone() | |
| - .into_iter() | |
| + r.iter() | |
| .filter(|enr| subnet_predicate(enr)) | |
| - .for_each(|enr| { | |
| + .map(|enr| enr.peer_id()) | |
| + .for_each(|peer_id| { | |
| if let Some(v) = metrics::get_int_counter( | |
| &metrics::SUBNET_PEERS_FOUND, | |
| &[query_str], | |
| ) { | |
| v.inc(); | |
| } | |
| - let other_min_ttl = mapped_results.get_mut(&enr); | |
| + let other_min_ttl = mapped_results.get_mut(&peer_id); | |
| // map peer IDs to the min_ttl furthest in the future | |
| match (query.min_ttl, other_min_ttl) { | |
| @@ -869,11 +880,15 @@ impl<TSpec: EthSpec> Discovery<TSpec> { | |
| } | |
| // update the mapping if we have a specified min_ttl | |
| (Some(min_ttl), Some(None)) => { | |
| - mapped_results.insert(enr, Some(min_ttl)); | |
| + mapped_results.insert(peer_id, Some(min_ttl)); | |
| + } | |
| + // first seen min_ttl for this enr | |
| + (Some(min_ttl), None) => { | |
| + mapped_results.insert(peer_id, Some(min_ttl)); | |
| } | |
| // first seen min_ttl for this enr | |
| - (min_ttl, None) => { | |
| - mapped_results.insert(enr, min_ttl); | |
| + (None, None) => { | |
| + mapped_results.insert(peer_id, None); | |
| } | |
| (None, Some(Some(_))) => {} // Don't replace the existing specific min_ttl | |
| (None, Some(None)) => {} // No-op because this is a duplicate | |
| @@ -897,7 +912,7 @@ impl<TSpec: EthSpec> Discovery<TSpec> { | |
| } | |
| /// Drives the queries returning any results from completed queries. | |
| - fn poll_queries(&mut self, cx: &mut Context) -> Option<HashMap<Enr, Option<Instant>>> { | |
| + fn poll_queries(&mut self, cx: &mut Context) -> Option<HashMap<PeerId, Option<Instant>>> { | |
| while let Poll::Ready(Some(query_result)) = self.active_queries.poll_next_unpin(cx) { | |
| let result = self.process_completed_queries(query_result); | |
| if result.is_some() { | |
| @@ -944,6 +959,23 @@ impl<TSpec: EthSpec> NetworkBehaviour for Discovery<TSpec> { | |
| ) { | |
| } | |
| + fn handle_pending_outbound_connection( | |
| + &mut self, | |
| + _connection_id: ConnectionId, | |
| + maybe_peer: Option<PeerId>, | |
| + _addresses: &[Multiaddr], | |
| + _effective_role: libp2p::core::Endpoint, | |
| + ) -> Result<Vec<Multiaddr>, libp2p::swarm::ConnectionDenied> { | |
| + if let Some(enr) = maybe_peer.and_then(|peer_id| self.enr_of_peer(&peer_id)) { | |
| + // ENR's may have multiple Multiaddrs. The multi-addr associated with the UDP | |
| + // port is removed, which is assumed to be associated with the discv5 protocol (and | |
| + // therefore irrelevant for other libp2p components). | |
| + Ok(enr.multiaddr_tcp()) | |
| + } else { | |
| + Ok(vec![]) | |
| + } | |
| + } | |
| + | |
| // Main execution loop to drive the behaviour | |
| fn poll( | |
| &mut self, | |
| @@ -1017,8 +1049,25 @@ impl<TSpec: EthSpec> NetworkBehaviour for Discovery<TSpec> { | |
| // update network globals | |
| *self.network_globals.local_enr.write() = enr; | |
| // A new UDP socket has been detected. | |
| - // NOTE: We assume libp2p itself can keep track of IP changes and we do | |
| - // not inform it about IP changes found via discovery. | |
| + // Build a multiaddr to report to libp2p | |
| + let addr = match socket_addr.ip() { | |
| + IpAddr::V4(v4_addr) => { | |
| + self.network_globals.listen_port_tcp4().map(|tcp4_port| { | |
| + Multiaddr::from(v4_addr).with(Protocol::Tcp(tcp4_port)) | |
| + }) | |
| + } | |
| + IpAddr::V6(v6_addr) => { | |
| + self.network_globals.listen_port_tcp6().map(|tcp6_port| { | |
| + Multiaddr::from(v6_addr).with(Protocol::Tcp(tcp6_port)) | |
| + }) | |
| + } | |
| + }; | |
| + | |
| + if let Some(address) = addr { | |
| + // NOTE: This doesn't actually track the external TCP port. More sophisticated NAT handling | |
| + // should handle this. | |
| + return Poll::Ready(ToSwarm::NewExternalAddrCandidate(address)); | |
| + } | |
| } | |
| Discv5Event::EnrAdded { .. } | |
| | Discv5Event::TalkRequest(_) | |
| @@ -1041,14 +1090,79 @@ impl<TSpec: EthSpec> NetworkBehaviour for Discovery<TSpec> { | |
| | FromSwarm::AddressChange(_) | |
| | FromSwarm::ListenFailure(_) | |
| | FromSwarm::NewListener(_) | |
| - | FromSwarm::NewListenAddr(_) | |
| | FromSwarm::ExpiredListenAddr(_) | |
| | FromSwarm::ListenerError(_) | |
| | FromSwarm::ListenerClosed(_) | |
| | FromSwarm::NewExternalAddrCandidate(_) | |
| | FromSwarm::ExternalAddrExpired(_) | |
| - | FromSwarm::ExternalAddrConfirmed(_) => { | |
| - // Ignore events not relevant to discovery | |
| + | FromSwarm::ExternalAddrConfirmed(_) => {} | |
| + FromSwarm::NewListenAddr(ev) => { | |
| + trace!(self.log, "Received NewListenAddr event from swarm"; "event" => ev); | |
| + | |
| + let user_port_override = || { | |
| + self.network_globals.listen_port_tcp4().is_some() | |
| + || self.network_globals.listen_port_tcp6().is_some() | |
| + }; | |
| + | |
| + if user_port_override() { | |
| + debug!(self.log, "Refusing to update ENR from libp2p due to presence of user-defined port numbers"); | |
| + return; | |
| + } | |
| + | |
| + let addr: Multiaddr = ev.addr.clone(); | |
| + let acceptable_multiaddr: bool = addr.iter().count() >= 2 | |
| + && addr | |
| + .iter() | |
| + .any(|x| matches!(x, Protocol::Ip4(_)) || matches!(x, Protocol::Ip6(_))) | |
| + && addr.iter().any(|x| matches!(x, Protocol::Tcp(_))); | |
| + let transport_is_tcp: bool = addr.iter().any(|x| matches!(x, Protocol::Tcp(_))); | |
| + | |
| + if acceptable_multiaddr { | |
| + let sock: SocketAddr = match (addr.iter().next(), addr.iter().nth(1)) { | |
| + (Some(Protocol::Ip4(ip4)), Some(Protocol::Tcp(tcp4))) => { | |
| + SocketAddr::V4(SocketAddrV4::new(ip4, tcp4)) | |
| + } | |
| + (Some(Protocol::Ip4(ip4)), Some(Protocol::Udp(udp4))) => { | |
| + SocketAddr::V4(SocketAddrV4::new(ip4, udp4)) | |
| + } | |
| + (Some(Protocol::Ip6(ip6)), Some(Protocol::Tcp(tcp6))) => { | |
| + SocketAddr::V6(SocketAddrV6::new(ip6, tcp6, 0, 0)) | |
| + } | |
| + (Some(Protocol::Ip6(ip6)), Some(Protocol::Udp(udp6))) => { | |
| + SocketAddr::V6(SocketAddrV6::new(ip6, udp6, 0, 0)) | |
| + } | |
| + _ => { | |
| + debug!(self.log, "Encountered multiaddr that was unacceptable for ENR advertisement"; "multiaddr" => ?addr); | |
| + return; | |
| + } | |
| + }; | |
| + | |
| + /* this closure shouldn't exist but `Ipv4Addr::is_global` is Nightly at the moment */ | |
| + let is_global = |ip: Ipv4Addr| { | |
| + !(ip.is_broadcast() | |
| + || ip.is_documentation() | |
| + || ip.is_link_local() | |
| + || ip.is_loopback() | |
| + || ip.is_multicast() | |
| + || ip.is_private() | |
| + || ip.is_unspecified()) | |
| + }; | |
| + | |
| + /* we need to perform this check so that we don't violate the ENR invariant: that every ENR-advertised address is publicly reachable */ | |
| + if let SocketAddr::V4(ip4) = sock { | |
| + if !is_global(*ip4.ip()) { | |
| + debug!(self.log, "Encountered multiaddr that was unacceptable for ENR advertisement (unreachable)"; "multiaddr" => ?addr); | |
| + return; | |
| + } | |
| + } | |
| + | |
| + self.discv5.update_local_enr_socket(sock, transport_is_tcp); | |
| + *self.network_globals.local_enr.write() = self.discv5.local_enr(); | |
| + | |
| + let local_enr: Enr = self.discv5.local_enr(); | |
| + info!(self.log, "Updated local ENR"; "enr" => local_enr.to_base64(), "seq" => local_enr.seq(), "id"=> %local_enr.node_id(), | |
| + "ip4" => ?local_enr.ip4(), "udp4"=> ?local_enr.udp4(), "tcp4" => ?local_enr.tcp4(), "tcp6" => ?local_enr.tcp6(), "udp6" => ?local_enr.udp6()); | |
| + } | |
| } | |
| } | |
| } | |
| @@ -1105,6 +1219,8 @@ mod tests { | |
| let log = build_log(slog::Level::Debug, false); | |
| let globals = NetworkGlobals::new( | |
| enr, | |
| + Some(9000), | |
| + None, | |
| MetaData::V2(MetaDataV2 { | |
| seq_number: 0, | |
| attnets: Default::default(), | |
| @@ -1212,6 +1328,6 @@ mod tests { | |
| assert_eq!(results.len(), 2); | |
| // when a peer belongs to multiple subnet ids, we use the highest ttl. | |
| - assert_eq!(results.get(&enr1).unwrap(), &instant1); | |
| + assert_eq!(results.get(&enr1.peer_id()).unwrap(), &instant1); | |
| } | |
| } | |
| diff --git a/lighthouse/tests/beacon_node.rs b/lighthouse/tests/beacon_node.rs | |
| index 10fcb101a..db4913900 100644 | |
| --- a/lighthouse/tests/beacon_node.rs | |
| +++ b/lighthouse/tests/beacon_node.rs | |
| @@ -22,7 +22,6 @@ use types::{ | |
| Address, Checkpoint, Epoch, ExecutionBlockHash, ForkName, Hash256, MainnetEthSpec, | |
| ProgressiveBalancesMode, | |
| }; | |
| -use unused_port::{unused_tcp4_port, unused_tcp6_port, unused_udp4_port, unused_udp6_port}; | |
| const DEFAULT_ETH1_ENDPOINT: &str = "http://localhost:8545/"; | |
| @@ -1004,7 +1003,7 @@ fn network_listen_address_flag_wrong_double_v6_value_config() { | |
| } | |
| #[test] | |
| fn network_port_flag_over_ipv4() { | |
| - let port = unused_tcp4_port().expect("Unable to find unused port."); | |
| + let port = 0; | |
| CommandLineTest::new() | |
| .flag("port", Some(port.to_string().as_str())) | |
| .run() | |
| @@ -1021,7 +1020,7 @@ fn network_port_flag_over_ipv4() { | |
| } | |
| #[test] | |
| fn network_port_flag_over_ipv6() { | |
| - let port = unused_tcp6_port().expect("Unable to find unused port."); | |
| + let port = 0; | |
| CommandLineTest::new() | |
| .flag("listen-address", Some("::1")) | |
| .flag("port", Some(port.to_string().as_str())) | |
| @@ -1039,8 +1038,8 @@ fn network_port_flag_over_ipv6() { | |
| } | |
| #[test] | |
| fn network_port_and_discovery_port_flags_over_ipv4() { | |
| - let tcp4_port = unused_tcp4_port().expect("Unable to find unused port."); | |
| - let disc4_port = unused_udp4_port().expect("Unable to find unused port."); | |
| + let tcp4_port = 0; | |
| + let udp4_port = 0; | |
| CommandLineTest::new() | |
| .flag("port", Some(tcp4_port.to_string().as_str())) | |
| .flag("discovery-port", Some(disc4_port.to_string().as_str())) | |
| @@ -1058,8 +1057,8 @@ fn network_port_and_discovery_port_flags_over_ipv4() { | |
| } | |
| #[test] | |
| fn network_port_and_discovery_port_flags_over_ipv6() { | |
| - let tcp6_port = unused_tcp6_port().expect("Unable to find unused port."); | |
| - let disc6_port = unused_udp6_port().expect("Unable to find unused port."); | |
| + let tcp6_port = 0; | |
| + let udp6_port = 0; | |
| CommandLineTest::new() | |
| .flag("listen-address", Some("::1")) | |
| .flag("port", Some(tcp6_port.to_string().as_str())) | |
| @@ -1078,10 +1077,10 @@ fn network_port_and_discovery_port_flags_over_ipv6() { | |
| } | |
| #[test] | |
| fn network_port_and_discovery_port_flags_over_ipv4_and_ipv6() { | |
| - let tcp4_port = unused_tcp4_port().expect("Unable to find unused port."); | |
| - let disc4_port = unused_udp4_port().expect("Unable to find unused port."); | |
| - let tcp6_port = unused_tcp6_port().expect("Unable to find unused port."); | |
| - let disc6_port = unused_udp6_port().expect("Unable to find unused port."); | |
| + let tcp4_port = 0; | |
| + let udp4_port = 0; | |
| + let tcp6_port = 0; | |
| + let udp6_port = 0; | |
| CommandLineTest::new() | |
| .flag("listen-address", Some("::1")) | |
| .flag("listen-address", Some("127.0.0.1")) | |
| @@ -1264,7 +1263,7 @@ fn network_load_flag() { | |
| // Tests for ENR flags. | |
| #[test] | |
| fn enr_udp_port_flag() { | |
| - let port = unused_udp4_port().expect("Unable to find unused port."); | |
| + let port = 0; | |
| CommandLineTest::new() | |
| .flag("enr-udp-port", Some(port.to_string().as_str())) | |
| .run_with_zero_port() | |
| @@ -1280,7 +1279,7 @@ fn enr_quic_port_flag() { | |
| } | |
| #[test] | |
| fn enr_tcp_port_flag() { | |
| - let port = unused_tcp4_port().expect("Unable to find unused port."); | |
| + let port = 0; | |
| CommandLineTest::new() | |
| .flag("enr-tcp-port", Some(port.to_string().as_str())) | |
| .run_with_zero_port() | |
| @@ -1288,7 +1287,7 @@ fn enr_tcp_port_flag() { | |
| } | |
| #[test] | |
| fn enr_udp6_port_flag() { | |
| - let port = unused_udp6_port().expect("Unable to find unused port."); | |
| + let port = 0; | |
| CommandLineTest::new() | |
| .flag("enr-udp6-port", Some(port.to_string().as_str())) | |
| .run_with_zero_port() | |
| @@ -1304,7 +1303,7 @@ fn enr_quic6_port_flag() { | |
| } | |
| #[test] | |
| fn enr_tcp6_port_flag() { | |
| - let port = unused_tcp6_port().expect("Unable to find unused port."); | |
| + let port = 0; | |
| CommandLineTest::new() | |
| .flag("enr-tcp6-port", Some(port.to_string().as_str())) | |
| .run_with_zero_port() | |
| @@ -1313,8 +1312,8 @@ fn enr_tcp6_port_flag() { | |
| #[test] | |
| fn enr_match_flag_over_ipv4() { | |
| let addr = "127.0.0.2".parse::<Ipv4Addr>().unwrap(); | |
| - let udp4_port = unused_udp4_port().expect("Unable to find unused port."); | |
| - let tcp4_port = unused_tcp4_port().expect("Unable to find unused port."); | |
| + let udp4_port = 0; | |
| + let tcp4_port = 0; | |
| CommandLineTest::new() | |
| .flag("enr-match", None) | |
| .flag("listen-address", Some("127.0.0.2")) | |
| @@ -1338,8 +1337,8 @@ fn enr_match_flag_over_ipv4() { | |
| fn enr_match_flag_over_ipv6() { | |
| const ADDR: &str = "::1"; | |
| let addr = ADDR.parse::<Ipv6Addr>().unwrap(); | |
| - let udp6_port = unused_udp6_port().expect("Unable to find unused port."); | |
| - let tcp6_port = unused_tcp6_port().expect("Unable to find unused port."); | |
| + let udp6_port = 0; | |
| + let tcp6_port = 0; | |
| CommandLineTest::new() | |
| .flag("enr-match", None) | |
| .flag("listen-address", Some(ADDR)) | |
| @@ -1363,12 +1362,12 @@ fn enr_match_flag_over_ipv6() { | |
| fn enr_match_flag_over_ipv4_and_ipv6() { | |
| const IPV6_ADDR: &str = "::1"; | |
| let ipv6_addr = IPV6_ADDR.parse::<Ipv6Addr>().unwrap(); | |
| - let udp6_port = unused_udp6_port().expect("Unable to find unused port."); | |
| - let tcp6_port = unused_tcp6_port().expect("Unable to find unused port."); | |
| + let udp6_port = 0; | |
| + let tcp6_port = 0; | |
| const IPV4_ADDR: &str = "127.0.0.1"; | |
| let ipv4_addr = IPV4_ADDR.parse::<Ipv4Addr>().unwrap(); | |
| - let udp4_port = unused_udp4_port().expect("Unable to find unused port."); | |
| - let tcp4_port = unused_tcp4_port().expect("Unable to find unused port."); | |
| + let udp4_port = 0; | |
| + let tcp4_port = 0; | |
| CommandLineTest::new() | |
| .flag("enr-match", None) | |
| .flag("listen-address", Some(IPV4_ADDR)) | |
| @@ -1406,7 +1405,7 @@ fn enr_match_flag_over_ipv4_and_ipv6() { | |
| #[test] | |
| fn enr_address_flag_with_ipv4() { | |
| let addr = "192.167.1.1".parse::<Ipv4Addr>().unwrap(); | |
| - let port = unused_udp4_port().expect("Unable to find unused port."); | |
| + let port = 0; | |
| CommandLineTest::new() | |
| .flag("enr-address", Some("192.167.1.1")) | |
| .flag("enr-udp-port", Some(port.to_string().as_str())) | |
| @@ -1419,7 +1418,7 @@ fn enr_address_flag_with_ipv4() { | |
| #[test] | |
| fn enr_address_flag_with_ipv6() { | |
| let addr = "192.167.1.1".parse::<Ipv4Addr>().unwrap(); | |
| - let port = unused_udp4_port().expect("Unable to find unused port."); | |
| + let port = 0; | |
| CommandLineTest::new() | |
| .flag("enr-address", Some("192.167.1.1")) | |
| .flag("enr-udp-port", Some(port.to_string().as_str())) | |
| @@ -1433,7 +1432,7 @@ fn enr_address_flag_with_ipv6() { | |
| fn enr_address_dns_flag() { | |
| let addr = Ipv4Addr::LOCALHOST; | |
| let ipv6addr = Ipv6Addr::LOCALHOST; | |
| - let port = unused_udp4_port().expect("Unable to find unused port."); | |
| + let port = 0; | |
| CommandLineTest::new() | |
| .flag("enr-address", Some("localhost")) | |
| .flag("enr-udp-port", Some(port.to_string().as_str())) | |
| @@ -1480,8 +1479,8 @@ fn http_address_ipv6_flag() { | |
| } | |
| #[test] | |
| fn http_port_flag() { | |
| - let port1 = unused_tcp4_port().expect("Unable to find unused port."); | |
| - let port2 = unused_tcp4_port().expect("Unable to find unused port."); | |
| + let port1 = 0; | |
| + let port2 = 0; | |
| CommandLineTest::new() | |
| .flag("http-port", Some(port1.to_string().as_str())) | |
| .flag("port", Some(port2.to_string().as_str())) | |
| @@ -1636,8 +1635,8 @@ fn metrics_address_ipv6_flag() { | |
| } | |
| #[test] | |
| fn metrics_port_flag() { | |
| - let port1 = unused_tcp4_port().expect("Unable to find unused port."); | |
| - let port2 = unused_tcp4_port().expect("Unable to find unused port."); | |
| + let port1 = 0; | |
| + let port2 = 0; | |
| CommandLineTest::new() | |
| .flag("metrics", None) | |
| .flag("metrics-port", Some(port1.to_string().as_str())) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment