fix(node): Correct owner ID and local user detection#4256
Merged
Conversation
This commit introduces several fixes to improve node and user identification, particularly for the local user, and enhances connection stability.
### Key Changes:
- **Correct Owner ID:** In `RadioConfigViewModel`, the `setOwner` function now ensures the correct user ID is used when setting a remote node's owner. It prevents accidentally using the local user's ID by validating it against the target node's existing user ID.
- **Improved Local User Detection:** The definition of a "local user" has been expanded. Previously, it was only checked against `DataPacket.ID_LOCAL`. Now, it also correctly compares against `myId` from `NodeRepository`. This fixes issues in `ContactsViewModel` and `MapView` where messages and map markers from the local user on other devices were not identified as "You".
- **Connection Keep-Alive:** A `keepAlive()` method has been added to the `RadioInterface` and implemented for `TCPInterface`, `SerialInterface`, and `NordicBleInterface`. A periodic heartbeat is now sent every 15 seconds from `RadioInterfaceService` for all connection types to prevent timeouts and maintain stable connections. The TCP implementation now sends an explicit `Heartbeat` packet.
- **Thread-Safe Stream Writes:** `StreamInterface` now uses a `Mutex` to protect write operations (`sendBytes`, `flushBytes`), preventing potential race conditions and data corruption when sending data over Serial or TCP connections.
- **Refactored State Updates:**
- `NodeRepository` now uses `combine` to derive `ourNodeInfo` and `myId`, ensuring these values are always in sync with the underlying node database and connection state.
- `ContactsViewModel` and `RadioConfigViewModel` have been refactored to use intermediate data classes or local variables for cleaner state management within `combine` blocks.
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4256 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 3 3
Lines 23 23
Branches 7 7
=====================================
Misses 23 23 ☔ View full report in Codecov by Sentry. |
jamesarich
added a commit
to jamesarich/Meshtastic-Android
that referenced
this pull request
Jan 21, 2026
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This commit introduces several fixes to improve node and user identification, particularly for the local user, and enhances connection stability.
Key Changes:
RadioConfigViewModel, thesetOwnerfunction now ensures the correct user ID is used when setting a remote node's owner. It prevents accidentally using the local user's ID by validating it against the target node's existing user ID.DataPacket.ID_LOCAL. Now, it also correctly compares againstmyIdfromNodeRepository. This fixes issues inContactsViewModelandMapViewwhere messages and map markers from the local user on other devices were not identified as "You".keepAlive()method has been added to theRadioInterfaceand implemented forTCPInterface,SerialInterface, andNordicBleInterface. A periodic heartbeat is now sent every 15 seconds fromRadioInterfaceServicefor all connection types to prevent timeouts and maintain stable connections. The TCP implementation now sends an explicitHeartbeatpacket.StreamInterfacenow uses aMutexto protect write operations (sendBytes,flushBytes), preventing potential race conditions and data corruption when sending data over Serial or TCP connections.NodeRepositorynow usescombineto deriveourNodeInfoandmyId, ensuring these values are always in sync with the underlying node database and connection state.ContactsViewModelandRadioConfigViewModelhave been refactored to use intermediate data classes or local variables for cleaner state management withincombineblocks.