VC instance learning (4): BT expands development documentation

xiaoxiao2021-03-06  46

BT expands development documentation

First, the principle of BT

As we all know, general downloads have great restrictions on the number of people downloaded simultaneously, because in general, the download is to transfer files from the server to the client, such as FTP, HTTP, PUB, etc. But there is a problem. As the user increases, the requirements for bandwidth also increases, and users will cause bottlenecks, and they will hang up the server, so many servers will have users. The limitations of the number, the download speed limit, which causes many inconveniences to the user.

But BT is different, download it with BT, the more users, the faster download, this is it? Because BT uses a pyramid scheme to achieve sharing, the working principle is as follows:

BT first divided a file into the Z part at the server, and the servers downloaded the Nth part. Take B has been downloaded the M part. BT will go to the computer to go to the computer to go to the computer, so it will not only reduce the server side, but also accelerate the user (B) Download speed, efficiency also improved, which also reduces the limitations between geographies. For example, C should have been downloaded to the server to download, but if you go to A and B's computer, you will be much better. So, the more people say, the more people downloaded, the faster everyone, the superiority of BT is here. Moreover, while you download, you are also uploading (others get some part of the file from your computer), so you are also contributing to the downloads provided by others.

Due to the different principles, the download files put on the BT server are very small. In fact, these files are not the file you want to download, these files are files that have been created when the software provider releases files. Generally, it is a file that is ended with. Torrent, a very small size. The general download is put the next file to the server, so that the server must provide a large amount of space, because so, we can proudly say: "BT speed, unlimited capacity"!

Second, BT defect

BT download is also a P2P shared download method, so its development prospect can also reflect the development prospect of P2P from one aspect! As a shared download method of P2P, it has countless BTFans, unlimited capacity, huge bandwidth, the latest and most comprehensive resources, which is not a compassion of any traditional download mode. However, there is also a defect:

First, the network security hidden dangers from the P2P download method: IP address is easily acquired by others, and the firewall setting is relatively difficult.

Second, BT download is still not ideal for some users who have someone Internet access. Therefore, the speed of downloading the intranet will be slower.

Third, BT prospects

Since BT has the advantage that is more than traditional download methods, we gerlenched into a new download system with a traditional download method with the BT download.

We think BT's download method can also do the following improvements:

(1) First of all, from safety: IP is easy to intercept. Analysis of the BT protocol can be clearly discovered that BT download is based on the basic development of connection information disclosed in IP, and the user must want the TRACKER server to report some must-have information every other time, including the downloader's IP and other information. This is saved in the database of the Tracker server so that other downloaders are obtained, and then the connection is established by parsing this information to transfer data. This shows: BT download method to avoid IP information is not almost impossible by others. However, we believe that even if you can't completely eliminate the hidden dangers of IP leaks, we should also reduce the security hidden dangers from IP expressions, so we look at the current BT download software, it is not difficult to find these BT. The client software is displayed in clear text, and we think this is not necessary, and gives it improving the IP information leaks in the snow.

So we believe that the client software of the BT should remove the function of displaying the current downloader IP, try to protect the downloader's IP.

(2) Secondary BT download mode is currently expanded, and we think this novel way to download in BT can be used in other aspects, such as the release of large files: in many applications, especially some of the daily needs Data Application Area: Network Conference, Network Radio, etc., these applications require one or a small number of data providers to provide source data, then other data recipients need to get these data, if they follow the traditional download mode, network requirements are obvious High, and in order to alleviate the pressure of the network, a wide variety of compression algorithms must be used to sacrifice our valuable time to get the best balance.

At this time, we think of this way of downloading BT, the BT download method is connected to each other, while transmitting the same file. In this case, it can significantly reduce the pressure of the network, and can also reduce the time waste caused by compression.

Fourth, BT development

We have studied all open source BT clients and server, which has a deep understanding of the principle of BT, and the following is simple to say BT function analysis:

(1) server

Since the server is responsible for a single one, you can summarize the Web release of the Torrent file, Tracker's exchange reservation download information service.

The release of the Torrent file, currently most of the server is handed over to the web publish page, this page and tracker share the same database, Torrent's Web Publishing system is responsible for Torrent's upload, download, management, etc., and from the database Read the corresponding Tracker run status data to display the download situation of the current Torrent file.

The Tracker server, the job is working in: listen in one or more ports, when accepting a connection request, select an idle port to establish a connection, send the download status data of the files you want to download to the client and At the same time, record some of this client to the database, and then on this connection, each time the communication status information of this client.

(2) client

The client's functionality is complicated relative to the server. The client can do can be divided into these parts: parse the Torrent file, connect the Tracker server, connect to other clients, receive data, send data, and maintenance download files.

Analyze the Torrent file, this feature is mainly to obtain information to download files, get Tracker's address and port, and download the file maintenance information. Connect the TRACKER server, this part is mainly to get the latest download status information, as well as the report download status.

Connect other clients, in order to get data, you must connect to other clients, download yourself without obtaining data, and prepare for other downloaders to send themselves download.

Maintain download files, this part is the completeness of the data downloaded and the complete file is complete.

The above is what we currently study the source code analysis. Since most of the BT's open source software is developed by Python language, although there are many a little, there are also people who are inherently inherent, so we absolutely, After reading the source code developed by Python, use C language.

(3) The source code analysis of the original Bittorrent is described below:

Since most of our current development is mostly working in the client, we ignore the study of the server here, directly cut into the client's research:

There are a lot of part of the BT client, which can be seen from his code structure:

Overall architecture:

Overall, the BT client is actually running in the form of a server. This seems to be a bit difficult to understand, but it is true. Why is a server? The main function of the client is to download files, but as a P2P software, it must provide upload services, that is, it must wait on a port, waiting for other Peers's connection requests. From this point of view, it must be run in the form of a server. When we actually analyze the code, we can see that the client is used to use the RawServer class to implement the web server. The client's code starts from Download.py, first complete the function 1, then enter the server cycle, and during each cycle process, the functions 2, 3, 4 are completed. Among them, the Rerequester class is responsible for completing the function 2, which adds its own task function to RawServer :: add_task (), to RawServer, and communicate with the Tracker server every other time. ENCIDER, Connecter and other classes are combined, complete features 3 and 4.

Class hierarchy:

There are many classes involved in the BT client, and I first describe these functions, then give them a hierarchy.

1, Rawserver: Responsible for the implementation of web server

2, Rerequester: Responsible and tracker communication. It calls RawServer :: add_task (), adds its own task function back to RawServer Relenter :: C ().

3, ENCIDER: A Handler class (mentioned in the analysis of the Tracker server), responsible for processing the connection with other Peers to analyze and analyze the read data according to the BT peer protocol.

In summary, the Encoder class is in encrypter.py, in this file, there is a Connection class, and there is a CONNECTER.PY file, there is a CONNECTION class, which is a bit embarrassing, for distinguishing, I will re-re- Named E-Connection and C-Connection.

Specific analysis needs to be seen according to source code (ignore here).

The above is our current development prospects, we think that such ideas should come out of a new data transmission area. V. Current research progress:

The analysis of the source code has ended the overall analysis and is now in the code analysis of the specific module. The next step is to do C rewrite for each class.

[Process Studio] Wang Jun wrote on November 27, 2004 in the early morning

转载请注明原文地址:https://www.9cbs.com/read-87468.html

New Post(0)