chore: remove dead SfppHasher + unused NodeRepository injection

- Delete SfppHasher wrapper (SDK SfppHash handles SFPP hashing)
- Remove unused NodeRepository from StoreForwardPacketHandlerImpl
- Update tests to match constructor change

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
James Rich
2026-05-05 16:46:54 -05:00
parent 64464196b0
commit c712d7ef68
4 changed files with 0 additions and 117 deletions

View File

@@ -24,7 +24,6 @@ import org.koin.core.annotation.Single
import org.meshtastic.core.model.DataPacket
import org.meshtastic.core.repository.HistoryManager
import org.meshtastic.core.repository.MeshDataHandler
import org.meshtastic.core.repository.NodeRepository
import org.meshtastic.core.repository.PacketRepository
import org.meshtastic.core.repository.StoreForwardPacketHandler
import org.meshtastic.proto.MeshPacket
@@ -39,7 +38,6 @@ import kotlin.time.Duration.Companion.milliseconds
*/
@Single
class StoreForwardPacketHandlerImpl(
private val nodeRepository: NodeRepository,
private val packetRepository: Lazy<PacketRepository>,
private val historyManager: HistoryManager,
private val dataHandler: Lazy<MeshDataHandler>,

View File

@@ -31,7 +31,6 @@ import okio.ByteString.Companion.toByteString
import org.meshtastic.core.model.DataPacket
import org.meshtastic.core.repository.HistoryManager
import org.meshtastic.core.repository.MeshDataHandler
import org.meshtastic.core.repository.NodeRepository
import org.meshtastic.core.repository.PacketRepository
import org.meshtastic.proto.Data
import org.meshtastic.proto.MeshPacket
@@ -43,7 +42,6 @@ import kotlin.test.Test
@OptIn(ExperimentalCoroutinesApi::class)
class StoreForwardPacketHandlerImplTest {
private val nodeRepository = mock<NodeRepository>(MockMode.autofill)
private val packetRepository = mock<PacketRepository>(MockMode.autofill)
private val historyManager = mock<HistoryManager>(MockMode.autofill)
private val dataHandler = mock<MeshDataHandler>(MockMode.autofill)
@@ -59,7 +57,6 @@ class StoreForwardPacketHandlerImplTest {
fun setUp() {
handler =
StoreForwardPacketHandlerImpl(
nodeRepository = nodeRepository,
packetRepository = lazy { packetRepository },
historyManager = historyManager,
dataHandler = lazy { dataHandler },

View File

@@ -1,25 +0,0 @@
/*
* Copyright (c) 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.model.util
import org.meshtastic.sdk.SfppHash
/** Computes SFPP (Store-Forward-Plus-Plus) message hashes for deduplication. */
object SfppHasher {
fun computeMessageHash(encryptedPayload: ByteArray, to: Int, from: Int, id: Int): ByteArray =
SfppHash.compute(encryptedPayload, to, from, id)
}

View File

@@ -1,87 +0,0 @@
/*
* Copyright (c) 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.model.util
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals
class SfppHasherTest {
@Test
fun outputIsAlways16Bytes() {
val hash = SfppHasher.computeMessageHash(byteArrayOf(1, 2, 3), to = 100, from = 200, id = 1)
assertEquals(16, hash.size)
}
@Test
fun emptyPayloadProduces16Bytes() {
val hash = SfppHasher.computeMessageHash(byteArrayOf(), to = 0, from = 0, id = 0)
assertEquals(16, hash.size)
}
@Test
fun deterministicOutput() {
val a = SfppHasher.computeMessageHash(byteArrayOf(0xAB.toByte()), to = 1, from = 2, id = 3)
val b = SfppHasher.computeMessageHash(byteArrayOf(0xAB.toByte()), to = 1, from = 2, id = 3)
assertEquals(a.toList(), b.toList())
}
@Test
fun differentPayloadsProduceDifferentHashes() {
val a = SfppHasher.computeMessageHash(byteArrayOf(1), to = 1, from = 2, id = 3)
val b = SfppHasher.computeMessageHash(byteArrayOf(2), to = 1, from = 2, id = 3)
assertNotEquals(a.toList(), b.toList())
}
@Test
fun differentIdsProduceDifferentHashes() {
val payload = byteArrayOf(0x10, 0x20)
val a = SfppHasher.computeMessageHash(payload, to = 1, from = 2, id = 100)
val b = SfppHasher.computeMessageHash(payload, to = 1, from = 2, id = 101)
assertNotEquals(a.toList(), b.toList())
}
@Test
fun differentFromProduceDifferentHashes() {
val payload = byteArrayOf(0x10, 0x20)
val a = SfppHasher.computeMessageHash(payload, to = 1, from = 2, id = 3)
val b = SfppHasher.computeMessageHash(payload, to = 1, from = 99, id = 3)
assertNotEquals(a.toList(), b.toList())
}
@Test
fun maxIntValues() {
val hash =
SfppHasher.computeMessageHash(
byteArrayOf(0xFF.toByte()),
to = Int.MAX_VALUE,
from = Int.MAX_VALUE,
id = Int.MAX_VALUE,
)
assertEquals(16, hash.size)
}
@Test
fun littleEndianByteOrder() {
// Verify the integer 0x04030201 is encoded as [01, 02, 03, 04] (little-endian)
val hashA = SfppHasher.computeMessageHash(byteArrayOf(), to = 0x04030201, from = 0, id = 0)
val hashB = SfppHasher.computeMessageHash(byteArrayOf(), to = 0x01020304, from = 0, id = 0)
// Different byte orderings must produce different hashes
assertNotEquals(hashA.toList(), hashB.toList())
}
}