This is the wiki page for the BitTorrent client implementing BEP 3: The BitTorrent Protocol Specification and BEP 9: Extension for Peers to Send Metadata Files.
After reading this wiki, you should understand the various components that comprise this codebase, reason about how they interact with one another, and ultimately be able to adapt this code to your needs or write a BitTorrent client yourself 🙂.
Let’s get started!
Before we begin, I recommended skimming the following in order:
You should have an idea of how to answer the following:
.torrent file expose?TODO
/: Top-level directory containing main.go and flag parsing logic.internal/: Libraries used internally by the program.
bittorrent/: Libraries related to the BitTorrent protocol.
client/: Given a torrent file, coordinates downloads from peers.handshake/: Handles initial connection to a peer.message/: Contains data structures for messages exchanged between peers.peer/: Abstracts a connection to a single peer.torrentfile/: Abstracts operations on the .torrent file.tracker/: Abstracts operations between the client and a BitTorrent tracker.preconditions/: Utility methods.stringutil/: Utility methods.udpprotocol/: Unused. Ignore this folder.TODO
TODO
TODO
TODO
TODO
TODO: Insert Wireshark debugging screenshot or video
Wireshark is a network packet analyzer that understands the format of packets specified by the BitTorrent protocol. Analyzing the packets sent or received (or lack thereof) will let you know if any packet is misconstructed.