remove inactive nodes after two cycles
This commit is contained in:
parent
7c90c2ceda
commit
248c2f694c
@ -14,13 +14,13 @@ echo -n "Checking if containers connected to each other... "
|
||||
for i in {2..12}
|
||||
do
|
||||
ip="172.17.0.${i}"
|
||||
curl -s "${ip}:31372/memory" | grep -e true -e false -c | grep 12 > /dev/null ||
|
||||
curl -s "${ip}:31372/memory" | grep -e true -e false -c | grep 52 > /dev/null ||
|
||||
echo Container at ip ${ip} did not connect to all other containers.
|
||||
done
|
||||
echo OK!
|
||||
|
||||
echo -n "Checking if containers can sign data... "
|
||||
for i in {2..12}
|
||||
for i in {2..52}
|
||||
do
|
||||
ip="172.17.0.${i}"
|
||||
random_key=$(curl -s "${ip}:31372/memory" | grep true | tail -1 | awk '{ print $4 }')
|
||||
|
@ -268,10 +268,24 @@ impl Store {
|
||||
self.nodes.insert(ip, info.clone())
|
||||
}
|
||||
|
||||
// pub async fn remove_node(&self, ip: &str) {
|
||||
// let mut nodes = self.nodes.lock().await;
|
||||
// nodes.remove(ip);
|
||||
// }
|
||||
pub async fn remove_inactive_nodes(&self) {
|
||||
let mut dangling_pubkeys = Vec::new();
|
||||
self.nodes.retain(|_, v| {
|
||||
let age = SystemTime::now()
|
||||
.duration_since(v.updated_at)
|
||||
.unwrap_or(Duration::ZERO)
|
||||
.as_secs();
|
||||
if age > 120 {
|
||||
dangling_pubkeys.push(v.pubkey.clone());
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
});
|
||||
for pubkey in dangling_pubkeys.iter() {
|
||||
self.keys.remove(pubkey);
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_localhost(&self) -> NodeUpdate {
|
||||
// TODO trigger reset_localhost_keys on error instead of expects
|
||||
|
@ -19,6 +19,7 @@ async fn cycle_keys(ds: Arc<Store>, tx: Sender<NodeUpdate>) {
|
||||
loop {
|
||||
sleep(Duration::from_secs(60)).await;
|
||||
let _ = tx.send(ds.reset_localhost_keys().await);
|
||||
ds.remove_inactive_nodes().await;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user