diff --git a/util/src/network/host.rs b/util/src/network/host.rs index 0612e4444..6c1598dd1 100644 --- a/util/src/network/host.rs +++ b/util/src/network/host.rs @@ -430,6 +430,7 @@ impl Host { let entry = NodeEntry { endpoint: n.endpoint.clone(), id: 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() { discovery.add_node(entry); @@ -755,7 +756,9 @@ impl Host { trace!(target: "network", "Session read error: {}:{:?} ({:?}) {:?}", token, s.id(), s.remote_addr(), e); if let UtilError::Network(NetworkError::Disconnect(DisconnectReason::IncompatibleProtocol)) = e { if let Some(id) = s.id() { - self.nodes.write().mark_as_useless(id); + if !self.reserved_nodes.read().contains(id) { + self.nodes.write().mark_as_useless(id); + } } } kill = true; @@ -889,7 +892,7 @@ impl Host { trace!(target: "network", "Removed from node table: {}", i); 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(&self, protocol: ProtocolId, io: &IoContext, action: F) where F: Fn(&NetworkContext) { diff --git a/util/src/network/node_table.rs b/util/src/network/node_table.rs index 416a0f8eb..5fd2a10e8 100644 --- a/util/src/network/node_table.rs +++ b/util/src/network/node_table.rs @@ -236,13 +236,15 @@ impl NodeTable { } /// Apply table changes coming from discovery - pub fn update(&mut self, mut update: TableUpdates) { + pub fn update(&mut self, mut update: TableUpdates, reserved: &HashSet) { 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())); entry.endpoint = node.endpoint; } for r in update.removed { - self.nodes.remove(&r); + if !reserved.contains(&r) { + self.nodes.remove(&r); + } } }