Serverless. Private. Resilient.
PeerConnect is an offline-first, peer-to-peer (P2P) messaging application for Android. It enables devices to create a local mesh network via Wi-Fi P2P and Bluetooth Low Energy (BLE), allowing for secure chat and file transfer without an internet connection, cellular data, or a centralized server.
It is designed for high-interference environments, subways, airplanes, or remote locations where traditional connectivity fails.
- 100% Offline: Operates entirely on the device's radio hardware (Bluetooth/Wi-Fi).
- Hybrid Discovery Engine:
- Auto-Connect: Uses a background algorithm to automatically detect and reconnect to known "friends" without user intervention.
- Scan & Select: A manual "Pairing Mode" that scans for unknown devices and presents a selection list, preventing accidental connections to strangers.
- Location Enforcer: Automatically handles Android's strict location/GPS requirements for P2P discovery (Android 10 through 14+).
- End-to-End Encryption: Messages are AES-encrypted locally before transmission, ensuring privacy even over open airwaves.
- File Sharing: Supports binary stream transfer for images and documents. Files are automatically saved to the system
Downloadsfolder using theMediaStoreAPI. - Resilient Queuing: If a device disconnects mid-chat, messages are queued locally in a Room Database and auto-flushed upon reconnection.
- Language: Kotlin
- Connectivity: Google Nearby Connections API (Strategy:
P2P_STAR) - Database: Android Room (SQLite abstraction) for persistence.
- Concurrency: Kotlin Coroutines &
lifecycleScope. - Architecture: Event-Driven Activity (Refactoring to MVVM in progress).
Unlike standard Bluetooth, the Nearby Connections API requires one device to be an Advertiser and one to be a Discoverer. To solve the "who connects to whom" problem without a server, PeerConnect implements a Randomized Role Switching Loop:
- Device A starts Scanning.
- Device B starts Advertising.
- If no connection is made within
Xseconds, they swap roles. - Ghost Timer Fix: A custom handler ensures that role-switching timers are cancelled immediately upon connection to prevent the radio from resetting during an active chat.
When adding a new contact, the app suspends the auto-loop and enters Pairing Mode:
- Host: Broadcasts availability securely.
- Joiner: Scans for signals and filters them into a temporary list.
- Selection: The user is presented with a dialog of found devices. Connection is only initiated when a specific peer is tapped.
- Identity: Devices exchange cryptographically generated IDs and nicknames.
- Text: Serialized Java Objects converted to Byte Payloads.
- Files:
Payload.Type.FILEutilizesParcelFileDescriptorto stream data directly from storage to storage, bypassing memory limits.
- Clone the repository:
git clone https://github.com/SilentFURY-x/PeerConnect-App.git
- Open in Android Studio: Ensure you are using the latest version (Hedgehog or newer).
- Permissions:
The app requests the following runtime permissions:
BLUETOOTH_SCAN/ADVERTISE/CONNECTACCESS_FINE_LOCATIONNEARBY_WIFI_DEVICES(Android 13+)
- Build & Run:
- Deploy to two physical Android devices.
- Note: Android Emulators do not support Bluetooth/Wi-Fi P2P protocols.
com.fury.peerconnect
โโโ data
โ โโโ database # Room Database setup
โ โโโ daos # Data Access Objects (PeerDao, MessageDao)
โ โโโ entities # Data classes (PeerEntity, MessageEntity)
โโโ logic
โ โโโ UserManager # Identity & SharedPrefs wrapper
โ โโโ SecurityHelper # AES Encryption logic
โโโ ui
โ โโโ adapters # RecyclerView Adapters for Chat/Peers
โ โโโ MainActivity.kt # Core Radio Logic & UI Controller
- Background Service: Implement a Foreground Service to keep the radio alive when the app is minimized.
- Mesh Networking: Implement routing logic to allow Device A to talk to Device C via Device B.
- Voice Calls: WebRTC implementation over the offline socket for real-time audio.
- MVVM Refactor: Migrate UI logic from Activity to ViewModels for better testability.
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
-
Fork the Project
-
Create your Feature Branch:
git checkout -b feature/AmazingFeature
-
Commit your Changes:
git commit -m 'Add some AmazingFeature' -
Push to the Branch:
git push origin feature/AmazingFeature
-
Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
Built with โค๏ธ by Arjun Tyagi