This project is a comprehensive, feature-rich BitTorrent client implemented in Golang.It provides a robust implementation of the BitTorrent protocol, supporting various operations from parsing magnet links to downloading files.
-
Magnet Link Parsing
- Extract detailed metadata from magnet links
- Handle complex magnet URI formats
- Resolve trackers and file information
-
Torrent File Handling
- Decode and parse .torrent files
- Extract comprehensive torrent metadata
- Support for various torrent file versions
-
Peer Discovery and Management
- Fetch peer information from trackers
- Perform robust peer handshakes
- Manage peer connections efficiently
-
File Download Capabilities
- Download complete files or specific pieces
- Piece-wise downloading with SHA-1 hash validation
- Support for large and small torrents
-
Network Communication
- Implement BitTorrent wire protocol
- Handle peer-to-peer communication
- Manage download and upload streams
- Golang 1.20 or higher
- Go Modules enabled
-
Clone the repository:
git clone https://github.com/TusharAbhinav/GoTorrent.git cd cmd/mybittorrent
-
Install dependencies:
go mod download
-
Build the application:
go build -o mybittorrent
The BitTorrent client supports multiple commands for various operations:
-
Decode Torrent File
./mybittorrent decode /path/to/torrent/file.torrent
-
Get Torrent Information
./mybittorrent info /path/to/torrent/file.torrent
-
Fetch Peer Information
./mybittorrent peers /path/to/torrent/file.torrent
-
Download Specific Piece
./mybittorrent download_piece /path/to/torrent/file.torrent piece_index
-
Download Complete File
./mybittorrent download /path/to/torrent/file.torrent /path/to/output/file
-
Parse Magnet Link
./mybittorrent magnet_parse "magnet:?xt=urn:btih:..."
-
Download via Magnet Link
./mybittorrent magnet_download "magnet:?xt=urn:btih:..." /path/to/output/file
GoTorrent/
│
├── cmd/
│ └── mybittorrent/
│ └── main.go # Application entry point
│
├── decode/ # Torrent file decoding
│ └── decode.go # Decoding logic
│
├── download/ # File download management
│ └── download.go # Download implementation
│
├── extensions/ # Additional protocol extensions
│ └── magnet/
│ └── magnet.go # Magnet link handling
│
├── info/ # Torrent file information
│ └── info.go # Torrent metadata extraction
│
├── peers/ # Peer discovery and management
│ └── peers.go # Peer-related functionality
│
├── queue/ # Download queue management
│ └── queue.go # Piece download queuing
│
├── tcp/ # TCP communication
│ └── tcp.go # Low-level network communication
│
├── torrent/ # Torrent file processing
│ └── torrent.go # Core torrent file handling
│
├── go.mod # Go module definition
├── go.sum # Dependency lockfile
└── README.md # Project documentation
- Currently supports single-file torrents
- Limited to public trackers
- Basic piece validation
- CodeCrafters Challenge
- BitTorrent Protocol Specification
- Open-source BitTorrent community