hopr_path/selectors/
mod.rs

1pub mod dfs;
2
3use async_trait::async_trait;
4use std::ops::Add;
5
6use hopr_internal_types::prelude::*;
7use hopr_primitive_types::primitives::Address;
8
9use crate::channel_graph::ChannelEdge;
10use crate::errors::Result;
11use crate::path::ChannelPath;
12
13/// Computes weights of edges corresponding to [`ChannelEdge`].
14pub trait EdgeWeighting<W>
15where
16    W: Default + Add<W, Output = W>,
17{
18    /// Edge weighting function.
19    fn calculate_weight(channel: &ChannelEdge) -> W;
20}
21
22/// Trait for implementing a custom path selection algorithm from the channel graph.
23#[async_trait]
24pub trait PathSelector {
25    /// Select a path of maximum `max_hops` from `source` to `destination` in the given channel graph.
26    /// NOTE: the resulting path does not contain `source` but does contain `destination`.
27    /// Fails if no such path can be found.
28    async fn select_path(
29        &self,
30        source: Address,
31        destination: Address,
32        min_hops: usize,
33        max_hops: usize,
34    ) -> Result<ChannelPath>;
35
36    /// Constructs a new valid packet `Path` from source to the given destination.
37    /// This method uses `INTERMEDIATE_HOPS` as the maximum number of hops.
38    async fn select_auto_path(&self, source: Address, destination: Address) -> Result<ChannelPath> {
39        self.select_path(source, destination, 1usize, INTERMEDIATE_HOPS).await
40    }
41}