NodeManager

Interface for managing the in-memory node database and processing received node information.

Properties

Link copied to clipboard
abstract val allowNodeDbWrites: StateFlow<Boolean>

Whether node database writes are allowed.

Link copied to clipboard
abstract val connectionIdentity: StateFlow<ConnectionIdentity?>

Fresh-handshake identity for the current connection session. Null when no handshake identity has been confirmed for the active transport. Cleared synchronously before a new address is published, and populated atomically when handleMyInfo captures the selected address and decodes nodeNum and deviceId from the same MyNodeInfo packet. Generation-boundary cleanup atomically preserves an identity already published for the new session. Never populated by loadCachedNodeDB or reactive DB cache emissions.

Link copied to clipboard
abstract val firmwareEdition: StateFlow<FirmwareEdition?>

The firmware edition reported by the connected device.

Link copied to clipboard
abstract val isNodeDbReady: StateFlow<Boolean>

Whether the node database is ready.

Link copied to clipboard
abstract val myDeviceId: StateFlow<String?>

The connected device's factory-burned hardware id from MyNodeInfo, as a thread-safe StateFlow. Null when not connected or when the hardware/firmware doesn't report one. Unlike myNodeNum (which firmware 2.8 re-derives from the public key), this survives upgrades, erases, and key changes.

Link copied to clipboard
abstract val myNodeNum: StateFlow<Int?>

The local node number as a thread-safe StateFlow.

Link copied to clipboard
abstract val nodeDBbyNodeNum: Map<Int, Node>

Reactive map of all nodes by their number.

Link copied to clipboard
abstract val reportsHeardOnCurrentLora: StateFlow<Boolean>

Whether the connected firmware reports NodeInfo.heard_on_current_lora. False until local metadata proves it, and false again on disconnect. Consumers of the unheard state (marker, banner, filter) gate on this rather than on the stored flag alone, so a stale false cannot surface while the database normalization is still in flight.

Functions

Link copied to clipboard
abstract fun applySessionNode(info: NodeInfo, changed: Set<NodeField>?, session: RadioSessionContext)

Applies a node the SDK session added (changed null) or updated after Ready. A user change routes through handleReceivedUser so identity correlation, retirement and the new-node notification apply; other fields merge only as far as changed names them, and never touch the app-owned link metrics.

Link copied to clipboard
abstract fun applySessionNodeRemoved(nodeNum: Int)

Removes a node the SDK dropped after an acknowledged removeNode, ending any local removal waiting for it.

Link copied to clipboard
abstract fun applyTrustedIdentityMigrations(removedNums: Collection<Int>)

Applies node-number removals returned by the trusted configuration install. Removed numbers stay retired for the current device/database session so delayed field packets cannot recreate migrated identities.

Link copied to clipboard
open fun cancelPendingRemoval(nodeNum: Int)

Ends a removal the radio did not apply, so the node's next packet brings it back.

Link copied to clipboard
abstract fun clear()

Clears the in-memory node database.

Link copied to clipboard

Clears the connection-session identity source synchronously.

Link copied to clipboard
abstract fun clearStaleConnectionIdentity(activeSessionGeneration: Long)

Atomically clears an identity retained from a generation other than activeSessionGeneration. An identity that already belongs to the active generation is preserved, even when its publication races a delayed boundary collector from the same generation.

Link copied to clipboard
abstract fun getMyId(): String

Returns the local node ID.

Link copied to clipboard
abstract fun getMyNodeInfo(): MyNodeInfo?

Returns information about the local node.

Link copied to clipboard
abstract fun getNodeById(id: String): Node?

Look up a node by its user ID string (e.g. "!a1b2c3d4").

Link copied to clipboard
abstract fun handleReceivedNodeStatus(fromNum: Int, s: StatusMessage, session: RadioSessionContext? = null)

Processes a received node status message.

Link copied to clipboard
abstract fun handleReceivedPaxcounter(fromNum: Int, p: Paxcount, session: RadioSessionContext? = null)

Processes a received paxcounter packet.

Link copied to clipboard
abstract fun handleReceivedPosition(fromNum: Int, myNodeNum: Int, p: Position, defaultTime: Long, session: RadioSessionContext? = null)

Processes a received position packet.

Link copied to clipboard
abstract fun handleReceivedUser(fromNum: Int, p: User, channel: Int = 0, manuallyVerified: Boolean = false, session: RadioSessionContext? = null)

Processes a received user packet.

Link copied to clipboard
abstract fun insertMetadata(nodeNum: Int, metadata: DeviceMetadata, session: RadioSessionContext? = null)

Inserts hardware metadata for a node.

Link copied to clipboard
abstract fun installNodeInfo(info: NodeInfo)

Installs a node from an SDK handshake or NodeDB refresh snapshot in memory. The caller persists the whole snapshot through NodeRepository.installConfig.

Link copied to clipboard
abstract fun loadCachedNodeDB()

Loads the cached node database from the repository.

Link copied to clipboard
abstract fun publishConnectionIdentity(sessionGeneration: Long, address: String, nodeNum: Int, deviceId: String?)

Publishes a fresh connection-session identity from a handshake MyNodeInfo. Invoked exactly once per handshake after sessionGeneration, address, nodeNum, and deviceId have been captured for the same session.

Link copied to clipboard
abstract fun removeByNodenum(nodeNum: Int)

Removes a node from the in-memory database by its number.

Link copied to clipboard
abstract fun setAllowNodeDbWrites(allowed: Boolean)

Sets whether node database writes are allowed.

Link copied to clipboard
abstract fun setFirmwareEdition(edition: FirmwareEdition?)

Sets the firmware edition of the connected device.

Link copied to clipboard
abstract fun setFirmwareVersion(version: String?, session: RadioSessionContext? = null)

Records the connected device's firmware version so node ingestion can gate on its capabilities. Passing null (a disconnect, or metadata not yet received) resets to the least-capable assumption.

Link copied to clipboard
abstract fun setMyDeviceId(id: String?)

Sets the connected device's hardware id.

Link copied to clipboard
abstract fun setMyNodeNum(num: Int?)

Sets the local node number.

Link copied to clipboard
abstract fun setNodeDbReady(ready: Boolean)

Sets whether the node database is ready.

Link copied to clipboard
abstract fun toNodeID(nodeNum: Int): String
Link copied to clipboard
abstract fun updateNode(nodeNum: Int, channel: Int = 0, transform: (Node) -> Node)

Updates a node using a side-effect-free transform and schedules persistence. The transform may be evaluated more than once after compare-and-set contention; callers must perform notifications and other effects afterward.

Link copied to clipboard
abstract fun updateNodeForSession(nodeNum: Int, session: RadioSessionContext, channel: Int = 0, transform: (Node) -> Node)

Session-bound counterpart to updateNode; deferred persistence is admitted only for session.

Link copied to clipboard
abstract suspend fun updateNodeStatusAndPersist(nodeNum: Int, status: String?)

Updates node status and awaits any required persistence.