Reputation Mechanism in eMule
Reputation mechanisms play an important role in P2P systems. To make users more willing to share their resources, some mechanisms are required to enable more incentives for users who contribute more to the entire P2P system.
In eMule, the incentive mechanism design scheme is the most intuitive one such as tit-for-tat. The significance of this solution is that if others are nice to you, then you are also nice to others.
The following describes the actual implementation. The cclientcreditslist and cclientcredits classes are responsible for the credit mechanism in the eMule.We can see the relationship between the list and elements again.,
You do not have to repeat those languages. Credibility-related information must be permanently saved to make sense. Therefore, cclientcreditslist provides loadlist and
Savelist method. We also noted that the cclientcredits class can be created using the creditstruct structure, while the creditstruct structure only
Contains static information. This mainly refers to the upload volume and download volume.
The credibility mechanism information must be reliable, and eMule adopts the digital signature method to achieve this. Crypto ++ provides functions related to Digital Signature Verification for eMule.
Yes. When cclientcreditslist is created, it loads its own public key and private key. If not, a pair is created. Cclientcreditslist contains
The information is signed by other people, so it is more convincing. In actual use, you must save the information and your private key. After re-installing eMule, you should back up the configuration file directory first, so that you can keep your accumulated credibility.
Download task is the expression of some files
The cpartfile class is the class used in eMule to represent a download task. It can also be seen from its name that this is an unfinished file. When a download task is created
EMule will create two files in the download directory, with three digits plus the suffix part files, such as 001. Part, 002. Part, etc. Add the same number
The. Part. Met file indicates the metadata of the corresponding file. The part file is created in the same size as the original file. After the download is complete, the file name is changed to its original name. Fact
Such as the name of the file, the modification date, and so on are all in the corresponding. Part. Met Meta File .. Part. Met also contains the parts of the file that have been downloaded
Information.
In the cpartfile class, gap_struct is used to indicate the download status of a file. A gap_struct is a pitfall, indicating the offset from the number of bytes to the number of bytes of the file. The download process is a process of continuous pitfalls. The cpartfile class has a member variable named "gaplist", which lists the current pitfalls of the file. The main requirement is that when the middle part of the pit is filled, one pit is converted into two pits. The list of pitfalls will also be saved in. Part. Met.
Cpartfile class code is huge, but this is required. First, it is possible to create a file from the search file csearchfile. This occurs when the user searches for the file
It occurs when you click Download next to the desired file. Created from a string containing an ed2k link, it extracts information from the ed2k link and creates a cpartfile. The remaining one,
After the eMule program is restarted, the previous download task is restored. In this case, you need to download the. Part and. Met files in the directory. In addition, it also needs to constantly process the downloaded data, in order
Reduces disk overhead and uses the requested_block_struct structure to store written data. It maintains a list of cupdownclients internally. If you know a new source information of the file, a corresponding cupdownclient will be created. The latter is the class with the largest amount of code in eMule. It also displays its status in color la s for the GUI.
The above mentioned Aich mechanism is of great help to ensure the correctness of the downloaded files and minimize repeated transfers. During the download process, this mechanism often checks the downloaded data.
Finally, let's mention its process method. This method is a kind of polling mechanism adopted by eMule to minimize the use of threads. The process side is also available in many other classes.
Method, this method is to do something related to daily operations, such as checking the status of each client linked to download the file, and sending download requests to them.
Download task queue
Cdownloadqueue is the download queue class. The project in this queue is the cpartfile pointer. Therefore, like many other List classes in eMule
It is enough to add, query, and delete elements in this list. For example, you can query the file based on its hashid or index. Cdownloadqueue is the same
To complete some statistical work.
Unlike other List classes, the information of all its elements is not stored in a file in a centralized manner, but corresponds to each download task. It must be stored separately in a metadata file (. part. met)
So when the class is initialized, it needs to find all possible download paths, find all. Part. Met files from those paths, and try to use these files to generate
Cpartfile class, and add these cpartfile classes correctly generated through the. Part. Met file to your own list. Similarly, when you exit, the metadata of all download tasks
Information is also saved on your own and will not be merged into a file.
The main task of the Process Method in cdownloadqueue is to call the process method in the cpartfile class in its list.
The download statistics are updated after each round of process. Here we can also see the significance of the Process Method in eMule, that is, a process that needs to be executed frequently.
And all the process methods must be executed in sequence. Therefore, you can reduce many problems such as multi-thread synchronization. EMule already exists
The use of Multithreading is minimized, but in many places, multithreading is inevitable and will not be excluded.
Upload task queue
Cuploadqueue is an upload queue class. This list class only contains a list of cupdownclient elements. It differs greatly from other List classes
The stored information does not need to be persistent, that is, you do not need to remember who you are uploading the file after the current eMule exits, and then continue to pass the information to them the next time it goes online, this is meaningless in most cases.
.
The upload queue list contains two lists: Upload list and queue list. When a new download request is received, it adds the corresponding clients to the queue list first and then adds them to the upload list as needed. Here, the Credibility Mechanism will have an impact on this.
The process method of cuploadqueue is relatively simple, that is, to send data to all the clients in the upload queue in sequence, and the clients in the queue will not get this opportunity. In addition, it also needs to complete some upload statistics.
In addition, we also need to note that in the cuploadqueue constructor, a timer with an interval of 100 milliseconds is created. This timer is required by all the above processes.
Basic. We can see this point by looking at its uploadtimer. This is filled with the execution of the process methods of various classes, including some of the classes we mentioned earlier, but not mentioned
Their process method, because it is too simple, basically just updates the information to be saved.
Cupdownclient class with the largest amount of code in eMule
The role of the cupdownclient class is to logically representOther client informationIt is the class with the largest amount of code in eMule.
We noticed that the header file of updownclient. H is defined, but there is no corresponding cupdownclient. cpp, and its implementation is scattered
Baseclient. cpp, downloadclient. cpp, peercacheclient. cpp, uploadclient. cpp, and
In urlclient. cpp.
Baseclient. cpp implements some basic functions of this class, including obtaining and setting basic status information, and processing and sending various requests as required. Here, the logical implementation
The cupdownclient class does not accept or send messages from the network. It only provides interfaces for processing various requests and constructs corresponding
Packet and send it to the corresponding network socket.
Downloadclient. cpp implements download-related functions, including sending various download requests and receiving corresponding data. There is also an a4af mechanism, which is
One mechanism in eMule, because a client can only request the same file from another client at the same time. In this way, for many download tasks (cpartfile ),
Their source (that is, the client of this file) partially overlaps. If other download tasks are downloading from this source, the current download task cannot be downloaded from this source. However
EMule allows you to manually control the download task. For example, you can differentiate the download task priority so that you can switch one source from another download task. A4af is actually ask
For another file.
In uploadclient. CPP, the upload function is implemented, that is, the download request is accepted and the corresponding file block is generated and sent out.
Peercacheclient. cpp implements peercache-related functions. peercache is a technology developed by joltid, which allows you
You can quickly upload or download some files (or part of the files) from snapshot servers provided by the ISP. The advantage of this technology is that it can reduce the bandwidth consumption of backbone networks, the parts must be taken on the backbone network.
The traffic is transferred to the Internal ISP. Of course, this function requires ISP cooperation. If the ISP provides this service, eMule will use it to reduce the bandwidth consumption of the backbone network.
Urlclient. cpp uses http to package the original eMule Protocol so that it can traverse more network firewalls as much as possible.
General Summary of Emule
There are many other classes in eMule, which make eMule more powerful and complete. There are many classes not mentioned above, but it does not mean it does not work. In addition, real-time is the one mentioned above.
Class is just a general introduction, and some details of their mutual cooperation are not reflected. However, these details can be easily grasped by understanding their general functions. As for the GUI Design,
It eventually corresponds to the data of a function implementation class.
For the communication protocol in eMule, we only need to briefly describe the format of its data packet, but we do not have to describe each of its
The meaning of the packet corresponding to opcode, because I think this is unnecessary. After knowing the format of the communication protocol and the location of the code that processes them, you can easily track the cause and effect of a message.
Analyze the entire communication protocol.
Here, I will mention other classes used in eMule and their functions. We can see that many classes can be simplified if you just want to find and download files.
Because of their existence, eMule functions are improved. Cipfilter, IP address filter, by identifying various types of IP address filtering information, it can put the network that does not want to connect
Addresses are filtered out. All locations in the eMule that need to connect to the network are used to filter data in a unified manner. Cwebserver can open a web server locally, and then you can use a browser
To control your eMule. Cscheduler supports scheduled download of download tasks. Cpeercachefinder is the master control of the peercache technology mentioned above
Class. In addition, eMule also has a built-in IRC client. A major member function is a static cpartfileconvert class, which can be used to convert files downloaded from other versions of the donkey.
Change. It even provides a class of carchiverecovery that automatically processes zip and RAR.
The kademlia network is a very important part of the eMule. Therefore, we put this part out separately and describe it after this summary.