Populate discovery from node table

This commit is contained in:
arkpar 2016-02-15 20:28:27 +01:00
parent 4b9c7f7517
commit 01a83e6031
3 changed files with 17 additions and 2 deletions

View File

@ -110,12 +110,20 @@ impl Discovery {
}
}
/// Add a new node to discovery table. Pings the node.
pub fn add_node(&mut self, e: NodeEntry) {
let endpoint = e.endpoint.clone();
self.update_node(e);
self.ping(&endpoint);
}
/// Add a list of known nodes to the table.
pub fn init_node_list(&mut self, mut nodes: Vec<NodeEntry>) {
for n in nodes.drain(..) {
self.update_node(n);
}
}
fn update_node(&mut self, e: NodeEntry) {
trace!(target: "discovery", "Inserting {:?}", &e);
let ping = {

View File

@ -386,6 +386,7 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
for n in boot_nodes {
host.add_node(&n);
}
host.discovery.lock().unwrap().init_node_list(host.nodes.read().unwrap().unordered_entries());
host
}

View File

@ -29,7 +29,7 @@ use hash::*;
use rlp::*;
use time::Tm;
use error::*;
use network::discovery::TableUpdates;
use network::discovery::{TableUpdates, NodeEntry};
pub use rustc_serialize::json::Json;
/// Node public key
@ -214,6 +214,12 @@ impl NodeTable {
refs.iter().map(|n| n.id.clone()).collect()
}
/// Unordered list of all entries
pub fn unordered_entries(&self) -> Vec<NodeEntry> {
// preserve failure counter
self.nodes.values().map(|n| NodeEntry { endpoint: n.endpoint.clone(), id: n.id.clone() }).collect()
}
/// Get particular node
pub fn get_mut(&mut self, id: &NodeId) -> Option<&mut Node> {
self.nodes.get_mut(id)