fixed small errors in logic

small errors that were causing everything to crash
This commit is contained in:
ghe0 2024-08-22 18:23:42 +03:00
parent 3e323cbd23
commit e13fb05dbb
Signed by: ghe0
GPG Key ID: 451028EE56A0FBB4
2 changed files with 5 additions and 4 deletions

@ -174,7 +174,7 @@ impl Store {
}; };
if let Some(mut old_node_info) = self.update_node(node.ip, node_info.clone()).await { if let Some(mut old_node_info) = self.update_node(node.ip, node_info.clone()).await {
if !node_info.public { if !node_info.public {
old_node_info.public = false; old_node_info.public = node_info.public;
} }
match old_node_info.ne(&node_info) { match old_node_info.ne(&node_info) {
true => { true => {
@ -191,8 +191,8 @@ impl Store {
/// returns old pubkey if node got updated /// returns old pubkey if node got updated
async fn update_node(&self, ip: String, info: NodeInfo) -> Option<NodeInfo> { async fn update_node(&self, ip: String, info: NodeInfo) -> Option<NodeInfo> {
if let Some(old_node) = self.nodes.get(&ip) { if let Some(old_node) = self.nodes.get(&ip) {
if old_node.updated_at > info.updated_at { if old_node.updated_at >= info.updated_at {
return None; return Some(info);
} }
} }
self.nodes.insert(ip, info.clone()) self.nodes.insert(ip, info.clone())

@ -13,14 +13,15 @@ use tokio::time::{sleep, Duration};
async fn cycle_keys(ds: Arc<Store>, tx: Sender<NodeUpdate>) { async fn cycle_keys(ds: Arc<Store>, tx: Sender<NodeUpdate>) {
loop { loop {
let _ = tx.send(ds.reset_localhost_keys().await);
sleep(Duration::from_secs(60)).await; sleep(Duration::from_secs(60)).await;
let _ = tx.send(ds.reset_localhost_keys().await);
} }
} }
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let ds: Arc<Store> = Arc::new(Store::init()); let ds: Arc<Store> = Arc::new(Store::init());
ds.reset_localhost_keys().await;
let (tx, mut _rx) = broadcast::channel(500); let (tx, mut _rx) = broadcast::channel(500);
let mut long_term_tasks = JoinSet::new(); let mut long_term_tasks = JoinSet::new();