Skip to main content

LocalGraph

Struct LocalGraph 

Source
pub struct LocalGraph { /* private fields */ }
Expand description

Local view of the swarm: known nodes, edges, and a dedup cache for incoming pingwaves. Holds the proximity-routing state — see BehaviorContext::propagate for the consumer side and mesh.rs pingwave dispatch for the producer side.

Implementations§

Source§

impl LocalGraph

Source

pub fn new(my_id: u64, radius: u8) -> Self

Create a new local graph

Source

pub fn with_node_timeout(self, timeout: Duration) -> Self

Set node timeout

Source

pub fn my_id(&self) -> u64

Get local node ID

Source

pub fn radius(&self) -> u8

Get radius

Source

pub fn create_pingwave(&self) -> Pingwave

Create a new pingwave to broadcast

Source

pub fn on_pingwave(&self, pw: Pingwave, from: SocketAddr) -> Option<Pingwave>

Process an incoming pingwave.

Returns Some(pingwave) if it should be forwarded, None otherwise.

seen_pingwaves and nodes are soft-capped via MAX_SEEN_PINGWAVES / MAX_GRAPH_NODES: existing entries continue to update, but novel keys are dropped once the cap is reached. The next periodic evict_stale_* sweep reclaims slots for legitimate nodes/pingwaves so admission resumes once memory pressure eases. Without the caps, a peer flooding pingwaves with random (origin_id, seq) could grow both maps at line-rate between the periodic eviction sweeps.

Source

pub fn on_capability(&self, ad: CapabilityAd, from: SocketAddr)

Process a capability advertisement

Source

pub fn add_edge(&self, from: u64, to: u64, latency_us: u32)

Add or update an edge

Source

pub fn get_node(&self, node_id: u64) -> Option<NodeInfo>

Get node info

Source

pub fn all_nodes(&self) -> Vec<NodeInfo>

Get all known nodes

Source

pub fn nodes_within_hops(&self, max_hops: u8) -> Vec<NodeInfo>

Get nodes within a specific hop distance

Source

pub fn find_by_tool(&self, tool: &str) -> Vec<NodeInfo>

Find nodes with a specific capability (tool)

Source

pub fn find_by_tag(&self, tag: &str) -> Vec<NodeInfo>

Find nodes with a specific tag

Source

pub fn find_with_gpu(&self) -> Vec<NodeInfo>

Find nodes with GPU

Source

pub fn path_to(&self, dest: u64) -> Option<Vec<u64>>

Get shortest path to a node (BFS).

Reconstructs the path from a parent map at the end rather than cloning the full path per neighbor — avoids quadratic behavior on long paths or wide frontiers.

Source

pub fn cleanup(&self) -> (usize, usize)

Clean up stale nodes and old pingwave cache entries

Source

pub fn stats(&self) -> GraphStats

Get graph statistics

Source

pub fn node_count(&self) -> usize

Get node count

Source

pub fn edge_count(&self) -> usize

Get edge count

Trait Implementations§

Source§

impl Debug for LocalGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more