hopr_api/ct/
traits.rs

1pub use hopr_network_types::types::DestinationRouting;
2use multiaddr::PeerId;
3
4use super::{MeasurableNeighbor, MeasurablePath, Telemetry, TrafficGenerationError};
5
6/// A trait specifying the graph traversal functionality
7#[async_trait::async_trait]
8pub trait NetworkGraphView {
9    /// Returns a stream of all known nodes in the network graph.
10    fn nodes(&self) -> futures::stream::BoxStream<'static, PeerId>;
11
12    /// Returns a list of all routes to the given destination of the specified length.
13    async fn find_routes(&self, destination: &PeerId, length: usize) -> Vec<DestinationRouting>;
14}
15
16/// A trait specifying the graph update functionality
17#[async_trait::async_trait]
18pub trait NetworkGraphUpdate {
19    /// Update the observation for the telemetry.
20    async fn record<N, P>(&self, telemetry: std::result::Result<Telemetry<N, P>, TrafficGenerationError<P>>)
21    where
22        N: MeasurableNeighbor + Clone + Send + Sync + 'static,
23        P: MeasurablePath + Clone + Send + Sync + 'static;
24}
25
26/// A trait for types that can produce a stream of cover traffic routes.
27///
28/// The basic assumption is that the implementor will provide the logic
29/// to choose suitable route candidates for cover traffic based on a
30/// custom algorithm.
31///
32/// The implementor should ensure that the produced routes are indefinite,
33/// since the exhaustion of the stream might result in termination of the
34/// cover traffic generation.
35pub trait TrafficGeneration {
36    fn build<T>(self, network_graph: T) -> impl futures::Stream<Item = DestinationRouting> + Send
37    where
38        T: NetworkGraphView + Send + Sync + 'static;
39}