mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 04:05:21 +00:00
Gossip mesh topology + source-based routing (#445)
* wip mesh graph * gossip fix * gossip works * source-based routing wip * log * update spec to be explicit about intermediate hops only * drop duplicate hops * add to spec * test * forgot comma * source routing v2 * add compression bomb protection * v2 source routing * fragmented packets inherit route * update spec * Gossip routing tmp with connection limit fixed (#569) * fix: r8 exception for LocationManager (#566) * fragmented packets inherit route * update spec * fix connection limits * fix: deserialization issue with routed packets * log * dynamic fragment size * fragment size * add tests * feat(gossip): implement two-way handshake for source routing edges - Update MeshGraphService to track directed announcements - Require bidirectional announcements for a 'confirmed' edge - Update RoutePlanner to strictly use confirmed edges - Update Mesh Topology debug view to show confirmed vs unconfirmed edges (solid vs dotted) * docs: update SOURCE_ROUTING.md with two-way handshake requirement * evict stale peers from mesh graph service * better logging * fix announce spe * fix: empty route * fix spec * fix: compile error in DebugSettingsSheet and potential NPE in RoutePlanner * revert * try again
This commit is contained in:
@@ -109,11 +109,19 @@ class BluetoothConnectionManager(
|
||||
}
|
||||
// Connection caps: enforce on change
|
||||
connectionScope.launch {
|
||||
dbg.maxConnectionsOverall.collect {
|
||||
dbg.maxConnectionsOverall.collect { maxOverall ->
|
||||
if (!isActive) return@collect
|
||||
// 1. Enforce client limits (handled by tracker)
|
||||
connectionTracker.enforceConnectionLimits()
|
||||
// Also enforce server side best-effort
|
||||
serverManager.enforceServerLimit(dbg.maxServerConnections.value)
|
||||
|
||||
// 2. Enforce overall limit on server connections if needed
|
||||
// (Tracker knows about all connections but can't disconnect servers directly)
|
||||
val maxServer = dbg.maxServerConnections.value
|
||||
val excessServers = connectionTracker.getExcessServerConnections(maxServer, maxOverall)
|
||||
excessServers.forEach { device ->
|
||||
Log.d(TAG, "Disconnecting server ${device.address} due to overall cap")
|
||||
serverManager.disconnectDevice(device)
|
||||
}
|
||||
}
|
||||
}
|
||||
connectionScope.launch {
|
||||
@@ -123,9 +131,18 @@ class BluetoothConnectionManager(
|
||||
}
|
||||
}
|
||||
connectionScope.launch {
|
||||
dbg.maxServerConnections.collect {
|
||||
dbg.maxServerConnections.collect { maxServer ->
|
||||
if (!isActive) return@collect
|
||||
serverManager.enforceServerLimit(dbg.maxServerConnections.value)
|
||||
// Enforce server specific limit
|
||||
serverManager.enforceServerLimit(maxServer)
|
||||
|
||||
// Also check if this change puts us over the overall limit
|
||||
val maxOverall = dbg.maxConnectionsOverall.value
|
||||
val excessServers = connectionTracker.getExcessServerConnections(maxServer, maxOverall)
|
||||
excessServers.forEach { device ->
|
||||
Log.d(TAG, "Disconnecting server ${device.address} due to overall cap")
|
||||
serverManager.disconnectDevice(device)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (_: Exception) { }
|
||||
@@ -261,6 +278,16 @@ class BluetoothConnectionManager(
|
||||
)
|
||||
}
|
||||
|
||||
fun sendToPeer(peerID: String, routed: RoutedPacket): Boolean {
|
||||
if (!isActive) return false
|
||||
return packetBroadcaster.sendToPeer(
|
||||
peerID,
|
||||
routed,
|
||||
serverManager.getGattServer(),
|
||||
serverManager.getCharacteristic()
|
||||
)
|
||||
}
|
||||
|
||||
fun cancelTransfer(transferId: String): Boolean {
|
||||
return packetBroadcaster.cancelTransfer(transferId)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user