Skip to main content

PathSelector

Trait PathSelector 

Source
pub trait PathSelector {
    // Required method
    fn select_path(
        &self,
        src: OffchainPublicKey,
        dest: OffchainPublicKey,
        hops: usize,
    ) -> Result<Vec<PathWithMetrics>>;
}
Expand description

Selects multi-hop paths through the network.

Implementors are responsible for determining how paths are found. The caller (e.g. crate::path::planner::PathPlanner) is responsible for caching, path selection strategy, and validation.

§Cycle-free invariant

Implementations must return only cycle-free (simple) paths — no node may appear more than once in any returned path. Cycles destroy path entropy and worsen anonymity. The built-in crate::path::selector::HoprGraphPathSelector guarantees this by using the simple_paths graph algorithm, which by definition never revisits a node. Alternative implementations must uphold the same invariant.

Required Methods§

Source

fn select_path( &self, src: OffchainPublicKey, dest: OffchainPublicKey, hops: usize, ) -> Result<Vec<PathWithMetrics>>

Return all candidate paths from src to dest using hops relays.

Each returned PathWithMetrics contains a path Vec<OffchainPublicKey> of length hops + 1 ([intermediates..., dest]; src excluded) paired with its accumulated traversal cost and optional per-path quality aggregates.

Every returned path must be cycle-free (see trait-level docs).

Returns Err when no paths can be found.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<G> PathSelector for HoprGraphPathSelector<G>
where G: NetworkGraphTraverse<NodeId = OffchainPublicKey> + NetworkGraphView<NodeId = OffchainPublicKey> + Clone + Send + Sync + 'static, <G as NetworkGraphTraverse>::Observed: EdgeObservableRead + Send + 'static,