feat: Implement KMP ServiceDiscovery for TCP devices#4854
Merged
jamesarich merged 7 commits intomainfrom Mar 19, 2026
Merged
Conversation
- Migrated NsdManager to use Kotlin Channels and Mutex to prevent race conditions on Android. - Abstracted NetworkRepository and NetworkMonitor to commonMain. - Added JmDNS dependency for Desktop mDNS TCP discovery. - Wired up live TCP device discovery in Desktop connections screen.
…sktop TCP discovery
…d feature extraction
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #4854 +/- ##
==========================================
+ Coverage 10.13% 10.43% +0.29%
==========================================
Files 545 551 +6
Lines 18095 18190 +95
Branches 2697 2715 +18
==========================================
+ Hits 1834 1898 +64
- Misses 16081 16097 +16
- Partials 180 195 +15
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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 pull request refactors the network discovery and monitoring logic to use a multiplatform architecture, introducing common interfaces and implementations for both Android and JVM (desktop) targets. It adds new abstractions for service discovery and network monitoring, and provides platform-specific implementations for each. The changes also update dependency management and documentation to reflect these architectural improvements.
Multiplatform abstractions and interface additions:
Introduced new common interfaces:
NetworkMonitor,ServiceDiscovery, and updatedNetworkRepositoryto depend on these abstractions, allowing for platform-specific implementations while sharing contracts across platforms. (core/network/src/commonMain/kotlin/org/meshtastic/core/network/repository/NetworkMonitor.kt[1]core/network/src/commonMain/kotlin/org/meshtastic/core/network/repository/ServiceDiscovery.kt[2]core/network/src/commonMain/kotlin/org/meshtastic/core/network/repository/NetworkRepository.kt[3]Added a new multiplatform data class
DiscoveredServiceto represent discovered network services in a platform-agnostic way. (core/network/src/commonMain/kotlin/org/meshtastic/core/network/repository/DiscoveredService.ktcore/network/src/commonMain/kotlin/org/meshtastic/core/network/repository/DiscoveredService.ktR1-R24)Platform-specific implementations:
AndroidNetworkMonitorandAndroidServiceDiscovery, which useConnectivityManagerandNsdManagerrespectively to provide the new interfaces. (core/network/src/androidMain/kotlin/org/meshtastic/core/network/repository/AndroidNetworkMonitor.kt[1]core/network/src/androidMain/kotlin/org/meshtastic/core/network/repository/AndroidServiceDiscovery.kt[2]JvmNetworkMonitor(always online) andJvmServiceDiscovery(using JmDNS for mDNS service discovery). (core/network/src/jvmMain/kotlin/org/meshtastic/core/network/repository/JvmNetworkMonitor.kt[1]core/network/src/jvmMain/kotlin/org/meshtastic/core/network/repository/JvmServiceDiscovery.kt[2]Refactoring and dependency injection:
NetworkRepositoryintoNetworkRepositoryImpl, which now depends on the new interfaces rather than platform-specific classes, and moved it to commonMain. Updated dependency injection annotations to bind the interface. (core/network/src/commonMain/kotlin/org/meshtastic/core/network/repository/NetworkRepositoryImpl.kt[1] [2] [3] [4] [5]Android service discovery improvements:
NsdManager.serviceListimplementation for Android, adding robust error handling, timeouts, and backoff for service resolution, and ensuring thread safety with a mutex. (core/network/src/androidMain/kotlin/org/meshtastic/core/network/repository/NsdManager.kt[1] [2]Dependency and documentation updates:
core/network/build.gradle.ktscore/network/build.gradle.ktsR51-R58)docs/kmp-status.md[1] [2]