BT source code learning experience (10): client source code analysis (list of related objects)

Source: Internet
Author: User

BT source code learning experience (10): client source code analysis (list of related objects) Author: Wolfenstein (neversaynever), The multitorrent object in BitTorrent/download. py can start the actual download task. To start downloading, you need to create a multitorrent object and call the start_torrent method repeatedly to start a new download. When calling this method, you must have prepared the corresponding download task information as a parameter, including the processed metadata (after BitTorrent/convertedmetainfo. PY module for processing), configuration information, a class that implements the feedback interface (in this way, the status changes during downloading can be reflected in a timely manner, as a result, the feedback interface is reflected in the text information or in the graphic interface.) and the local directory that stores the content of the seed file. This function returns a _ singletorrent object, which represents a single download task for a seed object. The short line before this object indicates that it is a private object and cannot be created separately, it can only be created through start_torrent. In addition to the feedback interface, it allows the interface module to actively call _ singletorrent. get_status to obtain statistics about the Download Status of the seed file. Of course, do not forget to call multitorrent. rawserver. listen_forever () to start scheduling. When creating a multitorrent class, it will create a rawserver internally. The previous steps were to directly analyze the program through the process, but this time it was different because the program structure of the client is complicated and various objects are correlated with each other, you must have a general understanding of the functions of these objects before further analysis. Therefore, this time we will briefly introduce the main objects involved in the client download program. Multitorrent: The main object for downloading task management, which is defined in BitTorrent/download. py. A rawserver is maintained internally and _ singletorrent can be created (defined in the same module as it .) It also maintains other objects internally. Singleportlistener: Manages network connections. It is the network connection processing object of rawserver in multitorrent and is defined in BitTorrent/encoder. py. Filepool: manages the file pool, which is defined in BitTorrent/storage. py. It ensures that the number of files opened on the hard disk is within a limited value at the same time. Ratelimiter: Speed limit class. It is defined in BitTorrent/ratelimiter. py. It can control the upload speed when all the seed files are downloaded. Storage and storagewrapper: storage management class. Defined in BitTorrent/storage. py and storagewrapper. in py, they are used to shield other parts of the program from the offset of the first part of the seed file corresponding to the file on the actual hard disk. That is to say, it provides the following services for other parts of the program, and determines that there are currently the first few, no first; read the first few parts (the first part is actually the file on the hard disk) according to the requirements of other parts, and then send them to the network; the other part obtains a new piece of data from the network and stores it on the hard disk. Storage and storagewrapper correspond to _ singletorrent one by one. Choker: Blocking management class. It is defined in BitTorrent/choker. py. It is used to determine the upload blocking policy, that is, which connections are blocked in the current connection. Corresponds to _ singletorrent. Measure: Speed calculator. It is defined in BitTorrent/currentratemeasure. py, and its function is to calculate the speed. Several measure objects are defined in _ singletorrent to calculate various rates (such as uploads and downloads ). Ratemeasure: it is also a speed calculator. It is defined in BitTorrent/ratemeasure. in py, unlike measure, it can input a parameter indicating the number of bytes left during initialization. Therefore, it has another function, that is, according to the current rate, estimated remaining time. _ Singletorrent defines a ratemeasure. Piecepicker: block selector. It is defined in BitTorrent/piecepicker. py to make a decision on the next download part. It corresponds to _ singletorrent. Downloader: Download The Working manager. It is defined in BitTorrent/Downloader. py to manage all download tasks in this subtask. Because the download process of a seed file has to deal with many peer-to-peer clients, several connections need to be established. Corresponds to _ singletorrent. Encoder: Connection Manager. It is defined in BitTorrent/encoder. py to manage all connections in the task of this seed file (whether actively connected to other peer customers or other peer customers connected to the local), one-to-one correspondence with _ singletorrent. Connection: connection. Defined in BitTorrent/connecter. py. This object corresponds to a connection. Therefore, a _ singletorrent contains several connection objects (the encoder is responsible for unified management ). Singledownload: single download. It is defined in BitTorrent/Downloader. py and corresponds to the download in a connection. It corresponds to the connection and is generated by the downloader object (Downloader. make_download). Every time a new connection is established, encoder will save the connection and generate a singledownload object. Upload: A single upload. It is defined in BitTorrent/Downloader. py and corresponds to the upload in a connection. Like singledownload, it corresponds to connection one by one. Each time a new connection is established, it is generated by encoder. Bitfield: a bitmap object. It is defined in BitTorrent/bitfield. py to represent a bit array. It is typically used to indicate the number of local files that are not downloaded during the current download process. In two places, storagewrapper stores the local block ownership information and singledownload stores the block ownership information of others (to determine whether to download the information from other users in the future ). Rerequester: Tracking request generator. It is defined in BitTorrent/rerequester. py to deal with the tracing server to obtain peer-to-peer customer information. Corresponds to _ singletorrent. Downloaderfeedback: Download the task status information collector. It is defined in BitTorrent/downloaderfeedback. py. It provides an interface for collecting the status information of download tasks, and can collect and display the status information to users. When a GUI program or other interface program calls the information collection function of _ singletorrent, it still needs to deal with the object (see the implementation of the _ singletorrent. get_status function ). Corresponds to _ singletorrent.

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.