CN113810451B - Method and device for establishing point-to-point link, first terminal equipment and storage medium - Google Patents

Method and device for establishing point-to-point link, first terminal equipment and storage medium Download PDF

Info

Publication number
CN113810451B
CN113810451B CN202010870884.1A CN202010870884A CN113810451B CN 113810451 B CN113810451 B CN 113810451B CN 202010870884 A CN202010870884 A CN 202010870884A CN 113810451 B CN113810451 B CN 113810451B
Authority
CN
China
Prior art keywords
address
destination
address pair
port
terminal device
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202010870884.1A
Other languages
Chinese (zh)
Other versions
CN113810451A (en
Inventor
张硕
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Honor Device Co Ltd
Original Assignee
Honor Device Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Honor Device Co Ltd filed Critical Honor Device Co Ltd
Priority to CN202010870884.1A priority Critical patent/CN113810451B/en
Publication of CN113810451A publication Critical patent/CN113810451A/en
Application granted granted Critical
Publication of CN113810451B publication Critical patent/CN113810451B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/104Peer-to-peer [P2P] networks

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

In the method, the first terminal device obtains an IP address and a port of a network card available for the second terminal device from a server. If the alternative address pair formed by the IP address and the port of the network card available for the first terminal equipment and the second terminal equipment does not have the IPv6 address pair, when the P2P historical traversal record table is not empty, the alternative address pair is matched with the address pair recorded in the P2P historical traversal record table, and the weight value of the alternative address pair is determined according to the matching degree. And then, selecting a destination address pair from the alternative address pairs according to the weight value, initiating a P2P crossing attempt by using the destination address pair, and establishing a P2P initial link after P2P crossing is successful. In the method, the target address pair is selected according to the weight value of the alternative address pair, so that the successful P2P crossing probability can be improved, and the establishment time of the P2P initial link can be further reduced.

Description

Method and device for establishing point-to-point link, first terminal equipment and storage medium
Technical Field
The embodiment of the application relates to the technical field of intelligent terminals, in particular to a method and a device for establishing a point-to-point link, first terminal equipment and a storage medium.
Background
A real-time User Datagram Protocol (UDP) -based communication service, such as an audio/video call, is performed between terminal devices (such as a mobile phone, a tablet, a large screen, a computer, a car machine, a sound box, or a watch), and a link between the devices has two types of backbone networks: real-time network (RTN) networks (server relay) and peer-to-peer (P2P) traversal (peer-to-peer communication) networks.
The RTN is a network architecture designed specifically for real-time transmission, and is a way of implementing real-time communication between two terminal devices by forwarding through a server having a public network IP address. The RTN network is similar to a leased private network, so that the operation cost is high.
The P2P passes through the network, namely, two terminal devices respectively take the public network IP address and the port of the opposite terminal as the destination IP address and the port to carry out direct communication without renting a private network, so the operation cost is low. However, one disadvantage of P2P traversal networks is that two terminal devices are not necessarily capable of traversing, and the traversal probability is different for different versions of an IP address.
In the related art, an IP address includes two mainstream versions: IPv4 addresses and IPv6 addresses. The IPv4 address is a 32-bit binary number, the IPv4 address is the core of the internet and is also the most widely used internet protocol version, and the subsequent version is the IPv6 address, until 2011, the IANA IPv4 address is completely used up. The IPv6 address increases the IP address from 32 bits to 128 bits, thereby enabling a larger address space to be supported so that the IP address will not run out in the foreseeable future.
For the terminal equipment using the IPv6 address, when P2P crossing is carried out, if internal and external network address conversion is not needed, the IPv6 address can be directly used for direct communication.
However, for a terminal device using an IPv4 address, after P2P traversal is generally performed by a Network Address Translation (NAT) device (such as a router), the NAT device is responsible for translating an intranet IP address + port of a device in a local area network into an IP address + port of a public network. Whether a terminal device using an IPv4 address can try to acquire a public network IP address + port of an opposite terminal through NAT detection and the like to realize P2P crossing is mainly determined by the type of the NAT device, the P2P crossing success rates of different types of NAT devices are different, and the time delay is also different.
In addition, when the terminal devices at both ends have multiple optional IP addresses, multiple attempts may be required to achieve successful P2P traversal, and the probability of successful P2P traversal is low, which also consumes much time and traffic.
Disclosure of Invention
The embodiment of the application provides a method and a device for establishing a point-to-point link, first terminal equipment and a storage medium, and also provides a computer readable storage medium to improve the probability of P2P crossing success and reduce the establishment time of a P2P initial link.
In a first aspect, an embodiment of the present application provides a method for establishing a point-to-point link, including: the method comprises the steps that a first terminal device obtains an IP address and a port of an available network card of the first terminal device from the local, and obtains an IP address and a port of an available network card of a second terminal device from a server; if the alternative address pair formed by the IP address and the port of the network card available for the first terminal equipment and the second terminal equipment does not exist in the IPv6 address pair, the P2P historical traversal record table is obtained, and when the P2P historical traversal record table is not empty, the alternative address pair is matched with the address pair recorded in the P2P historical traversal record table. Then, determining the weight value of the alternative address pair according to the matching degree of the alternative address pair and the address pair recorded in the P2P history traversing record table; selecting a destination address pair from the alternative address pair according to the weight value of the alternative address pair; using a source IP address and a source port in a destination address pair, and initiating a P2P traversing attempt to the destination IP address and the destination port in the destination address pair; and after the P2P crossing is successful, establishing a P2P initial link between the first terminal device and the second terminal device.
The server may be a P2P traversal assist server deployed in the cloud.
The P2P historical traversal record table may be stored in the first terminal device, or may be stored in a cloud server, for example: in the P2P traversal assistant server, this embodiment is not limited thereto. Thus, the P2P history traversal record table may be obtained as follows: the first terminal device obtains the P2P historical traversal record table locally stored by the first terminal device, or the first terminal device obtains the P2P historical traversal record table from a server.
In one possible implementation manner, the matching, by the first terminal device, the candidate address pair with the address pair recorded in the P2P history traversal record table may be: and respectively matching the source IP address and the source port in the alternative address pair with the source IP address and the source port in the recorded address pair, and matching the destination IP address and the destination port in the alternative address pair with the destination IP address and the destination port in the recorded address pair by using the IP address and the port of the first terminal device in the alternative address pair as the source IP address and the source port and using the IP address and the port of the second terminal device in the alternative address pair as the destination IP address and the destination port.
In this way, according to the matching degree between the candidate address pair and the address pair recorded in the P2P history traversal record table, the weight for determining the candidate address pair may be: determining the weight values of the source IP address and the source port in the alternative address pair according to the matching degree of the source IP address and the source port in the alternative address pair and the source IP address and the source port in the recorded address pair; and determining the weight values of the destination IP address and the destination port in the alternative address pair according to the matching degree of the destination IP address and the destination port in the alternative address pair and the destination IP address and the destination port in the recorded address pair. Then, the sum of the weight values of the source IP address and the source port and the weight values of the destination IP address and the destination port in the candidate address pair is calculated as the weight value of the candidate address pair.
Specifically, according to the matching degree between the source IP address and the source port in the candidate address pair and the source IP address and the source port in the recorded address pair, determining the weight values of the source IP address and the source port in the candidate address pair may be: if the source IP address and the source port in the alternative address pair are completely matched with the source IP address and the source port in the recorded address pair, determining that the weight values of the source IP address and the source port in the alternative address pair are a first weight value; and if the source IP address and the source port in the alternative address pair are partially matched with the source IP address and the source port in the recorded address pair, performing AND operation on the source IP address in the alternative address pair and the source IP address in the recorded address pair according to a subnet mask to obtain a maximum public substring, and obtaining the weight values of the source IP address and the source port in the alternative address pair according to the binary matching digit of the maximum public substring.
The first weight value may be set according to system performance and/or implementation requirements during specific implementation, and the magnitude of the first weight value is not limited in this embodiment, for example, the first weight value may be 5.
The and operation according to the subnet mask may obtain the maximum public substring as follows: and matching and calculating the two IPv4 addresses according to the sequence from left to right, and terminating the calculation once an inconsistent bit is encountered. The reason is that, when viewed from left to right, the first two decimal digits of the IPv4 address are usually the large network segment to which the IPv4 address belongs, the third decimal digit are usually the sub-network segment, and falling within the large network segment is a necessary condition for matching, and if the large network segments to which the two IPv4 addresses belong do not match, there is no need for matching at the back.
For example, for IPv4 addresses 10.18.18.18.18 and 10.18.18.19, the maximum common substring is 10.18.18.18, and the binary matching bit number of the maximum common substring is 8+7=31;
for IPv4 addresses 10.18.18.18 and 10.17.18.19, the maximum common substring is 10.18.16, and the binary matching bit number of the maximum common substring is 8+6=14.
Specifically, according to the matching degree between the destination IP address and the destination port in the candidate address pair and the destination IP address and the destination port in the recorded address pair, determining the weight values of the destination IP address and the destination port in the candidate address pair may be: if the destination IP address and the destination port in the alternative address pair are completely matched with the destination IP address and the destination port in the recorded address pair, determining that the weight values of the destination IP address and the destination port in the alternative address pair are second weight values; and if the target IP address and the target port in the alternative address pair are partially matched with the target IP address and the target port in the recorded address pair, performing AND operation on the target IP address in the alternative address pair and the target IP address in the recorded address pair according to a subnet mask to obtain a maximum public substring, and obtaining the weight values of the target IP address and the target port in the alternative address pair according to the binary matching digit of the maximum public substring.
The second weight value may be set according to system performance and/or implementation requirements during specific implementation, and the second weight value may be equal to or different from the first weight value, and the second weight value is not limited in this embodiment, for example, the second weight value may be 5.
In one possible implementation manner, selecting a destination address pair from the candidate address pair according to the weight value of the candidate address pair may be: and selecting the address pair with the largest weight value from the candidate address pairs as a destination address pair.
If the address pair with the largest weight value in the above candidate address pairs includes at least two address pairs, one of the at least two address pairs may be selected as the destination address pair.
In one possible implementation manner, after the first terminal device obtains the IP address and the port of the network card available to the first terminal device from the local, and obtains the IP address and the port of the network card available to the second terminal device from the server, if an IPv6 address pair exists in an alternative address pair consisting of the IP addresses and the ports of the network cards available to the first terminal device and the second terminal device, the IPv6 address pair is used as a destination address pair.
And if the alternative address pair formed by the IP address and the port of the network card available for the first terminal equipment and the second terminal equipment does not have the IPv6 address pair, selecting a destination address pair from the alternative address pair according to a preset sequence when a P2P historical traversing record table stored by the first terminal equipment is empty.
In one possible implementation manner, after a P2P traversal attempt is initiated to a destination IP address and a destination port in the destination address pair by using a source IP address and a source port in the destination address pair, the first terminal device may further record the destination address pair in the P2P history traversal record table after the P2P traversal succeeds.
In one possible implementation manner, after a P2P initial link between a first terminal device and a second terminal device is established, the first terminal device may further obtain a current available bandwidth of each available network card in the first terminal device, obtain a current available bandwidth of each available network card in the second terminal device, and obtain a bandwidth required by a service stream carried by the P2P initial link.
Then, obtaining a difference value obtained by subtracting the bandwidth required by the service flow carried by the P2P initial link from the current available bandwidth of each available network card in the first terminal equipment, and obtaining the available network card of which the difference value is a positive number in the first terminal equipment; and obtaining a difference value obtained by subtracting the bandwidth required by the service flow carried by the P2P initial link from the current available bandwidth of each available network card in the second terminal equipment, and obtaining the available network card of which the difference value is a positive number in the second terminal equipment.
Initiating a P2P traversing attempt by taking the IP address and the port of the available network card with the difference value as a positive number in the first terminal equipment as a source IP address and a source port and taking the IP address and the port of the available network card with the difference value as a positive number in the second terminal equipment as a destination IP address and a destination port; if the P2P crossing is successful, establishing a candidate P2P link according to the requirement by the address pair passing the success. And when the bandwidth of the candidate P2P link is greater than or equal to the bandwidth required by the service flow carried by the P2P initial link, using the candidate P2P link as an alternative P2P link between the first terminal device and the second terminal device.
In one possible implementation manner, after the first terminal device initiates a P2P traversal attempt, if the P2P traversal is successful, the address pair that is successfully traversed is recorded in the P2P historical traversal record table.
In a second aspect, an embodiment of the present application provides an apparatus for establishing a point-to-point link, where the apparatus is included in a first terminal device, and the apparatus has a function of implementing the first aspect and a behavior of the first terminal device in a possible implementation manner of the first aspect. The functions may be implemented by hardware, or by hardware executing corresponding software. The hardware or software includes one or more modules or units corresponding to the above-described functions. Such as a receiving module or unit, a processing module or unit, a transmitting module or unit, etc.
In a third aspect, an embodiment of the present application provides a first terminal device, including: one or more processors; a memory; a plurality of application programs; and one or more computer programs, wherein the one or more computer programs are stored in the memory, the one or more computer programs comprising instructions which, when executed by the first terminal device, cause the first terminal device to perform the steps of: acquiring the IP address and the port of the network card available for the first terminal equipment from the local, and acquiring the IP address and the port of the network card available for the second terminal equipment from the server; if the alternative address pair formed by the IP address and the port of the network card available for the first terminal equipment and the second terminal equipment does not have the IPv6 address pair, the P2P historical traversing record table is obtained, and when the P2P historical traversing record table is not empty, the alternative address pair is matched with the address pair recorded in the P2P historical traversing record table.
Determining the weight value of the alternative address pair according to the matching degree of the alternative address pair and the address pair recorded in the P2P historical traversal record table; selecting a destination address pair from the alternative address pair according to the weight value of the alternative address pair; and initiating a P2P crossing attempt to the destination IP address and the destination port in the destination address pair by using the source IP address and the source port in the destination address pair, and establishing a P2P initial link between the first terminal device and the second terminal device after P2P crossing is successful.
In one possible implementation manner, when the instruction is executed by the first terminal device, the step of causing the first terminal device to perform matching between the candidate address pair and an address pair recorded in the P2P history traversal record table may be: and taking the IP address and the port of the first terminal equipment in the candidate address pair as a source IP address and a source port, taking the IP address and the port of the second terminal equipment in the candidate address pair as a destination IP address and a destination port, respectively matching the source IP address and the source port in the candidate address pair with the source IP address and the source port in the recorded address pair, and matching the destination IP address and the destination port in the candidate address pair with the destination IP address and the destination port in the recorded address pair.
In one possible implementation manner, when the instruction is executed by the first terminal device, the step of causing the first terminal device to determine the weight of the candidate address pair according to the matching degree between the candidate address pair and the address pair recorded in the P2P history traversal record table may be: determining the weight values of the source IP address and the source port in the alternative address pair according to the matching degree of the source IP address and the source port in the alternative address pair and the source IP address and the source port in the recorded address pair; determining the weight values of the target IP address and the target port in the alternative address pair according to the matching degree of the target IP address and the target port in the alternative address pair and the target IP address and the target port in the recorded address pair; and calculating the sum of the weight values of the source IP address and the source port in the alternative address pair and the weight values of the destination IP address and the destination port as the weight value of the alternative address pair.
In one possible implementation manner, when the instruction is executed by the first terminal device, the step of determining the weight values of the source IP address and the source port in the candidate address pair according to the matching degrees between the source IP address and the source port in the candidate address pair and the source IP address and the source port in the recorded address pair by the first terminal device may be: if the source IP address and the source port in the alternative address pair are completely matched with the source IP address and the source port in the recorded address pair, determining that the weight values of the source IP address and the source port in the alternative address pair are first weight values; and if the source IP address and the source port in the alternative address pair are partially matched with the source IP address and the source port in the recorded address pair, performing AND operation on the source IP address in the alternative address pair and the source IP address in the recorded address pair according to a subnet mask to obtain a maximum public substring, and obtaining the weight values of the source IP address and the source port in the alternative address pair according to the binary matching digit of the maximum public substring.
In one possible implementation manner, when the instruction is executed by the first terminal device, the step of determining the weight values of the destination IP address and the destination port in the candidate address pair according to the matching degrees of the destination IP address and the destination port in the candidate address pair and the destination IP address and the destination port in the recorded address pair by the first terminal device may be: if the destination IP address and the destination port in the alternative address pair are completely matched with the destination IP address and the destination port in the recorded address pair, determining the weight values of the destination IP address and the destination port in the alternative address pair to be second weight values; and if the target IP address and the target port in the alternative address pair are partially matched with the target IP address and the target port in the recorded address pair, performing AND operation on the target IP address in the alternative address pair and the target IP address in the recorded address pair according to a subnet mask to obtain a maximum public substring, and obtaining the weight value of the target IP address and the target port in the alternative address pair according to the binary matching digit of the maximum public substring.
In one possible implementation manner, when the instruction is executed by the first terminal device, so that the first terminal device executes the above weight value according to the candidate address pair, the step of selecting the destination address pair from the candidate address pair may be: and selecting the address pair with the largest weight value from the candidate address pairs as a destination address pair.
In one possible implementation manner, when the instruction is executed by the first terminal device, the first terminal device is enabled to perform the following steps after the steps of locally acquiring the IP address and the port of the network card available to the first terminal device and acquiring the IP address and the port of the network card available to the second terminal device from the server are performed: and if an IPv6 address pair exists in an alternative address pair consisting of the IP address and the port of the network card available for the first terminal equipment and the second terminal equipment, taking the IPv6 address pair as a destination address pair.
In one possible implementation manner, when the instruction is executed by the first terminal device, the first terminal device further performs the following steps: and if the alternative address pair formed by the IP address and the port of the network card available for the first terminal equipment and the second terminal equipment does not have the IPv6 address pair, selecting a destination address pair from the alternative address pair according to a preset sequence when a P2P historical traversing record table stored by the first terminal equipment is empty.
In one possible implementation manner, when the instruction is executed by the first terminal device, the first terminal device is caused to execute the following steps after the step of initiating the P2P traversal attempt to the destination IP address and the destination port in the destination address pair by using the source IP address and the source port in the destination address pair is executed: after the P2P crossing is successful, the destination address pair is recorded in the P2P history crossing record table.
In one possible implementation manner, when the instruction is executed by the first terminal device, after the step of establishing the P2P initial link between the first terminal device and the second terminal device is executed by the first terminal device, the following steps are further executed: acquiring the current available bandwidth of each available network card in the first terminal device, the current available bandwidth of each available network card in the second terminal device, and the bandwidth required by the service flow carried by the P2P initial link; obtaining a difference value obtained by subtracting a bandwidth required by a service flow carried by the P2P initial link from a current available bandwidth of each available network card in the first terminal device, and obtaining an available network card of which the difference value is a positive number in the first terminal device; obtaining a difference value obtained by subtracting a bandwidth required by a service flow carried by the P2P initial link from a current available bandwidth of each available network card in the second terminal equipment, and obtaining the available network card of which the difference value is a positive number in the second terminal equipment; initiating a P2P traversing attempt by taking the IP address and the port of the available network card with the difference value as positive number in the first terminal equipment as a source IP address and a source port and taking the IP address and the port of the available network card with the difference value as positive number in the second terminal equipment as a destination IP address and a destination port; if the P2P crossing is successful, establishing a candidate P2P link as required by the address pair passing successfully; and when the bandwidth of the candidate P2P link is greater than or equal to the bandwidth required by the service flow carried by the P2P initial link, using the candidate P2P link as the candidate P2P link between the first terminal device and the second terminal device.
In one possible implementation manner, when the instruction is executed by the first terminal device, after the first terminal device executes the step of initiating the P2P traversal attempt, the following steps are further executed: if the P2P crossing is successful, the address pair which passes through successfully is recorded in the P2P history crossing record table.
In a fourth aspect, embodiments of the present application provide a computer-readable storage medium, in which a computer program is stored, and when the computer program runs on a computer, the computer program causes the computer to execute the method provided in the first aspect.
It should be understood that the second to fourth aspects of the embodiments of the present application are consistent with the technical solutions of the first aspect of the embodiments of the present application, and beneficial effects obtained by the aspects and the corresponding possible implementation manners are similar and will not be described again.
In a fifth aspect, the present application provides a computer program, which is used to execute the method provided in the first aspect when the computer program is executed by a computer.
In a possible design, the program of the fifth aspect may be stored in whole or in part on a storage medium packaged with the processor, or in part or in whole on a memory not packaged with the processor.
Drawings
Fig. 1 is a schematic diagram of an implementation of P2P traversal provided by the related art;
fig. 2 is a schematic structural diagram of a first terminal device according to an embodiment of the present application;
fig. 3 is a block diagram of a software structure of the first terminal device 100 according to an embodiment of the present application;
fig. 4 is a schematic view of an application scenario provided in an embodiment of the present application;
fig. 5 is a flowchart of a method for establishing a point-to-point link according to an embodiment of the present application;
fig. 6 is a flowchart of a method for establishing a point-to-point link according to another embodiment of the present application;
fig. 7 is a flowchart of a method for establishing a point-to-point link according to another embodiment of the present application;
fig. 8 is a schematic structural diagram of a first terminal device according to another embodiment of the present application.
Detailed Description
The terminology used in the description of the embodiments section of the present application is for the purpose of describing particular embodiments of the present application only and is not intended to be limiting of the present application.
In the related art, for a terminal device using an IPv4 address, after P2P traversal is generally performed by a NAT device (such as a router), the NAT device is responsible for converting an intranet IP address + port of a device in a local area network into an IP address + port of a public network. Whether a terminal device using an IPv4 address can try to acquire a public network IP address + port of an opposite terminal through NAT detection and the like to realize P2P traversal is mainly determined by the type of the NAT device, and the P2P traversal success rates and the time delays of different types of NAT devices are different, as shown in table 1.
TABLE 1
Figure GDA0003749218890000071
Fig. 1 is a schematic diagram of an implementation scheme of P2P traversal provided in the related art, and as shown in fig. 1, the implementation scheme of P2P traversal may include:
step 1, the terminal device a and the terminal device B interact with the NAT type detection server respectively to obtain the type of the self-connected NAT device (namely, the NAT type), and the public network IP address and the public network port allocated by the self-connected NAT device.
And 2, exchanging the NAT type, the public network IP address and the public network port of the two parties by the terminal device A and the terminal device B through the transfer server. When the NAT types of the terminal equipment A and the terminal equipment B are both IPv4 symmetrical types, the traversing is stopped; and when the NAT type of the terminal device A is a symmetrical type and the NAT type of the terminal device B is a port-limited conical type, executing the following steps 3, 4 and 5.
And 3, the terminal device A sends a plurality of data packets to the P2P crossing auxiliary server, and the P2P crossing auxiliary server responds to the data packets sent by the terminal device A. This step is time consuming and requires a lot of traffic.
And 4, the terminal equipment A calculates a port list which is possibly allocated by the NAT equipment connected with the terminal equipment A according to the data packet which is responded by the P2P traversing auxiliary server, the public network IP address and the public network port of the terminal equipment B.
And 5, the terminal device A informs the terminal device B of a possible port list of the terminal device A through the information transfer server.
And 6, the terminal device A and the terminal device B mutually transmit packets and punch by utilizing the obtained public network IP address and the public network port of the opposite side until a response is received, and the crossing at the public network port is successful. This step is time consuming and requires a lot of traffic to be consumed.
And 7, the bidirectional punching is successful, namely the P2P crossing is successful.
In the prior art, the success rate of P2P traversal under a fixed network is lower than that under a mobile network, the success rate of P2P traversal under IPv4 is lower than that of P2P traversal under IPv6, a result can be obtained by a P2P traversal basic algorithm for 1 second on average, and a result can be obtained by a P2P intelligent algorithm generally after 3-30 seconds. In addition, the P2P traversal intelligent algorithm mainly faces to the IPv4 address and the NAT device is a symmetric type.
That is to say, in the related art, most of schemes optimized for the P2P traversal algorithm focus on a scenario that two ends each have only one IP address, and when a plurality of IP addresses appear at the two ends and are selectable, how to quickly select a P2P link with the highest probability of traversal success is not provided in the related art.
Based on the above problems, embodiments of the present application provide a method for establishing a point-to-point link, which can improve the probability of successful P2P traversal and reduce the establishment time of a P2P initial link.
The method for establishing a peer-to-peer link provided in the embodiment of the present application may be applied to a first terminal device, where the first terminal device may be a smart phone, a tablet computer, a wearable device, a vehicle-mounted device, an Augmented Reality (AR)/Virtual Reality (VR) device, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, or a Personal Digital Assistant (PDA); the embodiment of the present application does not set any limit to the specific type of the terminal device.
Exemplarily, fig. 2 is a schematic structural diagram of a first terminal device according to an embodiment of the present invention, and as shown in fig. 2, the first terminal device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a Universal Serial Bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display screen 194, a Subscriber Identity Module (SIM) card interface 195, and the like. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, and the like.
It is to be understood that the illustrated structure of the embodiment of the present application does not constitute a specific limitation to the first terminal device 100. In other embodiments of the present application, the first terminal device 100 may include more or fewer components than shown, or combine certain components, or split certain components, or a different arrangement of components. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.
It should be noted that, for the first terminal device 100, the public network IP addresses corresponding to the cellular access and the router access are not the same.
Processor 110 may include one or more processing units, such as: the processor 110 may include an Application Processor (AP), a modem processor, a Graphics Processing Unit (GPU), an Image Signal Processor (ISP), a controller, a video codec, a Digital Signal Processor (DSP), a baseband processor, and/or a neural-Network Processing Unit (NPU), etc. The different processing units may be separate devices or may be integrated into one or more processors.
The controller can generate an operation control signal according to the instruction operation code and the timing signal to complete the control of instruction fetching and instruction execution.
A memory may also be provided in the processor 110 for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may hold instructions or data that have just been used or recycled by the processor 110. If the processor 110 needs to reuse the instruction or data, it can be called directly from the memory. Avoiding repeated accesses reduces the latency of the processor 110, thereby increasing the efficiency of the system.
In some embodiments, processor 110 may include one or more interfaces. The interface may include an integrated circuit (I2C) interface, an integrated circuit built-in audio (I2S) interface, a Pulse Code Modulation (PCM) interface, a universal asynchronous receiver/transmitter (UART) interface, a mobile industry processor interface (mobile industry processor interface, MIPI), a general-purpose-input/output (GPIO) interface, a Subscriber Identity Module (SIM) interface, and/or a Universal Serial Bus (USB) interface, etc.
The I2C interface is a bidirectional synchronous serial bus comprising a serial data line (SDA) and a serial clock line (DCL). In some embodiments, the processor 110 may include multiple sets of I2C buses. The processor 110 may be coupled to the touch sensor 180K, the charger, the flash, the camera 193, etc. through different I2C bus interfaces, respectively. For example: the processor 110 may be coupled to the touch sensor 180K through an I2C interface, so that the processor 110 and the touch sensor 180K communicate through an I2C bus interface to implement the touch function of the first terminal device 100.
The I2S interface may be used for audio communication. In some embodiments, processor 110 may include multiple sets of I2S buses. The processor 110 may be coupled to the audio module 170 through an I2S bus, enabling communication between the processor 110 and the audio module 170. In some embodiments, the audio module 170 may transmit an audio signal to the wireless communication module 160 through the I2S interface, so as to implement a function of answering a call through a bluetooth headset.
The PCM interface may also be used for audio communication, sampling, quantizing and encoding analog signals. In some embodiments, audio module 170 and wireless communication module 160 may be coupled by a PCM bus interface. In some embodiments, the audio module 170 may also transmit audio signals to the wireless communication module 160 through the PCM interface, so as to implement a function of answering a call through a bluetooth headset. Both the I2S interface and the PCM interface may be used for audio communication.
The UART interface is a universal serial data bus used for asynchronous communications. The bus may be a bidirectional communication bus. It converts the data to be transmitted between serial communication and parallel communication. In some embodiments, a UART interface is generally used to connect the processor 110 with the wireless communication module 160. For example: the processor 110 communicates with a bluetooth module in the wireless communication module 160 through a UART interface to implement a bluetooth function. In some embodiments, the audio module 170 may transmit the audio signal to the wireless communication module 160 through a UART interface, so as to implement the function of playing music through a bluetooth headset.
MIPI interfaces may be used to connect processor 110 with peripheral devices such as display screen 194, camera 193, and the like. The MIPI interface includes a Camera Serial Interface (CSI), a Display Serial Interface (DSI), and the like. In some embodiments, the processor 110 and the camera 193 communicate through a CSI interface to implement the shooting function of the first terminal device 100. The processor 110 and the display screen 194 communicate through the DSI interface to implement the display function of the first terminal device 100.
The GPIO interface may be configured by software. The GPIO interface may be configured as a control signal and may also be configured as a data signal. In some embodiments, a GPIO interface may be used to connect the processor 110 with the camera 193, the display 194, the wireless communication module 160, the audio module 170, the sensor module 180, and the like. The GPIO interface may also be configured as an I2C interface, an I2S interface, a UART interface, an MIPI interface, and the like.
The USB interface 130 is an interface conforming to the USB standard specification, and may be a Mini USB interface, a Micro USB interface, a USB Type C interface, or the like. The USB interface 130 may be used to connect a charger to charge the first terminal device 100, and may also be used to transmit data between the first terminal device 100 and a peripheral device. And the earphone can also be used for connecting an earphone and playing audio through the earphone. The interface may also be used to connect other electronic devices, such as AR devices and the like.
It should be understood that the interface connection relationship between the modules according to the embodiment of the present invention is only an exemplary illustration, and does not constitute a structural limitation on the first terminal device 100. In other embodiments of the present application, the first terminal device 100 may also adopt different interface connection manners or a combination of multiple interface connection manners in the above embodiments.
The charging management module 140 is configured to receive charging input from a charger. The charger can be a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 may receive charging input from a wired charger via the USB interface 130. In some wireless charging embodiments, the charging management module 140 may receive a wireless charging input through a wireless charging coil of the first terminal device 100. The charging management module 140 may also supply power to the first terminal device 100 through the power management module 141 while charging the battery 142.
The power management module 141 is used to connect the battery 142, the charging management module 140 and the processor 110. The power management module 141 receives input from the battery 142 and/or the charge management module 140, and supplies power to the processor 110, the internal memory 121, the display 194, the camera 193, the wireless communication module 160, and the like. The power management module 141 may also be used to monitor parameters such as battery capacity, battery cycle count, battery state of health (leakage, impedance), etc. In other embodiments, the power management module 141 may be disposed in the processor 110. In other embodiments, the power management module 141 and the charging management module 140 may be disposed in the same device.
The wireless communication function of the first terminal device 100 may be implemented by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, a modem processor, a baseband processor, and the like.
The antennas 1 and 2 are used for transmitting and receiving electromagnetic wave signals. Each antenna in the first terminal device 100 may be used to cover a single or multiple communication bands. Different antennas can also be multiplexed to improve the utilization of the antennas. For example: the antenna 1 may be multiplexed as a diversity antenna of a wireless local area network. In other embodiments, the antenna may be used in conjunction with a tuning switch.
The mobile communication module 150 may provide a solution including wireless communication of 2G/3G/4G/5G, etc. applied on the first terminal device 100. The mobile communication module 150 may include at least one filter, a switch, a power amplifier, a Low Noise Amplifier (LNA), and the like. The mobile communication module 150 may receive the electromagnetic wave from the antenna 1, filter, amplify, etc. the received electromagnetic wave, and transmit the electromagnetic wave to the modem processor for demodulation. The mobile communication module 150 may also amplify the signal modulated by the modem processor, and convert the signal into electromagnetic wave through the antenna 1 to radiate the electromagnetic wave. In some embodiments, at least some of the functional modules of the mobile communication module 150 may be disposed in the processor 110. In some embodiments, at least some of the functional modules of the mobile communication module 150 may be provided in the same device as at least some of the modules of the processor 110.
The modem processor may include a modulator and a demodulator. The modulator is used for modulating a low-frequency baseband signal to be transmitted into a medium-high frequency signal. The demodulator is used for demodulating the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then passes the demodulated low frequency baseband signal to a baseband processor for processing. The low frequency baseband signal is processed by the baseband processor and then passed to the application processor. The application processor outputs a sound signal through an audio device (not limited to the speaker 170A, the receiver 170B, etc.) or displays an image or video through the display screen 194. In some embodiments, the modem processor may be a stand-alone device. In other embodiments, the modem processor may be provided in the same device as the mobile communication module 150 or other functional modules, independent of the processor 110.
The wireless communication module 160 may provide a solution for wireless communication applied to the first terminal device 100, including Wireless Local Area Networks (WLANs) (e.g., wireless fidelity (Wi-Fi) networks), bluetooth (bluetooth, BT), global Navigation Satellite System (GNSS), frequency Modulation (FM), near Field Communication (NFC), infrared (IR), and the like. The wireless communication module 160 may be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via the antenna 2, performs frequency modulation and filtering processing on electromagnetic wave signals, and transmits the processed signals to the processor 110. The wireless communication module 160 may also receive a signal to be transmitted from the processor 110, perform frequency modulation and amplification on the signal, and convert the signal into electromagnetic waves via the antenna 2 to radiate the electromagnetic waves.
In some embodiments, the antenna 1 of the first terminal device 100 is coupled to the mobile communication module 150 and the antenna 2 is coupled to the wireless communication module 160, so that the first terminal device 100 can communicate with a network and other devices through a wireless communication technology. The wireless communication technology may include global system for mobile communications (GSM), general Packet Radio Service (GPRS), code division multiple access (code division multiple access, CDMA), wideband Code Division Multiple Access (WCDMA), time-division code division multiple access (time-division code division multiple access, TD-SCDMA), long Term Evolution (LTE), BT, GNSS, WLAN, NFC, FM, and/or IR technologies, etc. The GNSS may include a Global Positioning System (GPS), a global navigation satellite system (GLONASS), a beidou navigation satellite system (BDS), a quasi-zenith satellite system (QZSS), and/or a Satellite Based Augmentation System (SBAS).
The first terminal device 100 implements a display function by the GPU, the display screen 194, and the application processor, etc. The GPU is a microprocessor for image processing, and is connected to the display screen 194 and an application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. The processor 110 may include one or more GPUs that execute program instructions to generate or alter display information.
The display screen 194 is used to display images, video, and the like. The display screen 194 includes a display panel. The display panel may adopt a Liquid Crystal Display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (active-matrix organic light-emitting diode, AMOLED), a flexible light-emitting diode (FLED), a miniature, a Micro-oeld, a quantum dot light-emitting diode (QLED), and the like. In some embodiments, the first terminal device 100 may include 1 or N display screens 194, N being a positive integer greater than 1.
The first terminal device 100 may implement a photographing function through the ISP, the camera 193, the video codec, the GPU, the display screen 194, the application processor, and the like.
The ISP is used to process the data fed back by the camera 193. For example, when a photo is taken, the shutter is opened, light is transmitted to the camera photosensitive element through the lens, the optical signal is converted into an electrical signal, and the camera photosensitive element transmits the electrical signal to the ISP for processing and converting into an image visible to naked eyes. The ISP can also carry out algorithm optimization on the noise, brightness and skin color of the image. The ISP can also optimize parameters such as exposure, color temperature and the like of a shooting scene. In some embodiments, the ISP may be provided in camera 193.
The camera 193 is used to capture still images or video. The object generates an optical image through the lens and projects the optical image to the photosensitive element. The photosensitive element may be a Charge Coupled Device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The light sensing element converts the optical signal into an electrical signal, which is then passed to the ISP where it is converted into a digital image signal. And the ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into image signal in standard RGB, YUV and other formats. In some embodiments, the first terminal device 100 may include 1 or N cameras 193, N being a positive integer greater than 1.
The digital signal processor is used for processing digital signals, and can process digital image signals and other digital signals. For example, when the first terminal device 100 selects a frequency bin, the digital signal processor is configured to perform fourier transform or the like on the frequency bin energy.
Video codecs are used to compress or decompress digital video. The first terminal device 100 may support one or more video codecs. In this way, the first terminal device 100 can play or record video in a plurality of encoding formats, such as: moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, and the like.
The NPU is a neural-network (NN) computing processor that processes input information quickly by using a biological neural network structure, for example, by using a transfer mode between neurons of a human brain, and can also learn by itself continuously. The NPU may implement applications such as intelligent recognition of the first terminal device 100, for example: image recognition, face recognition, speech recognition, text understanding, and the like.
The external memory interface 120 may be used to connect an external memory card, such as a Micro SD card, to extend the storage capability of the first terminal device 100. The external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function. For example, files such as music, video, etc. are saved in an external memory card.
The internal memory 121 may be used to store computer-executable program code, which includes instructions. The internal memory 121 may include a program storage area and a data storage area. The storage program area may store an operating system, an application program (such as a sound playing function, an image playing function, and the like) required by at least one function, and the like. The storage data area may store data (such as audio data, a phonebook, etc.) created during use of the first terminal device 100, and the like. In addition, the internal memory 121 may include a high speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, a Universal Flash Storage (UFS), and the like. The processor 110 executes various functional applications and data processing of the first terminal device 100 by executing instructions stored in the internal memory 121 and/or instructions stored in a memory provided in the processor.
The first terminal device 100 may implement an audio function through the audio module 170, the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, and the application processor. Such as music playing, recording, etc.
The audio module 170 is used to convert digital audio information into analog audio signals for output, and also used to convert analog audio inputs into digital audio signals. The audio module 170 may also be used to encode and decode audio signals. In some embodiments, the audio module 170 may be disposed in the processor 110, or some functional modules of the audio module 170 may be disposed in the processor 110.
The speaker 170A, also called a "horn", is used to convert the audio electrical signal into an acoustic signal. The first terminal device 100 can listen to music through the speaker 170A or listen to a handsfree call.
The receiver 170B, also called "earpiece", is used to convert the electrical audio signal into an acoustic signal. When the first terminal apparatus 100 listens to a call or voice information, it is possible to listen to a voice by bringing the receiver 170B close to the human ear.
The microphone 170C, also referred to as a "microphone," is used to convert sound signals into electrical signals. When making a call or transmitting voice information, the user can input a voice signal to the microphone 170C by speaking near the microphone 170C through the mouth. The first terminal device 100 may be provided with at least one microphone 170C. In other embodiments, the first terminal device 100 may be provided with two microphones 170C, which may implement a noise reduction function in addition to collecting sound signals. In other embodiments, the first terminal device 100 may further include three, four or more microphones 170C to collect sound signals, reduce noise, identify sound sources, implement directional recording functions, and so on.
The earphone interface 170D is used to connect a wired earphone. The headset interface 170D may be the USB interface 130, or may be a 3.5mm open mobile electronic device platform (OMTP) standard interface, a cellular telecommunications industry association (cellular telecommunications industry association of the USA, CTIA) standard interface.
The pressure sensor 180A is used for sensing a pressure signal, and can convert the pressure signal into an electrical signal. In some embodiments, the pressure sensor 180A may be disposed on the display screen 194. The pressure sensor 180A can be of a wide variety, such as a resistive pressure sensor, an inductive pressure sensor, a capacitive pressure sensor, and the like. The capacitive pressure sensor may be a sensor comprising at least two parallel plates having an electrically conductive material. When a force acts on the pressure sensor 180A, the capacitance between the electrodes changes. The first terminal device 100 determines the intensity of the pressure from the change in the capacitance. When a touch operation is applied to the display screen 194, the first terminal device 100 detects the intensity of the touch operation based on the pressure sensor 180A. The first terminal device 100 may also calculate the touched position from the detection signal of the pressure sensor 180A. In some embodiments, the touch operations that are applied to the same touch position but different touch operation intensities may correspond to different operation instructions. For example: and when the touch operation with the touch operation intensity smaller than the first pressure threshold value acts on the short message application icon, executing an instruction for viewing the short message. And when the touch operation with the touch operation intensity larger than or equal to the first pressure threshold value acts on the short message application icon, executing an instruction of newly building the short message.
The gyro sensor 180B may be used to determine the motion attitude of the first terminal device 100. In some embodiments, the angular velocity of the first terminal device 100 about three axes (i.e., x, y, and z axes) may be determined by the gyro sensor 180B. The gyro sensor 180B may be used for photographing anti-shake. Illustratively, when the shutter is pressed, the gyro sensor 180B detects a shake angle of the first terminal device 100, calculates a distance to be compensated for by the lens module according to the shake angle, and allows the lens to counteract the shake of the first terminal device 100 through a reverse movement, thereby achieving anti-shake. The gyroscope sensor 180B may also be used for navigation, somatosensory gaming scenes.
The air pressure sensor 180C is used to measure air pressure. In some embodiments, the first terminal device 100 calculates an altitude from the barometric pressure measured by the barometric pressure sensor 180C, and assists positioning and navigation.
The magnetic sensor 180D includes a hall sensor. The first terminal device 100 may detect the opening and closing of the folder holster using the magnetic sensor 180D. In some embodiments, when the first terminal device 100 is a folder, the first terminal device 100 may detect the opening and closing of the folder according to the magnetic sensor 180D. And then according to the opening and closing state of the leather sheath or the opening and closing state of the flip cover, the automatic unlocking of the flip cover is set.
The acceleration sensor 180E can detect the magnitude of acceleration of the first terminal device 100 in various directions (generally, three axes). The magnitude and direction of gravity can be detected when the first terminal device 100 is stationary. The method can also be used for recognizing the posture of the electronic equipment, and is applied to horizontal and vertical screen switching, pedometers and other applications.
A distance sensor 180F for measuring a distance. The first terminal device 100 may measure the distance by infrared or laser. In some embodiments, the first terminal device 100 may take a picture of a scene using the distance sensor 180F for ranging to achieve fast focus.
The proximity light sensor 180G may include, for example, a Light Emitting Diode (LED) and a light detector, such as a photodiode. The light emitting diode may be an infrared light emitting diode. The first terminal device 100 emits infrared light to the outside through the light emitting diode. The first terminal device 100 detects infrared reflected light from a nearby object using a photodiode. When sufficient reflected light is detected, it can be determined that there is an object near the first terminal device 100. When insufficient reflected light is detected, the first terminal device 100 can determine that there is no object near the first terminal device 100. The first terminal device 100 can utilize the proximity light sensor 180G to detect that the user holds the first terminal device 100 to talk near the ear, so as to automatically turn off the screen to achieve the purpose of saving power. The proximity light sensor 180G can also be used in a holster mode, a pocket mode automatically unlocks and locks the screen.
The ambient light sensor 180L is used to sense ambient light brightness. The first terminal device 100 may adaptively adjust the brightness of the display screen 194 according to the perceived ambient light level. The ambient light sensor 180L may also be used to automatically adjust the white balance when taking a picture. The ambient light sensor 180L may also cooperate with the proximity light sensor 180G to detect whether the first terminal device 100 is in a pocket, in order to prevent a false touch.
The fingerprint sensor 180H is used to collect a fingerprint. The first terminal device 100 may utilize the collected fingerprint characteristics to realize fingerprint unlocking, access to an application lock, fingerprint photographing, fingerprint incoming call answering, and the like.
The temperature sensor 180J is used to detect temperature. In some embodiments, the first terminal device 100 executes a temperature processing policy using the temperature detected by the temperature sensor 180J. For example, when the temperature reported by the temperature sensor 180J exceeds the threshold, the first terminal device 100 performs reducing the performance of the processor located near the temperature sensor 180J, so as to reduce power consumption and implement thermal protection. In other embodiments, the first terminal device 100 heats the battery 142 when the temperature is below another threshold to avoid abnormal shutdown of the first terminal device 100 due to low temperature. In other embodiments, when the temperature is lower than a further threshold, the first terminal device 100 performs boosting on the output voltage of the battery 142 to avoid abnormal shutdown due to low temperature.
The touch sensor 180K is also called a "touch device". The touch sensor 180K may be disposed on the display screen 194, and the touch sensor 180K and the display screen 194 form a touch screen, which is also called a "touch screen". The touch sensor 180K is used to detect a touch operation applied thereto or nearby. The touch sensor can communicate the detected touch operation to the application processor to determine the touch event type. Visual output associated with the touch operation may be provided via the display screen 194. In other embodiments, the touch sensor 180K may be disposed on the surface of the first terminal device 100, different from the position of the display screen 194.
The bone conduction sensor 180M may acquire a vibration signal. In some embodiments, the bone conduction sensor 180M may acquire a vibration signal of the human vocal part vibrating the bone mass. The bone conduction sensor 180M may also contact the human pulse to receive the blood pressure pulsation signal. In some embodiments, the bone conduction sensor 180M may also be disposed in a headset, integrated into a bone conduction headset. The audio module 170 may analyze a voice signal based on the vibration signal of the bone mass vibrated by the sound part acquired by the bone conduction sensor 180M, so as to implement a voice function. The application processor can analyze heart rate information based on the blood pressure beating signal acquired by the bone conduction sensor 180M, so as to realize the heart rate detection function.
The keys 190 include a power-on key, a volume key, and the like. The keys 190 may be mechanical keys. Or may be touch keys. The first terminal device 100 may receive a key input, and generate a key signal input related to user setting and function control of the first terminal device 100.
The motor 191 may generate a vibration cue. The motor 191 may be used for incoming call vibration cues, as well as for touch vibration feedback. For example, touch operations applied to different applications (e.g., photographing, audio playing, etc.) may correspond to different vibration feedback effects. The motor 191 may also respond to different vibration feedback effects for touch operations applied to different areas of the display screen 194. Different application scenes (such as time reminding, receiving information, alarm clock, game and the like) can also correspond to different vibration feedback effects. The touch vibration feedback effect may also support customization.
Indicator 192 may be an indicator light that may be used to indicate a state of charge, a change in charge, or a message, missed call, notification, etc.
The SIM card interface 195 is used to connect a SIM card. The SIM card can be brought into and out of contact with the first terminal device 100 by being inserted into the SIM card interface 195 or being pulled out from the SIM card interface 195. The first terminal device 100 may support 1 or N SIM card interfaces, where N is a positive integer greater than 1. The SIM card interface 195 may support a Nano SIM card, a Micro SIM card, a SIM card, etc. Multiple cards can be inserted into the same SIM card interface 195 at the same time. The types of the plurality of cards may be the same or different. The SIM card interface 195 is also compatible with different types of SIM cards. The SIM card interface 195 is also compatible with external memory cards. The first terminal device 100 interacts with the network through the SIM card to implement functions such as a call and data communication. In some embodiments, the first terminal device 100 employs eSIM, namely: an embedded SIM card. The eSIM card may be embedded in the first terminal apparatus 100 and may not be separated from the first terminal apparatus 100.
The software system of the first terminal device 100 may adopt a hierarchical architecture, an event-driven architecture, a micro-core architecture, a micro-service architecture, or a cloud architecture. The embodiment of the present invention takes an Android system with a layered architecture as an example, and exemplarily illustrates a software structure of the first terminal device 100.
Fig. 3 is a block diagram of a software structure of the first terminal device 100 according to an embodiment of the present application.
The layered architecture divides the software into several layers, each layer having a clear role and division of labor. The layers communicate with each other through a software interface. In some embodiments, the Android system is divided into four layers, an application layer, an application framework layer, an Android runtime (Android runtime) and system library, and a kernel layer from top to bottom.
The application layer may include a series of application packages.
As shown in fig. 3, the application package may include applications such as camera, gallery, calendar, phone call, map, navigation, WLAN, bluetooth, music, video, short message, etc.
The application framework layer provides an Application Programming Interface (API) and a programming framework for the application program of the application layer. The application framework layer includes a number of predefined functions.
As shown in FIG. 3, the application framework layers may include a window manager, content provider, view system, phone manager, resource manager, notification manager, and the like.
The window manager is used for managing window programs. The window manager can obtain the size of the display screen, judge whether a status bar exists, lock the screen, intercept the screen and the like.
Content providers are used to store and retrieve data and make it accessible to applications. The data may include video, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
The view system includes visual controls such as controls to display text, controls to display pictures, and the like. The view system may be used to build applications. The display interface may be composed of one or more views. For example, the display interface including the short message notification icon may include a view for displaying text and a view for displaying pictures.
The phone manager is used to provide a communication function of the first terminal device 100. Such as management of call status (including on, off, etc.).
The resource manager provides various resources for the application, such as localized strings, icons, pictures, layout files, video files, and the like.
The notification manager enables the application to display notification information in the status bar, can be used to convey notification-type messages, can disappear automatically after a short dwell, and does not require user interaction. Such as a notification manager used to inform download completion, message alerts, etc. The notification manager may also be a notification that appears in the form of a chart or scroll bar text at the top status bar of the system, such as a notification of a background running application, or a notification that appears on the screen in the form of a dialog window. For example, prompting text information in the status bar, sounding a prompt tone, vibrating the electronic device, flashing an indicator light, etc.
The Android Runtime comprises a core library and a virtual machine. The Android runtime is responsible for scheduling and managing an Android system.
The core library comprises two parts: one part is a function which needs to be called by java language, and the other part is a core library of android.
The application layer and the application framework layer run in a virtual machine. And executing java files of the application program layer and the application program framework layer into a binary file by the virtual machine. The virtual machine is used for performing the functions of object life cycle management, stack management, thread management, safety and exception management, garbage collection and the like.
The system library may include a plurality of functional modules. For example: surface managers (surface managers), media Libraries (Media Libraries), three-dimensional graphics processing Libraries (e.g., openGL ES), 2D graphics engines (e.g., SGL), and the like.
The surface manager is used to manage the display subsystem and provide a fusion of the 2D and 3D layers for multiple applications.
The media library supports a variety of commonly used audio, video format playback and recording, and still image files, among others. The media library may support a variety of audio-video encoding formats, such as MPEG4, h.264, MP3, AAC, AMR, JPG, PNG, and the like.
The three-dimensional graphic processing library is used for realizing three-dimensional graphic drawing, image rendering, synthesis, layer processing and the like.
The 2D graphics engine is a drawing engine for 2D drawing.
The kernel layer is a layer between hardware and software. The inner core layer at least comprises a display driver, a camera driver, an audio driver and a sensor driver.
For convenience of understanding, the following embodiments of the present application will specifically describe, by taking a terminal device having a structure shown in fig. 2 and fig. 3 as an example, a method for establishing a point-to-point link provided in the embodiments of the present application with reference to the accompanying drawings and application scenarios.
At present, a terminal device takes a smart phone as an example, a latest flagship model of each mobile phone manufacturer generally supports dual-card dual-standby, and a Wireless Local Area Network (WLAN) network card supports two frequency bands of 2.4G and 5GHz and is simultaneously connected with two different routers; on the premise of a multi-network card simultaneous enabling technology, a smart phone may theoretically have 4 mutually independent IP addresses at most (two Subscriber Identity Module (SIM) cards are enabled and two different routers are connected), and then a maximum of 4 × 4=16 possible IP pairs may occur between two communicating smart phones for P2P penetration attempt, as shown in fig. 4, where fig. 4 is an application scenario diagram provided in an embodiment of the present application.
Fig. 4 shows a scenario where multiple IP address pairs exist at two communication ends, and an embodiment of the present application provides a method for establishing a point-to-point link, which can significantly improve the probability of P2P traversal success in the scenario shown in fig. 4, and can switch to an alternative link in real time when the quality of a primary link decreases.
It can be understood that, the second terminal device and the first terminal device in the scenario shown in fig. 4 are terminal devices having the same structure, and both can be implemented by using the structures shown in fig. 2 and fig. 3.
Fig. 5 is a flowchart of a method for establishing a point-to-point link according to an embodiment of the present application, and as shown in fig. 5, the method for establishing a point-to-point link may include:
in step 501, the first terminal device 100 obtains the IP address and port of the network card available to the first terminal device from the local, and obtains the IP address and port of the network card available to the second terminal device from the server.
The server may be a P2P traversal assist server deployed in the cloud.
For example, the IP address and port of the network card available to the second terminal device may be as shown in table 1.
TABLE 1
Figure GDA0003749218890000161
Specifically, the first terminal device 100 may implement the operation of step 501 through the processor 110, the antenna 1 and the mobile communication module 150, and/or through the processor 110, the antenna 2 and the wireless communication module 160.
Step 502, determining whether there is an IPv6 address pair in an alternative address pair formed by the IP address and the port of the network card available to the first terminal device 100 and the second terminal device. If not, go to step 503; if an IPv6 address pair exists, then step 510 is performed.
Step 503, acquiring a P2P history traversing record table.
In this embodiment, the P2P history traversal record table records IPv4 address pairs for which P2P traversal attempts have been performed and P2P traversal succeeds, for example, the P2P history traversal record table may be as shown in table 2.
TABLE 2
Figure GDA0003749218890000171
In a specific implementation, the P2P history traversing record table may be stored in the first terminal device, or may be stored in a cloud server, for example: in the P2P traversal assistant server, this embodiment is not limited thereto. Thus, the P2P history traversal record table may be obtained as follows: the first terminal device obtains the P2P historical traversal record table locally stored by the first terminal device, or the first terminal device obtains the P2P historical traversal record table from a server.
Step 504, determine whether the P2P history traversal record table is empty. If the P2P history traversing record table is not empty, go to step 505; if the P2P history traversal record table is empty, step 511 is executed.
And 505, matching the alternative address pair with an address pair recorded in the P2P history traversal record table.
Step 506, determining a weight value of the candidate address pair according to a matching degree between the candidate address pair and an address pair recorded in the P2P history traversal record table.
And 507, selecting a destination address pair from the candidate address pairs according to the weight values of the candidate address pairs.
Specifically, according to the weight value of the candidate address pair, selecting a destination address pair from the candidate address pair may be: and selecting the address pair with the largest weight value from the candidate address pairs as a destination address pair.
Assuming that the address pair with the largest weight value in the above candidate address pairs includes at least two address pairs, one of the at least two address pairs may be selected as the destination address pair.
Step 508, using the source IP address and the source port in the destination address pair, initiating a P2P traversal attempt to the destination IP address and the destination port in the destination address pair.
Specifically, after determining the source IP address and the source port, and the destination IP address and the destination port of the P2P traversal attempt, the present embodiment does not limit the algorithm employed by the P2P traversal attempt.
It is understood that the address pair mentioned in step 505 to step 508 is an IPv4 address pair.
In step 509, after the P2P traversal is successful, a P2P initial link between the first terminal device 100 and the second terminal device is established.
Specifically, the first terminal device 100 may implement the operations of step 508 and step 509 through the processor 110, the antenna 1 and the mobile communication module 150, and/or through the processor 110, the antenna 2 and the wireless communication module 160.
In this embodiment, the source IP address and the source port of the P2P initial link between the first terminal device 100 and the second terminal device are the source IP address and the source port in the destination address pair, and the destination IP address and the destination port of the P2P initial link are the destination IP address and the destination port in the destination address pair.
And step 510, taking the IPv6 address pair as a destination address pair. Step 508 is then performed.
Specifically, the first terminal device 100 may implement the operation of step 510 through the processor 110, the antenna 1 and the mobile communication module 150, and/or through the processor 110, the antenna 2 and the wireless communication module 160.
It is to be understood that the address pair in step 510 is an IPv6 address pair.
Step 511, selecting the destination address pair from the candidate address pairs according to a predetermined sequence. Step 508 is then performed.
It is understood that the address pair in step 511 is an IPv4 address pair.
The predetermined sequence may be set by itself when the specific implementation is performed, and the predetermined sequence is not limited in this embodiment. For example, the predetermined sequence may be to preferentially fetch the IPv4 address pair of which the source IP address and the destination IP address are both LTE, and if not, select the IPv4 address pair of which the source IP address and the destination IP address are both WLAN.
In the method for establishing the peer-to-peer link, the first terminal device 100 locally obtains the IP address and the port of the network card available to the first terminal device 100, and obtains the IP address and the port of the network card available to the second terminal device from the server. If there is no IPv6 address pair in the candidate address pair formed by the IP address and the port of the network card available to the first terminal device 100 and the second terminal device, a peer-to-peer P2P historical traversal record table is obtained, and when the P2P historical traversal record table is not empty, the candidate address pair is matched with the address pair recorded in the P2P historical traversal record table, and a weight value of the candidate address pair is determined according to a matching degree of the candidate address pair and the address pair recorded in the P2P historical traversal record table. Then, according to the weight values of the candidate address pairs, a destination address pair is selected from the candidate address pairs, a P2P traversal attempt is initiated by using the destination address pair, and after the P2P traversal succeeds, a P2P initial link between the first terminal device 100 and the second terminal device is established. In the method, the destination address pair is selected according to the weight value of the alternative address pair, and one address pair with the highest crossing probability can be selected from a plurality of alternative address pairs based on historical experience, so that the success probability of P2P crossing can be improved, and the establishment time of a P2P initial link can be further reduced.
Fig. 6 is a flowchart of a method for establishing a point-to-point link according to another embodiment of the present application, as shown in fig. 6, in the embodiment shown in fig. 5 of the present application, step 505 may be:
step 601, using the IP address and port of the first terminal device 100 in the candidate address pair as a source IP address and a source port, using the IP address and port of the second terminal device in the candidate address pair as a destination IP address and a destination port, respectively matching the source IP address and the source port in the candidate address pair with the source IP address and the source port in the address pair recorded in the P2P history traversal record table, and matching the destination IP address and the destination port in the candidate address pair with the destination IP address and the destination port in the recorded address pair.
Thus, step 506 may include:
step 602, determining the weight values of the source IP address and the source port in the candidate address pair according to the matching degree between the source IP address and the source port in the candidate address pair and the source IP address and the source port in the recorded address pair.
Specifically, according to the matching degree between the source IP address and the source port in the candidate address pair and the source IP address and the source port in the recorded address pair, determining the weight values of the source IP address and the source port in the candidate address pair may be: if the source IP address and the source port in the alternative address pair are completely matched with the source IP address and the source port in the recorded address pair, determining that the weight values of the source IP address and the source port in the alternative address pair are first weight values; and if the source IP address and the source port in the alternative address pair are partially matched with the source IP address and the source port in the recorded address pair, performing AND operation on the source IP address in the alternative address pair and the source IP address in the recorded address pair according to a subnet mask to obtain a maximum public substring, and obtaining weight values of the source IP address and the source port in the alternative address pair according to a binary matching digit of the maximum public substring.
The first weight value may be set according to system performance and/or implementation requirements during specific implementation, and the magnitude of the first weight value is not limited in this embodiment, for example, the first weight value may be 5.
And operation is performed according to the subnet mask, and the maximum common substring obtained may be: and performing matching calculation on the two IPv4 addresses in the order from left to right, and terminating the calculation once an inconsistent bit is encountered. The reason is that, when viewed from left to right, the first two decimal digits of the IPv4 address are usually the large network segment to which the IPv4 address belongs, the third decimal digit is usually the sub-network segment, and falling into the large network segment is a necessary condition for matching, and if the large network segments to which the two IPv4 addresses belong are not matched, there is no need for matching later.
For example, for IPv4 addresses 10.18.18.18.18 and 10.18.18.19, the maximum common substring is 10.18.18.18, and the binary matching bit number of the maximum common substring is 8+7=31;
for IPv4 addresses 10.18.18.18.18 and 10.17.18.19, the maximum common substring is 10.18.16, and the binary matching bit number of the maximum common substring is 8+6=14.
Step 603, determining the weight values of the destination IP address and the destination port in the candidate address pair according to the matching degree of the destination IP address and the destination port in the candidate address pair and the destination IP address and the destination port in the recorded address pair.
Specifically, according to the matching degree between the destination IP address and the destination port in the candidate address pair and the destination IP address and the destination port in the recorded address pair, determining the weight values of the destination IP address and the destination port in the candidate address pair may be: if the destination IP address and the destination port in the alternative address pair are completely matched with the destination IP address and the destination port in the recorded address pair, determining the weight values of the destination IP address and the destination port in the alternative address pair to be second weight values; and if the destination IP address and the destination port in the alternative address pair are partially matched with the destination IP address and the destination port in the recorded address pair, performing AND operation on the destination IP address in the alternative address pair and the destination IP address in the recorded address pair according to a subnet mask to obtain a maximum public substring, and obtaining the weight values of the destination IP address and the destination port in the alternative address pair according to the binary matching digit of the maximum public substring.
The second weight value may be set according to system performance and/or implementation requirements during specific implementation, and the second weight value may be equal to or different from the first weight value, and the second weight value is not limited in this embodiment, for example, the second weight value may be 5.
Step 604, calculating a sum of the weight values of the source IP address and the source port in the candidate address pair and the weight values of the destination IP address and the destination port as the weight value of the candidate address pair.
Taking the scenario shown in fig. 4 as an example, it is assumed that there are a (16 in the scenario shown in fig. 4) possible IPv4 address pairs between the first terminal device 100 and the second terminal device, and there are b address pairs recorded in the P2P history traversal record table; the first weight value and the second weight value are both 5.
Then, for each IPv4 address pair of the a IPv4 address pairs, the following calculation is performed with respect to each address pair recorded in the P2P history traversal record table:
1) If the source IP address and the source port are completely matched, the weight value of the source IP address and the source port in the alternative address pair is 5, and the weight values of the destination IP address and the destination port have the following two situations:
a. the destination IP address is completely matched with the destination port, the weight values of the destination IP address and the destination port in the alternative address pair are also 5, and the weight value of the alternative address pair is 10;
b. and if the target IP address is partially matched with the target port, performing AND operation on the target IP address in the alternative address pair and the target IP address in the recorded address pair according to a subnet mask to obtain a maximum public substring, and according to the binary matching digit of the maximum public substring, obtaining the weight value of the target IP address and the target port in the alternative address pair, wherein the weight value is shown in formula (1).
Figure GDA0003749218890000191
In the formula (1), m is the binary matching bit number of the maximum common substring. In this case, the weight value of the alternative address pair is
Figure GDA0003749218890000192
2) If the source IP address and the source port are partially matched, performing AND operation on the source IP address in the alternative address pair and the source IP address in the recorded address pair according to a subnet mask code to obtain a maximum public substring, and obtaining weight values of the source IP address and the source port in the alternative address pair according to binary matching digits of the maximum public substring, namely calculating the weight values of the source IP address and the source port according to the formula (1); the destination IP address and the weight value of the destination port have the following two cases:
a. if the destination IP address and the destination port are completely matched, the weight values of the destination IP address and the destination port in the alternative address pair are 5, and the weight of the alternative address pairWeight value of
Figure GDA0003749218890000201
b. If the destination IP address and the destination port are partially matched, performing AND operation on the destination IP address in the alternative address pair and the destination IP address in the recorded address pair according to a subnet mask code to obtain a maximum public substring, and obtaining the weight values of the destination IP address and the destination port in the alternative address pair according to the binary matching digit of the maximum public substring, namely calculating the weight values of the destination IP address and the destination port in the alternative address pair according to the formula (1), wherein the weight value of the alternative address pair is
Figure GDA0003749218890000202
For each IPv4 address pair in the a IPv4 address pairs, b weight values are calculated, and the largest one of the b weight values is taken as the weight value of the IPv4 address pair.
In this embodiment, the a IPv4 address pairs are all calculated as described above, and are sorted according to their respective weight values, and the IPv4 address pair with the largest weight value is taken as the initial link of the P2P traversal attempt.
In this embodiment, the higher the weight value of the candidate address pair is, the higher the matching degree between the candidate address pair and a certain IP address pair in the P2P history traversal record table is, the higher the similarity between the candidate address pair and a network segment where the certain IP address pair is located in the P2P history traversal record table is, and the higher the similarity between the network segments is, the higher the probability that the candidate address pair falls on the same NAT device is. According to historical experience, the higher the weight value of the candidate address pair is, the higher the probability of P2P traversal success is. Therefore, in step 507 of this embodiment, an address pair with the largest weight value is selected from the candidate address pairs as a destination address pair.
Further, after step 508, the method may further include:
step 605, after the P2P traversal is successful, record the destination address pair in the P2P history traversal record table.
In this embodiment, step 605 may be executed in parallel with step 509 or executed successively, and in this embodiment, the execution order of step 605 and step 509 is not limited, but fig. 6 illustrates that step 605 is executed after step 509.
Fig. 7 is a flowchart of a method for establishing a point-to-point link according to still another embodiment of the present application, and as shown in fig. 7, the method for establishing a point-to-point link may further include:
step 701, obtaining a current available bandwidth of each available network card in the first terminal device 100, obtaining a current available bandwidth of each available network card in the second terminal device, and obtaining a bandwidth required by a service flow carried by the P2P initial link.
Specifically, the current available bandwidth of the network card may be obtained through detection in a padding manner, and certainly, other bandwidth detection manners may also be used to obtain the current available bandwidth of the network card.
Step 702, obtaining a difference value obtained by subtracting a bandwidth required by a service flow carried by the P2P initial link from a current available bandwidth of each available network card in the first terminal device 100, and obtaining an available network card of which the difference value is a positive number in the first terminal device 100; and obtaining a difference value obtained by subtracting the bandwidth required by the service flow carried by the P2P initial link from the current available bandwidth of each available network card in the second terminal equipment, and obtaining the available network card with the difference value being a positive number in the second terminal equipment.
Step 703, the IP address and port of the available network card with the above difference being positive number in the first terminal device 100 are used as a source IP address and a source port, and the IP address and port of the available network card with the above difference being positive number in the second terminal device are used as a destination IP address and a destination port, and a P2P traversal attempt is initiated.
In step 704, if the P2P traversal is successful, a candidate P2P link is established as needed with the address pair successfully traversed.
Specifically, in some power consumption or traffic limitation scenarios, after the P2P traversal is successful, the candidate P2P link is not necessarily established immediately, but may be established again to continue the service data path when the quality of the P2P first-transmission link is degraded and the P2P link needs to be switched.
Specifically, the first terminal device 100 may implement the operations of step 703 and step 704 through the processor 110, the antenna 1 and the mobile communication module 150, and/or through the processor 110, the antenna 2 and the wireless communication module 160.
Step 705, when the bandwidth of the candidate P2P link is greater than or equal to the bandwidth required by the service flow carried by the P2P initial link, taking the candidate P2P link as an alternative P2P link between the first terminal device and the second terminal device.
Further, after step 703, the method may further include:
in step 706, if the P2P traversal is successful, the successfully traversed address pair is recorded in the P2P history traversal record table.
In this embodiment, step 704, step 705, and step 706 may be executed sequentially or in parallel, the execution sequence of step 704, step 705, and step 706 is not limited in this embodiment, and step 706 is executed after step 705 in fig. 7 as an example.
Note that, in this embodiment, steps 701 to 706 are executed after step 509. Specifically, after the P2P initial link is established, considering that the quality stability of the P2P link is insufficient, when the quality of the P2P initial link is degraded, a network card with a lower bandwidth load may be selected by the method provided in the embodiment shown in fig. 7, a P2P traversal attempt is performed, after the P2P traversal is successful, a candidate P2P link is established as needed, and when the bandwidth of the candidate P2P link is greater than or equal to the bandwidth required by the service flow carried by the P2P initial link, the candidate P2P link is used as the candidate P2P link between the first terminal device 100 and the second terminal device. In addition, after the P2P traversal succeeds, the address pairs that succeed in traversal can be recorded in the P2P historical traversal record table, aiming at enriching the P2P historical traversal record table by using the idle network card resources, and being used as a reference basis for subsequent P2P traversal.
The method provided by the embodiment shown in fig. 7 may switch the service carried by the P2P primary link to the alternative P2P link when the call quality of the P2P primary link is degraded, and switch back to the RTN when the quality of all P2P links is not feasible within the range allowed by power consumption. Because the communication cost is very low after the P2P traversal succeeds, the method provided by the embodiment shown in fig. 7 can prolong the service life of P2P, reduce the use of RTN, and further reduce the operation cost.
The method for establishing a peer-to-peer link provided in the embodiment of the present application is described below by taking a currently common video call product as an example.
Most video call products have two media stream data transmission modes of RTN (server transfer) and P2P (peer-to-peer communication) when a single call is made, and can be switched to another link with better quality in real time according to the call quality of the current link.
When a P2P link is established, in a scenario where a multi-network card is enabled, the method provided in the embodiments of fig. 5 to 7 of the present application may be used, where a first transmission link with the highest traversal probability is selected from multiple possible P2P paths according to an IP address and a P2P history traversal record table, and one or multiple alternative P2P links are established as needed based on bandwidth load, when the call quality of the first transmission link is degraded, it is considered to first switch to an alternative P2P link, and within a range allowed by power consumption, when the quality of all P2P links is not feasible, it is switched back to the RTN.
Because the result can be obtained only when the time for establishing a P2P link reaches 30 seconds at most, a plurality of P2P links can be selected as the primary link in a multi-network-card enabled scenario (for example, the scenario shown in fig. 4), and by using the methods provided by the embodiments shown in fig. 5 to 7 of the present application, the link with the highest crossing probability can be quickly selected as the P2P primary link, thereby significantly reducing the establishment time of the P2P primary link. Otherwise, the method is randomly selected from a plurality of P2P links, and the efficiency is low.
In addition, when the call quality of the P2P initial link is degraded, the service carried by the P2P initial link may be switched to the alternative P2P link, and within the range allowed by power consumption, the RTN is switched back when the quality of all the P2P links is not feasible. Because the communication cost is extremely low after the P2P crossing is successful, the embodiment of the application can prolong the service time of the P2P, reduce the use of RTN and further reduce the operation cost.
The path optimization method provided by the embodiment of the application can also be applied to other UDP-IP-based protocols or IP-like protocols, and can be used for increasing the speed of connection establishment and establishing an alternative link for switching when a plurality of IP addresses generated on the terminal equipment side are available in a multi-network card enabled scene.
It is to be understood that some or all of the steps or operations in the above-described embodiments are merely examples, and other operations or variations of various operations may be performed by the embodiments of the present application. Further, the various steps may be performed in a different order presented in the above-described embodiments, and it is possible that not all of the operations in the above-described embodiments are performed.
It will be appreciated that the first terminal device, in order to implement the above-described functions, comprises corresponding hardware and/or software modules for performing the respective functions. The exemplary algorithm steps described in connection with the embodiments disclosed herein may be embodied in hardware or in a combination of hardware and computer software. Whether a function is performed as hardware or computer software drives hardware depends upon the particular application and design constraints imposed on the solution. Skilled artisans may implement the described functionality in varying ways for each particular application, in conjunction with the embodiments, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In this embodiment, the terminal device may be divided into function modules according to the method embodiment, for example, each function module may be divided corresponding to each function, or two or more functions may be integrated into one module. The integrated module can be implemented in the form of hardware. It should be noted that the division of the modules in this embodiment is schematic, and is only a logic function division, and there may be another division manner in actual implementation.
Fig. 8 is a schematic structural diagram of a first terminal device according to another embodiment of the present application, where each functional module is divided by using corresponding functions, and fig. 8 illustrates a schematic possible composition diagram of the first terminal device 800 involved in the foregoing embodiment, as shown in fig. 8, the first terminal device 800 may include: a receiving unit 801, a processing unit 802, and a transmitting unit 803;
the receiving unit 801 may be configured to support the first terminal device 800 to perform step 501, step 508, step 509, step 510, step 703, step 704, and/or other processes used in the technical solutions described in the embodiments of the present application;
the processing unit 802 may be configured to support the first terminal device 800 to perform steps 501 to 507, step 511, steps 601 to 605, step 701, step 702, step 705, step 706, and/or the like, and/or other processes used in the technical solutions described in the embodiments of the present application;
the sending unit 803 may be configured to support the first terminal device 800 to perform step 501, step 508, step 509, step 510, step 703, step 704, and/or the like, and/or other processes for the technical solutions described in the embodiments of the present application.
It should be noted that all relevant contents of each step related to the above method embodiment may be referred to the functional description of the corresponding functional module, and are not described herein again.
The first terminal device 800 provided in this embodiment is configured to execute the method for establishing a point-to-point link, and therefore the same effect as the method described above can be achieved.
It should be understood that the first terminal device 800 may correspond to the first terminal device 100 shown in fig. 2. The functions of the receiving unit 801 and the sending unit 803 may be implemented by the processor 110, the antenna 1 and the mobile communication module 150 in the first terminal device 100 shown in fig. 2, and/or by the processor 110, the antenna 2 and the wireless communication module 160; the functions of the processing unit 802 may be implemented by the processor 110 in the first terminal device 100 shown in fig. 2.
In case of employing an integrated unit, the first terminal device 800 may include a processing module, a storage module, and a communication module.
The processing module may be configured to control and manage the actions of the first terminal device 800, and for example, may be configured to support the first terminal device 800 to execute the steps executed by the receiving unit 801, the processing unit 802, and the sending unit 803. The memory module may be used to support the first terminal device 800 in storing program codes and data, etc. A communication module, which may be used to support communication of the first terminal device 800 with other devices.
Among other things, a processing module may be a processor or controller that may implement or execute the various illustrative logical blocks, modules, and circuits described in connection with the present disclosure. A processor may also be a combination of computing functions, e.g., a combination of one or more microprocessors, a Digital Signal Processing (DSP) and a microprocessor, or the like. The storage module may be a memory. The communication module may specifically be a radio frequency circuit, a bluetooth chip, and/or a Wi-Fi chip, and the like, which interact with other electronic devices.
In an embodiment, when the processing module is a processor and the storage module is a memory, the first terminal device 800 according to the embodiment may be a device having the structure shown in fig. 2.
Embodiments of the present application further provide a computer-readable storage medium, in which a computer program is stored, and when the computer program runs on a computer, the computer is enabled to execute the method provided by the embodiments shown in fig. 4 to 7 of the present application.
Embodiments of the present application further provide a computer program product, which includes a computer program, when the computer program runs on a computer, causing the computer to execute the method provided by the embodiments shown in fig. 4 to 7 of the present application.
In the embodiments of the present application, "at least one" means one or more, and "a plurality" means two or more. "and/or" describes the association relationship of the associated objects, and means that there may be three relationships, for example, a and/or B, and may mean that a exists alone, a and B exist simultaneously, and B exists alone. Wherein A and B can be singular or plural. The character "/" generally indicates that the former and latter associated objects are in an "or" relationship. "at least one of the following" and the like, refer to any combination of these items, including any combination of singular or plural items. For example, at least one of a, b, and c may represent: a, b, c, a and b, a and c, b and c or a and b and c, wherein a, b and c can be single or multiple.
Those of ordinary skill in the art will appreciate that the various elements and algorithm steps described in connection with the embodiments disclosed herein can be implemented as electronic hardware, computer software, or combinations of electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, any function, if implemented in the form of a software functional unit and sold or used as a separate product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application or portions thereof that substantially contribute to the prior art may be embodied in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a read-only memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
The above description is only for the specific embodiments of the present application, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present disclosure, and all the changes or substitutions should be covered by the protection scope of the present application. The protection scope of the present application shall be subject to the protection scope of the claims.

Claims (22)

1. A method for establishing a point-to-point link, comprising:
the method comprises the steps that a first terminal device obtains an IP address and a port of an available network card of the first terminal device from the local, and obtains an IP address and a port of an available network card of a second terminal device from a server;
if an IPv6 address pair does not exist in an alternative address pair consisting of the IP address and the port of the network card available for the first terminal equipment and the second terminal equipment, acquiring a point-to-point P2P historical traversal record table, and matching the alternative address pair with an address pair recorded in the P2P historical traversal record table when the P2P historical traversal record table is not empty;
determining a weight value of the alternative address pair according to the matching degree of the alternative address pair and the address pair recorded in the P2P history traversing record table;
selecting a destination address pair from the alternative address pair according to the weight value of the alternative address pair;
initiating a P2P traversal attempt to a destination IP address and a destination port in the destination address pair using the source IP address and the source port in the destination address pair;
after P2P crossing succeeds, establishing a P2P initial link between the first terminal device and the second terminal device;
wherein, the determining the weight of the candidate address pair according to the matching degree of the candidate address pair and the address pair recorded in the P2P history traversal record table includes:
determining the weight values of the source IP address and the source port in the alternative address pair according to the matching degree of the source IP address and the source port in the alternative address pair and the source IP address and the source port in the recorded address pair;
determining the weight values of the destination IP address and the destination port in the alternative address pair according to the matching degree of the destination IP address and the destination port in the alternative address pair and the destination IP address and the destination port in the recorded address pair;
and calculating the sum of the weight values of the source IP address and the source port in the alternative address pair and the weight values of the destination IP address and the destination port as the weight value of the alternative address pair.
2. The method according to claim 1, wherein the matching the alternative address pair with an address pair recorded in the P2P history traversal record table comprises:
and taking the IP address and the port of the first terminal equipment in the alternative address pair as a source IP address and a source port, taking the IP address and the port of the second terminal equipment in the alternative address pair as a destination IP address and a destination port, respectively matching the source IP address and the source port in the alternative address pair with the source IP address and the source port in the recorded address pair, and matching the destination IP address and the destination port in the alternative address pair with the destination IP address and the destination port in the recorded address pair.
3. The method of claim 1, wherein determining weight values for the source IP address and the source port in the alternative address pair based on the degree of matching of the source IP address and the source port in the alternative address pair to the source IP address and the source port in the recorded address pair comprises:
if the source IP address and the source port in the alternative address pair are completely matched with the source IP address and the source port in the recorded address pair, determining that the weight values of the source IP address and the source port in the alternative address pair are first weight values;
and if the source IP address and the source port in the alternative address pair are partially matched with the source IP address and the source port in the recorded address pair, performing AND operation on the source IP address in the alternative address pair and the source IP address in the recorded address pair according to a subnet mask to obtain a maximum public substring, and obtaining weight values of the source IP address and the source port in the alternative address pair according to binary matching digits of the maximum public substring.
4. The method according to claim 1, wherein the determining the weight values of the destination IP address and the destination port in the alternative address pair according to the matching degree of the destination IP address and the destination port in the alternative address pair and the destination IP address and the destination port in the recorded address pair comprises:
if the destination IP address and the destination port in the alternative address pair are completely matched with the destination IP address and the destination port in the recorded address pair, determining that the weight values of the destination IP address and the destination port in the alternative address pair are second weight values;
and if the destination IP address and the destination port in the alternative address pair are partially matched with the destination IP address and the destination port in the recorded address pair, performing AND operation on the destination IP address in the alternative address pair and the destination IP address in the recorded address pair according to a subnet mask to obtain a maximum public substring, and obtaining the weight value of the destination IP address and the destination port in the alternative address pair according to the binary matching digit of the maximum public substring.
5. The method of claim 1, wherein selecting a destination address pair from the alternative address pair according to the weight value of the alternative address pair comprises:
and selecting the address pair with the maximum weight value from the alternative address pair as a destination address pair.
6. The method according to claim 1, wherein after the first terminal device locally obtains the IP address and port of the network card available to the first terminal device, and obtains the IP address and port of the network card available to the second terminal device from the server, the method further comprises:
and if an IPv6 address pair exists in an alternative address pair consisting of the IP address and the port of the network card available for the first terminal equipment and the second terminal equipment, taking the IPv6 address pair as a destination address pair.
7. The method of claim 1, further comprising:
and if the alternative address pair formed by the IP address and the port of the network card available for the first terminal equipment and the second terminal equipment does not have an IPv6 address pair, selecting a destination address pair from the alternative address pair according to a preset sequence when a point-to-point P2P historical traversal record table stored by the first terminal equipment is empty.
8. The method of any one of claims 1-7, wherein after initiating a P2P traversal attempt to a destination IP address and a destination port in the destination address pair using a source IP address and a source port in the destination address pair, further comprising:
after P2P crossing is successful, recording the destination address pair in the P2P history crossing record table.
9. The method according to any of claims 1-7, wherein after establishing the P2P initial link between the first terminal device and the second terminal device, the method further comprises:
acquiring the current available bandwidth of each available network card in the first terminal device, acquiring the current available bandwidth of each available network card in the second terminal device, and acquiring the bandwidth required by the service flow carried by the P2P initial link;
obtaining a difference value obtained by subtracting a bandwidth required by a service flow carried by the P2P initial link from a current available bandwidth of each available network card in the first terminal device, and obtaining an available network card of which the difference value is a positive number in the first terminal device; obtaining a difference value obtained by subtracting the bandwidth required by the service flow carried by the P2P initial link from the current available bandwidth of each available network card in the second terminal equipment, and obtaining the available network card of which the difference value is a positive number in the second terminal equipment;
initiating a P2P traversing attempt by taking the IP address and the port of the available network card with the difference value as positive number in the first terminal device as a source IP address and a source port and taking the IP address and the port of the available network card with the difference value as positive number in the second terminal device as a destination IP address and a destination port;
if the P2P crossing is successful, establishing a candidate P2P link as required by the address pair passing successfully;
and when the bandwidth of the candidate P2P link is greater than or equal to the bandwidth required by the service flow carried by the P2P initial link, taking the candidate P2P link as a candidate P2P link between the first terminal device and the second terminal device.
10. The method of claim 9, wherein after the initiating the P2P traversal attempt, further comprising:
if the P2P crossing is successful, the address pair with the passing success is recorded in the P2P history crossing record table.
11. An arrangement for establishing a point-to-point link, characterised by being arranged to perform a method according to any one of claims 1 to 10.
12. A first terminal device, comprising:
one or more processors; a memory; a plurality of application programs; and one or more computer programs, wherein the one or more computer programs are stored in the memory, the one or more computer programs comprising instructions which, when executed by the first terminal device, cause the first terminal device to perform the steps of:
acquiring the IP address and the port of the network card available to the first terminal equipment from the local, and acquiring the IP address and the port of the network card available to the second terminal equipment from the server;
if an IPv6 address pair does not exist in an alternative address pair consisting of the IP address and the port of the network card available for the first terminal equipment and the second terminal equipment, acquiring a point-to-point P2P historical traversal record table, and matching the alternative address pair with an address pair recorded in the P2P historical traversal record table when the P2P historical traversal record table is not empty;
determining a weight value of the alternative address pair according to the matching degree of the alternative address pair and the address pair recorded in the P2P historical traversal record table;
selecting a destination address pair from the alternative address pair according to the weight value of the alternative address pair;
initiating a P2P traversal attempt to a destination IP address and a destination port in the destination address pair using a source IP address and a source port in the destination address pair;
after P2P crossing is successful, establishing a P2P initial link between the first terminal device and the second terminal device;
wherein, when the instruction is executed by the first terminal device, the step of determining the weight of the candidate address pair according to the matching degree of the candidate address pair and the address pair recorded in the P2P history traversal record table by the first terminal device includes:
determining the weight values of the source IP address and the source port in the alternative address pair according to the matching degree of the source IP address and the source port in the alternative address pair and the source IP address and the source port in the recorded address pair;
determining the weight values of the destination IP address and the destination port in the alternative address pair according to the matching degree of the destination IP address and the destination port in the alternative address pair and the destination IP address and the destination port in the recorded address pair;
and calculating the sum of the weight values of the source IP address and the source port and the weight values of the destination IP address and the destination port in the alternative address pair as the weight value of the alternative address pair.
13. The first terminal device of claim 12, wherein the instructions, when executed by the first terminal device, cause the first terminal device to perform the step of matching the alternative address pair with an address pair recorded in the P2P history traversal record table comprises:
and taking the IP address and the port of the first terminal equipment in the alternative address pair as a source IP address and a source port, taking the IP address and the port of the second terminal equipment in the alternative address pair as a destination IP address and a destination port, respectively matching the source IP address and the source port in the alternative address pair with the source IP address and the source port in the recorded address pair, and matching the destination IP address and the destination port in the alternative address pair with the destination IP address and the destination port in the recorded address pair.
14. The first terminal device of claim 12, wherein the instructions, when executed by the first terminal device, cause the first terminal device to perform the step of determining weight values for the source IP address and the source port in the candidate address pair based on the degree of matching between the source IP address and the source port in the candidate address pair and the source IP address and the source port in the recorded address pair comprises:
if the source IP address and the source port in the alternative address pair are completely matched with the source IP address and the source port in the recorded address pair, determining that the weight values of the source IP address and the source port in the alternative address pair are first weight values;
and if the source IP address and the source port in the alternative address pair are partially matched with the source IP address and the source port in the recorded address pair, performing AND operation on the source IP address in the alternative address pair and the source IP address in the recorded address pair according to a subnet mask to obtain a maximum public substring, and obtaining weight values of the source IP address and the source port in the alternative address pair according to a binary matching digit of the maximum public substring.
15. The first terminal device of claim 12, wherein the instructions, when executed by the first terminal device, cause the first terminal device to perform the step of determining the weight values of the destination IP address and the destination port in the candidate address pair according to the matching degree of the destination IP address and the destination port in the candidate address pair and the destination IP address and the destination port in the recorded address pair, comprises:
if the destination IP address and the destination port in the alternative address pair are completely matched with the destination IP address and the destination port in the recorded address pair, determining that the weight values of the destination IP address and the destination port in the alternative address pair are second weight values;
and if the destination IP address and the destination port in the alternative address pair are partially matched with the destination IP address and the destination port in the recorded address pair, performing AND operation on the destination IP address in the alternative address pair and the destination IP address in the recorded address pair according to a subnet mask to obtain a maximum public substring, and obtaining weight values of the destination IP address and the destination port in the alternative address pair according to binary matching digits of the maximum public substring.
16. The first terminal device of claim 12, wherein the instructions, when executed by the first terminal device, cause the first terminal device to perform the step of selecting a destination address pair from the alternative address pair according to the weight value of the alternative address pair comprises:
and selecting the address pair with the maximum weight value from the alternative address pair as a destination address pair.
17. The first terminal device of claim 12, wherein the instructions, when executed by the first terminal device, cause the first terminal device to perform the following steps after the steps of locally obtaining the IP address and port of the network card available to the first terminal device and obtaining the IP address and port of the network card available to the second terminal device from the server:
and if an IPv6 address pair exists in an alternative address pair consisting of the IP address and the port of the network card available for the first terminal equipment and the second terminal equipment, taking the IPv6 address pair as a destination address pair.
18. The first terminal device of claim 12, wherein the instructions, when executed by the first terminal device, cause the first terminal device to further perform the steps of:
and if the alternative address pair formed by the IP address and the port of the network card available for the first terminal equipment and the second terminal equipment does not have the IPv6 address pair, selecting a destination address pair from the alternative address pair according to a preset sequence when a point-to-point P2P historical traversal record table stored by the first terminal equipment is empty.
19. The first end-point device of any of claims 12-18, wherein the instructions, when executed by the first end-point device, cause the first end-point device to perform the following further steps after the step of initiating a P2P traversal attempt to a destination IP address and a destination port of the destination address pair using a source IP address and a source port of the destination address pair:
after P2P crossing is successful, recording the destination address pair in the P2P history crossing record table.
20. The first terminal device according to any one of claims 12-18, wherein the instructions, when executed by the first terminal device, cause the first terminal device to perform the following steps after the step of establishing the P2P originating link between the first terminal device and the second terminal device:
acquiring the current available bandwidth of each available network card in the first terminal device, the current available bandwidth of each available network card in the second terminal device, and the bandwidth required by the service flow carried by the P2P initial link;
obtaining a difference value obtained by subtracting a bandwidth required by a service flow carried by the P2P initial link from a current available bandwidth of each available network card in the first terminal device, and obtaining an available network card of which the difference value is a positive number in the first terminal device; obtaining a difference value obtained by subtracting a bandwidth required by a service flow carried by the P2P initial link from a current available bandwidth of each available network card in the second terminal equipment, and obtaining the available network card of which the difference value is a positive number in the second terminal equipment;
initiating a P2P crossing attempt by taking the IP address and the port of the available network card with the difference value as a positive number in the first terminal device as a source IP address and a source port and taking the IP address and the port of the available network card with the difference value as a positive number in the second terminal device as a destination IP address and a destination port;
if the P2P crossing succeeds, establishing a candidate P2P link as required by the address pair passing successfully;
and when the bandwidth of the candidate P2P link is greater than or equal to the bandwidth required by the service flow carried by the P2P initial link, taking the candidate P2P link as a candidate P2P link between the first terminal device and the second terminal device.
21. The first terminal device of claim 20, wherein the instructions, when executed by the first terminal device, cause the first terminal device to perform the step of initiating a P2P traversal attempt further followed by the steps of:
if the P2P crossing is successful, the address pair with the passing success is recorded in the P2P history crossing record table.
22. A computer-readable storage medium, in which a computer program is stored which, when run on a computer, causes the computer to carry out the method according to any one of claims 1-10.
CN202010870884.1A 2020-08-26 2020-08-26 Method and device for establishing point-to-point link, first terminal equipment and storage medium Active CN113810451B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010870884.1A CN113810451B (en) 2020-08-26 2020-08-26 Method and device for establishing point-to-point link, first terminal equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010870884.1A CN113810451B (en) 2020-08-26 2020-08-26 Method and device for establishing point-to-point link, first terminal equipment and storage medium

Publications (2)

Publication Number Publication Date
CN113810451A CN113810451A (en) 2021-12-17
CN113810451B true CN113810451B (en) 2022-10-28

Family

ID=78943413

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010870884.1A Active CN113810451B (en) 2020-08-26 2020-08-26 Method and device for establishing point-to-point link, first terminal equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113810451B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114301964A (en) * 2021-12-25 2022-04-08 深圳市元征科技股份有限公司 Terminal device, network connection method thereof, communication system, and storage medium
CN116708532B (en) * 2023-08-03 2023-10-20 腾讯科技(深圳)有限公司 Local area network connection method, device, computer equipment and readable storage medium

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109274735A (en) * 2018-09-11 2019-01-25 腾讯科技(深圳)有限公司 A kind of peer-to-peer network connection method and relevant device
CN110661860A (en) * 2019-09-18 2020-01-07 华为技术有限公司 Method for establishing call and call equipment

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8341207B2 (en) * 2010-04-07 2012-12-25 Apple Inc. Apparatus and method for matching users for online sessions

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN109274735A (en) * 2018-09-11 2019-01-25 腾讯科技(深圳)有限公司 A kind of peer-to-peer network connection method and relevant device
CN110661860A (en) * 2019-09-18 2020-01-07 华为技术有限公司 Method for establishing call and call equipment

Also Published As

Publication number Publication date
CN113810451A (en) 2021-12-17

Similar Documents

Publication Publication Date Title
EP3846402B1 (en) Voice communication method, electronic device, and system
CN113438354B (en) Data transmission method and device, electronic equipment and storage medium
CN116614848A (en) Network link switching method based on electronic equipment position and electronic equipment
CN115334138B (en) QUIC data transmission method and device, client and server
CN113645571A (en) Data transmission method and electronic equipment
CN113810451B (en) Method and device for establishing point-to-point link, first terminal equipment and storage medium
US11997736B2 (en) Connection establishment method and terminal device
US20240098354A1 (en) Connection establishment method and electronic device
CN113973398A (en) Wireless network connection method, electronic equipment and chip system
CN113490291B (en) Data downloading method and device and terminal equipment
CN113596919B (en) Data downloading method and device and terminal equipment
CN114928898B (en) Method and device for establishing session based on WiFi direct connection
EP4293997A1 (en) Display method, electronic device, and system
EP4280596A1 (en) Video call method and related device
CN115134404B (en) Method for managing push connection and electronic equipment
CN113141637B (en) Multipath transmission control method and control device
CN113676902B (en) System, method and electronic equipment for providing wireless internet surfing
CN114979261A (en) Service interaction method, terminal, server and system
CN114765768A (en) Network selection method and equipment
CN114489876A (en) Text input method, electronic equipment and system
CN116708317B (en) Data packet MTU adjustment method and device and terminal equipment
WO2023280160A1 (en) Channel switching method and apparatus
CN117354876A (en) Data migration method, electronic equipment and networking system
CN117177228A (en) Equipment registration method, system and equipment
CN117931463A (en) Application control method, electronic equipment and system

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant