Populate discovery from node table
This commit is contained in:
parent
4b9c7f7517
commit
01a83e6031
@ -110,12 +110,20 @@ impl Discovery {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_node(&mut self, e: NodeEntry) {
|
/// Add a new node to discovery table. Pings the node.
|
||||||
|
pub fn add_node(&mut self, e: NodeEntry) {
|
||||||
let endpoint = e.endpoint.clone();
|
let endpoint = e.endpoint.clone();
|
||||||
self.update_node(e);
|
self.update_node(e);
|
||||||
self.ping(&endpoint);
|
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) {
|
fn update_node(&mut self, e: NodeEntry) {
|
||||||
trace!(target: "discovery", "Inserting {:?}", &e);
|
trace!(target: "discovery", "Inserting {:?}", &e);
|
||||||
let ping = {
|
let ping = {
|
||||||
|
@ -386,6 +386,7 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
|
|||||||
for n in boot_nodes {
|
for n in boot_nodes {
|
||||||
host.add_node(&n);
|
host.add_node(&n);
|
||||||
}
|
}
|
||||||
|
host.discovery.lock().unwrap().init_node_list(host.nodes.read().unwrap().unordered_entries());
|
||||||
host
|
host
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ use hash::*;
|
|||||||
use rlp::*;
|
use rlp::*;
|
||||||
use time::Tm;
|
use time::Tm;
|
||||||
use error::*;
|
use error::*;
|
||||||
use network::discovery::TableUpdates;
|
use network::discovery::{TableUpdates, NodeEntry};
|
||||||
pub use rustc_serialize::json::Json;
|
pub use rustc_serialize::json::Json;
|
||||||
|
|
||||||
/// Node public key
|
/// Node public key
|
||||||
@ -214,6 +214,12 @@ impl NodeTable {
|
|||||||
refs.iter().map(|n| n.id.clone()).collect()
|
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
|
/// Get particular node
|
||||||
pub fn get_mut(&mut self, id: &NodeId) -> Option<&mut Node> {
|
pub fn get_mut(&mut self, id: &NodeId) -> Option<&mut Node> {
|
||||||
self.nodes.get_mut(id)
|
self.nodes.get_mut(id)
|
||||||
|
Loading…
Reference in New Issue
Block a user