mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 13:45:21 +00:00
fix: centralize and strictly enforce connection limits (#618)
This commit is contained in:
@@ -46,22 +46,6 @@ class BluetoothGattServerManager(
|
||||
// State management
|
||||
private var isActive = false
|
||||
|
||||
// Enforce a server connection limit by canceling the oldest connections (best-effort)
|
||||
fun enforceServerLimit(maxServer: Int) {
|
||||
if (maxServer <= 0) return
|
||||
try {
|
||||
// Use connection tracker to get actual connected server devices
|
||||
val servers = connectionTracker.getConnectedDevices().values.filter { !it.isClient }
|
||||
if (servers.size > maxServer) {
|
||||
val excess = servers.size - maxServer
|
||||
// Disconnect oldest
|
||||
servers.sortedBy { it.connectedAt }.take(excess).forEach { d ->
|
||||
try { gattServer?.cancelConnection(d.device) } catch (_: Exception) { }
|
||||
}
|
||||
}
|
||||
} catch (_: Exception) { }
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect a specific device (used by ConnectionManager to enforce overall limits)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user