Disclosure of Invention
The technical problem to be solved by the invention is to provide a peer-to-peer network system structure with strong scalability and a realization method thereof.
In order to solve the technical problems, the invention is realized by the following technical scheme:
a peer-to-peer network system, comprising: a resource network and a regional network; the resource network is a sub-network formed by all resource nodes; the regional network is a sub-network formed by all resource nodes and common nodes in the same geographic region;
the resource node is a node sharing a large amount of resources in a network, and the type of node generally has longer online time, better processing capacity and higher network bandwidth, and comprises a data server and the like deployed in the network; the type node maintains the connection of a plurality of other resource nodes similar to the shared resource theme of the node, the nodes are called friend nodes of the node, and also maintains the connection of a plurality of other resource nodes which are close to the geographical position of the node (including a local area network and an adjacent area network), the nodes are called neighbor nodes of the node;
the common nodes are other nodes except resource nodes in the network, and the type of nodes generally share less resources, have shorter online time and lower processing performance and network bandwidth; the type node maintains a plurality of connections with other resource nodes and common nodes in the same area network, and the nodes are called neighbor nodes of the node.
The construction method of the peer-to-peer network system structure comprises the following steps:
(1) a method for searching and maintaining neighbor nodes by a common node, wherein,
the steps of searching the neighbor node by the common node are as follows:
step a: the common node A determines the number of resource nodes and the number of common nodes which can be maintained according to the bandwidth and the processing capacity of the common node A;
step b: the common node A constructs a 'Find _ Neighbor' message and sends the TTL of the message1(TTL is the survival Time of the message, Time-to-Live) is set to a smaller numerical value, and then the message is sent to all nodes adjacent to the message in the physical network;
step c: the node receiving the 'Find _ Neighbor' message firstly checks whether the area number of the area network where the node is located is the same as the area number of the initiating node, if so, a response message is sent to the node A, meanwhile, the node can also forward the received 'Find _ Neighbor' message to all nodes adjacent to the node in the physical network, and the step c is repeated by all the adjacent nodes receiving the forwarded 'Find _ Neighbor' message;
step d: when the initiating node A receives the response message, checking the type of the response node, checking whether the number of the neighbor nodes of the corresponding type maintained by the initiating node A meets the requirement, if not, listing the node in a neighbor node list, otherwise, directly ignoring the message;
step e: the initiating node A checks whether the number of the Neighbor nodes reaches the requirement after sending the 'Find _ Neighbor' message for a period of time, if so, the initiating node A finishes searching the Neighbor nodes, and if not, the initiating node A waits for a period of time randomly and then sends a 'Find _ Neighbor' message (the message TTL)2Is set to be specific TTL1Larger value) to make its number of neighbor nodes meet the requirements.
The steps of the ordinary node for maintaining the neighbor node are as follows:
step a: the common node A sends an 'Is _ Live' message to all the neighbor nodes of the common node A at regular time, the neighbor nodes immediately send back an 'I _ am _ Live' message after receiving the message, and if the node A Is in continuous TSurvival of the human bodyIf the I _ am _ Live message returned by the neighbor node is not received within the time, the node A judges that the neighbor node is failed;
step b: the common node A periodically counts the previous continuous time TStatistics ofThe number of times that all neighbor nodes in the network successfully respond to the resource query message is counted, and partial neighbor nodes with the lowest response query frequency are selected, for example, 1/9 neighbor nodes occupying the total number of neighbor nodes of the node with the lowest response query frequency can be selected;
step c: the common node A gives up the connection of the failed neighbor node and the selected neighbor node with lower response query frequency, and re-executes the step of searching the neighbor node to supplement the corresponding number of new neighbor nodes;
(2) a method for searching and maintaining neighbor nodes and friend nodes by a resource node, wherein,
the steps of searching the neighbor node by the resource node are as follows:
step a: the resource node B determines the number of neighbor nodes which can be maintained according to the factors such as the bandwidth and the processing capacity of the resource node B;
step b: resource management systemThe source node B constructs a 'Find _ Neighbor' message and sends the TTL of the message3Setting the message to a proper value, and then sending the message to all nodes adjacent to the message in the physical network;
step c: the node receiving the 'Find _ Neighbor' message firstly checks whether the node is a resource node, if so, a response message is sent to the node B, and meanwhile, the node can forward the received 'Find _ Neighbor' message to all nodes adjacent to the node B in a physical network;
step d: when the initiating node B receives the response message, checking whether the number of the neighbor nodes meets the requirement, if not, listing the node in a neighbor node list, otherwise, directly ignoring the message;
step e: and the initiating node B checks whether the number of the Neighbor nodes of the initiating node B meets the requirement after sending the 'Find _ Neighbor' message for a period of time, if so, the initiating node B finishes searching the Neighbor nodes, and if not, the initiating node B randomly waits for a period of time and then re-executes the steps a to d until the number of the Neighbor nodes meets the requirement.
The step of maintaining the neighbor node by the resource node is as follows:
step a: the resource node B sends an 'Is _ Live' message to all neighbor nodes at regular time, the neighbor nodes immediately send back an 'I _ am _ Live' message after receiving the message, and if the node B Is in continuous TSurvival of the human bodyIf the I _ am _ Live message returned by the neighbor node is not received within the time, the node B judges that the neighbor node is failed;
step b: and the resource node B abandons the connection of the failed neighbor node and re-executes the step of searching the neighbor node so as to ensure that the number of the neighbor nodes reaches the requirement.
The steps of searching friend nodes by the resource nodes are as follows:
step a: the resource node B determines the number of the friend nodes which can be maintained as N friend nodes according to the factors such as the bandwidth and the processing capacity of the resource node B;
step b: the resource node B constructs a 'Find _ Friend' message and sends the TTL of the message4Set to compare TTL3The message is sent to all nodes adjacent to the message in the physical network after the message has a larger value;
step c: the node receiving the Findfriend checks whether the node is a resource node, if so, the similarity of the shared resource theme of the node and the shared resource theme of the node B is calculated, if the similarity is greater than a set threshold, a response message is sent back, otherwise, the node does not send the response message; in addition, the node also forwards the message to all nodes adjacent to the node in the physical network;
step d: when the resource node B receives the response message, checking whether the number of the friend nodes maintained by the resource node B reaches the specified number, if not, adding the node sending the response message into the friend node list, and if so, directly ignoring the response message;
step e: and the resource node B checks whether the number of the Friend nodes meets the requirement after sending the 'Find _ Friend' message for a period of time, if so, the process of searching for the Friend nodes is ended, and if not, the resource node B waits for a random period of time and then repeatedly executes the steps a to d until the number of the Friend nodes meets the requirement.
Fourthly, the steps of maintaining the friend node by the resource node are as follows:
step a: the resource node A sends 'Is _ Live' message to all friend nodes of the resource node A at regular time, when the node receives the 'Is _ Live' message, the node immediately replies the 'I _ am _ Live' message, if the node B Is in the specified continuous TSurvival of the human bodyIf the 'I _ am _ Live' message returned by the friend node is not received within the time, the friend node is judged to be invalid;
step b: the resource node B gives up the connections of the friend nodes that have failed, and at the same time, performs the step of finding friend nodes again to supplement the corresponding number of new friend nodes.
The maintenance method of the peer-to-peer network system structure comprises the following steps:
(1) the node resource issuing and canceling method is characterized in that a common node does not need to issue own resources, so that the node of the type has no resource issuing and canceling process, and only the resource issuing and canceling method of the resource node is introduced, and the specific steps comprise:
step a: the resource node B recalculates the theme of the shared resource after the new resource releases or cancels a plurality of resources;
step b: the resource node B sends the updated theme to all friend nodes, after receiving the new theme, the friend nodes perform similarity calculation on the theme and the theme of the shared resource, if the result is greater than a set threshold, the friendship between the nodes is continuously maintained, otherwise, the node B abandons the connection with the corresponding friend node;
step c: the resource node B again performs the step of finding friend nodes to supplement the corresponding number of new friend nodes.
(2) The method for joining and exiting the network by the node specifically comprises the following steps:
step a: after a new node C joins in a P2P network system, the node can determine that the node belongs to a resource node or a common node according to the quantity of shared resources, and then establishes and maintains a neighbor node and a friend node according to the type of the node to which the node belongs and corresponding steps;
step b: when the node C needs to quit the network system, the node sends an 'Exit _ Net' message to all friend nodes and nodes which list the node C as neighbor nodes;
step c: the node receiving the message abandons the connection with the node C and executes the step of searching for the neighbor node or the friend node so as to supplement the corresponding number of new neighbor nodes and friend nodes;
step d: if the node C Is suddenly paralyzed and does not send the 'Exit _ Net' message to all friend nodes and neighbor nodes in time, the friend nodes and the neighbor nodes can judge that the node C fails within a certain time by using the 'Is _ Live' message sent between the friend nodes and the neighbor nodes at fixed time, and the neighbor nodes and the friend nodes can automatically abandon the connection between the node C and the node C.
The resource inquiry process based on the peer-to-peer network system comprises the following steps:
step a: the inquiry initiating node checks the node type of the inquiry initiating node, if the node is a resource node, the inquiry initiating node executes the step b; if the node is a common node, it sends a resource inquiry message to the common nodes in all its neighbor nodes, the common node receiving the inquiry message executes step c, and at the same time, the inquiry initiating node also sends a resource inquiry message to the resource nodes in all its neighbor nodes, the message contains an attribute value: d, maximum forwarding times, wherein the attribute value is used for controlling the maximum forwarded times of the query message, and the resource node receiving the query message executes the step d;
step b: the resource node firstly constructs a resource inquiry message, and the message contains an attribute value: the node checks whether the resource to be inquired is similar to the theme of the shared resource of the node, if so, the node sends a new inquiry message to all friend nodes of the node, if not, the node sends the inquiry message to all neighbor nodes of the node, and the resource node receiving the inquiry message executes the step d;
step c: when the common node receives a resource query message, the node searches a target resource in the stored resources, and if the target resource is found, a message of query hit is sent back to the resource query initiating node; if not, the node ends the resource positioning process;
step d: when a resource node receives a resource query message, whether a target resource exists in the stored resources of the resource node is checked firstly, if yes, a message hit by the query is sent back to a resource query initiating node, if not, the attribute value of the maximum forwarding times in the message is reduced by one, whether a new numerical value is zero or not is judged, if yes, the node finishes a resource positioning process, if not, whether the theme of the resource to be queried is similar to the theme of the shared resource of the resource node is further judged, if yes, the new query message is sent to all friend nodes of the resource node, otherwise, the query message is sent to all neighbor nodes of the resource node; and d, the resource node receiving the query message repeatedly executes the step d.
The invention has the advantages that the common node in the whole P2P network only establishes the neighbor relation with other resource nodes and common nodes in the same area network, and the resource node can establish the friend-neighbor relation with the resource nodes of other area networks. The structure limits the maintenance of the topological relation among a plurality of unstable (short online time) nodes in the P2P network to a local area, and meanwhile, resource nodes which are stable (long online time) and have more shared resources in each area network are used for establishing the association among different area networks. The resource query process based on the topological structure is as follows: the query initiating node firstly checks whether the target resource exists in the neighbor node in the same area network, and if the target resource does not exist in the neighbor node, the query initiating node forwards the query message to the resource node with the similar theme with the target resource in the resource network for rapid positioning. As can be seen from the above process, the peer-to-peer network system structure is beneficial to querying a target resource nearby and providing a service nearby, and in addition, if the target resource is searched by a node in the non-local area network, the node where the target resource is located is stable and has a higher bandwidth, which provides a guarantee for efficient transmission of subsequent resources.
Detailed Description
The invention is further described with reference to the following figures and specific embodiments.
Referring to fig. 1, fig. 1 is a schematic diagram of a peer-to-peer network structure according to the present invention. The whole P2P network is composed of two types of nodes, one type is a resource node, which is a node sharing a large amount of resources in the network, the type of node generally has longer online time, better processing capability and higher network bandwidth, and the type of node comprises a data server deployed in the network and the like; the other node is a common node, which is a node other than the resource node in the network, and the node of the type generally shares less resources, has shorter online time and lower processing performance and network bandwidth. The resource nodes and the common nodes form the whole P2P network. Each resource node and each common node are randomly allocated with an identifier, and meanwhile, the node is also allocated with an area number according to the physical position. In this way, the following two seed P2P network spaces are partitioned by the definition of the area number and node type of the node. The method comprises the following specific steps:
resource network: a P2P sub-network formed by all resource nodes, which is indicated by a dotted oval in FIG. 1 as a resource network;
area network: a P2P sub-network formed by all resource nodes containing the designated area number and common nodes, each indicated by a solid oval in fig. 1 is an area network;
the resource node maintains a plurality of other resource node connections similar to the shared resource theme of the node, the nodes are called friend nodes of the node, and also maintains a plurality of other resource node connections close to the geographical position of the node, and the nodes are called neighbor nodes of the node. The common node maintains a plurality of connections with other resource nodes in the same area network and the common node, and the nodes are called neighbor nodes of the node.
The P2P network mainly comprises three steps of a construction method of a peer-to-peer network system structure, a maintenance method of the peer-to-peer network system structure and a resource query method based on the same structure of the peer-to-peer network.
The construction method of the peer-to-peer network system structure comprises the following steps: (1) a method for searching and maintaining neighbor nodes by common nodes, and (2) a method for searching and maintaining neighbor nodes and friend nodes by resource nodes.
(1) Method for searching and maintaining neighbor node by common node
Referring to fig. 2, fig. 2 is an example peer-to-peer network. When a node a just joins a regional network I, the node does not have any Neighbor node or friend node, firstly, the node determines that the type of the node a is a common node according to the characteristic that the number of shared resources of the node a is small, then the node a constructs a 'Find _ Neighbor' message and sends the message to all nodes C and d adjacent to the node a in a physical network, after the nodes C and d receive the 'Find _ Neighbor' message, the region number of the regional network where the node a is located is found to be the same as the region number of an initiating node, then a response message is sent to the node a, meanwhile, the nodes C and d also respectively forward the received 'Find _ Neighbor' message to all nodes b, f and G adjacent to the node a in the physical network, and then the nodes b, f and G respectively repeat the previous operations of the nodes C and d, and the process is continued until the TTL value in the 'Find _ Neighbor' message is reduced to zero. After the node a sends the 'Find _ Neighbor' message, the node a waits for response messages sent back by other nodes, and lists the corresponding nodes in a Neighbor node list, after the node a sends the 'Find _ Neighbor' message for a period of time, the node a checks whether the number of the Neighbor nodes of the node a meets the requirement, if the number of the Neighbor nodes meets the requirement, the process of searching for the Neighbor nodes is finished, if the number of the Neighbor nodes does not meet the requirement, the node a waits for a random period of time and then initiates the step of searching for the Neighbor nodes again until the number of the Neighbor nodes meets the requirement, and the Neighbor nodes determined by the node a finally are supposed to comprise: nodes b, d, C and G.
In the process of maintaining the neighbor nodes of the node a, the nodes a and b, d, C and G send messages to each other periodically to declare that the nodes a and b are still in the network, and if the node b does not send back messages within the specified time, the node a considers that the node b has failed. In addition, the node a also counts the times that all neighbor nodes successfully respond to the resource query message in the previous continuous time, and selects a plurality of neighbor nodes with the lowest response query frequency, if the selected node is d, the node a interrupts the connection between the node a and the nodes b and d, and re-searches for new neighbor nodes for supplement, and if the found new neighbor nodes are f and h, the current neighbor node of the node a is updated as: nodes f, h, C and G.
(2) Method for searching and maintaining neighbor node and friend node by resource node
Referring to fig. 2, when node J just joins regional network II, the node does not have any Neighbor node or friend node, first, it determines that its category is resource node according to its characteristic of large amount of shared resources, then node J constructs "Find _ Neighbor" message and sends it to all nodes G, I and m adjacent to itself in the physical network, after node G, I and m receive "Find _ Neighbor" message, it checks whether its type is resource node, since node G and I Find itself to be resource node, they send response message to node J, node m is not resource node and therefore does not send response message to node J, furthermore, node G, I and m also forward the received "Find _ Neighbor" message to all nodes d, h, L and o adjacent to itself in the physical network, after that, node d, h, L and o repeat node G, h, L and o respectively, I and m just before, the above process continues until the TTL value in the "Find _ Neighbor" message is reduced to zero. After node J sends the 'Find _ Neighbor' message, it waits for the response message sent back by other nodes, and lists the corresponding node in its Neighbor node list, after sending the 'Find _ Neighbor' message for a period of time, it checks if the number of its Neighbor nodes reaches the requirement, if it reaches, it ends the process of searching Neighbor nodes, if it does not reach, it waits for a random period of time and initiates a 'Find _ Neighbor' message again, the TTL value in the message is bigger than before until the number of its Neighbor nodes reaches the requirement, it is assumed that the last determined Neighbor nodes of node a include: nodes b, d, C and G.
In the process of maintaining the neighbor nodes of the node a, the nodes a and b, d, C and G send messages to each other periodically to declare that the nodes a and b are still in the network, and if the node b does not send back messages within the specified time, the node a considers that the node b has failed. In addition, the node a also counts the times that all the neighbor nodes successfully respond to the resource query message in the previous continuous time, and selects a plurality of neighbor nodes with the lowest response query frequency, if the selected node is d, the node a interrupts the connection between the node a and the nodes b and d, and re-searches for new neighbor nodes for supplement, and if the found new neighbor nodes are f and h, the neighbor nodes of the node a are updated as follows: nodes f, h, C and G.
When a resource node J searches for Friend nodes, firstly, the node J constructs a 'Find _ Friend' message, the TTL of the message is set to be a larger value, then the message is sent to all nodes G, I and m adjacent to the node J in a physical network, after the node m receives the 'Find _ Friend' message, the node does not respond to the message because the node m is not a resource node, after the nodes G and I receive the 'Find _ Friend' message, the node M firstly confirms that the node is the resource node, then calculates the similarity of the shared resource theme of the node M and the shared resource theme of the initiating node J, and the similarity of the shared resource theme of the node M and the shared resource theme of the initiating node J is larger than a set threshold, and then returns a response message, in addition, the nodes G, I and m respectively forward the message to all nodes d, h, L and o adjacent to the node M in the physical network, and the nodes d, h, L and o repeat the nodes G, G and m, I and m, the above process continues so far until the TTL value in the "Find _ Friend" message is reduced to zero. After node J sends the 'Find _ Friend' message, it waits for the response sent back by other nodes, and lists the corresponding node in its Friend node list, after sending the 'Find _ Friend' message for a period of time, it checks if the number of Friend nodes reaches the requirement, if it reaches, it ends the Friend node searching process, if it does not reach, it waits for a random period of time and sends a 'Find _ Friend' message again, the TTL value in the message is larger than before until the number of Friend nodes reaches the requirement, it is assumed that the last Friend node searched by node J includes: nodes G, I and L.
In the process of maintaining the friend node of the node J, messages are periodically sent between the node J and the friend node to declare that the node J is still in the system, if the node J does not receive the message sent by a friend node (assuming that the node is I) within the specified continuous time, the friend node I is failed, and the node J abandons the connection of the node I. Meanwhile, node J would again perform the step of finding friend nodes to supplement the corresponding number of new friend nodes, assuming that new friend nodes are found as C, so that the updated friend nodes of node J include: nodes C, G and L.
The maintenance method of the peer-to-peer network system structure comprises the following steps: (1) a node resource release and withdrawal method, and (2) a node joining and quitting network method.
(1) Node resource publishing and revoking method
Referring to fig. 2, after releasing or revoking a plurality of new resources, the resource node J recalculates the theme of its own shared resource, and then sends the updated theme to all the friend nodes C, G and L, and after receiving the new theme, the friend node performs semantic similarity calculation on the theme and the theme of its own current shared resource, and if the calculation result is greater than the set threshold, the friend relationship between the nodes is continuously maintained, otherwise, the friend node abandons the connection with the node J. Meanwhile, the resource node J performs the step of searching friend nodes again to supplement a corresponding number of new friend nodes;
(2) method for node joining and exiting network
Referring to fig. 2, after a new node joins the P2P network, the node determines that the node belongs to a resource node (e.g., node J) or a common node (e.g., node a) according to the amount of its shared resources, and then establishes and maintains a neighbor node and a friend node according to the type of the node. When a node a or J needs to Exit the P2P network, the node sends an 'Exit _ Net' message to all its neighbor nodes and friend nodes (if any), the node receiving the message abandons the connection with the node a or J and searches for new neighbor nodes or friend nodes, if the node a or J fails to send the 'Exit _ Net' message to all its neighbor nodes and friend nodes (if any) in time due to sudden paralysis, the nodes can use the 'Is _ Live' message sent between them and the nodes a and J to judge that the node a or J fails in a certain time range, and then the neighbor nodes or friend nodes can automatically abandon the connection with the nodes a and J.
The resource query method based on the same structure of the peer-to-peer network specifically comprises the following steps:
assuming that the relationship between nodes in the area network I and the area network II in the example peer-to-peer network of fig. 2 and the information of shared resources are as shown in fig. 3, when a common node a in the area network I needs to obtain a resource R1_1, it only needs to send a resource query message to all its neighboring nodes, and nodes e and C will return the message hit by the query to the node a. When a common node a in a local area network I needs to search a resource R1_4, firstly, the node a sends a resource query message to all neighbor nodes of the node a, since the neighbor nodes b, e and C do not have target resources, the neighbor nodes do not send query responses to the node a, the resource node C finds that the query resource is similar to the theme R1 of the shared resource of the node C, then the attribute value of the maximum forwarding times in the query message is subtracted by 1 and then forwarded to the friend nodes K and J, when the resource nodes K and J receive the query message, the resource nodes K and J find that the node a has the target resources, and then the two nodes send a query hit message to the node a. When a resource node J in a regional network II needs to search a resource R2_2, the resource node J finds that the theme of the resource to be searched is different from the theme of the shared resource of the resource node J, then sends the query message to neighbor nodes I and L, and when the resource node L receives the query message, finds that the resource node J has the resource, then the node L sends a message of query hit to the node J.