Detailed Description
To make the objects, technical solutions and advantages of the embodiments of the present invention more apparent, embodiments of the present invention will be described in detail below with reference to the accompanying drawings. However, it will be appreciated by those of ordinary skill in the art that numerous technical details are set forth in order to provide a better understanding of the present application in various embodiments of the present invention. However, the technical solution claimed in the present application can be implemented without these technical details and various changes and modifications based on the following embodiments.
A first embodiment of the present invention relates to a communication method, as shown in fig. 1, including the steps of:
s11: at least M addresses are acquired.
Specifically, only M addresses may be obtained, or more than M addresses may be obtained, where the specific form of the address is similar to the SHA1 hash value, and may be an integer as long as 160 bits, which is randomly generated, and it is very unlikely that the address has the same address as other nodes.
S12: and respectively and simultaneously searching nodes which can be communicated with each address in the M addresses within a first preset time length.
In this step, the search duration is set to be a first preset duration, nodes which can communicate with each address in the M addresses are searched respectively and simultaneously, the step of searching for the nodes which can communicate with each address is performed simultaneously, and when the search duration reaches the first preset duration, the search for the nodes which can communicate with each address is stopped. The first preset time duration may be set as required, and may be set to a value that does not affect the chat experience much, for example, 5 seconds, and M may be set as experience, as long as it is ensured that when a node communicable with each address of M addresses is searched separately and simultaneously within the first preset time duration, the number of communicable nodes searched by at least one address may meet the requirement of sending the first information to be transmitted and the reply information, for example, M is equal to 20, and at this time, 30% to 50% of the number of communicable nodes searched by an address may generally meet the requirement.
Specifically, "a node communicable with an address" may be understood as: and a node which is close to the address and is online, wherein the distance between the two nodes is not measured by means of physical distance and router hop number, and the distance d is defined as a binary bit-by-bit sum of the ID values of the two nodes, that is, assuming that the IDs of the two nodes are a and b respectively, the following steps are provided: d ═ a XORb. Each node can judge the distance between other nodes and the node according to the distance concept, when the value of d is large, the distance between the nodes is long, and when the value of d is small, the distance between the two nodes is very short. Both "distance" and "distance" are described herein as a logical measure, i.e., the distance is non-directional, i.e., the distance a to b is constant equal to the distance b to a.
In practical applications, the search process of the communicable node corresponding to each address is roughly as follows: a. screening a plurality of nodes closest to the target ID from a k-bucket of the query initiator by the query initiator, and simultaneously sending asynchronous query requests to the nodes; b. after receiving the request, the inquired node finds out a plurality of nodes which are known by the inquired node and are closest to the inquiry target ID from the k-bucket of the inquired node, and returns the nodes to the initiator; c. after receiving the return information, the initiator picks out a plurality of nodes which are not requested from all known nodes which are closer to the target again, and repeats the step 1; d. the steps are repeated continuously until the active nodes which are closer to the target than the k nodes currently known by the inquirer cannot be obtained; e. in the inquiry process, nodes which do not respond in time are immediately eliminated; the querier must ensure that the k most nodes ultimately obtained are all active.
S13: and selecting an address with the node number larger than a first threshold value from the M addresses as a first sending address, sending first to-be-transmitted information to a plurality of first nodes which can be communicated with the first sending address, and acquiring first reply information returned by the first sending address by the plurality of first nodes.
In this step, addresses may be sequentially fetched from M addresses according to a generation sequence of the M addresses, and it may be determined whether the number of nodes that can communicate with the addresses is greater than a first threshold, and the fetched number of nodes that can communicate with the addresses is taken as a first sending address until the number of nodes that can communicate with the addresses is greater than the first threshold, where the first threshold may be set as needed.
It is understood that, when the number of the addresses acquired in step S11 is greater than M, selecting the first sending address may be performed from all the addresses according to the generation sequence of the addresses, where there may be a case where the selected address has not searched for a node that can communicate with the selected address, and at this time, a batch of addresses needs to be loaded (i.e., the selected address has searched for a node that can communicate with the selected address), and the address may be used after the batch of addresses is loaded, and if a subsequent address is loaded, the subsequent address is ready for subsequent use, so that the subsequent use is not affected, and the waiting may not be performed.
After the first sending address is selected, the terminal sends first information to be transmitted to a plurality of first nodes which can be communicated with the first sending address, the first information to be transmitted is sent to a target address through the plurality of first nodes, and first reply information returned by the target terminal returns to the first sending address through an original path of the sending information so as to be received by the terminal.
Compared with the prior art, the embodiment of the invention searches the nodes which can be communicated with each address in the M addresses respectively and simultaneously in the first preset time length, and can be communicated with the M addresses, so that the number of the nodes corresponding to at least one address in the M addresses can be ensured to meet the requirement, the address with the number of the nodes larger than the first threshold value can be selected from the M addresses to serve as the first sending address, namely, the number of the nodes which can be communicated and correspond to the first sending address can meet the requirement, the reliability of message sending is ensured, the first preset time length does not need to be set to be overlarge to ensure that the number of the nodes is large enough, meanwhile, the nodes which can be communicated and correspond to each address in the M addresses are searched simultaneously, namely, the searched nodes are more and faster by utilizing the concurrent processing of the program, therefore, the searching of the communicable nodes corresponding to the M addresses can be completed only by spending the first preset time, the searching time of the nodes corresponding to the addresses is shortened, and the message transmission efficiency is improved.
A second embodiment of the present invention relates to a communication method. The second embodiment is substantially the same as the first embodiment, and mainly differs therefrom in that: in the second embodiment of the present invention, after searching for nodes communicable with each of the M addresses respectively and simultaneously within the first preset time period, the method further includes: associating and storing each address in the M addresses with the searched nodes which can communicate with the address; after the first reply information returned by the plurality of first nodes is obtained, the method further comprises: selecting an address with the number of other nodes larger than a first threshold value from the M addresses as a second sending address, and acquiring a plurality of second nodes associated with the second sending address; and sending second information to be transmitted to the plurality of second nodes, and acquiring second reply information of the second sending address returned by the plurality of second nodes. Each address in the M addresses is respectively associated and stored with the searched node which can be communicated with the address, so that the address and the associated node can be selected from the current M addresses during subsequent message sending, the node is not required to be searched every time the message is sent, and the message transmission efficiency is further improved.
As shown in fig. 2, the communication method in the present embodiment specifically includes the following steps:
s21: at least M addresses are acquired.
S22: and respectively and simultaneously searching nodes which can communicate with each address in the M addresses within a first preset time length.
S23: and associating and storing each address in the M addresses with the searched nodes which can communicate with the address.
Specifically, each address is respectively associated with the searched node capable of communicating with the address and stored, so that the associated node capable of communicating with the address can be found in the process of taking out the address for use subsequently, and because each address in the M addresses is stored, the remaining addresses after the message is sent at this time can be reserved for other messages to be sent subsequently for use.
S24: and selecting an address with the node number larger than a first threshold value from the M addresses as a first sending address, sending first to-be-transmitted information to a plurality of first nodes which can be communicated with the first sending address, and acquiring first reply information returned by the first sending address by the plurality of first nodes.
S25: and selecting an address with the number of other nodes larger than the first threshold value from the M addresses as a second sending address, acquiring a plurality of second nodes associated with the second sending address, sending second to-be-transmitted information to the plurality of second nodes, and acquiring second reply information returned by the plurality of second nodes to the second sending address.
In this step, addresses subsequent to the first transmission address may be sequentially extracted according to a generation order of the M addresses, and it may be determined whether the number of nodes communicable with the address is greater than a first threshold value, until the number of the extracted nodes communicable with the address is greater than the first threshold value, the extracted nodes are used as a second transmission address, then the terminal transmits second to-be-transmitted information to a plurality of second nodes communicable with the second transmission address, the second to-be-transmitted information is transmitted to the destination address via the plurality of first nodes, and second reply information returned by the destination terminal returns to the second transmission address via an original path of the transmitted information, and is received by the terminal.
Steps S21, S22, and S24 in this embodiment are similar to steps S11, S12, and S13 in the first embodiment, and are not repeated here to avoid redundancy.
Compared with the prior art, the method and the device not only ensure the reliability of message sending, reduce the searching time of the node corresponding to the address and improve the efficiency of message transmission; meanwhile, each address in the M addresses is respectively associated with the searched node which can be communicated with the address and stored, so that the address and the associated node can be selected from the current M addresses when subsequent messages are sent, the node is not required to be searched every time the messages are sent, and the message transmission efficiency is further improved.
A third embodiment of the present invention relates to a communication method. The third embodiment is substantially the same as the second embodiment, and mainly differs in that: in a second embodiment, after the searching for nodes communicable with each of the M addresses separately and simultaneously within the first preset time period, the method further includes: and associating and storing each address in the M addresses with the searched nodes which can communicate with the address. In the third embodiment of the present invention, after searching for nodes communicable with each of the M addresses respectively and simultaneously within the first preset time period, the method further includes: marking the addresses of which the number of nodes is greater than a first threshold value in the M addresses; and respectively associating and storing the marked address in the M addresses with the searched nodes which can communicate with the M addresses. And only the address with the node number larger than the first threshold value in the M addresses is associated with the corresponding node and stored, so that the space occupied by the memory is reduced.
As shown in fig. 3, the communication method in the present embodiment specifically includes the following steps:
s31: at least M addresses are acquired.
S32: and respectively and simultaneously searching nodes which can communicate with each address in the M addresses within a first preset time length.
S33: and marking the addresses of which the number of the nodes is greater than the first threshold value in the M addresses, and associating and storing the marked addresses in the M addresses with the searched nodes which can communicate with the addresses respectively.
In this step, the addresses may be sequentially fetched according to the generation sequence of the M addresses, and it is determined whether the number of nodes that can communicate with the addresses is greater than a first threshold, if so, the addresses are marked, and then all the marked addresses are associated with the nodes that can communicate with the addresses and stored.
S34: and selecting one address from the marked addresses as a first sending address, sending first to-be-transmitted information to a plurality of first nodes which can communicate with the first sending address, and acquiring first reply information returned by the first sending addresses by the plurality of first nodes.
In this step, since the marked addresses are addresses whose number of nodes is greater than the first threshold, selecting one address from the marked addresses as the first sending address ensures that the number of nodes communicable with the first sending address can meet the requirement, thereby ensuring the reliability of the terminal sending the first information to be transmitted to the plurality of first nodes communicable with the first sending address and the terminal subsequently acquiring the first reply information whose target address is returned to the first sending address via the plurality of first nodes.
S35: and selecting another address from the marked addresses as a second sending address, acquiring a plurality of second nodes associated with the second sending address, sending second to-be-transmitted information to the plurality of second nodes, and acquiring second reply information returned by the plurality of second nodes to the second sending address.
In this step, another address may be selected from the marked addresses as a second sending address according to the storage order of the marked addresses, and when the terminal subsequently needs to send another message, the terminal may send second to-be-transmitted information to a plurality of second nodes communicable with the second sending address and acquire first reply information of the destination address returned to the first sending address via the plurality of first nodes.
Steps S31, S32 in the present embodiment are similar to steps S21, S22 in the second embodiment, and are not repeated here to avoid redundancy.
Compared with the prior art, the method and the device for transmitting the message ensure the reliability of message transmission, reduce the searching time of the node corresponding to the address and improve the efficiency of message transmission; meanwhile, each address in the M addresses is respectively associated and stored with the searched node which can be communicated with the address, so that the address and the associated node can be selected from the current M addresses when subsequent messages are sent, the node is not required to be searched every time the message is sent, and the message transmission efficiency is further improved; and only the address with the node number larger than the first threshold value in the M addresses is associated with the corresponding node and stored, so that the space occupied by the memory is reduced.
A fourth embodiment of the present invention relates to a communication method. The fourth embodiment is substantially the same as the third embodiment, and mainly differs therefrom in that: in a fourth embodiment of the present invention, after the second transmission address is selected, the method further includes: acquiring the number of addresses of which the number of remaining nodes in the M addresses is greater than a first threshold value; if the number of the addresses is smaller than a second threshold value, nodes which can be communicated with each address in P addresses are searched respectively and simultaneously within a second preset time length, wherein the P addresses are not overlapped with the M addresses. If the number of the addresses is smaller than the second threshold value, the nodes capable of communicating with each address in the P addresses are searched respectively and simultaneously within the second preset time period, namely, when the number of the remaining available addresses is insufficient, the nodes capable of communicating with the next batch of addresses are searched in advance, so that the searched addresses can be directly acquired when the message is sent, the time for waiting for the addresses to search the nodes capable of communicating is saved, and the message sending efficiency is improved.
As shown in fig. 4, the communication method in the present embodiment specifically includes the following steps:
s41: at least M addresses and P addresses are obtained.
That is, only M addresses and P addresses needed to be used by two subsequent loads may be generated, or more addresses may be generated for subsequent use, that is, a plurality of batches of addresses needed to be loaded are generated at one time.
S42: and respectively and simultaneously searching nodes which can communicate with each address in the M addresses within a first preset time length.
S43: and marking the addresses of which the number of the nodes is greater than the first threshold value in the M addresses, and associating and storing the marked addresses in the M addresses with the searched nodes which can communicate with the addresses respectively.
S44: and selecting one address from the marked addresses as a first sending address, sending first to-be-transmitted information to a plurality of first nodes which can communicate with the first sending address, and acquiring first reply information returned by the plurality of first nodes to the first sending address.
S45: and selecting another address from the marked addresses as a second sending address, acquiring a plurality of second nodes associated with the second sending address, sending second to-be-transmitted information to the plurality of second nodes, and acquiring second reply information returned by the plurality of second nodes to the second sending address.
S46: the number of addresses remaining in the tagged address is retrieved.
In this step, the remaining number of addresses is specifically: the number of addresses of the marked addresses that are not used as sending addresses for messaging, i.e. the number of unused nodes is greater than the first threshold.
S47: and when the number of the addresses is smaller than a second threshold value, searching nodes which can be communicated with each address in the P addresses respectively and simultaneously within a second preset time length.
And when the number of the addresses is less than a second threshold, searching nodes which can communicate with each address in the P addresses respectively and simultaneously within a second preset time period, wherein the second threshold can be set according to needs, for example, the second threshold can be 5, that is, when the number of the remaining marked addresses is less than 5, searching nodes which can communicate with each address in the P addresses in the next batch is started.
Specifically, the second preset duration may be the same as or different from the first preset duration, P may be equal to or not equal to N, optionally, P ≧ 2, and the specific search process is similar to the foregoing one, and is not described herein again.
Steps S41, S42, S43, S44, and S45 in the present embodiment are similar to steps S31, S32, S33, S34, and S35 in the second embodiment, and are not described again to avoid redundancy.
Certainly, steps S41, S42, S43, S44, and S45 in this embodiment may also be similar to steps S21, S22, S23, S24, and S25 in the second embodiment, at this time, the number of remaining addresses in the M addresses may be obtained, and if the number of addresses is less than a third threshold, nodes that can communicate with each address in the N addresses are respectively and simultaneously searched in a third preset time period, where the N addresses are not overlapped with the M addresses, the third threshold may be set as needed, for example, the number of the third threshold may be 5, and the third preset time period may be the same as or different from the first preset time period, and is not repeated here.
Compared with the prior art, the method and the device for transmitting the message ensure the reliability of message transmission, reduce the searching time of the node corresponding to the address and improve the efficiency of message transmission; meanwhile, each address in the M addresses is respectively associated and stored with the searched node which can be communicated with the address, so that the address and the associated node can be selected from the current M addresses when subsequent messages are sent, the node is not required to be searched every time the message is sent, and the message transmission efficiency is further improved; in addition, only the addresses with the number of nodes larger than the first threshold value in the M addresses are associated with the corresponding nodes and stored, so that the space occupied by the memory is reduced; in addition, when the number of the remaining available addresses is insufficient, the communicable nodes of the next group of addresses are searched in advance, so that the searched addresses can be directly acquired when the message is sent, the time for waiting the addresses to search the communicable nodes is saved, and the message sending efficiency is improved.
A fifth embodiment of the present invention relates to a communication method. The fifth embodiment is substantially the same as the fourth embodiment, and mainly differs therefrom in that: in a fourth embodiment, the obtaining at least M addresses specifically includes: at least M addresses and P addresses are obtained. In a fifth embodiment of the present invention, the acquiring at least M addresses specifically includes: acquiring the M addresses; before searching for a node communicable with each address of the P addresses respectively and simultaneously within a second preset time, the method further includes: and acquiring the P addresses. The next address is generated when the communicable node of the next address needs to be searched, so that time waste caused by incomplete subsequent use after excessive addresses are generated at one time is avoided, and meanwhile, the sending efficiency of the first information to be transmitted is improved.
As shown in fig. 5, the communication method in the present embodiment specifically includes the following steps:
s51: m addresses are obtained.
In this step, only the address required by the current loading (searching for the node with which the address can communicate) is generated, so that excessive time is not wasted for generating the address, and the efficiency of subsequently sending the first information to be transmitted is improved.
S52: and respectively and simultaneously searching nodes which can communicate with each address in the M addresses within a first preset time length.
S53: and marking the addresses of which the number of the nodes is greater than the first threshold value in the M addresses, and associating and storing the marked addresses in the M addresses with the searched nodes which can communicate with the addresses respectively.
S54: and selecting one address from the marked addresses as a first sending address, sending first to-be-transmitted information to a plurality of first nodes which can communicate with the first sending address, and acquiring first reply information returned by the first sending addresses by the plurality of first nodes.
S55: and selecting another address from the marked addresses as a second sending address, acquiring a plurality of second nodes associated with the second sending address, sending second to-be-transmitted information to the plurality of second nodes, and acquiring second reply information returned by the plurality of second nodes to the second sending address.
S56: the number of addresses remaining in the tagged address is retrieved.
S57: and when the number of the addresses is smaller than a second threshold value, acquiring the P addresses, and respectively and simultaneously searching nodes which can communicate with each address in the P addresses in a second preset time length.
In this step, a process of acquiring the P addresses is similar to the process of acquiring the M addresses, and "searching for a node communicable with each address in the P addresses within a second preset duration respectively and simultaneously" is similar to that in the fourth embodiment, and is not repeated here, where the second preset duration may be the same as or different from the first preset duration, P may be equal to or different from N, and optionally, P ≧ 2.
Steps S52, S53, S54, S55, and S56 in the present embodiment are similar to steps S42, S43, S44, S45, and S46 in the second embodiment, and are not described again to avoid redundancy.
Compared with the prior art, the method and the device for transmitting the message ensure the reliability of message transmission, reduce the searching time of the node corresponding to the address and improve the efficiency of message transmission; meanwhile, each address in the M addresses is respectively associated and stored with the searched node which can be communicated with the address, so that the address and the associated node can be selected from the current M addresses when subsequent messages are sent, the node is not required to be searched every time the message is sent, and the message transmission efficiency is further improved; in addition, only the addresses with the number of nodes larger than the first threshold value in the M addresses are associated with the corresponding nodes and stored, so that the space occupied by a memory is reduced; in addition, when the number of the remaining available addresses is insufficient, the communicable nodes of the next group of addresses are searched in advance, so that the searched addresses can be directly obtained when the message is sent, the time for waiting the addresses to search the communicable nodes is saved, and the message sending efficiency is improved; and the next address is generated when the communicable node of the next address needs to be searched, so that the time waste caused by one-time generation of excessive addresses and subsequent use is avoided, and meanwhile, the sending efficiency of the first to-be-transmitted information is improved.
The steps of the above methods are divided for clarity, and the implementation may be combined into one step or split some steps, and the steps are divided into multiple steps, so long as the same logical relationship is included, which are all within the protection scope of the present patent; it is within the scope of the patent to add insignificant modifications to the algorithms or processes or to introduce insignificant design changes to the core design without changing the algorithms or processes.
A sixth embodiment of the present invention relates to a terminal, as shown in fig. 6, including:
at least one processor 601; and the number of the first and second groups,
a memory 602 communicatively coupled to the at least one processor 601; wherein,
the memory 602 stores instructions executable by the at least one processor 601 to cause the at least one processor 601 to perform the above-described communication method.
Where the memory 602 and the processor 601 are coupled by a bus, the bus may comprise any number of interconnected buses and bridges that couple one or more of the various circuits of the processor 601 and the memory 602 together. The bus may also connect various other circuits such as peripherals, voltage regulators, power management circuits, and the like, which are well known in the art, and therefore, will not be described any further herein. A bus interface provides an interface between the bus and the transceiver. The transceiver may be one element or a plurality of elements, such as a plurality of receivers and transmitters, providing a means for communicating with various other apparatus over a transmission medium. The data processed by the processor 601 is transmitted over a wireless medium via an antenna, which further receives the data and transmits the data to the processor 601.
The processor 601 is responsible for managing the bus and general processing and may also provide various functions including timing, peripheral interfaces, voltage regulation, power management, and other control functions. While memory 602 may be used to store data used by processor 601 in performing operations.
A seventh embodiment of the present invention relates to a computer-readable storage medium storing a computer program. The computer program realizes the above-described method embodiments when executed by a processor.
That is, as can be understood by those skilled in the art, all or part of the steps in the method for implementing the embodiments described above may be implemented by a program instructing related hardware, where the program is stored in a storage medium and includes several instructions to enable a device (which may be a single chip, a chip, or the like) or a processor (processor) to execute all or part of the steps of the method described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
It will be understood by those of ordinary skill in the art that the foregoing embodiments are specific examples for carrying out the invention, and that various changes in form and details may be made therein without departing from the spirit and scope of the invention in practice.
It will be understood by those of ordinary skill in the art that the foregoing embodiments are specific examples for carrying out the invention, and that various changes in form and details may be made therein without departing from the spirit and scope of the invention in practice.