Periodidc broadcast announce (#183)

* noise: send nonce

* periodidc broadcast announce
This commit is contained in:
callebtc
2025-07-25 01:38:53 +02:00
committed by GitHub
parent 1c82e4ede8
commit bc14b9f179
2 changed files with 20 additions and 13 deletions
@@ -65,6 +65,7 @@ class BluetoothMeshService(private val context: Context) {
// Wire up PacketProcessor reference for recursive handling in MessageHandler // Wire up PacketProcessor reference for recursive handling in MessageHandler
messageHandler.packetProcessor = packetProcessor messageHandler.packetProcessor = packetProcessor
sendPeriodicBroadcastAnnounce()
//startPeriodicDebugLogging() //startPeriodicDebugLogging()
} }
@@ -87,6 +88,22 @@ class BluetoothMeshService(private val context: Context) {
} }
} }
/**
* Send broadcast announcement every 10 seconds
*/
private fun sendPeriodicBroadcastAnnounce() {
serviceScope.launch {
while (isActive) {
try {
delay(10000) // 10 seconds
sendBroadcastAnnounce()
} catch (e: Exception) {
Log.e(TAG, "Error in periodic broadcast announce: ${e.message}")
}
}
}
}
/** /**
* Setup delegate connections between components * Setup delegate connections between components
*/ */
@@ -604,6 +621,7 @@ class BluetoothMeshService(private val context: Context) {
* Send broadcast announce * Send broadcast announce
*/ */
fun sendBroadcastAnnounce() { fun sendBroadcastAnnounce() {
Log.d(TAG, "Sending broadcast announce")
serviceScope.launch { serviceScope.launch {
val nickname = delegate?.getNickname() ?: myPeerID val nickname = delegate?.getNickname() ?: myPeerID
@@ -115,21 +115,10 @@ class PacketProcessor(private val myPeerID: String) {
/** /**
* Handle Noise handshake message * Handle Noise handshake message
*/ */
private suspend fun handleNoiseHandshake(routed: RoutedPacket, step: Int) { private fun handleNoiseHandshake(routed: RoutedPacket, step: Int) {
val peerID = routed.peerID ?: "unknown" val peerID = routed.peerID ?: "unknown"
Log.d(TAG, "Processing Noise handshake step $step from $peerID") Log.d(TAG, "Processing Noise handshake step $step from $peerID")
delegate?.handleNoiseHandshake(routed, step)
val success = delegate?.handleNoiseHandshake(routed, step) ?: false
if (success) {
// Handshake successful, may need to send announce and cached messages
// This will be determined by the Noise implementation when session is established
delay(100)
delegate?.sendAnnouncementToPeer(peerID)
delay(500)
delegate?.sendCachedMessages(peerID)
}
} }
/** /**