Method and device for sending through handshake packet
By receiving the target connection request sent by the platform server, the smooth round trip time is obtained and the target time of sending the penetration handshake packet is determined. The timing difference caused by NAT device connection tracking is solved, and the success rate of NAT penetration and communication stability is improved. sex.
Patent Information
- Application Number
- CN202411378384.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-29
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2044-09-29
AI Technical Summary
The existing NAT devices have connection tracking functions, which leads to the timing differences between the connectivity detection packets reaching the exit NAT, resulting in NAT failure in penetration, and lacks effective solutions.
By receiving the target connection request sent by the platform server, the smooth round trip time between the client and the first network address conversion device and the smooth round trip time between the client and the platform server are obtained, and the smooth round trip time between the platform server and the second network address conversion device are combined with the Smooth the round trip time and determine the target moment for sending the penetration handshake packet to ensure that the penetration handshake packet on the client and device reaches the peer exit NAT at the same time.
This avoids NAT penetration failure caused by timing differences, improves communication quality and stability between the client and the device, improves user experience, and improves the success rate of NAT penetration.
Smart Images

Figure CN119276829A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of communications, and in particular to a method and device for sending a penetration handshake packet. Background Art
[0002] NAT (Network Address Translation) is a common network technology used to translate IP addresses on a private network into public IP addresses, enabling multiple devices to share a single public IP address. However, NAT technology restricts connections to internal hosts, preventing external hosts from actively connecting to internal hosts. This prevents direct communication between hosts on different internal networks. NAT traversal technology overcomes this limitation, enabling direct point-to-point communication between devices behind a NAT network, thereby improving network connectivity and stability.
[0003] NAT traversal technology requires identifying the NAT type. This is because different NAT types process network packets differently, which affects the success rate of NAT traversal. However, existing NAT devices have a connection tracking function. This function causes the NAT mapping port of the local connectivity check message to jump when the peer end's connectivity check message (a type of network packet) arrives at the egress NAT before the local end, causing the connectivity check to fail. If the local connectivity check message arrives at the peer end's egress NAT first, the same problem will occur.
[0004] There is currently no effective solution to the above problems. Summary of the Invention
[0005] The embodiment of the present invention provides a method and apparatus for sending a penetration handshake packet, so as to at least solve the problem of NAT penetration failure caused by the timing difference of the connectivity detection message arriving at the peer egress NAT in the related art.
[0006] According to one embodiment of the present invention, a method for sending a penetration handshake packet is provided, comprising: a device end receives a target connection establishment request from a platform server, wherein the target connection establishment request carries a first smooth round-trip time between a client and a first network address translation device, and a second smooth round-trip time between the client and the platform server; the device end receives a delay acquisition response from the platform server, wherein the delay acquisition response carries a third smooth round-trip time between the platform server and the second network address translation device; the device end determines a target time for sending a penetration handshake packet to the client based on the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time, and sends the penetration handshake packet to the client at the target time.
[0007] In an exemplary embodiment, the device side determines the target time for sending the penetration handshake packet to the client based on the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time, including: the device side determines the waiting time based on the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time; the device side determines the target time for sending the penetration handshake packet to the platform server based on the waiting time.
[0008] In an exemplary embodiment, the device side determines the target time for sending the penetration handshake packet to the platform server based on the waiting time, including: when the device side sends a connection establishment response to the platform server at a first time, the sum of the first time and the waiting time is determined as the target time; the device side sends the penetration handshake packet to the client at the target time.
[0009] In an exemplary embodiment, the device end determines the waiting period based on the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time, including: the device end determines the sum of the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time as the total smooth round-trip time; the device end determines the ratio of the total smooth round-trip time to the value two as the waiting period.
[0010] In an exemplary embodiment, before the device side receives a target connection request from the platform server, the method further includes: the client sends a first connection request to the platform server, wherein the first connection request carries a second smooth round-trip time between the client and the platform server; the platform server obtains the first smooth round-trip time based on the second smooth round-trip time and the smooth round-trip time between the platform server and the first network address translation device, and the platform server adds the second smooth round-trip time to the first connection request to obtain the target connection request; the platform server sends the target connection request to the device side.
[0011] In an exemplary embodiment, before the client sends a first connection establishment request to the platform server, the method further includes: the client periodically sending a session traversal request to N session traversal services of the platform server, wherein N is an integer greater than 1, and the port numbers of the N session traversal services are different; the client receives N session responses returned by the platform server, wherein the session responses carry the external network address and port number converted by the first network address translation device; and the client determines the type of the first network address translation device based on the N port numbers or N external network addresses carried in the N session responses.
[0012] In an exemplary embodiment, the client determines the type of the first network address translation device based on the N port numbers or N external network addresses carried in the N session responses, including: when the N port numbers are the same, the client determines that the type of the first network address translation device is a cone address translation device; otherwise, the client determines that the type of the first network address translation device is a symmetric address translation device; or, when the N external network addresses are the same, the client determines that the type of the first network address translation device is a cone address translation device; otherwise, the client determines that the type of the first network address translation device is a symmetric address translation device.
[0013] In an exemplary embodiment, the method further includes: when the type of the first network address translation device is the cone address translation device, the client sends one penetration handshake packet to the device end; when the type of the first network address translation device is the symmetric address translation device, the client sends M penetration handshake packets to the device end, wherein the M penetration handshake packets are divided into S groups, and when the client sends the i-th penetration handshake packet in the S-th group to achieve penetration of the first network address translation device and the second network address translation device, the target time is the time when any one of the clients sends the penetration handshake packet to the client, the time interval between two adjacent groups of penetration handshake packets is a preset value, and M, S, and i are integers.
[0014] In an exemplary embodiment, the method further includes: when the client sends a j-th session traversal service sending a session traversal request to the N session traversal services, the client obtains an average round-trip delay between the platform server and the first network address translation device from the platform server, where j is an integer greater than or equal to 1; the client determines a weighted sum of the average round-trip delay and the j-1th smooth round-trip time as the j-th smooth round-trip time, where, when j is greater than 1, the j-1th smooth round-trip time is the smoothed round-trip time obtained when the device sends the j-1th session traversal service sending a session traversal request to the platform server; when j is equal to 1, the j-1th smooth round-trip time is equal to the average round-trip delay, and the j-th smooth round-trip time is the smoothed round-trip time between the client and the platform server.
[0015] In an exemplary embodiment, after the client determines the weighted sum of the average round-trip delay and the j-1th smooth round-trip time as the jth smooth round-trip time, the method further includes: the client determines the jth deviation round-trip time based on the average round-trip delay and the jth smooth round-trip time, wherein the jth deviation round-trip time is the deviation round-trip time between the client and the platform server.
[0016] In an exemplary embodiment, the method also includes: the device side sends a connection response to the client side within a preset time after receiving the target connection request, and the client side sends a penetration handshake packet to the device side when receiving the connection response; when the client side receives the penetration handshake packet sent by the device side and the target conditions are met, the first network address translation device and the second network address translation device are successfully penetrated.
[0017] In an exemplary embodiment, the method further includes: the device side determines the sum of a first deviation round-trip time between the client and the first network address translation device, a second deviation round-trip time between the client and the platform server, and a third deviation round-trip time between the second network address translation device and the platform server as a target sum; the device side determines the difference between a fourth smoothed round-trip time between the first network address translation device and the second network address translation device and a fourth deviation round-trip time between the first network address translation device and the second network address translation device as a target difference; the target condition includes: the target sum is less than the target difference.
[0018] According to another embodiment of the present invention, a device for sending a penetration handshake packet is provided, including: a first receiving module, used to receive a target connection establishment request from a platform server, wherein the target connection establishment request carries a first smooth round-trip time between the client and the first network address translation device, and a second smooth round-trip time between the client and the platform server; a second receiving module, used to receive a delay acquisition response from the platform server, wherein the delay acquisition response carries a third smooth round-trip time between the platform server and the second network address translation device; a determination module, used to determine a target time for sending the penetration handshake packet to the client based on the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time, and send the penetration handshake packet to the client at the target time.
[0019] According to yet another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above methods are implemented.
[0020] According to another embodiment of the present invention, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform the steps in any one of the above method embodiments.
[0021] According to yet another embodiment of the present invention, a computer program product is provided, comprising computer instructions, which implement the steps of any of the above methods when executed by a processor.
[0022] According to the present invention, by receiving the target connection request sent by the platform server, the first smooth round-trip time between the client and the first network address translation device and the second smooth round-trip time between the client and the platform server are obtained, and the delay acquisition response sent by the platform server is received to obtain the third smooth round-trip time between the platform server and the second network address translation device, thereby determining the target time according to the first smooth round-trip time, the second smooth round-trip time and the third smooth round-trip time to instruct the device end to send a penetration handshake packet to the client at the target time, ensuring that the penetration handshake packets sent by the client and the device end arrive at the opposite end export NAT at the same time, avoiding the different time when the connectivity detection message (i.e., the penetration handshake packet) arrives at the end export NAT due to the timing difference, causing the NAT mapping port of the local connectivity detection message to jump, thereby causing the NAT penetration failure, which is conducive to the stable connection between the client and the device end, ensuring the communication quality and stability between the client and the device end, and improving the user experience. Therefore, the problem of NAT penetration failure caused by the timing difference of the connectivity detection message arriving at the opposite end export NAT in the related art can be solved, and the effect of improving the success rate of NAT penetration can be achieved. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 is a schematic diagram of a full cone NAT structure according to an embodiment of the present invention;
[0024] Figure 2 2. It is a schematic diagram of a restricted cone NAT structure according to an embodiment of the present invention;
[0025] Figure 3 1 is a block diagram of a port-restricted cone NAT structure according to an embodiment of the present invention;
[0026] Figure 4 is a schematic diagram of a symmetric NAT structure according to an embodiment of the present invention;
[0027] Figure 5 1 is a hardware structure block diagram of a mobile terminal according to a method for sending a penetration handshake packet according to an embodiment of the present invention;
[0028] Figure 6is a flowchart of a method for sending a penetration handshake packet according to an embodiment of the present invention;
[0029] Figure 7 is a NAT traversal flow chart according to an embodiment of the present invention;
[0030] Figure 8 is a timing diagram of NAT penetration according to an embodiment of the present invention;
[0031] Figure 9 is a schematic diagram of a penetration process data flow according to an embodiment of the present invention;
[0032] Figure 10 is a timing diagram of a NAT type identification process according to an embodiment of the present invention;
[0033] Figure 11 is a system structure diagram according to an embodiment of the present invention;
[0034] Figure 12 is a timing diagram of a terminal information exchange process according to an embodiment of the present invention;
[0035] Figure 13 This is Example 1 of the timing control time axis of DN2 being greater than CN1 according to an embodiment of the present invention;
[0036] Figure 14 This is Example 1 of the timing control time axis of DN2 being less than CN1 according to an embodiment of the present invention;
[0037] Figure 15 This is Example 2 of the timing control time axis where DN2 is greater than CN1 according to an embodiment of the present invention;
[0038] Figure 16 This is Example 2 of the timing control time axis where DN2 is less than CN1 according to an embodiment of the present invention;
[0039] Figure 17 4 is a structural block diagram of an apparatus for sending a penetration handshake packet according to an embodiment of the present invention. DETAILED DESCRIPTION
[0040] The prerequisite for implementing NAT (Network Address Translation) traversal technology is to identify the NAT type. This is because different NAT types process network packets in different ways, which affects the success rate of NAT traversal. Currently, the main NAT types are as follows:
[0041] Full Cone NAT: Figure 1As shown in the figure, all requests sent from the same private IP address and port (IP1:Port1) will be mapped to the same public IP address and port (IP:Port), and any external host (Public-PC2, Public-PC3) can communicate with the internal host (Private-PC1) by sending packets to the mapped public IP address and port.
[0042] Restricted Cone NAT: Figure 2 As shown in the figure, all requests sent from the same private IP address and port (IP1:Port1) will be mapped to the same public IP and port (IP:Port). Unlike the complete cone, the external host (Public-PC2) can send a message to the internal host (Private-PC1) only if the internal host (Private-PC1) has previously sent a message to the external host (Public-PC2). Otherwise, the external host (Public-PC3) cannot send a message to the internal host (Private-PC1).
[0043] Port Restricted Cone NAT: Figure 3 As shown, it is similar to the restricted cone, except that it includes the port number. That is, if an external host (Public-PC2 IP2:Port2) wants to send a message to the internal host (Private-PC1 IP1:Port1), this internal host (Private-PC1 IP1:Port1) must have previously sent a message to this IP address and port (IP2:Port2).
[0044] Symmetric: such as Figure 4 As shown in the figure, all requests sent from the same private IP address and port (IP1:Port1) to a specific destination IP address and port will be mapped to the same IP address and port. If the same host (Private-PC1) sends a packet using the same source address and port number (IP1:Port1) but to different destinations (Public-PC2, Public-PC4), NAT will use different mappings. Furthermore, only the external host that receives the data can send a packet back to the internal host.
[0045] Most operators provide optical modem Internet access services that are cone NAT, while fiber-to-the-home, 4G / 5G networks, public WIFI, etc. are all symmetric NAT for security reasons. The difficulty of penetrating different NAT types varies. From difficult to easy, they are: symmetric vs. symmetric, symmetric vs. cone or cone vs. symmetric, cone vs. cone. When one or both sides are cone NAT networks, port guessing is easier to hit and the penetration success rate is high. However, existing NAT devices have a connection tracking (Conntrack) function, which ensures that the five-tuple information of the uplink and downlink of the NAT device does not conflict. This will cause the NAT mapping port of the local connectivity detection message to jump when the connectivity detection message of the other end arrives at the egress NAT before the local end, resulting in the failure of the connectivity detection. When the connectivity detection message of the local end arrives at the egress NAT of the other end first, the same problem will occur. Therefore, how to avoid the NAT penetration failure caused by the timing difference of the connectivity detection message arriving at the egress NAT is an urgent problem to be solved.
[0046] In summary, the present invention proposes a method and device for sending a penetration handshake packet, which ensures that the penetration handshake packets on both ends arrive at the other end's egress NAT at the same time through dynamic packet sending timing control on the device side, thereby avoiding NAT penetration failure caused by the timing difference of the handshake packets arriving at the egress NAT.
[0047] Hereinafter, embodiments of the present invention will be described in detail with reference to the accompanying drawings and in combination with embodiments.
[0048] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0049] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 5 FIG is a hardware structure diagram of a mobile terminal for a method of sending a penetration handshake packet according to an embodiment of the present invention. Figure 5 As shown, the mobile terminal may include one or more ( Figure 5 Only one is shown) a processor 102 (the processor 102 may include but is not limited to a microprocessor MCU or a programmable logic device FPGA and other processing devices) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and an input and output device 108 for communication functions. It will be understood by those skilled in the art that Figure 5 The structure shown is only for illustration and does not limit the structure of the mobile terminal. Figure 5 More or fewer components than shown, or with Figure 5 Different configurations shown.
[0050] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the method for sending a penetration handshake packet in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, implementing the above-mentioned method. The memory 104 may include a high-speed random access memory and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include a memory remotely located relative to the processor 102, and these remote memories may be connected to the mobile terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0051] The transmission device 106 is used to receive or send data via a network. A specific example of the aforementioned network may include a wireless network provided by the mobile terminal's communications provider. In one embodiment, the transmission device 106 includes a network interface controller (NIC), which can be connected to other network devices via a base station to enable communication with the Internet. In another embodiment, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0052] In this embodiment, a method running on the above mobile terminal is provided. Figure 6 is a flow chart of a method for sending a penetration handshake packet according to an embodiment of the present invention. Figure 6 As shown, the process includes the following steps:
[0053] Step S602: The device receives a target connection establishment request from the platform server, wherein the target connection establishment request carries a first smoothed round-trip time between the client and the first network address translation device, and a second smoothed round-trip time between the client and the platform server;
[0054] The platform server can be a specially constructed server program used to transfer data traffic and provide some service interfaces and protocols to help establish connections between different devices. The platform server includes STUN (Session Traversal Utilities for NAT, used for session traversal in a NAT environment) service, signaling relay service, and latency acquisition service. Among them, the STUN service is mainly used to obtain the external network IP address and port of the terminal (client or device) in a NAT environment to establish a peer-to-peer (P2P) connection. The signaling relay service is mainly used to establish communication by relaying signaling through the server when two clients cannot communicate directly, and obtain the external network IP and port of the client and device after NAT. The latency acquisition service is mainly used to obtain latency information between external IP addresses or latency information between IP addresses based on operators and network monitoring service providers, thereby helping the client or device to measure the delay between the client or device and the server in real time to optimize the efficiency and quality of data transmission.
[0055] The above-mentioned device side and client side can be any terminal, such as a mobile phone, computer, tablet, etc., which is mainly used to obtain the external network IP and port after NAT from the STUN service deployed on the platform server in real time, identify the type of NAT closest to the platform server on this side, calculate the smoothed round-trip time and deviation round-trip time between the platform server in real time, and exchange the NAT type, delay information (i.e., round-trip time), and external network IP and port between the client and device side based on the signaling relay service.
[0056] The above-mentioned first network address translation device NAT1 can be the NAT device closest to the platform server between the client and the platform server, that is, the NAT device closest to the platform server connected to the client. The NAT device is mainly responsible for data transmission conversion and management between the private network and the public network (that is, the external network), including IP address conversion, protocol port conversion and network address translation table management.
[0057] The target connection request may be a P2P connection request, which carries the first smoothed round trip time RTT between the client and NAT1. CN1 , and the second smoothed round trip time RTT between the client and the platform server CP , where the first smoothed round trip time RTT CN1 The second smoothed round trip time RTT CP The smoothed round-trip time (RTT) between NAT1 and the platform server obtained by the platform server N1P Second smoothed round trip time RTT calculated in real time CPIt is calculated in real time based on the request and response message timestamps in the NAT type identification process. The device receives the target connection request from the signaling relay service of the platform server.
[0058] Optionally, before the device side receives the target connection request from the platform server, the method also includes: the client sends a first connection request to the platform server, wherein the first connection request carries the second smooth round-trip time between the client and the platform server; the platform server obtains the first smooth round-trip time based on the second smooth round-trip time and the smooth round-trip time between the platform server and the first network address translation device, and the platform server adds the second smooth round-trip time to the first connection request to obtain the target connection request; the platform server sends the target connection request to the device side.
[0059] The first connection request may be a P2P connection request, where the client sends the first connection request to the signaling relay service of the platform server, wherein the first connection request carries the second smoothed round trip time RTT between the client and the platform server. CP After receiving the first connection request, the signaling relay service of the platform server stores the second smoothed round trip time RTT CP And send the second smoothed round trip time RTT between the client and the platform server to the delay acquisition service of the platform server. CP At this time, the platform server's delay acquisition service receives the client's delay acquisition request, according to the second smooth round-trip time RTT CP and the smoothed round trip time RTT between the platform server and the first network address translation device (NAT1) N1P , get the first smoothed round trip time RTT between the client and NAT1 CN1 , and will carry the first smoothed round trip time RTT CN1 The client delay obtains the response and sends it to the signaling relay service of the platform server; after that, the signaling relay service of the platform server will carry the first smoothed round trip time RTT CN1 and the second smoothed round trip time RTT CP The target connection request is sent to the device end; the device end receives the target connection request from the signaling transfer service of the platform server.
[0060] Optionally, the first smoothed round trip time may be obtained by the following formula:
[0061] RTT CN1 =RTT CP -RTT N1P
[0062] Among them, RTT CN1 is the first smoothed round trip time, RTT CP is the second smoothed round trip time, RTT N1P It is the smoothed round trip time between the platform server and NAT1. The smoothed round trip time can be obtained by directly matching the client's external network IP address through the server's delay acquisition service.
[0063] Step S604: The device receives a latency acquisition response from the platform server, wherein the latency acquisition response carries a third smoothed round-trip time between the platform server and the second network address translation device;
[0064] The above-mentioned second network address translation device NAT2 can be the NAT device closest to the platform server between the device end and the platform server, that is, the NAT device closest to the platform server connected to the device end. The NAT device is mainly responsible for data transmission conversion and management between the private network and the public network (that is, the external network), including IP address conversion, protocol port conversion and network address translation table management.
[0065] The above delay acquisition response can be a delay acquisition response of the device end used by the delay acquisition service of the platform server to feedback the round-trip time between the platform server and NAT, for example, to feedback the third smoothed round-trip time RTT between the platform server and NAT2. N2P The delay acquisition response carries the third smoothed round trip time RTT between the device and NAT2 N2P , where the third smoothed round trip time RTT N2P The latency acquisition service of the platform server periodically obtains the data from the operator and network monitoring service provider. The device receives the latency acquisition service from the platform server and uses it to feedback the third smoothed round trip time (RTT) between the platform server and NAT2. N2P It should be noted that when obtaining the third smoothed round-trip time, based on the capabilities of the operator and network monitoring service provider, priority is given to obtaining the real-time smoothed round-trip time between external IP addresses. If this is not supported, the real-time smoothed round-trip time between IP addresses is obtained through the geographic location information corresponding to the IP address.
[0066] Step S606: The device determines a target time for sending a penetration handshake packet to the client based on the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time, and sends the penetration handshake packet to the client at the target time.
[0067] The aforementioned handshake packet is a special data packet used to establish a communication connection, primarily for traversing NAT1 and NAT2. This handshake packet contains specific information that allows the NAT traversal service to identify and process these communication requests, thereby enabling normal communication between the client and server. During NAT traversal, communication between the client or device and the platform server may be restricted due to the presence of a NAT device. Therefore, in the case of NAT1 and NAT2 traversal, direct information exchange is allowed between the client and the device.
[0068] The above-mentioned target time can be the time when the device side sends the penetration handshake packet, wherein the penetration handshake packet sent by the device side at the target time can arrive at the opposite end exit NAT (that is, the NAT on the opposite end closest to the platform server) at the same time as the penetration handshake packet sent by the client side; the device side determines the target time for sending the penetration handshake packet to the client side based on the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time, and sends the penetration handshake packet to the client side at the target time, thereby ensuring that the penetration handshake packets sent by the client side and the device side arrive at the opposite end exit NAT at the same time, avoiding the different arrival times of the connectivity detection message (that is, the penetration handshake packet) at the end exit NAT due to timing differences, causing the NAT mapping port of the local connectivity detection message to jump, thereby causing NAT penetration failure, improving the success rate of NAT penetration, and being conducive to a stable connection between the client side and the device side, ensuring the communication quality and stability between the client side and the device side, and improving user experience.
[0069] Specifically, the device side determines the waiting time according to the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time; the device side determines the target time for sending the penetration handshake packet to the client according to the waiting time.
[0070] The above waiting time can be the time it takes for the device to wait between sending the P2P connection establishment response and sending the penetration handshake packet. Through the waiting time, the target time for the device to send the penetration handshake packet to the client can be determined, thereby ensuring that the penetration handshake packets sent by the client and the device reach the peer egress NAT at the same time.
[0071] Optionally, the device side determines the target time for sending the penetration handshake packet to the platform server based on the waiting time, including: when the device side sends a connection establishment response to the signaling relay service of the platform server at a first time, the sum of the first time and the waiting time is determined as the target time; the device side sends the penetration handshake packet to the client at the target time.
[0072] Optionally, the execution entity of the above steps can be a background processor, or other devices with similar processing capabilities, or a machine that integrates at least an image acquisition device and a data processing device, wherein the image acquisition device may include a graphics acquisition module such as a camera, and the data processing device may include a computer, a mobile phone and other terminals, but is not limited to this.
[0073] Through the above steps, by receiving the target connection request sent by the signaling relay service of the platform server, the first smooth round-trip time between the client and the first network address translation device and the second smooth round-trip time between the client and the platform server are obtained, and by receiving the delay acquisition response sent by the delay acquisition service of the platform server, the third smooth round-trip time between the device end and the second network address translation device is obtained, thereby determining the target time according to the first smooth round-trip time, the second smooth round-trip time and the third smooth round-trip time, so as to instruct the device end to send a penetration handshake packet to the client at the target time, ensuring that the penetration handshake packets sent by the client and the device end arrive at the opposite end export NAT at the same time, avoiding the different time when the connectivity detection message (i.e., the penetration handshake packet) arrives at the end export NAT due to the timing difference, causing the NAT mapping port of the local connectivity detection message to jump, thereby causing the NAT penetration failure, which is conducive to the stable connection between the client and the device end, ensuring the communication quality and stability between the client and the device end, and improving the user experience. The problem of NAT penetration failure caused by the timing difference of the connectivity detection message arriving at the opposite end export NAT in the related technology is solved, and the success rate of NAT penetration is improved.
[0074] As an optional implementation, Figure 7 NAT penetration flow chart according to an embodiment of the present invention, such as Figure 7 As shown, the main process includes:
[0075] Client: After sending a P2P connection request, it receives a P2P connection response and sends a penetration handshake packet.
[0076] Device side: After receiving the P2P connection request, it obtains the delay information (i.e., the third smoothed round-trip time) from the delay acquisition service of the platform server, calculates the timing control TC value (i.e., the waiting time), and then sends a P2P connection response. After waiting for the TC time, it sends a penetration handshake packet.
[0077] Among them, the specific NAT penetration timing diagram is as follows Figure 8 As shown:
[0078] S801: The client sends a P2P connection establishment request to the platform server. After receiving the P2P connection establishment request sent by the client, the signaling relay service of the platform server forwards the P2P connection establishment request to the device.
[0079] S802: The device receives a P2P connection establishment request forwarded by the signaling relay service of the platform server, calculates the waiting time (TC), and then sends a P2P connection establishment response to the platform server while waiting for the TC.
[0080] S803: After receiving the P2P connection establishment response sent by the device, the signaling relay service of the platform server forwards the P2P connection establishment response to the client;
[0081] S804: After receiving the P2P connection establishment response forwarded by the signaling relay service of the platform server, the client sends a transparent handshake packet to the device;
[0082] S805: After waiting for the TC time, the device sends a penetration handshake packet to the client.
[0083] This ensures that the penetration handshake packets sent by the client and the device reach the other end's egress NAT at the same time, avoiding the situation where the connectivity detection message (i.e., the penetration handshake packet) arrives at the end egress NAT at different times due to timing differences, causing the NAT mapping port of the local connectivity detection message to jump, thereby causing NAT penetration failure.
[0084] As an optional implementation, the device end determines the waiting period based on the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time, including: the device end determines the sum of the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time as the total smooth round-trip time; the device end determines the ratio of the total smooth round-trip time to the value two as the waiting period.
[0085] Optionally, Figure 9 Schematic diagram of the penetration process data flow according to an embodiment of the present invention. Figure 9 As shown in the figure, the penetration process mainly includes the following data flows:
[0086] C->N1(CN1): client-side handshake packet data flow;
[0087] D->N2 (DN2): Device-side penetrating handshake packet data flow;
[0088] N1<->N2(N1N2 / N2N1): bidirectional penetrating handshake packet data flow;
[0089] ((D->N2)`+N2->P+P->N1+N1->C)(DP+CP): device-side P2P connection response data flow;
[0090] Due to the different timings of sending the handshake packets between the device and the client, NAT penetration failure caused by the timing difference of the handshake packets reaching the NAT of the other end cannot be avoided. The time required for D->P+C->P+C->N1+N1->N2 is equal to D->N2+N2->N1, that is, RTT DP +RTT CP +RTT CN1 +RTT N1N2 =RTT DN2 +RTT N2N1 , due to RTT N1N2 =RTT N2N1 , so only RTT is needed DP +RTT CP +RTT CN1 =RTT DN2 Therefore, it is necessary to introduce timing control T (i.e., the sum of smooth round-trip time) to control the device end to send the penetration handshake packet so that RTT DP +RTT CP +RTT CN1 =RTT DN2 +T. At the same time, due to RTT DP =RTT DN2 +RTT N2P , therefore, only RTT is required N2P +RTT CP +RTT CN1 =T. Specifically, the waiting time can be obtained by the following formula:
[0091]
[0092] Among them, TC is the waiting time, RTT N2P is the third smoothed round trip time, RTT CP is the second smoothed round trip time, RTT CN1 is the first smoothed round trip time.
[0093] As an optional implementation, before the client sends the first connection establishment request to the platform server, the method further includes: the client periodically sends a session traversal request to N session traversal services of the platform server, wherein N is an integer greater than 1, and the port numbers of the N session traversal services are different; the client receives N session responses returned by the platform server, wherein the session responses carry the external network address and port number converted by the first network address translation device; the client determines the type of the first network address translation device based on the N port numbers or N external network addresses carried by the N session responses.
[0094] The above-mentioned session traversal service can be a STUN service deployed by the platform server, used to determine the type of NAT; optionally, when the N port numbers are the same, the client determines that the type of the first network address translation device is a cone address translation device; otherwise, it determines that the type of the first network address translation device is a symmetric address translation device; or, when the N external network addresses are the same, the client determines that the type of the first network address translation device is a cone address translation device; otherwise, it determines that the type of the first network address translation device is a symmetric address translation device.
[0095] Figure 10 NAT type identification process timing diagram according to an embodiment of the present invention, such as Figure 10 As shown, N STUN services are deployed in the platform server. Each STUN service is bound to a different port number. The specific type identification process is as follows:
[0096] S1001: The client periodically initiates STUN requests to N STUN services on the platform and obtains the external IP and port after the egress NAT returned by the STUN service.
[0097] S1002: Based on the external IP and port returned by each of the N STUN services, if the external port numbers returned by multiple STUN services are the same, the client egress NAT type can be determined to be cone-shaped; otherwise, the client egress NAT type is considered to be symmetric; or if the external IPs returned by multiple STUN services are the same, the client egress NAT type can be determined to be cone-shaped; otherwise, the client egress NAT type is considered to be symmetric.
[0098] As an optional embodiment, the method also includes: when the type of the first network address translation device is the cone address translation device, the client sends one penetration handshake packet to the device end; when the type of the first network address translation device is the symmetric address translation device, the client sends M penetration handshake packets to the device end, wherein the M penetration handshake packets are divided into S groups, and when the client sends the i-th penetration handshake packet in the S-th group to achieve penetration of the first network address translation device and the second network address translation device, the target time is the time when any one of the clients sends the penetration handshake packet to the client, the time interval between two adjacent groups of penetration handshake packets is a preset value, and M, S, and i are integers.
[0099] The above-mentioned first network address translation device NAT1 can be conical or symmetric. Among them, the requests sent from the same private network IP address and port by the conical NAT will be mapped to the same public network IP address and port, while the requests sent from the same private network IP address and port by the symmetric NAT may be mapped to different public network IP addresses and ports.
[0100] When the type of the first network address translation device is a cone-shaped address translation device, the client only needs to send one penetration handshake packet to the device end; when the type of the first network address translation device is a symmetric address translation device, the client needs to send M penetration handshake packets to the device end, that is, send as many penetration handshake packets as possible, so as to ensure that as many NAT1 external network IPs as possible are covered, thereby improving the success rate of NAT penetration.
[0101] As an optional implementation, the method further includes: when the client sends the j-th session traversal service to the N session traversal services, the client obtains the average round-trip delay between the platform server and the first network address translation device from the platform server, where j is an integer greater than or equal to 1; the client determines the j-th smoothed round-trip time as a weighted sum of the average round-trip delay and the j-1th smoothed round-trip time, where, when j is greater than 1, the j-1th smoothed round-trip time is the smoothed round-trip time obtained by the device end sending the j-1th session traversal service to the platform server. When j is equal to 1, the j-1th smoothed round-trip time is equal to the average round-trip delay, and the j-th smoothed round-trip time is the smoothed round-trip time between the client and the platform server.
[0102] The second smoothed round trip time can be calculated in real time based on the request message (i.e., session request) timestamp and the response message (i.e., session response) timestamp in the timed NAT type identification process. Specifically, the second smoothed round trip time can be obtained by the following formula:
[0103]
[0104] Among them, RTT CP is the second smoothed round trip time, where the latest j-th smoothed round trip time is the second smoothed round trip time, RTT j-1 is the j-1th smoothed round trip time, RTT j is the average round trip delay, α is a preset weight, 0<α<1.
[0105] As an optional implementation, after the client determines the weighted sum of the average round-trip delay and the j-1th smooth round-trip time as the jth smooth round-trip time, the method further includes: the client determines the jth deviation round-trip time based on the average round-trip delay and the jth smooth round-trip time, wherein the jth deviation round-trip time is the deviation round-trip time between the client and the platform server.
[0106] Specifically, the j-th deviation round-trip time can be obtained through the following announcement:
[0107]
[0108] Among them, ΔRTT CP is the jth deviation round trip time, RTT j is the average round trip delay, ΔRTT j-1 is the j-1th deviation round trip time, RTT CP is the j-th smoothed round trip time, β is a preset weight, 0<β<1.
[0109] As an optional implementation, the method also includes: the device side sends a connection response to the client side within a preset time after receiving the connection request, and the client side sends a penetration handshake packet to the device side when receiving the connection response; when the client side receives the penetration handshake packet sent by the device side and meets the target conditions, the first network address translation device and the second network address translation device are successfully penetrated.
[0110] The above-mentioned preset duration can be used by the device end to obtain the duration of the smoothed round-trip time between the device end and the second network address translation device (NAT2); within the preset duration, the device end sends a 100Tring temporary response to the client through the signaling relay service of the platform server, wherein the 100Tring temporary response is used to indicate that the P2P connection request sent by the client is being processed. At the same time, the device end creates a new connection to initiate a delay acquisition request to the delay acquisition service of the platform server, thereby obtaining the smoothed round-trip time between the device end and NAT2 by receiving the delay acquisition response returned by the delay acquisition service of the platform server, and then sending a connection response to the client.
[0111] The above-mentioned target condition can be the time condition between the client receiving the penetration handshake packet sent by the device and the device receiving the penetration handshake packet sent by the client. Only when the client receives the penetration handshake packet sent by the device and the corresponding time condition is met, can the first network address translation device and the second network address translation device be successfully penetrated.
[0112] As an optional implementation, the method further includes: the device side determines the sum of the first deviation round-trip time between the client and the first network address translation device, the second deviation round-trip time between the client and the platform server, and the third deviation round-trip time between the second network address translation device and the platform server as the target sum; the device side determines the difference between the fourth smooth round-trip time between the first network address translation device and the second network address translation device and the fourth deviation round-trip time between the first network address translation device and the second network address translation device as the target difference; the target condition includes: the target sum is less than the target difference.
[0113] Specifically, the target condition can be expressed by the following formula:
[0114] ΔRTT CP +ΔRTT N2P +ΔRTT CN1 <RTT N1N2 -ΔRTT N1N2
[0115] Among them, ΔRTT CP is the second deviation round trip time, ΔRTT N2P is the third deviation round trip time, ΔRTT CN1 is the first deviation round trip time, RTT N1N2 is the fourth smoothed round trip time, ΔRTT N1N2 is the fourth deviation round trip time.
[0116] As an optional implementation, Figure 11 : is a system structure diagram according to an embodiment of the present invention, such as Figure 11 The system mainly includes:
[0117] Platform server: including STUN service, signaling transfer service and delay acquisition service,
[0118] Responsible for signaling transfer between the client and the device;
[0119] Responsible for obtaining the external network IP and port after NAT on the client and device sides;
[0120] Obtain latency information between external IP addresses based on operators and network monitoring service providers;
[0121] Obtain latency information between IP locations based on operators and network monitoring service providers;
[0122] NAT device: responsible for data transmission conversion and management between private and public networks, including IP address translation, protocol port translation, and network address translation table management;
[0123] Terminal (client / device):
[0124] Obtain the external IP and port after NAT from the STUN service in real time, and identify the NAT type of the local egress NAT;
[0125] Real-time measurement of the weighted average round-trip time (smoothed round-trip time) and the weighted average RTT deviation (deviation round-trip time) between the platform and the platform;
[0126] Based on the signaling relay service, the client and device sides exchange NAT type, latency information, and external IP and port.
[0127] As an optional implementation, Figure 12 is a timing diagram of the terminal information exchange process according to an embodiment of the present invention, such as Figure 12 The specific process is as follows:
[0128] S1201: The client sends a P2P (Peer-to-Peer) connection request to the signaling relay service. The connection request carries the local (client-side) NAT type, smoothed RTT (the second smoothed round-trip time between the client and the platform server), and offset RTT (the second offset round-trip time between the client and the platform server), and fills in the local NAT type, smoothed RTT, and offset RTT.
[0129] S1202: The signaling relay service identifies the source IP and source port information in the client network message and fills them into the protocol field of the request field (P2P connection request) as the client's external network IP and port data. At the same time, the signaling relay service sends a delay acquisition request to the delay acquisition service. The delay acquisition request carries the client's external network IP, smoothed RTT, and offset RTT.
[0130] S1203, the latency acquisition service obtains the smoothed RTT (smoothed round-trip time) and the deviation RTT (deviation round-trip time) between the platform server and the client's egress NAT (NAT1) based on the client's external network IP query, and calculates the smoothed RTT (first smoothed round-trip time between the client and the first network address translation device) and the deviation RTT (first deviation round-trip time between the client and the first network address translation device) between the client and the egress NAT;
[0131] S1204: The latency acquisition service sends a latency acquisition response to the signaling relay service, where the latency acquisition response carries the smoothed RTT and the offset RTT between the client and the egress NAT.
[0132] S1205: The signaling relay service receives the latency acquisition response, fills the smoothed RTT and the offset RTT between the client and the egress NAT into the P2P connection request protocol field, and forwards the P2P connection request to the device.
[0133] S1206: The device caches the client-side NAT type, smoothed RTT and offset RTT, public network IP and port, and the smoothed RTT and offset RTT between the client and the egress NAT, and sends a 100Trying provisional response to the signaling relay service, which forwards it to the client, indicating that the P2P connection establishment request is being processed.
[0134] S1207: The device creates a new connection and sends a latency acquisition request to the latency acquisition service. The latency acquisition request carries the smoothed RTT (smoothed round-trip time between the device and the platform server) and the deviation RTT (device-side deviation round-trip time).
[0135] S1208, the latency acquisition service obtains the smoothed RTT (third smoothed round-trip time) and the deviation RTT (third deviation round-trip time) between the platform server and the device's egress NAT (NAT2) based on the device's external network IP address query, and calculates the smoothed RTT (smoothed round-trip time) and the deviation RTT (deviation round-trip time) between the device and the egress NAT;
[0136] S1209: The latency acquisition service sends a latency acquisition response to the device. The latency acquisition response carries the smoothed RTT, deviation RTT, and external IP and port of the device from the device to the egress NAT.
[0137] S1210: The device caches the external IP and port of the device, as well as the smoothed RTT and deviation RTT between the device and the egress NAT.
[0138] S1211: The device sends a P2P connection establishment response to the signaling relay service. The P2P connection establishment response carries and populates the local (device side) NAT type, external IP address, and port. The signaling relay service then forwards the P2P connection establishment response to the client.
[0139] S1212: The client caches the NAT type, external IP address, and port number of the device.
[0140] It's important to note that in the above process, the signaling relay service matches requests and responses based on the unique session IDs in the P2P connection request and response. To avoid a large RTT deviation between the terminal's NAT device and the platform server, a CDN (Content Delivery Network) can be introduced to deliver the requested content to the server node closest to the terminal.
[0141] As an optional implementation, in a double-cone NAT scenario, the terminal (client or device) sends a penetration handshake packet to the other party's external network IP and port. When the handshake packets of both sides arrive at the local NAT before the other party's handshake packets, the NAT penetration success rate is high. Therefore, the device side needs to reply to the P2P connection response and wait for the TC time, and then send a penetration handshake packet to the client's external network IP and port. After receiving the P2P connection response, the client side can send a penetration handshake packet to the device's external network IP and port. The entire penetration process timing control is executed by the device side. Optionally, Figure 13 This is Example 1 of the timing control time axis of DN2 being greater than CN1 according to an embodiment of the present invention; Figure 14 This is Example 1 of the timing control time axis in which DN2 is less than CN1 according to an embodiment of the present invention, wherein C represents the client, D represents the device, N1 represents NAT1, and N2 represents NAT2.
[0142] As an optional implementation, in a NAT scenario where one side is symmetric and the other side is cone-shaped, when the symmetric side sends a handshake packet to the cone-shaped, due to the change in the target IP address, the egress NAT will reallocate a new NAT port according to the symmetric principle, resulting in the cone-shaped packet being rejected by the NAT device when sending to the old NAT port. Therefore, a birthday attack algorithm needs to be used for this NAT scenario, the essence of which is to achieve the penetration process through the principle of random collision.
[0143] The specific operation is as follows:
[0144] Step 1: The symmetric terminal creates multiple sockets and sends handshake packets to the external IP and port of the cone terminal. These packets are mapped to different external ports when exiting NAT.
[0145] Step 2: The cone-side terminal randomly sends a penetration handshake packet to different external network ports of the other party to see if one of the target ports hits the symmetrically mapped external network port. If so, a connection is successfully established.
[0146] The formula for calculating the penetration success rate is:
[0147]
[0148] Among them, 64511 is the port limit of 65535 minus the system default occupancy of 1024; Y is the number of guesses of the external network port on the cone side (Y handshake packets); X is the number of mapped ports on the symmetric side (X handshake packets); for example: when Y = 2400 and X = 200, the penetration success probability is 99.94%.
[0149] Optionally, Figure 15 This is Example 2 of the timing control time axis where DN2 is greater than CN1 according to an embodiment of the present invention; Figure 16 This is Example 2 of the timing control time axis in which DN2 is less than CN1 according to an embodiment of the present invention, wherein C represents the client, D represents the device, N1 represents NAT1, and N2 represents NAT2.
[0150] It should be noted that in actual use, in order to ensure successful penetration in this scenario, the X handshake packets of the symmetrical side terminal and the Y handshake packets of the conical side terminal must arrive at the exit NAT on this side before the other party. However, because there are too many packets, there will be a large time difference between the first packet and the last packet. If this time difference is greater than the time consumed between the two end exit NATs, some data packets will arrive at the other end exit NAT in advance, so X and Y need to be split into multiple groups of x and y, and the number of packets sent in each group of x and y is controlled to avoid time deviation caused by the time consumption of packet sending. The sending interval of each group of x and y can be a fixed value, which is agreed in advance by the client and the device. After the first group of penetration handshake packets is sent, the remaining groups of handshake packets are sent at fixed intervals. The specific formula for calculating the penetration success rate is as follows:
[0151]
[0152] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus the necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, or network device, etc.) to execute the methods described in each embodiment of the present invention.
[0153] This embodiment also provides a device for sending a penetration handshake packet, which is used to implement the above-mentioned embodiments and preferred implementations. Details that have already been described will not be repeated. As used below, the term "module" may refer to a combination of software and / or hardware that implements a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, implementation using hardware, or a combination of software and hardware, is also possible and contemplated.
[0154] Figure 17 is a structural block diagram of an apparatus for sending a penetration handshake packet according to an embodiment of the present invention. Figure 17As shown, the device includes: a first receiving module 1702, used to receive a target connection establishment request from a platform server, wherein the target connection establishment request carries a first smooth round-trip time between the client and the first network address translation device, and a second smooth round-trip time between the client and the platform server; a second receiving module 1704, used to receive a delay acquisition response from the platform server, wherein the delay acquisition response carries a third smooth round-trip time between the platform server and the second network address translation device; a determination module 1706, used to determine a target time for sending a penetration handshake packet to the client based on the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time, and send the penetration handshake packet to the client at the target time.
[0155] In an exemplary embodiment, the device is further used to determine a waiting time based on the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time; and determine the target time for sending a penetration handshake packet to the platform server based on the waiting time.
[0156] In an exemplary embodiment, the device is further configured to, when sending a connection establishment response to the platform server at a first moment, determine the sum of the first moment and the waiting time as the target moment; and send the penetration handshake packet to the client at the target moment.
[0157] In an exemplary embodiment, the device is further used to determine the sum of the first smooth round-trip time, the second smooth round-trip time and the third smooth round-trip time as the total smooth round-trip time; and determine the ratio of the total smooth round-trip time to the value two as the waiting time.
[0158] In an exemplary embodiment, before receiving a target connection request from a platform server, the client is also used to send a first connection request to the platform server, wherein the first connection request carries a second smooth round-trip time between the client and the platform server; the platform server obtains the first smooth round-trip time based on the second smooth round-trip time and the smooth round-trip time between the platform server and the first network address translation device, and the platform server adds the second smooth round-trip time to the first connection request to obtain the target connection request; the platform server sends the target connection request to the device end.
[0159] In an exemplary embodiment, the client is further used to periodically send session traversal requests to N session traversal services of the platform server, where N is an integer greater than 1 and the port numbers of the N session traversal services are different; receive N session responses returned by the platform server, where the session responses carry the external network address and port number converted by the first network address translation device; and determine the type of the first network address translation device based on the N port numbers or N external network addresses carried by the N session responses.
[0160] In an exemplary embodiment, the client is further used to determine, when the N port numbers are the same, that the type of the first network address translation device is a cone-shaped address translation device; otherwise, to determine that the type of the first network address translation device is a symmetric address translation device; or, when the N external network addresses are the same, to determine that the type of the first network address translation device is a cone-shaped address translation device; otherwise, to determine that the type of the first network address translation device is a symmetric address translation device.
[0161] In an exemplary embodiment, the client is also used to send one penetration handshake packet to the device end when the type of the first network address translation device is the cone address translation device; and to send M penetration handshake packets to the device end when the type of the first network address translation device is the symmetric address translation device, wherein the M penetration handshake packets are divided into S groups, and when the client sends the i-th penetration handshake packet in the S-th group to achieve penetration of the first network address translation device and the second network address translation device, the target time is the time when any one of the clients sends the penetration handshake packet to the client, the time interval between two adjacent groups of penetration handshake packets is a preset value, and M, S, and i are integers.
[0162] In an exemplary embodiment, the client is further configured to, when sending a j-th session traversal request to the N session traversal services, obtain an average round-trip delay between the platform server and the first network address translation device from the platform server, where j is an integer greater than or equal to 1; and determine a weighted sum of the average round-trip delay and the j-1th smooth round-trip time as the j-th smooth round-trip time, where, when j is greater than 1, the j-1th smooth round-trip time is the smoothed round-trip time obtained when the device sends the j-1th session traversal request to the platform server; and when j is equal to 1, the j-1th smooth round-trip time is equal to the average round-trip delay, and the j-th smooth round-trip time is the smoothed round-trip time between the client and the platform server.
[0163] In an exemplary embodiment, the client is further configured to determine a jth deviation round trip time based on the average round trip delay and the jth smoothed round trip time, wherein the jth deviation round trip time is the deviation round trip time between the client and the platform server.
[0164] In an exemplary embodiment, the device is also used to send a connection response to the client within a preset time after receiving the target connection request, and the client sends a penetration handshake packet to the device end when receiving the connection response; when the client receives the penetration handshake packet sent by the device end and the target conditions are met, the first network address translation device and the second network address translation device are successfully penetrated.
[0165] In an exemplary embodiment, the apparatus is further configured to determine the sum of a first deviation round-trip time between the client and the first network address translation device, a second deviation round-trip time between the client and the platform server, and a third deviation round-trip time between the second network address translation device and the platform server as a target sum; and to determine the difference between a fourth smoothed round-trip time between the first network address translation device and the second network address translation device and a fourth deviation round-trip time between the first network address translation device and the second network address translation device as a target difference; the target condition comprising: the target sum being less than the target difference.
[0166] It should be noted that the above modules can be implemented through software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0167] An embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, the steps of any of the above methods are implemented.
[0168] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk, or an optical disk.
[0169] An embodiment of the present invention further provides an electronic device, comprising a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0170] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0171] An embodiment of the present invention further provides a computer program product, comprising a computer program, which, when executed by a processor, implements the steps of the method described in each embodiment of the present application.
[0172] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail here.
[0173] Obviously, those skilled in the art will appreciate that the various modules or steps of the present invention described above can be implemented using a general-purpose computing device, can be centralized on a single computing device, or can be distributed across a network of multiple computing devices. They can be implemented using program code executable by the computing device, and thus, can be stored in a storage device and executed by the computing device. In some cases, the steps shown or described herein can be performed in a different order than that shown, or can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the present invention is not limited to any particular combination of hardware and software.
[0174] The foregoing description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Those skilled in the art will readily appreciate that various modifications and variations of the present invention are possible. Any modifications, equivalent substitutions, or improvements made within the principles of the present invention are intended to be within the scope of protection of the present invention.
Claims
1. A method for sending a penetration handshake packet, characterized in that: include: The device receives a target connection establishment request from the platform server, wherein the target connection establishment request carries a first smoothed round-trip time between the client and the first network address translation device, and a second smoothed round-trip time between the client and the platform server; The device receives a latency acquisition response from the platform server, wherein the latency acquisition response carries a third smoothed round trip time between the platform server and the second network address translation device; The device determines a target time for sending a penetration handshake packet to the client according to the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time, and sends the penetration handshake packet to the client at the target time.
2. The method according to claim 1, characterized in that The device determines, according to the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time, a target time for sending a penetration handshake packet to the client, including: The device determines the waiting time according to the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time; The device side determines the target time for sending the penetration handshake packet to the platform server according to the waiting time.
3. The method according to claim 2, characterized in that The device determines the target time for sending the penetration handshake packet to the platform server according to the waiting time, including: When the device sends a connection establishment response to the platform server at a first moment, the sum of the first moment and the waiting time is determined as the target moment; The device sends the penetration handshake packet to the client at the target time.
4. The method according to claim 2, characterized in that: The device determines the waiting time according to the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time, including: The device determines the sum of the first smooth round-trip time, the second smooth round-trip time and the third smooth round-trip time as the total smooth round-trip time; The device determines the waiting time as the ratio of the sum of the smoothed round-trip time and the value 2.
5. The method according to claim 1, characterized in that Before the device receives the target connection establishment request from the platform server, the method further includes: The client sends a first connection establishment request to the platform server, wherein the first connection establishment request carries a second smoothed round trip time between the client and the platform server; The platform server obtains the first smooth round trip time according to the second smooth round trip time and the smooth round trip time between the platform server and the first network address translation device, and the platform server adds the second smooth round trip time to the first connection establishment request to obtain the target connection establishment request; The platform server sends the target connection establishment request to the device end.
6. The method according to claim 5, characterized in that Before the client sends the first connection establishment request to the platform server, the method further includes: The client periodically sends a session traversal request to N session traversal services of the platform server, where N is an integer greater than 1, and the port numbers of the N session traversal services are different; The client receives N session responses returned by the platform server, wherein the session responses carry the external network address and port number converted by the first network address translation device; The client determines the type of the first network address translation device according to the N port numbers or N external network addresses carried by the N session responses.
7. The method according to claim 6, characterized in that The client determines the type of the first network address translation device according to the N port numbers or N external network addresses carried by the N session responses, including: In the case where the N port numbers are the same, the client determines that the type of the first network address translation device is a cone address translation device; otherwise, determines that the type of the first network address translation device is a symmetric address translation device; or, In the case that the N external network addresses are the same, the client determines that the type of the first network address translation device is a cone address translation device; otherwise, determines that the type of the first network address translation device is a symmetric address translation device.
8. The method according to claim 7, characterized in that The method further comprises: In the case that the type of the first network address translation device is the cone address translation device, the client sends one of the penetration handshake packets to the device end; In the case where the type of the first network address translation device is the symmetric address translation device, the client sends M of the penetration handshake packets to the device end, wherein the M penetration handshake packets are divided into S groups, and in the case where the client sends the i-th penetration handshake packet in the S-th group to achieve penetration of the first network address translation device and the second network address translation device, the target time is the time when any one of the clients sends the penetration handshake packet to the client, the time interval between two adjacent groups of penetration handshake packets is a preset value, and M, S, and i are integers.
9. The method according to claim 6, characterized in that The method further comprises: In a case where the client sends a j-th session traversal request to the N session traversal services, the client obtains, from the platform server, an average round-trip delay between the platform server and the first network address translation device, where j is an integer greater than or equal to 1; The client determines the jth smooth round-trip time as the weighted sum of the average round-trip delay and the j-1th smooth round-trip time, wherein, when j is greater than 1, the j-1th smooth round-trip time is the smooth round-trip time obtained by the device end sending a session traversal request to the platform server through the j-1th session traversal service, and when j is equal to 1, the j-1th smooth round-trip time is equal to the average round-trip delay, and the jth smooth round-trip time is the smooth round-trip time between the client and the platform server.
10. The method according to claim 9, characterized in that After the client determines the weighted sum of the average round trip delay and the j-1th smooth round trip time as the jth smooth round trip time, the method further includes: The client determines a jth deviation round trip time according to the average round trip delay and a jth smoothed round trip time, wherein the jth deviation round trip time is a deviation round trip time between the client and the platform server.
11. The method according to claim 1, characterized in that The method further comprises: The device sends a connection establishment response to the client within a preset time after receiving the target connection establishment request, and the client sends a penetration handshake packet to the device when receiving the connection establishment response; When the client receives the penetration handshake packet sent by the device and the target condition is met, the first network address translation device and the second network address translation device are successfully penetrated.
12. The method according to claim 11, characterized in that The method further comprises: The device end determines the sum of a first deviation round-trip time between the client and the first network address translation device, a second deviation round-trip time between the client and the platform server, and a third deviation round-trip time between the second network address translation device and the platform server as a target sum; The device end determines the difference between the fourth smoothed round trip time between the first network address translation device and the second network address translation device and the fourth deviation round trip time between the first network address translation device and the second network address translation device as the target difference; The target condition includes: the target sum is less than the target difference.
13. A device for sending a penetration handshake packet, characterized in that: include: A first receiving module is used to receive a target connection establishment request from a platform server, wherein the target connection establishment request carries a first smoothed round-trip time between the client and the first network address translation device, and a second smoothed round-trip time between the client and the platform server; A second receiving module is configured to receive a latency acquisition response from the platform server, wherein the latency acquisition response carries a third smoothed round trip time between the platform server and the second network address translation device; The determination module is used to determine the target time for sending the penetration handshake packet to the client according to the first smooth round-trip time, the second smooth round-trip time, and the third smooth round-trip time, and send the penetration handshake packet to the client at the target time.
14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program implements the steps of the method described in any one of claims 1 to 12 when executed by a processor.
15. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to perform the method according to any one of claims 1 to 12.
16. A computer program product comprising computer instructions, characterized in that When the computer instructions are executed by a processor, the steps of the method described in any one of claims 1 to 12 are implemented.
Citation Information
Patent Citations
Method for AP configuration management and wireless terminal access control by cloud-side platform
CN107483558A
Scheduling method and scheduling end for FogCDN scene
CN110278254A
UDP (User Datagram Protocol) link monitoring method and system and electronic equipment
CN112838966A
Network address translation type detection method and system and electronic equipment
CN115766654A
TCP NAT traversal method and system based on time synchronization
CN118158190A