Skip to content
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions crates/networking/p2p/discv4/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,18 @@ impl DiscoveryServer {
}

async fn lookup(&mut self) -> Result<(), DiscoveryServerError> {
// Sending the same FindNode message to all contacts to optimize message creation and encoding
let expiration: u64 = get_msg_expiration_from_seconds(EXPIRATION_SECONDS);
let random_priv_key = SecretKey::new(&mut OsRng);
let random_pub_key = public_key_from_signing_key(&random_priv_key);
let msg = Message::FindNode(FindNodeMessage::new(random_pub_key, expiration));
let mut buf = BytesMut::new();
msg.encode_with_header(&mut buf, &self.signer);

for contact in self.peer_table.get_contacts_for_lookup().await? {
if self.send_find_node(&contact.node).await.is_err() {
if self.udp_socket.send_to(&buf, &contact.node.udp_addr()).await.inspect_err(
|e| error!(sending = ?msg, addr = ?&contact.node.udp_addr(), err=?e, "Error sending message"),
).is_err() {
self.peer_table
.set_disposable(&contact.node.node_id())
.await?;
Expand Down Expand Up @@ -309,20 +319,6 @@ impl DiscoveryServer {
Ok(())
}

async fn send_find_node(&self, node: &Node) -> Result<(), DiscoveryServerError> {
let expiration: u64 = get_msg_expiration_from_seconds(EXPIRATION_SECONDS);

let random_priv_key = SecretKey::new(&mut OsRng);
let random_pub_key = public_key_from_signing_key(&random_priv_key);

let msg = Message::FindNode(FindNodeMessage::new(random_pub_key, expiration));
self.send(msg, node.udp_addr()).await?;

debug!(sent = "FindNode", to = %format!("{:#x}", node.public_key));

Ok(())
}

async fn send_neighbors(
&self,
neighbors: Vec<Node>,
Expand Down
Loading