BitTorrent Internals - Part 2 - Understanding the Torrent File

BitTorrent Internals - Part 2 - Understanding the Torrent File

A torrent file is an independent session of transfer. To distribute a file, say an Ubuntu image, we would create a torrent holding the meta information about it while the actual content is split into pieces and distributed in the network.

Lifecycle of a Torrent

Torrent is alive so long as there is at least a seeder, seeding the pieces in the network. Once all the nodes who can share the pieces have left the network, the download of the network stops, and the torrent ends until a new seeder pops up.

What torrent file holds

The .torrent file holds all critical meta yet static information about the content, like

  • announce - holds the URL of the tracker
  • created by - name and version of the program who created it
  • creation date - time at which the torrent was created
  • encoding - encoding of the strings in info dictionary
  • comment - some additional comments
  • info - a dictionary that describes files in the torrent

The info dictionary holds the information about the file that is being shared through the torrent. If the torrent is about the Ubuntu image, it will hold info like name, length, and md5sum of the actual file.

Given that the file is split into equal-length pieces, the info dictionary also holds

  • pieces - SHA1 of every piece of the file concatenated
  • piece length - number of bytes in each piece

This information is used in identifying and fetching pieces from the network.

Bencoding

Torrent files are encoded with a custom encoding called Bencoding. It supports data types such as Strings, Integers, List, and Dictionaries (which can only hold string keys).

Strings are encoded as <length>:<string>. Hence, a string arpit will be encoded as 5:arpit.

Integers are encoded as i<integer>e. Hence, an integer 10 will be encoded as i10e.

Lists are encoded as l<becoded values>e. Hence, the list ["a","b", 1 ] will be encoded as l1:a1:bi1e1.

Dictionaries are encoded as d<key1><value1><key2><value2>e. Hence, a dictionary {"a": 1, "b": 2} will be encoded as d1:ai1e1:bi2ee.

Here's the video of my explaining this in-depth ?? do check it out

Thank you so much for reading ?? If you found this helpful, do spread the word about it on social media; it would mean the world to me.

If you liked this short essay, you might also like my courses and playlists on

No alt text provided for this image

I teach an interactive course on System Design where you'll learn how to intuitively design scalable systems. The course will help you

  • become a better engineer
  • ace your technical discussions
  • get you acquainted with a spectrum of topics ranging from Storage Engines, High-throughput systems, to super-clever algorithms behind them.

I have compressed my ~10 years of work experience into this course, and aim to accelerate your engineering growth 100x. To date, the course is trusted by 800+ engineers from 11 different countries and here you can find what they say about the course.

Together, we will dissect and build some amazing systems and understand the intricate details. You can find the week-by-week curriculum and topics, testimonials, and other information at https://arpitbhayani.me/masterclass.

Zedan Saheer

Operations Specialist @ DSV | Supply Chain Management | Freight Forwarding | End to End Operations | Software Engineer | Programmer

2 年

There was a time I used to be a pirated fanatic , I kept the perception that I'm a super power being able to get whatever I want absolutely for free. As I grew up and I got the understanding it's basically stealing! I used to explain to everyone how to choose the better torrent file , More seeders , how to not be a leecher (the one who doesn't contribute to seeding). I had all the new games , software etc.. Hahaha this was maybe 6-8 years back. Glad to see this article of yours deep diving into the internals on how the words such as seeding really work under the hood. ????

要查看或添加评论,请登录

Arpit Bhayani的更多文章

  • The Ideal End To An Ideal Career

    The Ideal End To An Ideal Career

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    6 条评论
  • How to Find and Ride the Next Tech Wave

    How to Find and Ride the Next Tech Wave

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    6 条评论
  • Engineer or Manager? How to Decide Your Path

    Engineer or Manager? How to Decide Your Path

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    5 条评论
  • One Career Bet Worth Taking

    One Career Bet Worth Taking

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    5 条评论
  • Leave your job with grace and gratitude

    Leave your job with grace and gratitude

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    7 条评论
  • Turn Boring Projects into Opportunities

    Turn Boring Projects into Opportunities

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    1 条评论
  • When is the right time to switch?

    When is the right time to switch?

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    8 条评论
  • Ramping up faster in your new job

    Ramping up faster in your new job

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    4 条评论
  • Back Your Disagreement with Data

    Back Your Disagreement with Data

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    2 条评论
  • Doubt yourself every day

    Doubt yourself every day

    This edition of the newsletter contains one quick write-up that will help you grow faster in your career a video I…

    9 条评论

社区洞察

其他会员也浏览了