WO2022148361A1 - 建立p2p连接的方法、客户端及系统 - Google Patents

建立p2p连接的方法、客户端及系统 Download PDF

Info

Publication number
WO2022148361A1
WO2022148361A1 PCT/CN2022/070236 CN2022070236W WO2022148361A1 WO 2022148361 A1 WO2022148361 A1 WO 2022148361A1 CN 2022070236 W CN2022070236 W CN 2022070236W WO 2022148361 A1 WO2022148361 A1 WO 2022148361A1
Authority
WO
WIPO (PCT)
Prior art keywords
client
public network
network address
address
port
Prior art date
Application number
PCT/CN2022/070236
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 US18/271,013 priority Critical patent/US20240064206A1/en
Publication of WO2022148361A1 publication Critical patent/WO2022148361A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/104Peer-to-peer [P2P] networks
    • 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
    • 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/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
    • 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
    • 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

Definitions

  • the embodiments of the present application relate to the field of Internet technologies, and in particular, to a method for establishing a P2P connection.
  • One or more embodiments of the present application simultaneously relate to a client and a system for establishing a P2P connection, a computing device, a computer-readable storage medium, and a computer program product.
  • NAT technology is a technology that converts the private network address of the internal network into the public network address of the external network.
  • There is a mapping table inside the NAT device which stores the mapping relationship between the internal network and the external network. For the packets sent to the outside world, a mapping relationship between the internal network and the external network will be added to the mapping table of the NAT device. In the future, all packets sent from the external network will check the mapping table. If there is, replace the external network address of the packet with the internal network address.
  • the embodiments of the present application provide a method for establishing a P2P connection.
  • One or more embodiments of the present application simultaneously relate to a client and a system for establishing a P2P connection, a computing device, a computer-readable storage medium, and a computer program product to solve the technical problems existing in the prior art defect.
  • a method for establishing a P2P connection is provided, applied to a first client, including:
  • the response message determine at least one public network address corresponding to the internal network address of the first client
  • Register at least one public network address corresponding to the intranet address of the first client with the cloud server, and monitor at least one public network address corresponding to the intranet address of the first client;
  • a method for establishing a P2P connection including:
  • the first client and the second client communicate with at least two auxiliary nodes respectively, and obtain response messages returned by the at least two auxiliary nodes; according to the response messages, determine at least one public network address corresponding to the respective intranet addresses ; register at least one public network address corresponding to each intranet address with the cloud server, and monitor the at least one public network address;
  • the first client obtains at least one public network address corresponding to the intranet address of the second client through the cloud server, and sends a message to each of the at least one public network address corresponding to the intranet address of the second client.
  • the public network address sends an access request data packet;
  • the second client obtains at least one public network address corresponding to the internal network address of the first client through the cloud server in the case of monitoring its own target public network address to receive the access request data packet, and sends it to the Each of the at least one public network address corresponding to the internal network address of the first client returns a response data packet, and the target public network address is at least one public network address corresponding to the internal network address of the second client.
  • the web addresses one of the web addresses;
  • the first client establishes a P2P connection with the second client under the condition that the second client returns a response data packet to its own target public network address, and the target public network address is the One of at least one public network address corresponding to the internal network address of the first client.
  • a client including:
  • a first obtaining module configured to communicate with at least two auxiliary nodes, and obtain response messages returned by the at least two auxiliary nodes;
  • a determining module configured to determine at least one public network address corresponding to the internal network address of the first client according to the response message
  • a monitoring module configured to register at least one public network address corresponding to the internal network address of the first client with the cloud server, and monitor at least one public network address corresponding to the internal network address of the first client;
  • the connection establishment module is configured to establish a P2P connection with the second client under the condition that the second client returns a response data packet to the target public network address, and the target public network address is the first client One of at least one public network address corresponding to the internal network address of the terminal.
  • a system for establishing a P2P connection including:
  • the first client and the second client are configured to communicate with at least two auxiliary nodes respectively, and obtain response messages returned by the at least two auxiliary nodes; a public network address; register at least one public network address corresponding to each intranet address with the cloud server, and monitor the at least one public network address;
  • the first client is further configured to obtain at least one public network address corresponding to the intranet address of the second client through the cloud server, and send at least one public network address corresponding to the intranet address of the second client Each of the public network addresses in the address sends an access request data packet;
  • the second client is further configured to obtain at least one public address corresponding to the internal network address of the first client through the cloud server in the case of monitoring that the target public address of the client receives the access request data packet. network address, returning a response data packet to each of the at least one public network address corresponding to the internal network address of the first client, and the target public network address is the internal network address of the second client One of the corresponding at least one public network address;
  • the first client is further configured to establish a P2P connection with the second client in the case of monitoring that the second client returns a response data packet to the target public network address of the second client, and the target public address
  • the network address is one of at least one public network address corresponding to the internal network address of the first client.
  • a computing device including:
  • the memory is used to store computer-executable instructions
  • the processor is used to execute the computer-executable instructions to implement the following methods:
  • the response message determine at least one public network address corresponding to the internal network address of the first client
  • Register at least one public network address corresponding to the intranet address of the first client with the cloud server, and monitor at least one public network address corresponding to the intranet address of the first client;
  • a computer-readable storage medium which stores computer-executable instructions, and when the instructions are executed by a processor, implements any of the methods for establishing a P2P connection described in the first aspect above. step.
  • a computer program product that, when the computer program product is executed in a computer, causes the computer to execute any of the steps of the above-mentioned method for establishing a P2P connection.
  • a first client can communicate with at least two auxiliary nodes, and obtain response messages returned by the at least two auxiliary nodes; and then, according to the response messages, determine the first client at least one public network address corresponding to the internal network address of the client, register at least one public network address corresponding to the internal network address of the first client with the cloud server, and monitor at least one public network address corresponding to the internal network address of the first client address, establish a P2P connection with the second client in the case of monitoring that the second client returns a response data packet to the target public network address, and the target public network address corresponds to the internal network address of the first client one of at least one public address of .
  • the first client can be used to communicate with at least two auxiliary nodes, and at least one public network address corresponding to the internal network address of the first client can be detected, so as to determine whether there are multiple external public network addresses of the first client. That is to say, at least two auxiliary nodes can be used to more accurately detect the public network address corresponding to the internal network address of the first client, which improves the success rate of hole punching among clients corresponding to multiple public network addresses, and achieves a relatively high level of accuracy. High success rate of P2P connection.
  • FIG. 1 is a flowchart of a method for establishing a P2P connection provided by an embodiment of the present application
  • FIG. 2 is a schematic diagram of a conventional NAT detection provided by an embodiment of the present application.
  • FIG. 3 is a schematic diagram of a public network address provided by an embodiment of the present application.
  • FIG. 4 is a schematic diagram of establishing a P2P connection according to an embodiment of the present application.
  • FIG. 5 is a flowchart of another method for establishing a P2P connection provided by an embodiment of the present application.
  • FIG. 6 is a flowchart of another method for establishing a P2P connection provided by an embodiment of the present application
  • FIG. 7 is a schematic structural diagram of a client according to an embodiment of the present application.
  • FIG. 8 is a schematic structural diagram of a system for establishing a P2P connection provided by an embodiment of the present application.
  • FIG. 9 is a structural block diagram of a computing device provided by an embodiment of the present application.
  • IP address Internet Protocol Address, Internet Protocol Address
  • IP address is a unified address format provided by IP protocol, which assigns a logical address to each network and each host on the Internet , to mask the difference in physical addresses.
  • NAT Network Address Translation: Some hosts within the private network have been assigned local IP addresses (that is, private addresses only used within the private network), but want to communicate with hosts on the Internet (and When encryption is not required), the NAT method can be used. This method has at least one valid external global IP address, the public address. In this way, when all hosts using local addresses communicate with the outside world, they must convert their local addresses into public addresses on the NAT device before they can connect to the Internet.
  • NAT devices can be divided into three categories, including static NAT, dynamic NAT and NAPT (Network Address Port Translation). Static NAT translation is relatively simple. Dynamic NAT means that instead of establishing a one-to-one fixed correspondence between internal addresses and global addresses, the NAT mapping relationship is dynamically established by sharing the IP addresses of the NAT address pool. NATP is the most common NAT and the most studied type of NAT in academia. NATP maps the internal network connection to a separate IP address in the external network, and adds a port number selected by the NAT device to this address. There are four types, including full cone and IP restricted cone. Type, Port Restricted Cone, and Symmetrical Type.
  • IP-restricted cone NAT Once an internal host-port pair (iAddr:iPort) is mapped to (eAddr:ePort), all subsequent (iAddr:iPort) packets are translated to (eAddr:ePort); only (iAddr:iPort) ) has sent data to a specific external host hAddr, and the packet sent by the host hAddr from any port to (eAddr:ePort) will be forwarded to (iAddr:iPort).
  • Port-restricted cone NAT Once an internal host-port pair (iAddr:iPort) is mapped to (eAddr:ePort), all subsequent (iAddr:iPort) packets are translated to (eAddr:ePort); only (iAddr:iPort) ) has sent data to a specific external host port pair (hAddr:hPort), and packets sent by (hAddr:hPort) to (eAddr:ePort) will be forwarded to (iAddr:iPort).
  • Symmetric NAT The NAT gateway will treat the same packets as the internal host "address port pair" and the external host "address port pair” as a connection, and create a public network "address port pair” mapping on the gateway for translation. Only when the external host that receives the message sends a response message from the corresponding port pair can it be translated. Even if the internal host uses the previously used address-port pair to connect to a different external host (or port), the NAT gateway will establish a new one. mapping relationship.
  • Hole punching server STUN server, User Datagram Protocol (UDP) simply traverses Network Address Translator (NAT), which allows all clients corresponding to NAT devices (such as computers behind firewalls) to communicate with VOIP outside the local area network
  • the service provider implements telephone calls.
  • STUN server Through the STUN server, clients can learn their public address, the type of NAT in front of them, and the Internet side port that is NATed to a specific local port. This information will be used to establish UDP communication between the client and the VOIP service provider in order to implement the call.
  • a method for establishing a P2P connection is provided, and the present application also relates to a client and a system for establishing a P2P connection, a computing device, a computer-readable storage medium, and a computer program product, Detailed descriptions will be made one by one in the following examples.
  • FIG. 1 shows a flowchart of a method for establishing a P2P connection according to an embodiment of the present application, which is applied to a first client and specifically includes the following steps:
  • Step 102 Communicate with at least two auxiliary nodes, and obtain response messages returned by the at least two auxiliary nodes.
  • a first client can communicate with at least two auxiliary nodes to obtain response messages returned by the at least two auxiliary nodes; and then, according to the response messages, determine at least one public network address corresponding to the internal network address of the first client, register at least one public network address corresponding to the internal network address of the first client with the cloud server, and monitor the corresponding internal network address of the first client at least one public network address; in the case of listening to the second client returning a response data packet to the target public network address, establish a P2P connection with the second client, and the target public network address is the first client One of at least one public network address corresponding to the internal network address of the terminal.
  • the first client can be used to communicate with at least two auxiliary nodes to detect whether there are multiple public network addresses corresponding to the internal network address of the first client.
  • the public network address corresponding to the internal network address of the first client is detected, thereby improving the success rate of hole punching among clients corresponding to multiple public network addresses, and realizing the establishment of a P2P connection with a higher success rate.
  • the auxiliary node may be a full cone NAT device or a public network node, so that other types of nodes can establish a connection with the auxiliary node to detect the public network address, where the public network address may include the public network IP address and public network port.
  • the first client may obtain the at least two auxiliary nodes from a cloud server, the cloud server is a node scheduling server, and all nodes maintain signaling interaction with the cloud server. It should be noted that the greater the number of auxiliary nodes, the more comprehensive and accurate the detected public network address.
  • the number of auxiliary nodes is not limited in this application, and can be set according to specific requirements in practical applications.
  • the first client includes a terminal device waiting to establish a P2P connection and a corresponding NAT device, the terminal device interacts with the outside world through the corresponding NAT device, and the NAT device can convert the internal network address of the terminal device into an external device.
  • the public network address to interact with the outside world.
  • the second client that needs to establish a P2P connection with the first client can perform the same operation as the first client. That is, the second client can also communicate with the at least two auxiliary nodes, and obtain the response messages returned by the at least two auxiliary nodes, so as to determine at least one public network address corresponding to the internal network address of the second client, which is convenient for subsequent At least one public network address corresponding to the internal network address of the first client is exchanged to establish a P2P connection with the first client.
  • the first client before using the auxiliary node to detect the corresponding public network address, may also perform detection by traversing the auxiliary server to obtain the NAT type of the NAT device corresponding to the first client.
  • the first client communicates with at least two auxiliary nodes, and before acquiring the response messages returned by the at least two auxiliary nodes, the method further includes:
  • the intranet address and the NAT type of the corresponding NAT device are stored locally.
  • the traversal auxiliary server refers to the hole punching server, that is, the STUN server.
  • the public network address detection of the NAT device is divided into conventional NAT detection and NAT detection with the help of auxiliary nodes.
  • Conventional NAT detection refers to the communication between the first client and the traversal auxiliary server, and the current intranet and public network address pairs used for communication can be obtained ( IP_A, Port_A: IP_A', Port_A'), preliminarily determine the NAT type.
  • communicating with at least two auxiliary nodes to obtain response messages returned by the at least two auxiliary nodes may be as follows:
  • a response message returned by the at least two assisting nodes in response to the assisting probe request is received.
  • auxiliary nodes can be used for further detection.
  • the first client can randomly acquire at least two auxiliary nodes distributed in different locations from the cloud server;
  • the client uses the intranet address (IP_A, Port_A) used to communicate with the punching server to communicate with the obtained auxiliary nodes.
  • IP_A, Port_A intranet address
  • the first client receives the response information from these auxiliary nodes, it can record the connection with these auxiliary nodes.
  • Public network IP address and public network port that is, public network address).
  • FIG. 2 is a schematic diagram of a conventional NAT detection provided by an embodiment of the present application.
  • IP_A' Port_A'
  • the client B communicates with the hole punching server through the intranet IP address and intranet port (IP_B: Port_B), and is converted into the public network IP address and public network port (IP_B': Port_B') through the corresponding NAT device B. , and register its own NAT device type and the corresponding public network IP address and public network port in the hole punching server.
  • Step 104 Determine at least one public network address corresponding to the internal network address of the first client according to the response message.
  • the public network address may include a public network IP address and a public network port.
  • the public network address corresponding to the internal network address of the first client is roughly divided into three situations: Scenario 1, the public network IP addresses are different, and the corresponding internal network to public network addresses are different. Port mapping is certain; in case 2, when communicating with different auxiliary nodes, the port will change in a small range up and down the original position; in case 3, there are multiple public IP addresses, and the ports passing through the public IP addresses will also change.
  • FIG. 3 is a schematic diagram of a public network address provided by an embodiment of the present application.
  • client A communicates with auxiliary nodes D, E, F, and G respectively through an intranet address (IP_A: Port_A).
  • IP_A Intranet address
  • H communication according to the response messages returned by each auxiliary node, the public IP address of communication with auxiliary nodes D, E, F is IP_A1', and the public network IP address of communication with auxiliary nodes G and H is IP_A2', that is, , the NAT device A corresponding to the client A maps the intranet IP address IP_A of the client A to the public IP address IP_A1' or IP_A2' (no port restriction).
  • NAT device A corresponding to client A is a port-restricted cone
  • client A communicates with auxiliary nodes D, E, F, G, and H respectively through the intranet address (IP_A: Port_A), and according to the responses returned by each auxiliary node
  • IP_A Port_A
  • the public network IP addresses that communicate with the auxiliary nodes D, E, and F are IP_A1'
  • the public network port that communicates with the auxiliary nodes D and E is Port_A1'
  • the public network port that communicates with the auxiliary node F is Port_A2'
  • the public network IP addresses communicating with the auxiliary nodes G and H are both IP_A2'
  • the public network ports are both Port_A3'.
  • the NAT device A corresponding to the client A maps the internal network address (IP_A: Port_A) of the client A to the public network address (IP_A1': Port_A1'), (IP_A1': Port_A2') or (IP_A2': Port_A3 ').
  • NAT device corresponding to client B is a port-restricted cone
  • client B communicates with auxiliary nodes D, E, F, G, and H respectively through the intranet address (IP_B: Port_B), and according to the response messages returned by each auxiliary node
  • IP_B Port_B
  • the public network IP addresses that communicate with the auxiliary nodes D, E, F, G, and H are all IP_B', but the public network port that communicates with the auxiliary nodes D, E, F, and G is Port_B1', which communicates with the auxiliary node H.
  • the public network port is Port_B2', that is, the NAT device B corresponding to client B maps the internal network address (IP_B: Port_B) of client B to the public network address (IP_B'; Port_B1') or (IP_B'; Port_B2 ').
  • At least one public network address corresponding to the internal network address of the first client is determined according to the response message, and the specific implementation process may be as follows:
  • the NAT type of the NAT device corresponding to the first client is a port restriction cone
  • the NAT type of the NAT device corresponding to the first client is a port restriction cone, it means that the first client will limit the port when interacting with the outside world through the corresponding NAT device.
  • the public network IP address For the public network IP address, at least one corresponding public network port needs to be determined, and then the public network IP address and the corresponding at least one public network port are determined as a public network address, so as to obtain at least one public network address.
  • the at least one public network address sends an access request data packet to establish a P2P connection.
  • determining the estimated public network port corresponding to the public network IP address according to the at least one public network port a specific implementation process may be as follows:
  • the first public network port and the second public network port determine the start port identifier and the end port identifier
  • a public network port between the starting port identifier and the ending port identifier is determined as the estimated public network port.
  • the determination of the starting port identifier and the ending port identifier according to the first public network port and the second public network port may be as follows:
  • the initial port identifier is obtained by subtracting the preset threshold from the port identifier of the second public network port.
  • the preset threshold may be set in advance, such as 20, 30, 40, and the like.
  • auxiliary nodes due to the limited number of auxiliary nodes, it is difficult to determine all the public network ports corresponding to the public network IP address of the first client with the help of the auxiliary nodes.
  • other public network ports corresponding to the public network IP address can also be predicted according to the determined at least one public network port, so as to determine the estimated public network port as the public network port corresponding to the internal network address of the first client. web address.
  • the public network ports near these public network ports may also be the public network ports for subsequent hole punching operations. Therefore, according to at least one public network port returned by the auxiliary node, the starting port identification and the ending port identification can be determined, and then the continuous port between the starting port identification and the ending port identification can be determined as the corresponding public network IP address. The estimated public network port, and then determine the corresponding public network address.
  • the public network IP addresses determined by the first client by means of at least two auxiliary nodes are IP_A, IP_B, and IP_C.
  • IP_A assuming that the corresponding public network ports determined by the auxiliary node are ports 1121, 1123, and 1125, and the preset threshold is 20, then the starting port ID is 1101, and the ending port ID is 1145.
  • 1101 ⁇ 1145 The port between IP_A and 1101 ⁇ 1145 is determined as the estimated public network port, and then the port between IP_A and 1101 ⁇ 1145 is determined as a public network address.
  • the public network addresses corresponding to IP_B and IP_C can be obtained, thereby finally obtaining three public network addresses corresponding to the internal network address of the first client.
  • determining at least one public network IP address corresponding to the internal network address of the first client terminal according to the response message including:
  • auxiliary node For each auxiliary node in the at least two auxiliary nodes, determine the public network IP address corresponding to the response message returned by the auxiliary node;
  • the first client when the first client (or the second client) receives the response information from these auxiliary nodes, it can record the public network IP addresses established with these auxiliary nodes, and then use the obtained series of public network IP addresses. The IP address is analyzed. If all public IP addresses are displayed as the same, it is the same as the result of conventional NAT detection, that is, the NAT device corresponding to the first client (or the second client) The address is mapped to a public network IP address, and the first client subsequently establishes a connection with other clients through the public network IP address.
  • the corresponding NAT device maps the internal network address of the first client to multiple public network IP addresses, and at this time the corresponding multiple public network IP addresses can be recorded in the data structure of the local client. That is to say, a deduplication operation is performed on the public network IP address corresponding to the response message, and at least one public network IP address corresponding to the internal network address of the first client is determined.
  • the NAT type of the NAT device corresponding to the first client is not a port-restricted cone, it means that the NAT device corresponding to the first client has no restrictions on ports, and only needs to respond to the response messages returned by at least two auxiliary nodes.
  • the public network IP address is deduplicated to obtain the public network address, and there is no need to further determine the public network port.
  • the first client and the second client may communicate with at least two auxiliary nodes respectively, and obtain response messages returned by the at least two auxiliary nodes, thereby determining the public IP address and public network IP address of the corresponding NAT device.
  • network ports that is, public network addresses
  • at least two auxiliary nodes can be used to more accurately detect multiple public network addresses and public network ports corresponding to the respective intranet addresses of the first client and the second client,
  • the success rate of hole punching between clients corresponding to multiple public network addresses is improved, and a P2P connection with a higher success rate is realized.
  • Step 106 Register at least one public network address corresponding to the internal network address of the first client with the cloud server, and monitor at least one public network address corresponding to the internal network address of the first client.
  • the address corresponding to the internal network address of the first client may be registered with the cloud server at least one public network address, and monitor at least one public network address corresponding to the internal network address of the first client.
  • the cloud server is a server that manages and controls the at least two auxiliary nodes.
  • the registering with the cloud server at least one public network address corresponding to the intranet address of the first client includes:
  • At least one public network address corresponding to the internal network address of the first client and the NAT type of the corresponding NAT device are registered with the cloud server.
  • the first client can also detect its own NAT device type by traversing the auxiliary server (ie, the hole punching server), and then register it in the cloud server for the first client.
  • the second client obtains.
  • the second client can perform the same operation as the first client, and also register its own NAT type on the cloud server for the first client to obtain.
  • the first client and the second server can obtain each public network IP address corresponding to the intranet address, each public network port and the corresponding NAT type after performing NAT detection with the help of at least two auxiliary nodes respectively. It is registered on the cloud server in the form of data stream, and the cloud server and the opposite end exchange their respective registration information, so that the first client can obtain the public network IP address and public network port of the second client, thereby establishing a P2P connection.
  • the second client that needs to establish a P2P connection with the first client may perform the same operation as the first client. That is, the second client can also perform the steps described in the above steps 102-106, thereby determining at least one public network address and NAT type corresponding to the intranet address of the second client, and registering it on the cloud server to facilitate subsequent At least one public network address corresponding to the internal network address of the first client and the NAT type are exchanged to establish a P2P connection with the first client.
  • the first client and the second client respectively register at least one public network address corresponding to their respective intranet addresses with the cloud server
  • the first client can access the cloud server from the cloud server. to obtain at least one public network address corresponding to the intranet address of the second client in order to establish a P2P connection with the second client, that is, after registering the at least one public network address corresponding to the intranet address of the first client with the cloud server
  • Also includes:
  • At least one public network address corresponding to the intranet address of the second client is obtained through the cloud server, and at least one public network address corresponding to the intranet address of the second client is obtained by the second client through the at least one public network address.
  • the access request data packet may refer to a hole punching data packet.
  • at least one public network address corresponding to the internal network address of the second client obtained by the first client from the cloud server is the public address determined by the second client through the method steps of steps 102 to 106 above and with the help of the auxiliary node. web address.
  • the first client can send to the at least one public network address corresponding to the intranet address of the second client.
  • Each of the public network addresses in the network addresses sends an access request data packet.
  • the second client can monitor each of its own public network addresses. If it monitors any public network address of its own and receives the access request data packet sent by the first client, the second client can pass the cloud server. Acquire at least one public network address corresponding to the internal network address of the first client, and then return a response data packet to each of the at least one public network address corresponding to the internal network address of the first client.
  • the public network address includes a public network IP address and at least one public network port, and each of the at least one public network address corresponding to the internal network address of the second client The public network address sends an access request data packet, including:
  • the NAT type is a port restriction cone
  • the public network IP addresses included in the public network address and the at least two public network ports are respectively formed into at least two address-port pairs;
  • the access request packet is sent to each of the address-port pairs.
  • the NAT device maps the intranet address of the second client to multiple public addresses; that is, the second client may establish a connection with the first client through any one of the multiple public addresses. Therefore, when the first client determines that there are multiple public network addresses corresponding to the acquired internal network address of the second client, it needs to send an access request data packet to each of the multiple public network addresses.
  • each of the public addresses in the at least one public address corresponding to the acquired intranet address of the second client may also be Network address, determine the number of public network ports included in the public network address, if the public network address includes a public network port, directly include a public network IP address and a public network port in the public network address Form an address-port pair, and send an access request data packet to the address-port pair; if the public network address includes at least two public network ports, then one public network IP address included in the public network address is separated from at least two. The public network ports form at least two address-port pairs, and then the access request data packet is sent to each address-port pair.
  • obtaining at least one public network address corresponding to the intranet address of the second client through the cloud server includes:
  • At least one public network address corresponding to the intranet address of the second client that is returned by the cloud server in response to the request for assisting in establishing a connection is received.
  • the first client can send a request for assistance in establishing a connection to the cloud server, and the request for assisting in establishing a connection can carry the identifier of the second client.
  • the cloud server After receiving the request for assisting in establishing a connection, the cloud server returns the request to the first client. At least one public network address corresponding to the intranet address of the second client registered in the cloud server by the second client.
  • Step 108 Establish a P2P connection with the second client under the condition that the second client returns a response data packet to the target public network address within a preset time period, and the target public network address is the first client One of at least one public network address corresponding to the internal network address of the terminal.
  • the preset duration is the timeout duration, and the preset duration is within the timeout range, and the preset duration can be preset, such as 1 minute, 5 minutes, 10 minutes, and the like.
  • the response data packet is a hole punching data packet returned by the second client to the first first client, and is used to establish a P2P connection.
  • the second client listens to any public network address of its own and receives the access request data packet sent by the first client, the second client can obtain the information of the first client through the cloud server. at least one public network address corresponding to the internal network address, and a response data packet is returned to each of the at least one public network address corresponding to the internal network address of the first client. That is to say, the first client can monitor each public network address corresponding to its own intranet address, and if it monitors any public network address of its own and receives the response data packet returned by the second client, it means that the second client The access request data packet sent by the first client is successfully received, and the response data packet is successfully returned to the first client. At this time, the first client can establish a P2P connection with the second client.
  • the first client keeps monitoring at least one public network address corresponding to its own intranet address, a lot of processing resources will be wasted.
  • the public network address returns a response packet, it means that the second client fails to successfully receive the access request packet sent by the first client, or fails to return a response packet to the correct public network address of the first client, so it can A preset duration is set. If the preset duration is exceeded and the response data packet returned by the second client to any of its own public network addresses cannot be monitored, it means that the first client and the second client failed to establish a P2P connection. Stop listening.
  • FIG. 4 is a schematic diagram of establishing a P2P connection provided by an embodiment of the present application.
  • client A and client B each register with the cloud server at least one public network address determined with the help of an auxiliary node. , and then client A and client B exchange registration information, after that, client A sends several hole punching data packets according to the obtained at least one public network address of the opposite end; Public network address, returns several hole punching data packets, if the first client receives the hole punching data packets returned by the second client within the timeout range, it establishes a P2P connection with the second client, otherwise it is determined that the P2P connection establishment fails .
  • a first client can communicate with at least two auxiliary nodes, and obtain response messages returned by the at least two auxiliary nodes; and then, according to the response messages, determine the first client at least one public network address corresponding to the internal network address of the client, register at least one public network address corresponding to the internal network address of the first client with the cloud server, and monitor at least one public network address corresponding to the internal network address of the first client address, establish a P2P connection with the second client in the case of monitoring that the second client returns a response data packet to the target public network address, and the target public network address corresponds to the internal network address of the first client one of at least one public address of .
  • the first client can be used to communicate with at least two auxiliary nodes, and at least one public network address corresponding to the internal network address of the first client can be detected, so as to determine whether there are multiple external public network addresses of the first client. That is to say, at least two auxiliary nodes can be used to more accurately detect the public network address corresponding to the internal network address of the first client, which improves the success rate of hole punching among clients corresponding to multiple public network addresses, and achieves a relatively high level of accuracy. High success rate of P2P connection.
  • FIG. 5 shows a flowchart of another method for establishing a P2P connection provided by an embodiment of the present application, which specifically includes the following steps:
  • Step 502 the first client and the second client communicate with at least two auxiliary nodes respectively, and obtain the response messages returned by the at least two auxiliary nodes; according to the response messages, determine at least one corresponding to the respective intranet addresses Public network address; register at least one public network address corresponding to each intranet address with the cloud server, and monitor the at least one public network address.
  • the first client and the second client communicate with at least two auxiliary nodes respectively, and before acquiring the response messages returned by the at least two auxiliary nodes, the method further includes:
  • the first client and the second client communicate with the traversal auxiliary server respectively to obtain the respective intranet addresses and the NAT types of the respective NAT devices;
  • the first client and the second client store the respective intranet addresses and the NAT type of the corresponding NAT device locally.
  • the first client determines at least one public network address corresponding to its own intranet address according to the response message, and the specific implementation process may be as follows:
  • the NAT type of the NAT device corresponding to the first client is a port restriction cone
  • the second client determines that at least one public network address corresponding to its own intranet address is the same as the operation of the first client, as follows:
  • the NAT type of the NAT device corresponding to the second client is a port restriction cone
  • the first client and the second client respectively register at least one public network address corresponding to their respective intranet addresses with the cloud server, including:
  • At least one public network address corresponding to the respective intranet address and the NAT type of the respective corresponding NAT device are registered with the cloud server.
  • Step 504 The first client obtains at least one public network address corresponding to the intranet address of the second client through the cloud server, and sends each of the at least one public network address corresponding to the intranet address of the second client.
  • the public network address sends an access request data packet.
  • Step 506 In the case of monitoring that the target public network address of the second client receives the access request data packet, the second client obtains at least one public network address corresponding to the internal network address of the first client through the cloud server, and sends the data to the cloud server.
  • Each of the at least one public network address corresponding to the internal network address of the first client returns a response data packet
  • the target public network address is at least one public network address corresponding to the internal network address of the second client One of the public addresses.
  • Step 508 The first client establishes a P2P connection with the second client after monitoring that the second client returns a response data packet to its own target public network address, and the target public network address is the target public network address.
  • a first client can communicate with at least two auxiliary nodes, and obtain response messages returned by the at least two auxiliary nodes; and then, according to the response messages, determine the first client at least one public network address corresponding to the internal network address of the client, register at least one public network address corresponding to the internal network address of the first client with the cloud server, and monitor at least one public network address corresponding to the internal network address of the first client address, establish a P2P connection with the second client in the case of monitoring that the second client returns a response data packet to the target public network address, and the target public network address corresponds to the internal network address of the first client one of at least one public address of .
  • the first client can be used to communicate with at least two auxiliary nodes, and at least one public network address corresponding to the internal network address of the first client can be detected, so as to determine whether there are multiple external public network addresses of the first client. That is to say, at least two auxiliary nodes can be used to more accurately detect the public network address corresponding to the internal network address of the first client, which improves the success rate of hole punching among clients corresponding to multiple public network addresses, and achieves a relatively high level of accuracy. High success rate of P2P connection.
  • FIG. 6 shows a flowchart of another method for establishing a P2P connection provided by an embodiment of the present application, which specifically includes the following steps:
  • the complete process of establishing a P2P connection includes a NAT detection phase and a hole punching phase, wherein the NAT detection phase includes conventional NAT detection and NAT detection with the help of at least two auxiliary nodes, and the hole punching phase includes conventional hole punching and assistance. Node punching.
  • Step 602 The first client and the second client communicate with the hole punching server respectively, and obtain their respective intranet addresses, the first public address corresponding to the intranet addresses, and the NAT type of the corresponding NAT device; Register their respective first public network addresses, and exchange the peer's first public network addresses through the cloud server.
  • step 602 is that the first client and the second client respectively perform conventional NAT detection through the hole punching server, that is, the conventional detection stage.
  • Step 604 The first client and the second client respectively communicate with at least two auxiliary nodes through their respective intranet addresses, and obtain response messages returned by the at least two auxiliary nodes; and determine the respective auxiliary nodes according to the response messages. At least one second public network address corresponding to the intranet address.
  • the first client and the second client respectively perform NAT detection by using at least two auxiliary nodes.
  • Step 606 The first client and the second client respectively register at least one second public network address corresponding to their respective intranet addresses with the cloud server, and exchange at least one second public network address of the opposite end through the cloud server.
  • Step 608 The first client sends a hole punching data packet to the second client through the first public network address, and in the case of monitoring that the second client returns a response data packet to the first public network address within the timeout range, A P2P connection is established with the second client.
  • the first public network address is a public network address obtained through the hole punching server, that is, the first public network address is a conventionally detected public network address, so the above step 606 is a conventional hole punching operation.
  • Step 610 The first client sends a hole punching data packet to each of the at least one second public address of the second client, and monitors the second client to any of its own addresses within the timeout range.
  • the second public network address returns a response data packet, a P2P connection is established with the second client.
  • the second public network address is a public network address obtained with the help of at least two auxiliary nodes, so the above step 610 is an operation of punching holes with the help of the auxiliary nodes.
  • the method for establishing a P2P connection can further detect at least one public network address corresponding to the client's internal network address with the help of at least two auxiliary nodes on the basis of conventional detection, so as to determine whether the client's external public network address is There are more than one, that is, at least two auxiliary nodes can be used to more accurately detect the public network address corresponding to the internal network address of the client, which improves the success rate of hole punching between clients corresponding to multiple public network addresses, and achieves a relatively high performance. High success rate of P2P connection.
  • FIG. 7 shows a schematic structural diagram of a client provided by an embodiment of the present application.
  • the device includes:
  • a first obtaining module 702 configured to communicate with at least two auxiliary nodes, and obtain response messages returned by the at least two auxiliary nodes;
  • the determining module 704 is configured to determine, according to the response message, at least one public network address corresponding to the internal network address of the first client;
  • the monitoring module 706 is configured to register with the cloud server at least one public network address corresponding to the internal network address of the first client, and monitor at least one public network address corresponding to the internal network address of the first client;
  • the connection establishment module 708 is configured to establish a P2P connection with the second client when the second client returns a response data packet to the target public network address, and the target public network address is the first One of at least one public network address corresponding to the client's internal network address.
  • the device further includes:
  • the second acquisition module is configured to communicate with the traversal auxiliary server to acquire the intranet address and the NAT type of the corresponding NAT device;
  • the storage module is configured to store the intranet address and the NAT type of the corresponding NAT device locally.
  • the determining module 704 is further configured to:
  • the NAT type of the NAT device corresponding to the first client is a port restriction cone
  • the determining module 704 is further configured to:
  • the first public network port and the second public network port determine the start port identifier and the end port identifier
  • a public network port between the starting port identifier and the ending port identifier is determined as the estimated public network port.
  • the determining module 704 is further configured to:
  • the initial port identifier is obtained by subtracting the preset threshold from the port identifier of the second public network port.
  • the registration module 706 is further configured to:
  • At least one public network address corresponding to the internal network address of the first client and the NAT type of the corresponding NAT device are registered with the cloud server.
  • the first obtaining module 702 is further configured to:
  • a response message returned by the at least two assisting nodes in response to the assisting probe request is received.
  • the determining module 704 is further configured to:
  • auxiliary node For each auxiliary node in the at least two auxiliary nodes, determine the public network IP address corresponding to the response message returned by the auxiliary node;
  • the device further includes:
  • a third obtaining module is configured to obtain at least one public network address corresponding to the intranet address of the second client through the cloud server, and at least one public network address corresponding to the intranet address of the second client is the the public network address determined by the second client through the at least two auxiliary nodes;
  • the sending module is configured to send an access request data packet to each of the at least one public network address corresponding to the internal network address of the second client.
  • the public network address includes a public network IP address and at least one public network port; the sending module is further configured to:
  • the NAT type is a port restriction cone
  • the public network IP addresses included in the public network address and the at least two public network ports are respectively formed into at least two address-port pairs;
  • the access request packet is sent to each of the address-port pairs.
  • the third obtaining module is further configured to:
  • At least one public network address corresponding to the intranet address of the second client that is returned by the cloud server in response to the request for assisting in establishing a connection is received.
  • the client provided by the present application can communicate with at least two auxiliary nodes, and obtain response messages returned by the at least two auxiliary nodes; and then, according to the response messages, determine at least one corresponding to the intranet address of the first client public network address, register at least one public network address corresponding to the internal network address of the first client with the cloud server, and monitor at least one public network address corresponding to the internal network address of the first client, when monitoring the second client
  • the terminal returns a response data packet to the target public network address, establishes a P2P connection with the second client, and the target public network address is one of at least one public network address corresponding to the internal network address of the first client .
  • the first client can be used to communicate with at least two auxiliary nodes, and at least one public network address corresponding to the internal network address of the first client can be detected, so as to determine whether there are multiple external public network addresses of the first client. That is to say, at least two auxiliary nodes can be used to more accurately detect the public network address corresponding to the internal network address of the first client, which improves the success rate of hole punching among clients corresponding to multiple public network addresses, and achieves a relatively high level of accuracy. High success rate of P2P connection.
  • the above is a schematic solution of a client according to this embodiment. It should be noted that the technical solution of the client and the technical solution of the above-mentioned method for establishing a P2P connection belong to the same concept, and the details that are not described in detail in the technical solution of the client can be referred to the description of the technical solution of the above-mentioned method for establishing a P2P connection .
  • FIG. 8 shows a schematic structural diagram of a system for establishing a P2P connection provided by an embodiment of the present application.
  • the system includes: a first client 802 and a second client 804;
  • the first client 802 and the second client 804 are configured to communicate with at least two auxiliary nodes respectively, and obtain response messages returned by the at least two auxiliary nodes; according to the response messages, determine the correspondence between the respective intranet addresses at least one public network address; register at least one public network address corresponding to each intranet address with the cloud server, and monitor the at least one public network address;
  • the first client 802 is further configured to obtain at least one public network address corresponding to the intranet address of the second client through the cloud server, and send at least one public address corresponding to the intranet address of the second client.
  • Each of the public network addresses in the network addresses sends an access request data packet;
  • the second client 804 is further configured to obtain at least one corresponding to the intranet address of the first client through the cloud server in the case of monitoring that the target public address of the client receives the access request data packet.
  • public network address returning a response data packet to each of the at least one public network address corresponding to the internal network address of the first client, and the target public network address is the internal network of the second client One of at least one public network address corresponding to the address;
  • the first client 802 is further configured to establish a P2P connection with the second client in the case of monitoring that the second client returns a response data packet to the target public network address of the second client, the target
  • the public network address is one of at least one public network address corresponding to the internal network address of the first client.
  • first client 802 and the second client 804 are further configured to:
  • first client 802 and the second client 804 are further configured to:
  • At least one public network address corresponding to the respective intranet address and the NAT type of the respective corresponding NAT device are registered with the cloud server.
  • the system for establishing a P2P connection can communicate with at least two auxiliary nodes to obtain response messages returned by the at least two auxiliary nodes; and then, according to the response messages, determine the intranet address of the first client
  • the corresponding at least one public network address register at least one public network address corresponding to the internal network address of the first client with the cloud server, and monitor at least one public network address corresponding to the internal network address of the first client.
  • the target public network address is at least one public address corresponding to the internal network address of the first client. one of the web addresses.
  • the first client can be used to communicate with at least two auxiliary nodes, and at least one public network address corresponding to the internal network address of the first client can be detected, so as to determine whether there are multiple external public network addresses of the first client. That is to say, at least two auxiliary nodes can be used to more accurately detect the public network address corresponding to the internal network address of the first client, which improves the success rate of hole punching among clients corresponding to multiple public network addresses, and achieves a relatively high level of accuracy. High success rate of P2P connection.
  • the above is a schematic solution of a system for establishing a P2P connection according to this embodiment. It should be noted that the technical solution of the system for establishing a P2P connection and the technical solution of the above-mentioned method for establishing a P2P connection belong to the same concept. A description of the technical solution of the method of connection.
  • FIG. 9 shows a structural block diagram of a computing device 900 according to an embodiment of the present application.
  • Components of the computing device 900 include, but are not limited to, memory 910 and processor 920 .
  • the processor 920 is connected with the memory 910 through the bus 930, and the database 950 is used for saving data.
  • Computing device 900 also includes access device 940 that enables computing device 900 to communicate via one or more networks 960 .
  • networks include a public switched telephone network (PSTN), a local area network (LAN), a wide area network (WAN), a personal area network (PAN), or a combination of communication networks such as the Internet.
  • Access device 940 may include one or more of any type of network interface (eg, network interface card (NIC)), wired or wireless, such as IEEE 802.11 wireless local area network (WLAN) wireless interface, World Interoperability for Microwave Access ( Wi-MAX) interface, Ethernet interface, Universal Serial Bus (USB) interface, cellular network interface, Bluetooth interface, Near Field Communication (NFC) interface, and the like.
  • NIC network interface card
  • the above-mentioned components of the computing device 900 and other components not shown in FIG. 9 may also be connected to each other, eg, through a bus. It should be understood that the structural block diagram of the computing device shown in FIG. 9 is only for the purpose of example, rather than limiting the scope of the present application. Those skilled in the art can add or replace other components as required.
  • Computing device 900 may be any type of stationary or mobile computing device, including mobile computers or mobile computing devices (eg, tablet computers, personal digital assistants, laptops, notebook computers, netbooks, etc.), mobile phones (eg, smart phones) ), wearable computing devices (eg, smart watches, smart glasses, etc.) or other types of mobile devices, or stationary computing devices such as desktop computers or PCs.
  • Computing device 900 may also be a mobile or stationary server.
  • the processor 920 is configured to execute the following computer-executable instructions:
  • the response message determine at least one public network address corresponding to the internal network address of the first client
  • Register at least one public network address corresponding to the intranet address of the first client with the cloud server, and monitor at least one public network address corresponding to the intranet address of the first client;
  • the above is a schematic solution of a computing device according to this embodiment. It should be noted that the technical solution of the computing device and the technical solution of the above-mentioned method for establishing a P2P connection belong to the same concept, and the details that are not described in detail in the technical solution of the computing device can be referred to the above-mentioned technical solution of the method for establishing a P2P connection. description of.
  • An embodiment of the present application further provides a computer-readable storage medium, which stores computer instructions, and when the instructions are executed by a processor, is used for:
  • the response message determine at least one public network address corresponding to the internal network address of the first client
  • Register at least one public network address corresponding to the intranet address of the first client with the cloud server, and monitor at least one public network address corresponding to the intranet address of the first client;
  • the above is a schematic solution of a computer-readable storage medium of this embodiment. It should be noted that the technical solution of the storage medium and the technical solution of the above-mentioned method for establishing a P2P connection belong to the same concept, and the details that are not described in detail in the technical solution of the storage medium can be referred to the above-mentioned technical solution of the method for establishing a P2P connection. description of.
  • An embodiment of the present application also provides a computer program product, which, when the computer program product is executed in a computer, causes the computer to execute any of the steps of the above-mentioned method for establishing a P2P connection.
  • the computer-executable instructions include computer program code, which may be in source code form, object code form, an executable file, some intermediate form, or the like.
  • the computer-readable storage medium may include: any entity or device capable of carrying the computer program code, a recording medium, a U disk, a removable hard disk, a magnetic disk, an optical disk, a computer memory, a read-only memory (ROM, Read-Only Memory) ), random access memory (RAM, Random Access Memory), electrical carrier signals, telecommunication signals, and software distribution media, etc.
  • computer-readable Storage media exclude electrical carrier signals and telecommunications signals.

Landscapes

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

Abstract

本申请提供建立P2P连接的方法、客户端及系统,其中所述建立P2P连接的方法包括:与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网地址;向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址;在预设时长内监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接。如此,可以利用至少两个辅助节点更加准确的探测出客户端的内网地址对应的至少一个公网地址,提高了对应有多公网地址的客户端之间的打洞成功率,实现较高成功率的P2P建连。

Description

建立P2P连接的方法、客户端及系统
本申请要求于2021年1月6日提交中国专利局、申请号为202110011856.9、发明名称为“建立P2P连接的方法、客户端及系统”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请实施例涉及互联网技术领域,特别涉及一种建立P2P连接的方法。本申请一个或者多个实施例同时涉及一种客户端及建立P2P连接的系统,一种计算设备,一种计算机可读存储介质,以及一种计算机程序产品。
背景技术
随着互联网技术的快速发展,接入到互联网中的客户端的数量迅速增加,为了便于客户端的互联,每个客户端都可以拥有自身的公网地址,但是,随着在线客户端的数量急剧增加,可分配的公网地址数量严重不足。为了解决公网地址紧缺的问题,互联网中引入了NAT(Network Address Translation,网络地址转换)技术。
NAT技术是一种把内部网络私有网络地址转换为外部网络的公网地址的技术,NAT设备内部有一张映射表,这个表存储了内网到外网的映射关系,凡是由内网经过NAT设备对外发送的报文,都会使NAT设备的映射表添加一项内网到外网的映射关系。以后凡是从外网发送的报文,都会检查映射表,如果存在,则将该报文的外网地址替换为内网地址。
然而,实际的网络环境复杂多变,一个体系庞大的局域网下往往有多个通往外界的公网地址,这些公网地址都是通过动态配置而得,并且每个公网地址又对应着多个端口号,从而导致多公网地址的NAT设备之间的打洞较难实现,这些无疑都给实现P2P(peer to peer,端到端)的直接通信建连带来了阻碍。
发明内容
有鉴于此,本申请实施例提供了一种建立P2P连接的方法。本申请一个或者多个实施例同时涉及一种客户端及建立P2P连接的系统,一种计算设备,一种计算机可读存储介质,以及一种计算机程序产品,以解决现有技术中存在的技术缺陷。
根据本申请实施例的第一方面,提供了一种建立P2P连接的方法,应用于第一客户端,包括:
与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;
根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网地址;
向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址;
在监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。
根据本申请实施例的第二方面,提供了一种建立P2P连接的方法,包括:
第一客户端和第二客户端分别与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;根据所述应答消息,确定各自的内网地址对应的至少一个公网地址;向云服务器登记各自的内网地址对应的至少一个公网地址,并监听所述至少一个公网地址;
所述第一客户端通过所述云服务器获取所述第二客户端的内网地址对应的至少一个公网地址,向所述第二客户端的内网地址对应的至少一个公网地址中的每个所述公网地址发送访问请求数据包;
所述第二客户端在监听到自身的目标公网地址接收到访问请求数据包的情况下,通过所述云服务器获取所述第一客户端的内网地址对应的至少一个公网地址,向所述第一客户端的内网地址对应的至少一个公网地址中的每个所述公网地址返回响应数据包,所述目标公网地址为所述第二客户端的内网地址对应的至少一个公网地址之一;
所述第一客户端在监听到所述第二客户端向自身的目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。
根据本申请实施例的第三方面,提供了一种客户端,包括:
第一获取模块,被配置为与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;
确定模块,被配置为根据所述应答消息,确定第一客户端的内网地址对应的至少一个公网地址;
监听模块,被配置为向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址;
建联模块,被配置为在监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客 户端的内网地址对应的至少一个公网地址之一。
根据本申请实施例的第四方面,提供了一种建立P2P连接的系统,包括:
第一客户端和第二客户端,被配置为分别与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;根据所述应答消息,确定各自的内网地址对应的至少一个公网地址;向云服务器登记各自的内网地址对应的至少一个公网地址,并监听所述至少一个公网地址;
所述第一客户端,进一步被配置为通过所述云服务器获取所述第二客户端的内网地址对应的至少一个公网地址,向所述第二客户端的内网地址对应的至少一个公网地址中的每个所述公网地址发送访问请求数据包;
所述第二客户端,进一步被配置为在监听到自身的目标公网地址接收到访问请求数据包的情况下,通过所述云服务器获取所述第一客户端的内网地址对应的至少一个公网地址,向所述第一客户端的内网地址对应的至少一个公网地址中的每个所述公网地址返回响应数据包,所述目标公网地址为所述第二客户端的内网地址对应的至少一个公网地址之一;
所述第一客户端,进一步被配置为在监听到所述第二客户端向自身的目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。
根据本申请实施例的第五方面,提供了一种计算设备,包括:
存储器和处理器;
所述存储器用于存储计算机可执行指令,所述处理器用于执行所述计算机可执行指令,以实现下述方法:
与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;
根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网地址;
向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址;
在监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。
根据本申请实施例的第六方面,提供了一种计算机可读存储介质,其存储有计算机可执行指令,该指令被处理器执行时实现任意上述第一方面所述的建立P2P连接的方法的步骤。
根据本申请实施例的第七方面,提供了一种计算机程序产品,当所述计算机程序产品在计算机中执行时,令计算机执行任意上述建立P2P连接的方法的步骤。
本申请提供的建立P2P连接的方法,第一客户端可以与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;然后,根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网地址,向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址,在监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。这种情况下,可以利用第一客户端与至少两个辅助节点通信,探测出第一客户端的内网地址对应的至少一个公网地址,以确定第一客户端对外的公网地址是否有多个,也即可以利用至少两个辅助节点更加准确的探测出第一客户端的内网地址对应的公网地址,提高了对应有多公网地址的客户端之间的打洞成功率,实现较高成功率的P2P建连。
附图说明
图1是本申请一实施例提供的一种建立P2P连接的方法的流程图;
图2是本申请一实施例提供的一种常规NAT探测的示意图;
图3是本申请一实施例提供的一种公网地址的示意图;
图4是本申请一实施例提供的一种建立P2P连接的示意图;
图5是本申请一实施例提供的另一种建立P2P连接的方法的流程图;
图6是本申请一实施例提供的另一种建立P2P连接的方法的流程图
图7是本申请一实施例提供的一种客户端的结构示意图;
图8是本申请一实施例提供的一种建立P2P连接的系统的结构示意图;
图9是本申请一实施例提供的一种计算设备的结构框图。
具体实施方式
在下面的描述中阐述了很多具体细节以便于充分理解本申请。但是本申请能够以很多不同于在此描述的其它方式来实施,本领域技术人员可以在不违背本申请内涵的情况下做类似推广,因此本申请不受下面公开的具体实施的限制。
在本申请一个或多个实施例中使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本申请一个或多个实施例。在本申请一个或多个实施例和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包 括多数形式,除非上下文清楚地表示其他含义。还应当理解,本申请一个或多个实施例中使用的术语“和/或”是指并包含一个或多个相关联的列出项目的任何或所有可能组合。
应当理解,尽管在本申请一个或多个实施例中可能采用术语第一、第二等来描述各种信息,但这些信息不应限于这些术语。这些术语仅用来将同一类型的信息彼此区分开。例如,在不脱离本申请一个或多个实施例范围的情况下,第一也可以被称为第二,类似地,第二也可以被称为第一。取决于语境,如在此所使用的词语“如果”可以被解释成为“在……时”或“当……时”或“响应于确定”。
首先,对本申请一个或多个实施例涉及的名词术语进行解释。
IP地址(Internet Protocol Address,互联网协议地址):又译为网际协议地址,IP地址是IP协议提供的一种统一的地址格式,它为互联网上的每一个网络和每一台主机分配一个逻辑地址,以此来屏蔽物理地址的差异。
NAT(Network Address Translation,网络地址转换):在专用网内部的一些主机本来已经分配到了本地IP地址(即仅在本专用网内使用的专用地址),但又想和因特网上的主机通信(并不需要加密)时,可使用NAT方法。这种方法至少有一个有效的外部全球IP地址,即公网地址。这样,所有使用本地地址的主机在和外界通信时,都要在NAT设备上将其本地地址转换成公网地址,才能和因特网连接。
按照功能,NAT设备可以分为三类,包括静态NAT、动态NAT以及端NAPT(Network Address Port Translation)。静态NAT转换较为简单,动态NAT是指不建立内部地址和全局地址的一对一的固定对应关系,而通过共享NAT地址池的IP地址动态建立NAT的映射关系。NATP是最常见的NAT,也是学术界研究最多的NAT类型。NATP将内网连接映射到外部网络中的一个单独IP地址上,同时在该地址上加上一个由NAT设备选定的端口号,共分为四种类型,包括全锥型、IP受限锥型、端口受限锥型和对称型。
全锥形NAT:一旦内部主机端口对(iAddr:iPort)被NAT网关映射到(eAddr:ePort),所有后续的(iAddr:iPort)报文都会被转换为(eAddr:ePort);任何一个外部主机发送到(eAddr:ePort)的报文将会被转换后发到(iAddr:iPort)。
IP限制锥形NAT:一旦内部主机端口对(iAddr:iPort)被映射到(eAddr:ePort),所有后续的(iAddr:iPort)报文都会被转换为(eAddr:ePort);只有(iAddr:iPort)向特定的外部主机hAddr发送过数据,主机hAddr从任意端口发送到(eAddr:ePort)的报文将会被转发到(iAddr:iPort)。
端口限制锥形NAT:一旦内部主机端口对(iAddr:iPort)被映射到(eAddr:ePort),所有后续的(iAddr:iPort)报文都会被转换为(eAddr:ePort);只有(iAddr:iPort)向特定的外部主机端口对(hAddr:hPort)发送过数据,由(hAddr:hPort)发送到(eAddr:ePort)的报文将会被转发到(iAddr:iPort)。
对称型NAT:NAT网关会把内部主机“地址端口对”和外部主机“地址端口对”完全相同的报文看作一个连接,在网关上创建一个公网“地址端口对”映射进行转换,只有收到报文的外部主机从对应的端口对发送回应的报文,才能被转换,即使内部主机使用之前用过的地址端口对去连接不同外部主机(或端口)时,NAT网关也会建立新的映射关系。
打洞服务器:即STUN服务器,用户数据报协议(UDP)简单穿越网络地址转换器(NAT),它允许所有的NAT设备对应的客户端(如防火墙后边的计算机)与位于局部区域网以外的VOIP服务商实现电话通话。通过STUN服务器,客户端可以了解他们的公网地址、挡在他们前面的NAT类型和通过NAT与特定局部端口相连的因特网方端口。这些信息将被用于建立客户端与VOIP服务商之间的UDP通信,以便实现通话。
在本申请中,提供了一种建立P2P连接的方法,本申请同时涉及一种客户端及建立P2P连接的系统,一种计算设备,一种计算机可读存储介质,以及一种计算机程序产品,在下面的实施例中逐一进行详细说明。
图1示出了根据本申请一实施例提供的一种建立P2P连接的方法的流程图,应用于第一客户端,具体包括以下步骤:
步骤102:与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息。
实际应用中,实际的网络环境复杂多变,一个体系庞大的局域网下往往有多个通往外界的公网地址,这些公网地址都是通过动态配置而得,并且每个公网地址又对应着多个端口号,从而导致多公网地址的NAT设备之间的打洞较难实现,这些无疑都给实现P2P(peer to peer,端到端)的直接通信建连带来了阻碍。
因而,本申请中提供了一种建立P2P连接的方法,第一客户端可以与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;然后,根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网地址,向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址;在监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述 目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。这种情况下,可以利用第一客户端与至少两个辅助节点通信,探测出第一客户端的内网地址对应的公网地址是否有多个,也即可以利用至少两个辅助节点更加准确的探测出第一客户端的内网地址对应的公网地址,从而提高对应有多公网地址的客户端之间的打洞成功率,实现较高成功率的P2P建连。
具体的,辅助节点可以是全锥形NAT设备,或者公网节点,使得其他类型的节点都可以与辅助节点建立连接,从而探测公网地址,其中,该公网地址可以包括公网IP地址和公网端口。具体实现时,第一客户端可以从云服务器中获取所述至少两个辅助节点,所述云服务器即为节点调度服务器,所有节点和云服务器保持信令交互。需要说明的是,辅助节点的数量越多,探测出的公网地址就越全面,越准确,本申请中不对辅助节点的数量进行限制,实际应用中可以根据具体需求进行设置。
需要说明的是,第一客户端包括等待建立P2P连接的终端设备和对应的NAT设备,该终端设备通过对应的NAT设备和外界进行交互,NAT设备可以将该终端设备的内网地址转换成对外的公网地址,从而和外界进行交互。
另外,需要与第一客户端建立P2P连接的第二客户端,可以和第一客户端执行相同的操作。即第二客户端也可以与所述至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息,从而确定出第二客户端的内网地址对应的至少一个公网地址,便于后续与第一客户端的内网地址对应的至少一个公网地址进行交换,以与第一客户端建立P2P连接。
本实施例一个可选的实施方式中,第一客户端在借助辅助节点探测对应的公网地址之前,还可以通过穿越辅助服务器进行探测,获取第一客户端对应的NAT设备的NAT类型,因而第一客户端与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息之前,还包括:
与所述穿越辅助服务器通信,获取所述内网地址以及对应的NAT设备的NAT类型;
将所述内网地址以及对应的NAT设备的NAT类型存储至本地。
需要说明的是,穿越辅助服务器是指打洞服务器,即STUN服务器。NAT设备的公网地址探测分为常规NAT探测和借助辅助节点的NAT探测,常规NAT探测是指第一客户端和穿越辅助服务器通信,可以获得当前用于通信的内网和公网地址对(IP_A,Port_A:IP_A’,Port_A’),初步确定NAT类型。
本实施例一个可选的实施方式中,与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息,具体实现过程可以如下:
通过所述第一客户端的内网地址向所述至少两个辅助节点发送协助探测请求;
接收所述至少两个辅助节点响应于所述协助探测请求返回的应答消息。
需要说明的是,作为对常规NAT探测的补充,可以进一步借助辅助节点进行探测,第一客户端首先可以从云服务器中随机获取到分布在不同位置的至少两个辅助节点;然后让第一客户端使用之前和打洞服务器通信的内网地址(IP_A,Port_A)与获取到的辅助节点通信,当第一客户端接收到这些辅助节点的应答信息后,可以记录下与这些辅助节点建连的公网IP地址和公网端口(即公网地址)。
示例的,图2是本申请一实施例提供的一种常规NAT探测的示意图,如图2所示,客户端A通过内网IP地址、内网端口(IP_A:Port_A),经对应的NAT设备A,转换为公网IP地址、公网端口(IP_A′:Port_A′)和打洞服务器通信,在打洞服务器中登记自身NAT设备类型和对应的公网IP地址、公网端口。相应的,客户端B通过内网IP地址、内网端口(IP_B:Port_B),经对应的NAT设备B,转换为公网IP地址、公网端口(IP_B′:Port_B′)和打洞服务器通信,在打洞服务器中登记自身NAT设备类型和对应的公网IP地址、公网端口。
步骤104:根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网地址。
具体的,在与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息的基础上,进一步的,将根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网地址。其中,公网地址可以包括公网IP地址和公网端口。
需要说明的是,根据所述应答消息,确定所述第一客户端的内网地址对应的公网地址大致分为三种情形:情形1,公网IP地址不同,对应的内网到公网的端口映射一定;情形2,和不同辅助节点通信时,端口会在原位置上下小范围变化;情形3,公网IP地址有多个,并且通过公网IP地址的端口也会发生变化。
示例的,图3是本申请一实施例提供的一种公网地址的示意图,如图3所示,客户端A通过内网地址(IP_A:Port_A)分别与辅助节点D、E、F、G、 H通信,根据各个辅助节点返回的应答消息可知,与辅助节点D、E、F通信的公网IP地址为IP_A1′,与辅助节点G、H通信的公网IP地址为IP_A2′,也即,客户端A对应的NAT设备A将客户端A的内网IP地址IP_A映射为公网IP地址IP_A1′或IP_A2′(不限制端口)。
若客户端A对应的NAT设备A为端口限制锥形,则客户端A通过内网地址(IP_A:Port_A)分别与辅助节点D、E、F、G、H通信,根据各个辅助节点返回的应答消息可知,与辅助节点D、E、F通信的公网IP地址为IP_A1′,且与辅助节点D、E通信的公网端口为Port_A1′,与辅助节点F通信的公网端口为Port_A2′;与辅助节点G、H通信的公网IP地址均为IP_A2′,公网端口均为Port_A3′。也即,客户端A对应的NAT设备A将客户端A的内网地址(IP_A:Port_A)映射为公网地址(IP_A1′:Port_A1′)、(IP_A1′:Port_A2′)或(IP_A2′:Port_A3′)。
若客户端B对应的NAT设备为端口限制锥形,则客户端B通过内网地址(IP_B:Port_B)分别与辅助节点D、E、F、G、H通信,根据各个辅助节点返回的应答消息可知,与辅助节点D、E、F、G、H通信的公网IP地址均为IP_B′,但是与辅助节点D、E、F、G通信的公网端口为Port_B1′,与辅助节点H通信的公网端口为Port_B2′,也即,客户端B对应的NAT设备B将客户端B的内网地址(IP_B:Port_B)映射为公网地址(IP_B′;Port_B1′)或(IP_B′;Port_B2′)。
本实施例一个可选的实施方式中,根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网地址,具体实现过程可以为:
在所述第一客户端对应的NAT设备的NAT类型为端口限制锥形的情况下,根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网IP地址;
针对所述至少一个公网IP地址中的每个所述公网IP地址,确定所述公网IP地址对应的至少一个公网端口;根据所述至少一个公网端口,确定所述公网IP地址对应的预估公网端口;将所述预估公网端口和所述公网IP地址组合为所述公网地址。
需要说明的是,如果第一客户端对应的NAT设备的NAT类型为端口限制锥形,则说明第一客户端在通过对应的NAT设备和外界交互时,会对端口进行限制,因而针对每个公网IP地址,需要确定出其对应的至少一个公网端口,然后将该公网IP地址和对应的至少一个公网端口确定为一个公网地址,从而得到至少一个公网地址,后续可以根据该至少一个公网地址发送访问请求数据 包,建立P2P连接。
本实施例一个可选的实施方式中,所述根据所述至少一个公网端口,确定所述公网IP地址对应的预估公网端口,具体实现过程可以如下:
确定所述至少一个公网端口中端口标识最大的第一公网端口,以及端口标识最小的第二公网端口;
根据所述第一公网端口和所述第二公网端口,确定起始端口标识和终止端口标识;
将所述起始端口标识和所述终止端口标识之间的公网端口确定为所述预估公网端口。
本实施例一个可选的实施方式中,所述根据所述第一公网端口和所述第二公网端口,确定起始端口标识和终止端口标识,具体实现过程可以如下:
将所述第一公网端口的端口标识加上预设阈值,得到所述终止端口标识;
将所述第二公网端口的端口标识减去所述预设阈值,得到所述起始端口标识。
具体的,预设阈值可以预先进行设置,如可以为20、30、40等。
需要说明的是,由于辅助节点的个数有限,借助辅助节点很难确定出第一客户端的公网IP地址对应的全部公网端口,因而在借助辅助节点确定出公网IP地址对应的至少一个公网端口后,还可以根据确定出至少一个公网端口对该公网IP地址对应的其他公网端口进行预测,从而确定出预估公网端口,作为第一客户端的内网地址对应的公网地址。
另外,由于借助辅助节点确定出的至少一个公网端口只是第一客户端和相应辅助节点交互时使用的公网端口,这些公网端口附近的公网端口也可能是后续进行打洞操作的公网端口,因而可以根据辅助节点返回的至少一个公网端口,确定出起始端口标识和终止端口标识,然后将起始端口标识和终止端口标识之间连续的端口确定为该公网IP地址对应的预估公网端口,进而确定出对应的公网地址。
示例的,假设第一客户端借助至少两个辅助节点确定出的公网IP地址为IP_A、IP_B和IP_C。针对IP_A,假设借助辅助节点确定出的对应的公网端口为1121端口、1123端口和1125端口,预设阈值为20,那么起始端口标识1101,终止端口标识为1145,此时将1101~1145之间的端口,确定为预估公网端口,然后将IP_A和1101~1145之间的端口确定为一个公网地址。针对IP_B和IP_C执行上述相同的操作,可以分别得到IP_B和IP_C对应的公网地址,从而最终 得到第一客户端的内网地址对应的3个公网地址。
本实施例一个可选的实施方式中,根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网IP地址,包括:
针对所述至少两个辅助节点中的每个辅助节点,确定所述辅助节点返回的应答消息对应的公网IP地址;
对所述应答消息对应的公网IP地址进行去重操作,确定出所述第一客户端的内网地址对应的至少一个公网IP地址。
实际应用中,当第一客户端(或第二客户端)接收到这些辅助节点的应答信息后,可以记录下与这些辅助节点建连的公网IP地址,然后对获取到的一系列公网IP地址进行分析,若所有的公网IP地址都显示为同一个,则和常规NAT探测的结果相同,即第一客户端(或第二客户端)对应的NAT设备将第一客户端的内网地址映射为一个公网IP地址,第一客户端后续通过该公网IP地址和其他客户端建立连接。
如果根据所述应答消息,确定所述第一客户端的内网地址对应的公网IP地址有多个(即获取到的公网IP地址不相同),即第一客户端(或第二客户端)对应的NAT设备将第一客户端的内网地址映射为多个公网IP地址,则此时可以将对应的多个公网IP地址记录到本地客户端的数据结构中。也就是说,对所述应答消息对应的公网IP地址进行去重操作,确定出所述第一客户端的内网地址对应的至少一个公网IP地址。
另外,如果第一客户端对应的NAT设备的NAT类型不为端口限制锥形,则说明第一客户端对应的NAT设备对端口没有限制,只需要根据至少两个辅助节点返回的应答消息,对公网IP地址进行去重,得到公网地址即可,无需进一步确定公网端口。
本申请中第一客户端和第二客户端可以分别与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息,从而确定出各自对应的NAT设备的公网IP地址和公网端口(即公网地址);也即,可以利用至少两个辅助节点更加准确的探测出第一客户端和第二客户端各自的内网地址对应的多个公网地址和公网端口,从而提高对应有多公网地址的客户端之间的打洞成功率,实现较高成功率的P2P建连。
步骤106:向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址。
具体的,在根据所述应答消息,确定所述第一客户端的内网地址对应的至 少一个公网地址的基础上,进一步的,可以向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址。其中,云服务器为管控所述至少两个辅助节点的服务器。
本实施例一个可选的实施方式中,所述向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,包括:
向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址以及所述对应的NAT设备的NAT类型。
需要说明的是,由于不同类型的NAT设备对端口的要求不同,因而第一客户端还可以通过穿越辅助服务器(即打洞服务器)探测自身的NAT设备类型,然后登记到云服务器中,供第二客户端获取。相应的,第二客户端可以执行和第一客户端相同的操作,将其自身的NAT类型也登记到云服务器上,供第一客户端获取。
也就是说,第一客户端和第二服务器可以分别借助至少两个辅助节点进行NAT探测后,可以得到内网地址对应的每个公网IP地址、每个公网端口以及对应的NAT类型,并以数据流的形式登记到云服务器上,通过云服务器和对端交换各自的登记信息,从而便于第一客户端获取到第二客户端的公网IP地址和公网端口,从而建立P2P连接。
需要说明的是,需要与第一客户端建立P2P连接的第二客户端,可以和第一客户端执行相同的操作。即,第二客户端也可以执行上述步骤102-106所述的步骤,从而确定出第二客户端的内网地址对应的至少一个公网地址和NAT类型,并在云服务器上进行登记,便于后续与第一客户端的内网地址对应的至少一个公网地址和NAT类型进行交换,以与第一客户端建立P2P连接。
本实施例一个可选的实施方式中,第一客户端和第二客户端分别向云服务器登记各自的内网地址对应的至少一个公网地址之后,第一客户端就可以从所述云服务器中获取第二客户端的内网地址对应的至少一个公网地址,以与第二客户端建立P2P连接,也即向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址之后,还包括:
通过所述云服务器获取所述第二客户端的内网地址对应的至少一个公网地址,所述第二客户端的内网地址对应的至少一个公网地址为所述第二客户端通过所述至少两个辅助节点确定出的公网地址;
向所述第二客户端的内网地址对应的至少一个公网地址中的每个所述公网地址发送访问请求数据包。
具体的,访问请求数据包可以是指打洞数据包。另外,第一客户端从云服务器中获取到的第二客户端的内网地址对应的至少一个公网地址即为第二客户端通过上述步骤102-106的方法步骤,借助辅助节点确定出的公网地址。
需要说明的是,第一客户端通过所述云服务器获取所述第二客户端的内网地址对应的至少一个公网地址之后,就可以向所述第二客户端的内网地址对应的至少一个公网地址中的每个所述公网地址发送访问请求数据包。相应的,第二客户端可以监听自身的各个公网地址,如果监听到自身的任一公网地址接收到第一客户端发送的访问请求数据包,则第二客户端可以通过所述云服务器获取所述第一客户端的内网地址对应的至少一个公网地址,然后向所述第一客户端的内网地址对应的至少一个公网地址中的每个所述公网地址返回响应数据包。
本实施例一个可选的实施方式中,公网地址包括一个公网IP地址和至少一个公网端口,所述向所述第二客户端的内网地址对应的至少一个公网地址中的每个所述公网地址发送访问请求数据包,包括:
通过所述云服务器获取所述第二客户端对应的NAT设备的NAT类型;
在所述NAT类型为端口限制锥形的情况下,针对所述至少一个公网地址中的每个所述公网地址,确定所述公网地址包括的公网端口的个数;
在所述公网地址包括至少两个公网端口的情况下,将所述公网地址包括的公网IP地址分别和所述至少两个公网端口组成至少两个地址端口对;
向每个所述地址端口对发送所述访问请求数据包。
实际应用中,如果获取到的第二客户端的内网地址对应的公网地址有多个,则说明第二客户端借助辅助节点确定出的公网地址有多个,即第二客户端对应的NAT设备将第二客户端的内网地址映射为了多个公网地址;也就是说,第二客户端可能通过该多个公网地址中的任意一个公网地址和第一客户端建立连接。因而第一客户端在确定出获取到的第二客户端的内网地址对应的公网地址有多个时,需要向该多个公网地址中的每一个公网地址发送访问请求数据包。
另外,在第二客户端对应的NAT设备的NAT类型为端口限制锥形的情况下,还可以针对获取到的第二客户端的内网地址对应的至少一个公网地址中的每个所述公网地址,确定所述公网地址包括的公网端口的个数,若所述公网地址包括一个公网端口,则直接将该公网地址包括的一个该公网IP地址和该公网端口组成一个地址端口对,向该地址端口对发送访问请求数据包即可;若所述公网地址包括至少两个公网端口,则将该公网地址包括的一个公网IP地址 分别和至少两个公网端口组成至少两个地址端口对,然后向每个所述地址端口对发送所述访问请求数据包。
本实施例一个可选的实施方式中,通过所述云服务器获取所述第二客户端的内网地址对应的至少一个公网地址,包括:
向所述云服务器发送协助建联请求;
接收所述云服务器响应于所述协助建联请求返回的所述第二客户端的内网地址对应的至少一个公网地址。
需要说明的是,第一客户端可以向云服务器发送协助建联请求,该协助建联请求中可以携带第二客户端的标识,云服务器接收到该协助建联请求后,向第一客户端返回第二客户端在云服务器中登记的第二客户端的内网地址对应的至少一个公网地址。
步骤108:在预设时长内监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。
具体的,预设时长为超时时长,预设时长内即超时范围内,该预设时长可以预先设置,如1分钟、5分钟、10分钟等。响应数据包为第二客户端向第一第一客户端返回的打洞数据包,用于建立P2P连接。
需要说明的是,如果第二客户端监听到自身的任一公网地址接收到第一客户端发送的访问请求数据包,则第二客户端可以通过所述云服务器获取所述第一客户端的内网地址对应的至少一个公网地址,并向所述第一客户端的内网地址对应的至少一个公网地址中的每个所述公网地址返回响应数据包。也就是说,第一客户端可以监听自身的内网地址对应的各个公网地址,如果监听到自身的任一公网地址接收到第二客户端返回的响应数据包,则说明第二客户端成功接收到了第一客户端发送的访问请求数据包,且成功向第一客户端返回响应数据包,此时第一客户端可以与第二客户端建立P2P连接。
另外,如果第一客户端一直监听自身的内网地址对应的至少一个公网地址,那么会浪费大量的处理资源,如果第一客户端很长时间没有监听到第二客户端向自身的任一公网地址返回响应数据包,则说明第二客户端未能成功接收到第一客户端发送的访问请求数据包,或者未能向第一客户端正确的公网地址返回响应数据包,因而可以设置一个预设时长,如果超过了预设时长,未能监听到第二客户端向自身的任一公网地址返回响应数据包,则说明第一客户端和第二客户端建立P2P连接失败,停止监听。
示例的,图4是本申请一实施例提供的一种建立P2P连接的示意图,如图4所示,客户端A和客户端B各自分别向云服务器登记借助辅助节点确定的至少一个公网地址,然后客户端A和客户端B互换登记信息,之后,客户端A根据获取到的对端的至少一个公网地址,发送若干个打洞数据包;客户端B根据获取到的对端的至少一个公网地址,返回若干个打洞数据包,第一客户端如果在超时范围内接收到第二客户端返回的打洞数据包,则与第二客户端建立P2P连接,否则确定P2P建立连接失败。
本申请提供的建立P2P连接的方法,第一客户端可以与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;然后,根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网地址,向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址,在监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。这种情况下,可以利用第一客户端与至少两个辅助节点通信,探测出第一客户端的内网地址对应的至少一个公网地址,以确定第一客户端对外的公网地址是否有多个,也即可以利用至少两个辅助节点更加准确的探测出第一客户端的内网地址对应的公网地址,提高了对应有多公网地址的客户端之间的打洞成功率,实现较高成功率的P2P建连。
图5示出了本申请一实施例提供的另一种建立P2P连接的方法的流程图,具体包括以下步骤:
步骤502:第一客户端和第二客户端分别与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;根据所述应答消息,确定各自的内网地址对应的至少一个公网地址;向云服务器登记各自的内网地址对应的至少一个公网地址,并监听所述至少一个公网地址。
本实施例一个可选的实施方式中,所述第一客户端和第二客户端分别与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息之前,还包括:
所述第一客户端和所述第二客户端分别与穿越辅助服务器通信,获取各自内网地址以及各自对应的NAT设备的NAT类型;
所述第一客户端和所述第二客户端将各自内网地址以及对应的NAT设备的NAT类型存储至本地。
本实施例一个可选的实施方式中,所述第一客户端根据所述应答消息,确 定自身的内网地址对应的至少一个公网地址,具体实现过程可以如下:
在所述第一客户端对应的NAT设备的NAT类型为端口限制锥形的情况下,根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网IP地址;
针对所述至少一个公网IP地址中的每个所述公网IP地址,确定所述公网IP地址对应的至少一个公网端口;根据所述至少一个公网端口,确定所述公网IP地址对应的预估公网端口;将所述预估公网端口和所述公网IP地址组合为所述公网地址。
相应的,第二客户端根据所述应答消息,确定自身的内网地址对应的至少一个公网地址与第一客户端的操作相同,具体如下:
在所述第二客户端对应的NAT设备的NAT类型为端口限制锥形的情况下,根据所述应答消息,确定所述第二客户端的内网地址对应的至少一个公网IP地址;
针对所述至少一个公网IP地址中的每个所述公网IP地址,确定所述公网IP地址对应的至少一个公网端口;根据所述至少一个公网端口,确定所述公网IP地址对应的预估公网端口;将所述预估公网端口和所述公网IP地址组合为所述公网地址。
本实施例一个可选的实施方式中,所述第一客户端和第二客户端分别向云服务器登记各自的内网地址对应的至少一个公网地址,包括:
向云服务器登记各自的内网地址对应的至少一个公网地址以及各自对应的NAT设备的NAT类型。
步骤504:第一客户端通过所述云服务器获取所述第二客户端的内网地址对应的至少一个公网地址,向所述第二客户端的内网地址对应的至少一个公网地址中的每个所述公网地址发送访问请求数据包。
步骤506:第二客户端在监听到自身的目标公网地址接收到访问请求数据包的情况下,通过所述云服务器获取所述第一客户端的内网地址对应的至少一个公网地址,向所述第一客户端的内网地址对应的至少一个公网地址中的每个所述公网地址返回响应数据包,所述目标公网地址为所述第二客户端的内网地址对应的至少一个公网地址之一。
步骤508:第一客户端在监听到所述第二客户端向自身的目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。
本申请提供的建立P2P连接的方法,第一客户端可以与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;然后,根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网地址,向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址,在监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。这种情况下,可以利用第一客户端与至少两个辅助节点通信,探测出第一客户端的内网地址对应的至少一个公网地址,以确定第一客户端对外的公网地址是否有多个,也即可以利用至少两个辅助节点更加准确的探测出第一客户端的内网地址对应的公网地址,提高了对应有多公网地址的客户端之间的打洞成功率,实现较高成功率的P2P建连。
图6示出了本申请一实施例提供的另一种建立P2P连接的方法的流程图,具体包括以下步骤:
需要说明的是,建立P2P连接的完整过程包括NAT探测阶段和打洞阶段,其中,NAT探测阶段包括常规NAT探测和借助至少两个辅助节点进行NAT探测,打洞阶段包括常规打洞和借助辅助节点打洞。
步骤602:第一客户端和第二客户端分别与打洞服务器通信,获取各自的内网地址、该内网地址对应的第一公网地址以及对应的NAT设备的NAT类型;分别向云服务器登记各自的第一公网地址,并通过所述云服务器交换对端的第一公网地址。
需要说明的是,上述步骤602就是第一客户端和第二客户端分别通过打洞服务器进行常规NAT探测,即常规探测阶段。
步骤604:第一客户端和第二客户端分别通过各自的内网地址与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;并根据所述应答消息,确定各自的内网地址对应的至少一个第二公网地址。
需要说明的是,上述步骤604就是第一客户端和第二客户端分别借助至少两个辅助节点进行NAT探测。
步骤606:第一客户端和第二客户端分别向云服务器登记各自的内网地址对应的至少一个第二公网地址,并通过所述云服务器交换对端的至少一个第二公网地址。
步骤608:第一客户端通过所述第一公网地址向第二客户端发送打洞数据 包,在超时范围内监听到第二客户端向第一公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接。
需要说明的是,第一公网地址是通过打洞服务器获取到的公网地址,即第一公网地址是常规探测到的公网地址,因而上述步骤606就是常规打洞的操作。
步骤610:第一客户端向第二客户端的至少一个第二公网地址中的每个第二公网地址发送打洞数据包,在超时范围内监听到第二客户端向自身的任一第二公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接。
需要说明的是,第二公网地址是借助至少两个辅助节点获取到的公网地址,因而上述步骤610就是借助辅助节点打洞的操作。
本申请提供的建立P2P连接的方法,可以在常规探测的基础上借助至少两个辅助节点,进一步探测出客户端的内网地址对应的至少一个公网地址,以确定客户端对外的公网地址是否有多个,也即可以利用至少两个辅助节点更加准确的探测出客户端的内网地址对应的公网地址,提高了对应有多公网地址的客户端之间的打洞成功率,实现较高成功率的P2P建连。
与上述方法实施例相对应,本申请还提供了客户端实施例,图7示出了本申请一实施例提供的一种客户端的结构示意图。如图7所示,该装置包括:
第一获取模块702,被配置为与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;
确定模块704,被配置为根据所述应答消息,确定第一客户端的内网地址对应的至少一个公网地址;
监听模块706,被配置为向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址;
建联模块708,被配置为在监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。
可选地,所述装置还包括:
第二获取模块,被配置为与穿越辅助服务器通信,获取所述内网地址以及对应的NAT设备的NAT类型;
存储模块,被配置为将所述内网地址以及对应的NAT设备的NAT类型存储至本地。
可选地,确定模块704进一步被配置为:
在所述第一客户端对应的NAT设备的NAT类型为端口限制锥形的情况下,根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网IP地址;
针对所述至少一个公网IP地址中的每个所述公网IP地址,确定所述公网IP地址对应的至少一个公网端口;根据所述至少一个公网端口,确定所述公网IP地址对应的预估公网端口;将所述预估公网端口和所述公网IP地址组合为所述公网地址。
可选地,确定模块704进一步被配置为:
确定所述至少一个公网端口中端口标识最大的第一公网端口,以及端口标识最小的第二公网端口;
根据所述第一公网端口和所述第二公网端口,确定起始端口标识和终止端口标识;
将所述起始端口标识和所述终止端口标识之间的公网端口确定为所述预估公网端口。
可选地,确定模块704进一步被配置为:
将所述第一公网端口的端口标识加上预设阈值,得到所述终止端口标识;
将所述第二公网端口的端口标识减去所述预设阈值,得到所述起始端口标识。
可选地,登记模块706进一步被配置为:
向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址以及所述对应的NAT设备的NAT类型。
可选地,第一获取模块702进一步被配置为:
通过所述第一客户端的内网地址向所述至少两个辅助节点发送协助探测请求;
接收所述至少两个辅助节点响应于所述协助探测请求返回的应答消息。
可选地,确定模块704进一步被配置为:
针对所述至少两个辅助节点中的每个辅助节点,确定所述辅助节点返回的应答消息对应的公网IP地址;
对所述应答消息对应的公网IP地址进行去重操作,确定出所述第一客户端的内网地址对应的至少一个公网IP地址。
可选地,所述装置还包括:
第三获取模块,被配置为通过所述云服务器获取所述第二客户端的内网地址对应的至少一个公网地址,所述第二客户端的内网地址对应的至少一个公网地址为所述第二客户端通过所述至少两个辅助节点确定出的公网地址;
发送模块,被配置为向所述第二客户端的内网地址对应的至少一个公网地址中的每个所述公网地址发送访问请求数据包。
可选地,所述公网地址包括一个公网IP地址和至少一个公网端口;发送模块进一步被配置为:
通过所述云服务器获取所述第二客户端对应的NAT设备的NAT类型;
在所述NAT类型为端口限制锥形的情况下,针对所述至少一个公网地址中的每个所述公网地址,确定所述公网地址包括的公网端口的个数;
在所述公网地址包括至少两个公网端口的情况下,将所述公网地址包括的公网IP地址分别和所述至少两个公网端口组成至少两个地址端口对;
向每个所述地址端口对发送所述访问请求数据包。
可选地,第三获取模块进一步被配置为:
向所述云服务器发送协助建联请求;
接收所述云服务器响应于所述协助建联请求返回的所述第二客户端的内网地址对应的至少一个公网地址。
本申请提供的客户端可以与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;然后,根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网地址,向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址,在监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。这种情况下,可以利用第一客户端与至少两个辅助节点通信,探测出第一客户端的内网地址对应的至少一个公网地址,以确定第一客户端对外的公网地址是否有多个,也即可以利用至少两个辅助节点更加准确的探测出第一客户端的内网地址对应的公网地址,提高了对应有多公网地址的客户端之间的打洞成功率,实现较高成功率的P2P建连。
上述为本实施例的一种客户端的示意性方案。需要说明的是,该客户端的技术方案与上述的建立P2P连接的方法的技术方案属于同一构思,客户端的技术方案未详细描述的细节内容,均可以参见上述建立P2P连接的方法的技 术方案的描述。
与上述方法实施例相对应,本申请还提供了建立P2P连接的系统实施例,图8示出了本申请一实施例提供的一种建立P2P连接的系统的结构示意图。如图8所示,该系统包括:第一客户端802和第二客户端804;
第一客户端802和第二客户端804,被配置为分别与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;根据所述应答消息,确定各自的内网地址对应的至少一个公网地址;向云服务器登记各自的内网地址对应的至少一个公网地址,并监听所述至少一个公网地址;
所述第一客户端802,进一步被配置为通过所述云服务器获取所述第二客户端的内网地址对应的至少一个公网地址,向所述第二客户端的内网地址对应的至少一个公网地址中的每个所述公网地址发送访问请求数据包;
所述第二客户端804,进一步被配置为在监听到自身的目标公网地址接收到访问请求数据包的情况下,通过所述云服务器获取所述第一客户端的内网地址对应的至少一个公网地址,向所述第一客户端的内网地址对应的至少一个公网地址中的每个所述公网地址返回响应数据包,所述目标公网地址为所述第二客户端的内网地址对应的至少一个公网地址之一;
所述第一客户端802,进一步被配置为在监听到所述第二客户端向自身的目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。
可选地,所述第一客户端802和第二客户端804进一步被配置为:
分别与穿越辅助服务器通信,获取各自内网地址以及各自对应的NAT设备的NAT类型;
将各自内网地址以及对应的NAT设备的NAT类型存储至本地。
可选地,所述第一客户端802和第二客户端804进一步被配置为:
向云服务器登记各自的内网地址对应的至少一个公网地址以及各自对应的NAT设备的NAT类型。
本申请提供的建立P2P连接的系统,可以与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;然后,根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网地址,向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址,在监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一 客户端的内网地址对应的至少一个公网地址之一。这种情况下,可以利用第一客户端与至少两个辅助节点通信,探测出第一客户端的内网地址对应的至少一个公网地址,以确定第一客户端对外的公网地址是否有多个,也即可以利用至少两个辅助节点更加准确的探测出第一客户端的内网地址对应的公网地址,提高了对应有多公网地址的客户端之间的打洞成功率,实现较高成功率的P2P建连。
上述为本实施例的一种建立P2P连接的系统的示意性方案。需要说明的是,该建立P2P连接的系统的技术方案与上述的建立P2P连接的方法的技术方案属于同一构思,建立P2P连接的系统的技术方案未详细描述的细节内容,均可以参见上述建立P2P连接的方法的技术方案的描述。
图9示出了根据本申请一实施例提供的一种计算设备900的结构框图。该计算设备900的部件包括但不限于存储器910和处理器920。处理器920与存储器910通过总线930相连接,数据库950用于保存数据。
计算设备900还包括接入设备940,接入设备940使得计算设备900能够经由一个或多个网络960通信。这些网络的示例包括公用交换电话网(PSTN)、局域网(LAN)、广域网(WAN)、个域网(PAN)或诸如因特网的通信网络的组合。接入设备940可以包括有线或无线的任何类型的网络接口(例如,网络接口卡(NIC))中的一个或多个,诸如IEEE802.11无线局域网(WLAN)无线接口、全球微波互联接入(Wi-MAX)接口、以太网接口、通用串行总线(USB)接口、蜂窝网络接口、蓝牙接口、近场通信(NFC)接口,等等。
在本申请的一个实施例中,计算设备900的上述部件以及图9中未示出的其他部件也可以彼此相连接,例如通过总线。应当理解,图9所示的计算设备结构框图仅仅是出于示例的目的,而不是对本申请范围的限制。本领域技术人员可以根据需要,增添或替换其他部件。
计算设备900可以是任何类型的静止或移动计算设备,包括移动计算机或移动计算设备(例如,平板计算机、个人数字助理、膝上型计算机、笔记本计算机、上网本等)、移动电话(例如,智能手机)、可佩戴的计算设备(例如,智能手表、智能眼镜等)或其他类型的移动设备,或者诸如台式计算机或PC的静止计算设备。计算设备900还可以是移动式或静止式的服务器。
其中,处理器920用于执行如下计算机可执行指令:
与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;
根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网地址;
向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址;
在预设时长内监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。
上述为本实施例的一种计算设备的示意性方案。需要说明的是,该计算设备的技术方案与上述的建立P2P连接的方法的技术方案属于同一构思,计算设备的技术方案未详细描述的细节内容,均可以参见上述建立P2P连接的方法的技术方案的描述。
本申请一实施例还提供一种计算机可读存储介质,其存储有计算机指令,该指令被处理器执行时以用于:
与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;
根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网地址;
向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址;
在预设时长内监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。
上述为本实施例的一种计算机可读存储介质的示意性方案。需要说明的是,该存储介质的技术方案与上述的建立P2P连接的方法的技术方案属于同一构思,存储介质的技术方案未详细描述的细节内容,均可以参见上述建立P2P连接的方法的技术方案的描述。
本申请一实施例还提供一种计算机程序产品,当所述计算机程序产品在计算机中执行时,令计算机执行任意上述建立P2P连接的方法的步骤。
上述为本实施例的一种计算机程序产品的示意性方案。需要说明的是,该计算机程序产品的技术方案与上述的建立P2P连接的方法的技术方案属于同一构思,计算机程序产品的技术方案未详细描述的细节内容,均可以参见上述建立P2P连接的方法的技术方案的描述。
上述对本申请特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程 不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。
所述计算机可执行指令包括计算机程序代码,所述计算机程序代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。所述计算机可读存储介质可以包括:能够携带所述计算机程序代码的任何实体或装置、记录介质、U盘、移动硬盘、磁碟、光盘、计算机存储器、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、电载波信号、电信信号以及软件分发介质等。需要说明的是,所述计算机可读存储介质包含的内容可以根据司法管辖区内立法和专利实践的要求进行适当的增减,例如在某些司法管辖区,根据立法和专利实践,计算机可读存储介质不包括电载波信号和电信信号。
需要说明的是,对于前述的各方法实施例,为了简便描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本申请并不受所描述的动作顺序的限制,因为依据本申请,某些步骤可以采用其它顺序或者同时进行。其次,本领域技术人员也应该知悉,申请中所描述的实施例均属于优选实施例,所涉及的动作和模块并不一定都是本申请所必须的。
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其它实施例的相关描述。
以上公开的本申请优选实施例只是用于帮助阐述本申请。可选实施例并没有详尽叙述所有的细节,也不限制该发明仅为所述的具体实施方式。显然,根据本申请的内容,可作很多的修改和变化。本申请选取并具体描述这些实施例,是为了更好地解释本申请的原理和实际应用,从而使所属技术领域技术人员能很好地理解和利用本申请。本申请仅受权利要求书及其全部范围和等效物的限制。

Claims (19)

  1. 一种建立P2P连接的方法,其特征在于,应用于第一客户端,包括:
    与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;
    根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网地址;
    向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址;
    在预设时长内监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。
  2. 根据权利要求1所述的建立P2P连接的方法,其特征在于,所述与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息之前,还包括:
    与穿越辅助服务器通信,获取所述第一客户端的内网地址以及所述第一客户端对应的NAT设备的NAT类型;
    将所述第一客户端的内网地址以及所述第一客户端对应的NAT设备的NAT类型存储至本地。
  3. 根据权利要求2所述的建立P2P连接的方法,其特征在于,所述根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网地址,包括:
    在所述第一客户端对应的NAT设备的NAT类型为端口限制锥形的情况下,根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网IP地址;
    针对所述至少一个公网IP地址中的每个所述公网IP地址,确定所述公网IP地址对应的至少一个公网端口;根据所述至少一个公网端口,确定所述公网IP地址对应的预估公网端口;将所述预估公网端口和所述公网IP地址组合为所述公网地址。
  4. 根据权利要求3所述的建立P2P连接的方法,其特征在于,所述根据所述至少一个公网端口,确定所述公网IP地址对应的预估公网端口,包括:
    确定所述至少一个公网端口中端口标识最大的第一公网端口,以及端口标识最小的第二公网端口;
    根据所述第一公网端口和所述第二公网端口,确定起始端口标识和终止端 口标识;
    将所述起始端口标识和所述终止端口标识之间的公网端口确定为所述预估公网端口。
  5. 根据权利要求4所述的建立P2P连接的方法,其特征在于,所述根据所述第一公网端口和所述第二公网端口,确定起始端口标识和终止端口标识,包括:
    将所述第一公网端口的端口标识加上预设阈值,得到所述终止端口标识;
    将所述第二公网端口的端口标识减去所述预设阈值,得到所述起始端口标识。
  6. 根据权利要求2所述的建立P2P连接的方法,其特征在于,所述向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,包括:
    向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址以及所述对应的NAT设备的NAT类型。
  7. 根据权利要求1所述的建立P2P连接的方法,其特征在于,所述与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息,包括:
    通过所述第一客户端的内网地址向所述至少两个辅助节点发送协助探测请求;
    接收所述至少两个辅助节点响应于所述协助探测请求返回的应答消息。
  8. 根据权利要求3所述的建立P2P连接的方法,其特征在于,所述根据所述应答消息,确定所述第一客户端的内网地址对应的至少一个公网IP地址,包括:
    针对所述至少两个辅助节点中的每个辅助节点,确定所述辅助节点返回的应答消息对应的公网IP地址;
    对所述应答消息对应的公网IP地址进行去重操作,确定出所述第一客户端的内网地址对应的至少一个公网IP地址。
  9. 根据权利要求1-8任一所述的建立P2P连接的方法,其特征在于,所述向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址之后,还包括:
    通过所述云服务器获取所述第二客户端的内网地址对应的至少一个公网地址,所述第二客户端的内网地址对应的至少一个公网地址为所述第二客户端通过所述至少两个辅助节点确定出的公网地址;
    向所述第二客户端的内网地址对应的至少一个公网地址中的每个所述公网地址发送访问请求数据包。
  10. 根据权利要求9所述的建立P2P连接的方法,其特征在于,所述公网地址包括一个公网IP地址和至少一个公网端口;
    所述向所述第二客户端的内网地址对应的至少一个公网地址中的每个所述公网地址发送访问请求数据包,包括:
    通过所述云服务器获取所述第二客户端对应的NAT设备的NAT类型;
    在所述第二客户端对应的NAT设备的NAT类型为端口限制锥形的情况下,针对所述至少一个公网地址中的每个所述公网地址,确定所述公网地址包括的公网端口的个数;
    在所述公网地址包括至少两个公网端口的情况下,将所述公网地址包括的公网IP地址分别和所述至少两个公网端口组成至少两个地址端口对;
    向每个所述地址端口对发送所述访问请求数据包。
  11. 根据权利要求9所述的建立P2P连接的方法,其特征在于,所述通过所述云服务器获取所述第二客户端的内网地址对应的至少一个公网地址,包括:
    向所述云服务器发送协助建联请求;
    接收所述云服务器响应于所述协助建联请求返回的所述第二客户端的内网地址对应的至少一个公网地址。
  12. 一种建立P2P连接的方法,其特征在于,包括:
    第一客户端和第二客户端分别与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;根据所述应答消息,确定各自的内网地址对应的至少一个公网地址;向云服务器登记各自的内网地址对应的至少一个公网地址,并监听所述至少一个公网地址;
    所述第一客户端通过所述云服务器获取所述第二客户端的内网地址对应的至少一个公网地址,向所述第二客户端的内网地址对应的至少一个公网地址中的每个所述公网地址发送访问请求数据包;
    所述第二客户端在监听到自身的目标公网地址接收到访问请求数据包的情况下,通过所述云服务器获取所述第一客户端的内网地址对应的至少一个公网地址,向所述第一客户端的内网地址对应的至少一个公网地址中的每个所述公网地址返回响应数据包,所述目标公网地址为所述第二客户端的内网地址对应的至少一个公网地址之一;
    所述第一客户端在监听到所述第二客户端向自身的目标公网地址返回响 应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。
  13. 根据权利要求12所述的建立P2P连接的方法,其特征在于,所述第一客户端和第二客户端分别与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息之前,还包括:
    所述第一客户端和所述第二客户端分别与穿越辅助服务器通信,获取各自内网地址以及各自对应的NAT设备的NAT类型;
    所述第一客户端和所述第二客户端将各自内网地址以及对应的NAT设备的NAT类型存储至本地。
  14. 根据权利要求10所述的建立P2P连接的方法,其特征在于,所述第一客户端和第二客户端分别向云服务器登记各自的内网地址对应的至少一个公网地址,包括:
    向云服务器登记各自的内网地址对应的至少一个公网地址以及各自对应的NAT设备的NAT类型。
  15. 一种客户端,其特征在于,包括:
    第一获取模块,被配置为与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;
    确定模块,被配置为根据所述应答消息,确定第一客户端的内网地址对应的至少一个公网地址;
    监听模块,被配置为向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址;
    建联模块,被配置为在监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。
  16. 一种建立P2P连接的系统,其特征在于,包括:
    第一客户端和第二客户端,被配置为分别与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;根据所述应答消息,确定各自的内网地址对应的至少一个公网地址;向云服务器登记各自的内网地址对应的至少一个公网地址,并监听所述至少一个公网地址;
    所述第一客户端,进一步被配置为通过所述云服务器获取所述第二客户端的内网地址对应的至少一个公网地址,向所述第二客户端的内网地址对应的至少一个公网地址中的每个所述公网地址发送访问请求数据包;
    所述第二客户端,进一步被配置为在监听到自身的目标公网地址接收到访问请求数据包的情况下,通过所述云服务器获取所述第一客户端的内网地址对应的至少一个公网地址,向所述第一客户端的内网地址对应的至少一个公网地址中的每个所述公网地址返回响应数据包,所述目标公网地址为所述第二客户端的内网地址对应的至少一个公网地址之一;
    所述第一客户端,进一步被配置为在监听到所述第二客户端向自身的目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。
  17. 一种计算设备,其特征在于,包括:
    存储器和处理器;
    所述存储器用于存储计算机可执行指令,所述处理器用于执行所述计算机可执行指令,以实现下述方法:
    与至少两个辅助节点通信,获取所述至少两个辅助节点返回的应答消息;
    根据所述应答消息,确定第一客户端的内网地址对应的至少一个公网地址;
    向云服务器登记所述第一客户端的内网地址对应的至少一个公网地址,并监听所述第一客户端的内网地址对应的至少一个公网地址;
    在监听到第二客户端向目标公网地址返回响应数据包的情况下,与所述第二客户端建立P2P连接,所述目标公网地址为所述第一客户端的内网地址对应的至少一个公网地址之一。
  18. 一种计算机可读存储介质,其特征在于,其存储有计算机指令,该指令被处理器执行时实现权利要求1至11任意一项所述建立P2P连接的方法的步骤。
  19. 一种计算机程序产品,当所述计算机程序产品在计算机中执行时,令计算机执行权利要求1至11任意一项所述建立P2P连接的方法的步骤。
PCT/CN2022/070236 2021-01-06 2022-01-05 建立p2p连接的方法、客户端及系统 WO2022148361A1 (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
US18/271,013 US20240064206A1 (en) 2021-01-06 2022-01-05 Method, client, and system for establishing p2p connection

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110011856.9A CN112637364B (zh) 2021-01-06 2021-01-06 建立p2p连接的方法、客户端及系统
CN202110011856.9 2021-01-06

Publications (1)

Publication Number Publication Date
WO2022148361A1 true WO2022148361A1 (zh) 2022-07-14

Family

ID=75291475

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/070236 WO2022148361A1 (zh) 2021-01-06 2022-01-05 建立p2p连接的方法、客户端及系统

Country Status (3)

Country Link
US (1) US20240064206A1 (zh)
CN (1) CN112637364B (zh)
WO (1) WO2022148361A1 (zh)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116708358A (zh) * 2022-10-31 2023-09-05 荣耀终端有限公司 P2p穿越方法、设备及存储介质
CN116939003A (zh) * 2023-09-19 2023-10-24 敏于行(北京)科技有限公司 跨nat的端到端网络连接建立方法及系统

Families Citing this family (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112637364B (zh) * 2021-01-06 2023-01-10 上海哔哩哔哩科技有限公司 建立p2p连接的方法、客户端及系统
CN115225646A (zh) * 2021-04-21 2022-10-21 武汉斗鱼鱼乐网络科技有限公司 一种p2p节点推荐方法、终端、介质及计算机设备
CN113965630B (zh) * 2021-10-25 2024-08-09 深圳市元征科技股份有限公司 一种udp连接方法、电子设备及存储介质
CN114390049A (zh) * 2021-12-29 2022-04-22 中国电信股份有限公司 一种应用数据获取方法及装置

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040148406A1 (en) * 2002-12-10 2004-07-29 Koji Shima Network system for establishing peer-to-peer communication
CN101217536A (zh) * 2007-12-28 2008-07-09 腾讯科技(深圳)有限公司 穿越网络地址转换设备/防火墙的方法、系统及客户端
CN106878474A (zh) * 2017-04-25 2017-06-20 浙江风向标科技有限公司 一种p2p连接建立的方法和装置
CN107580081A (zh) * 2017-09-18 2018-01-12 北京奇艺世纪科技有限公司 一种nat穿透方法及装置
CN107580082A (zh) * 2017-09-18 2018-01-12 北京奇艺世纪科技有限公司 一种对称型nat的穿透方法及装置
CN112637364A (zh) * 2021-01-06 2021-04-09 上海哔哩哔哩科技有限公司 建立p2p连接的方法、客户端及系统

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102231763B (zh) * 2011-06-20 2014-04-09 北京思创银联科技股份有限公司 一种基于nat穿透的共享方法
CN103916382B (zh) * 2013-12-25 2018-05-01 三亚中兴软件有限责任公司 基于sip媒体能力重协商的nat穿越方法、代理服务器和系统
CN106331198B (zh) * 2015-06-29 2020-04-21 中兴通讯股份有限公司 Nat穿透方法及装置
CN106713437A (zh) * 2016-12-16 2017-05-24 江苏神州信源系统工程有限公司 一种用于nat网络中服务器向客户端发送消息的方法

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040148406A1 (en) * 2002-12-10 2004-07-29 Koji Shima Network system for establishing peer-to-peer communication
CN101217536A (zh) * 2007-12-28 2008-07-09 腾讯科技(深圳)有限公司 穿越网络地址转换设备/防火墙的方法、系统及客户端
CN106878474A (zh) * 2017-04-25 2017-06-20 浙江风向标科技有限公司 一种p2p连接建立的方法和装置
CN107580081A (zh) * 2017-09-18 2018-01-12 北京奇艺世纪科技有限公司 一种nat穿透方法及装置
CN107580082A (zh) * 2017-09-18 2018-01-12 北京奇艺世纪科技有限公司 一种对称型nat的穿透方法及装置
CN112637364A (zh) * 2021-01-06 2021-04-09 上海哔哩哔哩科技有限公司 建立p2p连接的方法、客户端及系统

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116708358A (zh) * 2022-10-31 2023-09-05 荣耀终端有限公司 P2p穿越方法、设备及存储介质
CN116708358B (zh) * 2022-10-31 2024-04-05 荣耀终端有限公司 P2p穿越方法、设备及存储介质
CN116939003A (zh) * 2023-09-19 2023-10-24 敏于行(北京)科技有限公司 跨nat的端到端网络连接建立方法及系统
CN116939003B (zh) * 2023-09-19 2023-11-14 敏于行(北京)科技有限公司 跨nat的端到端网络连接建立方法及系统

Also Published As

Publication number Publication date
CN112637364B (zh) 2023-01-10
CN112637364A (zh) 2021-04-09
US20240064206A1 (en) 2024-02-22

Similar Documents

Publication Publication Date Title
WO2022148361A1 (zh) 建立p2p连接的方法、客户端及系统
US9143421B2 (en) Network system capable of implementing stun with the assistance of two network devices and method thereof
EP2255497B1 (en) Traversal of symmetric network address translator for multiple simultaneous connections
CN108900351B (zh) 内网设备类型识别方法及装置
EP3219087B1 (en) Methods, systems, and computer readable media for facilitating the resolving of endpoint hostnames in test environments with firewalls, network address translators(nats), or clouds
US20100088427A1 (en) Selective Routing of Data Transmission Between Clients
CN111800341B (zh) 一种跨路由器终端通信方法及装置
US20100241710A1 (en) Method and system for videoconferencing or data transfer between clients behind different network address translators
CN112770408B (zh) 一种日志的传输方法、装置、计算机设备和存储介质
JP7401564B2 (ja) 通信方法及び関連デバイス
CN113542244B (zh) 微服务调用方法、装置、服务器和系统
WO2023186109A1 (zh) 节点访问方法以及数据传输系统
GB2598293A (en) Apparatus, methods, and computer programs
CN112073553A (zh) 网络地址转换类型的检测方法、装置、设备及存储介质
US11863630B2 (en) Connection establishment method, server, accessed node, access node, and storage medium
WO2022148364A1 (zh) 数据发送方法及装置、建立p2p连接的方法及系统
CN112019641B (zh) 数据传输方法和装置
JP6605149B2 (ja) 共有端末の検出方法及びその装置
CN112804290B (zh) 一种适用于频谱/信号分析仪的云平台接入方法
GB2607362A (en) Private cloud routing server connection mechanism for use in a private communication architecture
CN107317869B (zh) 一种节点nat类型探测方法、装置以及系统
CN113225224B (zh) 网络测速的方法、系统、存储介质以及计算机设备
CN114422456B (zh) 任务处理方法以及装置
EP2608488B1 (en) Dialog establishment over a peer-to-peer architecture
Cardwell Capturing Network Traffic

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: 22736523

Country of ref document: EP

Kind code of ref document: A1

WWE Wipo information: entry into national phase

Ref document number: 18271013

Country of ref document: US

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 21.11.2023)

122 Ep: pct application non-entry in european phase

Ref document number: 22736523

Country of ref document: EP

Kind code of ref document: A1