WO2020248963A1 - 一种建立端到端网络连接的方法、装置及网络系统 - Google Patents

一种建立端到端网络连接的方法、装置及网络系统 Download PDF

Info

Publication number
WO2020248963A1
WO2020248963A1 PCT/CN2020/095045 CN2020095045W WO2020248963A1 WO 2020248963 A1 WO2020248963 A1 WO 2020248963A1 CN 2020095045 W CN2020095045 W CN 2020095045W WO 2020248963 A1 WO2020248963 A1 WO 2020248963A1
Authority
WO
WIPO (PCT)
Prior art keywords
node
super
nat
data packet
nat type
Prior art date
Application number
PCT/CN2020/095045
Other languages
English (en)
French (fr)
Inventor
杨仁志
王斌
张腾
周力
李艳明
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Priority to EP20822695.1A priority Critical patent/EP3958534B1/en
Priority to US17/618,123 priority patent/US12058096B2/en
Publication of WO2020248963A1 publication Critical patent/WO2020248963A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/256NAT traversal
    • H04L61/2575NAT traversal using address mapping retrieval, e.g. simple traversal of user datagram protocol through session traversal utilities for NAT [STUN]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L45/00Routing or path finding of packets in data switching networks
    • H04L45/72Routing based on the source address
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/2514Translation of Internet protocol [IP] addresses between local and global IP addresses
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/2517Translation of Internet protocol [IP] addresses using port numbers
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/255Maintenance or indexing of mapping tables
    • H04L61/2553Binding renewal aspects, e.g. using keep-alive messages
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/256NAT traversal
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/256NAT traversal
    • H04L61/2589NAT traversal over a relay server, e.g. traversal using relay for network address translation [TURN]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/14Session management
    • H04L67/141Setup of application sessions
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W40/00Communication routing or communication path finding
    • H04W40/02Communication route or path selection, e.g. power-based or shortest path routing
    • H04W40/12Communication route or path selection, e.g. power-based or shortest path routing based on transmission quality or channel quality
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W40/00Communication routing or communication path finding
    • H04W40/02Communication route or path selection, e.g. power-based or shortest path routing
    • H04W40/22Communication route or path selection, e.g. power-based or shortest path routing using selective relaying for reaching a BTS [Base Transceiver Station] or an access point

Definitions

  • This application relates to the field of Internet technology, and in particular to a method, device and network system for establishing an end-to-end network connection.
  • IP Internet Protocol
  • IPv4 Internet Protocol Version 4
  • NAT network address translation
  • NAT While NAT technology solves the problem of the shortage of IPv4 addresses, it also brings about the problem of limited connections between network devices. According to NAT restrictions on network connections, NAT can be divided into full cone NAT (full cone NAT), restricted cone NAT (address-restricted cone NAT), port restricted cone NAT (Port-Restricted cone NAT) and Symmetric NAT (Symmetric NAT).
  • full cone NAT full cone NAT
  • restricted cone NAT restricted cone NAT
  • port restricted cone NAT Port-Restricted cone NAT
  • Symmetric NAT Symmetric NAT
  • NAT traversal technology is widely used.
  • the current NAT traversal is mostly based on STUN (session traversal utilities for NAT) protocol and/or TURN (traversal using relay NAT) protocol.
  • Relay servers are used to handle the connection between network devices in the NAT environment.
  • the network devices that are the two parties of the data interaction need to establish connections with the relay server respectively, and send the data to the relay server, and the relay server forwards the data to the network devices of both parties.
  • the connection quality between network devices will fluctuate due to factors such as the performance, load, and network environment of the relay server, and the maintenance of the relay server usually requires a lot of bandwidth costs.
  • the embodiment of the application provides a method, device and network system for establishing an end-to-end network connection, which can realize the establishment of network connection and data transmission for terminal equipment in any network environment without the need to use a relay server for data transfer. .
  • an embodiment of the present application provides a method for establishing an end-to-end network connection.
  • the method includes: a first node obtains super node information from a server, the super node is a node determined by the server and the network address translation NAT type is a cone NAT, or a node with a public network Internet protocol IP address;
  • the node sends data packets and determines its own NAT type according to the data packets returned by the super node;
  • the first node obtains the NAT type of the second node to be connected from the server; the first node according to its own NAT type and the NAT type of the second node Determine whether to use a relay node; when the first node determines to use a relay node, the first node selects a node from the super nodes as the relay node, and uses the relay node to establish a connection with the second node.
  • the first node obtains super node information from the server; then, uses the super node to obtain its own NAT type, and obtains from the server the NAT type of the second node to be connected; then, according to its own NAT
  • the type and the NAT type of the second node determine whether to use a relay node, and when a relay node needs to be used, a relay node is selected from the super nodes to establish a connection with the second node. Therefore, this method realizes that terminal devices in any network environment can establish network connection and data transmission without using a server for data transfer, so that there is no need to maintain a server for data transfer and avoid additional investment required to maintain the server.
  • the super node can be distributed in a large number of network systems to assume the role of data relay, so that the network resources of the super node can be fully utilized and improved Network resource utilization.
  • the first node sends data packets to at least two super nodes; the first node determines its own data packet according to whether it receives the data packet returned by the super node and the parameters of the data packet returned by the super node.
  • NAT type Therefore, the first node can determine its own NAT type without relying on the server, which provides a basis for determining whether to use a relay node in connection with the second node.
  • the first node selects the first super node and the second super node from the super nodes; the first node sends the first data packet to the first super node, so that the first super node obtains the first The source IP address and source port of the data packet, and instruct the second super node to send the second data packet to the source IP address and source port of the first data packet; if the first node receives the second data packet, it determines its own NAT
  • the type is a complete cone NAT.
  • the first node can determine whether its NAT type is a complete cone NAT.
  • the first node if it does not receive the second data packet, it sends the third data packet to the second super node, so that the second super node obtains the source IP address and source port of the third data packet , And analyze whether the source port of the first data packet and the source port of the third data packet are the same; if the source port of the first data packet is different from the source port of the third data packet, the first node determines that its NAT type is symmetric NAT. Therefore, when the first node determines that its own NAT type is not a complete cone NAT, with the second super node, it further determines whether its own NAT type is a symmetric NAT.
  • the first node analyzes whether the fourth data packet is received, and the fourth data packet is the second super node The source IP address and source port of the third data packet are sent, and the public network port used by the second super node to send the fourth data packet is different from the destination port of the third data packet; if the first node receives the fourth data packet, then It is determined that its NAT type is restricted cone NAT; if the first node does not receive the fourth data packet, it is determined that its NAT type is port restricted cone NAT.
  • the first node determines that its NAT type is not a complete cone NAT or a symmetric NAT, with the help of the second super node, it can further determine whether its NAT type is a restricted cone NAT or a port restricted cone. NAT.
  • the first node obtains the link quality of each super node, and selects the first super node and the second super node according to the link quality. Therefore, it is ensured that the first node forms a low-latency and stable communication with the first super node and the second super node, and the speed and accuracy of the first node in determining its own NAT type are improved.
  • the first node determines whether the super node information includes historically selected super nodes, and if the historically selected super nodes are included, the first super node is selected from the historically selected super nodes And the second super node. Therefore, the first node does not need to obtain the link quality of each super node, and can select the first super node and the second super node to increase the selection speed.
  • the first node obtains online node information from the server; the first node determines the node identity (ID) of the second node from the online node information according to the user instruction; Send a query instruction carrying the node ID of the second node; the first node receives the NAT type of the second node that the server inquires according to the node ID of the second node.
  • the first node obtains the NAT type of the second node from the server, which provides a basis for determining whether to use the relay node to establish a connection with the second node.
  • the A node determines that no relay node is needed. Therefore, using the feature that nodes under the complete cone NAT and nodes with public IP addresses can be accessed by any node, when the NAT type of any one of the first node and the second node is a complete cone NAT, or, When any one has a public IP address, the first node can be directly connected to the second node, so there is no need to use a relay node.
  • the first node determines to use the relay node, which is used for the first node and the second node to perform UDP (user datagram protocol, user Datagram protocol) hole punch.
  • UDP user datagram protocol, user Datagram protocol
  • the first node and the second node satisfy that the NAT type of one node is a symmetric NAT, and the NAT type of the other node is a port-restricted cone NAT, the first node determines that it is in use
  • the relay node is used by the first node and the second node to perform port prediction.
  • the first node determines to use a relay node, and the relay node is used in the first node and the second node Data is forwarded between.
  • the first node obtains the link quality of each super node, and selects a relay node from the super nodes according to the link quality. Therefore, it is ensured that the relay node and the first node and the second node form low-delay and stable communication through the data forwarding of the relay node.
  • the first node, the second node, and the super node include terminal devices located in a wide area network (WAN) and/or a local area network (LAN).
  • WAN wide area network
  • LAN local area network
  • the server is located in a wide area network WAN and/or a local area network LAN; the server has a public IP address, or the NAT type of the server is a cone NAT. Therefore, it is ensured that any terminal device can actively access the server and establish a connection with the server.
  • the first node uses the relay node to perform instant messaging (IM) with the second node.
  • IM instant messaging
  • the instant communication includes voice communication, video communication, image transmission, text transmission, and/or file transmission. In at least one form.
  • an embodiment of the present application also provides an apparatus for establishing an end-to-end network connection.
  • the device includes: a transceiver, a memory, and a processor; wherein the memory includes program instructions.
  • the program instructions When the program instructions are executed by the processor, the device is used to perform the following steps: obtain super node information from the server, and the super node is determined by the server, Network address translation (NAT) type is a conical NAT node, or a node with a public Internet protocol (IP) address; sending data packets to the super node, and according to the data packet returned by the super node Determine its own NAT type; obtain the NAT type of the second node to be connected from the server; determine whether to use a relay node according to its own NAT type and the NAT type of the second node; when it is determined to use a relay node, from the super node The node is selected as the relay node, and the relay node is used to establish a connection with the second node.
  • NAT Network
  • the device provided by the embodiment of the application is used to obtain the super node information including the super node from the server; then, use the super node to obtain its own NAT type, and obtain the NAT type of the second node to be connected from the server; then, according to The own NAT type and the NAT type of the second node determine whether to use the relay node, and when the relay node needs to be used, the relay node is selected from the super nodes to establish a connection with the second node.
  • this method realizes that terminal devices in any network environment can establish network connection and data transmission without using a server for data transfer, and there is no need to maintain a server for data transfer, thereby avoiding additional investment required to maintain the server Bandwidth and other costs; and, since any terminal device that meets the requirements of the NAT type can be used as a super node, the super node can be distributed in a large number of network systems to assume the role of data relay, so that the network resources of the super node can be fully utilized and improved Network resource utilization.
  • the device provided in the embodiment of the present application may also implement other implementation manners of the foregoing first aspect.
  • the embodiments of the present application also provide a network system.
  • a network system Including: node and server; server, used to send super node information to the first node, a super node is a node whose NAT type determined by the server is a conical NAT, or a node with a public IP address; the first node is used to Send data packets to the super node, and determine its own NAT type according to the data packets returned by the super node; the server is also used to respond to the request of the first node and send the NAT type of the second node to the first node, and the second node is the first node.
  • the node to be connected selected by a node; the first node is also used to determine whether to use a relay node according to its own NAT type and the NAT type of the second node; the first node is also used when it is determined to use a relay node , Select a node from the super nodes as a relay node, and use the relay node to establish a connection with the second node.
  • the first node obtains the super node information including the super node from the server; then, uses the super node to obtain its own NAT type, and obtains from the server the NAT type of the second node to be connected; then, Determine whether to use the relay node according to its own NAT type and the NAT type of the second node, and when the relay node needs to be used, the relay node is selected from the super nodes to establish a connection with the second node. Therefore, this method realizes that terminal devices in any network environment can establish network connection and data transmission without using a server for data transfer, so that there is no need to maintain a server for data transfer and avoid additional investment required to maintain the server.
  • the super node can be distributed in a large number of network systems to assume the role of data relay, so that the network resources of the super node can be fully utilized and improved Network resource utilization.
  • first node in the system provided in the embodiment of the present application may also execute other implementation manners of the foregoing first aspect.
  • the embodiments of the present application also provide a computer-readable storage medium, and the computer-readable storage medium stores instructions, which when run on a computer, cause the computer to execute the methods of the above aspects.
  • the embodiments of the present application also provide a computer program product containing instructions, which when run on a computer, cause the computer to execute the methods of the foregoing aspects.
  • the embodiments of the present application also provide a chip system including a processor, which is used to support the above-mentioned device or system to realize the functions involved in the above-mentioned aspects, for example, to generate or process the functions involved in the above-mentioned method. information.
  • Figure 1 shows a typical NAT application scenario
  • Figure 2 is a schematic diagram of a complete cone NAT
  • Figure 3 is a schematic diagram of a restricted cone NAT
  • Figure 4 is a schematic diagram of a port restricted cone NAT
  • Figure 5 is a schematic diagram of a symmetric NAT
  • Figure 6 is a schematic diagram of the current NAT traversal technology
  • FIG. 7 is a schematic structural diagram of a network system provided by an embodiment of this application.
  • FIG. 8 is a flowchart of a method for establishing an end-to-end network connection provided by an embodiment of this application.
  • Figure 9 shows a schematic diagram of UDP hole punching using a relay node
  • FIG. 10 shows a schematic diagram of port prediction direct connection using a relay node
  • Figure 11 shows a flow chart for the first node to determine its own NAT type
  • FIG. 12 is a schematic diagram of the first stage of the first node determining its own NAT type
  • Figure 13 is a schematic diagram of the second stage of the first node determining its own NAT type
  • Figure 14 is a schematic diagram of the third stage of the first node determining its own NAT type
  • step S103 is a flowchart of step S103 of a method for establishing an end-to-end network connection provided by an embodiment of the present application;
  • 16 is a schematic structural diagram of an apparatus for establishing an end-to-end network connection provided by an embodiment of the application;
  • FIG. 17 is a schematic structural diagram of another apparatus for establishing an end-to-end network connection provided by an embodiment of this application.
  • FIG. 18 is a schematic diagram of a computer-readable storage medium provided by an embodiment of this application.
  • FIG. 19 is a schematic structural diagram of a chip system provided by an embodiment of the application.
  • IP addresses can include public network addresses and intranet addresses.
  • the public network address refers to the unique IP address in the Internet, such as the IP address of a wide area network (WAN), the public network address can be routed in the public network;
  • the internal network address refers to the internal network, such as a local area network (local area network, LAN) IP address, the internal network address cannot be routed in the public network.
  • the intranet IP address can include three different ranges of Internet Protocol Version 4 (IPv4) address space, used for enterprise intranets or private intranets of different sizes ,as follows:
  • NAT Network address translation
  • the 1918 private network address allocation (address allocation for private internets) protocol defines the intranet IP address space, which allocates an intranet IP address for each device in the intranet environment, and uses the mapping from the intranet IP address to the external IP address, Enable network devices located in the intranet environment to access the Internet through the same public IP address, thereby solving the problem of the shortage of IPv4 addresses.
  • Figure 1 shows a typical NAT application scenario.
  • a private network includes a private intranet with an intranet address space (such as 192.168.xx or 10.xxx) and a router (as a NAT device) connected to the intranet .
  • This router occupies an intranet address (such as 10.76.100.1) in the network address space, and it also connects to the public network through public IP addresses provided by one or more Internet service providers (ISPs).
  • ISPs Internet service providers
  • the source address (source IP and source port) of the data packet is converted from the internal network address (internal network IP and internal network port) to the public network address (public network IP and public network port) ).
  • the router tracks the destination address (destination IP and destination port) on each connection.
  • a data packet returns to the router, it uses the connection tracking data recorded in the output stage to determine which network device to forward to in the intranet.
  • NAT While NAT technology solves the problem of the shortage of IPv4 addresses, it also brings about the problem of limited connections between network devices. According to NAT restrictions on network connections, NAT can be divided into full cone NAT (full cone NAT), restricted cone NAT (address-restricted cone NAT), port restricted cone NAT (Port-Restricted cone NAT) and Symmetric NAT (Symmetric NAT).
  • full cone NAT full cone NAT
  • restricted cone NAT restricted cone NAT
  • port restricted cone NAT Port-Restricted cone NAT
  • Symmetric NAT Symmetric NAT
  • FIG 2 is a schematic diagram of a complete cone NAT.
  • a network nested word socket (LocalIP: LocalPort (intranet IP address: intranet port))
  • Intranet IP address intranet port
  • NAT Network nested word socket
  • PublicIP PublicPort
  • the internal network host will use this socket to send data packets to any external host using this (PublicIP: PublicPort).
  • PublicIP PublicPort
  • any external host can send data packets to the intranet host through this (PublicIP: PublicPort).
  • FIG 3 is a schematic diagram of a restricted cone NAT.
  • a network nested word socket (LocalIP: LocalPort) is established in an intranet host, and a data packet is sent to an external host through the socket for the first time, the NAT device will assign a (PublicIP: PublicPort ), the data packets sent by the intranet host using this socket to any external host will use this (PublicIP: PublicPort).
  • PublicIP PublicPort
  • the external host wants to send data packets to the internal host to meet two conditions: First, the internal host has sent a data packet to an external host (IP-1: Port-1) through the socket; The external host uses (IP-1: any Port) to send data packets to (PublicIP: PublicPort); if these two conditions are not met, the internal host cannot receive the data packets from the external host.
  • IP-1 Port-1
  • PublicIP PublicPort
  • FIG 4 is a schematic diagram of a port restricted cone NAT.
  • a network nested word socket (LocalIP: LocalPort)
  • the NAT device will assign a (PublicIP: PublicPort )
  • PublicIP PublicPort
  • the data packets sent by the intranet host using this socket to any external host will use this (PublicIP: PublicPort).
  • the external host wants to send data packets to the internal host to meet two conditions: First, the internal host has sent a data packet to an external host (IP-1: Port-1) through the socket; The external host uses (IP-1: Port-1) to send data packets to (PublicIP: PublicPort); if these two conditions are not met, the internal host cannot receive the data packets from the external host.
  • IP-1 Port-1
  • PublicIP PublicPort
  • FIG. 5 is a schematic diagram of a symmetric NAT.
  • a network nested word socket (LocalIP: LocalPort)
  • the NAT device will assign a (PublicIP- 1: Port-1)
  • the internal network host also uses this socket to send data packets to the external host 2 for the first time
  • the NAT device will also allocate one (PublicIP-2: Port-2) to it, if there are more NAT devices
  • PublicIP-1 and PublicIP-2 may be different. If the NAT device has only one public IP address, Port-1 and Port-2 must be different.
  • any external host wants to send data to this intranet host, it should first receive the data sent to him by this intranet host. Otherwise, even if the external host knows one of the intranet hosts (PublicIP: Port), it cannot Send data to this intranet host.
  • PublicIP Port
  • FIG. 6 is a schematic diagram of the current NAT traversal technology. As shown in Figure 6, most of the current NAT traversal is based on STUN (session traversal utilities for NAT) protocol and/or TURN (traversal using relay NAT) protocol.
  • Relay servers are used to handle the communication between network devices. Connection. Among them, the relay server is a public server that uses a well-known public IP address that can be accessed from anywhere in the world.
  • the network equipment in the intranet first actively establishes and maintains a connection with the relay server. When the network devices of the two communication parties exchange data, they send the data packet to the relay server, and the relay server is responsible for forwarding the data packet to the other party's network device.
  • devices A, B, and C respectively establish connections with the relay server.
  • device A in the local area network wants to send a picture to device B in another local area network
  • device A needs to send the picture to the relay server first, and the relay server receives the picture sent by device A, and then The picture is forwarded to device B
  • device C in the public network wants to send a picture to device A in the local area network
  • device C also needs to first send the picture to the relay server, and the relay server receives the transmission from device C After the picture, forward the picture to device A.
  • the relay server needs to forward the data generated by all devices, which will bring serious bandwidth overhead, high bandwidth investment cost, and high maintenance cost of the relay server.
  • the connection quality between network devices will also be affected.
  • the embodiment of the application provides a method for establishing an end-to-end network connection.
  • This method can be applied to the network system shown in FIG. 7.
  • the network system includes servers and nodes.
  • the nodes are named ordinary nodes and super nodes according to different network functions in the embodiments of this application. There is no essential difference between ordinary nodes and super nodes except for different network functions.
  • a node can be either a normal node or a super node.
  • Ordinary nodes and super nodes can be terminal devices located in a wide area network (WAN) and/or a local area network (LAN), such as mobile phones, personal computers, workstations, tablet computers, smart wearable devices, Smart home equipment, Internet of Things equipment, etc.
  • WAN wide area network
  • LAN local area network
  • the node can be installed with a client program, and users with a specific account can use the account to log in to the server in the client program to establish a long connection between the node and the server.
  • the server can be located in the wide area network WAN, and/or the local area network LAN; and the server should have a public IP address, or the NAT type of the server is a cone NAT, so that any terminal device can actively access the server and communicate with the server.
  • the server establishes a connection.
  • Fig. 8 is a flowchart of a method for establishing an end-to-end network connection provided by an embodiment of the application.
  • This method is used to establish an end-to-end network connection between two nodes to realize end-to-end communication between the two nodes, such as instant communication, such as: voice communication, video communication, image transmission, text transmission, and file transmission.
  • instant communication such as: voice communication, video communication, image transmission, text transmission, and file transmission.
  • the embodiments of the present application refer to these two nodes as the first node and the second node, where the first node is the node that initiates the connection, and the second node is the node that responds to the connection.
  • the method may include the following steps:
  • Step S101 The first node obtains super node information from the server.
  • the super node is a node determined by the server and whose network address translation NAT type is a cone NAT, or a node with a public network Internet Protocol IP address.
  • the Internet Protocol IP address may include a public IP address and an intranet IP address.
  • the public IP address refers to the unique IP address in the Internet, such as the IP address of a wide area network (WAN).
  • the public IP address can be routed in the public network;
  • the internal IP address refers to the internal network , Such as the IP address of the local area network (LAN), the internal network IP address cannot be routed in the public network.
  • the server when the first node logs in to the server, the server performs login verification on the first node based on information such as the user account and public key. If the first node login verification is passed, the first node establishes a persistent connection with the server and sends the A node sends super node information.
  • Super node information can include the node identity (ID), IP address (including IPv4 address and/or IPv6 address), port (including public network port and internal network port (if NAT exists) of the super node), online status, etc. information.
  • the node ID may be any information used to determine the identity of the node, such as the node number, the MAC address of the node, the hardware identification code of the node, or the unique identifier (UID) of the node.
  • the super node information may be a super node list as shown in Table 1.
  • the server in the initial stage of the establishment of the network system, may not have determined a super node from the connected nodes, or, has not determined a sufficient number of super nodes. At this time, the server may determine itself as a super node. When the network system has multiple servers, some of the servers can be determined to be super nodes.
  • the server determines multiple super nodes, it can choose to send only part of the super node information to the first node. For example, according to the geographic location of the first node, only the super node information near the first node is sent.
  • the server may obtain the public network IP address of the first node from the data packet sent by the first node, and determine the geographic location information of the first node according to the public network IP address, for example: located in City A ; Then, the server can select the super node information located in city A from the determined super nodes and send it to the first node.
  • the first node can obtain its own geographic location information through a built-in GPS module, etc., and when logging in to the server, send its own geographic location information to the server, so that the server can use the The geographic location information selects the super node information near the first node and sends it to the first node.
  • the server can obtain the Internet service provider ISP information of the first node according to the public network IP address of the first node, and then select the super node information with the same ISP as the first node and send it to the first node . For example, if the server determines that the ISP of the first node is China Telecom according to the public network IP address of the first node, the server will select the super node information of the same ISP as China Telecom and send it to the first node.
  • the server can ensure that the first node and the super node have a low connection delay and a stable connection speed by sending the nearby super node information or the super node information of the same ISP to the first node.
  • the super node may be a node whose NAT type is a conical NAT, or a node with a public IP address.
  • ISPs due to the shortage of IPv4 addresses, ISPs usually do not assign IPv4 public network addresses to nodes, and the number of IP addresses that can be assigned to IPv6 is huge, so there is no need to worry about address shortages. Therefore, when ISPs support IPv6, ISPs usually Nodes are assigned unique public network IPv6 addresses, so that these nodes with IPv6 addresses can be used as super nodes.
  • Step S102 The first node sends a data packet to the super node, and determines its own NAT type according to the data packet returned by the super node.
  • the first node may select at least two super nodes to determine its own NAT type, which may specifically include sending data packets to at least two super nodes. After receiving the data packets, the super node responds according to rules and returns data Then, the first node can determine its own NAT type according to whether it receives the data packet returned by the super node, and the source IP address and source port of the data packet returned by the super node.
  • the specific implementation process of the first node selecting at least two super nodes to determine its own NAT type in step S102 will be further elaborated in conjunction with FIG. 11-14.
  • each node after each node logs in to the server each time, it will determine its own NAT type according to the obtained super node, and report it to the server, so that the server will record the NAT type of all logged-in nodes and report it according to the latest node
  • the NAT type updates and maintains the super node information. For example, if a node has not been determined as a super node before, but its latest NAT type reported at time T0 is a complete cone NAT, the server can determine it as a super node at time T0; if a node has been determined as a super node Node, but its latest NAT type reported at time T1 is a symmetric NAT, then the server can determine that it is a normal node at time T1.
  • Step S103 The first node obtains the NAT type of the second node to be connected from the server.
  • the first node After logging in to the server, the first node can obtain the online node synchronously from the server and present it to the user through the client; then, the user can determine the second node from the online nodes by performing a selection operation on the client; then, the first node The node initiates a request for obtaining the NAT type of the second node to the server according to the second node determined by the user; the server responds to the request of the first node, queries the NAT type of the second node, and returns it to the first node.
  • Step S103 that is, the specific implementation process of the first node obtaining the NAT type of the second node to be connected from the server, will be further elaborated in conjunction with FIG. 15.
  • Step S104 The first node determines whether to use the relay node according to its own NAT type and the NAT type of the second node.
  • the NAT type of the relay node is a cone NAT, or has a public Internet protocol (IP) address
  • IP Internet protocol
  • the relay node can establish a connection with the first node and the second node respectively.
  • the first node and the second node need to establish a connection and perform data communication, they can establish a connection through a relay node according to their own NAT type, and can establish an indirect connection through the data transfer of the relay node.
  • the first node and the second node establish an indirect connection through the relay node, the data communication between the first node and the second node is transmitted through the relay node.
  • Step S105 When the first node determines to use the relay node, the first node selects a node from the super nodes as the relay node, and uses the relay node to establish a connection with the second node.
  • Table 2 shows the correspondence between the NAT type and connection mode of the node.
  • the first node and the second node may The connection is established through the "direct connection" method, without the use of relay nodes.
  • the IPv6 addresses assigned by the ISP to the nodes are all public IP addresses. Therefore, if the first node and/or the second node have an IPv6 address, the connection can be established through a "direct connection" method, without the need for a relay node .
  • the first node and the second node can be established through "traversal and direct connection".
  • connection “Direct connection after traversal” specifically includes that the first node and the second node first use the relay node to perform UDP hole punching (UDP hole punch), and establish a direct connection after the hole punching is successful.
  • UDP hole punch UDP hole punch
  • the first node and the second node can also establish a connection through "traversal and direct connection”.
  • Figure 9 shows a schematic diagram of UDP hole punching using a relay node.
  • the first node A is located under the NAT device N1
  • the second node B is located under the NAT device N2
  • the NAT device N1 has the public IP address P1
  • the NAT device N2 has the public IP address P2
  • C1 is the relay node.
  • the embodiment of the application uses a relay node to perform UDP hole punching to establish a direct connection between the first node A and the second node B, including the following steps:
  • Step 1 The first node A and the second node B respectively establish UDP connections with the relay node C1; NAT devices N1 and N2 create a UDP conversion state, the NAT device N1 allocates the public network port X to the first node A, and the NAT device N2 is The second node B allocates public network port Y.
  • Step 2 The first node A sends a UDP packet to the relay node C1 to inform the relay node C1 of the request of the first node A to establish a connection with the second node B.
  • Step 3 The relay node C1 sends a UDP packet to the second node B to send the request of the first node A to establish a connection with the second node B and the public network IP address and public network port of the first node A (P1: X ) Inform the second node B.
  • Step 4 If the second node B accepts the connection request of the first node A, it sends a UDP packet to the public network IP address and public network port (P1:X) of the first node A.
  • the UDP packet sent by the second node B is not forwarded to the first node A after being received by the NAT device N1, but is discarded because the first node A has not sent a data packet to the second node B before.
  • Step 5 The first node A sends a UDP packet to the public network IP address and public network port (P2: Y) of the second node B, where (P2: Y) can be notified to the first node A by the relay node C1. Since the second node B has sent a UDP packet to the first node A before, the NAT device N2 will forward the data packet to the second node B so that the second node B can receive the UDP packet of the first node A.
  • P2: Y public network IP address and public network port
  • the first node A and the second node B have successfully punched holes to establish direct communication.
  • the first node and the second node when one of the first node and the second node is a symmetric NAT, and the other node is a port-restricted conical NAT, the first node and the second node can be directly connected through "port prediction ”Method to establish a connection, “port prediction direct connection” method requires at least two relay nodes to achieve.
  • FIG. 10 shows a schematic diagram of port prediction direct connection using a relay node.
  • the first node A is located under the NAT device N1
  • the second node B is located under the NAT device N2
  • the NAT device N1 has the public IP address P1
  • the NAT device N2 has the public IP address P2.
  • C1 and C2 are Relay node.
  • the first node A and the second node B use "port prediction direct connection" to establish a direct connection, which may include The following steps:
  • Step 1 The first node A sends a data packet to the relay node C1, so that the relay node C1 obtains the public network port X1 allocated by the NAT device N1 for the first node A.
  • Step 2 The relay node C1 feeds back the public network port X1 to the first node A.
  • Step 3 The first node A sends a data packet to the relay node C2.
  • the data includes information such as the public network port X1 fed back by the relay node C1, so that the relay node C2 obtains the NAT device N1 twice allocated to the first node A Public network ports X1 and X2.
  • Step 4 The second node B sends a data packet to C2, so that the relay node C2 obtains the public network port Y allocated by the NAT device N2 for the second node B.
  • Step 5 The relay node C2 predicts the port allocated by the NAT device N1 based on the obtained public network ports X1 and X2, and sends the prediction result to the second node B, and feeds back the public network port Y to the first node A ,
  • the prediction result can include multiple predicted ports.
  • Step 6 the second node B uses the predicted port as the target port to send a large number of data packets to the first node A.
  • Step 7 The first node A uses port Y as the target port to send a large number of data packets to the second node B, and then switches to the receiving mode.
  • the second node B can receive the data packet sent by the first node A to the port Y, and the first node A can receive The data packet sent by the second node B to the hit port. So far, the port prediction of the first node A and the second node B is successful, and direct communication is established.
  • the first node and the second node may forward data through the relay node to establish communication. Specifically, the first node and the second node establish a connection with the relay node, and the data that needs to be transmitted between the first node and the second node is sent to the relay node, and the relay node forwards the data to the other node.
  • the first node can perform tranceroute operation or ping operation on each known super node to obtain route tracking information (route hops, route) and communication between the first node and each super node.
  • Route tracking information route hops, route
  • Index information that can reflect link quality such as time-consuming and/or packet loss rate, and then select a super node with better link quality as a relay node according to at least one index information.
  • the relay node forms a low-delay and stable communication with the first node and the second node.
  • the first node determines that the relay node that has been selected is included in the super node information, and if it does, the relay node that has been selected is re- Determined as a relay node.
  • the first node does not need to obtain the link quality of each super node, and the selection speed of the relay node is improved.
  • the first node obtains super node information from the server; then, uses the super node to obtain its own NAT type, and obtains from the server the NAT type of the second node to be connected; then, according to its own NAT
  • the type and the NAT type of the second node determine whether to use a relay node, and when a relay node needs to be used, a relay node is selected from the super nodes to establish a connection with the second node. Therefore, this method realizes that terminal devices in any network environment can establish network connection and data transmission without using a server for data transfer, so that there is no need to maintain a server for data transfer and avoid additional investment required to maintain the server.
  • the super node can be distributed in a large number of network systems to assume the role of data relay, so that the network resources of the super node can be fully utilized and improved Network resource utilization.
  • Fig. 11 shows a flowchart for the first node to determine its own NAT type.
  • step S102 that is, the first node sends a data packet to the super node, and determines its own NAT type according to the data packet returned by the super node, including the following steps:
  • Step S201 the first node selects the first super node and the second super node from the super nodes.
  • the first node can perform tranceroute operation or ping operation on each known super node to obtain route tracking information (route hops, route) and communication between the first node and each super node.
  • Route tracking information route hops, route
  • Index information that can reflect link quality such as time-consuming and/or packet loss rate, and then select two super nodes with better link quality as the first super node and the second super node according to at least one index information.
  • the first node forms a low-latency and stable communication with the first super node and the second super node, and the speed and accuracy of the first node in determining its own NAT type are improved.
  • the first node judges that the super node that has been selected is included in the super node information, and if it contains, the super node that has been selected is included in the super node information.
  • the nodes are re-determined as the first super node and the second super node.
  • the first node does not need to obtain the link quality of each super node, and can select the first super node and the second super node to increase the selection speed.
  • Fig. 12 is a schematic diagram of the first stage in which the first node determines its own NAT type.
  • the first stage includes step S202 and step S203, which can determine whether the first node is a complete cone NAT.
  • Step S202 The first node sends a first data packet to the first super node.
  • the first node A sends a first data packet D1 to the first super node S1; the first super node S1 receives the first data packet D1, and obtains the source IP address and source of the first data packet D1 from the analysis Port (P1: X1), (P1: X1) is the public network IP address and public network port assigned by the NAT device to the first node A.
  • the first data packet D1 also contains instructions for instructing the first super node S1 to notify (P1: X1) to the second super node S2, and instructing the second super node S2 to send the second super node S2 to (P1: X1) Data packet D2.
  • Step S203 If the first node receives the second data packet, it determines that its NAT type is a complete cone NAT.
  • the complete cone NAT does not restrict the data packets of the external host, if the first node A can receive the data packet of the second super node S2 without sending the data packet to the second super node S2, then Explain that its NAT type is a complete cone NAT.
  • the first node can determine whether its own NAT type is a complete cone NAT through one data packet sending and receiving action.
  • Figure 13 is a schematic diagram of the second stage of the first node determining its own NAT type.
  • the second stage includes step S204 and step S205, which can determine whether the first node is a symmetric NAT.
  • Step S204 If the first node does not receive the second data packet, it sends a third data packet to the second super node.
  • the first node may preset the duration Tn. After the first node sends the first data packet to the first super node at time Ts, it waits to receive the second data packet. If the first node waits until the time Ts+Tn If the second data packet is not received, it can be considered that "the second data packet is not received".
  • the first node A sends a third data packet D3 to the second super node S2; the second super node S2 receives the third data packet D3, and parses to obtain the source IP address and source port of the third data packet D3 (P3: X3), (P3: X3) is the public IP address and public network port assigned by the NAT device to the first node A; then, the second super node S2 analyzes the source port X1 and the third port of the first data packet Whether the source port X3 of the data packet is the same, then the analysis result is sent to the first node A through (P3: X3).
  • Step S205 If the source port of the first data packet is different from the source port of the third data packet, the first node determines that its NAT type is a symmetric NAT.
  • symmetric NAT allocates different public network ports for connections initiated by internal hosts to different external devices, if the source port X1 and source port X3 are different, it means that the NAT type of the first node is a symmetric NAT.
  • Figure 14 is a schematic diagram of the third stage of the first node determining its own NAT type.
  • the third stage includes steps S206 to S208, which can determine whether the first node is a restricted cone NAT or a port restricted cone NAT.
  • Step S206 If the source port of the first data packet is the same as the source port of the third data packet, the first node analyzes whether the fourth data packet is received.
  • the fourth data packet D4 is sent to (P3: X3) by the second super node S2 when it is determined that the source port X1 and the source port X3 are the same.
  • the public network port used by the second super node S2 to send the fourth data packet D4 is different from the destination port of the third data packet D3.
  • Step S207 If the first node receives the fourth data packet, it determines that its NAT type is restricted cone NAT.
  • the restricted cone NAT does not restrict the source port of the data packet sent by the external host, if the first node A receives the fourth data packet D4, it indicates that the NAT type is a restricted cone NAT.
  • Step S208 If the first node does not receive the fourth data packet, it determines that its NAT type is a port-restricted cone NAT.
  • the first node can preset the duration Tm. After the first node sends the third data packet to the second super node at the time Tr, it waits to receive the fourth data packet. If the first node waits until the time Tm+Tr If the fourth data packet is not received, it can be considered that "the fourth data packet has not been received".
  • the restricted cone NAT restricts the source port of the data packet sent by the external host, if the first node A does not receive the fourth data packet D4, it means that the NAT type is a port restricted cone NAT.
  • the first node can determine its own NAT type by using the super node to send and receive data packets and determine at most three stages, and provide a basis for determining whether to use a relay node to establish a connection with the second node.
  • FIG. 15 is a flowchart of step S103 of a method for establishing an end-to-end network connection provided by an embodiment of the present application.
  • step S103 that is, the first node obtains the NAT type of the second node to be connected from the server, and includes the following steps:
  • Step S301 The first node obtains online node information from the server, the online node information includes the node ID of the online node, and the online node includes a node that has established a connection with the server.
  • the server can summarize the connected node information to obtain online node information.
  • the online node information may be an online node list, and the online node list may include information such as the node ID of the online node and the user name and avatar bound to the node.
  • the first node can send a synchronization request to the server to make the server send online node information to the first node.
  • the server can directly send the online node list to the first node.
  • the server may also actively send online node information to the first node, so that the first node does not need to send a request to the server.
  • Step S302 the first node determines the node ID of the second node according to the user instruction and online node information
  • the first node After the first node obtains the online node information, it can display the online node information to the user in the form of visualization or voice information. Allow users to select the second node through visual operation or voice operation.
  • the client program installed on the mobile terminal when the first node is a mobile terminal with a screen, the client program installed on the mobile terminal generates an operable interface for selecting the second node and displays it on the screen.
  • the operable interface can display information such as the user name and avatar bound to each online node. Therefore, a user with a mobile terminal can select any online node as the second node by means of touch and key. After the user makes a selection, the first node can determine the node ID of the second node.
  • Step S303 The first node sends a query instruction carrying the node ID of the second node to the server.
  • the server After receiving the query instruction, the server queries the NAT type of the second node according to the node ID carried in the query instruction. Since a node will report its own NAT type to the server every time it logs in, the NAT type of each node maintained by the server can be kept up to date, so the NAT type of the second node obtained in the first section is also up to date.
  • Step S304 The first node receives the NAT type of the second node from the server.
  • the first node obtains the NAT type of the second node from the server, which provides a basis for judging whether to use the relay node to establish a connection with the second node.
  • the first node includes hardware structures and/or software modules corresponding to each function.
  • the embodiments of the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain function is executed by hardware or computer software-driven hardware depends on the specific application and design constraint conditions of the technical solution. Professionals and technicians can use different methods for each specific application to implement the described functions, but such implementation should not be considered as going beyond the scope of the embodiments of the present application.
  • FIG. 16 is a schematic structural diagram of an apparatus for establishing an end-to-end network connection provided by an embodiment of the application.
  • the device for establishing an end-to-end network connection serves as the first node and implements the corresponding function through the hardware device structure shown in FIG. 16.
  • the device for establishing an end-to-end network connection includes a transceiver 401, a memory 402, and a processor 403.
  • the processor 403 may include one or more processing units.
  • the processor 403 may include an application processor (AP), a modem processor, and a graphics processing unit (GPU). ), image signal processor (image signal processor, ISP), controller, video codec, digital signal processor (digital signal processor, DSP), baseband processor, and/or neural network processor (neural-network processing) unit, NPU), etc.
  • AP application processor
  • modem processor modem processor
  • GPU graphics processing unit
  • image signal processor image signal processor
  • ISP image signal processor
  • controller video codec
  • digital signal processor digital signal processor
  • baseband processor baseband processor
  • neural network processor neural-network processing unit
  • the memory 402 is coupled with the processor 403, and is used to store various software programs and/or multiple sets of instructions.
  • the memory 402 may include a high-speed random access memory, and may also include a non-volatile memory.
  • the memory 402 may store an operating system, such as an embedded operating system such as ANDROID, IOS, WINDOWS, or LINUX.
  • the transceiver 401 is a network interface controller (English: network interface controller, NIC), including a twisted pair interface (for example: RJ45) or an optical fiber interface, so that the device can access the local area network LAN through a wired connection Or wide area network WAN.
  • NIC network interface controller
  • RJ45 twisted pair interface
  • optical fiber interface optical fiber interface
  • the transceiver 401 includes an antenna 404 and a mobile communication module 405, so that the device can access a cellular network (cellular network).
  • the antenna 404 is used to transmit and receive electromagnetic wave signals;
  • the mobile communication module 405 can provide the devices on the device including global system for mobile communications (GSM), general packet radio service (GPRS), Code division multiple access (code division multiple access, CDMA), wideband code division multiple access (WCDMA), time division code division multiple access (time-division code division multiple access, TD-SCDMA), long-term Evolution (long term evolution, LTE), fifth generation mobile networks (new radio, 5G NR) and other wireless communication solutions.
  • GSM global system for mobile communications
  • GPRS general packet radio service
  • CDMA Code division multiple access
  • WCDMA wideband code division multiple access
  • time division code division multiple access time-division code division multiple access
  • LTE long-term Evolution
  • 5G NR fifth generation mobile networks
  • the mobile communication module 405 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc.
  • the mobile communication module 405 can receive electromagnetic waves by the antenna 404, and perform processing such as filtering and amplifying the received electromagnetic waves, and transmitting them to the modem processor for demodulation.
  • the mobile communication module 405 can also amplify the signal modulated by the modem processor, and convert it to electromagnetic wave radiation via the antenna 404.
  • at least part of the functional modules of the mobile communication module 405 may be provided in the processor 403.
  • at least part of the functional modules of the mobile communication module 405 and at least part of the modules of the processor 403 may be provided in the same device.
  • the transceiver 401 includes an antenna 404 and a wireless communication module 406, so that the device can access a wireless local area network (Wireless local area networks, WLAN), such as a wireless hotspot Wi-Fi.
  • the wireless communication module 406 receives electromagnetic waves via the antenna 404, modulates the frequency of the electromagnetic wave signals and filters them, and sends the processed signals to the processor 403.
  • the wireless communication module 406 may also receive the signal to be sent from the processor 403, perform frequency modulation, amplify it, and convert it into electromagnetic wave radiation through the antenna 404.
  • the device When the software program and/or multiple sets of instructions in the memory 402 are executed by the processor 403, the device is used to perform the following steps: obtain super node information from the server, the super node is determined by the server, and network address translation (network address translation, NAT) A node whose type is a cone NAT, or a node with a public Internet protocol (Internet Protocol, IP) address; sends data packets to the super node, and determines its own NAT type according to the data packets returned by the super node; from the server Obtain the NAT type of the second node to be connected; determine whether to use the relay node according to its own NAT type and the NAT type of the second node; when it is determined to use the relay node, select the node from the super node as the relay node, and Use the relay node to establish a connection with the second node.
  • network address translation network address translation
  • the device provided by the embodiment of the present application can obtain super node information from the server; then, use the super node to obtain its own NAT type, and obtain from the server the NAT type of the second node to be connected; then, according to its own NAT type and The NAT type of the second node determines whether to use a relay node, and when a relay node needs to be used, a relay node is selected from the super nodes to establish a connection with the second node. Therefore, this method realizes that terminal devices in any network environment can establish network connection and data transmission without using a server for data transfer, so that there is no need to maintain a server for data transfer and avoid additional investment required to maintain the server.
  • the super node can be distributed in a large number of network systems to assume the role of data relay, so that the network resources of the super node can be fully utilized and improved Network resource utilization.
  • the device when the software program and/or multiple sets of instructions in the memory 402 are executed by the processor 403, the device is also used to perform the following steps to realize sending data packets to the super node, and according to the information returned by the super node
  • the data packet determines its own NAT type: sends data packets to at least two super nodes; determines its own NAT type according to whether the data packet returned by the super node is received, and the parameters of the data packet returned by the super node. Therefore, the first node can determine its own NAT type without relying on the server, which provides a basis for determining whether to use a relay node in connection with the second node.
  • the device when the software program and/or multiple sets of instructions in the memory 402 are executed by the processor 403, the device is also used to perform the following steps to realize sending data packets to the super node, and according to the information returned by the super node
  • the data packet determines its own NAT type: select the first super node and the second super node from the super nodes; send the first data packet to the first super node so that the first super node obtains the source IP address and source of the first data packet Port, and instruct the second super node to send a second data packet to the source IP address and source port of the first data packet; if it receives the second data packet, it determines that its NAT type is a complete cone NAT.
  • the first node can determine whether its NAT type is a complete cone NAT.
  • the device when the software program and/or multiple sets of instructions in the memory 402 are executed by the processor 403, the device is also used to perform the following steps: if the second data packet is not received, send to the second super node The third data packet enables the second super node to obtain the source IP address and source port of the third data packet, and analyze whether the source port of the first data packet and the source port of the third data packet are the same; if the source of the first data packet The port is different from the source port of the third data packet, and it is determined that its NAT type is a symmetric NAT.
  • the device determines that the NAT type of the first node is not a symmetric NAT, with the aid of the second super node, it can further determine whether the NAT type of the first node is a restricted cone NAT or a port restricted cone NAT. .
  • the device when the software program and/or multiple sets of instructions in the memory 402 are executed by the processor 403, the device is also used to perform the following steps: if the source port of the first data packet and the third data packet The source port is the same, analyze whether the fourth data packet is received, the fourth data packet is sent by the second super node to the source IP address and source port of the third data packet, and the public network used by the second super node to send the fourth data packet The port is different from the destination port of the third data packet; if the fourth data packet is received, it is determined that its own NAT type is restricted cone NAT; if the fourth data packet is not received, it is determined that its own NAT type is port receiving Only conical NAT.
  • the device determines that the NAT type of the first node is not a complete cone NAT or a symmetric NAT, with the aid of the second super node, it can further determine whether the NAT type of the first node is a restricted cone NAT or a port acceptor. Only conical NAT.
  • the device when the software program and/or multiple sets of instructions in the memory 402 are run by the processor 403, the device is also used to perform the following steps to select the first super node and the second super node from the super nodes.
  • Node Obtain the link quality of each super node, and select the first super node and the second super node according to the link quality. Therefore, the device does not need to obtain the link quality of each super node, and can select the first super node and the second super node to improve the selection speed.
  • the device when the software program and/or multiple sets of instructions in the memory 402 are run by the processor 403, the device is also used to perform the following steps to select the first super node and the second super node from the super nodes.
  • Node Determine whether the super node information includes historically selected super nodes. If it includes historically selected super nodes, select the first super node and the second super node from the historically selected super nodes. Therefore, the device does not need to obtain the link quality of each super node, and can select the first super node and the second super node to improve the selection speed.
  • the device when the software program and/or multiple sets of instructions in the memory 402 are executed by the processor 403, the device is further configured to perform the following steps to obtain the NAT type of the second node to be connected from the server: Obtain online node information from the server; determine the identity document (ID) of the second node from the online node information according to the user instruction; send a query instruction carrying the node ID of the second node to the server; the receiving server according to the second node The NAT type of the second node queried by the node ID.
  • the device determines the second node according to the user's instruction, and obtains the NAT type of the second node from the server, which provides a basis for determining whether the first node uses a relay node to establish a connection with the second node.
  • the device when the software program and/or multiple sets of instructions in the memory 402 are executed by the processor 403, the device is also used to perform the following steps to implement NAT according to its own NAT type and the second node
  • the type determines whether to use a relay node: when the NAT type of the device and/or the second node is a complete cone NAT, or when the device and/or the second node has a public IP address , It is determined that the relay node does not need to be used.
  • nodes under the complete cone NAT and nodes with public IP addresses can be accessed by any node, when the NAT type of any one of the first node and the second node is a complete cone NAT, or, When any one has a public IP address, the first node can be directly connected to the second node, so there is no need to use a relay node.
  • the device when the software program and/or multiple sets of instructions in the memory 402 are executed by the processor 403, the device is also used to perform the following steps to realize the determination according to its own NAT type and the NAT type of the second node Whether to use a relay node: when the NAT type of the device and the second node is restricted cone NAT or port restricted cone NAT, or when the NAT type of the device and the second node meets one of them is symmetric NAT, the other When one NAT type is a restricted cone NAT, a relay node is determined to be used, and the relay node is used for the device and the second node to perform UDP (user datagram protocol, user datagram protocol) hole punching.
  • UDP user datagram protocol, user datagram protocol
  • the device when the software program and/or multiple sets of instructions in the memory 402 are executed by the processor 403, the device is also used to perform the following steps to realize the determination according to its own NAT type and the NAT type of the second node Whether to use a relay node:
  • the device and the second node satisfy that one of the NAT types is symmetrical NAT, and the other NAT type is port-restricted cone NAT, determine to use a relay node, which is used for the device and The second node performs port prediction.
  • the device when the software program and/or multiple sets of instructions in the memory 402 are executed by the processor 403, the device is also used to perform the following steps to realize the determination according to its own NAT type and the NAT type of the second node Whether to use a relay node:
  • the relay node is used to forward data between the device and the second node. Since the relay node can be selected from the super nodes, the embodiment of the present application does not need to maintain a server for data transfer, avoiding the additional cost of bandwidth and other costs required to maintain the server; and, since any NAT type meets the requirements of terminal equipment It can be used as a super node. Therefore, a super node can be distributed in a large number of network systems, using its own bandwidth resources to assume the role of data relay, which is conducive to making full use of the network resources of each node and improving the utilization of network resources.
  • the device when the software program and/or multiple sets of instructions in the memory 402 are run by the processor 403, the device is also used to perform the following steps to realize the selection of a node from the super nodes as a relay node:
  • the link quality of each super node, and the relay node is selected from the super nodes according to the link quality. Therefore, it is ensured that the relay node and the first node and the second node form low-delay and stable communication through the data forwarding of the relay node.
  • FIG. 17 is a schematic structural diagram of another apparatus for establishing an end-to-end network connection provided by an embodiment of the application.
  • the first node implements the corresponding function through the software module shown in FIG. 17.
  • the device for establishing an end-to-end network connection includes: a receiving module 501, which obtains super node information from a server, and the super node is determined by the server , NAT type is a conical NAT node, or a node with a public IP address; sending module 502, used to send data packets to the super node; receiving module 501, also used to receive data packets returned by the super node; processing module 503, is also used to determine the NAT type of the first node according to the data packet returned by the super node; the receiving module 501 is also used to obtain the NAT type of the second node to be connected from the server; the processing module 503 is also used to The NAT type of the node and the NAT type of the second node determine whether to use the relay node; the processing
  • the device provided by the embodiment of the present application can obtain super node information from the server; then, use the super node to obtain its own NAT type, and obtain from the server the NAT type of the second node to be connected; then, according to its own NAT type and The NAT type of the second node determines whether to use a relay node, and when a relay node needs to be used, a relay node is selected from the super nodes to establish a connection with the second node.
  • the method realizes that terminal devices in any network environment can establish network connection and data transmission without using a server for data transfer, so there is no need to maintain a server for data transfer, and avoid the additional bandwidth required to maintain the server.
  • the super node can be distributed in a large number of network systems to assume the role of data relay, so that the network resources of the super node can be fully utilized and the network Resource utilization.
  • an embodiment of the present application also provides a computer-readable storage medium 601, which stores instructions in the computer-readable storage medium 601, which when run on a computer, causes the computer to execute the methods of the above aspects.
  • the embodiments of the present application also provide a computer program product containing instructions, which when run on a computer, cause the computer to execute the methods of the above aspects.
  • FIG. 19 is a schematic structural diagram of the chip system.
  • the chip system includes a processor 701, which is used to support the foregoing device to implement the functions involved in the foregoing aspects, for example, to generate or process the information involved in the foregoing method.
  • the chip system further includes a memory 702 for storing program instructions and data necessary for the device to establish an end-to-end network connection.
  • the chip system can be composed of chips, or include chips and other discrete devices.

Landscapes

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

Abstract

本申请实施例提供了一种建立端到端网络连接的方法及装置。其中,该方法包括:第一节点从服务器获取超级节点信息;然后,利用超级节点获取自身的NAT类型,以及,从服务器获取待连接的第二节点的NAT类型;然后,根据自身的NAT类型和第二节点的NAT类型确定是否使用中继节点,并从超级节点中选取中继节点与第二节点建立连接。由此,该方案实现了任意网络环境下的终端设备在不需要使用服务器进行数据中转的情况下建立网络连接和数据传输,无需维护用于数据中转的服务器,避免维护服务器所需额外投入的带宽等成本;并且,该方案可以通过选取大量的超级节点承担数据中继作用,使超级节点的网络资源得到充分利用,提高网络资源利用率。

Description

一种建立端到端网络连接的方法、装置及网络系统
本申请要求在2019年6月11日提交中国国家知识产权局、申请号为201910501933.1的中国专利申请的优先权,发明名称为“一种建立端到端网络连接的方法、装置及网络系统”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及互联网技术领域,尤其涉及一种建立端到端网络连接的方法、装置及网络系统。
背景技术
随着互联网、智能硬件和物联网等相关技术的发展,接入到互联网中的终端设备的数量迅速增加,预计到2020年,互联网中在线的终端设备将会达到250亿台以上。理想状态下,为了便于终端设备的互联,每个终端设备都可以拥有自己的公网互联网协议(internet protocol,IP)地址。但是,随着在线设备数量的增加,在当前广泛采用互联网通信协议第四版(internet protocol version 4,IPv4)下,可分配的公网IP地址的数量严重不足。
为了解决公网IP地址紧缺的问题,互联网中引入了网络地址转换(network address translation,NAT)技术。NAT是一种在数据包通过路由器或防火墙时重写其来源IP地址或目的IP地址的技术,具体利用NAT设备将多个网络设备置于一个私有的内网环境中,根据互联网工程任务小组(internet engineering task force,IETF)发布的请求意见稿(request for comments,RFC)1918私有网络地址分配(address allocation for private internets)协议定义的内网IP地址空间,为内网环境中的每个设备分配内网IP地址,并用通过内网IP地址到外网IP地址的映射,使位于内网环境中的网络设备通过同一个公网IP地址接入互联网,由此解决IPv4地址短缺的问题。
NAT技术在解决IPv4地址短缺的问题的同时,也带来了网络设备之间连接受限的问题。按照NAT对网络连接的限制条件,NAT可以分为完全圆锥型NAT(full cone NAT)、受限圆锥型NAT(address-restricted cone NAT)、端口受限圆锥型NAT(Port-Restricted cone NAT)和对称型NAT(Symmetric NAT)。其中,除完全圆锥型NAT以外,另外三种类型的NAT都只允许内网设备主动向外部发起连接,不接受来自外部的主动连接,因此,在没有建立连接的情况下,来自外部设备连接请求会被NAT设备拒绝,导致内网设备无法与外部设备建立连接。
为了解网络设备在任意NAT类型下的连接问题,NAT穿越(NAT traversal)技术得到广泛应用。目前的NAT穿越大多基于STUN(session traversal utilities for NAT,NAT会话穿越应用程序)协议和/或TURN(traversal using relay NAT)协议,使用中继服务器处理NAT环境中的网络设备之间的连接,其中,作为数据交互双方的网络设备需要分别与中继服务器建立连接,并将数据发送给中继服务器,由中继服务器将数据转发给双方的网络设备。上述NAT穿越技术中,网络设备之间的连接质量会受到中继服务器的性能、负载和网络环境等因素的 影响而存在波动,并且中继服务器的维护也通常需要投入大量的带宽成本。
发明内容
本申请实施例提供了一种建立端到端网络连接的方法、装置及网络系统,能够实现任意网络环境下的终端设备在不需要使用中继服务器进行数据中转的情况下建立网络连接和数据传输。
第一方面,本申请实施例提供了一种建立端到端网络连接的方法。该方法包括:第一节点从服务器获取超级节点信息,超级节点是服务器确定的、网络地址转换NAT类型是圆锥型NAT的节点,或者,具有公网互联网协议IP地址的节点;第一节点向超级节点发送数据包,并根据超级节点返回的数据包确定自身的NAT类型;第一节点从服务器获取待连接的第二节点的NAT类型;第一节点根据自身的NAT类型和第二节点的NAT类型确定是否使用中继节点;当第一节点确定使用中继节点时,第一节点从超级节点中选取节点作为中继节点,并使用中继节点与第二节点建立连接。
本申请实施例提供的方法,第一节点从服务器获取超级节点信息;然后,利用超级节点获取自身的NAT类型,以及,从服务器获取待连接的第二节点的NAT类型;然后,根据自身的NAT类型和第二节点的NAT类型确定是否使用中继节点,并在需要使用中继节点时,从超级节点中选取中继节点与第二节点建立连接。由此,该方法实现了任意网络环境下的终端设备在不需要使用服务器进行数据中转的情况下建立网络连接和数据传输,从而无需维护用于数据中转的服务器,避免维护服务器所需额外投入的带宽等成本;并且,由于任何NAT类型满足要求的终端设备都可以作为超级节点,因此,超级节点可以大量分布在网络系统中,承担数据中继作用,使超级节点的网络资源得到充分利用,提高网络资源利用率。
在一种可选择的实现方式中,第一节点向至少两个超级节点发送数据包;第一节点根据是否接收到超级节点返回的数据包,以及,超级节点返回的数据包的参数确定自身的NAT类型。由此,第一节点可以在不依靠服务器的情况下,确定自身的NAT类型,为确定与第二节点连接是否使用中继节点提供依据。
在一种可选择的实施方式中,第一节点从超级节点中选取第一超级节点和第二超级节点;第一节点向第一超级节点发送第一数据包,使第一超级节点获取第一数据包的源IP地址和源端口,并指示第二超级节点向第一数据包的源IP地址和源端口发送第二数据包;第一节点如果接收到第二数据包,则确定自身的NAT类型是完全圆锥型NAT。由此,借助第一超级节点和第二超级节点,第一节点能够确定自身NAT类型是否是完全圆锥型NAT。
在一种可选择的实施方式中,第一节点如果未接收到第二数据包,向第二超级节点发送第三数据包,使第二超级节点获取第三数据包的源IP地址和源端口,并分析第一数据包的源端口和第三数据包的源端口是否相同;如果第一数据包的源端口和第三数据包的源端口不同,第一节点确定自身的NAT类型是对称型NAT。由此,第一节点在确定自身的NAT类型不是完全圆锥型NAT的情况下,借助第二超级节点,进一步确定自身NAT类型是否是对称型NAT。
在一种可选择的实施方式中,如果第一数据包的源端口和第三数据包的源端口相同,第一节点分析是否接收到第四数据包,第四数据包是第二超级节点向第三数据包的源IP地址和源端口发送的,第二超级节点发送第四数据包使用的公网端口与第三数据包的目的端口不同;第一节点如果接收到第四数据包,则确定自身的NAT类型是受限圆锥型NAT;第一节点如果未接收到第四数据包,则确定自身的NAT类型是端口受限圆锥型NAT。由此,第一节点在确定自身的NAT类型不是完全圆锥型NAT或者对称型NAT的情况下,借助第二超级节点,能 够进一步确定自身NAT类型是否是受限圆锥型NAT或端口受限圆锥型NAT。
在一种可选择的实施方式中,第一节点获取每个超级节点的链路质量,并根据链路质量选取第一超级节点和第二超级节点。由此,保证第一节点与第一超级节点和第二超级节点形成低延时且稳定的通信,提高第一节点确定自身NAT类型的速度和准确性。
在一种可选择的实施方式中,第一节点确定超级节点信息中是否包含历史选取过的超级节点,如果包含历史选取过的超级节点,则从历史选取过的超级节点中选取第一超级节点和第二超级节点。由此,第一节点不需要获取每个超级节点的链路质量,就可以选取第一超级节点和第二超级节点,提高选取速度。
在一种可选择的实施方式中,第一节点从服务器获取在线节点信息;第一节点根据用户指令从在线节点信息中确定第二节点的节点身份标识(identity,ID);第一节点向服务器发送携带第二节点的节点ID的查询指令;第一节点接收服务器根据第二节点的节点ID查询到的第二节点的NAT类型。由此,第一节点从服务器获取第二节点的NAT类型,为是否使用中继节点与第二节点建立连接提供判断依据。
在一种可选择的实施方式中,当第一节点和/或第二节点的NAT类型为完全圆锥型NAT时,或者,当第一节点和/或第二节点具有公网IP地址时,第一节点确定不需要使用中继节点。由此,利用完全圆锥型NAT下的节点和具有公网IP地址的节点能够被任何节点访问的特点,当第一节点和第二节点中的任何一个的NAT类型为完全圆锥型NAT,或者,任何一个具有公网IP地址时,第一节点可以与第二节点直连,从而不需要使用中继节点。
在一种可选择的实施方式中,当第一节点和第二节点的NAT类型为受限圆锥型NAT或端口受限圆锥型NAT时,或者,当第一节点和第二节点满足一个节点的NAT类型为对称型NAT,另一个节点的NAT类型为受限圆锥型NAT时,第一节点确定使用中继节点,中继节点用于第一节点和第二节点进行UDP(user datagram protocol,用户数据报协议)打洞(holepunch)。
在一种可选择的实施方式中,当第一节点和第二节点满足一个节点的NAT类型为对称型NAT,另一个节点的NAT类型为端口受限圆锥型NAT时,第一节点确定使用中继节点,中继节点用于第一节点和第二节点进行端口预测。
在一种可选择的实施方式中,当第一节点和第二节点的NAT类型同时为对称型NAT时,第一节点确定使用中继节点,中继节点用于在第一节点和第二节点之间转发数据。
在一种可选择的实施方式中,第一节点获取每个超级节点的链路质量,并根据链路质量从超级节点中选取中继节点。由此,保证中继节点与第一节点和第二节点通过中继节点的数据转发形成低延时且稳定的通信。
在一种可选择的实施方式中,第一节点、第二节点和超级节点包括位于广域网(wide area network,WAN),和/或,局域网(local area network,LAN)中的终端设备。
在一种可选择的实施方式中,服务器位于广域网WAN,和/或,局域网LAN中;服务器具有公网IP地址,或者,服务器的NAT类型是圆锥型NAT。由此,保证任何一个终端设备都能主动访问到该服务器,并与该服务器建立连接。
在一种可选择的实施方式中,第一节点使用中继节点与第二节点进行即时通信(instant messaging,IM),即时通信包括语音通信、视频通信、图像传输、文本传输和/或文件传输中的至少一种形式。
第二方面,本申请实施例还提供一种建立端到端网络连接的装置。该装置包括:收发器、存储器和处理器;其中,存储器包括有程序指令,程序指令被处理器运行时,使得装置用于 执行如下步骤:从服务器获取超级节点信息,超级节点是服务器确定的、网络地址转换(network address translation,NAT)类型是圆锥型NAT的节点,或者,具有公网互联网协议(internet protocol,IP)地址的节点;向超级节点发送数据包,并根据超级节点返回的数据包确定自身的NAT类型;从服务器获取待连接的第二节点的NAT类型;根据自身的NAT类型和第二节点的NAT类型确定是否使用中继节点;当确定使用中继节点时,从超级节点中选取节点作为中继节点,并使用中继节点与第二节点建立连接。
本申请实施例提供的装置,用于从服务器获取包含超级节点的超级节点信息;然后,利用超级节点获取自身的NAT类型,以及,从服务器获取待连接的第二节点的NAT类型;然后,根据自身的NAT类型和第二节点的NAT类型确定是否使用中继节点,并在需要使用中继节点时,从超级节点中选取中继节点与第二节点建立连接。由此,该方法实现了任意网络环境下的终端设备在不需要使用服务器进行数据中转的情况下建立网络连接和数据传输,无需维护用于数据中转的服务器,从而避免维护服务器所需额外投入的带宽等成本;并且,由于任何NAT类型满足要求的终端设备都可以作为超级节点,因此,超级节点可以大量分布在网络系统中,承担数据中继作用,使超级节点的网络资源得到充分利用,提高网络资源利用率。
进一步地,本申请实施例提供的装置,还可以执行前述第一方面的其他实施方式。
第三方面,本申请实施例还提供一种网络系统。包括:节点和服务器;服务器,用于向第一节点发送超级节点信息,超级节点是服务器确定的NAT类型是圆锥型NAT的节点,或者,具有公网IP地址的节点;第一节点,用于向超级节点发送数据包,并根据超级节点返回的数据包确定自身的NAT类型;服务器,还用于响应第一节点的请求,向第一节点发送第二节点的NAT类型,第二节点是第一节点选取的待连接的节点;第一节点,还用于根据自身的NAT类型和第二节点的NAT类型确定是否使用中继节点;第一节点,还用于所当确定使用中继节点时,从超级节点中选取节点作为中继节点,并使用中继节点与第二节点建立连接。
本申请实施例提供的系统,第一节点从服务器获取包含超级节点的超级节点信息;然后,利用超级节点获取自身的NAT类型,以及,从服务器获取待连接的第二节点的NAT类型;然后,根据自身的NAT类型和第二节点的NAT类型确定是否使用中继节点,并在需要使用中继节点时,从超级节点中选取中继节点与第二节点建立连接。由此,该方法实现了任意网络环境下的终端设备在不需要使用服务器进行数据中转的情况下建立网络连接和数据传输,从而无需维护用于数据中转的服务器,避免维护服务器所需额外投入的带宽等成本;并且,由于任何NAT类型满足要求的终端设备都可以作为超级节点,因此,超级节点可以大量分布在网络系统中,承担数据中继作用,使超级节点的网络资源得到充分利用,提高网络资源利用率。
进一步地,本申请实施例提供的系统中的第一节点,还可以执行前述第一方面的其他实施方式。
第四方面,本申请实施例还提供一种计算机可读存储介质,计算机可读存储介质中存储有指令,当其在计算机上运行时,使得计算机执行上述各方面的方法。
第五方面,本申请实施例还提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述各方面的方法。
第六方面,本申请实施例还提供了一种芯片系统,该芯片系统包括处理器,用于支持上述装置或系统实现上述方面中所涉及的功能,例如,生成或处理上述方法中所涉及的信息。
附图说明
图1示出了一个典型的NAT应用场景;
图2是完全圆锥型NAT的示意图;
图3是受限圆锥型NAT的示意图;
图4是端口受限圆锥型NAT的示意图;
图5是对称型NAT的示意图;
图6为目前的NAT穿越技术的示意图;
图7为本申请实施例提供的一种网络系统的结构示意图;
图8为本申请实施例提供的一种建立端到端网络连接的方法的流程图;
图9示出了使用中继节点进行UDP打洞的示意图;
图10示出了使用中继节点进行端口预测直连的示意图;
图11示出了第一节点确定自身NAT类型的流程图;
图12为第一节点确定自身NAT类型的第一阶段示意图;
图13为第一节点确定自身NAT类型的第二阶段示意图;
图14为第一节点确定自身NAT类型的第三阶段示意图;
图15是本申请实施例提供的一种建立端到端网络连接的方法步骤S103的流程图;
图16为本申请实施例提供的一种建立端到端网络连接的装置的结构示意图;
图17为本申请实施例提供的另一种建立端到端网络连接的装置的结构示意图;
图18为本申请实施例提供的一种计算机可读存储介质示意图;
图19为本申请实施例提供的芯片系统的结构示意图。
具体实施方式
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚地描述。在本申请实施例的描述中,除非另有说明,“/”表示或的意思,例如,A/B可以表示A或B;本申请实施例中的“和/或”仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。另外,在本申请实施例的描述中,“多个”是指两个或两个以上。
在对本申请实施例的技术方案进行阐述说明之前,首先对本申请实施例的技术方案涉及到的技术背景和应用场景做具体说明。
互联网协议IP地址可以包括公网地址和内网地址。其中,公网地址是指在因特网Internet中唯一的IP地址,例如广域网(wide area network,WAN)的IP地址,公网地址可以在公网中路由;内网地址是指在内部网络,例如局域网(local area network,LAN)的IP地址,内网地址无法在公网中路由。根据RFC 1918私有网络地址分配协议,内网IP地址可以包括三个范围不同的互联网通信协议第四版(internet protocol version 4,IPv4)地址空间,用于不同规模的企业内网或者专用内网使用,如下:
10.0.0.0-10.255.255.255,共约1677万个IP地址。
172.16.0.0-172.31.255.255,共约104万个IP地址。
92.168.0.0-192.168.255.255,共约65536个IP地址。
由于内网中的网络设备通常数量有限,因此在IPv4和RFC 1918中,内网IP地址的数量能够满足使用需求。而对于公网来说,由于接入到互联网中的网络设备的数量越来越多,IPv4协议的IP地址数量正在出现紧缺甚至耗尽情况,为了解决IPv4地址紧缺的问题,当前互联 网中引入了网络地址转换(network address translation,NAT)技术。NAT是一种在数据包通过NAT设备(路由器或防火墙)时重写其来源IP地址或目的IP地址的技术,具体利用NAT设备将多个网络设备置于一个私有的内网环境中,根据RFC 1918私有网络地址分配(address allocation for private internets)协议定义的内网IP地址空间,为内网环境中的每个设备分配内网IP地址,并用通过内网IP地址到外网IP地址的映射,使位于内网环境中的网络设备通过同一个公网IP地址接入互联网,由此解决IPv4地址短缺的问题。
图1示出了一个典型的NAT应用场景。如图1所示,在一个典型的配置中,一个专用网络包括具有内网地址空间(比如192.168.x.x或10.x.x.x)的专用内网和连接在这个内网的一个路由器(作为NAT设备)。这个路由器占有这个网络地址空间的一个内网地址(比如10.76.100.1),同时它还通过一个或多个因特网服务提供商(internet service provider,ISP)提供的公网IP地址连接到公网。当数据包由内网向公网传递时,数据包的源地址(源IP和源端口)从内网地址(内网IP和内网端口)转换为公网地址(公网IP和公网端口)。并且,路由器跟踪每个连接上的目的地址(目的IP和目的端口),当有数据包返回路由器时,它通过输出阶段记录的连接跟踪数据来决定该转发给内网中的哪个网络设备。
NAT技术在解决IPv4地址短缺的问题的同时,也带来了网络设备之间的连接受限的问题。按照NAT对网络连接的限制条件,NAT可以分为完全圆锥型NAT(full cone NAT)、受限圆锥型NAT(address-restricted cone NAT)、端口受限圆锥型NAT(Port-Restricted cone NAT)和对称型NAT(Symmetric NAT)。下面结合附图对上述四种NAT类型做具体说明:
图2是完全圆锥型NAT的示意图。如图2所示,当内网主机内建立一个网络嵌套字socket(LocalIP:LocalPort(内网IP地址:内网端口)),并通过该socket第一次向外部主机发送数据包时,NAT设备会为其分配一个(PublicIP:PublicPort(公网IP地址:公网端口)),以后该内网主机使用这个socket向外部任何主机发送的数据包都会使用这个(PublicIP:PublicPort)。并且,任何外部主机都可以通过这个(PublicIP:PublicPort)将数据包发送给该内网主机。
图3是受限圆锥型NAT的示意图。如图3所示,当内网主机内建立一个网络嵌套字socket(LocalIP:LocalPort),并通过该socket第一次向外部主机发送数据包时,NAT设备会为其分配一个(PublicIP:PublicPort),以后该内网主机使用这个socket向外部任何主机发送的数据包都会使用这个(PublicIP:PublicPort)。此外,外网主机想要向内网主机发送数据包需要满足两个条件:第一,内网主机曾经通过该socket向某个外网主机(IP-1:Port-1)发送过数据包;该外网主机使用(IP-1:任意Port)向(PublicIP:PublicPort)发送数据包;如果不满足这两个条件,内网主机无法接收到该外网主机的数据包。
图4是端口受限圆锥型NAT的示意图。如图4所示,当内网主机内建立一个网络嵌套字socket(LocalIP:LocalPort),并通过该socket第一次向外部主机发送数据包时,NAT设备会为其分配一个(PublicIP:PublicPort),以后该内网主机使用这个socket向外部任何主机发送的数据包都会使用这个(PublicIP:PublicPort)。此外,外网主机想要向内网主机发送数据包需要满足两个条件:第一,内网主机曾经通过该socket向某个外网主机(IP-1:Port-1)发送过数据包;该外网主机使用(IP-1:Port-1)向(PublicIP:PublicPort)发送数据包;如果不满足这两个条件,内网主机无法接收到该外网主机的数据包。
图5是对称型NAT的示意图。如图5所示,当内网主机内建立一个网络嵌套字socket(LocalIP:LocalPort),并通过该socket第一次向外部主机1发送数据包时,NAT设备会为其分配一个(PublicIP-1:Port-1),如果该内网主机还使用这个socket第一次向外部主机2发 送数据包,NAT设备还会为其分配一个(PublicIP-2:Port-2),如果NAT设备有多于一个公网IP地址,则PublicIP-1和PublicIP-2可能不同,如果NAT设备只有一个公网IP地址,则Port-1和Port-2一定不同。此外,任何外部主机如果想要发送数据给这个内网主机,那么它首先应该接收到这个内网主机发送给他的数据,否则即使外部主机知道内网主机的一个(PublicIP:Port),也不能发送数据给这个内网主机。
由此可见,由于一些NAT类型只允许内网主机主动向外部主机发起连接,不接受来自外部主机的主动连接,因此,在没有建立连接的情况下,来自外部设备连接请求会被NAT设备拒绝,导致内网设备无法与外部设备建立连接。
为了解网络设备在任意NAT类型下的连接问题,NAT穿越(NAT traversal)技术得到的广泛应用。图6为目前的NAT穿越技术的示意图。如图6所示,目前的NAT穿越大多基于STUN(session traversal utilities for NAT,NAT会话穿越应用程序)协议和/或TURN(traversal using relay NAT)协议,使用中继服务器来处理网络设备之间的连接。其中,该中继服务器是一个公共服务器,使用的是一个众所周知的、从全球任何地方都能访问得到的公网IP地址,内网中的网络设备首先主动与中继服务器建立并保持连接,当通信双方的网络设备进行数据交互时,将数据包发送给中继服务器,由中继服务器负责将数据包转发给对方的网络设备。
示例地,如图6所示,设备A、B、C分别与中继服务器建立连接。当位于局域网内的设备A想要发送一张图片给位于另一个局域网内的设备B时,设备A需要首先将图片发送给中继服务器,中继服务器接收到设备A发送的图片后,再将图片转发给设备B;当位于公网中的设备C想要发送一张图片给位于局域网中的设备A时,设备C也需要首先将图片发送给中继服务器,中继服务器接收到设备C发送的图片后,再将图片转发给设备A。
由此可见,在目前的NAT穿越技术中,中继服务器需要转发所有设备产生的数据,由此会带来严重的带宽开销,带宽投入成本高,中继服务器维护成本高。并且,由于中继服务器的性能、负载和网络环境等会存在波动,网络设备之间的连接质量也会受到影响。
本申请实施例提供了一种建立端到端网络连接的方法。该方法可以应用到图7示出的网络系统中。如图7所示,该网络系统包括服务器和节点。其中,节点根据在本申请实施例中的网络作用不同被命名为普通节点和超级节点,普通节点和超级节点除网络作用不同以外没有本质区别,一个节点既可以是普通节点也可能是超级节点。普通节点和超级节点可以是位于广域网(wide area network,WAN),和/或,局域网(local area network,LAN)中的终端设备,例如:手机、个人电脑、工作站、平板电脑、智能穿戴设备、智能家居设备、物联网设备等。节点可以安装有客户端程序,拥有特定账号的用户可以在客户端程序中使用账号登录到服务器,使节点与服务器建立长连接。服务器可以位于广域网WAN,和/或,局域网LAN中;并且服务器应当具有公网IP地址,或者,服务器的NAT类型是圆锥型NAT,使任何一个终端设备都能主动访问到该服务器,并与该服务器建立连接。
图8为本申请实施例提供的一种建立端到端网络连接的方法的流程图。该方法用于两个节点建立端到端的网络连接,实现两个节点之间的端到端通信,比如即时通信,例如:语音通信、视频通信、图像传输、文本传输和文件传输等。为便于描述,本申请实施例将这两个节点称为第一节点和第二节点,其中,第一节点为发起连接的节点,第二节点为响应连接的节点。如图8所示,该方法可以包括以下步骤:
步骤S101,第一节点从服务器获取超级节点信息,超级节点是服务器确定的、网络地址转换NAT类型是圆锥型NAT的节点,或者,具有公网互联网协议IP地址的节点。
互联网协议IP地址可以包括公网IP地址和内网IP地址。其中,公网IP地址是指在因特 网Internet中唯一的IP地址,例如广域网(wide area network,WAN)的IP地址,公网IP地址可以在公网中路由;内网IP地址是指在内部网络,例如局域网(local area network,LAN)的IP地址,内网IP地址无法在公网中路由。
具体地,当第一节点登录到服务器时,服务器根据用户账号和公钥等信息对第一节点进行登录验证,如果第一节点登录验证通过,则第一节点与服务器建立长连接,并且向第一节点发送超级节点信息。超级节点信息可以包括超级节点的节点身份标识(identity,ID)、IP地址(包括IPv4地址和/或IPv6地址)、端口(包括公网端口和内网端口(如果存在NAT))和在线状态等信息。其中,节点ID可以是任何用于确定节点身份的信息,例如节点编号、节点的MAC地址、节点的硬件识别码或节点的唯一标识符(unique identifier,UID)等。
在一个实施例中,超级节点信息如表1所示可以是超级节点列表。
节点ID IP地址 端口 在线状态
1 116.138.177.20 49153 在线
2 139.215.187.111 50995 在线
3 2001:DB8:2de::e13 60125 在线
4 2001:0DB8::1428:57ab 54230 离线
表1 超级节点列表
在一个实施例中,在网络系统建立初期,服务器可能还没有从连接的节点中确定超级节点,或者,还没有确定出足够数量的超级节点,此时,服务器可以将自身确定为超级节点,当网络系统具有多个服务器时,可以确定其中的一部分服务器为超级节点。
在一个实施例中,如果服务器确定了多个超级节点,可以选择仅向第一节点发送其中一部分超级节点信息,例如:根据第一节点的地理位置,仅发送第一节点附近的超级节点信息。
作为一种可选择的实施方式,服务器可以从第一节点发送的数据包中获取第一节点的公网IP地址,根据该公网IP地址确定第一节点的地理位置信息,例如:位于A市;然后,服务器可以从已确定的超级节点中选取位于A市的超级节点信息发送给第一节点。
作为一种可选择的实施方式,第一节点可以通过内置的GPS模块等获取自身的地理位置信息,并在登录到服务器时,将自身的地理位置信息发送给服务器,使服务器根据第一节点的地理位置信息选择第一节点附近的超级节点信息,并发送给第一节点。
作为一种可选择的实施方式,服务器可以根据第一节点的公网IP地址获取第一节点的因特网服务提供商ISP信息,然后选择与第一节点具有相同ISP的超级节点信息发送给第一节点。示例地,如果服务器根据第一节点的公网IP地址确定第一节点的ISP为中国电信,则服务器会选择ISP同为中国电信的超级节点信息发送给第一节点。
由此,服务器通过向第一节点发送附近的超级节点信息或相同ISP的超级节点信息,能够保证第一节点和超级节点之间具有较低的连接延迟和稳定的连接速度。
本申请实施例要求超级节点能够接收到其他节点主动发起的连接请求,并与发起连接请求的节点建立连接。因此,为了满足上述要求,根据目前NAT类型的限制规则,超级节点可以是NAT类型是圆锥型NAT的节点,或者具有公网IP地址的节点。目前,由于IPv4地址短缺,ISP通常不会为节点分配IPv4的公网地址,而IPv6可分配的IP地址数量巨大,无需担心地址短缺问题,因此,当ISP支持IPv6时,ISP通常会为每个节点分配唯一的公网IPv6地址,从而这些具有IPv6地址的节点可作为超级节点。
步骤S102,第一节点向超级节点发送数据包,并根据超级节点返回的数据包确定自身的 NAT类型。
在一个实施例中,第一节点可以选定至少两个超级节点确定自身的NAT类型,具体可以包括向至少两个超级节点发送数据包,超级节点接收到数据包后,根据规则响应并返回数据包,然后,第一节点可以根据是否接收到超级节点返回的数据包,以及,超级节点返回的数据包的源IP地址和源端口等参数确定自身的NAT类型。步骤S102中的第一节点选定至少两个超级节点确定自身的NAT类型的具体实现过程,将结合图11-图14做进一步阐述说明。
在一个实施例中,每个节点在每次登录到服务器之后,都会根据获取的超级节点确定自身的NAT类型,并上报给服务器,使服务器记录所有登录过节点的NAT类型,并根据节点最新上报的NAT类型对超级节点信息进行更新维护。例如,如果一个节点之前未被确定为超级节点,但是它在T0时刻最新上报的NAT类型为完全圆锥型NAT,则服务器可以在T0时刻将它确定为超级节点;如果一个节点已经被确定为超级节点,但是它在T1时刻最新上报的NAT类型为对称型NAT,则服务器可以在T1时刻确定它为普通节点。
步骤S103,第一节点从服务器获取待连接的第二节点的NAT类型。
第一节点在登录到服务器之后,可以从服务器同步获取在线节点,并通过客户端呈现给用户;然后,用户可以通过在客户端执行选择操作,从在线节点中确定第二节点;然后,第一节点根据用户确定的第二节点向服务器发起获取第二节点的NAT类型的请求;服务器响应第一节点的请求,查询得到第二节点的NAT类型,并返回给第一节点。步骤S103,即第第一节点从服务器获取待连接的第二节点的NAT类型的具体实现过程,将结合图15做进一步阐述说明。
步骤S104,第一节点根据自身的NAT类型和第二节点的NAT类型确定是否使用中继节点。
本申请实施例中,中继节点的NAT类型为圆锥型NAT,或者,具有公网互联网协议(internet protocol,IP)地址,中继节点可以分别与第一节点和第二节点建立连接。当第一节点和第二节点需要建立连接和进行数据通信时,可以根据自身的NAT类型借助中继节点建立连接,可以通过中继节点的数据中转建立间接连接。当第一节点和第二节点通过中继节点建立间接连接时,第一节点和第二节点之间的数据通信都通过中继节点的转发送达。
步骤S105,当第一节点确定使用中继节点时,第一节点从超级节点中选取节点作为中继节点,并使用中继节点与第二节点建立连接。
表2 示出了节点的NAT类型和连接方式的对应关系。
Figure PCTCN2020095045-appb-000001
表2 节点的NAT类型和连接方式
在一个实施例中,当第一节点和/或第二节点的NAT类型为完全圆锥型NAT,或者第一节点和/或第二节点具有公网IP地址时,第一节点和第二节点可以通过“直连”的方式建立连接,不需要使用中继节点。目前,ISP为节点分配的IPv6地址均为公网IP地址,因此,如果第一节点和/或第二节点具有IPv6地址,则可以通过“直连”的方式建立连接,不需要使用中继节点。
在一个实施例中,当第一节点和第二节点的NAT类型为受限圆锥型NAT或者端口受限圆锥型NAT时,第一节点和第二节点可以通过“穿越后直连”的方式建立连接。“穿越后直连”具体包括第一节点和第二节点首先利用中继节点进行UDP打洞(UDP holepunch),打洞成功后,建立直连。当一个节点的NAT类型为对称性NAT,另一个节点的NAT类型为受限圆锥型NAT时;第一节点和第二节点也可以通过“穿越后直连”的方式建立连接。
图9示出了使用中继节点进行UDP打洞的示意图。如图9所示,第一节点A位于NAT设备N1下,第二节点B位于NAT设备N2下,NAT设备N1拥有公网IP地址P1,NAT设备N2拥有公网IP地址P2,C1为中继节点。本申请实施例使用中继节点进行UDP打洞,以建立第一节点A和第二节点B之间的直接连接,包括以下步骤:
步骤一:第一节点A和第二节点B分别和中继节点C1建立UDP连接;NAT设备N1和N2创建UDP转换状态,NAT设备N1为第一节点A分配公网端口X,NAT设备N2为第二节点B分配公网端口Y。
步骤二,第一节点A向中继节点C1发送UDP包,以将第一节点A期望与第二节点B建立连接的请求告知中继节点C1。
步骤三,中继节点C1向第二节点B发送UDP包,以将第一节点A期望与第二节点B建立连接的请求和第一节点A的公网IP地址和公网端口(P1:X)告知第二节点B。
步骤四,如果第二节点B接受了第一节点A的连接请求,则向第一节点A的公网IP地址和公网端口(P1:X)发送UDP包。第二节点B发送的UDP包被NAT设备N1收到后不会转发给第一节点A,而是被丢弃,因为第一节点A之前未向第二节点B发送过数据包。
步骤五,第一节点A向第二节点B的公网IP地址和公网端口(P2:Y)发送UDP包,其中,(P2:Y)可由中继节点C1告知第一节点A。由于第二节点B之前向第一节点A发送过UDP包,因此,NAT设备N2会将该数据包转发给第二节点B,使第二节点B能够接收到第一节点A的UDP包。
至此,第一节点A和第二节点B打洞成功,建立直连通信。
在一个实施例中,当第一节点和第二节点中的其中一个节点为对称型NAT,另一个节点为端口受限圆锥型NAT时,第一节点和第二节点可以通过“端口预测直连”的方式建立连接,“端口预测直连”的方式至少需要借助两个中继节点来实现。
图10示出了使用中继节点进行端口预测直连的示意图。如图10所示,第一节点A位于NAT设备N1下,第二节点B位于NAT设备N2下,NAT设备N1拥有公网IP地址P1,NAT设备N2拥有公网IP地址P2,C1和C2为中继节点。
进一步结合图10,当第一节点A为对称型NAT,第二节点B为端口受限圆锥型NAT时,第一节点A和第二节点B使用“端口预测直连”建立直接连接,可以包括以下步骤:
步骤一,第一节点A向中继节点C1发送数据包,使中继节点C1获得NAT设备N1为第一节点A分配的公网端口X1。
步骤二,中继节点C1将公网端口X1反馈给第一节点A。
步骤三,第一节点A向中继节点C2发送数据包,该数据包括中继节点C1反馈的公网端口X1等信息,使中继节点C2获得NAT设备N1两次为第一节点A分配的公网端口X1和X2。
步骤四,第二节点B向C2发送数据包,使中继节点C2获得NAT设备N2为第二节点B分配的公网端口Y。
步骤五,中继节点C2基于获取的公网端口X1和X2,对NAT设备N1分配的端口进行 预测,并将预测结果发送给第二节点B,以及将公网端口Y反馈给第一节点A,预测结果中可以包括多个预测的端口。
步骤六,第二节点B以预测的端口作为目标端口,向第一节点A发送大量数据包。
步骤七,第一节点A以端口Y为目标端口,向第二节点B发送大量数据包,随后转入接收模式。
如果预测的端口命中了NAT设备N1在步骤七为第一节点A分配的公网端口,则第二节点B能够接收到第一节点A向端口Y发送的数据包,第一节点A能够接收到第二节点B向命中端口发送的数据包。至此,第一节点A和第二节点B端口预测成功,建立直连通信。
在一个实施例中,如果第一节点和第二节点的NAT类型均为对称型NAT,则第一节点和第二节点可以通过中继节点转发数据建立通信。具体包括:第一节点和第二节点分别和中继节点建立连接,第一节点和第二节点之间需要传输的数据均发送给中继节点,由中继节点转发给对方节点。
在一个实施例中,第一节点可以对每个已知的超级节点执行tranceroute操作或者ping操作,以获取第一节点与每个超级节点之间的路由追踪信息(路由跳数、路线)、通信耗时和/或丢包率等能够体现链路质量的指标信息,然后,根据至少一种指标信息选取链路质量较好的一个超级节点作为中继节点。
例如:选取通信耗时最低的超级节点作为中继节点;或者,当通信耗时接近时,选取丢包率最低的超级节点最为中继节点;当通信耗时和丢包率两种指标信息都接近时,选取路由跳数最少的超级节点作为中继节点。
由此,保证中继节点与第一节点和第二节点形成低延时且稳定的通信。
在一个实施例中,如果第一节点曾经选取过中继节点,则第一节点判断曾经选取过的中继节点是包含在超级节点信息中,如果包含,则将曾经选取过的中继节点重新确定为中继节点。
由此,第一节点不需要获取每个超级节点的链路质量,提高中继节点的选取速度。
本申请实施例提供的方法,第一节点从服务器获取超级节点信息;然后,利用超级节点获取自身的NAT类型,以及,从服务器获取待连接的第二节点的NAT类型;然后,根据自身的NAT类型和第二节点的NAT类型确定是否使用中继节点,并在需要使用中继节点时,从超级节点中选取中继节点与第二节点建立连接。由此,该方法实现了任意网络环境下的终端设备在不需要使用服务器进行数据中转的情况下建立网络连接和数据传输,从而无需维护用于数据中转的服务器,避免维护服务器所需额外投入的带宽等成本;并且,由于任何NAT类型满足要求的终端设备都可以作为超级节点,因此,超级节点可以大量分布在网络系统中,承担数据中继作用,使超级节点的网络资源得到充分利用,提高网络资源利用率。
图11示出了第一节点确定自身NAT类型的流程图。
如图11所示,在一个实施例中,步骤S102,即第一节点向超级节点发送数据包,并根据超级节点返回的数据包确定自身的NAT类型包括以下步骤:
步骤S201,第一节点从超级节点中选取第一超级节点和第二超级节点。
在一个实施例中,第一节点可以对每个已知的超级节点执行tranceroute操作或者ping操作,以获取第一节点与每个超级节点之间的路由追踪信息(路由跳数、路线)、通信耗时和/或丢包率等能够体现链路质量的指标信息,然后,根据至少一种指标信息选取链路质量较好的两个超级节点作为第一超级节点和第二超级节点。
例如:选取通信耗时最低的两个节点作为第一超级节点和第二超级节点;或者,当通信 耗时接近时,选取丢包率最低的两个节点作为第一超级节点和第二超级节点;当通信耗时和丢包率两种指标信息都接近时,选取路由跳数最少的两个节点作为第一超级节点和第二超级节点。
由此,保证第一节点与第一超级节点和第二超级节点形成低延时且稳定的通信,提高第一节点确定自身NAT类型的速度和准确性。
在一个实施例中,如果第一节点曾经使用过超级节点获取自身的NAT类型,则第一节点判断曾经选取过的超级节点是包含在超级节点信息中,如果包含,则将曾经选取过的超级节点重新确定为第一超级节点和第二超级节点。
由此,第一节点不需要获取每个超级节点的链路质量,就可以选取第一超级节点和第二超级节点,提高选取速度。
图12为第一节点确定自身NAT类型的第一阶段示意图。第一阶段包含步骤S202和步骤S203,能够确定第一节点是否为完全圆锥型NAT。
步骤S202,第一节点向第一超级节点发送第一数据包。
如图12所示,第一节点A向第一超级节点S1发送第一数据包D1;第一超级节点S1接收第一数据包D1,并从解析获取第一数据包D1的源IP地址和源端口(P1:X1),(P1:X1)即为NAT设备为第一节点A分配的公网IP地址和公网端口。第一数据包D1还包含有指令,该指令用于指示第一超级节点S1将(P1:X1)告知给第二超级节点S2,以及指示第二超级节点S2向(P1:X1)发送第二数据包D2。
步骤S203,第一节点如果接收到第二数据包,则确定自身的NAT类型是完全圆锥型NAT。
由于完全圆锥型NAT不对外部主机的数据包进行限制,因此,如果第一节点A在未向第二超级节点S2发送过数据包的情况下,能够接收到第二超级节点S2的数据包,则说明自身的NAT类型是完全圆锥型NAT。
由此,借助第一超级节点和第二超级节点,第一节点可以通过一次数据包的发送和接收动作确定自身的NAT类型是否是完全圆锥型NAT。
图13为第一节点确定自身NAT类型的第二阶段示意图。第二阶段包含步骤S204和步骤S205,能够确定第一节点是否为对称型NAT。
步骤S204,第一节点如果未接收到第二数据包,向第二超级节点发送第三数据包。
在一个实施例中,第一节点可以预设时长Tn,第一节点在Ts时刻向第一超级节点发送第一数据包之后,即等待接收第二数据包,如果第一节点直到Ts+Tn时刻也没有接收到第二数据包,则可以认为“未接收到第二数据包”。
如图13所示,第一节点A向第二超级节点S2发送第三数据包D3;第二超级节点S2接收第三数据包D3,并解析获取第三数据包D3的源IP地址和源端口(P3:X3),(P3:X3)即为NAT设备为第一节点A分配的公网IP地址和公网端口;然后,第二超级节点S2分析第一数据包的源端口X1和第三数据包的源端口X3是否相同,然后将分析结果发送通过(P3:X3)发送给第一节点A。
步骤S205,如果第一数据包的源端口和第三数据包的源端口不同,第一节点确定自身的NAT类型是对称型NAT。
由于对称型NAT会为内网主机的向不同外部设备发起的连接分配不同的公网端口,因此,如果源端口X1和源端口X3不同,则说明第一节点的NAT类型是对称型NAT。
图14为第一节点确定自身NAT类型的第三阶段示意图。第三阶段包含步骤S206至步骤S208,能够确定第一节点是受限圆锥型NAT还是端口受限圆锥型NAT。
步骤S206,如果第一数据包的源端口和第三数据包的源端口相同,第一节点分析是否接收到第四数据包。
其中,第四数据包D4是第二超级节点S2在确定源端口X1和源端口X3相同的情况下向(P3:X3)发送的。第二超级节点S2发送第四数据包D4使用的公网端口与第三数据包D3的目的端口不同。
步骤S207,第一节点如果接收到第四数据包,则确定自身的NAT类型是受限圆锥型NAT。
由于受限圆锥型NAT不对外部主机发送的数据包的源端口进行限制,如果第一节点A接收到第四数据包D4,则说明NAT类型是受限圆锥型NAT。
步骤S208,第一节点如果未接收到第四数据包,则确定自身的NAT类型是端口受限圆锥型NAT。
在一个实施例中,第一节点可以预设时长Tm,第一节点在Tr时刻向第二超级节点发送第三数据包之后,即等待接收第四数据包,如果第一节点直到Tm+Tr时刻也没有接收到第四数据包,则可以认为“未接收到第四数据包”。
由于受限圆锥型NAT对外部主机发送的数据包的源端口进行限制,如果第一节点A未接收到第四数据包D4,则说明NAT类型是端口受限圆锥型NAT。
由此,第一节点利用超级节点,通过至多三个阶段的数据包收发和判断,即可确定自身的NAT类型,为是否使用中继节点与第二节点建立连接提供判断依据。
图15是本申请实施例提供的一种建立端到端网络连接的方法步骤S103的流程图。
在一个实施例中,如图15所示,步骤S103即第一节点从服务器获取待连接的第二节点的NAT类型,包括以下步骤:
步骤S301,第一节点从服务器获取在线节点信息,在线节点信息包含在线节点的节点ID,在线节点包括已经与服务器建立了连接的节点。
每个节点登录到服务器之后,都会与服务器建立长连接以保持在线状态,因此服务器可以将已连接的节点信息进行汇总,得到在线节点信息。在一个实施例中,在线节点信息可以是在线节点列表,该在线节点列表可以包含在线节点的节点ID和节点绑定的用户名、头像等信息。第一节点在登录到服务器之后,可以向服务器发送同步请求,使服务器向第一节点发送在线节点信息,例如:服务器可以直接向第一节点发送在线节点列表。此外,服务器也可以主动向第一节点发送在线节点信息,从而不需要第一节点向服务器发送请求。
步骤S302,第一节点根据用户指令和在线节点信息确定第二节点的节点ID;
第一节点获取在线节点信息之后,可以通过可视化或语音信息等形式将在线节点信息展示给用户。使用户通过可视化操作或语音操作等方式选择第二节点。
示例地,当第一节点是带有屏幕的移动终端时,移动终端安装的客户端程序生成用于选择第二节点的可操作界面,并显示在屏幕中。可操作界面可以显示每个在线节点绑定的用户名和头像等信息。因此,持有移动终端的用户可以通过触摸和按键等方式选择任意一个在线节点作为第二节点。在用户做出选择之后,第一节点即可以确定第二节点的节点ID。
步骤S303,第一节点向服务器发送携带第二节点的节点ID的查询指令。
服务器接收到查询指令后,根据查询指令携带的节点ID查询第二节点的NAT类型。由于节点每次登录后都会向服务器上报自身的NAT类型,因此,服务器维护的各个节点的NAT类型可以保持最新,从而第一节获取的第二节点的NAT类型也是最新的。
步骤S304,第一节点从服务器接收第二节点的NAT类型。
由此,第一节点从服务器获取第二节点的NAT类型,为是否使用中继节点与第二节点建 立连接提供判断依据。
上述本申请实施例提供的实施例中,对本申请实施例提供的建立端到端网络连接的方法各方案进行了介绍。可以理解的是,第一节点为了实现上述功能,其包含了执行各个功能相应的硬件结构和/或软件模块。本领域技术人员应该很容易意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,本申请实施例能够以硬件或硬件和计算机软件的结合形式来实现。某个功能究竟以硬件还是计算机软件驱动硬件的方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请实施例的范围。
图16为本申请实施例提供的一种建立端到端网络连接的装置的结构示意图。在一个实施例中,所述建立端到端网络连接的装置用作第一节点并通过图16示出的硬件装置结构实现相应的功能。如图16所示,该建立端到端网络连接的装置包括:收发器401、存储器402和处理器403。
在一个实施例中,处理器403可以包括一个或多个处理单元,例如:处理器403可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。
存储器402与处理器403耦合,用于存储各种软件程序和/或多组指令。在一些实施例中,存储器402可包括高速随机存取的存储器,并且也可包括非易失性存储器。存储器402可以存储操作系统,例如ANDROID,IOS,WINDOWS,或者LINUX等嵌入式操作系统。
在一个实施例中,收发器401为网络接口控制器(英语:network interface controller,NIC),包括双绞线接口(例如:RJ45)或光纤接口,使该装置能够通过有线连接方式接入局域网LAN或广域网WAN。
在一个实施例中,收发器401包括天线404和移动通信模块405,使该装置能够接入到蜂窝移动网络(cellular network)。其中,天线404用于发射和接收电磁波信号;移动通信模块405可以提供该装置上的包括全球移动通讯系统(global system for mobile communications,GSM),通用分组无线服务(general packet radio service,GPRS),码分多址接入(code division multiple access,CDMA),宽带码分多址(wideband code division multiple access,WCDMA),时分码分多址(time-division code division multiple access,TD-SCDMA),长期演进(long term evolution,LTE),第五代移动通信技术(5th generation mobile networks new radio,5G NR)等无线通信的解决方案。移动通信模块405可以包括至少一个滤波器,开关,功率放大器,低噪声放大器(low noise amplifier,LNA)等。移动通信模块405可以由天线404接收电磁波,并对接收的电磁波进行滤波,放大等处理,传送至调制解调处理器进行解调。移动通信模块405还可以对经调制解调处理器调制后的信号放大,经天线404转为电磁波辐射出去。在一些实施例中,移动通信模块405的至少部分功能模块可以被设置于处理器403中。在一些实施例中,移动通信模块405的至少部分功能模块可以与处理器403的至少部分模块被设置在同一个器件中。
在一个实施例中,收发器401包括天线404和无线通信模块406,使该装置能够接入到无线局域网(Wireless local area networks,WLAN),例如:无线热点Wi-Fi。无线通信模块406经由天线404接收电磁波,将电磁波信号调频以及滤波处理,将处理后的信号发送到处 理器403。无线通信模块406还可以从处理器403接收待发送的信号,对其进行调频,放大,经天线404转为电磁波辐射出去。
当存储器402中的软件程序和/或多组指令被处理器403运行时,使得装置用于执行如下步骤:从服务器获取超级节点信息,超级节点是服务器确定的、网络地址转换(network address translation,NAT)类型是圆锥型NAT的节点,或者,具有公网互联网协议(internet protocol,IP)地址的节点;向超级节点发送数据包,并根据超级节点返回的数据包确定自身的NAT类型;从服务器获取待连接的第二节点的NAT类型;根据自身的NAT类型和第二节点的NAT类型确定是否使用中继节点;当确定使用中继节点时,从超级节点中选取节点作为中继节点,并使用中继节点与第二节点建立连接。
本申请实施例提供的装置,能够从服务器获取超级节点信息;然后,利用超级节点获取自身的NAT类型,以及,从服务器获取待连接的第二节点的NAT类型;然后,根据自身的NAT类型和第二节点的NAT类型确定是否使用中继节点,并在需要使用中继节点时,从超级节点中选取中继节点与第二节点建立连接。由此,该方法实现了任意网络环境下的终端设备在不需要使用服务器进行数据中转的情况下建立网络连接和数据传输,从而无需维护用于数据中转的服务器,避免维护服务器所需额外投入的带宽等成本;并且,由于任何NAT类型满足要求的终端设备都可以作为超级节点,因此,超级节点可以大量分布在网络系统中,承担数据中继作用,使超级节点的网络资源得到充分利用,提高网络资源利用率。
在一个实施例中,当存储器402中的软件程序和/或多组指令被处理器403运行时,还使得装置用于执行如下步骤,以实现向超级节点发送数据包,并根据超级节点返回的数据包确定自身的NAT类型:向至少两个超级节点发送数据包;根据是否接收到超级节点返回的数据包,以及,超级节点返回的数据包的参数确定自身的NAT类型。由此,第一节点可以在不依靠服务器的情况下,确定自身的NAT类型,为确定与第二节点连接是否使用中继节点提供依据。
在一个实施例中,当存储器402中的软件程序和/或多组指令被处理器403运行时,还使得装置用于执行如下步骤,以实现向超级节点发送数据包,并根据超级节点返回的数据包确定自身的NAT类型:从超级节点中选取第一超级节点和第二超级节点;向第一超级节点发送第一数据包,使第一超级节点获取第一数据包的源IP地址和源端口,并指示第二超级节点向第一数据包的源IP地址和源端口发送第二数据包;如果接收到第二数据包,则确定自身的NAT类型是完全圆锥型NAT。由此,借助第一超级节点和第二超级节点,第一节点能够确定自身NAT类型是否是完全圆锥型NAT。
在一个实施例中,当存储器402中的软件程序和/或多组指令被处理器403运行时,还使得装置用于执行如下步骤:如果未接收到第二数据包,向第二超级节点发送第三数据包,使第二超级节点获取第三数据包的源IP地址和源端口,并分析第一数据包的源端口和第三数据包的源端口是否相同;如果第一数据包的源端口和第三数据包的源端口不同,确定自身的NAT类型是对称型NAT。由此,该装置在确定第一节点的NAT类型不是对称型NAT的情况下,借助第二超级节点,能够进一步确定第一节点的NAT类型是否是受限圆锥型NAT或端口受限圆锥型NAT。
在一个实施例中,当存储器402中的软件程序和/或多组指令被处理器403运行时,还使得装置用于执行如下步骤::如果第一数据包的源端口和第三数据包的源端口相同,分析是否接收到第四数据包,第四数据包是第二超级节点向第三数据包的源IP地址和源端口发送的,第二超级节点发送第四数据包使用的公网端口与第三数据包的目的端口不同;如果接收到第 四数据包,则确定自身的NAT类型是受限圆锥型NAT;如果未接收到第四数据包,则确定自身的NAT类型是端口受限圆锥型NAT。由此,该装置在确定第一节点的NAT类型不是完全圆锥型NAT或者对称型NAT的情况下,借助第二超级节点,能够进一步确定第一节点NAT类型是否是受限圆锥型NAT或端口受限圆锥型NAT。
在一个实施例中,当存储器402中的软件程序和/或多组指令被处理器403运行时,还使得装置用于执行如下步骤,以实现从超级节点中选取第一超级节点和第二超级节点:获取每个超级节点的链路质量,并根据链路质量选取第一超级节点和第二超级节点。由此,该装置不需要获取每个超级节点的链路质量,就可以选取第一超级节点和第二超级节点,提高选取速度。
在一个实施例中,当存储器402中的软件程序和/或多组指令被处理器403运行时,还使得装置用于执行如下步骤,以实现从超级节点中选取第一超级节点和第二超级节点:确定超级节点信息中是否包含历史选取过的超级节点,如果包含历史选取过的超级节点,则从历史选取过的超级节点中选取第一超级节点和第二超级节点。由此,该装置不需要获取每个超级节点的链路质量,就可以选取第一超级节点和第二超级节点,提高选取速度。
在一个实施例中,当存储器402中的软件程序和/或多组指令被处理器403运行时,还使得装置用于执行如下步骤,以实现从服务器获取待连接的第二节点的NAT类型:从服务器获取在线节点信息;根据用户指令从在线节点信息中确定第二节点的节点身份标识(identity document,ID);向服务器发送携带第二节点的节点ID的查询指令;接收服务器根据第二节点的节点ID查询到的第二节点的NAT类型。由此,该装置根据用户的指令确定第二节点,并从服务器获取第二节点的NAT类型,为第一节点是否使用中继节点与第二节点建立连接提供判断依据。
在一个实施例中,当存储器402中的软件程序和/或多组指令被处理器403运行时,还使得装置用于执行如下步骤,以实现根据自身的NAT类型和所述第二节点的NAT类型确定是否使用中继节点:当所述装置和/或所述第二节点的NAT类型为完全圆锥型NAT时,或者,当所述装置和/或所述第二节点具有公网IP地址时,确定不需要使用所述中继节点。由此,利用完全圆锥型NAT下的节点和具有公网IP地址的节点能够被任何节点访问的特点,当第一节点和第二节点中的任何一个的NAT类型为完全圆锥型NAT,或者,任何一个具有公网IP地址时,第一节点可以与第二节点直连,从而不需要使用中继节点。
在一个实施例中,当存储器402中的软件程序和/或多组指令被处理器403运行时,还使得装置用于执行如下步骤,以实现根据自身的NAT类型和第二节点的NAT类型确定是否使用中继节点:当装置和第二节点的NAT类型为受限圆锥型NAT或端口受限圆锥型NAT时,或者,当装置和第二节点满足其中一个的NAT类型为对称型NAT,另一个的NAT类型为受限圆锥型NAT时,确定使用中继节点,中继节点用于装置和第二节点进行UDP(user datagram protocol,用户数据报协议)打洞(holepunch)。
在一个实施例中,当存储器402中的软件程序和/或多组指令被处理器403运行时,还使得装置用于执行如下步骤,以实现根据自身的NAT类型和第二节点的NAT类型确定是否使用中继节点:当装置和第二节点满足其中一个的NAT类型为对称型NAT,另一个的NAT类型为端口受限圆锥型NAT时,确定使用中继节点,中继节点用于装置和第二节点进行端口预测。
在一个实施例中,当存储器402中的软件程序和/或多组指令被处理器403运行时,还使得装置用于执行如下步骤,以实现根据自身的NAT类型和第二节点的NAT类型确定是否使 用中继节点:当装置和第二节点的NAT类型同时为对称型NAT时,确定使用中继节点,中继节点用于在装置和第二节点之间转发数据。由于中继节点可以从超级节点中选取,因此,本申请实施例无需维护用于数据中转的服务器,避免维护服务器所需额外投入的带宽等成本;并且,由于任何NAT类型满足要求的终端设备都可以作为超级节点,因此,超级节点可以大量分布在网络系统中,利用自身的带宽资源承担数据中继作用,有利于充分利用各个节点的网络资源,提高网络资源利用率。
在一个实施例中,当存储器402中的软件程序和/或多组指令被处理器403运行时,还使得装置用于执行如下步骤,以实现从超级节点中选取节点作为中继节点:获取每个超级节点的链路质量,并根据链路质量从超级节点中选取中继节点。由此,保证中继节点与第一节点和第二节点通过中继节点的数据转发形成低延时且稳定的通信。
图17为本申请实施例提供的另一种建立端到端网络连接的装置的结构示意图。在一个实施例中,第一节点通过图17示出的软件模块实现相应的功能,该建立端到端网络连接的装置包括:接收模块501,从服务器获取超级节点信息,超级节点是服务器确定的、NAT类型是圆锥型NAT的节点,或者,具有公网IP地址的节点;发送模块502,用于向超级节点发送数据包;接收模块501,还用于接收超级节点返回的数据包;处理模块503,还用于根据超级节点返回的数据包确定第一节点的NAT类型;接收模块501,还用于从服务器获取待连接的第二节点的NAT类型;处理模块503,还用于根据第一节点的NAT类型和第二节点的NAT类型确定是否使用中继节点;处理模块503,还用于当确定使用中继节点时,从超级节点中选取节点作为中继节点,使第一节点使用中继节点与第二节点建立连接。
本申请实施例提供的装置,能够从服务器获取超级节点信息;然后,利用超级节点获取自身的NAT类型,以及,从服务器获取待连接的第二节点的NAT类型;然后,根据自身的NAT类型和第二节点的NAT类型确定是否使用中继节点,并在需要使用中继节点时,从超级节点中选取中继节点与第二节点建立连接。由此,该方法实现了任意网络环境下的终端设备在不需要使用服务器进行数据中转的情况下建立网络连接和数据传输从而无需维护用于数据中转的服务器,避免维护服务器所需额外投入的带宽等成本;并且,由于任何NAT类型满足要求的终端设备都可以作为超级节点,因此,超级节点可以大量分布在网络系统中,承担数据中继作用,使超级节点的网络资源得到充分利用,提高网络资源利用率。
如图18所示,本申请实施例还提供一种计算机可读存储介质601,计算机可读存储介质601中存储有指令,当其在计算机上运行时,使得计算机执行上述各方面的方法。
本申请实施例还提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述各方面的方法。
本申请实施例还提供了一种芯片系统,图19为该芯片系统的结构示意图。该芯片系统包括处理器701,用于支持上述装置实现上述方面中所涉及的功能,例如,生成或处理上述方法中所涉及的信息。在一种可能的设计中,芯片系统还包括存储器702,用于保存建立端到端网络连接的装置必要的程序指令和数据。该芯片系统,可以由芯片构成,也可以包含芯片和其他分立器件。
以上的具体实施方式,对本申请实施例的目的、技术方案和有益效果进行了进一步详细说明,所应理解的是,以上仅为本申请实施例的具体实施方式而已,并不用于限定本申请实施例的保护范围,凡在本申请实施例的技术方案的基础之上,所做的任何修改、等同替换、改进等,均应包括在本申请实施例的保护范围之内。

Claims (32)

  1. 一种建立端到端网络连接的方法,其特征在于,包括:
    第一节点从服务器获取超级节点信息,所述超级节点是所述服务器确定的、网络地址转换(network address translation,NAT)类型是圆锥型NAT的节点,或者,具有公网互联网协议(internet protocol,IP)地址的节点;
    所述第一节点向所述超级节点发送数据包,并根据所述超级节点返回的数据包确定自身的NAT类型;
    所述第一节点从所述服务器获取待连接的第二节点的NAT类型;
    所述第一节点根据自身的NAT类型和所述第二节点的NAT类型确定是否使用中继节点;
    当所述第一节点确定使用中继节点时,所述第一节点从所述超级节点中选取节点作为中继节点,并使用所述中继节点与所述第二节点建立连接。
  2. 根据权利要求1所述的方法,其特征在于,所述第一节点向所述超级节点发送数据包,并根据所述超级节点返回的数据包确定自身的NAT类型,包括:
    所述第一节点向至少两个所述超级节点发送数据包;
    所述第一节点根据是否接收到所述超级节点返回的数据包,以及,所述超级节点返回的数据包的参数确定自身的NAT类型。
  3. 根据权利要求1所述的方法,其特征在于,所述第一节点向所述超级节点发送数据包,并根据所述超级节点返回的数据包确定自身的NAT类型,包括:
    所述第一节点从所述超级节点中选取第一超级节点和第二超级节点;
    所述第一节点向所述第一超级节点发送第一数据包,使所述第一超级节点获取所述第一数据包的源IP地址和源端口,并指示所述第二超级节点向所述第一数据包的源IP地址和源端口发送第二数据包;
    所述第一节点如果接收到所述第二数据包,则确定自身的NAT类型是完全圆锥型NAT。
  4. 根据权利要求3所述的方法,其特征在于,还包括:
    所述第一节点如果未接收到所述第二数据包,向所述第二超级节点发送第三数据包,使所述第二超级节点获取所述第三数据包的源IP地址和源端口,并分析所述第一数据包的源端口和所述第三数据包的源端口是否相同;
    如果所述第一数据包的源端口和所述第三数据包的源端口不同,所述第一节点确定自身的NAT类型是对称型NAT。
  5. 根据权利要求4所述的方法,其特征在于,还包括:
    如果所述第一数据包的源端口和所述第三数据包的源端口相同,所述第一节点分析是否接收到第四数据包,所述第四数据包是所述第二超级节点向所述第三数据包的源IP地址和源端口发送的,所述第二超级节点发送所述第四数据包使用的公网端口与所述第三数据包的目的端口不同;
    所述第一节点如果接收到所述第四数据包,则确定自身的NAT类型是受限圆锥型NAT;
    所述第一节点如果未接收到所述第四数据包,则确定自身的NAT类型是端口受限圆锥型 NAT。
  6. 根据权利要求3所述的方法,其特征在于,所述第一节点从所述超级节点中选取第一超级节点和第二超级节点,包括:
    所述第一节点确定所述超级节点信息中是否包含历史选取过的所述超级节点,如果包含历史选取过的所述超级节点,则从历史选取过的所述超级节点中选取所述第一超级节点和所述第二超级节点。
  7. 根据权利要求3所述的方法,其特征在于,所述第一节点从所述超级节点中选取第一超级节点和第二超级节点,包括:
    所述第一节点获取每个所述超级节点的链路质量,并根据所述链路质量选取所述第一超级节点和所述第二超级节点。
  8. 根据权利要求1-7任一项所述的方法,其特征在于,所述第一节点从所述服务器获取待连接的第二节点的NAT类型,包括:
    所述第一节点从所述服务器获取在线节点信息;
    所述第一节点根据用户指令从所述在线节点信息中确定所述第二节点的节点身份标识(identity,ID);
    所述第一节点向所述服务器发送携带所述第二节点的节点ID的查询指令;
    所述第一节点接收所述服务器根据所述第二节点的节点ID查询到的所述第二节点的NAT类型。
  9. 根据权利要求1-8任一项所述的方法,其特征在于,所述第一节点根据自身的NAT类型和所述第二节点的NAT类型确定是否使用中继节点,包括:
    当所述第一节点和/或所述第二节点的NAT类型为完全圆锥型NAT时,或者,当所述第一节点和/或所述第二节点具有公网IP地址时,所述第一节点确定不需要使用所述中继节点。
  10. 根据权利要求1-8任一项所述的方法,其特征在于,所述第一节点根据自身的NAT类型和所述第二节点的NAT类型确定是否使用中继节点,包括:
    当所述第一节点和所述第二节点的NAT类型为受限圆锥型NAT或端口受限圆锥型NAT时,或者,当所述第一节点和所述第二节点满足一个节点的NAT类型为对称型NAT,另一个节点的NAT类型为受限圆锥型NAT时,所述第一节点确定使用中继节点,所述中继节点用于所述第一节点和所述第二节点进行UDP(user datagram protocol,用户数据报协议)打洞(holepunch)。
  11. 根据权利要求1-8任一项所述的方法,其特征在于,所述第一节点根据自身的NAT类型和所述第二节点的NAT类型确定是否使用中继节点,包括:
    当所述第一节点和所述第二节点满足一个节点的NAT类型为对称型NAT,另一个节点的NAT类型为端口受限圆锥型NAT时,所述第一节点确定使用中继节点,所述中继节点用于所述第一节点和所述第二节点进行端口预测。
  12. 根据权利要求1-8任一项所述的方法,其特征在于,所述第一节点根据自身的NAT类型和所述第二节点的NAT类型确定是否使用中继节点,包括:
    当所述第一节点和所述第二节点的NAT类型同时为对称型NAT时,所述第一节点确定使用中继节点,所述中继节点用于在所述第一节点和所述第二节点之间转发数据。
  13. 根据权利要求1-12任一项所述的方法,其特征在于,所述第一节点从所述超级节点中选取节点作为中继节点,包括:
    所述第一节点获取每个所述超级节点的链路质量,并根据所述链路质量从所述超级节点中选取所述中继节点。
  14. 根据权利要求1-13任一项所述的方法,其特征在于,所述第一节点、所述第二节点和所述超级节点包括位于广域网(wide area network,WAN),和/或,局域网(local area network,LAN)中的终端设备。
  15. 根据权利要求1-13任一项所述的方法,其特征在于,所述服务器位于广域网WAN,和/或,局域网LAN中;所述服务器具有公网IP地址,或者,所述服务器的NAT类型是圆锥型NAT。
  16. 根据权利要求1-13任一项所述的方法,其特征在于,所述第一节点使用所述中继节点与所述第二节点建立连接,还包括:
    所述第一节点使用所述中继节点与所述第二节点进行即时通信(instant messaging,IM),所述即时通信包括语音通信、视频通信、图像传输、文本传输和/或文件传输中的至少一种形式。
  17. 一种建立端到端网络连接的装置,用作第一节点,其特征在于,所述装置包括:收发器、存储器和处理器;其中,所述存储器包括有程序指令,所述程序指令被所述处理器运行时,使得所述装置用于执行如下步骤:
    从服务器获取超级节点信息,所述超级节点是所述服务器确定的、网络地址转换(network address translation,NAT)类型是圆锥型NAT的节点,或者,具有公网互联网协议(internet protocol,IP)地址的节点;
    向所述超级节点发送数据包,并根据所述超级节点返回的数据包确定自身的NAT类型;
    从所述服务器获取待连接的第二节点的NAT类型;
    根据自身的NAT类型和所述第二节点的NAT类型确定是否使用中继节点;
    当确定使用中继节点时,从所述超级节点中选取节点作为中继节点,并使用所述中继节点与所述第二节点建立连接。
  18. 根据权利要求17所述的装置,其特征在于,所述程序指令还使得所述装置执行如下步骤,以实现向所述超级节点发送数据包,并根据所述超级节点返回的数据包确定自身的NAT类型:
    向至少两个所述超级节点发送数据包;
    根据是否接收到所述超级节点返回的数据包,以及,所述超级节点返回的数据包的参数 确定自身的NAT类型。
  19. 根据权利要求17所述的装置,其特征在于,所述程序指令还使得所述装置执行如下步骤,以实现向所述超级节点发送数据包,并根据所述超级节点返回的数据包确定自身的NAT类型:
    从所述超级节点中选取第一超级节点和第二超级节点;
    向所述第一超级节点发送第一数据包,使所述第一超级节点获取所述第一数据包的源IP地址和源端口,并指示所述第二超级节点向所述第一数据包的源IP地址和源端口发送第二数据包;
    如果接收到所述第二数据包,则确定自身的NAT类型是完全圆锥型NAT。
  20. 根据权利要求19所述的装置,其特征在于,所述程序指令还使得所述装置执行如下步骤:
    如果未接收到所述第二数据包,向所述第二超级节点发送第三数据包,使所述第二超级节点获取所述第三数据包的源IP地址和源端口,并分析所述第一数据包的源端口和所述第三数据包的源端口是否相同;
    如果所述第一数据包的源端口和所述第三数据包的源端口不同,确定自身的NAT类型是对称型NAT。
  21. 根据权利要求20所述的装置,其特征在于,所述程序指令还使得所述装置执行如下步骤:
    如果所述第一数据包的源端口和所述第三数据包的源端口相同,分析是否接收到第四数据包,所述第四数据包是所述第二超级节点向所述第三数据包的源IP地址和源端口发送的,所述第二超级节点发送所述第四数据包使用的公网端口与所述第三数据包的目的端口不同;
    如果接收到所述第四数据包,则确定自身的NAT类型是受限圆锥型NAT;
    如果未接收到所述第四数据包,则确定自身的NAT类型是端口受限圆锥型NAT。
  22. 根据权利要求19所述的装置,其特征在于,所述程序指令还使得所述装置执行如下步骤,以实现从所述超级节点中选取第一超级节点和第二超级节点:
    确定所述超级节点信息中是否包含历史选取过的所述超级节点,如果包含历史选取过的所述超级节点,则从历史选取过的所述超级节点中选取所述第一超级节点和所述第二超级节点。
  23. 根据权利要求19所述的装置,其特征在于,所述程序指令还使得所述装置执行如下步骤,以实现从所述超级节点中选取第一超级节点和第二超级节点:
    获取每个所述超级节点的链路质量,并根据所述链路质量选取所述第一超级节点和所述第二超级节点。
  24. 根据权利要求17-23任一项所述的装置,其特征在于,所述程序指令还使得所述装置执行如下步骤,以实现从所述服务器获取待连接的第二节点的NAT类型:
    从所述服务器获取在线节点信息;
    根据用户指令从所述在线节点信息中确定所述第二节点的节点身份标识(identity,ID);
    向所述服务器发送携带所述第二节点的节点ID的查询指令;
    接收所述服务器根据所述第二节点的节点ID查询到的所述第二节点的NAT类型。
  25. 根据权利要求17-24任一项所述的装置,其特征在于,所述程序指令还使得所述装置执行如下步骤,以实现根据自身的NAT类型和所述第二节点的NAT类型确定是否使用中继节点:
    当所述装置和/或所述第二节点的NAT类型为完全圆锥型NAT时,或者,当所述装置和/或所述第二节点具有公网IP地址时,确定不需要使用所述中继节点。
  26. 根据权利要求17-24任一项所述的装置,其特征在于,所述程序指令还使得所述装置执行如下步骤,以实现根据自身的NAT类型和所述第二节点的NAT类型确定是否使用中继节点:
    当所述装置和所述第二节点的NAT类型为受限圆锥型NAT或端口受限圆锥型NAT时,或者,当所述装置和所述第二节点满足其中一个的NAT类型为对称型NAT,另一个的NAT类型为受限圆锥型NAT时,确定使用中继节点,所述中继节点用于所述装置和所述第二节点进行UDP(user datagram protocol,用户数据报协议)打洞(holepunch)。
  27. 根据权利要求17-24任一项所述的装置,其特征在于,所述程序指令还使得所述装置执行如下步骤,以实现根据自身的NAT类型和所述第二节点的NAT类型确定是否使用中继节点:
    当所述装置和所述第二节点满足其中一个的NAT类型为对称型NAT,另一个的NAT类型为端口受限圆锥型NAT时,确定使用中继节点,所述中继节点用于所述装置和所述第二节点进行端口预测。
  28. 根据权利要求17-24任一项所述的装置,其特征在于,所述程序指令还使得所述装置执行如下步骤,以实现根据自身的NAT类型和所述第二节点的NAT类型确定是否使用中继节点:
    当所述装置和所述第二节点的NAT类型同时为对称型NAT时,确定使用中继节点,所述中继节点用于在所述装置和所述第二节点之间转发数据。
  29. 根据权利要求17-28任一项所述的装置,其特征在于,所述程序指令还使得所述装置执行如下步骤,以实现从所述超级节点中选取节点作为中继节点:
    获取每个所述超级节点的链路质量,并根据所述链路质量从所述超级节点中选取所述中继节点。
  30. 一种网络系统,其特征在于,包括:节点和服务器;
    所述服务器,用于向第一节点发送超级节点信息,所述超级节点是所述服务器确定的、网络地址转换(network address translation,NAT)类型是圆锥型NAT的节点,或者,具有公网互联网协议(internet protocol,IP)地址的节点;
    所述第一节点,用于向所述超级节点发送数据包,并根据所述超级节点返回的数据包确 定自身的NAT类型;
    所述服务器,还用于响应所述第一节点的请求,向所述第一节点发送第二节点的NAT类型,所述第二节点是所述第一节点选取的待连接的节点;
    所述第一节点,还用于根据自身的NAT类型和所述第二节点的NAT类型确定是否使用中继节点;
    所述第一节点,还用于所当确定使用中继节点时,从所述超级节点中选取节点作为中继节点,并使用所述中继节点与所述第二节点建立连接。
  31. 根据权利要求30所述的网络系统,其特征在于,
    所述第一节点,用于向至少两个所述超级节点发送数据包;
    所述超级节点,用于响应来自所述第一节点的数据包,向所述第一节点返回发送数据包;
    所述第一节点,还用于根据是否接收到所述超级节点返回的数据包,以及,所述超级节点返回的数据包的参数确定自身的NAT类型。
  32. 根据权利要求30所述的网络系统,其特征在于,
    所述服务器,用于向所述第一节点发送在线节点信息;
    所述第一节点,用于根据用户指令从所述在线节点信息中确定所述第二节点的节点ID;
    所述第一节点,还用于向所述服务器发送携带所述第二节点的节点ID的查询指令;
    所述服务器,还用于响应所述查询指令,根据所述第二节点的节点ID查询所述第二节点的NAT类型,并将所述第二节点的NAT类型发送给所述第一节点。
PCT/CN2020/095045 2019-06-11 2020-06-09 一种建立端到端网络连接的方法、装置及网络系统 WO2020248963A1 (zh)

Priority Applications (2)

Application Number Priority Date Filing Date Title
EP20822695.1A EP3958534B1 (en) 2019-06-11 2020-06-09 Method and apparatus for establishing end-to-end network connection, and network system
US17/618,123 US12058096B2 (en) 2019-06-11 2020-06-09 Method and apparatus for establishing end-to-end network connection, and network system

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201910501933.1 2019-06-11
CN201910501933.1A CN110266828A (zh) 2019-06-11 2019-06-11 一种建立端到端网络连接的方法、装置及网络系统

Publications (1)

Publication Number Publication Date
WO2020248963A1 true WO2020248963A1 (zh) 2020-12-17

Family

ID=67917620

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/095045 WO2020248963A1 (zh) 2019-06-11 2020-06-09 一种建立端到端网络连接的方法、装置及网络系统

Country Status (4)

Country Link
US (1) US12058096B2 (zh)
EP (1) EP3958534B1 (zh)
CN (1) CN110266828A (zh)
WO (1) WO2020248963A1 (zh)

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114374667A (zh) * 2021-12-28 2022-04-19 中国电信股份有限公司 一种分配nat ip的方法、装置及存储介质
CN114449027A (zh) * 2021-12-20 2022-05-06 北京网神洞鉴科技有限公司 远程取证方法、装置、电子设备及存储介质
WO2023007248A1 (en) * 2021-07-30 2023-02-02 Quantum Networks (SG) Pte. Ltd. System and method for independent binding of virtual networks overlay using a physical network topology
WO2023122217A1 (en) * 2021-12-22 2023-06-29 Universal City Studios Llc Bi-directional cbrs communications system and methods

Families Citing this family (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110266828A (zh) 2019-06-11 2019-09-20 华为技术有限公司 一种建立端到端网络连接的方法、装置及网络系统
CN113067911B (zh) * 2020-01-02 2023-06-30 中国移动通信有限公司研究院 一种nat穿越方法、装置、电子设备和存储介质
CN112019641B (zh) * 2020-10-19 2021-01-15 腾讯科技(深圳)有限公司 数据传输方法和装置
CN112367388B (zh) * 2020-10-30 2024-05-24 北京北信源软件股份有限公司 服务器与客户端并发通信的方法及装置
CN113507153A (zh) * 2021-07-12 2021-10-15 四川智汇同盟信息技术有限公司 一种新能源汽车广义电池管理系统及方法
CN116094821B (zh) * 2023-01-29 2024-05-14 中国联合网络通信集团有限公司 一种路由配置方法及装置

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030145106A1 (en) * 2002-01-31 2003-07-31 Sun Microsystems, Inc. System and method for directing wireless data packet traffic
WO2004073281A2 (en) * 2003-02-12 2004-08-26 Saviso Group Ltd Methods and apparatus for traffic management in peer-to.peer networks
CN1863157A (zh) * 2005-10-28 2006-11-15 华为技术有限公司 穿越nat实现网络通信的方法及装置
CN105610999A (zh) * 2016-03-30 2016-05-25 上海斐讯数据通信技术有限公司 一种通过穿透nat实现p2p通信的方法、设备、服务器及系统
CN109495599A (zh) * 2018-11-16 2019-03-19 深圳市网心科技有限公司 数据传输方法和系统、电子装置及计算机可读存储介质
CN109660637A (zh) * 2018-11-16 2019-04-19 深圳市网心科技有限公司 P2p打洞传输方法和系统、电子装置及计算机可读存储介质
CN109831547A (zh) * 2019-03-14 2019-05-31 腾讯科技(深圳)有限公司 Nat穿透方法、装置、设备及存储介质
CN110266828A (zh) * 2019-06-11 2019-09-20 华为技术有限公司 一种建立端到端网络连接的方法、装置及网络系统

Family Cites Families (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7788378B2 (en) * 2005-04-22 2010-08-31 Microsoft Corporation Apparatus and method for community relay node discovery
CN100469022C (zh) * 2006-05-29 2009-03-11 腾讯科技(深圳)有限公司 一种检测网络类型的方法及系统
CN101217536B (zh) * 2007-12-28 2011-11-09 腾讯科技(深圳)有限公司 穿越网络地址转换设备/防火墙的方法、系统及客户端
CN101282302B (zh) * 2008-05-29 2012-05-02 腾讯科技(深圳)有限公司 数据中转方法、系统、客户端及服务器
US8165091B2 (en) * 2008-06-27 2012-04-24 Nix John A Efficient handover of media communications in heterogeneous IP networks using LAN profiles and network handover rules
CN101820382B (zh) * 2009-02-28 2013-02-27 华为技术有限公司 一种通告网络地址转换设备信息的方法、装置和系统
US8751500B2 (en) 2012-06-26 2014-06-10 Google Inc. Notification classification and display
CN103139349A (zh) 2013-03-06 2013-06-05 广东欧珀移动通信有限公司 一种移动终端信息通知方法、装置及移动终端
US10237236B2 (en) * 2015-06-25 2019-03-19 Microsoft Technology Licensing, Llc Media Session
JP6254620B2 (ja) * 2016-02-02 2017-12-27 エヌ・ティ・ティ・コミュニケーションズ株式会社 端末、通信方法、及びプログラム
US11238855B1 (en) * 2017-09-26 2022-02-01 Amazon Technologies, Inc. Voice user interface entity resolution

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030145106A1 (en) * 2002-01-31 2003-07-31 Sun Microsystems, Inc. System and method for directing wireless data packet traffic
WO2004073281A2 (en) * 2003-02-12 2004-08-26 Saviso Group Ltd Methods and apparatus for traffic management in peer-to.peer networks
CN1863157A (zh) * 2005-10-28 2006-11-15 华为技术有限公司 穿越nat实现网络通信的方法及装置
CN105610999A (zh) * 2016-03-30 2016-05-25 上海斐讯数据通信技术有限公司 一种通过穿透nat实现p2p通信的方法、设备、服务器及系统
CN109495599A (zh) * 2018-11-16 2019-03-19 深圳市网心科技有限公司 数据传输方法和系统、电子装置及计算机可读存储介质
CN109660637A (zh) * 2018-11-16 2019-04-19 深圳市网心科技有限公司 P2p打洞传输方法和系统、电子装置及计算机可读存储介质
CN109831547A (zh) * 2019-03-14 2019-05-31 腾讯科技(深圳)有限公司 Nat穿透方法、装置、设备及存储介质
CN110266828A (zh) * 2019-06-11 2019-09-20 华为技术有限公司 一种建立端到端网络连接的方法、装置及网络系统

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
See also references of EP3958534A4

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023007248A1 (en) * 2021-07-30 2023-02-02 Quantum Networks (SG) Pte. Ltd. System and method for independent binding of virtual networks overlay using a physical network topology
CN114449027A (zh) * 2021-12-20 2022-05-06 北京网神洞鉴科技有限公司 远程取证方法、装置、电子设备及存储介质
WO2023122217A1 (en) * 2021-12-22 2023-06-29 Universal City Studios Llc Bi-directional cbrs communications system and methods
CN114374667A (zh) * 2021-12-28 2022-04-19 中国电信股份有限公司 一种分配nat ip的方法、装置及存储介质
CN114374667B (zh) * 2021-12-28 2024-04-16 中国电信股份有限公司 一种分配nat ip的方法、装置及存储介质

Also Published As

Publication number Publication date
EP3958534A4 (en) 2022-06-08
EP3958534B1 (en) 2024-08-21
EP3958534A1 (en) 2022-02-23
CN110266828A (zh) 2019-09-20
US12058096B2 (en) 2024-08-06
US20220286425A1 (en) 2022-09-08

Similar Documents

Publication Publication Date Title
WO2020248963A1 (zh) 一种建立端到端网络连接的方法、装置及网络系统
US8374188B2 (en) Techniques to manage a relay server and a network address translator
CN102265568B (zh) 一种通信方法及负载均衡器
JP6009630B2 (ja) 同時パケット・データ・ネットワーク(pdn)・アクセス
US20130058256A1 (en) Port mapping method and apparatus, and communication system
US10419236B1 (en) Mobile wide area network IP translation configuration
US8612601B2 (en) Management method and management device for network address translation
US9049122B2 (en) Bandwidth probing messages
US11784963B2 (en) NAT traversal method, device, and system
EP3462713B1 (en) Nat entry management method and apparatus, and nat device
WO2021008591A1 (zh) 数据传输方法、装置及系统
US20140032782A1 (en) Method and apparatus for route selection of host in multihoming site
CN112333713A (zh) 5g自组网系统、自组网方法、计算机设备及存储介质
CN107547690B (zh) Nat中的端口分配方法、装置、nat设备及存储介质
WO2024114022A1 (zh) 会话控制方法、系统及smf网元
CN114598532B (zh) 连接建立方法、装置、电子设备和存储介质
CN108650179B (zh) 一种配置转发表的方法、转发装置及计算机可读存储介质
CN108337331B (zh) 网络穿透方法、装置、系统及网络连通性检查方法
KR101124635B1 (ko) IPv4/IPv6 연동 게이트웨이
EP3264724B1 (en) Method and apparatus for sending, transferring and acquiring capability
KR101586058B1 (ko) Nat환경을 고려한 피투피 통신 연결 장치 및 이를 이용한 피투피 통신 연결 방법
WO2016197832A1 (zh) 报文处理方法、设备和系统
CN114513387A (zh) 一种隧道建立方法、装置及设备

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20822695

Country of ref document: EP

Kind code of ref document: A1

ENP Entry into the national phase

Ref document number: 2020822695

Country of ref document: EP

Effective date: 20211117

NENP Non-entry into the national phase

Ref country code: DE