Connection establishment method and device, storage medium and electronic device
By establishing a relay connection during NAT penetration and establishing a point-to-point connection according to the network address translation type, the problem of excessive resource consumption during NAT penetration is solved, and the connection success rate and user experience are improved.
Patent Information
- Application Number
- CN202510069349.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-16
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2045-01-16
AI Technical Summary
The resource consumption during NAT penetration is too large, resulting in a high impact on code streaming and equipment resource overhead.
By receiving the data request message from the terminal device, a relay connection is established and the network address translation type of the terminal device and the target device are obtained. According to these types, a point-to-point connection is established, a relay connection is interrupted, and an address exchange is performed through an idle device to achieve a P2P connection.
It improves the connection success rate, reduces resource consumption, optimizes penetration problems in symmetric NAT environments, and ensures business continuity and user experience fluency.
Smart Images

Figure CN119520587B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computers, and in particular to a connection establishment method and device, a storage medium, and an electronic device. Background Art
[0002] With the rapid development of the internet, NAT (Network Address Translation) technology has become a key solution to the IPv4 address shortage. NAT technology allows for the mapping and translation of private IP addresses (such as those used within a local area network) to public IP addresses (used for internet communications). This allows multiple devices to share a single public IP address, effectively alleviating the shortage of IPv4 address resources. However, NAT technology restricts connections to intranet hosts, preventing external hosts from actively connecting to them. This prevents direct communication between hosts on different intranets. NAT traversal technology overcomes this limitation, enabling peer-to-peer (P2P) communication between devices behind a NAT network. This improves network stability, reduces transmission latency, and reduces platform traffic costs.
[0003] NAT traversal technology has varying success rates depending on the NAT type used by the two-way devices. The difficulty of traversal increases with cone-to-cone, cone-to-symmetric, or symmetric-to-cone, or symmetric-to-symmetric. Furthermore, the more challenging NAT traversal processes consume significant device resources, impacting the device's normal services. Preventing the impact of resource consumption on stream transmission during NAT traversal is a pressing issue.
[0004] To address the above-mentioned problems, no effective solutions have been proposed so far. Summary of the Invention
[0005] The embodiments of the present application provide a connection establishment method and apparatus, a storage medium, and an electronic device to at least solve the technical problem that resource consumption during NAT penetration has a significant impact on stream transmission and that device resource overhead is high.
[0006] According to one aspect of an embodiment of the present application, a connection establishment method is provided, comprising: receiving a data request message sent by a terminal device, wherein the data request message is used to request data of a target device, and the terminal device and the target device belong to different local area networks; in response to the data request message, establishing a relay connection between the terminal device and the target device, and obtaining the network address translation type corresponding to the terminal device and the target device, wherein the network address translation type represents a behavior pattern of a device in processing data packets; establishing the terminal device based on whether the network address translation types corresponding to the terminal device and the target device are both symmetric. and a point-to-point connection between the terminal device and the target device, and interrupting the relay connection, wherein, when at least one of the terminal device and the target device is asymmetric, the point-to-point connection is realized by exchanging addresses between the target device and the first idle device, the first idle device and the target device belong to the same local area network, and when the terminal device and the target device are both symmetric, the point-to-point connection is realized by exchanging addresses between the target device, the first idle device and the second idle device, the second idle device and the target device belong to different local area networks, and the network address translation type of the second idle device is the asymmetric type.
[0007] According to another aspect of an embodiment of the present application, a connection establishment device is further provided, comprising: a receiving module for receiving a data request message sent by a terminal device, wherein the data request message is used to request to obtain data of a target device, and the terminal device and the target device belong to different local area networks; an acquisition module for establishing a relay connection between the terminal device and the target device in response to the data request message, and obtaining the network address translation type corresponding to the terminal device and the target device, wherein the network address translation type represents a behavior pattern of a device in processing data packets; a processing module for determining whether the network address translation types corresponding to the terminal device and the target device are both correct. A point-to-point connection is established between the terminal device and the target device, and the relay connection is interrupted, wherein, when at least one of the terminal device and the target device is of an asymmetric type, the point-to-point connection is realized by exchanging addresses between the target device and a first idle device, and the first idle device and the target device belong to the same local area network. When the terminal device and the target device are both of the symmetric type, the point-to-point connection is realized by exchanging addresses between the target device, the first idle device and the second idle device, and the second idle device and the target device belong to different local area networks, and the network address translation type of the second idle device is the asymmetric type.
[0008] In an exemplary embodiment, the device is used to establish a point-to-point connection between the terminal device and the target device and interrupt the relay connection based on whether the network address translation types corresponding to the terminal device and the target device are both symmetric in the following manner: when at least one of the terminal device and the target device is asymmetric, the point-to-point connection is established based on the first idle device and the relay connection is interrupted; when the terminal device and the target device are both symmetric, the point-to-point connection is established based on the first idle device and the second idle device, and the relay connection is interrupted.
[0009] In an exemplary embodiment, the device is used to establish the point-to-point connection based on the first idle device and interrupt the relay connection when at least one of the terminal device and the target device is not of the symmetrical type in the following manner: when at least one of the terminal device and the target device is not of the symmetrical type, receive a first point-to-point connection request sent by the terminal device; in response to the first point-to-point connection request, obtain the device operating status of each device in a first group of devices, wherein the first group of devices and the target device belong to the same local area network; determine a first group of idle devices from the first group of devices based on the device operating status; send the first point-to-point connection request to the first group of idle devices; determine the device in the first group of idle devices that responds to the first point-to-point connection request as the The first idle device establishes a first penetration connection between the first idle device and the terminal device; when the first penetration connection is successfully established, sends a first address exchange request to the target device and the first idle device respectively, wherein the first address exchange request is used to request the target device and the first idle device to exchange address information with each other; when the target device and the first idle device complete the exchange of address information, receives the login request sent by the target device and the first idle device to complete the login of the target device and the first idle device, switches the relay connection to a point-to-point connection between the target device and the first idle device, and interrupts the relay connection, wherein the point-to-point connection is automatically established when the target device and the first idle device complete the login.
[0010] In an exemplary embodiment, the apparatus is configured to establish the point-to-point connection based on the first idle device and the second idle device and interrupt the relay connection when the terminal device and the target device are both of the symmetrical type in the following manner: when the terminal device and the target device are both of the symmetrical type, determine whether the second idle device exists; and when the second idle device exists, establish the point-to-point connection based on the first idle device and the second idle device and interrupt the relay connection.
[0011] In an exemplary embodiment, the device is used to determine whether the second idle device exists when the terminal device and the target device are both of the symmetric type in the following manner: when the terminal device and the target device are both of the symmetric type, receive a second point-to-point connection request sent by the terminal device; in response to the second point-to-point connection request, obtain the device operation status of the second group of devices, wherein the second group of devices and the target device belong to different local area networks, and the network address translation type corresponding to the second group of idle devices is the asymmetric type; determine a second group of idle devices from the second group of devices based on the device operation status; send a point-to-point cascade request to the second group of idle devices; determine the device in the second group of idle devices that responds to the point-to-point cascade request as the second idle device, and establish a second penetration connection between the second idle device and the terminal device.
[0012] In an exemplary embodiment, the device is used to establish the point-to-point connection based on the first idle device and the second idle device and interrupt the relay connection in the presence of the second idle device in the following manner: in the presence of the second idle device, receive a third point-to-point connection request sent by the second idle device; in response to the third point-to-point connection request, obtain the device operating status of each device in the first group of devices, wherein the first group of devices and the target device belong to the same local area network; determine a first group of idle devices from the first group of devices based on the device operating status; send the third point-to-point connection request to the first group of idle devices; determine the device in the first group of idle devices that responds to the third point-to-point connection request as the first idle device, and establish a third penetration connection between the first idle device and the second idle device. ; When the second penetration connection and the third penetration connection are both successfully established, a second address exchange request is sent to the target device and the second idle device respectively, wherein the second address exchange request is used to request the target device and the first idle device to exchange address information with each other through the second idle device; when the second idle device sends the second address exchange request to the first idle device, and the target device and the first idle device complete the address information exchange, a login request is received from the target device and the first idle device to complete the login of the target device and the first idle device, the relay connection is switched to a point-to-point connection between the target device and the first idle device, and the relay connection is interrupted, wherein the point-to-point connection is automatically established when the target device and the first idle device complete the login.
[0013] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored. The computer program is configured to execute the above-mentioned connection establishment method when running.
[0014] According to another aspect of the present application, a computer program product or computer program is provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the above connection establishment method.
[0015] According to another aspect of the embodiments of the present application, an electronic device is provided, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to execute the connection establishment method through the computer program.
[0016] In an embodiment of the present application, by adopting a method for establishing a relay connection between a terminal device and a target device and obtaining a network address translation type, by judging whether the network address translation types corresponding to the two devices are both symmetric, and establishing a point-to-point connection strategy based on this judgment result, the purpose of efficiently establishing a P2P connection in different network environments is achieved, thereby achieving the technical effect of improving the connection success rate and reducing resource consumption. Specifically, when at least one of the terminal device and the target device is asymmetric, the P2P connection is achieved by exchanging addresses between the target device and the first idle device in the same local area network; if both are symmetric, a second idle device in a different local area network is introduced, whose network address translation type is asymmetric, and address exchange is performed by cascading multiple devices, thereby optimizing the penetration problem in a symmetric NAT environment, ensuring business continuity and smooth user experience, and thus solving the technical problem that resource consumption during NAT penetration has a large impact on stream transmission and high device resource overhead. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0018] Figure 1 is a schematic diagram of an application environment of an optional connection establishment method according to an embodiment of the present application;
[0019] Figure 2 is a flow chart of an optional connection establishment method according to an embodiment of the present application;
[0020] Figure 3 This is a schematic diagram of an application environment of an optional connection establishment method according to an embodiment of the present application;
[0021] Figure 4 This is a schematic diagram of a non-bisymmetric NAT scenario of an optional connection establishment method according to an embodiment of the present application;
[0022] Figure 5 This is a schematic diagram of a dual symmetric NAT scenario of an optional connection establishment method according to an embodiment of the present application;
[0023] Figure 6 This is a schematic diagram of the main steps of an optional connection establishment method according to an embodiment of the present application;
[0024] Figure 7 is a structural diagram of an optional connection establishment device according to an embodiment of the present application;
[0025] Figure 8is a schematic structural diagram of an optional connection establishment product according to an embodiment of the present application;
[0026] Figure 9 It is a schematic structural diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0027] In order to enable those skilled in the art to better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.
[0028] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] According to one aspect of an embodiment of the present application, a connection establishment method is provided. Optionally, in this embodiment, the connection establishment method can be applied to Figure 1 In the hardware environment composed of the server 101 and the terminal device 103 shown in FIG. Figure 1As shown, the server 101 is connected to the terminal device 103 via a network and can be used to provide services for the terminal device or the application installed on the terminal device. The application 107 can be a video application, instant messaging application, browser application, educational application, game application, etc. A database 105 may be set up on the server or independently of the server to provide data storage services for the server 101, for example, a game data storage server. The above-mentioned network may include but is not limited to: a wired network, a wireless network, wherein the wired network includes: a local area network, a metropolitan area network and a wide area network, and the wireless network includes: Bluetooth, WIFI and other networks that realize wireless communication. The terminal device 103 may be a terminal configured with an application, and may include but is not limited to at least one of the following: a mobile phone (such as an Android phone, an iOS phone, etc.), a laptop computer, a tablet computer, a PDA, a MID (Mobile Internet Devices), a PAD, a desktop computer, a smart TV, an intelligent voice interaction device, a smart home appliance, a vehicle-mounted terminal, an aircraft, a virtual reality (VR) terminal, an augmented reality (AR) terminal, a mixed reality (MR) terminal and other computer devices. The above-mentioned server may be a single server, a server cluster consisting of multiple servers, or a cloud server.
[0030] Combine Figure 1 As shown, the above connection establishment method can be executed by an electronic device, which can be a terminal device or a server. The above connection establishment method can be implemented by the terminal device or the server separately, or by the terminal device and the server together.
[0031] The above is only an example and is not specifically limited in this embodiment.
[0032] Alternatively, as an optional implementation, Figure 2 As shown, the above connection establishment method includes:
[0033] S202, receiving a data request message sent by a terminal device, wherein the data request message is used to request data of a target device, and the terminal device and the target device belong to different local area networks;
[0034] S204, in response to the data request message, establishing a relay connection between the terminal device and the target device, and obtaining the network address translation type corresponding to the terminal device and the target device, wherein the network address translation type indicates a behavior mode of the device in processing data packets;
[0035] S206, based on whether the network address translation types corresponding to the terminal device and the target device are both symmetric, establish a point-to-point connection between the terminal device and the target device, and interrupt the relay connection, wherein, when at least one of the terminal device and the target device is asymmetric, the point-to-point connection is achieved by exchanging addresses between the target device and the first idle device, and the first idle device and the target device belong to the same local area network; when the terminal device and the target device are both symmetric, the point-to-point connection is achieved by exchanging addresses between the target device, the first idle device and the second idle device, and the second idle device and the target device belong to different local area networks, and the network address translation type of the second idle device is asymmetric.
[0036] Optionally, in the embodiments of the present application, the receiving terminal device may include, but is not limited to, a user-operated smart device capable of sending and receiving data over a network. This includes, but is not limited to, a smartphone, tablet computer, laptop computer, or desktop computer. For example, a user may use their smartphone to request a connection to a smart camera at home through an application, with the camera being the target device.
[0037] In embodiments of the present application, the data request message may include, but is not limited to, a signal or information packet sent by a terminal device to request specific data from a target device. This includes, but is not limited to, video streaming requests, file download requests, or status information queries. For example, when a user wants to view the real-time video of a smart camera, the smartphone will send a data request message to the camera, requesting the video stream data.
[0038] It should be noted that data request messages are not limited to text; they can also include multimedia data such as video, audio, or images. For example, a data request message could be a user requesting a real-time video stream from a smart camera, a temperature sensor reading from a home automation system, or heart rate data from a health monitoring device. These requests can span different application scenarios and device types, and this application does not limit them.
[0039] Optionally, in embodiments of the present application, the relay connection may include, but is not limited to, a network connection method that allows two devices that would otherwise be unable to communicate directly to exchange data via an intermediary server or node. This includes, but is not limited to, a virtual connection established via a cloud platform relay server. For example, when a direct P2P connection cannot be established between a terminal device and a target device, data can be forwarded via the cloud platform's relay server to enable communication.
[0040] It should be further clarified that the establishment of relay connections is not limited to cloud platform relay servers and can also be achieved through other intermediary devices or services. For example, the relay connection can be established through a proxy server on the enterprise's internal network, or through a relay point provided by a specific network optimization service. These intermediary services can be hardware devices or software services, and their function is to facilitate data transmission in different network environments and conditions, which is not limited by this application.
[0041] Optionally, in embodiments of the present application, the aforementioned network address translation type may include, but is not limited to, rules and behavior patterns describing how a NAT device processes and translates data packets passing through it. This includes, but is not limited to, cone NAT and symmetric NAT. For example, symmetric NAT dynamically assigns a different public IP and port to each session, while cone NAT uses the same public IP and port for all sessions on intranet devices.
[0042] It should be pointed out that the network address translation type is not limited to symmetric and asymmetric types, but can also include other NAT types such as full cone, restricted cone, port restricted cone, etc. These types describe how the NAT device processes and converts data packets flowing through it. Different NAT types have different processing rules and behavior patterns for data packets, which will affect the establishment and maintenance of P2P connections. For example, full cone NAT is open to all external connections initiated to specific ports on the intranet, while restricted cone NAT is only open to connections to specific IPs. These different NAT types have a direct impact on the establishment and maintenance of P2P connections, and this application does not limit this.
[0043] Optionally, in embodiments of the present application, the aforementioned point-to-point connection may include, but is not limited to, a direct communication path between two devices, without intervening through any intermediary server or node. This includes, but is not limited to, a direct connection established via the ICE (Interactive Connectivity Establishment) framework. For example, once the end device and the target device are able to determine each other's external IP address and port, they can perform a series of tests and exchange information via the ICE framework, ultimately establishing a direct P2P connection.
[0044] Optionally, in this embodiment of the present application, the aforementioned first idle device may include, but is not limited to, an idle device within the same local area network, which can assist in establishing a P2P connection between the terminal device and the target device. This includes, but is not limited to, other smart devices within the same home network. For example, if the target device is a smart camera, and a smart light bulb within the same local area network is idle, the smart light bulb can serve as the first idle device to assist in establishing the P2P connection.
[0045] Optionally, in this embodiment of the present application, the aforementioned second idle device may include, but is not limited to, an idle device in a different local area network (LAN) whose network address translation type is asymmetric, and which participates in the P2P connection establishment process. This includes, but is not limited to, devices located in different network environments. For example, if both the terminal device and the target device are behind symmetric NAT, a second device located behind an asymmetric NAT network (such as an office printer) may be required to assist in address exchange and P2P connection establishment.
[0046] For example, let's take a smart home monitoring system as an example. A user requests a real-time video stream from a smart camera (target device) at home via a smartphone (terminal device). The following is the specific implementation process:
[0047] S1: The user sends a data request message to the smart camera via a smartphone. The message contains an instruction to request a real-time video stream.
[0048] S2: After receiving the data request message, the smart camera responds to the request by establishing a relay connection with the smartphone through the cloud platform (relay server) and starts transmitting real-time video stream data.
[0049] S3: At the same time, the cloud platform obtains the network address translation type corresponding to the smartphone and smart camera. Assume that the NAT type of the smartphone is symmetric and the NAT type of the smart camera is cone.
[0050] S4: Based on the network address translation type information and because the smart camera uses an asymmetric NAT, the cloud platform decides to use a device cascade-assisted penetration solution. The cloud platform checks the same LAN for available devices that can serve as the first idle device and finds that the smart light bulb (the first idle device) is idle.
[0051] S5: The smart camera exchanges addresses with the smartphone through the smart bulb (the first idle device), establishing a point-to-point connection. The smart bulb sends a request to the cloud platform's STUN server to obtain its public IP and port after passing through egress NAT, and sends this information to the smartphone.
[0052] S6: The smartphone and the smart bulb start the ICE interaction process based on the external network IP and port behind the NAT of both parties to perform NAT penetration.
[0053] S7: After NAT penetration is successful, the smartphone suspends the relay transmission link through the cloud platform and sends an address exchange request to the smart camera, carrying the device serial number of the smart bulb and the port number bound to the local network socket.
[0054] S8: The smart camera and the smart bulb complete the address exchange process and update the ARP table entry, allowing the smart camera to send data directly to the smartphone.
[0055] S9: The smart camera creates a new network socket and binds it to the port number corresponding to the local network socket of the smart bulb. It sends a request to the smartphone to resume the real-time video stream service, completing the link switch from the cloud platform relay to P2P transmission.
[0056] The above process enables efficient P2P connection establishment in different NAT environments. In asymmetric NAT scenarios, by introducing idle devices (smart lightbulbs) within the same LAN as relays, resource usage on the target device (smart camera) is reduced while simultaneously increasing the success rate of P2P connections. In symmetric NAT scenarios, by adding an asymmetric NAT device (such as an office printer) on a different LAN as a second idle device, many-to-many cascade penetration is achieved, avoiding the time-consuming and resource-intensive nature of dual-symmetric NAT penetration. This solution not only improves connection efficiency and reduces latency, but also reduces platform traffic costs and enhances the user experience.
[0057] Through the embodiment of the present application, by adopting a method for establishing a relay connection and obtaining a network address translation type between a terminal device and a target device, by judging whether the network address translation types corresponding to the two devices are both symmetric, and establishing a point-to-point connection strategy based on this judgment result, the purpose of efficiently establishing a P2P connection in different network environments is achieved, thereby achieving the technical effect of improving the connection success rate and reducing resource consumption. Specifically, when at least one of the terminal device and the target device is asymmetric, the P2P connection is achieved by exchanging addresses between the target device and the first idle device in the same local area network; if both are symmetric, a second idle device in a different local area network is introduced, whose network address translation type is asymmetric, and address exchange is performed by cascading multiple devices, thereby optimizing the penetration problem in a symmetric NAT environment, ensuring business continuity and smooth user experience, and thus solving the technical problem that resource consumption during NAT penetration has too much impact on stream transmission and high device resource overhead.
[0058] As an optional solution, based on whether the network address translation types corresponding to the terminal device and the target device are both symmetric, a point-to-point connection is established between the terminal device and the target device, and the relay connection is terminated, including:
[0059] In the case where at least one of the terminal device and the target device is asymmetric, establishing a point-to-point connection based on the first idle device and interrupting the relay connection;
[0060] In the case that both the terminal device and the target device are symmetrical, a point-to-point connection is established based on the first idle device and the second idle device, and the relay connection is terminated.
[0061] Optionally, in an embodiment of the present application, symmetric NAT is a type of network address translation that dynamically assigns a different address and port to each external port connection passing through NAT. In this mode, the NAT device maintains a dynamic translation table that records the mapping relationship between internal private addresses and external public network addresses. Whenever a new connection request arrives, the NAT device searches the translation table. If no match is found, a new entry is created and an unused external port is randomly selected to establish a connection. The characteristic of symmetric NAT is that for each new external connection request, even the same external address and port from the same internal device may be assigned a different external address and port. This means that devices in a symmetric NAT environment cannot accept all connections from any external source through only one external address and port, which poses a challenge to P2P communication.
[0062] Optionally, in an embodiment of the present application, asymmetric NAT is another type of network address translation that allows traffic from the same internal address and port to be mapped to the same external address and port. However, for return traffic, as long as the source address and port match the mapping recorded on the NAT device, it can be forwarded to the correct internal device even if the destination address and port are different. Asymmetric NAT is commonly used in P2P applications because it allows an internal device to use a fixed external address and port to accept connections from any external source. This type of NAT is more friendly to P2P communication because it does not require a new external port to be allocated for each new connection request like symmetric NAT, thereby simplifying the process of establishing a P2P connection.
[0063] For example, take remote monitoring and data backup as an example, where a user wants to remotely access a NAS storage device (target device) in a home network through a smartphone (terminal device) to back up photos and videos.
[0064] S1: The user sends a data request message to the NAS storage device through the smartphone, requesting to back up the photos and videos in the smartphone.
[0065] S2: The NAS storage device responds to the data request message, establishes a relay connection with the smartphone through the cloud platform relay server, and starts transmitting data.
[0066] S3: The cloud platform obtains the network address translation type of the smartphone and the NAS storage device. Assume that the NAT type of the smartphone is asymmetric and the NAT type of the NAS storage device is symmetric.
[0067] S4: Based on the NAT type information, the cloud platform decides to establish a peer-to-peer connection with the first idle device (the smart router in the home network). The smart router sends a request to the cloud platform's STUN server to obtain its public IP and port after the egress NAT.
[0068] S5: The smart router (the first idle device) exchanges addresses with the smartphone, establishing a peer-to-peer connection. The smart router creates a new network socket and obtains its own NATed public IP and port from the cloud platform's STUN server. It then constructs a P2P connection response containing its own device serial number, network NAT type, NATed public IP and port, and the port number bound to the local network socket. The response is forwarded to the smartphone via the cloud platform's signaling server.
[0069] S6: The smartphone and smart router start the ICE interaction process based on the external network IP and port after NAT on both sides to perform NAT penetration.
[0070] S7: After NAT penetration is successful, the smartphone suspends the relay transmission link through the cloud platform and sends an address exchange request to the NAS storage device and the smart router through the relay transmission link and the P2P transmission link respectively, carrying the device serial numbers of both devices.
[0071] S8: The NAS storage device and the smart router complete the address exchange process and update the ARP table entry, allowing the NAS storage device to send data directly to the smartphone.
[0072] S9: The NAS storage device creates a new network socket and binds it to the port number corresponding to the local network socket of the smart router, sends a data backup recovery service request to the smartphone, completes the link switch from the cloud platform relay to the P2P transmission, and disconnects the relay connection.
[0073] The above process enables efficient P2P connection establishment in various NAT environments. When at least one device uses an asymmetric NAT, the first idle device (smart router) assists in successfully establishing a point-to-point connection and interrupting the relay connection, reducing reliance on cloud platform resources, lowering data transmission costs, and improving data transmission efficiency. In symmetric NAT environments, by introducing a first idle device and a second idle device (for example, the second idle device could be a printer in the user's office or a smart TV in another home network), multi-to-multi cascade traversal is achieved, avoiding the time-consuming and resource-intensive nature of dual-symmetric NAT traversal. This solution not only improves connection efficiency and reduces latency, but also reduces platform traffic costs and enhances the user experience. By optimizing the NAT traversal process, the continuity and stability of data backup are ensured, while also improving network resource utilization.
[0074] As an optional solution, when at least one of the terminal device and the target device is not symmetrical, a point-to-point connection is established based on the first idle device, and the relay connection is interrupted, including: when at least one of the terminal device and the target device is not symmetrical, receiving a first point-to-point connection request sent by the terminal device; in response to the first point-to-point connection request, obtaining the device operation status of each device in the first group of devices, wherein the first group of devices and the target device belong to the same local area network; determining a first group of idle devices from the first group of devices based on the device operation status; sending a first point-to-point connection request to the first group of idle devices; determining the device in the first group of idle devices that responds to the first point-to-point connection request as the first idle device. an idle device, establishing a first penetration connection between the first idle device and the terminal device; when the first penetration connection is successfully established, sending a first address exchange request to the target device and the first idle device respectively, wherein the first address exchange request is used to request the target device and the first idle device to exchange address information with each other; when the target device and the first idle device complete the exchange of address information, receiving the login request sent by the target device and the first idle device to complete the login of the target device and the first idle device, switching the relay connection to a point-to-point connection between the target device and the first idle device, and interrupting the relay connection, wherein when the target device and the first idle device complete the login, a point-to-point connection is automatically established.
[0075] Optionally, in an embodiment of the present application, the above-mentioned first point-to-point connection request may include but is not limited to a network request sent by a terminal device in order to establish direct communication with a target device, and this request contains necessary network parameters and authentication information so that the target device or other devices in the same local area network can respond and establish a connection. Including but not limited to a data packet containing a port number, an IP address, and specific protocol requirements. For example, when a smartphone needs to establish a connection with a smart camera in a home network, it will send a connection request containing its public IP address and port number so that the smart camera or other devices in the same local area network can respond.
[0076] Optionally, in this embodiment of the present application, the first group of devices may include, but is not limited to, all smart devices on the same local area network as the target device, which can assist in establishing a point-to-point connection. This includes, but is not limited to, smart sockets, smart light bulbs, smart thermostats, etc. For example, if the target device is a NAS server in a home, then the first group of devices may include smart TVs, smart speakers, and other smart home devices on the same home network.
[0077] Optionally, in the embodiment of the present application, the device operating status may include, but is not limited to, parameters describing whether the device is currently able to participate in network operations, such as whether it is idle, busy, network connection quality, etc. This includes, but is not limited to, the device's CPU usage, memory usage, current network bandwidth usage, etc. For example, in a smart home network, a smart socket may appear to be busy because it is controlling an appliance in use, while a smart light bulb may appear to be idle because it is not currently turned on.
[0078] Optionally, in an embodiment of the present application, the first group of idle devices may include, but is not limited to, devices in the first group that are not currently performing tasks or that can allocate resources to assist in establishing a peer-to-peer connection. These devices may include, but are not limited to, a smart refrigerator that has just completed an update or a smart speaker that is not currently playing music. For example, if a smart refrigerator in a home network has just completed a software update and is idle, it can be selected as one of the first group of idle devices to assist in establishing a peer-to-peer connection.
[0079] Optionally, in embodiments of the present application, the first penetration connection may include, but is not limited to, a network connection established between the terminal device and the first idle device for NAT penetration. This connection allows the two devices to exchange necessary information for direct communication, bypassing the NAT device. This includes, but is not limited to, connections established via the STUN protocol or other NAT penetration technologies. For example, a first penetration connection may be established between a smartphone and a smart refrigerator, enabling them to exchange external IP addresses and port numbers, thereby achieving NAT penetration.
[0080] Optionally, in an embodiment of the present application, the first address exchange request may include but is not limited to a request sent by the terminal device to the target device and the first idle device, with the purpose of allowing the two devices to exchange their network address information with each other so as to directly establish a connection. This includes but is not limited to a data packet containing a device serial number, IP address, and port number. For example, a smartphone may send a request to a smart camera and a smart refrigerator, requesting them to exchange their respective internal IP addresses so that the smartphone can directly establish a connection with the smart camera.
[0081] Optionally, in an embodiment of the present application, the login request may include, but is not limited to, a request sent by the target device and the first idle device to the network system to confirm that they are ready to begin direct communication. This request may include device authentication information and network parameters, including, but not limited to, a data packet containing the device's MAC address and a login token. For example, in a smart home system, after exchanging address information, the smart camera and smart refrigerator will send a login request to the cloud platform to confirm that they are ready for peer-to-peer communication.
[0082] It should be noted that the first point-to-point connection establishment request between the terminal device and the target device may include a variety of network parameters and authentication information, which is not limited to the basic IP address and port number. It may also include encryption keys, protocol type, data transmission format, etc. For example, the request may include parameters for the SSL / TLS encryption protocol to ensure the security of the connection, or specify the use of the MQTT protocol for communication between IoT devices. This application does not limit this.
[0083] Among them, in response to the first point-to-point connection request, when obtaining the device operating status of each device in the first group of devices, the parameters of the device operating status can be very diverse, including CPU load, memory usage, network bandwidth occupancy, device temperature, battery power, etc. These parameters can help the system more accurately evaluate the availability and performance of the device, thereby selecting the best device to assist in establishing the point-to-point connection. For example, a device may not be selected as the first idle device because of low battery power, even if it currently has no other tasks. This application is not limited to this.
[0084] Furthermore, when determining the first group of idle devices from the first group of devices based on their operating status, the system may consider various attributes and historical behaviors of the devices, such as their reliability records, past connection success rates, and user-defined device priorities. For example, if a device frequently fails in past connection attempts, the system may prioritize other devices even if their current operating status is suboptimal. This application does not impose any limitations on this.
[0085] On the other hand, when sending the first point-to-point connection establishment request to the first group of idle devices, this request can include various types of network protocols and data formats to accommodate the needs of different devices and network environments. For example, the request may be sent in JSON format or include data in XML format to accommodate the parsing capabilities of different devices. This application does not impose any restrictions on this.
[0086] On the other hand, when determining the device in the first group of idle devices that responds to the first point-to-point connection request as the first idle device, the system may evaluate and select the best device based on multiple dimensions, such as response speed, connection quality, and historical connection stability. For example, even if multiple devices respond to the request, the system may select the device with the shortest response time and the strongest signal as the first idle device. This application does not limit this.
[0087] Furthermore, when the first penetration connection is successfully established, the first address exchange request sent to the target device and the first idle device, respectively, may include various types of address information, including IPv4 addresses, IPv6 addresses, MAC addresses, and possibly network interface identifiers. For example, the request may require the devices to exchange their addresses on different network interfaces, or addresses used under different network protocols. This application is not limited to this.
[0088] After the target device and the first idle device have completed the address information exchange, login requests from the target device and the first idle device are received. These requests may include various authentication and authorization information, such as username and password, digital certificate, one-time password (OTP), etc. This information is used to ensure that only authorized devices can establish a point-to-point connection. For example, the system may require the device to provide a login request based on two-factor authentication to enhance security. This application does not limit this.
[0089] Finally, when the relay connection is switched to a point-to-point connection between the target device and the first idle device and the relay connection is interrupted, this process may involve various network optimization and fault recovery mechanisms to ensure connection stability and data integrity. For example, the system may monitor network quality during the switching process and automatically restore to the relay connection if a problem is detected, or automatically switch back to a more economical connection method after data transmission is completed. This application is not limited to this.
[0090] For example, consider a remote office scenario where an employee (terminal device) needs to retrieve important documents from a file server (target device) on the company's intranet. The following is the specific implementation process:
[0091] S1: The employee's laptop (terminal device) sends the first point-to-point connection request to the file server (target device) on the company's intranet, requesting to obtain a specific document.
[0092] S2: The file server responds to the first point-to-point connection request and queries the operating status of the first group of devices (such as printers, scanners, and other computers) in the same intranet, including CPU load, memory usage, and network bandwidth usage.
[0093] S3: Based on the device operating status, the file server determines a first group of idle devices, for example, discovers an idle printer (the first idle device).
[0094] S4: The file server sends a first point-to-point connection request to the idle printer, requesting assistance in establishing a pass-through connection with the employee's laptop.
[0095] S5: The printer responds to the first point-to-point connection request and establishes a first penetration connection with the employee's laptop. For example, the printer obtains the external network IP and port after NAT through the STUN protocol and starts the ICE interaction process.
[0096] S6: Once the first penetration connection is successfully established, the file server sends a first address exchange request to the printer and the employee's laptop respectively, requesting both parties to exchange address information, such as IP addresses and port numbers.
[0097] S7: The printer and the employee's laptop complete the exchange of address information, for example, by sending ARP requests and responses to confirm each other's LAN addresses.
[0098] S8: The file server receives the login requests from the printer and the employee's laptop, completes the logins for both parties, and prepares to switch the connection. For example, the file server may require both parties to provide digital certificates or passwords to verify their identities.
[0099] S9: The file server switches the relay connection to a point-to-point connection between the printer and the employee's laptop, and disconnects the previous relay connection. For example, the file server may send a control signal to instruct the two parties to communicate directly.
[0100] The above process enables efficient P2P connection establishment in an asymmetric NAT environment. In situations where at least one of the terminal device and the target device is asymmetric, the system successfully establishes a point-to-point connection with the assistance of the first idle device (the printer), terminating the relay connection. This reduces reliance on the company's intranet resources, lowers data transmission costs, and improves data transmission efficiency. This approach not only improves connection stability and security but also allows for flexible resource allocation and connection management in complex network environments, ensuring the rapid and secure transmission of important documents. Furthermore, by automatically switching connections and terminating relay connections, the system conserves bandwidth, reduces latency, improves user experience, and saves the company network operating costs.
[0101] As an optional solution, when the terminal device and the target device are both symmetrical, a point-to-point connection is established based on the first idle device and the second idle device, and the relay connection is interrupted, including: when the terminal device and the target device are both symmetrical, determining whether there is a second idle device; when the second idle device exists, establishing a point-to-point connection based on the first idle device and the second idle device, and interrupting the relay connection.
[0102] Optionally, in an embodiment of the present application, when the terminal device and the target device are both symmetrical, the process of determining whether a second idle device exists may involve considerations of multiple dimensions, including the network location of the device, the network address translation type, and the functionality of the device. For example, the second idle device may be located in a local area network different from that of the target device, and its NAT type may be asymmetric. Such a device can assist in establishing a more stable point-to-point connection. In addition, the selection of the second idle device may also be based on its processing power, available resources, and historical connection success rate. For example, a device with higher processing power and lower battery consumption may be more popular as the second idle device. This application is not limited to this.
[0103] It should be noted that, in the presence of a second idle device, the process of establishing a point-to-point connection based on the first idle device and the second idle device may include a variety of technical solutions and parameter configurations. For example, this connection may be implemented through different communication protocols, such as TCP, UDP, or application-layer-specific protocols. The establishment of a connection may need to consider the security of data transmission, and therefore may involve the use of encryption technologies such as SSL / TLS. In addition, the stability and efficiency of the connection may be affected by network conditions, and therefore the transmission rate or retransmission strategy may need to be dynamically adjusted. For example, if the network conditions are poor, the system may choose to use a more robust transmission protocol or add a data packet confirmation mechanism. This application is not limited to this.
[0104] In addition, in the process of interrupting the relay connection after establishing a point-to-point connection, a variety of network management and optimization technologies may be involved. For example, the interruption of the relay connection may need to ensure the integrity and consistency of data transmission, so data synchronization or status confirmation may be performed before the interruption. In addition, the interruption of the relay connection may be based on real-time monitoring and analysis of network traffic to ensure that it is performed when the network load is low to reduce the impact on network performance. For example, the system may automatically interrupt the relay connection when it detects a low network traffic, or during non-peak hours specified by the user. This application is not limited to this.
[0105] As an optional solution, when the terminal device and the target device are both symmetrical, determining whether there is a second idle device includes: when the terminal device and the target device are both symmetrical, receiving a second point-to-point connection request sent by the terminal device; obtaining the device operating status of the second group of devices in response to the second point-to-point connection request, wherein the second group of devices and the target device belong to different local area networks, and the network address translation type corresponding to the second group of idle devices is asymmetric; determining a second group of idle devices from the second group of devices based on the device operating status; sending a point-to-point cascade request to the second group of idle devices; determining the device in the second group of idle devices that responds to the point-to-point cascade request as the second idle device, and establishing a second penetration connection between the second idle device and the terminal device.
[0106] Optionally, in an embodiment of the present application, the above-mentioned second point-to-point connection request may include but is not limited to a network request sent by a terminal device to establish direct communication with a target device. This request may contain specific protocol identifiers, port information, encryption parameters, etc. to ensure compatibility and security with the target device. It includes but is not limited to a data packet containing the public IP address, port number, and encryption protocol type (such as TLS / SSL) of the terminal device. For example, when a terminal device needs to establish a secure point-to-point connection with a target device, it may send a connection request containing its public IP address and port number, and specify the use of the TLS protocol to encrypt communication. This application does not limit this.
[0107] It should be noted that when both the terminal device and the target device are symmetric, the second point-to-point connection establishment request sent by the receiving terminal device may involve multiple network parameters and authentication information. These parameters and information include not only basic IP addresses and port numbers, but also encryption keys, protocol types, data transmission formats, etc. For example, the request may include parameters for the SSL / TLS encryption protocol to ensure the security of the connection, or specify the use of the MQTT protocol for communication between IoT devices. In addition, the request may also include QoS (Quality of Service) requirements to ensure the priority and efficiency of data transmission. This application does not limit this.
[0108] Optionally, in an embodiment of the present application, the second group of devices may include, but is not limited to, a series of devices located in a different local area network from the target device. These devices may use different network address translation types, including asymmetric NAT. These devices may be any type of network device, such as routers, switches, smart home devices, etc. For example, if the target device is a server on a company's intranet, the second group of devices may include smart TVs, game consoles, or other network-enabled devices on an employee's home network. This application does not limit this.
[0109] Among them, in response to the second point-to-point connection request, when obtaining the device operating status of the second group of devices, the parameters of the device operating status can be very diverse, including CPU load, memory usage, network bandwidth occupancy, device temperature, battery power, etc. These parameters can help the system more accurately evaluate the availability and performance of the device, thereby selecting the best device to assist in establishing the point-to-point connection. For example, a device may not be selected as the second group of idle devices because of low battery power, even if it currently has no other tasks. In addition, the acquisition of device operating status may be implemented through different monitoring tools and protocols, such as SNMP (Simple Network Management Protocol) or a custom device API. This application is not limited to this.
[0110] Optionally, in an embodiment of the present application, the aforementioned second group of idle devices may include, but is not limited to, devices in the second group that are not currently performing tasks or that can allocate resources to assist in establishing a peer-to-peer connection. These devices may be selected based on factors such as their network performance, processing power, and available bandwidth. For example, if the second group of devices includes a smart TV and a game console, and the game console is not currently running any games, it may be selected as a second group of idle devices to assist in establishing a peer-to-peer connection. This application is not limited to this.
[0111] When determining the second group of idle devices from the second group of devices based on the device operating status, the system may consider various attributes and historical behaviors of the devices, such as the device's reliability record, previous connection success rate, and user priority settings for the devices. For example, if a device frequently fails in past connection attempts, the system may prioritize other devices even if their current operating status is not optimal. In addition, the system may select devices based on their energy consumption and environmental impact to achieve green energy conservation goals. This application does not limit this.
[0112] Optionally, in embodiments of the present application, the aforementioned point-to-point cascade request may include, but is not limited to, a request sent by a terminal device to a second group of idle devices, requesting that these devices assist in establishing a passthrough connection with the target device. This request may include network parameters for the target device, protocol details for the passthrough connection, and so on. For example, the terminal device may send a cascade request containing the target device's public IP address, port number, and the intended passthrough protocol (e.g., STUN or TURN). This application is not limited to this.
[0113] When sending a point-to-point cascade request to the second group of idle devices, the request can include various types of network protocols and data formats to accommodate the needs of different devices and network environments. For example, the request may be sent in JSON format or include data in XML format to accommodate the parsing capabilities of different devices. In addition, the request may also include requirements for specific network quality of service, such as low latency or high throughput, to meet the needs of specific applications. This application does not limit this.
[0114] Optionally, in embodiments of the present application, the second penetration connection may include, but is not limited to, a network connection established between the terminal device and the second idle device for NAT penetration. This connection allows the two devices to exchange necessary information for direct communication, bypassing the NAT device. This includes, but is not limited to, connections established via the STUN protocol or other NAT penetration technologies. For example, a second penetration connection may be established between the terminal device and the gaming console, enabling them to exchange external IP addresses and port numbers, thereby achieving NAT penetration. This application is not limited to this.
[0115] When the device in the second group of idle devices that responds to the point-to-point cascade request is identified as the second idle device and a second pass-through connection is established between the second idle device and the terminal device, establishing this connection may involve various security and encryption measures to protect the security and privacy of data transmission. For example, the connection may utilize VPN (virtual private network) technology to encrypt all transmitted data, or IPSec (Internet Protocol security) to ensure data integrity and confidentiality. Furthermore, establishing the connection may also include optimizing the network path to reduce latency and improve data transmission efficiency. This application does not limit this.
[0116] For example, consider a security monitoring system where a remote security monitoring center (terminal device) needs to establish a connection with a surveillance camera (target device) in a company building to transmit video data in real time. The following is the specific implementation process:
[0117] S1: The remote security monitoring center (terminal device) sends a second point-to-point connection request to the surveillance camera (target device) in the company building, requesting to establish a real-time video data transmission connection.
[0118] S2: The surveillance camera responds to the second point-to-point connection request and queries the operating status of the second group of devices (such as security equipment in other branches) in different local area networks outside the building, including CPU load, memory usage, network bandwidth utilization, etc.
[0119] S3: Based on the device operating status, the surveillance camera determines which devices in the second group of devices are in an idle state and the corresponding network address translation type is asymmetric, for example, a security router of a branch office.
[0120] S4: The surveillance camera sends a point-to-point cascade request to the branch office's security router (the second group of idle devices), requesting assistance in establishing a penetration connection with the remote security monitoring center.
[0121] S5: The branch office's security router responds to the peer-to-peer cascade request and establishes a second penetration connection with the remote security monitoring center. For example, it obtains the public IP and port after NAT using the STUN protocol and begins the ICE interaction process.
[0122] S6: Once the second penetration connection is successfully established, the surveillance camera sends a first address exchange request to the security router of the branch office, requesting to exchange address information, such as IP address and port number.
[0123] S7: After the branch office's security router completes the exchange of address information, the surveillance camera receives a login request from the branch office's security router, completes the login, and prepares to switch the relay connection to a point-to-point connection.
[0124] S8: The surveillance camera switches the relay connection to a point-to-point connection with the branch office's security router and disconnects the previous relay connection. For example, the surveillance camera may send a control signal to instruct the two parties to communicate directly.
[0125] The above process enables efficient P2P connection establishment in a symmetric NAT environment. When both the terminal device and the target device are symmetric, a point-to-point connection is successfully established with the assistance of the branch office's security router (a second, unused device), terminating the relay connection. This reduces reliance on the company's intranet resources, lowers data transmission costs, and improves data transmission efficiency. This approach not only improves connection stability and security but also allows for flexible resource allocation and connection management in complex network environments, ensuring the rapid and secure transmission of critical video data. Furthermore, by automatically switching connections and terminating relay connections, the system conserves bandwidth, reduces latency, improves user experience, and reduces network operating costs for the company. By optimizing the NAT penetration process, the continuity and stability of the security surveillance system are ensured while improving network resource utilization.
[0126] As an optional solution, in the presence of a second idle device, establishing a point-to-point connection based on the first idle device and the second idle device and interrupting the relay connection, including: in the presence of the second idle device, receiving a third point-to-point connection establishment request sent by the second idle device; in response to the third point-to-point connection establishment request, obtaining a device operating status of each device in the first group of devices, wherein the first group of devices and the target device belong to the same local area network; determining a first group of idle devices from the first group of devices based on the device operating status; sending a third point-to-point connection establishment request to the first group of idle devices; determining the device in the first group of idle devices that responds to the third point-to-point connection establishment request as the first idle device, and establishing a third penetration connection between the first idle device and the second idle device; When both the second penetration connection and the third penetration connection are successfully established, a second address exchange request is sent to the target device and the second idle device respectively, wherein the second address exchange request is used to request the target device and the first idle device to exchange address information with each other through the second idle device; when the second idle device sends the second address exchange request to the first idle device, and when the target device and the first idle device complete the exchange of address information, a login request is received from the target device and the first idle device to complete the login of the target device and the first idle device, the relay connection is switched to a point-to-point connection between the target device and the first idle device, and the relay connection is interrupted, wherein when the target device and the first idle device complete the login, a point-to-point connection is automatically established.
[0127] Optionally, in an embodiment of the present application, the above-mentioned third point-to-point connection request may include but is not limited to a network request sent by the second idle device to establish direct communication with a device in the first group of devices. This request may contain specific protocol identifiers, port information, encryption parameters, etc. to ensure compatibility and security with devices in the first group of devices. Including but not limited to a data packet containing the public IP address, port number and encryption protocol type (such as TLS / SSL) of the second idle device. For example, when the second idle device needs to establish a secure point-to-point connection with the smart router in the first group of devices, it may send a connection request containing its public IP address and port number, and specify the use of the TLS protocol to encrypt communication. This application is not limited to this.
[0128] Optionally, in embodiments of the present application, the third penetration connection may include, but is not limited to, a network connection established between the first idle device and the second idle device for NAT penetration. This connection allows the two devices to exchange necessary information for direct communication, bypassing the NAT device. This includes, but is not limited to, connections established via the STUN protocol or other NAT penetration technologies. For example, a third penetration connection may be established between the first idle device (a smart router) and the second idle device (a security router at a branch office), enabling them to exchange external IP addresses and port numbers, thereby achieving NAT penetration. This application is not limited to this.
[0129] Optionally, in embodiments of the present application, the second address exchange request may include, but is not limited to, a request for the target device and the first idle device to exchange address information via the second idle device. This request may include network parameters for the target device and the first idle device, protocol details for the passthrough connection, and the like. For example, the target device may send an address exchange request including its public IP address, port number, and the intended passthrough protocol (such as STUN or TURN). This application is not limited to this.
[0130] For example, let's assume a large enterprise needs to establish a secure remote access connection between its headquarters (where the target device is located) and its branch offices to ensure that remote workers can securely access the company's internal network resources. The following is the specific implementation process:
[0131] S1: The branch office's VPN server (second idle device) sends a third point-to-point connection request to the company headquarters' firewall (target device), requesting to establish a VPN connection.
[0132] S2: The firewall at the company headquarters responds to the third point-to-point connection request and queries the operating status of the first group of devices (such as routers, switches, and other servers) in the same LAN, including CPU load, memory usage, and network bandwidth utilization.
[0133] S3: Based on the device operating status, the firewall determines an idle device in the first group of devices, for example, an idle internal router (the first group of idle devices) is found.
[0134] S4: The firewall sends a third point-to-point connection request to the idle internal router, requesting assistance in establishing a pass-through connection with the branch office VPN server.
[0135] S5: The internal router responds to the third point-to-point connection request and establishes a third passthrough connection with the branch office VPN server. For example, it obtains the public IP and port after NAT using the STUN protocol and begins the ICE interaction process.
[0136] S6: Once the second penetration connection (the connection between the branch VPN server and the corporate headquarters firewall) and the third penetration connection (the connection between the internal router and the branch VPN server) are successfully established, the firewall sends a second address exchange request to the internal router and the branch VPN server respectively, requesting the two parties to exchange address information, such as IP addresses and port numbers.
[0137] S7: The branch office VPN server sends a second address exchange request to the internal router, and the firewall and the internal router complete the address information exchange, for example, by sending ARP requests and responses to confirm each other's LAN addresses.
[0138] S8: The firewall receives the login requests from the internal router and the branch office VPN server, completes the login for both parties, and prepares to switch the relay connection to a point-to-point connection.
[0139] S9: The firewall switches the relay connection to a point-to-point connection with the internal router and terminates the previous relay connection. For example, the firewall may send a control signal to instruct the two parties to communicate directly.
[0140] The above process enables efficient P2P connection establishment in a symmetric NAT environment. In the presence of a second idle device, with the assistance of the internal router (the first idle device), a point-to-point connection is successfully established and the relay connection is terminated. This reduces reliance on the company's intranet resources, lowers data transmission costs, and improves data transmission efficiency. This approach not only improves connection stability and security but also allows for flexible resource allocation and connection management in complex network environments, ensuring the continuity and stability of remote access. Furthermore, by automatically switching connections and terminating relay connections, the system conserves bandwidth, reduces latency, improves user experience, and saves the company network operating costs. By optimizing the NAT penetration process, the continuity and stability of the remote access system are ensured while improving network resource utilization.
[0141] The following is a further explanation of this application with reference to specific examples:
[0142] Figure 3 FIG. 1 is a schematic diagram of an application environment of an optional connection establishment method according to an embodiment of the present application. Figure 3 As shown, a P2P connection establishment method and system includes:
[0143] Cloud platform (STUN server, application server, signaling server, and relay server):
[0144] 1) Responsible for maintaining the device group information under the user terminal account;
[0145] 2) Responsible for relay transmission between terminal equipment and target equipment;
[0146] 3) Responsible for signaling transmission between terminal devices and target devices and device groups;
[0147] Terminal devices: Access target devices through application software to perform routine services such as remote configuration, alarm notification, real-time preview, and video playback;
[0148] Target devices:
[0149] 1) Receive business access requests from terminal device application software and execute corresponding business processing logic;
[0150] 2) Receive the link switching request sent by the platform relay server and execute the switching process from the relay transmission link to the P2P transmission link;
[0151] Device group: In the same local area network, each device node uses its own device discovery function to identify other device nodes around it, and forms device group information and reports it to the platform application server.
[0152] In the same network, different device nodes identify other device nodes around them through their own device discovery function. The device discovery broadcast message carries the device serial number and the assigned local IP address. The following device group information is formed on each device node:
[0153]
[0154] Table 1
[0155] 2) The platform's STUN server deploys multiple STUN (Session Traversal Utilities for NAT) services, each bound to a different port number. Each device sends a STUN request to multiple STUN services on the platform to obtain its public IP and port after passing through the egress NAT. If the public port numbers returned by multiple STUN services are the same, the device's network NAT type is considered cone-shaped; otherwise, the network NAT type is considered symmetric.
[0156] 3) Each device sends a login request to the platform application server and reports its own network NAT type and corresponding device group information. The platform application server receives the network NAT type and device group information reported by each device node under the same user account, forming the following example content in Table 2:
[0157]
[0158] Table 2
[0159] Because the penetration success rate is low and the penetration time is long in the symmetric vs. symmetric NAT scenario, and too many device resources are occupied, this application solution adds a device group cascade assisted penetration scenario (symmetric vs. symmetric) during the NAT penetration process according to the different network NAT types of different device groups.
[0160] In an exemplary embodiment, Figure 4 FIG. 1 is a schematic diagram of a non-bisymmetric NAT scenario according to an optional connection establishment method of an embodiment of the present application. Figure 4 As shown in the figure, in a non-bisymmetric NAT scenario, the target device P2P connection process includes but is not limited to the following:
[0161] S1, the user terminal device sends a request to start the real-time preview service to the target device C on network 1 through the platform application server;
[0162] S2: The platform relay server establishes a relay transmission link between the terminal device and the target device C. Based on the platform relay transmission link, the terminal device and the target device C start the execution process of the real-time preview service. At the same time, the platform application server marks the device C's device operation status as busy.
[0163] S3: When the real-time preview service starts, the terminal device sends a P2P connection establishment request to the platform application server. The request carries the NAT type of the terminal device's network and the public IP and port after NAT (obtained using the STUN service). The platform application server obtains the operating status information of each node in the device group where device C is located and forwards the P2P connection establishment request to the idle device node through the signaling server.
[0164] S4: After receiving the P2P connection request, the idle device node in the same device group creates a new network socket and obtains its own NATed public IP and port from the platform's STUN server. It then constructs a P2P connection response containing its own device serial number, network NAT type, NATed public IP and port, and the port number bound to the local network socket, and forwards it to the terminal device via the platform's signaling server. Subsequently, the terminal device and the idle node in the device group initiate the NAT traversal ICE (Interactive Connectivity Establishment) interaction process based on the NAT types and NATed public IP and port of both parties.
[0165] S5: When one of the idle device nodes successfully penetrates NAT, the terminal device stops the NAT penetration process with other device nodes, suspends the real-time preview service with the target device on the relay transmission link, and sends an address exchange request to the target device C and the successfully penetrated device A via the relay transmission link and the P2P transmission link respectively. The request carries the device serial numbers of both devices. The request sent to the target device C also carries the port number bound to the local network socket of device A and the external network IP and port of the terminal device that successfully penetrated.
[0166] S6: Devices A and C match the corresponding device group information based on each other's device serial numbers. After obtaining each other's local IP addresses, they initiate negotiation and perform an address exchange process. Devices A and C bind each other's local IP addresses and send Free ARP requests to other routing nodes in the network to update the ARP entries cached by other routing nodes (i.e., the mapping between IP addresses and MAC addresses).
[0167] After both parties complete the address exchange process, they resend a login request to the platform application server, including the updated device group information. Device C then creates a new network socket and binds it to the port number corresponding to Device A's local network socket. It then sends a request to resume the real-time preview service to the external IP and port number that the terminal device successfully penetrated, completing the link handover process between the terminal device and the target device.
[0168] In another exemplary embodiment, Figure 5 FIG. 1 is a schematic diagram of a dual symmetric NAT scenario of an optional connection establishment method according to an embodiment of the present application, such as Figure 5 As shown in the figure, in the dual symmetric NAT scenario, the target device P2P connection process includes but is not limited to the following:
[0169] When the platform application server identifies that both the terminal device and the target device's network are symmetric, it checks whether there are any asymmetric network nodes under the user account. If so, it executes the target device P2P connection process in a dual symmetric NAT scenario. If not, it stops the NAT traversal process to minimize the impact of complex traversal scenarios on the user's terminal device performance. The dual symmetric NAT scenario differs from the non-dual symmetric NAT scenario in that the NAT traversal process includes a device cascade traversal step, so this process only describes the differences in the NAT traversal process.
[0170] S1: The terminal device sends a P2P connection request to the platform application server with the target device C in network 1, carrying the terminal device's NATed public network IP and port. The platform application server obtains the operating status information of the asymmetric network node (network 2) under the user account and sends a P2P cascade request to the idle device node through the signaling server, carrying the device serial number of the target device C and the terminal device's NATed public network IP and port.
[0171] S2: After receiving the P2P cascade request, the idle device node in the asymmetric network creates a new network socket and obtains its own NATed public network IP and port from the platform STUN server. It then constructs a P2P cascade response with its own NATed public network IP and port, and forwards it to the terminal device through the platform signaling server.
[0172] In step S3, the terminal device and an idle device node on the asymmetric network initiate the NAT traversal ICE interaction process based on the public network IP and port numbers behind NAT on both sides. Furthermore, because the terminal device receives a P2P cascade response message forwarded by the platform, it must wait for the peer to notify it of the traversal result. The NAT traversal process cannot be concluded based on the success of ICE on a single device.
[0173] S4: Each idle device node in the asymmetric network sends a P2P connection request to the platform application server, carrying the device's own NATed public network IP and port. The platform application server obtains the operating status information of each node in the device group where device C is located and forwards the P2P connection request to the idle device node through the signaling server.
[0174] S5: After receiving the P2P connection request, the idle device node in the target device group creates a new network socket and obtains its own NATed public IP and port from the platform's STUN server. It then constructs a P2P connection response carrying its own device serial number, NATed public IP and port, and the port number bound to the local network socket. This response is forwarded to the requesting device in the asymmetric network via the platform's signaling server. Subsequently, the requesting device in the asymmetric network and the idle device node in the target device group initiate the NAT traversal ICE interaction process based on the NATed public IP and port of both parties.
[0175] S6: When both the terminal device and the idle device nodes in the target device group complete NAT traversal with the same idle device (relay device) in the asymmetric network, they both stop NAT traversal with other idle devices in their device groups. Device A is the device in the target device group that has successfully completed NAT traversal, and device D is the device in the asymmetric network that has successfully completed NAT traversal.
[0176] S7, device D sends a P2P cascade completion notification to the terminal device, carrying its own external network IP and port number of successful penetration, the device serial number of device A, and the port number bound to the local network socket of device A;
[0177] S8: The terminal device suspends the real-time preview service with the target device on the relay transmission link, and sends an address exchange request to the target device C and the successfully penetrated device D via the relay transmission link and the P2P transmission link respectively. Device D forwards the address exchange request to device A. The exchange request carries the device serial numbers of devices A and C. The request sent to the target device C also carries the port number bound to the local network socket of device A and the external network IP and port of device D that successfully penetrated.
[0178] S9: The subsequent address exchange process is the same as that in the non-double-symmetric NAT scenario;
[0179] In yet another exemplary embodiment, Figure 6 FIG. 1 is a schematic diagram of the main steps of an optional connection establishment method according to an embodiment of the present application. Figure 6 As shown, the following steps are included:
[0180] S1, start;
[0181] S2, the terminal device establishes a relay transmission link with the target device;
[0182] S3, the terminal device initiates a P2P connection establishment with the target device;
[0183] S4, determining the NAT type of the terminal device and the target device;
[0184] S5: In the case of symmetric vs. cone / cone vs. symmetric / cone vs. cone, the P2P connection establishment process for the non-bisymmetric NAT scenario is performed;
[0185] S6, in the case of symmetric VS symmetric, determining whether there is an asymmetric network node device group under the user account;
[0186] S7, if the result of S6 is yes, execute the P2P connection establishment process in the dual symmetric NAT scenario;
[0187] S8, after the P2P connection establishment process in the non-bisymmetric NAT scenario or the P2P connection establishment process in the bisymmetric NAT scenario is completed, an address switching process is performed;
[0188] S9, when the judgment result of S6 is no or after S8 is completed, ends.
[0189] Through the embodiment of the present application, the terminal device establishes a relay transmission link with the target device, and at the same time initiates a NAT penetration process with the idle devices in the device group. On the premise of not occupying the hardware resources and network resources of the target device, and without affecting the continuity and stability of the target device's service transmission, a P2P connection is established between the terminal device and the target device through a one-to-many NAT penetration method between the terminal device and the idle devices in the device group and an address switching process after the penetration is successful, thereby improving the penetration success rate between the terminal device network and the target device network, and after the NAT penetration is successful, the relay transmission link is seamlessly switched to the P2P transmission link through the address switching process. On the premise of ensuring the continuity and stability of the target device's service transmission, a P2P connection is established between the terminal device and the target device.
[0190] On the other hand, by determining the network NAT type of the terminal device and the target device, the P2P connection process in different NAT scenarios is executed according to different NAT type combinations. In the dual-symmetric NAT scenario, by adding cone network nodes during the interaction between two symmetric network nodes, many-to-many cascade penetration is achieved, thus avoiding the problems of long NAT penetration time and high consumption of device hardware and network resources in dual-symmetric networks.
[0191] It is understandable that in the specific implementation of this application, related data such as user information is involved. When the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0192] It should be noted that for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that this application is not limited by the order of the actions described, because according to this application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by this application.
[0193] According to another aspect of the embodiment of the present application, a connection establishment device for implementing the above connection establishment method is also provided. Figure 7 As shown, the device includes:
[0194] A receiving module 702 is configured to receive a data request message sent by a terminal device, wherein the data request message is used to request data of a target device, and the terminal device and the target device belong to different local area networks;
[0195] an acquisition module 704, configured to establish a relay connection between the terminal device and the target device in response to the data request message, and acquire a network address translation type corresponding to the terminal device and the target device, wherein the network address translation type indicates a behavior mode of a device processing a data packet;
[0196] Processing module 706 is used to establish a point-to-point connection between the terminal device and the target device and interrupt the relay connection based on whether the network address translation types corresponding to the terminal device and the target device are both symmetric, wherein, when at least one of the terminal device and the target device is asymmetric, the point-to-point connection is achieved by exchanging addresses between the target device and a first idle device, and the first idle device and the target device belong to the same local area network. When the terminal device and the target device are both symmetric, the point-to-point connection is achieved by exchanging addresses between the target device, the first idle device and the second idle device, and the second idle device and the target device belong to different local area networks, and the network address translation type of the second idle device is asymmetric.
[0197] As an optional solution, the above-mentioned device is used to establish a point-to-point connection between the terminal device and the target device and interrupt the relay connection based on whether the network address translation types corresponding to the terminal device and the target device are both symmetric in the following manner: when at least one of the terminal device and the target device is asymmetric, establish a point-to-point connection based on the first idle device and interrupt the relay connection; when the terminal device and the target device are both symmetric, establish a point-to-point connection based on the first idle device and the second idle device, and interrupt the relay connection.
[0198] As an optional solution, the above-mentioned device is used to establish a point-to-point connection based on a first idle device and interrupt the relay connection in the following manner when at least one of the terminal device and the target device is not symmetrical: when at least one of the terminal device and the target device is not symmetrical, receive a first point-to-point connection request sent by the terminal device; in response to the first point-to-point connection request, obtain the device operating status of each device in the first group of devices, wherein the first group of devices and the target device belong to the same local area network; determine a first group of idle devices from the first group of devices based on the device operating status; send a first point-to-point connection request to the first group of idle devices; determine the devices in the first group of idle devices that respond to the first point-to-point connection request For a first idle device, a first penetration connection is established between the first idle device and a terminal device; when the first penetration connection is successfully established, a first address exchange request is sent to the target device and the first idle device respectively, wherein the first address exchange request is used to request the target device and the first idle device to exchange address information with each other; when the target device and the first idle device complete the exchange of address information, a login request is received from the target device and the first idle device to complete the login of the target device and the first idle device, the relay connection is switched to a point-to-point connection between the target device and the first idle device, and the relay connection is interrupted, wherein when the target device and the first idle device complete the login, a point-to-point connection is automatically established.
[0199] As an optional solution, the above-mentioned device is used to establish a point-to-point connection based on the first idle device and the second idle device and interrupt the relay connection when the terminal device and the target device are both symmetrical in the following manner: when the terminal device and the target device are both symmetrical, determine whether there is a second idle device; when the second idle device exists, establish a point-to-point connection based on the first idle device and the second idle device, and interrupt the relay connection.
[0200] As an optional solution, the above-mentioned device is used to determine whether there is a second idle device when the terminal device and the target device are both symmetrical in the following manner: when the terminal device and the target device are both symmetrical, receive a second point-to-point connection request sent by the terminal device; in response to the second point-to-point connection request, obtain the device operation status of the second group of devices, wherein the second group of devices and the target device belong to different local area networks, and the network address translation type corresponding to the second group of idle devices is asymmetric; determine a second group of idle devices from the second group of devices based on the device operation status; send a point-to-point cascade request to the second group of idle devices; determine the device in the second group of idle devices that responds to the point-to-point cascade request as the second idle device, and establish a second penetration connection between the second idle device and the terminal device.
[0201] As an optional solution, the above-mentioned device is used to establish a point-to-point connection based on the first idle device and the second idle device and interrupt the relay connection in the following manner when there is a second idle device: when there is a second idle device, receive a third point-to-point connection request sent by the second idle device; in response to the third point-to-point connection request, obtain the device operation status of each device in the first group of devices, wherein the first group of devices and the target device belong to the same local area network; determine the first group of idle devices from the first group of devices based on the device operation status; send a third point-to-point connection request to the first group of idle devices; determine the device in the first group of idle devices that responds to the third point-to-point connection request as the first idle device, and establish the third point-to-point connection between the first idle device and the second idle device. Penetration connection; when the second penetration connection and the third penetration connection are successfully established, sending a second address exchange request to the target device and the second idle device respectively, wherein the second address exchange request is used to request the target device and the first idle device to exchange address information with each other through the second idle device; when the second idle device sends the second address exchange request to the first idle device, and the target device and the first idle device complete the address information exchange, receiving the login request sent by the target device and the first idle device to complete the login of the target device and the first idle device, switching the relay connection to a point-to-point connection between the target device and the first idle device, and interrupting the relay connection, wherein, when the target device and the first idle device complete the login, a point-to-point connection is automatically established.
[0202] In the embodiments of the present application, the term "module" or "unit" refers to a computer program or portion of a computer program that has a predetermined function and works together with other related parts to achieve a predetermined goal. It can be implemented in whole or in part using software, hardware (such as processing circuits or memory), or a combination thereof. Similarly, a processor (or multiple processors or memories) can be used to implement one or more modules or units. In addition, each module or unit can be part of an overall module or unit that includes the functionality of the module or unit.
[0203] Regarding the apparatus in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.
[0204] According to one aspect of the present application, a computer program product is provided, which includes a computer program.
[0205] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0206] Figure 8 The block diagram schematically shows a computer system structure of an electronic device used to implement an embodiment of the present application.
[0207] It should be noted that Figure 8 The computer system 800 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0208] like Figure 8 As shown, computer system 800 includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 802 or programs loaded from storage 808 into random access memory (RAM) 803. RAM 803 also stores various programs and data required for system operation. CPU 801, ROM 802, and RAM 803 are interconnected via bus 804. An input / output interface (I / O) 805 is also connected to bus 804.
[0209] The following components are connected to the input / output interface 805: an input section 806 including a keyboard, mouse, and the like; an output section 807 including devices such as a cathode ray tube (CRT), a liquid crystal display (LCD), and speakers; a storage section 808 including a hard disk; and a communication section 809 including a network interface card such as a local area network card or a modem. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the input / output interface 805 as needed. Removable media 811, such as a magnetic disk, an optical disk, a magneto-optical disk, or a semiconductor memory, is installed in the drive 810 as needed, so that computer programs read from the removable media can be installed in the storage section 808 as needed.
[0210] In particular, according to an embodiment of the present application, the processes described in the various method flow charts can be implemented as computer software programs. For example, an embodiment of the present application includes a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for executing the methods shown in the flow charts. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 809 and / or installed from a removable medium 811. When the computer program is executed by the central processing unit 801, the various functions defined in the system of the present application are performed.
[0211] In such an embodiment, the computer program can be downloaded and installed from the network through the communication section 809 and / or installed from the removable medium 811. When the computer program is executed by the central processing unit 801, various functions provided by the embodiments of the present application are performed.
[0212] According to another aspect of the embodiment of the present application, an electronic device for implementing the above connection establishment method is also provided. The electronic device may be Figure 1 The terminal device or server shown in FIG. This embodiment is described by taking the electronic device as a terminal device as an example. Figure 9 As shown, the electronic device includes a memory 902 and a processor 904. The memory 902 stores a computer program, and the processor 904 is configured to execute the steps of at least one of the above method embodiments through the computer program.
[0213] Optionally, in this embodiment, the electronic device may be located in at least one network device among a plurality of network devices of a computer network.
[0214] Optionally, in this embodiment, the above-mentioned processor can be configured to execute the methods in each embodiment of the present application through a computer program.
[0215] Alternatively, those skilled in the art will appreciate that Figure 9 The structure shown is for illustration only. Figure 9 It does not limit the structure of the above electronic device. For example, the electronic device may also include Figure 9 More or fewer components (such as network interfaces, etc.) as shown in, or with Figure 9 Different configurations shown.
[0216] Among them, the memory 902 can be used to store software programs and modules, such as the program instructions / modules corresponding to the connection establishment method and device in the embodiment of the present application. The processor 904 executes various functional applications and data processing by running the software programs and modules stored in the memory 902, that is, realizing the above-mentioned connection establishment method. The memory 902 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 902 may further include a memory remotely located relative to the processor 904, and these remote memories may be connected to the terminal via a network. Examples of the above-mentioned networks include but are not limited to the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof. Among them, the memory 902 can be used for information such as device information, but is not limited to it. As an example, if Figure 9As shown, the memory 902 may include, but is not limited to, the receiving module 702, the acquiring module 704, and the processing module 706 in the connection establishment device. In addition, it may also include, but is not limited to, other module units in the connection establishment device, which will not be repeated in this example.
[0217] Optionally, the transmission device 906 is configured to receive or transmit data via a network. Specific examples of the aforementioned network may include wired networks and wireless networks. In one embodiment, the transmission device 906 includes a network interface controller (NIC), which can be connected to other network devices and a router via a network cable to enable communication with the Internet or a local area network. In one embodiment, the transmission device 906 is a radio frequency (RF) module configured to communicate with the Internet wirelessly.
[0218] In addition, the electronic device further includes: a display 908 for displaying data transmitted by the target device; and a connection bus 910 for connecting various module components in the electronic device.
[0219] In other embodiments, the terminal device or server may be a node in a distributed system, wherein the distributed system may be a blockchain system, and the blockchain system may be a distributed system formed by connecting multiple nodes via network communication. The nodes may form a peer-to-peer network, and any computing device, such as a server, terminal, or other electronic device, may become a node in the blockchain system by joining the peer-to-peer network.
[0220] According to one aspect of the present application, a computer-readable storage medium is provided, and a processor of an electronic device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the electronic device executes the connection establishment method provided in various optional implementations of the above-mentioned connection establishment aspects.
[0221] Optionally, in this embodiment, the above-mentioned computer-readable storage medium can be configured to store data for executing the methods in various embodiments of the present application.
[0222] Optionally, in this embodiment, a person of ordinary skill in the art may understand that all or part of the steps in the various methods of the above embodiments may be completed by instructing hardware related to the terminal device through a program, and the program may be stored in a computer-readable storage medium, which may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0223] The serial numbers of the above embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0224] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above-mentioned computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a number of instructions for causing one or more electronic devices to execute all or part of the steps of the method described in each embodiment of the present application.
[0225] In the above embodiments of the present application, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0226] In the several embodiments provided in this application, it should be understood that the disclosed applications can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0227] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0228] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0229] The above is only a preferred embodiment of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A connection establishment method, characterized in that: include: Receiving a data request message sent by a terminal device, wherein the data request message is used to request to obtain data of a target device, and the terminal device and the target device belong to different local area networks; In response to the data request message, establish a relay connection between the terminal device and the target device, and obtain network address translation types corresponding to the terminal device and the target device, wherein the network address translation type indicates a behavior mode of a device processing a data packet; Based on whether the network address translation types corresponding to the terminal device and the target device are both symmetric, a point-to-point connection between the terminal device and the target device is established, and the relay connection is interrupted, wherein, when at least one of the terminal device and the target device is asymmetric, the point-to-point connection is realized by exchanging addresses between the target device and a first idle device, and the first idle device and the target device belong to the same local area network, and when the terminal device and the target device are both symmetric, the point-to-point connection is realized by exchanging addresses between the target device, the first idle device and a second idle device, and the second idle device and the target device belong to different local area networks, and the network address translation type of the second idle device is asymmetric; The method further includes: when at least one of the terminal device and the target device is of the asymmetric type and a first penetration connection between the first idle device and the terminal device is successfully established, sending a first address exchange request to the target device and the first idle device respectively, wherein the first address exchange request is used to request the target device and the first idle device to exchange address information with each other; The method also includes: when the terminal device and the target device are both of the symmetric type, and a second penetration connection between the second idle device and the terminal device, and a third penetration connection between the first idle device and the second idle device are successfully established, sending a second address exchange request to the target device and the second idle device respectively, wherein the second address exchange request is used to request the target device and the first idle device to exchange address information with each other through the second idle device.
2. The method according to claim 1, characterized in that The step of establishing a point-to-point connection between the terminal device and the target device based on whether the network address translation types corresponding to the terminal device and the target device are both symmetric, and interrupting the relay connection, comprises: In the case where at least one of the terminal device and the target device is of the asymmetric type, establishing the point-to-point connection based on the first idle device, and interrupting the relay connection; In the case that both the terminal device and the target device are of the symmetric type, the point-to-point connection is established based on the first idle device and the second idle device, and the relay connection is interrupted.
3. The method according to claim 2, characterized in that The step of establishing the point-to-point connection based on the first idle device and interrupting the relay connection when at least one of the terminal device and the target device is not of the symmetric type includes: In a case where at least one of the terminal device and the target device is not of the symmetric type, receiving a first point-to-point connection establishment request sent by the terminal device; In response to the first point-to-point connection establishment request, obtaining a device operation status of each device in a first group of devices, wherein the first group of devices and the target device belong to the same local area network; Determining a first group of idle devices from the first group of devices based on the device operating status; Sending the first point-to-point connection establishment request to the first group of idle devices; Determine a device in the first group of idle devices that responds to the first point-to-point connection establishment request as the first idle device, and establish the first penetration connection between the first idle device and the terminal device; When the target device and the first idle device complete the exchange of address information, a login request sent by the target device and the first idle device is received to complete the login of the target device and the first idle device, the relay connection is switched to a point-to-point connection between the target device and the first idle device, and the relay connection is interrupted, wherein the point-to-point connection is automatically established when the target device and the first idle device complete the login.
4. The method according to claim 2, characterized in that: In the case where both the terminal device and the target device are of the symmetric type, establishing the point-to-point connection based on the first idle device and the second idle device, and interrupting the relay connection, comprises: In the case that the terminal device and the target device are both of the symmetric type, determining whether there is a second idle device; In the case where the second idle device exists, the point-to-point connection is established based on the first idle device and the second idle device, and the relay connection is terminated.
5. The method according to claim 4, characterized in that When both the terminal device and the target device are of the symmetric type, determining whether the second idle device exists includes: In a case where both the terminal device and the target device are of the symmetric type, receiving a second point-to-point connection establishment request sent by the terminal device; In response to the second point-to-point connection establishment request, obtaining a device operation status of a second group of devices, wherein the second group of devices and the target device belong to different local area networks, and the network address translation type corresponding to the second group of devices is the asymmetric type; Determining a second group of idle devices from the second group of devices based on the device operating status; Sending a point-to-point cascade request to the second group of idle devices; A device in the second group of idle devices that responds to the point-to-point cascade request is determined as the second idle device, and the second penetration connection is established between the second idle device and the terminal device.
6. The method according to claim 5, characterized in that The step of establishing the point-to-point connection based on the first idle device and the second idle device and interrupting the relay connection in the presence of the second idle device includes: In the case where the second idle device exists, receiving a third point-to-point connection establishment request sent by the second idle device; In response to the third point-to-point connection establishment request, obtaining a device operation status of each device in a first group of devices, wherein the first group of devices and the target device belong to the same local area network; Determining a first group of idle devices from the first group of devices based on the device operating status; Sending the third point-to-point connection establishment request to the first group of idle devices; Determine a device in the first group of idle devices that responds to the third point-to-point connection establishment request as the first idle device, and establish the third penetration connection between the first idle device and the second idle device; When the second idle device sends the second address exchange request to the first idle device and the target device and the first idle device complete the address information exchange, receive the login request sent by the target device and the first idle device to complete the login of the target device and the first idle device, switch the relay connection to a point-to-point connection between the target device and the first idle device, and interrupt the relay connection, wherein the point-to-point connection is automatically established when the target device and the first idle device complete the login.
7. A connection establishment device, characterized in that: include: A receiving module, used for receiving a data request message sent by a terminal device, wherein the data request message is used for requesting to obtain data of a target device, and the terminal device and the target device belong to different local area networks; an acquisition module, configured to establish a relay connection between the terminal device and the target device in response to the data request message, and acquire network address translation types corresponding to the terminal device and the target device, wherein the network address translation type indicates a behavior mode of a device processing a data packet; a processing module, configured to establish a point-to-point connection between the terminal device and the target device, and interrupt the relay connection, based on whether the network address translation types corresponding to the terminal device and the target device are both symmetric, wherein, when at least one of the terminal device and the target device is asymmetric, the point-to-point connection is realized by exchanging addresses between the target device and a first idle device, the first idle device and the target device belong to the same local area network, and when the terminal device and the target device are both symmetric, the point-to-point connection is realized by exchanging addresses between the target device, the first idle device and a second idle device, the second idle device and the target device belong to different local area networks, and the network address translation type of the second idle device is asymmetric; The apparatus is further configured to: when at least one of the terminal device and the target device is of the asymmetric type and a first penetration connection between the first idle device and the terminal device is successfully established, send a first address exchange request to the target device and the first idle device respectively, wherein the first address exchange request is used to request the target device and the first idle device to exchange address information with each other; The apparatus is further used for, when the terminal device and the target device are both of the symmetric type, and a second penetration connection between the second idle device and the terminal device, and a third penetration connection between the first idle device and the second idle device are both successfully established, sending a second address exchange request to the target device and the second idle device respectively, wherein the second address exchange request is used to request the target device and the first idle device to exchange address information with each other through the second idle device.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored computer program, wherein the computer program can be executed by an electronic device to perform the method described in any one of claims 1 to 6.
9. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method described in any one of claims 1 to 6 are implemented.
10. 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 execute the method according to any one of claims 1 to 6 through the computer program.
Citation Information
Patent Citations
Network crossing method, device and system
CN103391334A
Method and equipment for determining NAT (Network Address Translation) traversal strategy
CN118056391A