ArticleDirectory
Http://zh.wikipedia.org/wiki/BitTorrent_ (% E5 % 8d % 8f % E8 % AE % AE)
BitTorrent protocol(AbbreviationBT, Commonly knownBit flood,BT downloadIs a network file transfer protocol that implements point-to-point file sharing technology. Compared with other point-to-point protocols, it has a more point-to-point feature. Simply put, the more people download, the faster the download speed. After the download is complete, you only need to stop the task and continue to upload it as a seed for others to download.
TCP/IP protocol is used for downloading through HTTP/ftp. BitTorrent is a P2P File Transfer Protocol Based on the TCP/IP protocol, which is at the application layer of the TCP/IP structure. The BitTorrent protocol itself also contains many specific content protocols and extension protocols, which are constantly being expanded.
According to the BitTorrent protocol, the file publisher generates a. torrent file based on the file to be released, that is, the seed file, also referred to as "Seed ".
A seed file is essentially a text file that contains the tracker information and file information. Tracker information is mainly the address of the tracker server required for BT download and the settings for the tracker server. The file information is generated based on the calculation of the target file, the calculation result is encoded according to the bencode rules in the BitTorrent protocol. The main principle is to divide the downloaded files into equal blocks, which must be an integer of 2 K to the power of 2 k (because it is a virtual block, files are not generated on the hard disk), and the index information and hash Verification Code of each block are written into the seed file. Therefore, the seed file is the "Index" of the downloaded file ".
To download the file content, you must first obtain the corresponding seed file and then use the BT client to download it.
During download, the BT client first parses the seed file to obtain the tracker address, and then connects to the tracker server. The tracker server responds to the download request and provides the IP addresses of other download recipients (including Publishers. The downloader connects to another Downloader. Based on the seed file, the two tell the other party that they already have blocks, and then exchange the data that the other party does not have. In this case, the data traffic on a single line is dispersed without the participation of other servers, thus reducing the server load.
For each downloaded part, you need to calculate the hash verification code of the downloaded part and compare it with the hash verification code in the seed file. If the hash verification code is the same, it indicates that the block is correct. If the hash verification code is different, you need to download the block again. This rule aims to solve the problem of download content accuracy.
For HTTP/FTP downloads, the published files are only on one or more servers. There are too many people to download the files, and the bandwidth of the server is very high and very slow. BitTorrent downloads feature that the more people download, the more bandwidth it provides, and the more seeds it receives, the faster the download speed.
To solve the problem that some users "Run right after", there is also a super seed algorithm that slowly opens the download content in the unofficial BitTorrent protocol.
[Edit] DHT Network
At present, DHT network technology has been developed and can be downloaded without tracker.
DHT is called a Distributed Hash table. It is a distributed storage method. When a server is not required, each client is responsible for a small range of routing, and is responsible for storing a small amount of data, so as to achieve addressing and storage of the entire DHT network. Using the BT download software that supports this technology, you do not need to connect to tracker to download it, because the software will find and communicate with other users who download the same file in the DHT network to start the download task.
Some software (such as the IOT platform) will automatically search for seed resources through DHT to form a seed market.
In addition, the DHT used hereAlgorithmIt is also called kademlia (also used in eMule, known as the KAD network, and the specific implementation protocol is different ).
The obvious advantage of this technology is that it greatly reduces the burden on Tracker (or even unnecessary ). Users can create communications more quickly (especially when they cannot connect to tracker ).
[Edit] related concepts in BT
Tracker: the server that collects the downloaded information and provides the information to other download users so that the download users can connect to each other and transmit data.
Seed: indicates that all files in a download task are completely downloaded by a Downloader. In this case, the downloader becomes a seed. The file published by the publisher itself is the original seed.
Solution: The publisher provides all the content of the download task. After the download is completed, the publisher continues to provide the download to others.
A c ++-written BT client can study its implementation:
Enhanced ctorrent
Http://www.rahul.net/dholmes/ctorrent/