Skip to content

Latest commit

 

History

32 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CotTorrent

A BitTorrent client implementation in Go. This project implements the core BitTorrent protocol including support for magnet links via the Extension Protocol (BEP 10) and Metadata Extension (BEP 9).

Features

  • Parse and display torrent file information
  • Discover peers via HTTP trackers
  • Perform BitTorrent handshakes with peers
  • Download files from torrent files
  • Magnet link support:
    • Parse magnet URIs
    • Extension protocol handshake
    • Metadata fetching (ut_metadata)
    • Download files using only a magnet link

Building

go build -o cottorrent ./cmd/main.go

Usage

Torrent File Commands

Display torrent info:

./cottorrent info <torrent-file>

List peers from tracker:

./cottorrent peers <torrent-file>

Perform handshake with a peer:

./cottorrent handshake <torrent-file> <peer_ip>:<peer_port>

Download a file:

./cottorrent download -o <output-path> <torrent-file>

Magnet Link Commands

Parse a magnet link:

./cottorrent magnet_parse "<magnet-link>"

Perform extension handshake:

./cottorrent magnet_handshake "<magnet-link>"

Fetch and display torrent metadata:

./cottorrent magnet_info "<magnet-link>"

Download a single piece:

./cottorrent magnet_download_piece -o <output-path> "<magnet-link>" <piece-index>

Download entire file:

./cottorrent magnet_download -o <output-path> "<magnet-link>"

Examples

Using the included sample torrent file:

# View torrent info
./cottorrent info sample.torrent

# List available peers
./cottorrent peers sample.torrent

# Download the file
./cottorrent download -o debian.iso sample.torrent

Using a magnet link:

# Download a file via magnet link
./cottorrent magnet_download -o /tmp/output.gif "magnet:?xt=urn:btih:c5fb9894bdaba464811b088d806bdd611ba490af&dn=magnet3.gif&tr=http%3A%2F%2Fbittorrent-test-tracker.codecrafters.io%2Fannounce"

Project Structure

cottorrent/
├── cmd/
│   └── main.go              # CLI entry point
├── internal/
│   ├── bitfield/            # Bitfield handling for piece availability
│   ├── client/              # Peer connection and messaging
│   ├── download/            # Download orchestration
│   ├── handshake/           # BitTorrent handshake protocol
│   ├── message/             # Protocol message encoding/decoding
│   ├── peers/               # Peer representation
│   └── torrent/             # Torrent file parsing and tracker communication
├── sample.torrent           # Sample torrent file for testing
├── go.mod
└── go.sum

Protocol Support

  • BEP 3: The BitTorrent Protocol Specification
  • BEP 10: Extension Protocol
  • BEP 9: Extension for Peers to Send Metadata Files (ut_metadata)

Dependencies

Limitations

  • Supports only HTTP trackers
  • Does not support multi file torrents

About

A BitTorrent client implementation in Go. This project implements the core BitTorrent protocol including support for magnet links via the Extension Protocol (BEP 10) and Metadata Extension (BEP 9).

Resources

Stars

5 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages