From 7db61eeadbe7486c41dfa38c0ac95ea976d9d11b Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Sat, 26 Nov 2022 14:46:57 +0100 Subject: [PATCH] misc(net): discovery docs and renames (#268) --- crates/net/network/src/discovery.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/net/network/src/discovery.rs b/crates/net/network/src/discovery.rs index b8a93f294..469710033 100644 --- a/crates/net/network/src/discovery.rs +++ b/crates/net/network/src/discovery.rs @@ -25,11 +25,11 @@ pub struct Discovery { local_enr: NodeRecord, /// Handler to interact with the Discovery v4 service discv4: Discv4, - /// All updates from the discv4 service. + /// All KAD table updates from the discv4 service. discv4_updates: ReceiverStream, /// The initial config for the discv4 service dsicv4_config: Discv4Config, - /// Buffered events until polled. + /// Events buffered until polled. queued_events: VecDeque, /// The handle to the spawned discv4 service _discv4_service: JoinHandle<()>, @@ -72,7 +72,9 @@ impl Discovery { } /// Manually adds an address to the set. - pub(crate) fn add_known_address(&mut self, peer_id: PeerId, addr: SocketAddr) { + /// + /// This has the same effect as adding node discovered via network gossip. + pub(crate) fn add_node_address(&mut self, peer_id: PeerId, addr: SocketAddr) { self.on_discv4_update(TableUpdate::Added(NodeRecord { address: addr.ip(), tcp_port: addr.port(), @@ -82,7 +84,7 @@ impl Discovery { } /// Returns all nodes we know exist in the network. - pub fn known_nodes(&mut self) -> &HashMap { + pub fn nodes(&mut self) -> &HashMap { &self.discovered_nodes } @@ -117,6 +119,7 @@ impl Discovery { return Poll::Ready(event) } + // drain the update stream while let Poll::Ready(Some(update)) = self.discv4_updates.poll_next_unpin(cx) { self.on_discv4_update(update) } @@ -125,7 +128,6 @@ impl Discovery { return Poll::Pending } } - // drain the update stream } }