Skip to content

About

name speaks for itself ig.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

Folders and files

Repository files navigation

BitTorrent Client from Scratch (C++)

A BitTorrent client built from scratch in C++ to understand how peer-to-peer file sharing works under the hood.

This project is a learning journey through networking, file formats, hashing, distributed systems, and protocol implementation. Instead of relying on existing torrent libraries, the goal is to implement the core components of the BitTorrent protocol manually.


Objectives

  • Learn the BitTorrent protocol
  • Understand Bencoding and torrent file structure
  • Practice socket programming in C++
  • Implement tracker and peer communication
  • Learn SHA-1 hashing and integrity verification
  • Build a functional torrent downloader

Features

Phase 1: Bencoding Parser

  • String decoding
  • Integer decoding
  • List decoding
  • Dictionary decoding
  • Nested structure support

Phase 2: Torrent File Parser

  • Read .torrent files
  • Extract metadata
  • Parse announce URL
  • Parse piece length
  • Parse file information

Phase 3: Hashing

  • Generate info hash
  • Verify downloaded pieces using SHA-1

Phase 4: Tracker Communication

  • Connect to HTTP trackers
  • Send announce requests
  • Parse tracker responses

Phase 5: Peer Communication

  • Implement BitTorrent handshake
  • Exchange protocol messages
  • Manage peer connections

Phase 6: Download Engine

  • Request pieces
  • Download blocks
  • Reassemble files
  • Verify integrity

Phase 7: Improvements

  • Multi-peer downloads
  • Download progress display
  • Better error handling
  • Performance optimizations

Project Structure

bittorrent-client/
│
├── src/
│   ├── main.cpp
│   ├── bencode.cpp
│   ├── bencode.h
│   └── torrent_parser.cpp
│
├── tests/
│
├── docs/
│
├── README.md
│
└── .gitignore

Current Progress

Completed

  • Project setup

In Progress

  • Bencoding parser

Example Bencoded Data

String:

4:spam

Integer:

i42e

List:

l4:spami42ee

Dictionary:

d3:cow3:moo4:spam4:eggse

Learning Goals

Through this project, I aim to gain hands-on experience with:

  • TCP/IP networking
  • Socket programming
  • Recursive parsers
  • Serialization formats
  • Cryptographic hashing
  • Distributed systems
  • Peer-to-peer architectures
  • Modern C++

References

  • BitTorrent Protocol Specification
  • BEP 3 (BitTorrent Protocol)
  • C++ Documentation

Disclaimer

This project is intended for educational purposes to understand the design and implementation of peer-to-peer protocols and networking systems.


Building projects to learn systems programming, networking, and cybersecurity.

About

name speaks for itself ig.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages