What is P2P File Share?
P2P File Share is a pure peer-to-peer file sharing system built with Node.js, inspired by the BitTorrent protocol. It enables multiple clients to exchange files directly with each other without requiring a central server. Each node acts as both a client and a server, creating a distributed network where files are shared efficiently among peers. Unlike traditional file sharing systems that rely on centralized servers, P2P File Share implements a fully decentralized architecture where:- No central server is required - Files are transferred directly between peers
- No tracker dependency - Peer discovery happens through peer exchange (PEX)
- Equal participation - Every node can accept incoming connections and connect to known peers
- Collaborative distribution - Files are divided into pieces that are downloaded and shared simultaneously, accelerating distribution
This is a prototype implementation designed for educational purposes. It does not include encryption or authentication mechanisms.
Key Features
Pure P2P Architecture
No trackers or central servers required. Operates in a fully distributed manner.
Peer Exchange (PEX)
Dynamic peer discovery - nodes share information about other peers to build the network.
Piece-based Transfer
Files are divided into 64 KiB pieces (configurable) for efficient parallel downloading.
Integrity Verification
SHA-1 hash calculation and verification ensures file integrity after download.
Progress Tracking
Real-time console output showing download percentage, bytes transferred, and average speed.
Cross-platform
Works on Linux, Windows, and macOS with Node.js v22+.
Architecture Overview
The P2P File Share system uses a mesh network topology where nodes connect to each other via TCP sockets. The protocol implements several message types for coordination:Protocol Messages
handshake- Initial connection and metadata exchange (file name, size, hash, piece size)bitfield- Broadcast which pieces a peer currently has availablerequest- Request a specific piece from a peerpiece- Send requested piece data (base64 encoded)have- Notify peers when a new piece is acquiredpeers- Exchange peer addresses for network discovery
How It Works
- Seeder nodes have the complete file and listen for connections
- Leecher nodes connect to a seed or another peer to begin downloading
- Nodes exchange metadata through handshake messages
- Peers share their piece availability via bitfield messages
- Leechers request pieces from peers that have them
- As pieces are downloaded, nodes notify others via
havemessages - Once complete, leechers verify file integrity and become seeders themselves
The system implements an anti-collision rule: only the peer with the higher ID initiates connections to prevent duplicate connections between the same pair of peers.
Project Structure
The codebase is organized into three main modules:Module Responsibilities
manager.js- Handles reading and writing file pieces, calculating SHA-1 hashesnode.js- Core P2P networking, TCP connections, message protocol implementationpeer.js- Command-line interface and application entry point
Use Cases
P2P File Share is ideal for:- Learning - Understanding how BitTorrent-style protocols work
- Local networks - Fast file distribution across multiple machines
- Development - Building custom P2P applications
- Education - Teaching distributed systems concepts