Back to browse
GitHub Repository

A distributed P2P BitTorrent client in Go with custom networking and concurrency handling.

2 starsGo

I built a concurrent BitTorrent engine in Go to master P2P protocols

by Jyotishmoy·Feb 14, 2026·4 points·4 comments

AI Analysis

●●SolidWizardryBig BrainNiche Gem

BitTorrent engine tackles real distributed systems problems—slow peers, data poisoning, pipelining.

Strengths
  • Solves genuine P2P challenges: worker pools prevent slowest peer bottleneck, pipelining saturates bandwidth, stateless re-queueing handles failures.
  • Deep technical execution: binary handshakes, Bencode parsing with reflection, Big-Endian encoding, tracker protocol—no shortcuts.
  • Educational value for learning distributed systems, concurrency patterns, and protocol implementation at a non-trivial scale.
Weaknesses
  • Zero documentation beyond README—no guides, examples, or tests visible; unclear if it actually downloads files reliably.
  • BitTorrent clients already exist; novelty is the learning journey, not a novel architecture or competitive advantage.
Target Audience

Backend engineers, distributed systems learners, Go developers interested in P2P protocols

Similar To

Transmission (established BitTorrent client) · libtorrent (reference P2P implementation) · Syncthing (Go-based P2P, but different use case)

Post Description

I’ve always used BitTorrent, but I never understood the complexity of peer-to-peer orchestration until I tried to build it from scratch. I wanted to move beyond simple "Hello World" projects and tackle something that involved real-world constraints: network latency, data poisoning, and the "Slow Peer Problem."

Key Technical Challenges I Solved:

Non-Blocking Concurrency: Used a worker pool where each peer gets its own Goroutine. I implemented a "Stateless Worker" logic where if a peer fails a SHA-1 hash check or drops the connection, the piece is automatically re-queued into a thread-safe channel for other peers to pick up.

Request Pipelining: To fight network RTT, I implemented a pipeline depth of 5. The client dispatches multiple 16KB block requests without waiting for the previous one to return, ensuring the bandwidth is fully saturated.

The Binary Boundary: Dealing with Big-Endian logic and the 68-byte binary handshake taught me more about encoding/binary and byte-alignment than any textbook could.

Zero-Trust Data Integrity: Every 256KB piece is verified against a "Golden Hash" using crypto/sha1 before being written to disk. If a single bit is off, the data is purged.

The Specification: I’ve documented the full spec in the README, covering:

Reflection-based Bencode Parsing.

Compact Tracker Discovery (BEP-0023).

The Choke/Unchoke Protocol State Machine.

Data Granularity (Pieces vs. Blocks).

Repo: https://github.com/Jyotishmoy12/Bittorrent-Client-in-Go

I’d love to get feedback from the community on my concurrency model and how I handled the peer lifecycle.

Similar Projects