Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Don't ping all nodes on start (#1656)
Browse files Browse the repository at this point in the history
* Don't ping all nodes on start

* Fixed test
  • Loading branch information
arkpar authored and gavofyork committed Jul 19, 2016
1 parent 4e447cc commit 340f0b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
14 changes: 8 additions & 6 deletions util/src/network/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,12 @@ impl Discovery {
}

/// Add a new node to discovery table. Pings the node.
pub fn add_node(&mut self, e: NodeEntry) {
pub fn add_node(&mut self, e: NodeEntry, new: bool) {
let endpoint = e.endpoint.clone();
self.update_node(e);
self.ping(&endpoint);
if new {
self.ping(&endpoint);
}
}

/// Add a list of known nodes to the table.
Expand Down Expand Up @@ -549,10 +551,10 @@ mod tests {

let node1 = Node::from_str("enode://a979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@127.0.0.1:7770").unwrap();
let node2 = Node::from_str("enode://b979fb575495b8d6db44f750317d0f4622bf4c2aa3365d6af7c284339968eef29b69ad0dce72a4d8db5ebb4968de0e3bec910127f134779fbcb0cb6d3331163c@127.0.0.1:7771").unwrap();
discovery1.add_node(NodeEntry { id: node1.id.clone(), endpoint: node1.endpoint.clone() });
discovery1.add_node(NodeEntry { id: node2.id.clone(), endpoint: node2.endpoint.clone() });
discovery1.add_node(NodeEntry { id: node1.id.clone(), endpoint: node1.endpoint.clone() }, true);
discovery1.add_node(NodeEntry { id: node2.id.clone(), endpoint: node2.endpoint.clone() }, true);

discovery2.add_node(NodeEntry { id: key1.public().clone(), endpoint: ep1.clone() });
discovery2.add_node(NodeEntry { id: key1.public().clone(), endpoint: ep1.clone() }, true);
discovery2.refresh();

for _ in 0 .. 10 {
Expand All @@ -579,7 +581,7 @@ mod tests {
let ep = NodeEndpoint { address: SocketAddr::from_str("127.0.0.1:40446").unwrap(), udp_port: 40447 };
let mut discovery = Discovery::new(&key, ep.address.clone(), ep.clone(), 0);
for _ in 0..1200 {
discovery.add_node(NodeEntry { id: NodeId::random(), endpoint: ep.clone() });
discovery.add_node(NodeEntry { id: NodeId::random(), endpoint: ep.clone() }, true);
}
assert!(Discovery::nearest_node_entries(&NodeId::new(), &discovery.node_buckets).len() <= 16);
let removed = discovery.check_expired(true).len();
Expand Down
8 changes: 4 additions & 4 deletions util/src/network/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ impl Host {

self.nodes.write().add_node(n);
if let Some(ref mut discovery) = *self.discovery.lock() {
discovery.add_node(entry);
discovery.add_node(entry, true);
}
}
}
Expand All @@ -433,7 +433,7 @@ impl Host {
self.nodes.write().add_node(Node::new(entry.id.clone(), entry.endpoint.clone()));

if let Some(ref mut discovery) = *self.discovery.lock() {
discovery.add_node(entry);
discovery.add_node(entry, false);
}

Ok(())
Expand Down Expand Up @@ -550,7 +550,7 @@ impl Host {
if let Some(mut discovery) = discovery {
discovery.init_node_list(self.nodes.read().unordered_entries());
for n in self.nodes.read().unordered_entries() {
discovery.add_node(n.clone());
discovery.add_node(n.clone(), false);
}
*self.discovery.lock() = Some(discovery);
io.register_stream(DISCOVERY).expect("Error registering UDP listener");
Expand Down Expand Up @@ -788,7 +788,7 @@ impl Host {
self.nodes.write().add_node(Node::new(entry.id.clone(), entry.endpoint.clone()));
let mut discovery = self.discovery.lock();
if let Some(ref mut discovery) = *discovery.deref_mut() {
discovery.add_node(entry);
discovery.add_node(entry, true);
}
}
}
Expand Down

0 comments on commit 340f0b6

Please sign in to comment.