update keepalive
Signed-off-by: Valentyn Faychuk <valy@detee.ltd>
This commit is contained in:
parent
ce69455dd6
commit
4a6e8c4c73
@ -231,6 +231,15 @@ impl State {
|
|||||||
.nth(skip)
|
.nth(skip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn update_keepalive(&self) {
|
||||||
|
let mut nodes = self.nodes.write().await;
|
||||||
|
if let Some(my_info) = nodes.get_mut(&self.my_ip) {
|
||||||
|
let mut updated_info = my_info.clone();
|
||||||
|
updated_info.keepalive = SystemTime::now();
|
||||||
|
let _ = nodes.insert(self.my_ip.clone(), updated_info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// This returns true if the update should be further forwarded
|
/// This returns true if the update should be further forwarded
|
||||||
/// For example, we never forward our own updates that came back
|
/// For example, we never forward our own updates that came back
|
||||||
pub async fn process_node_update(&self, (node_ip, node_info): (String, NodeInfo)) -> bool {
|
pub async fn process_node_update(&self, (node_ip, node_info): (String, NodeInfo)) -> bool {
|
||||||
|
@ -51,6 +51,7 @@ pub async fn heartbeat(
|
|||||||
loop {
|
loop {
|
||||||
interval.tick().await;
|
interval.tick().await;
|
||||||
println!("Heartbeat...");
|
println!("Heartbeat...");
|
||||||
|
state.update_keepalive().await;
|
||||||
state.remove_inactive_nodes().await;
|
state.remove_inactive_nodes().await;
|
||||||
let connected_ips = state.get_connected_ips().await;
|
let connected_ips = state.get_connected_ips().await;
|
||||||
println!("Connected nodes ({}): {:?}", connected_ips.len(), connected_ips);
|
println!("Connected nodes ({}): {:?}", connected_ips.len(), connected_ips);
|
||||||
|
Loading…
Reference in New Issue
Block a user