A decentralized peer-to-peer communication application that enables secure messaging and file sharing without requiring internet connectivity or central servers.
This application creates a mesh network where devices can communicate directly with each other, automatically discovering peers and routing messages through multiple hops to ensure connectivity across the network. It features end-to-end encryption, chunked file transfer with integrity verification, and a modern GUI interface.
- Language: Python 3.7+
- GUI Framework: Tkinter (built-in)
- Encryption: Cryptography library (Fernet symmetric encryption with PBKDF2)
- Architecture: Object-oriented design with observer pattern
- TCP (Transmission Control Protocol): Used for reliable message and file transfer
- Port: User-defined (default 9999)
- Ensures message delivery and ordering
- Connection-oriented communication between peers
- UDP (User Datagram Protocol): Used for network broadcasting and peer discovery
- Port: Primary port + 1 (default 10000)
- Broadcasts discovery messages every 5 seconds
- Enables automatic network topology mapping
- JSON-based messaging: Custom protocol for structured communication
- Message Types:
discovery: Peer announcement and network joinchat: Text message communicationfile_chunk: File data transmission in chunkspeer_list: Network topology updates
- Mesh Architecture: True peer-to-peer with message relaying
- Automatic Routing: Messages propagate through multiple hops
- Fault Tolerance: Network remains functional if individual nodes fail
- Dynamic Discovery: Peers automatically find and connect to each other
- Encryption: AES-128 encryption via Fernet (when password provided)
- Key Derivation: PBKDF2 with 100,000 iterations and salt
- File Integrity: SHA256 hashing for corruption detection
- Message Deduplication: Prevents infinite loops in mesh routing
- Chunked Transfer: Files split into 8KB chunks for reliable transmission
- Base64 Encoding: Binary data encoded for JSON transport
- Integrity Verification: SHA256 hash verification on reassembly
- Automatic Reassembly: Chunks combined and saved to downloads folder
- Real-time peer-to-peer messaging
- Secure file sharing with integrity checking
- Automatic peer discovery and connection
- Message encryption with password protection
- Cross-platform compatibility (Windows, Linux, macOS)
- Modern tabbed interface (Chat, Peers, Files)
- Real-time message display with syntax highlighting
- Peer management with connection status
- File transfer progress tracking
- Connection status indicators
- Professional styling and error handling
- Mesh topology with automatic routing
- Fault-tolerant communication
- Stale peer cleanup (30-second timeout)
- Message caching to prevent duplicates
- Background thread management
# Required
python >= 3.7
# Optional (for encryption)
pip install cryptography# Clone or download the application
python mesh_network_app.py
# Or install dependencies first
pip install cryptography
python mesh_network_app.py# Install PyInstaller
pip install pyinstaller
# Build standalone executable
pyinstaller --onefile --windowed mesh_network_app.py
# Or use provided build script
python build.py- Launch the application
- Connect to network using the dialog:
- Enter your display name
- Set port number (default 9999)
- Optional: Set encryption password
- Start chatting and sharing files with discovered peers
- Single Device Testing: Use different ports (9999, 10000, etc.)
- LAN Deployment: Ensure devices are on same subnet
- Firewall Configuration: Open chosen ports for TCP/UDP
- WiFi Hotspot: One device can create hotspot for direct connection
- Go to "Files" tab
- Click "Select File to Send"
- Choose file and confirm
- File chunks will be transmitted to all connected peers
- Received files appear in
mesh_downloads/folder
{
"type": "discovery",
"node_id": "abcd1234",
"node_name": "User-Device",
"ip": "192.168.1.100",
"port": 9999,
"timestamp": 1699123456.789
}{
"type": "chat",
"message_id": "unique-uuid",
"sender_id": "abcd1234",
"sender_name": "User-Device",
"timestamp": 1699123456.789,
"content": "encrypted_message_content"
}{
"type": "file_chunk",
"message_id": "unique-uuid",
"sender_id": "abcd1234",
"sender_name": "User-Device",
"timestamp": 1699123456.789,
"file_id": "file-uuid",
"chunk_index": 0,
"chunk_data": "base64_encoded_chunk",
"file_metadata": {
"filename": "document.pdf",
"file_size": 12345,
"file_hash": "sha256_hash",
"total_chunks": 3
}
}MeshNode (Core)
├── FernetCryptoProvider (Encryption)
├── ChunkedFileManager (File Handling)
├── PeerManager (Peer State)
└── NetworkTransport (TCP/UDP)
MeshNetworkApp (GUI)
├── ChatWidget (Messaging UI)
├── PeersWidget (Network View)
├── FileTransferWidget (File UI)
└── StatusBar (Connection Status)
- Observer Pattern: GUI updates from network events
- Strategy Pattern: Pluggable encryption providers
- Factory Pattern: Message type creation
- Singleton-like: Single mesh node per application
- Main Thread: GUI and user interaction
- Network Threads: TCP server, UDP discovery, cleanup
- Background Tasks: File transfer, message processing
- Thread Safety: Locks and thread-safe queues
- Port: 9999 (TCP), 10000 (UDP discovery)
- Chunk Size: 8KB for file transfers
- Peer Timeout: 30 seconds
- Discovery Interval: 5 seconds
- Download Folder:
mesh_downloads/
# In code customization
node = MeshNode(
node_name="CustomName",
port=8888,
password="encryption_key"
)-
No Peers Found
- Check firewall settings
- Ensure devices on same network
- Verify port availability
-
Connection Failed
- Different ports for multiple instances
- Admin permissions may be required
- Antivirus software blocking connections
-
File Transfer Fails
- Large files may take time
- Network interruption during transfer
- Check available disk space
-
Encryption Not Working
- Install:
pip install cryptography - All peers must use same password
- Password case-sensitive
- Install:
# Enable detailed logging
python mesh_network_app.py --debug# Test port availability
netstat -an | grep 9999
telnet localhost 9999- Algorithm: AES-128 in Fernet format
- Key Derivation: PBKDF2-HMAC-SHA256
- Salt: Fixed application salt (not cryptographically ideal)
- Iterations: 100,000 PBKDF2 rounds
- Fixed salt reduces security against rainbow tables
- No forward secrecy (same key for all messages)
- Peer authentication relies on network trust
- No certificate validation for peer identity
- Implement unique per-session salts
- Add peer certificate verification
- Use ephemeral key exchange (like Signal Protocol)
- Add message authentication codes (MAC)
- Optimal Network Size: 5-20 peers
- Message Propagation: O(n) where n = number of peers
- Memory Usage: ~10MB base + message cache
- File Transfer Rate: ~1-5 MB/s depending on network
- Use wired connections for better performance
- Keep networks small for faster message propagation
- Close unused applications to free network bandwidth
- Use dedicated WiFi network for mesh communication
mesh_network_app.py # Main application file
├── Data Classes # Message, PeerInfo definitions
├── Abstract Interfaces # Crypto, File, Transport abstractions
├── Concrete Implementations # Network, crypto, file handling
├── UI Components # GUI widgets and dialogs
└── Main Application # Integration and orchestration
# Custom encryption provider
class CustomCryptoProvider(ICryptoProvider):
def encrypt(self, data: str) -> str:
# Your encryption logic
pass
def decrypt(self, data: str) -> str:
# Your decryption logic
pass# Run multiple instances for testing
python mesh_network_app.py --port 9999 --name "Node1"
python mesh_network_app.py --port 10001 --name "Node2"This project is provided as-is for educational and personal use. The networking protocols and cryptographic implementations should be reviewed by security professionals before production deployment.
Potential improvements:
- Implement proper key exchange protocols
- Add voice/video call support
- Create mobile app versions
- Add group chat functionality
- Implement distributed file storage
- Add network visualization tools
- TCP/IP Protocol: RFC 793, RFC 791
- UDP Protocol: RFC 768
- JSON Format: RFC 7159
- Fernet Encryption: Cryptography.io specification
- PBKDF2: RFC 2898
- SHA-256: FIPS 180-4
Built with Python • Tkinter • TCP/UDP • Fernet Encryption