Skip to content

Latest commit

ย 

History

History
87 lines (72 loc) ยท 3.99 KB

File metadata and controls

87 lines (72 loc) ยท 3.99 KB

๐Ÿฆ‹ Butterfly Drop

P2P file sharing via WebRTC DataChannels. No cloud, no accounts.

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Device A   โ”‚                    โ”‚  Device B   โ”‚
โ”‚  (Sender)   โ”‚                    โ”‚ (Receiver)  โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜
       โ”‚                                  โ”‚
       โ”‚ 1. WS: session-create            โ”‚
       โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
       โ”‚                                  โ”‚
       โ”‚ 2. WS: session-join              โ”‚
       โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
       โ”‚                                  โ”‚
       โ”‚ 3. WS: SDP offer/answer          โ”‚
       โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
       โ”‚ 4. WS: ICE candidates            โ”‚
       โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
       โ”‚                                  โ”‚
       โ”‚ 5. WebRTC P2P established        โ”‚
       โ”‚โ—„โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ–บโ”‚
       โ”‚                                  โ”‚
       โ”‚ 6. DataChannel: file chunks      โ”‚
       โ”‚โ—„โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ–บโ”‚
       โ”‚   (DTLS encrypted, SCTP)         โ”‚
       โ”‚                                  โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Signaling   โ”‚                    โ”‚ Signaling   โ”‚
โ”‚   Server    โ”‚                    โ”‚   Server    โ”‚
โ”‚  (WebSocket)โ”‚                    โ”‚  (WebSocket)โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
     โ”‚                                    โ”‚
     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ SDP/ICE only โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
     (no file data, ephemeral sessions)

Flow:

  1. Sender creates session โ†’ Signaling server generates session ID
  2. Receiver joins via session ID โ†’ Signaling server links peers
  3. SDP offer/answer exchange โ†’ WebRTC negotiation
  4. ICE candidates exchange โ†’ NAT traversal
  5. P2P connection established โ†’ Direct WebRTC DataChannel
  6. File chunks stream โ†’ DTLS encrypted, ordered delivery

Stack

  • React 19 + TypeScript + Vite
  • Node.js + WebSocket (ws)
  • WebRTC DataChannels
  • Tailwind + shadcn/ui

Specs

  • Chunk Size: 16-64 KB (adaptive)
  • Session: 12-char URL-safe ID, 30min timeout
  • Data Channel: Ordered, no retransmission
  • STUN: Google's public servers
  • Speed: ~50-100 MB/s (LAN, <10MB), ~20-60 MB/s (LAN, >100MB)
  • Bundle: 826 KB (254 KB gzipped)

Roadmap & Future Enhancements

๐Ÿšง In Progress / Planned

  • Multi-Peer Support: Send files to multiple peers simultaneously in the same session
    • Select multiple devices at once
    • Parallel file transfers with individual progress tracking
    • Aggregate transfer statistics
    • See MULTI_PEER_PLAN.md for detailed architecture

๐Ÿ”ฎ Future Enhancements

  • Multiple Data Channel Support: Use multiple data channels per peer for improved throughput and parallel transfers
  • Resumable Transfers: Resume interrupted file transfers
  • File Preview: Preview images, videos, and documents before downloading
  • Folder Structure Preservation: Better folder transfer with nested directory support
  • Transfer Speed Optimization: Adaptive chunk sizing based on network conditions
  • Transfer Queue: Queue multiple file transfers
  • Bandwidth Throttling: Control upload/download speed limits

License

MIT