Skip to content

Conversation

@callebtc
Copy link
Collaborator

Description

Address rotation handled. I added peer-aware gating and robust disconnects so only one direct connection per peer remains active.

What I changed

  • Peer-connected checks in the tracker
    • New APIs:
      • isPeerDirectlyConnected(peerID: String): Boolean
      • getConnectedAddressForPeer(peerID: String): String?
    • These use addressPeerMap and connectedDevices to resolve if a peer already has an active link.
  • Drop duplicate on first ANNOUNCE
    • In BluetoothMeshService.handleAnnounce:
      • On the FIRST ANNOUNCE for a device connection, before binding deviceAddress -> peerID, it checks if that peerID is already connected via another existingAddress.
      • If found and different, it drops the new, redundant connection via connectionManager.disconnectAddress(deviceAddress).
      • Otherwise it binds the mapping and marks that peer as directly connected (and schedules initial sync). This keeps exactly one connection per peer (client or server).
  • Disconnect now handles server connections too
    • BluetoothConnectionManager.disconnectAddress(...):
      • If it’s a client connection, calls gatt.disconnect().
      • If it’s a server connection (no GATT), calls gattServer.cancelConnection(device).
      • Always cleans up tracking afterward.

Why this is robust

  • Works with rotating MACs: we can’t know the peer at scan/connection time, but as soon as the peer ANNOUNCE arrives over the new connection, we enforce the one-direct-connection-
    per-peer rule and drop the newcomer.
  • Applies across client/server roles. The check uses existing mappings and connected state, and the disconnect path works for either role.
  • Keeps backoff correct: We previously fixed the attempt-tracking bug so disconnecting the duplicate doesn’t reset the retry window.

Files changed

  • app/src/main/java/com/bitchat/android/mesh/BluetoothConnectionTracker.kt
    • Added isPeerDirectlyConnected and getConnectedAddressForPeer.
  • app/src/main/java/com/bitchat/android/mesh/BluetoothMeshService.kt
    • Enforced dropping duplicate connection in ANNOUNCE handling.
  • app/src/main/java/com/bitchat/android/mesh/BluetoothConnectionManager.kt
    • Upgraded disconnectAddress to support server connections.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants