mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 02:25:21 +00:00
Periodidc broadcast announce (#183)
* noise: send nonce * periodidc broadcast announce
This commit is contained in:
@@ -65,6 +65,7 @@ class BluetoothMeshService(private val context: Context) {
|
||||
|
||||
// Wire up PacketProcessor reference for recursive handling in MessageHandler
|
||||
messageHandler.packetProcessor = packetProcessor
|
||||
sendPeriodicBroadcastAnnounce()
|
||||
//startPeriodicDebugLogging()
|
||||
}
|
||||
|
||||
@@ -86,6 +87,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
|
||||
@@ -604,6 +621,7 @@ class BluetoothMeshService(private val context: Context) {
|
||||
* Send broadcast announce
|
||||
*/
|
||||
fun sendBroadcastAnnounce() {
|
||||
Log.d(TAG, "Sending broadcast announce")
|
||||
serviceScope.launch {
|
||||
val nickname = delegate?.getNickname() ?: myPeerID
|
||||
|
||||
|
||||
@@ -115,21 +115,10 @@ class PacketProcessor(private val myPeerID: String) {
|
||||
/**
|
||||
* Handle Noise handshake message
|
||||
*/
|
||||
private suspend fun handleNoiseHandshake(routed: RoutedPacket, step: Int) {
|
||||
private fun handleNoiseHandshake(routed: RoutedPacket, step: Int) {
|
||||
val peerID = routed.peerID ?: "unknown"
|
||||
Log.d(TAG, "Processing Noise handshake step $step from $peerID")
|
||||
|
||||
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)
|
||||
}
|
||||
delegate?.handleNoiseHandshake(routed, step)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user