MeshTopology

Incremental mesh topology graph built from NeighborInfo reports.

Usage:

val topology = MeshTopology()
topology.addNeighborInfo(neighborInfo)
val path = topology.shortestPath(nodeA, nodeB)
val neighbors = topology.getNeighbors(nodeA)

Thread-safe — all mutations and reads are guarded by an internal Mutex, so this class is safe to call concurrently from any coroutine context. This is a consumer-side utility; it is not used inside the engine actor's hot path and therefore does not violate the single-writer invariant (ADR-002).

The graph is directed — if node A reports node B as a neighbor, that's a directed edge A→B. Undirected queries consider both directions.

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
data class Edge(val from: NodeId, val to: NodeId, val snr: Float, val lastUpdated: Int = 0)

Directed edge from a reporting node from to a neighbor to, carrying the reported signal quality (snr) and the NeighborInfo.lastUpdated value from the source report.

Functions

Link copied to clipboard
suspend fun addNeighborInfo(info: NeighborInfo)

Ingest a NeighborInfo report, replacing all edges from the reporting node.

Link copied to clipboard

Get all edges in the topology graph.

Link copied to clipboard
suspend fun clear()

Clear all topology data.

Link copied to clipboard
suspend fun edgeCount(): Int

Number of directed edges.

Link copied to clipboard
suspend fun getEdge(from: NodeId, to: NodeId): MeshTopology.Edge?

Get the edge from from to to (if from reported to as neighbor).

Link copied to clipboard
suspend fun getNeighbors(nodeId: NodeId): List<MeshTopology.Edge>

Get all outgoing edges from a node (nodes it reported as neighbors).

Link copied to clipboard
suspend fun isDirectReach(a: NodeId, b: NodeId): Boolean

Check if there's a direct edge in either direction between two nodes.

Link copied to clipboard
suspend fun nodes(): Set<NodeId>

All nodes that have reported neighbors or been reported as a neighbor.

Link copied to clipboard
suspend fun removeNode(nodeId: NodeId)

Remove a node and all edges referencing it.

Link copied to clipboard
suspend fun shortestPath(from: NodeId, to: NodeId): List<NodeId>

Find shortest path between two nodes using BFS on the undirected graph. Returns the path as a list of NodeIds including start and end. Returns listOf(from) when from == to. Returns an empty list when no path exists.