fix: harden reliability, clean up KMP compliance, and improve code quality (#5023)

This commit is contained in:
James Rich 2026-04-09 13:21:46 -05:00 committed by GitHub
parent 537029a71c
commit 14b381c1eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
53 changed files with 370 additions and 409 deletions

View file

@ -253,7 +253,13 @@ class MeshDataHandlerImpl(
val u =
User.ADAPTER.decode(payload)
.let { if (it.is_licensed == true) it.copy(public_key = okio.ByteString.EMPTY) else it }
.let { if (packet.via_mqtt == true) it.copy(long_name = "${it.long_name} (MQTT)") else it }
.let {
if (packet.via_mqtt == true && !it.long_name.endsWith(" (MQTT)")) {
it.copy(long_name = "${it.long_name} (MQTT)")
} else {
it
}
}
nodeManager.handleReceivedUser(packet.from, u, packet.channel)
}

View file

@ -170,19 +170,27 @@ class NodeManagerImpl(
}
override fun updateNode(nodeNum: Int, withBroadcast: Boolean, channel: Int, transform: (Node) -> Node) {
val next = transform(_nodeDBbyNodeNum.value[nodeNum] ?: getOrCreateNode(nodeNum, channel))
_nodeDBbyNodeNum.update { it.put(nodeNum, next) }
if (next.user.id.isNotEmpty()) {
_nodeDBbyID.update { it.put(next.user.id, next) }
// Perform read + transform inside update{} to ensure atomicity.
// Without this, concurrent calls for the same nodeNum could read the same snapshot
// and the last writer would silently overwrite the other's changes.
var next: Node? = null
_nodeDBbyNodeNum.update { map ->
val current = map[nodeNum] ?: getOrCreateNode(nodeNum, channel)
val transformed = transform(current)
next = transformed
map.put(nodeNum, transformed)
}
val result = next ?: return
if (result.user.id.isNotEmpty()) {
_nodeDBbyID.update { it.put(result.user.id, result) }
}
if (next.user.id.isNotEmpty() && isNodeDbReady.value) {
scope.handledLaunch { nodeRepository.upsert(next) }
if (result.user.id.isNotEmpty() && isNodeDbReady.value) {
scope.handledLaunch { nodeRepository.upsert(result) }
}
if (withBroadcast) {
serviceBroadcasts.broadcastNodeChange(next)
serviceBroadcasts.broadcastNodeChange(result)
}
}
@ -282,7 +290,7 @@ class NodeManagerImpl(
} else {
var newUser =
user.let { if (it.is_licensed == true) it.copy(public_key = ByteString.EMPTY) else it }
if (info.via_mqtt) {
if (info.via_mqtt && !newUser.long_name.endsWith(" (MQTT)")) {
newUser = newUser.copy(long_name = "${newUser.long_name} (MQTT)")
}
next = next.copy(user = newUser, publicKey = newUser.public_key)