This project is a BitTorrent-inspired Peer-to-Peer (P2P) file sharing system that enables users to share files by dividing them into chunks and distributing these chunks across peers. The system leverages a tracker server to coordinate peers and manage chunk availability.
- Kabir Singh Bhatia ([email protected])
- Prabhudatta Mishra ([email protected])
- File Chunking: Files are split into fixed-size chunks with SHA1 hashes for integrity.
- Tracker Server: Manages peer connections and keeps track of which peers have which chunks.
- Peer-to-Peer Data Exchange: Peers share missing chunks with each other, prioritizing rarest pieces.
- Data Integrity Verification: Ensures the received chunks match their expected hash for reliable transfers.
- Optimistic Unchoking: Supports equitable resource sharing among peers by maintaining a list of top peers and rotating connections.
chunker_file.py
: Splits files into chunks and saves each chunk to disk.hashing.py
: Calculates and verifies SHA1 hashes for data integrity.torrent_metadata.py
: Generates and saves metadata for files, storing information like chunk hashes, file size, and tracker URL.tracker_server.py
: Coordinates peers, maintaining connections and tracking chunk distribution.peer.py
: Represents individual peers, handling chunk uploads, downloads, and communication with the tracker.piece_manager.py
: Manages and prioritizes missing pieces, helping peers choose the rarest pieces first for download.
- Python 3.8 or above
- Internet access to run a local tracker and connect peers (or use a network setup for local testing)
-
Clone the repository:
git clone https://github.com/Prabhudatta3004/P2P_File_Sharing.git cd P2P_File_Sharing
-
Install required dependencies:
pip install -r requirements.txt
-
Ensure the tracker and peer files are set up with the correct IP addresses and ports. Adjust
TRACKER_HOST
andTRACKER_PORT
inpeer.py
if necessary.
-
Start the Tracker Server: Run the tracker server to handle peer connections:
python tracker_server.py
-
Start a Peer: Run a peer instance, providing the file to share:
python peer.py
- Modify
file_path
inpeer.py
with the file's path to be shared. - Each peer will share, request, and download chunks of the file based on availability in the network.
- Modify
-
Metadata Creation: To generate a metadata file for any file you intend to share, use
torrent_metadata.py
:python torrent_metadata.py
Update the file path and tracker URL in the script for your specific setup.
To test the setup:
- Start
tracker_server.py
to listen for peers. - Start multiple instances of
peer.py
on different terminals or systems, pointing to the same or different files. - Monitor the peer interactions in the console, where you’ll see chunk sharing and download progress.
We welcome contributions to improve the project! Here’s how to get started:
- Fork the Repository: Click on the 'Fork' button at the top of this page to create a copy of this repository in your account.
- Create a New Branch: For each feature or bug fix, create a new branch with a meaningful name:
git checkout -b feature-name
- Make Changes and Commit: Implement your changes and commit them with descriptive messages.
git commit -m "Add a new feature"
- Push and Create a Pull Request:
Open a pull request on the main repository to merge your changes.
git push origin feature-name
- Code Quality: Follow PEP8 guidelines and document functions as necessary.
- Testing: Test new features or modifications to ensure stability.
- Documentation: Update this README or create additional documentation for major changes.
- Implementing more robust error handling for network issues.
- Enhancing the peer selection logic for improved performance.
- Adding a graphical interface for user-friendly interactions.
- Adding Unit tests and system checks.
- Implementing DHT (Distributed Hashing tables) instead of tracker_server.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.