MCPcopy Index your code
hub / github.com/PeterKwesiAnsah/bitty

github.com/PeterKwesiAnsah/bitty @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
39 symbols 90 edges 8 files 11 documented · 28% updated 17mo ago★ 59
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Bitty

This is a custom BitTorrent client built from scratch using Go. The client is capable of downloading torrents based on .torrent files. It utilizes several custom packages to handle torrent metadata parsing, peer connections, and file downloading. Future plans include running the client in a browser using WebAssembly.

Features

  • Decodes .torrent files using the bencode encoding.
  • Connects to peers using the BitTorrent protocol.
  • Downloads torrent content and writes it to a specified destination.
  • Built with extensibility in mind, with plans for future WebAssembly integration.

Installation

Prerequisites

  • Go 1.16 or higher
  • Git

Clone the Repository

git clone https://github.com/peterkwesiansah/bitty
cd bitty

Install Dependencies

Install the required Go packages:

go mod tidy

Usage

Running the BitTorrent Client

To run the BitTorrent client, you need to provide a source .torrent file and a destination path where the downloaded content will be stored.

  1. Compile and run the program:
go run main.go -src /path/to/source.torrent -dst /path/to/destination

Example:

go run main.go -src debian-12.5.0-amd64-netinst.iso.torrent -dst ./debian-12.5.0-amd64-netinst.iso
  1. The program will automatically start downloading the content from the torrent and save it in the specified destination folder.

Command-Line Flags

  • -src: Path to the source .torrent file. (Required)
  • -dst: Path where the downloaded content should be saved. (Required)

If the src or dst flags are missing, the program will prompt you to use the correct format.

run instead: go run main.go -src /path/to/source -dst /path/to/destination

Code Overview

Main Components

  • Torrent File Parsing: The client reads the torrent metadata using bencode decoding and prepares the necessary information for downloading.
  • Peer Discovery: The client connects with peers through the tracker and establishes P2P connections.
  • Downloading: The client downloads the torrent content piece by piece, using the Torrent struct to manage the process.

Key Packages

  • bencodeTorrent: Handles parsing of the .torrent file and decoding the bencode format.
  • peers: Manages peer discovery and P2P communication.
  • torrentfile: Manages the actual downloading of the torrent data, ensuring that pieces are correctly ordered and written to the destination.

Plans for WebAssembly

One of the future goals is to compile this BitTorrent client to WebAssembly (Wasm), allowing it to run in a browser environment. The major steps involved in achieving this include:

  • Modifying the network layer: Browser environments handle WebSockets and HTTP differently from native environments, so the peer connection logic will need to adapt accordingly.
  • File system changes: Browsers use an in-memory filesystem or the FileSystem API for writing downloaded content, so the current file-writing logic will need to be adjusted for WebAssembly.

To Do

  • [ ] Adapt network and peer management for WebAssembly (Wasm).
  • [ ] Implement browser-based UI for downloading torrents.
  • [ ] Test WebAssembly builds across major browsers.
  • [ ] Download torrent files using magnet links.

Contributing

Contributions are welcome! If you have ideas for new features or improvements, feel free to fork the repository and submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Core symbols most depended-on inside this repo

String
called by 4
peers/peers.go
ReadMessage
called by 3
message/message.go
Serialize
called by 3
message/message.go
HasPiece
called by 1
bitfield/bitfield.go
Read
called by 1
bitfield/bitfield.go
trackerInfo
called by 1
peers/peers.go
parsePeers
called by 1
peers/peers.go
Peers
called by 1
peers/peers.go

Shape

Method 16
Struct 13
Function 8
TypeAlias 2

Languages

Go100%

Modules by API surface

worker/worker.go10 symbols
peers/peers.go8 symbols
torrentfile/torrentfile.go5 symbols
bencodeTorrent/decode.go5 symbols
message/message.go4 symbols
handshake/handshake.go3 symbols
bitfield/bitfield.go3 symbols
main.go1 symbols

For agents

$ claude mcp add bitty \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page