Don't ping all nodes on start (#1656)

* Don't ping all nodes on start

* Fixed test
This commit is contained in:
Arkadiy Paronyan 2016-07-19 09:24:19 +02:00 committed by Gav Wood
parent 4e447ccc68
commit 340f0b6f58
2 changed files with 12 additions and 10 deletions

View File

@ -119,11 +119,13 @@ 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);
if new {
self.ping(&endpoint);
}
}
/// Add a list of known nodes to the table.
pub fn init_node_list(&mut self, mut nodes: Vec<NodeEntry>) {
@ -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 {
@ -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();

View File

@ -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);
}
}
}
@ -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(())
@ -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");
@ -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);
}
}
}