diff --git a/nym-client/src/client/cover_traffic_stream.rs b/nym-client/src/client/cover_traffic_stream.rs index 82f904eec7..f1caedc740 100644 --- a/nym-client/src/client/cover_traffic_stream.rs +++ b/nym-client/src/client/cover_traffic_stream.rs @@ -1,29 +1,35 @@ use crate::client::mix_traffic::MixMessage; +use crate::client::topology_control::TopologyInnerRef; use crate::client::LOOP_COVER_AVERAGE_DELAY; use futures::channel::mpsc; -use log::{info, trace}; +use log::{info, trace, warn}; use sphinx::route::Destination; use std::time::Duration; use topology::NymTopology; -pub(crate) async fn start_loop_cover_traffic_stream( +pub(crate) async fn start_loop_cover_traffic_stream( tx: mpsc::UnboundedSender, our_info: Destination, - topology: T, -) where - T: NymTopology, -{ + topology_ctrl_ref: TopologyInnerRef, +) { info!("Starting loop cover traffic stream"); loop { trace!("next cover message!"); let delay = mix_client::poisson::sample(LOOP_COVER_AVERAGE_DELAY); let delay_duration = Duration::from_secs_f64(delay); tokio::time::delay_for(delay_duration).await; - let cover_message = mix_client::packet::loop_cover_message( - our_info.address, - our_info.identifier, - &topology, - ); + + let read_lock = topology_ctrl_ref.read().await; + let topology = read_lock.topology.as_ref(); + if topology.is_none() { + warn!("No valid topology detected - won't send any loop cover message this time"); + continue; + } + + let topology = topology.unwrap(); + + let cover_message = + mix_client::packet::loop_cover_message(our_info.address, our_info.identifier, topology); // if this one fails, there's no retrying because it means that either: // - we run out of memory