mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 18:45:20 +00:00
more logging
This commit is contained in:
@@ -88,6 +88,7 @@ class BluetoothConnectionTracker(
|
|||||||
* Add a device connection
|
* Add a device connection
|
||||||
*/
|
*/
|
||||||
fun addDeviceConnection(deviceAddress: String, deviceConn: DeviceConnection) {
|
fun addDeviceConnection(deviceAddress: String, deviceConn: DeviceConnection) {
|
||||||
|
Log.d(TAG, "Tracker: Adding device connection for $deviceAddress")
|
||||||
connectedDevices[deviceAddress] = deviceConn
|
connectedDevices[deviceAddress] = deviceConn
|
||||||
pendingConnections.remove(deviceAddress)
|
pendingConnections.remove(deviceAddress)
|
||||||
}
|
}
|
||||||
@@ -180,16 +181,19 @@ class BluetoothConnectionTracker(
|
|||||||
* Add a pending connection attempt
|
* Add a pending connection attempt
|
||||||
*/
|
*/
|
||||||
fun addPendingConnection(deviceAddress: String): Boolean {
|
fun addPendingConnection(deviceAddress: String): Boolean {
|
||||||
|
Log.d(TAG, "Tracker: Adding pending connection for $deviceAddress")
|
||||||
synchronized(pendingConnections) {
|
synchronized(pendingConnections) {
|
||||||
// Double-check inside synchronized block
|
// Double-check inside synchronized block
|
||||||
val currentAttempt = pendingConnections[deviceAddress]
|
val currentAttempt = pendingConnections[deviceAddress]
|
||||||
if (currentAttempt != null && !currentAttempt.isExpired() && !currentAttempt.shouldRetry()) {
|
if (currentAttempt != null && !currentAttempt.isExpired() && !currentAttempt.shouldRetry()) {
|
||||||
|
Log.d(TAG, "Tracker: Connection attempt already in progress for $deviceAddress")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update connection attempt atomically
|
// Update connection attempt atomically
|
||||||
val attempts = (currentAttempt?.attempts ?: 0) + 1
|
val attempts = (currentAttempt?.attempts ?: 0) + 1
|
||||||
pendingConnections[deviceAddress] = ConnectionAttempt(attempts)
|
pendingConnections[deviceAddress] = ConnectionAttempt(attempts)
|
||||||
|
Log.d(TAG, "Tracker: Added pending connection for $deviceAddress (attempts: $attempts)")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -318,7 +322,7 @@ class BluetoothConnectionTracker(
|
|||||||
appendLine("Connected Devices: ${connectedDevices.size} / ${powerManager.getMaxConnections()}")
|
appendLine("Connected Devices: ${connectedDevices.size} / ${powerManager.getMaxConnections()}")
|
||||||
connectedDevices.forEach { (address, deviceConn) ->
|
connectedDevices.forEach { (address, deviceConn) ->
|
||||||
val age = (System.currentTimeMillis() - deviceConn.connectedAt) / 1000
|
val age = (System.currentTimeMillis() - deviceConn.connectedAt) / 1000
|
||||||
appendLine(" - $address (${if (deviceConn.isClient) "client" else "server"}, ${age}s, RSSI: ${deviceConn.rssi})")
|
appendLine(" - $address (we're ${if (deviceConn.isClient) "client" else "server"}, ${age}s, RSSI: ${deviceConn.rssi})")
|
||||||
}
|
}
|
||||||
appendLine()
|
appendLine()
|
||||||
appendLine("Subscribed Devices (server mode): ${subscribedDevices.size}")
|
appendLine("Subscribed Devices (server mode): ${subscribedDevices.size}")
|
||||||
|
|||||||
@@ -192,6 +192,7 @@ class BluetoothGattClientManager(
|
|||||||
|
|
||||||
scanCallback = object : ScanCallback() {
|
scanCallback = object : ScanCallback() {
|
||||||
override fun onScanResult(callbackType: Int, result: ScanResult) {
|
override fun onScanResult(callbackType: Int, result: ScanResult) {
|
||||||
|
Log.d(TAG, "Scan result received: ${result.device.address}")
|
||||||
handleScanResult(result)
|
handleScanResult(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,6 +277,8 @@ class BluetoothGattClientManager(
|
|||||||
if (!hasOurService) {
|
if (!hasOurService) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.d(TAG, "Received scan result from $deviceAddress - already connected: ${connectionTracker.isDeviceConnected(deviceAddress)}")
|
||||||
|
|
||||||
// Store RSSI from scan results for later use (especially for server connections)
|
// Store RSSI from scan results for later use (especially for server connections)
|
||||||
connectionTracker.updateScanRSSI(deviceAddress, rssi)
|
connectionTracker.updateScanRSSI(deviceAddress, rssi)
|
||||||
@@ -314,7 +317,7 @@ class BluetoothGattClientManager(
|
|||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
private fun connectToDevice(device: BluetoothDevice, rssi: Int) {
|
private fun connectToDevice(device: BluetoothDevice, rssi: Int) {
|
||||||
if (!permissionManager.hasBluetoothPermissions()) return
|
if (!permissionManager.hasBluetoothPermissions()) return
|
||||||
|
|
||||||
val deviceAddress = device.address
|
val deviceAddress = device.address
|
||||||
Log.i(TAG, "Connecting to bitchat device: $deviceAddress")
|
Log.i(TAG, "Connecting to bitchat device: $deviceAddress")
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,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
|
||||||
startPeriodicDebugLogging()
|
// startPeriodicDebugLogging()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -120,7 +120,7 @@ class BluetoothMeshService(private val context: Context) {
|
|||||||
delay(100)
|
delay(100)
|
||||||
sendAnnouncementToPeer(peerID)
|
sendAnnouncementToPeer(peerID)
|
||||||
|
|
||||||
delay(500)
|
delay(1000)
|
||||||
storeForwardManager.sendCachedMessages(peerID)
|
storeForwardManager.sendCachedMessages(peerID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user