This project is a Peer-to-Peer (P2P) File Sharing Application designed to facilitate file sharing among multiple peers in a decentralized network. The application includes features like file search, downloads, peer management, and exclusion settings, all presented with a user-friendly graphical interface.
Features
-
File Search
: Search for files across connected peers. -
File Download
: Download files in chunks from peers. -
Peer Management
: View, add, or remove peers dynamically. -
Exclusion Settings
: Exclude specific files or folders from sharing. -
Robust Networking
: Uses UDP for peer discovery and TCP for reliable file transfer. -
GUI
: Easy-to-use graphical interface for managing files and peers.
The project is structured into multiple layers to separate concerns:
-
File Manager
: Manages shared files and directories. -
PeerManager
: Handles peer-related operations. -
DownloadManager
: Coordinates file downloads using chunk-based transfers.
UDP Broadcaster
: Broadcasts peer availability using UDP.UDPListener
: Listens for peer requests and responses.TCPFileServer
: Serves file chunks via TCP.TCPFileClient
: Requests file chunks from peers.
HashUtil
: Generates unique SHA-1 hashes for files.ChunkManager
: Splits files into chunks and reassembles them.
P2PFileSharingUI
: Provides the graphical user interface for managing the application.
Java Development Kit (JDK) 8 or higher.
Docker (optional, for containerized deployment).
Visual Studio Code or any other Java IDE (for local development).
Using Docker
-
This application is containerized for ease of setup. Follow the steps below:
-
Open a terminal in the project directory.
-
Run the following commands:
-
docker-compose build
-
docker-compose up
-
The application will build and start in the Docker environment.
-
To stop the application, use: docker-compose down
Without Docker
To run the project locally without Docker:
-
Ensure Java is installed on your system.
-
Open a terminal in the project directory.
-
Compile the project using: mkdir -p /app/bin && javac -d /app/bin $(find /app/src -name "*.java")
-
Start the application using: java -cp /app/bin P2PFileSharingUI
-
The application will launch, opening the graphical user interface.
Set Shared Folder:
- Define a folder to share files with other peers.
- Exclude specific files or folders using the exclusion settings.
Connect to Network:
-
Use the Connect button to discover and connect to peers.
-
Search for Files: Enter the file name in the search bar and click Search. Results will appear in the Found Files section.
-
Download Files: Select a file from the results and download it to your destination folder.
-
Manage Peers: Use the List Peers option to view active peers. Disconnect from the network using the Disconnect button.
DownloadManager
- Coordinates downloading files in chunks from peers. Manages active downloads and ensures completion using a round-robin strategy for chunk requests.
HashUtil
- Computes a unique SHA-1 hash for files to ensure integrity and avoid duplicates.
TCPFileClient and TCPFileServer
- Enables reliable file transfer using TCP for chunked data exchange between peers.
P2PFileSharingUI
- Provides an intuitive graphical interface for managing file sharing, peer connections, and file downloads.