This commit is contained in:
James Rich 2026-04-20 07:28:34 -05:00 committed by GitHub
commit e78faebde2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 1600 additions and 0 deletions

View file

@ -48,6 +48,7 @@ import org.meshtastic.core.repository.PacketHandler
import org.meshtastic.core.repository.PacketRepository
import org.meshtastic.core.repository.PlatformAnalytics
import org.meshtastic.core.repository.RadioConfigRepository
import org.meshtastic.core.repository.RemoteShellHandler
import org.meshtastic.core.repository.ServiceBroadcasts
import org.meshtastic.core.repository.ServiceRepository
import org.meshtastic.core.repository.StoreForwardPacketHandler
@ -96,6 +97,7 @@ class MeshDataHandlerImpl(
private val storeForwardHandler: StoreForwardPacketHandler,
private val telemetryHandler: TelemetryPacketHandler,
private val adminPacketHandler: AdminPacketHandler,
private val remoteShellHandler: RemoteShellHandler,
@Named("ServiceScope") private val scope: CoroutineScope,
) : MeshDataHandler {
@ -181,6 +183,12 @@ class MeshDataHandlerImpl(
adminPacketHandler.handleAdminMessage(packet, myNodeNum)
}
PortNum.REMOTE_SHELL_APP -> {
remoteShellHandler.handleRemoteShell(packet)
// Do not broadcast — RemoteShell frames are point-to-point PTY I/O
shouldBroadcast = false
}
PortNum.NEIGHBORINFO_APP -> {
neighborInfoHandler.handleNeighborInfo(packet)
shouldBroadcast = true

View file

@ -0,0 +1,55 @@
/*
* Copyright (c) 2025-2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.data.manager
import co.touchlab.kermit.Logger
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import org.koin.core.annotation.Single
import org.meshtastic.core.model.util.decodeOrNull
import org.meshtastic.core.repository.ReceivedShellFrame
import org.meshtastic.core.repository.RemoteShellHandler
import org.meshtastic.proto.MeshPacket
import org.meshtastic.proto.RemoteShell
/**
* Handles incoming [RemoteShell] packets (REMOTE_SHELL_APP portnum = 13).
*
* This is a scaffold implementation. The RemoteShell firmware feature is currently unreleased (gated to
* [org.meshtastic.core.model.Capabilities.supportsRemoteShell]). When the firmware ships, this handler should be
* expanded to manage PTY session state and relay I/O to the UI.
*/
@Single
class RemoteShellPacketHandlerImpl : RemoteShellHandler {
/**
* Emits every received [ReceivedShellFrame] (decoded frame + sender node number).
*
* Uses [MutableSharedFlow] with a buffer so that rapid or structurally-identical frames are never silently dropped
* (unlike `StateFlow` which conflates by equality).
*/
private val _lastFrame = MutableSharedFlow<ReceivedShellFrame>(extraBufferCapacity = 16)
override val lastFrame: SharedFlow<ReceivedShellFrame> = _lastFrame.asSharedFlow()
override fun handleRemoteShell(packet: MeshPacket) {
val payload = packet.decoded?.payload ?: return
val frame = RemoteShell.ADAPTER.decodeOrNull(payload, Logger) ?: return
Logger.d { "RemoteShell frame from ${packet.from}: op=${frame.op} sessionId=${frame.session_id}" }
_lastFrame.tryEmit(ReceivedShellFrame(from = packet.from, frame = frame))
}
}

View file

@ -45,6 +45,7 @@ import org.meshtastic.core.repository.PacketHandler
import org.meshtastic.core.repository.PacketRepository
import org.meshtastic.core.repository.PlatformAnalytics
import org.meshtastic.core.repository.RadioConfigRepository
import org.meshtastic.core.repository.RemoteShellHandler
import org.meshtastic.core.repository.ServiceBroadcasts
import org.meshtastic.core.repository.ServiceRepository
import org.meshtastic.core.repository.StoreForwardPacketHandler
@ -84,6 +85,7 @@ class MeshDataHandlerTest {
private val storeForwardHandler: StoreForwardPacketHandler = mock(MockMode.autofill)
private val telemetryHandler: TelemetryPacketHandler = mock(MockMode.autofill)
private val adminPacketHandler: AdminPacketHandler = mock(MockMode.autofill)
private val remoteShellHandler: RemoteShellHandler = mock(MockMode.autofill)
private val testDispatcher = StandardTestDispatcher()
private val testScope = TestScope(testDispatcher)
@ -108,6 +110,7 @@ class MeshDataHandlerTest {
storeForwardHandler = storeForwardHandler,
telemetryHandler = telemetryHandler,
adminPacketHandler = adminPacketHandler,
remoteShellHandler = remoteShellHandler,
scope = testScope,
)

View file

@ -64,6 +64,12 @@ data class Capabilities(val firmwareVersion: String?, internal val forceEnableAl
/** Support for ESP32 Unified OTA. Supported since firmware v2.7.18. */
val supportsEsp32Ota = atLeast(V2_7_18)
/**
* Support for the RemoteShell module (PTY-over-mesh, REMOTE_SHELL_APP portnum). Defined in protobufs HEAD
* (post-v2.7.21); gated to [UNRELEASED] until a firmware release ships it.
*/
val supportsRemoteShell = atLeast(UNRELEASED)
companion object {
private val V2_6_8 = DeviceVersion("2.6.8")
private val V2_6_9 = DeviceVersion("2.6.9")

View file

@ -85,6 +85,12 @@ class CapabilitiesTest {
assertTrue(caps("2.7.19").supportsTakConfig)
}
@Test
fun supportsRemoteShell_is_currently_unreleased() {
assertFalse(caps("2.7.22").supportsRemoteShell)
assertFalse(caps("3.0.0").supportsRemoteShell)
}
@Test
fun supportsEsp32Ota_requires_V2_7_18() {
assertFalse(caps("2.7.17").supportsEsp32Ota)
@ -104,6 +110,7 @@ class CapabilitiesTest {
assertFalse(c.supportsStatusMessage)
assertFalse(c.supportsTrafficManagementConfig)
assertFalse(c.supportsTakConfig)
assertFalse(c.supportsRemoteShell)
assertFalse(c.supportsEsp32Ota)
}
@ -115,5 +122,6 @@ class CapabilitiesTest {
assertTrue(c.supportsStatusMessage)
assertTrue(c.supportsTrafficManagementConfig)
assertTrue(c.supportsTakConfig)
assertTrue(c.supportsRemoteShell)
}
}

View file

@ -92,6 +92,8 @@ sealed interface NodeDetailRoute : Route {
@Serializable data class PaxMetrics(val destNum: Int) : NodeDetailRoute
@Serializable data class NeighborInfoLog(val destNum: Int) : NodeDetailRoute
@Serializable data class RemoteShell(val destNum: Int) : NodeDetailRoute
}
@Serializable

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2025-2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.repository
import kotlinx.coroutines.flow.SharedFlow
import org.meshtastic.proto.MeshPacket
import org.meshtastic.proto.RemoteShell
/**
* A decoded [RemoteShell] frame together with the node number that sent it.
*
* Propagating [from] allows downstream consumers (e.g. the ViewModel) to verify that a frame actually originated from
* the expected peer rather than relying solely on [RemoteShell.session_id].
*/
data class ReceivedShellFrame(val from: Int, val frame: RemoteShell)
/**
* Interface for handling RemoteShell packets (REMOTE_SHELL_APP portnum = 13).
*
* RemoteShell is a PTY-over-mesh feature that relays a shell session across the mesh network. The firmware-side
* implementation is currently unreleased (gated to [Capabilities.supportsRemoteShell]).
*/
interface RemoteShellHandler {
/**
* The most recently received [ReceivedShellFrame], emitted to collectors.
*
* Uses [SharedFlow] (not `StateFlow`) so that rapid or identical frames are never silently dropped.
*/
val lastFrame: SharedFlow<ReceivedShellFrame>
/**
* Processes an incoming RemoteShell packet.
*
* @param packet The received mesh packet carrying a [RemoteShell] payload.
*/
fun handleRemoteShell(packet: MeshPacket)
}

View file

@ -862,6 +862,8 @@
<string name="modules_unlocked">Modules unlocked</string>
<string name="modules_already_unlocked">Modules already unlocked</string>
<string name="remote">Remote</string>
<string name="remote_shell">Remote Shell</string>
<string name="phosphor_colour">Phosphor colour</string>
<string name="node_count_template">(%1$d online / %2$d shown / %3$d total)</string>
<string name="react">React</string>
<string name="disconnect">Disconnect</string>