hopr_path/selectors/
mod.rs

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