Skip to content

About

Capable of downloading multiple files and is compatible with the existing Torrents.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BitTorrent Client (Java)

CMSC 417 - Computer Networks - Spring 2026

Prerequisites

  • Java 17+ (tested with OpenJDK 21)
  • Gradle 8.7+ (wrapper included)

Build

./gradlew build

Run

# Basic usage
java -cp build/classes/java/main bittorrent.Main <torrent-file>

# With options
java -cp build/classes/java/main bittorrent.Main \
  -o ./downloads \
  --strategy rarest \
  --choking standard \
  flatland.torrent

# Or build a fat jar first
./gradlew jar
java -jar build/libs/bittorrent-client-1.0.jar flatland.torrent -o ./downloads

Options

Flag Values Default Description
-o <dir> path . Output directory
--strategy sequential, rarest, endgame sequential Piece selection strategy
--choking standard, bittyrant, propshare standard Choking algorithm
-v - off Verbose logging
-h - - Show help

Run Tests

./gradlew test

Features

Core Features

  1. HTTP tracker communication (hand-coded over raw sockets, no HTTP libraries)
    • Compact peer format support
    • Single announce URL and announce-list (BEP 12) support
  2. Download files from other instances of this client
  3. Download files from official BitTorrent clients (Transmission, qBittorrent)

Extra Credit Features

  1. UDP tracker (BEP 15) - connect/announce over DatagramSocket
  2. HTTPS tracker - hand-coded HTTP wrapped with SSLSocketFactory
  3. Multi-file mode - pieces mapped across file boundaries
  4. Rarest-first strategy - piece availability counting, random tie-breaking
  5. Endgame mode - aggressive requesting when few pieces remain
  6. BitTyrant - minimize upload to maintain reciprocation
  7. PropShare - proportional upload allocation based on download received

Architecture

bittorrent/
├── Main.java              CLI entry point
├── bencode/               Bencode encoder/decoder
├── torrent/               .torrent file parser
├── tracker/               HTTP, HTTPS, UDP tracker clients
├── peer/                  Wire protocol (handshake, messages, connections)
├── download/              Download orchestration, piece management, file I/O
└── strategy/              Pluggable piece selection and choking algorithms

Key Design Choices

  • Threading: One thread per peer connection + scheduled executor for periodic tasks
  • Thread safety: synchronized blocks on PieceManager, CopyOnWriteArrayList for peer list, AtomicInteger/AtomicLong for counters
  • Strategy pattern: Pluggable PieceStrategy and ChokingStrategy interfaces
  • File I/O: RandomAccessFile with byte-range mapping for multi-file support
  • No third-party libraries: All HTTP/UDP communication hand-coded over raw sockets
  • SHA-1: java.security.MessageDigest (standard library)

Test Coverage

40 tests across 7 test files covering all core and extra credit features:

Test File Tests Coverage
BencodeTest 7 Encode/decode all types, round-trip, invalid input
TorrentFileTest 6 Metadata parsing, info hash, announce URLs, piece sizes
TrackerResponseTest 3 Compact peers, failure response, non-compact peers
PeerMessageTest 5 All message types, serialization, bitfield packing
PieceManagerTest 6 Piece lifecycle, block management, completion tracking
StrategyTest 8 Sequential, rarest-first, endgame, choking
HttpTrackerClientTest 4 URL encoding, construction, response parsing

About

Capable of downloading multiple files and is compatible with the existing Torrents.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages