From c712d7ef6890e8d46e7b5d148f45493a2fe27f72 Mon Sep 17 00:00:00 2001 From: James Rich Date: Tue, 5 May 2026 16:46:54 -0500 Subject: [PATCH] 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> --- .../manager/StoreForwardPacketHandlerImpl.kt | 2 - .../StoreForwardPacketHandlerImplTest.kt | 3 - .../meshtastic/core/model/util/SfppHasher.kt | 25 ------ .../core/model/util/SfppHasherTest.kt | 87 ------------------- 4 files changed, 117 deletions(-) delete mode 100644 core/model/src/commonMain/kotlin/org/meshtastic/core/model/util/SfppHasher.kt delete mode 100644 core/model/src/commonTest/kotlin/org/meshtastic/core/model/util/SfppHasherTest.kt diff --git a/core/data/src/commonMain/kotlin/org/meshtastic/core/data/manager/StoreForwardPacketHandlerImpl.kt b/core/data/src/commonMain/kotlin/org/meshtastic/core/data/manager/StoreForwardPacketHandlerImpl.kt index 39fbc3b7b..7fef493f8 100644 --- a/core/data/src/commonMain/kotlin/org/meshtastic/core/data/manager/StoreForwardPacketHandlerImpl.kt +++ b/core/data/src/commonMain/kotlin/org/meshtastic/core/data/manager/StoreForwardPacketHandlerImpl.kt @@ -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, private val historyManager: HistoryManager, private val dataHandler: Lazy, diff --git a/core/data/src/commonTest/kotlin/org/meshtastic/core/data/manager/StoreForwardPacketHandlerImplTest.kt b/core/data/src/commonTest/kotlin/org/meshtastic/core/data/manager/StoreForwardPacketHandlerImplTest.kt index 75e37318f..5bbce6fc9 100644 --- a/core/data/src/commonTest/kotlin/org/meshtastic/core/data/manager/StoreForwardPacketHandlerImplTest.kt +++ b/core/data/src/commonTest/kotlin/org/meshtastic/core/data/manager/StoreForwardPacketHandlerImplTest.kt @@ -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(MockMode.autofill) private val packetRepository = mock(MockMode.autofill) private val historyManager = mock(MockMode.autofill) private val dataHandler = mock(MockMode.autofill) @@ -59,7 +57,6 @@ class StoreForwardPacketHandlerImplTest { fun setUp() { handler = StoreForwardPacketHandlerImpl( - nodeRepository = nodeRepository, packetRepository = lazy { packetRepository }, historyManager = historyManager, dataHandler = lazy { dataHandler }, diff --git a/core/model/src/commonMain/kotlin/org/meshtastic/core/model/util/SfppHasher.kt b/core/model/src/commonMain/kotlin/org/meshtastic/core/model/util/SfppHasher.kt deleted file mode 100644 index 3a6caf542..000000000 --- a/core/model/src/commonMain/kotlin/org/meshtastic/core/model/util/SfppHasher.kt +++ /dev/null @@ -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 . - */ -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) -} diff --git a/core/model/src/commonTest/kotlin/org/meshtastic/core/model/util/SfppHasherTest.kt b/core/model/src/commonTest/kotlin/org/meshtastic/core/model/util/SfppHasherTest.kt deleted file mode 100644 index 917414e3d..000000000 --- a/core/model/src/commonTest/kotlin/org/meshtastic/core/model/util/SfppHasherTest.kt +++ /dev/null @@ -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 . - */ -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()) - } -}