wifi improvements

This commit is contained in:
CC
2026-06-09 00:53:09 +02:00
parent d2d9ab6c69
commit b4df0d7cf1
7 changed files with 258 additions and 70 deletions
@@ -15,6 +15,8 @@ object AppStateStore {
private val seenMessageIds = mutableSetOf<String>()
private val seenPublicMessageKeys = mutableSetOf<String>()
private val peerIdsByTransport = mutableMapOf<String, Set<String>>()
// Direct (single-hop) peer IDs per transport, used to gossip a unified neighbor set.
private val directPeerIdsByTransport = mutableMapOf<String, Set<String>>()
// Connected peer IDs (mesh ephemeral IDs)
private val _peers = MutableStateFlow<List<String>>(emptyList())
val peers: StateFlow<List<String>> = _peers.asStateFlow()
@@ -59,6 +61,30 @@ object AppStateStore {
.toList()
}
/**
* Record the set of direct (single-hop) peers reachable over a given transport. Each transport
* (BLE, Wi-Fi Aware, ...) only knows its own direct peers; [getDirectPeers] unions them so every
* transport can gossip the same complete neighbor list under our shared node identity.
*/
fun setTransportDirectPeers(transportId: String, ids: Collection<String>) {
synchronized(this) {
directPeerIdsByTransport[transportId] = ids.toSet()
}
}
fun clearTransportDirectPeers(transportId: String) {
synchronized(this) {
directPeerIdsByTransport.remove(transportId)
}
}
/** Union of direct peers across all transports. */
fun getDirectPeers(): Set<String> {
synchronized(this) {
return directPeerIdsByTransport.values.flatten().toSet()
}
}
fun addPublicMessage(msg: BitchatMessage) {
synchronized(this) {
val publicKey = publicMessageKey(msg)
@@ -130,6 +156,7 @@ object AppStateStore {
seenMessageIds.clear()
seenPublicMessageKeys.clear()
peerIdsByTransport.clear()
directPeerIdsByTransport.clear()
_peers.value = emptyList()
_publicMessages.value = emptyList()
_privateMessages.value = emptyMap()