Cheap routing optimizations

- Don't relay back to sender or relayer
- Only send to connected device if recipientID matches one
- Don't relay our own ACK/read receipt
This commit is contained in:
GUVWAF
2025-07-12 13:18:09 +02:00
parent 4545afb0c4
commit d1085fde0b
6 changed files with 216 additions and 114 deletions
@@ -4,6 +4,7 @@ import android.util.Log
import com.bitchat.android.crypto.EncryptionService
import com.bitchat.android.protocol.BitchatPacket
import com.bitchat.android.protocol.MessageType
import com.bitchat.android.model.RoutedPacket
import kotlinx.coroutines.*
import java.util.*
import kotlin.collections.mutableSetOf
@@ -88,7 +89,10 @@ class SecurityManager(private val encryptionService: EncryptionService, private
/**
* Handle key exchange packet
*/
suspend fun handleKeyExchange(packet: BitchatPacket, peerID: String): Boolean {
suspend fun handleKeyExchange(routed: RoutedPacket): Boolean {
val packet = routed.packet
val peerID = routed.peerID ?: "unknown"
if (peerID == myPeerID) return false
if (packet.payload.isEmpty()) {
@@ -113,7 +117,7 @@ class SecurityManager(private val encryptionService: EncryptionService, private
Log.d(TAG, "Successfully processed key exchange from $peerID")
// Notify delegate
delegate?.onKeyExchangeCompleted(peerID, packet.payload)
delegate?.onKeyExchangeCompleted(peerID, packet.payload, routed.relayAddress)
return true
@@ -315,5 +319,5 @@ class SecurityManager(private val encryptionService: EncryptionService, private
* Delegate interface for security manager callbacks
*/
interface SecurityManagerDelegate {
fun onKeyExchangeCompleted(peerID: String, peerPublicKeyData: ByteArray)
fun onKeyExchangeCompleted(peerID: String, peerPublicKeyData: ByteArray, receivedAddress: String?)
}