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,
)