mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 07:05:21 +00:00
better logging of device id
This commit is contained in:
@@ -121,7 +121,7 @@ class BluetoothGattServerManager(
|
|||||||
|
|
||||||
when (newState) {
|
when (newState) {
|
||||||
BluetoothProfile.STATE_CONNECTED -> {
|
BluetoothProfile.STATE_CONNECTED -> {
|
||||||
Log.d(TAG, "Server: Device connected ${device.address}")
|
Log.i(TAG, "Server: Device connected ${device.address}")
|
||||||
val deviceConn = BluetoothConnectionTracker.DeviceConnection(
|
val deviceConn = BluetoothConnectionTracker.DeviceConnection(
|
||||||
device = device,
|
device = device,
|
||||||
isClient = false
|
isClient = false
|
||||||
@@ -129,7 +129,7 @@ class BluetoothGattServerManager(
|
|||||||
connectionTracker.addDeviceConnection(device.address, deviceConn)
|
connectionTracker.addDeviceConnection(device.address, deviceConn)
|
||||||
}
|
}
|
||||||
BluetoothProfile.STATE_DISCONNECTED -> {
|
BluetoothProfile.STATE_DISCONNECTED -> {
|
||||||
Log.d(TAG, "Server: Device disconnected ${device.address}")
|
Log.i(TAG, "Server: Device disconnected ${device.address}")
|
||||||
connectionTracker.cleanupDeviceConnection(device.address)
|
connectionTracker.cleanupDeviceConnection(device.address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,7 +165,7 @@ class BluetoothGattServerManager(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (characteristic.uuid == CHARACTERISTIC_UUID) {
|
if (characteristic.uuid == CHARACTERISTIC_UUID) {
|
||||||
Log.d(TAG, "Server: Received packet from ${device.address}, size: ${value.size} bytes")
|
Log.i(TAG, "Server: Received packet from ${device.address}, size: ${value.size} bytes")
|
||||||
val packet = BitchatPacket.fromBinaryData(value)
|
val packet = BitchatPacket.fromBinaryData(value)
|
||||||
if (packet != null) {
|
if (packet != null) {
|
||||||
val peerID = String(packet.senderID).replace("\u0000", "")
|
val peerID = String(packet.senderID).replace("\u0000", "")
|
||||||
|
|||||||
@@ -521,6 +521,27 @@ class BluetoothMeshService(private val context: Context) {
|
|||||||
*/
|
*/
|
||||||
fun getPeerRSSI(): Map<String, Int> = peerManager.getAllPeerRSSI()
|
fun getPeerRSSI(): Map<String, Int> = peerManager.getAllPeerRSSI()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get device address for a specific peer ID
|
||||||
|
*/
|
||||||
|
fun getDeviceAddressForPeer(peerID: String): String? {
|
||||||
|
return connectionManager.addressPeerMap.entries.find { it.value == peerID }?.key
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get all device addresses mapped to their peer IDs
|
||||||
|
*/
|
||||||
|
fun getDeviceAddressToPeerMapping(): Map<String, String> {
|
||||||
|
return connectionManager.addressPeerMap.toMap()
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print device addresses for all connected peers
|
||||||
|
*/
|
||||||
|
fun printDeviceAddressesForPeers(): String {
|
||||||
|
return peerManager.getDebugInfoWithDeviceAddresses(connectionManager.addressPeerMap)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get debug status information
|
* Get debug status information
|
||||||
*/
|
*/
|
||||||
@@ -531,7 +552,7 @@ class BluetoothMeshService(private val context: Context) {
|
|||||||
appendLine()
|
appendLine()
|
||||||
appendLine(connectionManager.getDebugInfo())
|
appendLine(connectionManager.getDebugInfo())
|
||||||
appendLine()
|
appendLine()
|
||||||
appendLine(peerManager.getDebugInfo())
|
appendLine(peerManager.getDebugInfo(connectionManager.addressPeerMap))
|
||||||
appendLine()
|
appendLine()
|
||||||
appendLine(fragmentManager.getDebugInfo())
|
appendLine(fragmentManager.getDebugInfo())
|
||||||
appendLine()
|
appendLine()
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ class PeerManager {
|
|||||||
/**
|
/**
|
||||||
* Get debug information
|
* Get debug information
|
||||||
*/
|
*/
|
||||||
fun getDebugInfo(): String {
|
fun getDebugInfo(addressPeerMap: Map<String, String>? = null): String {
|
||||||
return buildString {
|
return buildString {
|
||||||
appendLine("=== Peer Manager Debug Info ===")
|
appendLine("=== Peer Manager Debug Info ===")
|
||||||
appendLine("Active Peers: ${activePeers.size}")
|
appendLine("Active Peers: ${activePeers.size}")
|
||||||
@@ -191,13 +191,39 @@ class PeerManager {
|
|||||||
val nickname = peerNicknames[peerID] ?: "Unknown"
|
val nickname = peerNicknames[peerID] ?: "Unknown"
|
||||||
val timeSince = (System.currentTimeMillis() - lastSeen) / 1000
|
val timeSince = (System.currentTimeMillis() - lastSeen) / 1000
|
||||||
val rssi = peerRSSI[peerID]?.let { "${it} dBm" } ?: "No RSSI"
|
val rssi = peerRSSI[peerID]?.let { "${it} dBm" } ?: "No RSSI"
|
||||||
appendLine(" - $peerID ($nickname) - last seen ${timeSince}s ago, RSSI: $rssi")
|
|
||||||
|
// Find device address for this peer ID
|
||||||
|
val deviceAddress = addressPeerMap?.entries?.find { it.value == peerID }?.key
|
||||||
|
val addressInfo = deviceAddress?.let { " [Device: $it]" } ?: " [Device: Unknown]"
|
||||||
|
|
||||||
|
appendLine(" - $peerID ($nickname)$addressInfo - last seen ${timeSince}s ago, RSSI: $rssi")
|
||||||
}
|
}
|
||||||
appendLine("Announced Peers: ${announcedPeers.size}")
|
appendLine("Announced Peers: ${announcedPeers.size}")
|
||||||
appendLine("Announced To Peers: ${announcedToPeers.size}")
|
appendLine("Announced To Peers: ${announcedToPeers.size}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get debug information with device addresses
|
||||||
|
*/
|
||||||
|
fun getDebugInfoWithDeviceAddresses(addressPeerMap: Map<String, String>): String {
|
||||||
|
return buildString {
|
||||||
|
appendLine("=== Device Address to Peer Mapping ===")
|
||||||
|
if (addressPeerMap.isEmpty()) {
|
||||||
|
appendLine("No device address mappings available")
|
||||||
|
} else {
|
||||||
|
addressPeerMap.forEach { (deviceAddress, peerID) ->
|
||||||
|
val nickname = peerNicknames[peerID] ?: "Unknown"
|
||||||
|
val isActive = activePeers.containsKey(peerID)
|
||||||
|
val status = if (isActive) "ACTIVE" else "INACTIVE"
|
||||||
|
appendLine(" Device: $deviceAddress -> Peer: $peerID ($nickname) [$status]")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
appendLine()
|
||||||
|
appendLine(getDebugInfo(addressPeerMap))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Notify delegate of peer list updates
|
* Notify delegate of peer list updates
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user