From 70839d70d86354232f168e63ce4062219acb85c7 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 13 Oct 2021 17:12:13 +0200 Subject: Try to handle termination and closing of stuff properly --- src/peering/basalt.rs | 2 +- src/peering/fullmesh.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'src/peering') diff --git a/src/peering/basalt.rs b/src/peering/basalt.rs index e0c8301..efbf6e6 100644 --- a/src/peering/basalt.rs +++ b/src/peering/basalt.rs @@ -3,11 +3,11 @@ use std::net::SocketAddr; use std::sync::{Arc, RwLock}; use std::time::Duration; +use async_trait::async_trait; use log::{debug, info, trace, warn}; use lru::LruCache; use rand::{thread_rng, Rng}; use serde::{Deserialize, Serialize}; -use async_trait::async_trait; use sodiumoxide::crypto::hash; diff --git a/src/peering/fullmesh.rs b/src/peering/fullmesh.rs index b579654..793eeb2 100644 --- a/src/peering/fullmesh.rs +++ b/src/peering/fullmesh.rs @@ -8,6 +8,8 @@ use async_trait::async_trait; use log::{debug, info, trace, warn}; use serde::{Deserialize, Serialize}; +use tokio::sync::watch; + use sodiumoxide::crypto::hash; use crate::endpoint::*; @@ -171,8 +173,8 @@ impl FullMeshPeeringStrategy { strat } - pub async fn run(self: Arc) { - loop { + pub async fn run(self: Arc, must_exit: watch::Receiver) { + while !*must_exit.borrow() { // 1. Read current state: get list of connected peers (ping them) let (to_ping, to_retry) = { let known_hosts = self.known_hosts.read().unwrap(); -- cgit v1.2.3