BitTorrent protocol specification-metainfo file structure-Part 2

Source: Internet
Author: User
Tags sha1 hash

Metainfo file structure)
All the data in the meta-information file is encoded in the B encoding method. For the B encoding specification, see the B encoding in this series of documents.

Meta-information files (which we often see. the content of a torrent file is a B-encoded dictionary that contains the keys listed below, where string-type values are all encoded in UTF-8.

Info: The value corresponding to the key is a dictionary describing the torrent file. The dictionary has two possible structures: one corresponds to a single file torrent without a directory structure (that is, the seed file contains only one file ), the other method corresponds to multi-file Torrent (for details, see the following ). (Dictionary type)
Announce: The value corresponding to the key change is the announce URL of the tracker. (String type)
Announce-list: (Optional). This is an extension of the formal specification to provide backward compatibility. (List of lists of strings type)
Creation date: (optional) the value corresponding to the key is the creation time of the torrent file. The time is in the standard UNIX time format. (Integer type, which is the number of seconds since 00:00:00)
Comment: (optional) the value of this key is the comment of the torrent file maker. (String type)
Create by: (Optional). The value of this key is used to create a torrent file.Program. (String type)
Encoding: (optional), as shown in the preceding figure ,. the torrent Metafile contains an info dictionary. When the dictionary is too large, you need to partition It (piece). This encoding is used to generate the part. (String type)

Info Dictionary (that is, the value corresponding to the key info)
This section describes the keys shared by the two modes (single file mode and multi-file mode)

Piece length: The value corresponding to the key is the number of bytes per piece (piece. (Integer type)
Pieces: The value corresponding to this key is a string connected by all the 20-byte sha1 hash values. Each piece (piece) contains a unique sha1 hash value. (Byte string type)
PRIVATE: (Optional). The value of this key is of the integer type. If it is set to 1. The client must broadcast its own existence, and then obtain other peers by explicitly describing the trackers in the meta-information file. If it is set to 0 or not, it indicates that the client can obtain other peers in other ways, such as PEX peer exchange technology and DHT technology. "Private" can be interpreted as there is no external peer source (if the client does not provide PEX peer exchange technology or DHT technology, the BitTorrent client must use tracker to obtain other peers ). (Integer type)

Info in single file mode (the info key in single file Mode)

Corresponding to the single file mode, info dictionary contains the following structure:

Name: file name. It is recommended. (String type)
Length: the number of bytes occupied by the file. (Integer type)
Md5sum: (optional), which is equivalent to a 32-character hexadecimal string of the MD5 file. BitTorrent does not use this key at all, but some programs include it for greater compatibility. (String type)

Info in multiple file mode (the info key in Multi-file mode)
Corresponding to the multi-file mode, info dictionary contains the following structure:

name: Specifies the directory name for storing all files. We recommend that you use this parameter. (String type)
files: A list of dictionaries, each file corresponds to a dictionary (in fact, the following field corresponds to the key in single file mode ), in other words, the multi-file mode is a set of multiple single-file modes ). Each dictionary in the list contains the following structure:
length: Refer to single file mode
md5sum: Refer to single file mode
path: A list containing one or more elements. These elements are combined to indicate the file path and file name. Each element in the list corresponds to a directory name or file name (when it is the last element, it corresponds to a file name ). for example, the file "dir1/dir2/file. ext "consists of three string elements:" dir1 "," dir2 ", and" file. ext ". These three elements are encoded into B-encoded string list: L4: dir14: dir28: file. exte

Notes
the key piece length indicates the normal size of the piece (piece), which is usually the N power of 2. Generally, the size of a piece (piece) is selected based on the total size of the file data in torrent. If the size of a piece (piece) is too large, inefficiency will occur. If the size of a piece (piece) is too small. too large torrent files also affect the choice of the size of a piece (piece. Previously, the selected piece size should be set. torrent files cannot exceed 50-KB (it is estimated that this can reduce storage. the tracker load of the torrent file ).
at present, the best practice is to keep the size of a piece (piece) to kb or less, although for 8-10 Gb files, it will. torrent files are too large, but the increase in the number of files is conducive to file sharing. The most commonly used piece (piece) is 256 kb, 512 KB, and 1 MB.
except the last part, all parts have the same size and the last part is irregular. In this way, the number of pieces (piece) is determined by (total length/piece size.
in Multi-file mode, the file data can be considered as a long continuous stream, which is a series of files in the file list. In this way, the number of pieces (piece) in Multi-file mode is determined in the same way as that in single-file mode. A piece (piece) may span the file boundary.
each piece (piece) contains a sha1 hash value corresponding to the piece (piece) data. These hash values form the key-value corresponding to the pieces key in the info dictionary above ). Note that this value is not a list composed of strings, but a string with a length multiple of 20.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.