This commit is contained in:
callebtc
2025-07-21 19:18:46 +02:00
parent 554b687ad8
commit bfb9a535ac
6 changed files with 20 additions and 19 deletions
@@ -61,6 +61,9 @@ class BluetoothMeshService(private val context: Context) {
init {
setupDelegates()
// Wire up PacketProcessor reference for recursive handling in MessageHandler
messageHandler.packetProcessor = packetProcessor
// startPeriodicDebugLogging()
}
@@ -41,7 +41,7 @@ class BluetoothPacketBroadcaster(
fragments.forEach { fragment ->
broadcastSinglePacket(RoutedPacket(fragment), gattServer, characteristic)
// 20ms delay between fragments (matching iOS/Rust)
delay(20)
delay(200)
}
}
return
@@ -27,6 +27,9 @@ class MessageHandler(private val myPeerID: String) {
// Delegate for callbacks
var delegate: MessageHandlerDelegate? = null
// Reference to PacketProcessor for recursive packet handling
var packetProcessor: PacketProcessor? = null
// Coroutines
private val handlerScope = CoroutineScope(Dispatchers.IO + SupervisorJob())
@@ -88,14 +91,11 @@ class MessageHandler(private val myPeerID: String) {
// Create a new routed packet with the decrypted inner packet
val innerRouted = RoutedPacket(innerPacket, peerID, routed.relayAddress)
// Process the decrypted inner packet recursively
when (MessageType.fromValue(innerPacket.type)) {
MessageType.MESSAGE -> handleMessage(innerRouted)
MessageType.DELIVERY_ACK -> handleDeliveryAck(innerRouted)
MessageType.READ_RECEIPT -> handleReadReceipt(innerRouted)
else -> {
Log.w(TAG, "Unexpected inner packet type: ${innerPacket.type}")
}
// Use PacketProcessor to handle the inner packet recursively
if (packetProcessor != null) {
packetProcessor!!.processPacket(innerRouted)
} else {
Log.w(TAG, "PacketProcessor reference is null; cannot recursively process inner packet.")
}
} else {
Log.w(TAG, "Failed to parse decrypted data as packet from $peerID")
@@ -39,9 +39,9 @@ class PacketProcessor(private val myPeerID: String) {
Log.d(TAG, "🎭 Created packet actor for peer: $peerID")
try {
for (packet in channel) {
Log.d(TAG, "🔒 Processing packet type ${packet.packet.type} from $peerID (serialized)")
Log.d(TAG, "Processing packet type ${packet.packet.type} from $peerID (serialized)")
handleReceivedPacket(packet)
Log.d(TAG, "🔓 Completed packet type ${packet.packet.type} from $peerID")
Log.d(TAG, "Completed packet type ${packet.packet.type} from $peerID")
}
} finally {
Log.d(TAG, "🎭 Packet actor for $peerID terminated")