It is an unstructured peer-to-peer file-sharing network using Java 21 and Netty 4
-
Clone the repository:
git clone https://github.com/halcyonsdev/p2p-file-transfer.git
-
Navigate to the project directory:
cd p2p-file-transfer -
Build the project:
mvn clean install
-
Run the application:
java -DpeerName=peer -jar target/p2p-file-transfer.jar --config=config/config.properties --peerName=peer --bindPort=8080
- Supports a decentralized network where each peer can directly communicate with others.
- Uses TCP connections managed through Netty.
- Allows peers to request and share files efficiently.
- Supports transferring files in chunks to handle large files.
- Periodic pings
KeepAliveMessageare sent to ensure the connection between peers remains active. - Timeouts trigger reconnection attempts or removal of inactive peers.
- Defines a flexible communication protocol using Protocol Buffers (Protobuf).
- Messages include handshakes, file requests, and other network events.
The ping-pong system is a critical component of the network that:
- Sends periodic ping messages to discover and verify active peers.
- Receives pong responses from peers, which include their metadata.
- Times out inactive peers and removes them from the network.
- Notifies other components about discovered peers, allowing dynamic adjustment of connections.
- Ping: Each peer periodically sends a
PingMessageto its connected peers. - Pong: Upon receiving a ping, peers respond with a
PongMessagethat includes their details. - Timeout Handling: If no pong is received within a specific timeout period, the pinging peer assumes the target is inactive and cleans up resources associated with that peer.
- Automatically connects to available peers when connection slots are free.
- Prioritizes unconnected peers for establishing new connections.
- Configuration can be provided via a
.propertiesfile. - Properties include settings for connection limits, ping intervals, and timeout durations.
- High-performance networking with Netty as the underlying framework.
- Supports asynchronous communication for scalability.
- Provides detailed logs for network events, file transfers, and system actions.
- Startup: Each peer starts and loads its configuration from the provided
.propertiesfile or by default properties. - Handshake: Peers perform an initial handshake to establish connections and exchange metadata.
- Ping-Pong: The ping-pong system ensures active peers are discovered and maintains a healthy network.
- File Requests: Peers can request files from others by sending a
GetFilesRequestmessage and receiving the response with available file names. - File Transfer: File chunks are sent between peers upon request.
This project is licensed under the MIT License. See the LICENSE file for details.