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} | for i in {2..12} | ||||||
| do | do | ||||||
|   ip="172.17.0.${i}" |   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. |     echo Container at ip ${ip} did not connect to all other containers. | ||||||
| done | done | ||||||
| echo OK! | echo OK! | ||||||
| 
 | 
 | ||||||
| echo -n "Checking if containers can sign data... " | echo -n "Checking if containers can sign data... " | ||||||
| for i in {2..12} | for i in {2..52} | ||||||
| do | do | ||||||
|   ip="172.17.0.${i}" |   ip="172.17.0.${i}" | ||||||
|   random_key=$(curl -s "${ip}:31372/memory" | grep true | tail -1 | awk '{ print $4 }') |   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()) |         self.nodes.insert(ip, info.clone()) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     //    pub async fn remove_node(&self, ip: &str) {
 |     pub async fn remove_inactive_nodes(&self) { | ||||||
|     //        let mut nodes = self.nodes.lock().await;
 |         let mut dangling_pubkeys = Vec::new(); | ||||||
|     //        nodes.remove(ip);
 |         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 { |     pub async fn get_localhost(&self) -> NodeUpdate { | ||||||
|         // TODO trigger reset_localhost_keys on error instead of expects
 |         // 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 { |     loop { | ||||||
|         sleep(Duration::from_secs(60)).await; |         sleep(Duration::from_secs(60)).await; | ||||||
|         let _ = tx.send(ds.reset_localhost_keys().await); |         let _ = tx.send(ds.reset_localhost_keys().await); | ||||||
|  |         ds.remove_inactive_nodes().await; | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user