A true peer-to-peer file sharing system using WebRTC DataChannels for direct communication between browsers. The server only acts as a signaling server to facilitate WebRTC connection establishment, with no file data passing through the server.
The True P2P application implements direct peer-to-peer file sharing using WebRTC DataChannels. This approach provides the highest level of privacy and true P2P communication while maintaining the reliability of WebRTC for NAT traversal and connection establishment.
- Backend: Flask, Flask-SocketIO (signaling only)
- Frontend: HTML5, CSS3, JavaScript (ES6+)
- P2P Protocol: WebRTC DataChannels
- Signaling: WebSocket (Socket.IO)
- NAT Traversal: STUN servers
- Styling: Bootstrap 5, Font Awesome icons
.
βββ app.py # Main Flask application with
βββ templates/
β βββ upload.html # File upload interface
β βββ receive.html # File download interface
βββ static/
β βββ js/
β β βββ protocol.js # True P2P protocol implementation
β β βββ upload.js # Upload page JavaScript
β β βββ receive.js # Download page JavaScript
β βββ css/
β βββ style.css # Application styles
βββ requirements.txt # Python dependencies for this repo
βββ .gitignore # Git ignore rules
βββ README.md # This documentation
- File Selection: User selects files to share
- Protocol Initialization: True P2P protocol is initialized
- File Chunking: Files are split into chunks for transfer
- WebRTC Setup: RTCPeerConnection is established
- Data Channel Creation: WebRTC DataChannel is created
- Signaling: Server facilitates WebRTC connection establishment
- Direct Transfer: File chunks are sent directly to peer
- Shareable URL: A shareable URL is generated for distribution
- Magnet URI Access: User accesses the shareable URL
- Metadata Retrieval: Transfer metadata is retrieved from server
- Protocol Initialization: True P2P protocol is initialized
- WebRTC Setup: RTCPeerConnection is established
- Data Channel Setup: WebRTC DataChannel is configured
- Signaling: Server facilitates WebRTC connection establishment
- Direct Download: File chunks are received directly from peer
- File Reconstruction: Chunks are reassembled into original file
- Progress Tracking: Real-time progress updates are displayed
- File Download: Reconstructed file is made available for download
GET /- Upload page interfaceGET /share/<transfer_id>- Download page interface
POST /api/create-transfer- Create new transferGET /api/transfer/<transfer_id>- Get transfer informationPOST /api/cleanup- Clean up expired transfers
join_transfer_room- Join transfer room for signalingwebrtc_offer- WebRTC offer for peer connectionwebrtc_answer- WebRTC answer for peer connectionwebrtc_ice_candidate- ICE candidate for NAT traversalrequest_offer- Request WebRTC offer from senderpeer_joined- Notify when peer joins roomoffer_requested- Notify when offer is requested
Uploader Server Downloader
| | |
|-- Select Files --------->| |
| | |
|-- Initialize Protocol -->| |
| | |
|-- Chunk Files ---------->| |
| | |
|-- Setup WebRTC --------->| |
| | |
|-- Create Data Channel -->| |
| | |
|-- Join Signaling Room -->| |
| | |
|-- Generate Share URL --->| |
| | |
| |<-- Access Share URL -----|
| | |
| |-- Return Metadata ------->|
| | |
| |<-- Join Signaling Room --|
| | |
|<-- WebRTC Signaling ------------------------------->|
| |
|<-- Direct P2P Transfer ---------------------------->|
| |
|<-- File Transfer Complete-------------------------->|
- Direct P2P Transfer: Files sent directly between peers
- WebRTC DataChannels: High-performance data transfer
- NAT Traversal: Automatic NAT traversal with STUN servers
- File Chunking: Efficient chunk-based transfer
- Progress Tracking: Real-time transfer progress
- Shareable URLs: Easy sharing via generated URLs
- Direct P2P Download: Files received directly from peers
- WebRTC DataChannels: Reliable data channel communication
- File Reconstruction: Automatic file assembly from chunks
- Progress Tracking: Real-time download progress
- Direct Download: Browser-based file download
- Error Handling: Comprehensive error management
- True P2P: No server storage of file data
- WebRTC Signaling: Server only for connection establishment
- STUN Servers: NAT traversal support
- Data Channel Management: Reliable data transfer
- Connection Monitoring: Real-time connection status
- Resource Cleanup: Automatic cleanup of resources
const iceServers = [
{ urls: 'stun:stun.l.google.com:19302' },
{ urls: 'stun:stun1.l.google.com:19302' },
];
const dataChannelConfig = {
ordered: true,
maxRetransmits: 3
};# SocketIO configuration
socketio = SocketIO(app, cors_allowed_origins="*")
# Transfer cleanup settings
CLEANUP_INTERVAL = 86400 # 24 hours in seconds
MAX_FILE_SIZE = 100 * 1024 * 1024 # 100MB limit- Python 3.7+
- Flask, Flask-SocketIO
- Modern web browser with WebRTC support
-
Install Dependencies
pip install -r requirements.txt
-
Run the Application
python app.py
-
Access the Application
- Open
http://localhost:5004in your browser - Start uploading and sharing files!
- Open
-
Upload Files
- Select files using the file input
- Click "Start Direct P2P Sharing"
- Wait for WebRTC connection establishment
- Copy the shareable URL
-
Download Files
- Open the shareable URL
- Wait for WebRTC connection establishment
- Monitor download progress
- Click "Download File" when complete
The application provides comprehensive logging for debugging and monitoring:
True P2P Upload: Page initialized
True P2P Upload: Files selected: 1
True P2P Upload: Generated transfer ID: true-p2p-1234567890-abc123
True P2P Upload: Protocol initialized
True P2P Upload: File set for processing: example.jpg (1024000 bytes)
True P2P Upload: File split into 16 chunks
True P2P Upload: WebRTC connection ready
True P2P Upload: Data channel ready for P2P transfer
True P2P Upload: Shareable URL generated
- Upload Progress: Direct P2P transfer progress
- Download Progress: Real-time download percentage
- WebRTC Status: Connection and data channel status
- Peer Status: Peer connection monitoring
- No Server Storage: Files never stored on server
- Direct P2P: Direct communication between peers
- End-to-End: Data encrypted by WebRTC
- STUN Servers: Trusted STUN servers for NAT traversal
- WebRTC Security: Built-in WebRTC security features
- HTTPS: Use HTTPS in production