In the BitTorrent file distribution protocol, a torrent file or metainfo file is a computer file format that contains metadata about files and folders to be distributed, in addition to a list of network locations of trackers, which are computers that help participants in the system find each other and form efficient distribution groups called swarms. Torrent files use .torrent as the filename extension. A torrent file acts as a table of contents (index), allowing a client to find other decentralized nodes interacting with the same torrent file. With the help of a torrent file, one can download small parts of the original file from nodes that have already downloaded it. These "peers" enable clients to download one or many files. A torrent file does not contain the content to be distributed; it only contains metadata information about those files, such as their names, folder structure, sizes, and cryptographic hash values for verifying file integrity. Torrent files also contain SHA cryptographic hashes of the file pieces. The BitTorrent Project describes it as a free speech tool allowing users to share information without bearing high bandwidth costs. Instead of individual clients fetching files from a central server, BitTorrent eliminates the need for central content storage by allowing clients to download and upload thousands of chunks of the original file. Many free/freeware programs and operating systems, such as the various Linux distributions offer a torrent file as a P2P download option for users seeking the aforementioned benefits. Torrent files can store the metadata of any file format.
Background Traditional client-server architecture has an asymmetric flow of data: a server only sends data and a client only downloads the data. This puts an asymmetric bandwidth load on the server, especially as the number of concurrent clients increases. The BitTorrent protocol addresses this by decentralizing the distribution. Each client also acts as the server. Peers in BitTorrent swarms don't require a complete copy of the file to start contributing to the swarm; the client can start uploading as soon as it has a piece. Each file to be distributed is divided into small information chunks called pieces. Downloading peers achieve high download speeds by requesting multiple pieces from different computers simultaneously in the swarm. Once obtained, these pieces are usually immediately made available for download by others in the swarm. In this way, the burden on the network is spread among the peers, rather than concentrating at a central distribution hub or cluster. As long as all the pieces are available, peers can come and go; no one peer needs to have all the chunks or to even stay connected to the swarm in order for distribution to continue among the remaining peers. A torrent file is created to represent a file or folder to be shared. In order to get the list of peers who may be sharing pieces, the client connects to the trackers named in the torrent file. A similar result can also be achieved through the use of distributed hash tables (DHT). Then, the client connects directly to the peers in order to request pieces and otherwise participate in a swarm. The client may also report progress to trackers. When the client has all the pieces, the torrent client assembles them into a complete form. They may also continue sharing the pieces, elevating their status to that of seeder rather than an ordinary peer.
File structure A torrent file contains a list of files and integrity metadata about all the pieces, and optionally contains a large list of trackers. A torrent file is a bencoded dictionary with the following keys (the keys in any bencoded dictionary are lexicographically ordered):
announce—the URL of the tracker info—this maps to a dictionary whose keys are very dependent on whether one or more files are being shared: files—a list of dictionaries each corresponding to a file (only when multiple files are being shared). Each dictionary has the following keys: length—size of the file in bytes. path—a list of strings corresponding to subdirectory names, the last of which is the actual file name length—size of the file in bytes (only when one file is being shared though) name—suggested filename where the file is to be saved (if one file)/suggested directory name where the files are to be saved (if multiple files) piece length—number of bytes per piece. This is commonly 28 KiB = 256 KiB = 262,144 B. pieces—a hash list, i.e., a concatenation of each piece's SHA-1 hash. As SHA-1 returns a 160-bit hash, pieces will be a string whose length is a multiple of 20 bytes. If the torrent contains multiple files, the pieces are formed by concatenating the files in the order they appear in the files dictionary (i.e., all pieces in the torrent are the full piece length except for the last piece, which may be shorter). All strings must be UTF-8 encoded, except for pieces, which contains binary data. A torrent is uniquely identified by an infohash, a SHA-1 hash calculated over the contents of the info dictionary in bencode form. Changes to other portions of the torrent do not affect the hash. This hash is used to identify the torrent to other peers via DHT and to the tracker. It is also used in magnet links.
BitTorrent v2 The BitTorrent v2 protocol (BEP-0052) introduces a new definition of the torrent file. The basic structure is:
… excerpt ends here. Continue reading the full article.