stability improvements

This commit is contained in:
Valentyn Faychuk 2024-12-22 18:36:25 +02:00
parent 1da6053acf
commit 780c1e54a3
Signed by: valy
GPG Key ID: F1AB995E20FEADC5
3 changed files with 14 additions and 13 deletions

@ -26,7 +26,7 @@ pub struct NodeInfo {
impl NodeInfo { impl NodeInfo {
pub fn is_newer_than(&self, older_self: &Self) -> bool { pub fn is_newer_than(&self, older_self: &Self) -> bool {
self.keepalive > older_self.keepalive self.keepalive >= older_self.keepalive
} }
pub fn to_json(&self) -> String { pub fn to_json(&self) -> String {
@ -188,17 +188,18 @@ impl State {
} }
/// This returns true if NodeInfo got modified. /// This returns true if NodeInfo got modified.
pub fn process_node_update(&self, (ip, mut node_info): (String, NodeInfo)) -> bool { pub fn process_node_update(&self, (ip, node_info): (String, NodeInfo)) -> bool {
if let Some(old_node) = self.nodes.get(&ip) { let is_update_new = self
if !node_info.is_newer_than(&old_node) { .nodes
return false; .get(&ip)
} .map(|curr_info| node_info.is_newer_than(&curr_info))
node_info.public = node_info.public || old_node.public; .unwrap_or(true);
} if is_update_new {
println!("Inserting: {}, {}", ip, node_info.to_json()); println!("Inserting: {}, {}", ip, node_info.to_json());
node_info.log(&ip); node_info.log(&ip);
self.nodes.insert(ip, node_info); self.nodes.insert(ip, node_info);
true }
is_update_new
} }
pub fn get_node_list(&self) -> Vec<(String, NodeInfo)> { pub fn get_node_list(&self) -> Vec<(String, NodeInfo)> {

@ -175,8 +175,8 @@ impl Update for MyServer {
} }
} }
} }
yield Err(error_status);
state.decrease_mratls_conns(); state.decrease_mratls_conns();
yield Err(error_status);
}; };
Ok(Response::new(Box::pin(stream) as Self::GetUpdatesStream)) Ok(Response::new(Box::pin(stream) as Self::GetUpdatesStream))

@ -33,7 +33,7 @@ impl From<(String, datastore::NodeInfo)> for NodesResp {
let last_keepalive: DateTime<Utc> = node_info.keepalive.into(); let last_keepalive: DateTime<Utc> = node_info.keepalive.into();
let joined_at = joined_at.format("%Y-%m-%d %H:%M:%S").to_string(); let joined_at = joined_at.format("%Y-%m-%d %H:%M:%S").to_string();
let last_keepalive = last_keepalive.format("%Y-%m-%d %H:%M:%S").to_string(); let last_keepalive = last_keepalive.format("%Y-%m-%d %H:%M:%S").to_string();
crate::http_server::NodesResp { NodesResp {
ip, ip,
joined_at, joined_at,
last_keepalive, last_keepalive,