Skip to content

fix(node): Correct owner ID and local user detection#4256

Merged
jamesarich merged 1 commit into
mainfrom
fix/names
Jan 19, 2026
Merged

fix(node): Correct owner ID and local user detection#4256
jamesarich merged 1 commit into
mainfrom
fix/names

Conversation

@jamesarich

Copy link
Copy Markdown
Collaborator

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.

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>
@github-actions github-actions Bot added the bugfix PR tag label Jan 19, 2026
@codecov

codecov Bot commented Jan 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (a418563) to head (9575b15).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

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.
📢 Have feedback on the report? Share it here.

@jamesarich jamesarich added this pull request to the merge queue Jan 19, 2026
Merged via the queue into main with commit 3b0dda4 Jan 19, 2026
11 checks passed
@jamesarich jamesarich deleted the fix/names branch January 19, 2026 03:50
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix PR tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant