Make sure reserved peers are in the node table (#1616)

This commit is contained in:
Arkadiy Paronyan 2016-07-14 10:38:53 +02:00 committed by Gav Wood
parent 50c43bd819
commit 8d0e05adb7
2 changed files with 9 additions and 4 deletions

View File

@ -430,6 +430,7 @@ impl Host {
let entry = NodeEntry { endpoint: n.endpoint.clone(), id: n.id.clone() }; let entry = NodeEntry { endpoint: n.endpoint.clone(), id: n.id.clone() };
self.reserved_nodes.write().insert(n.id.clone()); self.reserved_nodes.write().insert(n.id.clone());
self.nodes.write().add_node(Node::new(entry.id.clone(), entry.endpoint.clone()));
if let Some(ref mut discovery) = *self.discovery.lock() { if let Some(ref mut discovery) = *self.discovery.lock() {
discovery.add_node(entry); discovery.add_node(entry);
@ -755,9 +756,11 @@ impl Host {
trace!(target: "network", "Session read error: {}:{:?} ({:?}) {:?}", token, s.id(), s.remote_addr(), e); trace!(target: "network", "Session read error: {}:{:?} ({:?}) {:?}", token, s.id(), s.remote_addr(), e);
if let UtilError::Network(NetworkError::Disconnect(DisconnectReason::IncompatibleProtocol)) = e { if let UtilError::Network(NetworkError::Disconnect(DisconnectReason::IncompatibleProtocol)) = e {
if let Some(id) = s.id() { if let Some(id) = s.id() {
if !self.reserved_nodes.read().contains(id) {
self.nodes.write().mark_as_useless(id); self.nodes.write().mark_as_useless(id);
} }
} }
}
kill = true; kill = true;
break; break;
}, },
@ -889,7 +892,7 @@ impl Host {
trace!(target: "network", "Removed from node table: {}", i); trace!(target: "network", "Removed from node table: {}", i);
self.kill_connection(i, io, false); self.kill_connection(i, io, false);
} }
self.nodes.write().update(node_changes); self.nodes.write().update(node_changes, &*self.reserved_nodes.read());
} }
pub fn with_context<F>(&self, protocol: ProtocolId, io: &IoContext<NetworkIoMessage>, action: F) where F: Fn(&NetworkContext) { pub fn with_context<F>(&self, protocol: ProtocolId, io: &IoContext<NetworkIoMessage>, action: F) where F: Fn(&NetworkContext) {

View File

@ -236,15 +236,17 @@ impl NodeTable {
} }
/// Apply table changes coming from discovery /// Apply table changes coming from discovery
pub fn update(&mut self, mut update: TableUpdates) { pub fn update(&mut self, mut update: TableUpdates, reserved: &HashSet<NodeId>) {
for (_, node) in update.added.drain() { for (_, node) in update.added.drain() {
let mut entry = self.nodes.entry(node.id.clone()).or_insert_with(|| Node::new(node.id.clone(), node.endpoint.clone())); let mut entry = self.nodes.entry(node.id.clone()).or_insert_with(|| Node::new(node.id.clone(), node.endpoint.clone()));
entry.endpoint = node.endpoint; entry.endpoint = node.endpoint;
} }
for r in update.removed { for r in update.removed {
if !reserved.contains(&r) {
self.nodes.remove(&r); self.nodes.remove(&r);
} }
} }
}
/// Increase failure counte for a node /// Increase failure counte for a node
pub fn note_failure(&mut self, id: &NodeId) { pub fn note_failure(&mut self, id: &NodeId) {