In the analysis section above, the third step of taskmain is to enable the Topology class to analyze topology_file and start the Network object. This time, I will mainly introduce the detailed process of this part. The main content includes the Mechanism Analysis of the Topology class and sub-class Euclidian Topology class, Failure Model class and Network Class interaction. After understanding this, We will basically clarify the P2PSim startup mechanism. By convention, I have provided a general flowchart of the process involved here. 650) this. width = 650; "onclick = 'window. open (" http://blog.51cto.com/viewpic.php?refimg= "+ This. src) 'style = "border-bottom: 0px; border-left: 0px; border-top: 0px; border-right: 0px "title =" "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1R2163944-0.jpg "Height =" 788 "1011? = ""/> This part of the call is caused by Topology: parse (topology_file) in taskmain function. In the pase function, the name of topology is first read from topology_file, such as the Euclidian topology and the corresponding failure model. As for the failure model, it seems that it is used to set the packet loss policy in data transmission. This is not my interest, so I am too lazy to analyze it carefully. If this parameter is not specified in topology_file, an nullfailure model without packet loss is provided by default. In topology and failure models, their constructors do nothing special. The top and fm objects are used as parameters to construct Network object instances. In the structure of the Network object, the topology and failure models are saved to the Network object. In the future, only Network instances will be available for access. Finally, thread is called in the Network object structure to run the run function as a task. In this function, the Network instance opens a mechanism for communication between tasks in channellibtask), and then continuously reads the Node (peer) information from the topology object from this channel. Save it to your _ nodes member. This member is a map of IPaddress and Node pointer. Finally, Topology: parse) calls the parse of the topology object to complete the parsing of the remaining part of topology_file. Note that the top pointer of the toplogy object is a subclass object of the Topology class, such as an object of the Euclidian class. Next, we will take the Euclidian topology as an example.
IPaddress x, y
To parse the location of the peer in the space, and use ipaddress to identify the peer. Parse each record and construct the object of a Node class subclass in the factory mode. Besides saving it in the _ nodes member, it is also a map from IPaddress to node ), the run function sent to the Network object through the channel. The yellow and green arrows in the figure indicate the contact.
This article is from the Nathan technical space blog, please be sure to keep this source http://nathanxu.blog.51cto.com/50836/247545