-
Notifications
You must be signed in to change notification settings - Fork 567
Wi-Fi Direct and Local Network Support for Mesh Communications #511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- Add WiFiDirectConnectionManager for device-to-device communication - Add LocalNetworkConnectionManager for TCP/IP communication over local Wi-Fi - Add corresponding packet broadcasters and permission managers - Add Wi-Fi Direct onboarding screens - Add Local Network diagnostics and manual IP connection feature
- Integrate WiFiDirectConnectionManager and LocalNetworkConnectionManager into BluetoothMeshService - Add Wi-Fi permissions and features to AndroidManifest.xml - Update PermissionManager to handle Wi-Fi permissions - Add Local Network toggle to debug settings - Update onboarding flow to include Wi-Fi Direct checks - Update strings for Wi-Fi Direct and Local Network features
- Add comprehensive class documentation with features and architecture - Document ports used (UDP 8990 for discovery, TCP 8989 for data) - Explain self-connection prevention and manual IP connection features
- Rename BROADCAST_PORT to DISCOVERY_PORT for clarity (UDP 8988) - Rename BROADCAST_MESSAGE to DISCOVERY_MESSAGE - Update all references to use correct port names - Update documentation to reflect correct port numbers
- Fix LocalNetworkPacketBroadcaster constructor call (remove extra argument) - Replace BROADCAST_MESSAGE references with DISCOVERY_MESSAGE
Removed the unused `FragmentManager` dependency from `WiFiDirectPacketBroadcaster`, `LocalNetworkPacketBroadcaster`, and `WiFiDirectConnectionManager`. This simplifies the constructors for these classes and removes an unnecessary dependency that was not being used.
|
It is necessary to test on many devices locally. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| // Packet operations | ||
| override fun sendPacket(packet: BitchatPacket) { | ||
| // Sign the packet before broadcasting | ||
| val signedPacket = signPacketBeforeBroadcast(packet) | ||
| connectionManager.broadcastPacket(RoutedPacket(signedPacket)) | ||
| wifiDirectManager.broadcastPacket(RoutedPacket(signedPacket)) | ||
| localNetworkManager.broadcastPacket(RoutedPacket(signedPacket)) | ||
| wifiDirectManager.broadcastPacket(RoutedPacket(signedPacket)) | ||
| localNetworkManager.broadcastPacket(RoutedPacket(signedPacket)) | ||
| wifiDirectManager.broadcastPacket(RoutedPacket(signedPacket)) | ||
| localNetworkManager.broadcastPacket(RoutedPacket(signedPacket)) | ||
| } | ||
|
|
||
| override fun relayPacket(routed: RoutedPacket) { | ||
| connectionManager.broadcastPacket(routed) | ||
| wifiDirectManager.broadcastPacket(routed) | ||
| localNetworkManager.broadcastPacket(routed) | ||
| wifiDirectManager.broadcastPacket(routed) | ||
| localNetworkManager.broadcastPacket(routed) | ||
| wifiDirectManager.broadcastPacket(routed) | ||
| localNetworkManager.broadcastPacket(routed) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove duplicated Wi‑Fi broadcast calls
sendPacket and relayPacket invoke wifiDirectManager.broadcastPacket and localNetworkManager.broadcastPacket three times each with the same arguments. Every call therefore transmits the same packet multiple times over Wi‑Fi Direct and the local network, wasting bandwidth/battery and generating duplicate deliveries. These calls should run once per manager (similar duplication occurs in other methods in this file).
Useful? React with 👍 / 👎.
| scope.launch(Dispatchers.IO) { | ||
| try { | ||
| val input = DataInputStream(BufferedInputStream(socket.getInputStream())) | ||
|
|
||
| while (isActive && !socket.isClosed) { | ||
| try { | ||
| // Read packet length | ||
| val packetLength = input.readInt() | ||
| if (packetLength <= 0 || packetLength > 1024 * 1024) { // 1MB max | ||
| Log.w(TAG, "Invalid packet length: $packetLength") | ||
| break | ||
| } | ||
|
|
||
| // Read packet data | ||
| val packetData = ByteArray(packetLength) | ||
| input.readFully(packetData) | ||
|
|
||
| // Parse packet | ||
| val packet = BitchatPacket.fromBinaryData(packetData) | ||
| if (packet != null) { | ||
| Log.d(TAG, "Received packet from $deviceAddress: type=${packet.type}") | ||
|
|
||
| // Find peer ID for this device address | ||
| // This would need to be passed from the connection manager | ||
| // For now, we'll use a placeholder | ||
| val peerID = "wifi_peer_$deviceAddress" | ||
|
|
||
| // TODO: Call delegate to handle received packet | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forward Wi‑Fi Direct packets to mesh layer
WiFiDirectPacketBroadcaster.handleClientConnection reads packets from a socket but stops after logging and leaves a // TODO without notifying any delegate. There is no other path that forwards those packets, so inbound Wi‑Fi Direct data is silently dropped and peers cannot deliver messages. The broadcaster needs a callback into WiFiDirectConnectionManager (e.g., delegate.onPacketReceived) when a packet is parsed so the mesh service can process it.
Useful? React with 👍 / 👎.
- Add WiFiDirectPacketDelegate interface to forward received packets - Implement packet delegate in WiFiDirectConnectionManager - Remove TODO and properly forward packets to mesh service - Fix issue where inbound Wi-Fi Direct data was silently dropped
- Remove duplicate broadcastPacket calls in sendPacket, relayPacket, sendPrivateMessage, sendReadReceipt, and other methods - Each connection manager (Wi-Fi Direct, Local Network) is now called only once per packet instead of 3 times - Fixes bandwidth waste and prevents duplicate message deliveries - Improves battery efficiency by reducing unnecessary network transmissions
|
this is absolutely wicked. any prebuilds i can test with? |
|
hi @yet300 – impressive PR. I have a branch with working wifi aware support. to my knowledge, wifi direct needs user interaction ton make a connection, is that true? couldn't test this branch yet. |
|
Yes |
Overview
This PR adds comprehensive Wi-Fi Direct and Local Network support to the BitChat mesh communication system, providing robust peer-to-peer connectivity options that work with iPhone hotspots and Android emulators.
Features Added
🔗 Wi-Fi Direct Support
🌐 Local Network Support
🔧 Integration & UI
Technical Implementation
Architecture
Key Components
Network Discovery
"BITCHAT_DISCOVERY:<peerID>"messages on port 8988Code Quality Improvements
Refactoring
Example Refactored Code
Compatibility
Device Support
Network Environments
Testing
Manual Testing Scenarios
Debug Features
Breaking Changes
Future Enhancements
Commits Summary
ac9ab81feat: Add Wi-Fi Direct and Local Network support8f358b4feat: Integrate Wi-Fi Direct and Local Network into mesh servicea5f225edocs: Improve LocalNetworkConnectionManager documentation18fa9a7fix: Correct Local Network ports and constants2291bfbfix: Correct LocalNetworkConnectionManager constructor and constantsThis implementation provides BitChat with enterprise-grade mesh networking capabilities, ensuring reliable communication across diverse device and network environments. 🚀📱✨