keepalive updates working correctly

This commit is contained in:
ghe0 2024-09-19 05:20:30 +03:00
parent 1804c8e00c
commit 801d058682
Signed by: ghe0
GPG Key ID: 451028EE56A0FBB4

@ -1,11 +1,11 @@
#![allow(dead_code)] #![allow(dead_code)]
use crate::grpc::challenge::NodeUpdate; use crate::grpc::challenge::NodeUpdate;
use chrono::{DateTime, Utc};
use dashmap::DashMap; use dashmap::DashMap;
use dashmap::DashSet; use dashmap::DashSet;
use solana_sdk::signature::keypair::Keypair; use solana_sdk::signature::keypair::Keypair;
use std::time::SystemTime; use std::time::SystemTime;
use std::time::{Duration, UNIX_EPOCH}; use std::time::{Duration, UNIX_EPOCH};
use chrono::{DateTime, Utc};
type IP = String; type IP = String;
pub const LOCALHOST: &str = "localhost"; pub const LOCALHOST: &str = "localhost";
@ -28,6 +28,7 @@ impl NodeInfo {
|| self.ratls_attacks > other_node.ratls_attacks || self.ratls_attacks > other_node.ratls_attacks
|| self.ratls_conns > other_node.ratls_conns || self.ratls_conns > other_node.ratls_conns
|| self.mints > other_node.mints || self.mints > other_node.mints
|| (self.public && !other_node.public)
{ {
return true; return true;
} }
@ -94,9 +95,7 @@ impl Store {
} }
pub fn increase_mint_requests(&self) { pub fn increase_mint_requests(&self) {
println!("increasing localhost");
if let Some(mut localhost_info) = self.nodes.get_mut(LOCALHOST) { if let Some(mut localhost_info) = self.nodes.get_mut(LOCALHOST) {
println!("increasing localhost from {}", localhost_info.mint_requests);
localhost_info.mint_requests += 1; localhost_info.mint_requests += 1;
} }
} }
@ -137,7 +136,7 @@ impl Store {
} }
None => SystemTime::now(), None => SystemTime::now(),
}; };
let node_info = NodeInfo { let mut node_info = NodeInfo {
started_at, started_at,
keepalive, keepalive,
mint_requests: node.mint_requests, mint_requests: node.mint_requests,
@ -150,6 +149,7 @@ impl Store {
if !node_info.newer_than(&old_node) { if !node_info.newer_than(&old_node) {
return false; return false;
} }
node_info.public = node_info.public || old_node.public;
} }
self.nodes.insert(ip, node_info); self.nodes.insert(ip, node_info);
true true
@ -160,7 +160,7 @@ impl Store {
.iter() .iter()
.map(|node| { .map(|node| {
let joined_at: DateTime<Utc> = node.value().started_at.into(); let joined_at: DateTime<Utc> = node.value().started_at.into();
let last_keepalive: DateTime<Utc> = node.value().started_at.into(); let last_keepalive: DateTime<Utc> = node.value().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 { crate::http_server::NodesResp {