Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Peer-to-Peer File Sharing System

A Java-based P2P file sharing system that allows peers to share, discover, and download files directly from each other.

Architecture

  • Tracker Server: Central coordinator that maintains registry of peers and their shared files
  • Peer Nodes: Each peer acts as both client (to request files) and server (to serve files)
  • File Transfer: Files are split into chunks for efficient transfer

Components

Tracker (tracker/)

  • TrackerServer.java: Main tracker server that listens for peer connections
  • TrackerHandler.java: Handles individual peer communications with the tracker

Peer (peer/)

  • PeerServer.java: Handles incoming file requests from other peers
  • PeerClient.java: Handles outgoing requests to tracker and other peers (includes CLI)

Utilities (util/)

  • FileChunker.java: Utilities for splitting files into chunks and retrieving chunks
  • HashUtil.java: Utilities for calculating file hashes (MD5) for integrity verification

How to Run

1. Start the Tracker Server

java tracker.TrackerServer

2. Start Peer Nodes

In separate terminal windows:

# First peer on port 8001
java peer.PeerClient localhost 5000 8001

# Second peer on port 8002  
java peer.PeerClient localhost 5000 8002

3. Using the Peer CLI Interface

Once a peer is running, you'll see a menu:

  1. Share file - Share a local file with the network
  2. Search file - Search for files shared by other peers
  3. Download file - Download a file from other peers
  4. Exit - Shut down the peer

Example Workflow

  1. Start tracker: java tracker.TrackerServer
  2. Start peer 1: java peer.PeerClient localhost 5000 8001
  3. Start peer 2: java peer.PeerClient localhost 5000 8002
  4. In peer 1's interface, choose option 1 to share a file (e.g., a test text file)
  5. In peer 2's interface, choose option 2 to search for the file
  6. In peer 2's interface, choose option 3 to download the file from peer 1

Notes

  • Files are stored in each peer's local filesystem
  • The tracker only maintains metadata (peer addresses and file names)
  • Actual file transfers happen directly between peers
  • Files are split into 64KB chunks for transfer
  • MD5 hashing is used to verify file integrity after download

About

A Java-based P2P file sharing system that allows peers to share, discover, and download files directly from each other.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages