pub struct PathPlanner<Surb, R, S> {
me: OffchainPublicKey,
pub surb_store: Surb,
resolver: Arc<R>,
selector: Arc<S>,
cache: Cache<(NodeId, NodeId, u32), Arc<WeightedCollection<ValidatedPath>>>,
refresh_period: Duration,
}Expand description
Path planner that resolves [DestinationRouting] to [ResolvedTransportRouting].
The planner delegates path discovery to any PathSelector implementation and
owns the moka cache of fully-validated [ValidatedPath] objects paired with
their traversal cost, keyed by (source: NodeId, destination: NodeId, hops: u32).
On a cache miss the planner calls the selector, validates every candidate against
the chain resolver, and stores an Arc<WeightedCollection<ValidatedPath>> in the
cache. On a cache hit a candidate is picked via weighted random selection (higher
cost = higher quality = higher probability).
A background sweep (background_refresh) can be spawned to
proactively re-warm the cache for all previously-seen keys.
Fields§
§me: OffchainPublicKey§surb_store: Surb§resolver: Arc<R>§selector: Arc<S>§cache: Cache<(NodeId, NodeId, u32), Arc<WeightedCollection<ValidatedPath>>>§refresh_period: DurationImplementations§
Source§impl<Surb, R, S> PathPlanner<Surb, R, S>
impl<Surb, R, S> PathPlanner<Surb, R, S>
Sourcepub fn new(
me: OffchainPublicKey,
surb_store: Surb,
resolver: R,
selector: S,
config: PathPlannerConfig,
) -> Self
pub fn new( me: OffchainPublicKey, surb_store: Surb, resolver: R, selector: S, config: PathPlannerConfig, ) -> Self
Create a new path planner.
me is this node’s [OffchainPublicKey]; it is used as the source in path queries.
Sourceasync fn resolve_node_id_to_offchain_key(
&self,
node_id: &NodeId,
) -> Result<OffchainPublicKey>
async fn resolve_node_id_to_offchain_key( &self, node_id: &NodeId, ) -> Result<OffchainPublicKey>
Resolve a [NodeId] to an [OffchainPublicKey].
async fn resolve_path( &self, source: NodeId, destination: NodeId, options: RoutingOptions, ) -> Result<ValidatedPath>
Sourcepub async fn resolve_routing(
&self,
size_hint: usize,
max_surbs: usize,
routing: DestinationRouting,
) -> Result<(ResolvedTransportRouting<HoprSurb>, Option<usize>)>
pub async fn resolve_routing( &self, size_hint: usize, max_surbs: usize, routing: DestinationRouting, ) -> Result<(ResolvedTransportRouting<HoprSurb>, Option<usize>)>
Resolve a [DestinationRouting] to a [ResolvedTransportRouting].
Returns the resolved routing and, for Return variants, the number of remaining SURBs.
Trait Implementations§
Source§impl<Surb, R, S> BackgroundPathCacheRefreshable for PathPlanner<Surb, R, S>
impl<Surb, R, S> BackgroundPathCacheRefreshable for PathPlanner<Surb, R, S>
Source§fn run_background_refresh(&self) -> impl Future<Output = ()> + Send + 'static
fn run_background_refresh(&self) -> impl Future<Output = ()> + Send + 'static
Returns a future that runs the background path-cache refresh loop.
The returned future iterates over all keys currently in the planner’s cache and recomputes their paths on a configurable schedule, so that steady-state traffic is always served from cache.
Auto Trait Implementations§
impl<Surb, R, S> Freeze for PathPlanner<Surb, R, S>where
Surb: Freeze,
impl<Surb, R, S> !RefUnwindSafe for PathPlanner<Surb, R, S>
impl<Surb, R, S> Send for PathPlanner<Surb, R, S>
impl<Surb, R, S> Sync for PathPlanner<Surb, R, S>
impl<Surb, R, S> Unpin for PathPlanner<Surb, R, S>where
Surb: Unpin,
impl<Surb, R, S> !UnwindSafe for PathPlanner<Surb, R, S>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more