mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 03:25:19 +00:00
- Added duplicate connection detection in key exchange handler - When same peer connects through multiple peripherals, keep only one - Track intentional disconnects to suppress disconnect messages - Don't show disconnect message when dropping duplicate connections - This prevents the confusing connect/disconnect/connect pattern The issue was that both devices try to connect to each other simultaneously, creating duplicate connections. One gets dropped, but now it's handled gracefully.
1.7 KiB
1.7 KiB
Connection Stability Fixes for BluetoothMeshService
Issues Causing Disconnect/Reconnect
- Simultaneous Connection Attempts: Both devices acting as central and peripheral can create duplicate connections
- Temporary ID Management: Using peripheral UUIDs as temporary IDs causes confusion
- Premature State Updates: Peer list updates happen before connections are fully established
- Aggressive Disconnect Handling: Peers are removed immediately on disconnect without grace period
Recommended Fixes
1. Implement Connection Deduplication
- Track ongoing connection attempts by peer ID
- Reject duplicate connections from same peer
- Use deterministic logic to decide which side maintains connection (e.g., compare peer IDs)
2. Improve Peer State Management
- Add connection states: CONNECTING, CONNECTED, DISCONNECTING
- Only show "joined" after key exchange AND announce received
- Add grace period before showing "left" messages (e.g., 5 seconds)
3. Fix Temporary ID Handling
- Don't add temp IDs to activePeers
- Only update peer lists after receiving real peer ID
- Use a separate pendingPeripherals dictionary
4. Consolidate Key Exchange and Announce
- Send key exchange and announce as atomic operation
- Wait for both before considering peer "connected"
- Add sequence numbers to prevent duplicate processing
5. Add Connection Stability Timer
- Don't show "joined" until connection stable for 1 second
- Buffer rapid connect/disconnect cycles
- Implement exponential backoff for reconnection attempts
Implementation Priority
- Fix duplicate connection handling (highest impact)
- Add connection grace period
- Improve state management
- Consolidate initialization messages