@magicred-1/ble-mesh 1.3.7 → 1.3.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -87,6 +87,14 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
87
87
|
val chunks: MutableMap<Int, ByteArray> = mutableMapOf()
|
|
88
88
|
)
|
|
89
89
|
|
|
90
|
+
// Transaction queuing for pending sessions
|
|
91
|
+
private val pendingTransactions = mutableMapOf<String, MutableList<PendingTransaction>>()
|
|
92
|
+
private data class PendingTransaction(
|
|
93
|
+
val txId: String,
|
|
94
|
+
val payload: ByteArray,
|
|
95
|
+
val maxPayloadSize: Int
|
|
96
|
+
)
|
|
97
|
+
|
|
90
98
|
// Coroutines
|
|
91
99
|
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
|
92
100
|
|
|
@@ -482,7 +490,10 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
482
490
|
if (sessions.containsKey(recipientPeerId)) {
|
|
483
491
|
sendTransactionToPeer(txId, payload, recipientPeerId, maxPayloadSize)
|
|
484
492
|
} else {
|
|
485
|
-
// No session, initiate handshake
|
|
493
|
+
// No session, queue transaction and initiate handshake
|
|
494
|
+
Log.d(TAG, "No session for $recipientPeerId, queuing transaction $txId and initiating handshake")
|
|
495
|
+
val pending = PendingTransaction(txId, payload, maxPayloadSize)
|
|
496
|
+
pendingTransactions.getOrPut(recipientPeerId) { mutableListOf() }.add(pending)
|
|
486
497
|
initiateHandshakeInternal(recipientPeerId)
|
|
487
498
|
}
|
|
488
499
|
} else {
|
|
@@ -513,6 +524,7 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
513
524
|
val encrypted = encryptPayload(encryptedPayload, recipientPeerId)
|
|
514
525
|
|
|
515
526
|
if (encrypted != null) {
|
|
527
|
+
Log.d(TAG, "Sending transaction $txId to $recipientPeerId (encrypted size: ${encrypted.size}, max: $maxPayloadSize)")
|
|
516
528
|
if (encrypted.size <= maxPayloadSize) {
|
|
517
529
|
// Small enough for single packet
|
|
518
530
|
val packet = createPacket(
|
|
@@ -521,11 +533,14 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
521
533
|
recipientId = hexStringToByteArray(recipientPeerId)
|
|
522
534
|
)
|
|
523
535
|
broadcastPacket(packet)
|
|
536
|
+
Log.d(TAG, "✅ Sent encrypted transaction $txId as single packet")
|
|
524
537
|
} else {
|
|
525
538
|
// Need to chunk large transaction
|
|
526
539
|
Log.d(TAG, "Transaction too large (${encrypted.size} bytes), using chunking")
|
|
527
540
|
sendChunkedTransaction(txId, encrypted, recipientPeerId)
|
|
528
541
|
}
|
|
542
|
+
} else {
|
|
543
|
+
Log.e(TAG, "❌ Failed to encrypt transaction $txId - no session with $recipientPeerId")
|
|
529
544
|
}
|
|
530
545
|
}
|
|
531
546
|
|
|
@@ -1237,6 +1252,18 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
1237
1252
|
peers[senderId] = peer.copy(noisePublicKey = packet.payload)
|
|
1238
1253
|
}
|
|
1239
1254
|
|
|
1255
|
+
// Send queued transactions for this peer
|
|
1256
|
+
val queuedTransactions = pendingTransactions.remove(senderId)
|
|
1257
|
+
if (!queuedTransactions.isNullOrEmpty()) {
|
|
1258
|
+
Log.d(TAG, "Sending ${queuedTransactions.size} queued transaction(s) to $senderId")
|
|
1259
|
+
scope.launch {
|
|
1260
|
+
queuedTransactions.forEach { pending ->
|
|
1261
|
+
sendTransactionToPeer(pending.txId, pending.payload, senderId, pending.maxPayloadSize)
|
|
1262
|
+
delay(50) // Small delay between transactions
|
|
1263
|
+
}
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1240
1267
|
// Send response handshake
|
|
1241
1268
|
if (packet.recipientId == null || packet.recipientId.contentEquals(myPeerIdBytes)) {
|
|
1242
1269
|
Log.d(TAG, "Sending handshake response to $senderId")
|
|
@@ -1254,16 +1281,31 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
1254
1281
|
private fun handleNoiseEncrypted(packet: BitchatPacket, senderId: String) {
|
|
1255
1282
|
// Check if message is for us
|
|
1256
1283
|
if (packet.recipientId != null && !packet.recipientId.contentEquals(myPeerIdBytes)) {
|
|
1284
|
+
Log.d(TAG, "Encrypted packet not for us")
|
|
1257
1285
|
return
|
|
1258
1286
|
}
|
|
1259
1287
|
|
|
1260
|
-
val sessionKey = sessions[senderId]
|
|
1261
|
-
|
|
1288
|
+
val sessionKey = sessions[senderId]
|
|
1289
|
+
if (sessionKey == null) {
|
|
1290
|
+
Log.w(TAG, "❌ No session key for $senderId, cannot decrypt")
|
|
1291
|
+
return
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
val decrypted = decryptPayload(packet.payload, sessionKey)
|
|
1295
|
+
if (decrypted == null) {
|
|
1296
|
+
Log.e(TAG, "❌ Failed to decrypt payload from $senderId")
|
|
1297
|
+
return
|
|
1298
|
+
}
|
|
1262
1299
|
|
|
1263
|
-
if (decrypted.isEmpty())
|
|
1300
|
+
if (decrypted.isEmpty()) {
|
|
1301
|
+
Log.w(TAG, "Empty decrypted payload from $senderId")
|
|
1302
|
+
return
|
|
1303
|
+
}
|
|
1264
1304
|
|
|
1265
1305
|
val payloadType = NoisePayloadType.fromValue(decrypted[0])
|
|
1266
1306
|
val payloadData = decrypted.copyOfRange(1, decrypted.size)
|
|
1307
|
+
|
|
1308
|
+
Log.d(TAG, "📬 Decrypted message from $senderId, type: $payloadType, data size: ${payloadData.size}")
|
|
1267
1309
|
|
|
1268
1310
|
when (payloadType) {
|
|
1269
1311
|
NoisePayloadType.PRIVATE_MESSAGE -> handlePrivateMessage(payloadData, senderId)
|
|
@@ -1281,9 +1323,12 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
1281
1323
|
putString("fromPeerId", senderId)
|
|
1282
1324
|
})
|
|
1283
1325
|
}
|
|
1284
|
-
NoisePayloadType.SOLANA_TRANSACTION ->
|
|
1326
|
+
NoisePayloadType.SOLANA_TRANSACTION -> {
|
|
1327
|
+
Log.d(TAG, "🔐 Processing encrypted Solana transaction")
|
|
1328
|
+
handleSolanaTransaction(payloadData, senderId)
|
|
1329
|
+
}
|
|
1285
1330
|
NoisePayloadType.TRANSACTION_RESPONSE -> handleTransactionResponse(payloadData, senderId)
|
|
1286
|
-
else ->
|
|
1331
|
+
else -> Log.w(TAG, "Unknown payload type: $payloadType")
|
|
1287
1332
|
}
|
|
1288
1333
|
}
|
|
1289
1334
|
|
|
@@ -1330,6 +1375,7 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
1330
1375
|
}
|
|
1331
1376
|
|
|
1332
1377
|
private fun handleSolanaTransaction(data: ByteArray, senderId: String) {
|
|
1378
|
+
Log.d(TAG, "📨 Received Solana transaction from $senderId, data size: ${data.size}")
|
|
1333
1379
|
// Parse TLV Solana transaction
|
|
1334
1380
|
var txId: String? = null
|
|
1335
1381
|
var serializedTransaction: String? = null
|
|
@@ -1351,16 +1397,31 @@ class BleMeshModule(reactContext: ReactApplicationContext) : ReactContextBaseJav
|
|
|
1351
1397
|
offset += length
|
|
1352
1398
|
|
|
1353
1399
|
when (tag.toInt()) {
|
|
1354
|
-
0x01 ->
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1400
|
+
0x01 -> {
|
|
1401
|
+
txId = String(value, Charsets.UTF_8)
|
|
1402
|
+
Log.d(TAG, " TX ID: $txId")
|
|
1403
|
+
}
|
|
1404
|
+
0x02 -> {
|
|
1405
|
+
serializedTransaction = String(value, Charsets.UTF_8)
|
|
1406
|
+
Log.d(TAG, " Serialized TX size: ${value.size} bytes")
|
|
1407
|
+
}
|
|
1408
|
+
0x03 -> {
|
|
1409
|
+
firstSignerPublicKey = String(value, Charsets.UTF_8)
|
|
1410
|
+
Log.d(TAG, " First signer: $firstSignerPublicKey")
|
|
1411
|
+
}
|
|
1412
|
+
0x04 -> {
|
|
1413
|
+
secondSignerPublicKey = String(value, Charsets.UTF_8)
|
|
1414
|
+
Log.d(TAG, " Second signer: $secondSignerPublicKey")
|
|
1415
|
+
}
|
|
1416
|
+
0x05 -> {
|
|
1417
|
+
description = String(value, Charsets.UTF_8)
|
|
1418
|
+
Log.d(TAG, " Description: $description")
|
|
1419
|
+
}
|
|
1359
1420
|
}
|
|
1360
1421
|
}
|
|
1361
1422
|
|
|
1362
1423
|
if (txId == null || serializedTransaction == null || firstSignerPublicKey == null) {
|
|
1363
|
-
Log.e(TAG, "Invalid Solana transaction data")
|
|
1424
|
+
Log.e(TAG, "❌ Invalid Solana transaction data (txId=$txId, tx=${serializedTransaction != null}, signer=${firstSignerPublicKey != null})")
|
|
1364
1425
|
return
|
|
1365
1426
|
}
|
|
1366
1427
|
|