mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 02:45:20 +00:00
direct peer detection by annouce TTL
This commit is contained in:
@@ -464,21 +464,24 @@ class BluetoothMeshService(private val context: Context) {
|
||||
// Process the announce
|
||||
val isFirst = messageHandler.handleAnnounce(routed)
|
||||
|
||||
// Map device address -> peerID on first announce seen over this device connection
|
||||
// Map device address -> peerID based on TTL (max TTL = direct neighbor)
|
||||
// Matches iOS logic: any announce with max TTL on a link defines the direct peer
|
||||
val deviceAddress = routed.relayAddress
|
||||
val pid = routed.peerID
|
||||
if (deviceAddress != null && pid != null) {
|
||||
// First ANNOUNCE over a device connection defines a direct neighbor.
|
||||
if (!connectionManager.hasSeenFirstAnnounce(deviceAddress)) {
|
||||
// Check if this is a direct connection (MAX TTL)
|
||||
// Note: packet.ttl is UByte, compare with AppConstants.MESSAGE_TTL_HOPS
|
||||
val isDirect = routed.packet.ttl == com.bitchat.android.util.AppConstants.MESSAGE_TTL_HOPS
|
||||
|
||||
if (isDirect) {
|
||||
// Bind or rebind this device address to the announcing peer
|
||||
connectionManager.addressPeerMap[deviceAddress] = pid
|
||||
connectionManager.noteAnnounceReceived(deviceAddress)
|
||||
Log.d(TAG, "Mapped device $deviceAddress to peer $pid on FIRST-ANNOUNCE for this connection")
|
||||
Log.d(TAG, "Mapped device $deviceAddress to peer $pid (TTL=${routed.packet.ttl})")
|
||||
|
||||
// Mark as directly connected (upgrades from routed if needed)
|
||||
// Mark as directly connected
|
||||
try { peerManager.setDirectConnection(pid, true) } catch (_: Exception) { }
|
||||
|
||||
// Initial sync for this newly direct peer
|
||||
// Initial sync for this direct peer
|
||||
try { gossipSyncManager.scheduleInitialSyncToPeer(pid, 1_000) } catch (_: Exception) { }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user