This project implements a Peer-to-Peer (P2P) file sharing application. The system allows peers to discover each other, exchange file metadata, and transfer files in a decentralized network. The application leverages Java for its core logic, Java Swing for the graphical user interface (GUI), and Docker for deployment and testing across multiple simulated peers.
- File Sharing:
- Share files across peers.
- Exclude specific files or directories from sharing.
- File Downloading:
- Search for available files in the network.
- Restrict downloads based on file masks.
- Download files in chunks from multiple peers.
- Network Discovery:
- Broadcast and response mechanisms for peer discovery.
- Dynamic routing through discovered peers.
- Decentralized Operation:
- No central server; peers communicate directly.
- Automatic route calculation and message forwarding.
- GUI Support:
- User-friendly interface for managing shared files and downloads.
- Visual representation of connected peers.
- Dockerized Deployment:
- Simulate a multi-peer network using Docker containers.
-
File Management:
FileManager.java: Handles file chunking, saving, merging, and listing shared files.PeerFileMetadata.java: Represents metadata for shared files (e.g., filename, size, hash).
-
Network and Communication:
BroadcastManager.java: Manages peer discovery through broadcast messages.DiscoveryMessage.java: Tracks routing and TTL (time-to-live) for discovery messages.Peer.java&PeerNetworkInterface.java: Represent peers and their network interfaces.FileTransferManager.java: Handles file chunk requests and transfers between peers.NetworkUtils.java: Provides utility functions for network operations (e.g., subnet matching).
-
Message Handling:
Message.java: Interface for various message types.FileChunkMessage.java: Encapsulates a file chunk and metadata for transfer.PeerFileMetadataRequestMessage.java: Requests specific file chunks from a peer.
-
GUI Components:
MainFrame.java: Main application window.FilesPanel.java: Interface for managing shared files and exclusions.DownloadPanel.java: Interface for managing downloads and monitoring progress.GUIUtils.java: Utility functions for GUI components.
-
Application Entry Point:
App.java: Initializes the application and manages thread execution.
The project includes a Docker-based setup to simulate a multi-peer network. The docker-compose.yml file defines multiple peers connected through overlapping networks.
Below is a visual representation of the Docker network and peer setup:
docker-compose.yml:- Defines multiple peer containers and their network connections.
- Simulates a realistic P2P network using Docker networks.
Dockerfile:- Builds the Java application environment.
Makefile:- Simplifies Docker build and run commands.
- Java 17
- Docker and Docker Compose
- Start/Restart the docker containers and networks:
make rebuild
- Clean up unused docker containers and networks:
make clean
- Compile source codes.
- Execute the application:
java -cp out com.github.fevzibabaoglu.App
- Launch the Application:
- Run the main class.
- Set Up Shared Files:
- Configure the source and destination folder in the
Filespanel. - Add exclusions if needed.
- Configure the source and destination folder in the
- Search and Download Files:
- Use the
Downloadpanel to browse available files. - Right-click on a file and select
Download.
- Use the
- Each container represents a peer.
- Files shared by peers are accessible through the Docker volumes configured in the
docker-compose.ymlfile. - Observe the peer discovery process in the logs.
- Broadcast Mechanism:
BroadcastManagerbroadcastsDiscoveryMessageto find peers.- Forwarding ensures the message reaches peers within the TTL.
- File Transfer:
- File chunks are transferred using
FileChunkMessage. - Chunk requests are managed through
PeerFileMetadataRequestMessage.
- File chunks are transferred using
- Separate threads handle:
- Broadcasting and listening for discovery messages.
- File transfer requests and responses.
- Simulates a P2P network with overlapping subnets.
- Each peer connects to multiple networks to mimic real-world scenarios.
This project is open-source and released under the MIT License.
