Analysis of Bittorrent protocol Workflow

Source: Internet
Author: User

The Bittorrent protocol is used by the BT download software. This Protocol specifies how to download a file, including many processes. Here we will mainly introduce some concepts related to Bittorrent protocol interaction.

Bittorrent protocol Interaction

Considering the implementation of Bittorrent protocol by different software, the following protocol interaction measurement experiment only analyzes packets before and after data transmission. BitComet 0.63 is used in our experiment. The following are some measurements: (assume that our machine is host.)

1. Communication without seeds

When you do not download the seed or submit the download command, you can see that the host communicates with a series of remote hosts with IP addresses and sends a 98-byte UDP packet, the ports used are all 17638. These packets can be considered as the message packets that the BitComet program sends to the P2P network host (because these UDP packets are not included in the ABC download program)

2. Communication with the tracker server

Because the Tracker server provides Http/Https services, it responds to Http/Https requests. The response contains the peer list to help host A obtain the required information. information recorded in the torrent file: The tracker server list and the info value of the file initiate an HTTP connection to the tracker server and use the GET command to obtain the peer list 。

3. Communicate with peers

When the host obtains the peer list, it will initiate a TCP connection to these IP addresses, and the ports are randomly distributed, the subsequent data transmission is based on TCP. During an observation, an IP address (222.95.92.4 assumed B) occupies the main traffic, next we will conduct observation and analysis on their communication:

In an experiment (5 MB buffer), the sending data of host A and host B is as follows:

 

Packets

Bites

A-> B

2238

2142621

B->

1886

1367552

As you can see, B is the main data source of A and receives A considerable amount of data from A, indicating that the host of B address is not A seed, but the download of B address is the same as that of 。

After three TCP handshakes, host A initiates Bittorrent handshake to host B, and host B sends A handshake. the handshake message content can be referenced. It is worth noting that the handshake starts with 19 characters (0x13) and follows the string 'bittorrent Protocol ', this can be used as a keyword to detect the download of BT. After handshaking is completed, it is the data stream with the length prefix and information displayed in turn. The zero-length information is used to maintain the connection, ignored. This information is generally sent once every 2 minutes, but it is easy to time out while waiting for data 。

Bittorrent

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.

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.