Skip to content

siddiqui-ayan/cliTorrent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cliTorrent logo

cliTorrent 🧲

cliTorrent is a minimal async BitTorrent client built from scratch - handling peer connections, trackers (HTTP/UDP), and piece verification - all inside a terminal.

Demo

Live demo of the client downloading a Torrent file

Demo

Features implemented

  • ✅ Full .torrent file parser (bencode format)
  • ✅ Multi-tracker support (HTTP/HTTPS and UDP)
  • ✅ Concurrent downloads from multiple peers using asyncio
  • ✅ Single-file and multi-file torrent support
  • ✅ SHA-1 piece verification
  • ✅ Intelligent stall recovery and peer rotation
  • ✅ A simple terminal based UI
  • ❌ DHT support
  • ❌ Rarest piece first implementation
  • ❌ Uploading/seeding to other peers
  • ❌ Downlolad multiple torrents at once

Flow of my bittorent client

        ┌─────────────────────────────────────────────────────────────────┐
        │                    BitTorrent Client Flow                       │
        └─────────────────────────────────────────────────────────────────┘

                         ┌──────────────┐
                         │  User Input  │
                         │(Torrent File)│
                         └──────┬───────┘
                                │
                                ▼
                    ┌─────────────────────┐
                    │  Parse Torrent File │
                    │  (bencode, torrent) │
                    └────────────┬────────┘
                                 │
                    ┌────────────┴────────────┐
                    │                         │
                    ▼                         ▼
            ┌───────────────┐      ┌──────────────────┐
            │ Extract Meta  │      │ Calculate Info   │
            │ (filename,    │      │ Hash (SHA-1)     │
            │  size, etc)   │      └──────────────────┘
            └───────────────┘
                    │
                    ▼
          ┌──────────────────────┐
          │ Contact Tracker      │
          │ (tracker.py)         │
          │ Get Peer List        │
          └─────────┬────────────┘
                    │
                    ▼
          ┌──────────────────────┐
          │ Establish P2P Conn   │
          │ (peers.py)           │
          │ Download Pieces      │
          └─────────┬────────────┘
                    │
        ┌───────────┼───────────┐
        ▼           ▼           ▼
    ┌────────┐ ┌────────┐ ┌──────────┐
    │Piece 1 │ │Piece 2 │ │Piece N   │
    └─────┬──┘ └────┬───┘ └─────┬────┘
          │         │           │
          └────────┬┴──────────┬─┘
                   ▼           ▼
          ┌──────────────────────┐
          │ Verify Hash & Save   │
          │ (downloader.py)      │
          └─────────┬────────────┘
                    │
                    ▼
          ┌──────────────────────┐
          │ Update UI Status     │
          │ (ui.py)              │
          │ Progress, Speed, etc │
          └──────────────────────┘

Installation

  1. Clone the repo
git clone https://github.com/siddiqui-ayan/cliTorrent
cd cliTorrent
  1. Install the required modules
pip install -r requirements.txt
  1. Run the bittorent client
python main.py ./examples/onepiece.torrent

Sources

I wouldn't have been able to get this far without the help of the following resources: Markus Eliasson's bittorent blog, manware's youtube video and the Unofficial bittorent spec, so thank you :)

About

cliTorrent is an Asynchronous (non-blocking) bittorent client written completely in scratch using python.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages