BT Operating Principle Analysis and Intranet acceleration Methods

Source: Internet
Author: User
BT Operation Principle Analysis and Intranet speed-up method (transfer)

Because Intranet users cannot provide an external port, they cannot act as servers. however, when using BT, we found that it could allow Intranet users to send messages. As a programmer, we couldn't help downloading its source code for analysis (to see it, I also specifically wrote Python :})

Compared with other P2P software, BT has a unique place. It has an intermediate Web server, which is the announce we entered at the release. this server provides unified management for publishing. Unlike other P2P software, it looks for very unstable personal servers everywhere. the Web server can send messages to intranet users (the principles are described below), which cannot be implemented by other software, however, the bad thing is that announce cannot be downloaded when it is on the machine. The key to P2P download is to be popular, and announce will be lost when it stops.

The role of. torrent
We all know that we need to download a. torrent file before using Bt. What is this file:
First, announce recorded the location of the Publishing Server, so that Bt knew that the Web server was released.
Then there are some file information, file names, directory names, lengths, and so on. Finally, the segment length and the sha1 verification code of the segment (BT for the sake of continuous transfer and file verification, the file is divided into several segments). You can use the WordPad to view the torrent file, which means you know a rough picture. The garbled code behind it is the sha1 verification code.

Start-implement SHA verification for resumable Data Transfer

After opening a torrent file, you must select the file to save. then, if the object does not exist, create a new object. If the object exists, use the sha1 verification code to verify the object. The error is that the object has not been downloaded, so that the object can be resumed, but the 128-bit verification can be implemented, not long enough.

Obtain peer

Now I know what to download. Where can I download it? In this case, we need to find out who provided the upload. Here bt is implemented through the Web server. First, BT will analyze torrent to get a string of URLs.

Http://btfans.3322.org: 6969/announc... 2 & event = started

Http://btfans.3322.org: 6969/announce is the address of the publisher
Info_hash is the Sha Verification Code of info in the torrent file. The web finds the corresponding record in the release list,
Peer_id is its own identifier. It is the first eight bits of Sha verification for 12 0 and the current time + globally unique identifier code (guid), with a total of 20 bits
Port you provide the port for upload
IP: your IP address. If not, the server will find it on its own.
Uploaded downloaded: How much have you uploaded and downloaded? The server can use it for traffic analysis.
Left: How many bytes do you want to download?
Event status, which indicates whether the server is preparing to start or stop the download or whether the download is complete.
This operation is performed once every 5 minutes by default, or is set by the server.

What will the server do?

The server has a track program to manage these requests.
After this code string is obtained, info_hash will be used to search for the list. You can download it if you find it. Sorry if you cannot find it.
Then it will reconnect your IP address and port so that you can know whether you are an intranet user or a common network user (if you are an intranet user, it cannot be connected, because it will connect to your server, your server certainly does not have this port)
Then the server returns the IP addresses and ports of all Internet users who are downloading the file, as shown in the following figure:
D8: intervali1800e5 eersld2: ip14: XXX. XXX. XX. xxx7 eer id20: 00180531904b7e3abdd74 orti6881eeee
Interval 1800 tells BT how many seconds to query once. Here is 30 minutes (a bit too much)
Finally, if you are a public network user, it will put the IP address and port you submitted into the list corresponding to info_hash, so that others will
You can find

Download
After obtaining these peer IP addresses, BT can find the corresponding IP address to download.
BT will go to all the peers to find what you want to download, not to download to seed.
Every time BT finds a peer, it creates a socket to download. Therefore, the more people download, the faster the download speed.

How Intranet users can send messages

As mentioned above, the server only returns the public IP address. How can Intranet users send messages? This is because bt is an active connection software (even if you have downloaded the software, or actively connect to others)
The following is a simulation process:

1. The intranet user starts to perform seed,
2. The server receives the request. Because the request is the first one, no peer returns
3. A public network user submits a request. Because seed is an intranet user, no peer returns the request and waits for download. However, the server puts its IP address in the list.
4. After interval, the Intranet sends a request to the server to obtain the above public IP address.
5. After obtaining the public IP address, the Intranet will be connected immediately.
6. The Internet user establishes a connection and starts data transmission (note that it is a bit strange that the Internet user is a server and the Intranet user is a client)
7. Other Intranet Users download data from the above public network users

Therefore, you must have a public network user to participate in seed. Otherwise, other Intranet users cannot download seed. if all users are Intranet users, all connections will not be established. Of course, this is an extreme situation.
As shown above, Intranet users cannot connect to intranet users. Other users cannot find you from the server, so they cannot actively connect to you. You can only find Internet users on the server every 30 minutes to connect one by one.
Many users in China use Intranet users (I have not tried more than 10 peer servers). Therefore, Intranet users use BT much slower than Internet users. so with the following

Intranet Acceleration

After understanding the principle, we have a solution. Isn't it possible for people outside to find us?
Refer weapon nat-port image (also called Network Address Translation) its principle is not mentioned here (in fact it is not very complicated ), the function is to allow the server to forward requests from the specified port to the specified IP address, so that other machines can respond to these requests, when the Intranet sends data to the Internet, it does not randomly allocate ports as other gateway services do. Instead, it uses the port specified above.

Available Software:
WinRoute pro
Porttunnel
See http://www.pconline.com.cn/pcedu/so...1/127157_2.html for software downloads and usage

However, if your server is Win2000 and you use the built-in network sharing function, there is a simpler method.
Right-click your shared connection and choose Properties.
Go to the public configuration board and press the Settings button. The setting window is displayed.
To the Service Board, press add
Enter the name as needed
Port 6881
Select TCP
Enter your computer name or IP address in the private network
Save it, add the 6882-6889 port image in the same way, and direct them to your computer.
(Because my system is a traditional system, the above names are not necessarily the same as yours)
If you do not understand, please refer to the NAT instructions in the Win2000 help system.

After port ing is used, you are the only one, and others are still the same (including servers), but you can build a dedicated BT download machine.
Now enjoy the following speed pleasure

Disadvantages of BT:
1. It must be written in Python across platforms, but it consumes a lot of resources in windows. In particular, the server should consider using C to rewrite track www. torsponse. CX seems to have done so (its return is not the same as the standard), but it is not unknown if it is not a rewrite.

2 when the track encounters an intranet seed, set the interval to a smaller value.
3. Thinking .......

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.