mirror of
https://github.com/permissionlesstech/bitchat-android.git
synced 2026-07-25 01:45:22 +00:00
Fix Wi-Fi Aware connectivity and UI integration post-merge
- Replace bindProcessToNetwork with bindSocket for VPN compatibility. - Implement Scoped IPv6 address resolution (aware0) for mesh routing. - Bridge Wi-Fi Aware incoming messages to AppStateStore for UI visibility. - Fix syntax errors and variable name conflicts in Debug UI.
This commit is contained in:
@@ -170,6 +170,13 @@ class MainActivity : OrientationAwareActivity() {
|
||||
if (running && svc != null) {
|
||||
svc.delegate = object : com.bitchat.android.wifiaware.WifiAwareMeshDelegate {
|
||||
override fun didReceiveMessage(message: com.bitchat.android.model.BitchatMessage) {
|
||||
if (message.isPrivate) {
|
||||
message.senderPeerID?.let { pid -> com.bitchat.android.services.AppStateStore.addPrivateMessage(pid, message) }
|
||||
} else if (message.channel != null) {
|
||||
com.bitchat.android.services.AppStateStore.addChannelMessage(message.channel, message)
|
||||
} else {
|
||||
com.bitchat.android.services.AppStateStore.addPublicMessage(message)
|
||||
}
|
||||
chatViewModel.didReceiveMessage(message)
|
||||
}
|
||||
override fun didUpdatePeerList(peers: List<String>) {
|
||||
|
||||
@@ -36,9 +36,6 @@ class DebugSettingsManager private constructor() {
|
||||
private val _packetRelayEnabled = MutableStateFlow(true)
|
||||
val packetRelayEnabled: StateFlow<Boolean> = _packetRelayEnabled.asStateFlow()
|
||||
|
||||
private val _packetRelayEnabled = MutableStateFlow(true)
|
||||
val packetRelayEnabled: StateFlow<Boolean> = _packetRelayEnabled.asStateFlow()
|
||||
|
||||
// Master transport toggles
|
||||
private val _bleEnabled = MutableStateFlow(true)
|
||||
val bleEnabled: StateFlow<Boolean> = _bleEnabled.asStateFlow()
|
||||
|
||||
@@ -52,7 +52,7 @@ fun DebugSettingsSheet(
|
||||
val verboseLogging by manager.verboseLoggingEnabled.collectAsState()
|
||||
val gattServerEnabled by manager.gattServerEnabled.collectAsState()
|
||||
val gattClientEnabled by manager.gattClientEnabled.collectAsState()
|
||||
val packetRelayEnabled by manager.packetRelayEnabled.collectAsState()
|
||||
val packetRelayed by manager.packetRelayEnabled.collectAsState()
|
||||
val maxOverall by manager.maxConnectionsOverall.collectAsState()
|
||||
val maxServer by manager.maxServerConnections.collectAsState()
|
||||
val maxClient by manager.maxClientConnections.collectAsState()
|
||||
@@ -280,7 +280,7 @@ fun DebugSettingsSheet(
|
||||
Icon(Icons.Filled.PowerSettingsNew, contentDescription = null, tint = Color(0xFFFF9500))
|
||||
Text(stringResource(R.string.debug_packet_relay), fontFamily = FontFamily.Monospace, fontSize = 14.sp, fontWeight = FontWeight.Medium)
|
||||
Spacer(Modifier.weight(1f))
|
||||
Switch(checked = packetRelayEnabled, onCheckedChange = { manager.setPacketRelayEnabled(it) })
|
||||
Switch(checked = packetRelayed, onCheckedChange = { manager.setPacketRelayEnabled(it) })
|
||||
}
|
||||
// Removed aggregate labels; we will show per-direction compact labels below titles
|
||||
// Toggle: overall vs per-connection vs per-peer
|
||||
|
||||
@@ -619,7 +619,7 @@ class WifiAwareMeshService(private val context: Context) {
|
||||
}
|
||||
override fun onLost(network: Network) {
|
||||
networkCallbacks.remove(peerId)
|
||||
Log.d(TAG, "SERVER: network lost for \${peerId.take(8)}…")
|
||||
Log.d(TAG, "SERVER: network lost for ${peerId.take(8)}…")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -656,11 +656,13 @@ class WifiAwareMeshService(private val context: Context) {
|
||||
) {
|
||||
// TCP keep-alive pings
|
||||
serviceScope.launch {
|
||||
val os = client.getOutputStream()
|
||||
while (peerSockets.containsKey(peerId)) {
|
||||
try { os.write(0) } catch (_: IOException) { break }
|
||||
delay(2_000)
|
||||
}
|
||||
try {
|
||||
val os = client.getOutputStream()
|
||||
while (peerSockets.containsKey(peerId)) {
|
||||
try { os.write(0) } catch (_: IOException) { break }
|
||||
delay(2_000)
|
||||
}
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
// Discovery keep-alive
|
||||
serviceScope.launch {
|
||||
@@ -711,14 +713,7 @@ class WifiAwareMeshService(private val context: Context) {
|
||||
override fun onCapabilitiesChanged(network: Network, nc: NetworkCapabilities) {
|
||||
if (peerSockets.containsKey(peerId)) return
|
||||
val info = (nc.transportInfo as? WifiAwareNetworkInfo) ?: return
|
||||
val addr = info.peerIpv6Addr as Inet6Address
|
||||
|
||||
val lp = cm.getLinkProperties(network)
|
||||
val iface = lp?.interfaceName
|
||||
|
||||
try {
|
||||
val sock = Socket()
|
||||
network.bindSocket(sock)
|
||||
val addr = info.peerIpv6Addr as? Inet6Address ?: return
|
||||
|
||||
val lp = cm.getLinkProperties(network)
|
||||
val iface = lp?.interfaceName
|
||||
@@ -731,13 +726,17 @@ class WifiAwareMeshService(private val context: Context) {
|
||||
|
||||
// Use scoped IPv6 if interface name is available
|
||||
val scopedAddr = if (iface != null && addr.scopeId == 0) {
|
||||
Inet6Address.getByAddress(null, addr.address, java.net.NetworkInterface.getByName(iface))
|
||||
try {
|
||||
Inet6Address.getByAddress(null, addr.address, java.net.NetworkInterface.getByName(iface))
|
||||
} catch (e: Exception) {
|
||||
addr
|
||||
}
|
||||
} else {
|
||||
addr
|
||||
}
|
||||
|
||||
sock.connect(java.net.InetSocketAddress(scopedAddr, port), 7000)
|
||||
Log.d(TAG, "CLIENT: TCP connected to \${peerId.take(8)}… addr=\$scopedAddr:\$port (iface=\$iface)")
|
||||
Log.d(TAG, "CLIENT: TCP connected to ${peerId.take(8)}… addr=$scopedAddr:$port (iface=$iface)")
|
||||
|
||||
peerSockets[peerId] = sock
|
||||
try { peerManager.setDirectConnection(peerId, true) } catch (_: Exception) {}
|
||||
@@ -776,11 +775,13 @@ class WifiAwareMeshService(private val context: Context) {
|
||||
) {
|
||||
// TCP keep-alive
|
||||
serviceScope.launch {
|
||||
val os = sock.getOutputStream()
|
||||
while (peerSockets.containsKey(peerId)) {
|
||||
try { os.write(0) } catch (_: IOException) { break }
|
||||
delay(2_000)
|
||||
}
|
||||
try {
|
||||
val os = sock.getOutputStream()
|
||||
while (peerSockets.containsKey(peerId)) {
|
||||
try { os.write(0) } catch (_: IOException) { break }
|
||||
delay(2_000)
|
||||
}
|
||||
} catch (_: Exception) {}
|
||||
}
|
||||
// Discovery keep-alive
|
||||
serviceScope.launch {
|
||||
@@ -1047,9 +1048,7 @@ class WifiAwareMeshService(private val context: Context) {
|
||||
senderID = myPeerID,
|
||||
payload = tlvPayload
|
||||
)
|
||||
val signed = encryptionService.signData(announcePacket.toBinaryDataForSigning()!!)?.let {
|
||||
announcePacket.copy(signature = it)
|
||||
} ?: announcePacket
|
||||
val signed = signPacketBeforeBroadcast(announcePacket)
|
||||
|
||||
broadcastPacket(RoutedPacket(signed))
|
||||
try { gossipSyncManager.onPublicPacketSeen(signed) } catch (_: Exception) { }
|
||||
@@ -1074,9 +1073,7 @@ class WifiAwareMeshService(private val context: Context) {
|
||||
senderID = myPeerID,
|
||||
payload = tlvPayload
|
||||
)
|
||||
val signed = encryptionService.signData(packet.toBinaryDataForSigning()!!)?.let {
|
||||
packet.copy(signature = it)
|
||||
} ?: packet
|
||||
val signed = signPacketBeforeBroadcast(packet)
|
||||
|
||||
broadcastPacket(RoutedPacket(signed))
|
||||
peerManager.markPeerAsAnnouncedTo(peerID)
|
||||
|
||||
Reference in New Issue
Block a user