WO2022148364A1 - 数据发送方法及装置、建立p2p连接的方法及系统 - Google Patents

数据发送方法及装置、建立p2p连接的方法及系统 Download PDF

Info

Publication number
WO2022148364A1
WO2022148364A1 PCT/CN2022/070246 CN2022070246W WO2022148364A1 WO 2022148364 A1 WO2022148364 A1 WO 2022148364A1 CN 2022070246 W CN2022070246 W CN 2022070246W WO 2022148364 A1 WO2022148364 A1 WO 2022148364A1
Authority
WO
WIPO (PCT)
Prior art keywords
terminal
port
access request
file descriptor
request data
Prior art date
Application number
PCT/CN2022/070246
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,024 priority Critical patent/US12010088B2/en
Publication of WO2022148364A1 publication Critical patent/WO2022148364A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/2514Translation of Internet protocol [IP] addresses between local and global IP addresses
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/2517Translation of Internet protocol [IP] addresses using port numbers
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/256NAT traversal
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L61/00Network arrangements, protocols or services for addressing or naming
    • H04L61/09Mapping addresses
    • H04L61/25Mapping addresses of the same type
    • H04L61/2503Translation of Internet protocol [IP] addresses
    • H04L61/256NAT traversal
    • H04L61/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/2592Translation of Internet protocol [IP] addresses using tunnelling or encapsulation
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L2101/00Indexing scheme associated with group H04L61/00
    • H04L2101/60Types of network addresses
    • H04L2101/695Types of network addresses using masks or ranges of addresses

Definitions

  • the embodiments of the present application relate to the field of communication technologies, and in particular, to a method for sending data.
  • One or more embodiments of the present application also relate to a data sending apparatus, a method and 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 IP address of the internal network to the public IP address of the external network. It enables multiple hosts within a certain range to use only one public IP address to connect to the external network.
  • NAT technology solves the problem of IPv4 address shortage to a certain extent, it destroys end-to-end (P2P) network communication. The main reason is that NAT does not allow external network hosts to actively access internal network hosts.
  • the router will map to different addresses and ports according to the destination address. Only when the host has sent a packet to an external host (IP_x, Port_x), from the external host (IP_x, Port_x) ) can be received by the symmetric NAT router.
  • an embodiment of the present application provides a data sending method.
  • One or more embodiments of the present application also relate to a data sending apparatus, a method and system for establishing a P2P connection, a computing device, a computer-readable storage medium, and a computer program product to solve existing problems in the technical flaws in the technology.
  • a method for sending data is provided, which is applied to a terminal under a symmetric NAT, including:
  • S1 establish a queue accommodating m file descriptors for n 1 first access request data packets, where 2 ⁇ m ⁇ n 1 ;
  • S2 Create the i-th file descriptor in the queue, send the i-th first access request data packet through the i-th file descriptor, and perform the processing on the source port recorded by the i-th file descriptor monitoring, wherein the i-th file descriptor and the i-th first access request data packet have the same source port, where 1 ⁇ i ⁇ n 1 ;
  • the data sending method further includes: if no response data packet is received when the preset listening time T of the source port recorded in the n1th file descriptor ends, re-executing it as n1 first access requests The step in which the packet builds a queue to hold m file descriptors.
  • the data sending method further includes: sending the first data to be transmitted and/or receiving the second data to be transmitted through the first port.
  • stopping monitoring of other source ports until the first port receives a response data packet includes:
  • the method before establishing a queue accommodating m file descriptors for the n 1 first access request data packets, the method further includes:
  • the method before sending the i-th first access request data packet through the i-th file descriptor, the method further includes:
  • the i-th first access request data packet is generated based on the received address information of the terminal to be accessed and the source port corresponding to the i-th file descriptor.
  • a method for establishing a P2P connection including:
  • the first terminal sends n 2 second access request data packets at a second preset time interval t 2 through a file descriptor, wherein the first terminal is under a port-restricted NAT, and the n 2 second access request data packets are The destination IP address in the access request data packet is the same and the destination port is different;
  • the second terminal under the symmetric NAT corresponding to the destination IP address performs the following operations:
  • S1 establish a queue accommodating m file descriptors for n 1 first access request data packets, where 2 ⁇ m ⁇ n 1 ;
  • S2 Create the i-th file descriptor in the queue, send the i-th first access request data packet through the i-th file descriptor, and perform the processing on the source port recorded by the i-th file descriptor monitoring, wherein the i-th file descriptor and the i-th first access request data packet have the same source port, where 1 ⁇ i ⁇ n 1 ;
  • the port-restricted NAT monitors that the source port of the first terminal receives a message from the second terminal.
  • the first terminal obtains the address information in the first access request data packet, and sends a response data packet to the obtained address information;
  • the symmetric NAT detects that the first port of the second terminal receives a response data packet, and stops monitoring other source ports, wherein the first port corresponds to the obtained address information.
  • the method for establishing a P2P connection further includes:
  • the first terminal will re-execute the second preset through a file descriptor under the preset condition.
  • the method further includes:
  • the first terminal and the second terminal respectively send an information acquisition request to the traversal assistance server;
  • the first terminal and the second terminal respectively receive the respective address information and the NAT type sent by the traversal assistance server;
  • the first terminal and the second terminal send the received respective address information and NAT type to the access management server;
  • the first terminal receives the address information and the NAT type of the second terminal fed back by the access management server, and the second terminal receives the address information and the NAT type of the first terminal fed back by the access management server .
  • the method further includes:
  • the second access request data packet is generated based on the IP address in the received address information of the second terminal, the set destination port, and the source port corresponding to the file descriptor.
  • the initial port of the second terminal is set as a random number, and the destination ports with the same interval between port numbers are set for the n 2 second access request data packets, including:
  • the interval between the destination port of each second access request data packet and the destination port of the previous second access request data packet is set to a fixed value related to the preset value.
  • the first terminal when the first terminal sends n 2 second access request data packets, a first mapping relationship between the address information of the first terminal and the address information of the second terminal is established, and the first mapping relationship between the address information of the first terminal and the address information of the second terminal is established.
  • a second mapping relationship between the address information of the second terminal and the address information of the first terminal is established, and the monitoring of the first terminal's address information
  • the source port receiving the first access request data packet from the second terminal includes:
  • the method for establishing a P2P connection further includes:
  • the second data to be transmitted is sent by the first terminal to the first port through the source port corresponding to the file descriptor of the first terminal.
  • the first access request data packet and the second access request data packet include UDP packets.
  • a data sending device which is applied to a terminal under a symmetric NAT, including:
  • the establishment module is configured to execute step S1: establish a queue accommodating m file descriptors for n 1 first access request data packets, wherein 2 ⁇ m ⁇ n 1 ;
  • Create a sending module configured to perform step S2: create the ith file descriptor in the queue and send the ith first access request data packet through the ith file descriptor, and send the ith file descriptor to the ith file descriptor.
  • the source ports recorded by the file descriptors are monitored, wherein the i-th file descriptor and the i-th first access request data packet have the same source port, where 1 ⁇ i ⁇ n 1 ;
  • the stop monitoring module is configured to perform step S4: in the case of m*j ⁇ i ⁇ m*(j+1), when the i-th file descriptor is created in the queue, end the monitoring of the i-m-th source port monitor and destroy the corresponding file descriptor until the first port receives a response packet, stop monitoring other source ports, where j ⁇ 1, the first port is any source in the monitored state port.
  • a system for establishing a P2P connection including a port-restricted NAT, a first terminal under the port-restricted NAT, a symmetric NAT, and a first terminal under the symmetric NAT two terminals,
  • the first terminal is configured to send n 2 second access request data packets at a second preset time interval t 2 through a file descriptor, wherein the destination IP address in the n 2 second access request data packets The address is the same and the destination port is different;
  • the second terminal corresponds to the destination IP address, and the second terminal is configured to perform the following steps:
  • S1 establish a queue accommodating m file descriptors for n 1 first access request data packets, where 2 ⁇ m ⁇ n 1 ;
  • S2 Create the i-th file descriptor in the queue, send the i-th first access request data packet through the i-th file descriptor, and perform the processing on the source port recorded by the i-th file descriptor monitoring, wherein the i-th file descriptor and the i-th first access request data packet have the same source port, where 1 ⁇ i ⁇ n 1 ;
  • the first terminal is configured to: within a listening time period of t 2 *n 2 +t 1 *n 1 of the source port of the first terminal, the port-restricted NAT listens to the first terminal's When the source port receives the first access request data packet from the second terminal, obtain the address information in the first access request data packet, and send a response data packet to the obtained address information;
  • the symmetric NAT is configured to: monitor that the first port of the second terminal receives a response data packet, and stop monitoring other source ports, wherein the first port corresponds to the obtained address information.
  • a computing device including a memory, a processor, and computer instructions stored in the memory and executable on the processor, the processor implementing the computer instructions when the processor executes the computer instructions. Describe the steps of the data transmission method.
  • a computer-readable storage medium which stores computer instructions, and when the computer instructions are executed by a processor, implements the steps of the data sending method.
  • 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 data sending method.
  • the terminal under symmetric NAT utilizes a queue accommodating m file descriptors and sets an appropriate listening time for each file descriptor, so that the terminal side only uses m file descriptors to send relative data.
  • a large number of data packets, using fewer file descriptors to provide a higher success rate for establishing a connection, occupying fewer file descriptors can improve the utilization of file descriptors, save public resources, and use as few file descriptors as possible to achieve the same Function.
  • 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 structural diagram of a system for P2P connection provided by an embodiment of the present application
  • FIG. 3 is a process flow diagram of a data sending method performed by a second terminal under symmetric NAT provided by an embodiment of the present application;
  • FIG. 4 is a process flow diagram of a method for establishing a P2P connection provided by an embodiment of the present application
  • FIG. 5 is a schematic structural diagram of a data sending apparatus provided by an embodiment of the present application.
  • FIG. 6 is a structural block diagram of a computing device provided by an embodiment of the present application.
  • a data transmission method is provided, and the application also relates to a data transmission apparatus, a method for establishing a P2P connection, a system for establishing a P2P connection, a computing device, and a computer-readable storage
  • the medium and a computer program product are described in detail one by one in the following embodiments.
  • FIG. 1 shows a flowchart of a method for establishing a P2P connection according to an embodiment of the present application, which specifically includes the following steps:
  • Step 102 The first terminal sends n 2 second access request data packets at a second preset time interval t 2 through a file descriptor, wherein the first terminal is under the port-restricted NAT, and the n 2
  • the destination IP addresses in the second access request data packets are the same and the destination ports are different.
  • the first terminal and the second terminal under the symmetric NAT respectively send information acquisition requests to the traversal auxiliary server, and the traversal auxiliary server sends the respective address information of the first and second terminals to the first terminal and the second terminal and NAT type, the first terminal and the second terminal send the received respective address information and NAT type to the access management server, and the access management server feeds back the address information and NAT type of the second terminal to the first terminal, and sends the second terminal to the second terminal.
  • the terminal feeds back the address information and the NAT type of the first terminal.
  • the address information includes the external network IP and external network port of the first terminal and the second terminal, and the four-tuple of the internal network IP and internal network port, namely (IP-A, Port-A, IP-natA, Port-natA), (IP -B, Port-B, IP-natB, Port-natB).
  • the traversal auxiliary server is a server such as a STUN server
  • the access management server is a server such as a Tracker server.
  • the access management server sends the node information of playing the same resource to each terminal according to the same requested resource ID. Intranet, public network address quadruple and NAT type of the terminal.
  • the first terminal After the first terminal obtains the intranet, public network address quadruple and NAT type of the second terminal, the first terminal uses the file descriptor previously established with the traversal auxiliary server to use the same source port at the second preset time interval t2
  • the second access request data packet is sent, and the second access request data packet may be a UDP packet or a TCP packet. In an embodiment, a UDP packet is used, which has better real-time performance.
  • the destination IP addresses are the same, both are the external network IP addresses of the second terminal, and the destination IP addresses of the n 2 second access request data packets are the external network IP addresses of the second terminal,
  • the destination ports of all the second access request data packets are different, wherein n 2 can be determined according to experience, and is a value within a predetermined range.
  • different destination ports of all the second access request data packets are achieved by:
  • a second access request data packet is generated based on the IP address in the received address information of the second terminal, the set destination port, and the source port corresponding to the file descriptor.
  • setting the initial port of the second terminal as a random number, and setting the destination port with the same interval between port numbers for the n 2 second access request data packets can be implemented as follows :
  • the interval between the destination port of each second access request data packet and the destination port of the previous second access request data packet is set to a fixed value related to the preset value.
  • the default value can be set to 1024, and these ports will not be allocated during automatic allocation, which can improve the success rate of hole punching.
  • Setting the port interval of 1 to this value can separate the ports, improve the matching degree between the mapping relationship of the second terminal and the destination port, and improve the success rate of P2P connection establishment.
  • the first terminal establishes a second access request data packet through a file descriptor
  • the destination IP address is the external network IP address of the second terminal
  • the destination port is the set above-mentioned initial port
  • a port-restricted NAT of the first terminal will establish n 2 different ports that can receive from the symmetric NAT of the second terminal
  • the mapping relationship requested by the data packet as long as the data packet from the symmetric NAT of the second terminal belongs to one of the n 2 mapping relationships, the hole punching can be successful.
  • Step 104 The second terminal under the symmetric NAT corresponding to the destination IP address performs a data sending operation.
  • the data sending operation includes:
  • S1 establish a queue accommodating m file descriptors for n 1 first access request data packets, where 2 ⁇ m ⁇ n 1 ;
  • S2 Create the i-th file descriptor in the queue, send the i-th first access request data packet through the i-th file descriptor, and perform the processing on the source port recorded by the i-th file descriptor monitoring, wherein the i-th file descriptor and the i-th first access request data packet have the same source port, where 1 ⁇ i ⁇ n 1 ;
  • the i+1-th file descriptor is created in the queue, and the i+1-th first access is sent through the i+1-th file descriptor Request data packet, monitor the source port recorded by the i+1 th file descriptor, the i+1 th file descriptor has the same source port as the i+1 th first access request data packet, after creating the ith ith file descriptor
  • +1 file descriptor at the first preset time interval t 1 , create the i+2 th file descriptor in the queue, and send the i+2 th first access request data through the i+2 th file descriptor package, monitor the source port recorded by the i+2 file descriptor, the i+2 file descriptor has the same source port as the i+2 first access request data packet, and so on, let i Self-increment by 1, after each i self-increment by 1, after the corresponding
  • the second terminal After the second terminal waits for a time period of t 2 *n 2 , it initializes an empty queue that can accommodate m file descriptors, creates the first file descriptor and adds it to the queue, and establishes that the destination address is the external network IP of the first terminal.
  • the first access request data packet of the address and port is sent through the file descriptor, and the file descriptor has the same source port as the first access request data packet.
  • a second file descriptor is created and added to the queue, and the first access request data packet whose destination address is the IP address and port of the first terminal is created, described by the second file
  • n 1 and n 2 may be the same or different, and the first preset time interval t 1 and the second preset time interval t 2 may be the same or different.
  • the first preset time interval t 1 can be determined according to the packet loss rate when the access request data packet is sent, etc. If the value is too small, the packet loss rate is high, and an appropriate first preset time interval t 1 is selected according to the situation. In one embodiment, the first preset time interval t1 is set to 50ms.
  • the monitoring time T t 1 *m, which can be set according to the actual situation. If the monitoring time is too short, the first terminal may send a response packet to the second terminal, but due to network congestion, the monitoring will be stopped before it is received. If the monitoring time is too long, the connection establishment time is too long, which occupies the P2P transmission data after the connection establishment. In an optional embodiment, the listening time is set to 1s.
  • Step 106 During the listening time period of t 2 *n 2 +t 1 *n 1 of the source port of the first terminal, the port-restricted NAT monitors that the source port of the first terminal receives a message from the first terminal. In the case of the first access request data packet of the two terminals, the first terminal obtains the address information in the first access request data packet, and sends a response data packet to the obtained address information.
  • the listening time set by the file descriptor used by the first terminal is t 2 *n 2 +t 1 *n 1 , if within the listening time, the port-restricted NAT monitors that the source port corresponding to the file descriptor receives For the first access request data packet from the symmetric NAT of the second terminal, the first access request data packet is unpacked to obtain address information therein, and the first terminal sends a response data packet to the address information.
  • Step 108 The symmetric NAT monitors that the first port of the second terminal receives the response data packet, and stops monitoring other source ports, wherein the first port corresponds to the obtained address information.
  • the port corresponding to any file descriptor in the queue receives the response data packet from the first terminal, the address information corresponding to the file descriptor is recorded, the monitoring of other source ports is stopped, and the queue is cleared.
  • 1 file descriptor is used on the port-restricted NAT side and m file descriptors are used on the symmetric NAT side, and fewer file descriptors are used to provide higher connection establishment success. Taking up fewer file descriptors can improve the utilization of file descriptors, save public resources, and use as few file descriptors as possible to achieve the same function.
  • the first terminal will re-execute the second preset through a file descriptor under the preset condition.
  • the preset condition may be that the external network address is detected again or the network switching is detected. For example, the network is switched from the mobile network to the WIFI or from the WIFI to the mobile network, then the connection is re-established, and steps 102 to 108 are executed.
  • the first terminal is located in a port-restricted NAT router 203, also called a port-restricted NAT
  • the second terminal is located in a symmetric NAT router 204, also called a symmetric NAT.
  • a first mapping relationship between the address information of the first terminal and the address information of the second terminal is established, and n 1 first access requests are sent at the second terminal
  • a second mapping relationship between the address information of the second terminal and the address information of the first terminal is established.
  • the first mapping relationship is shown as 201 in FIG. 2
  • the second mapping relationship is shown as 202 in FIG. 2 . Show.
  • the receiving of the first access request data packet from the second terminal by the source port of the first terminal that is monitored may be implemented as follows:
  • the first mapping relationship is compared with the second mapping relationship, and if there is a matching mapping relationship, it is monitored that the source port of the first terminal receives the first access request data packet from the second terminal.
  • n 2 first mapping relationships IP 1 , Port 1 , IP 2 , Port 2
  • IP 1 , IP 2 and Port 1 IP 1 , IP 2 and Port 1 in the two mapping relationships match, if there is a second mapping relationship between Port 2 and Port 1
  • Port 2 in a first mapping relationship matches, it can be monitored that the first terminal receives the first access request data packet. For example, the first terminal sends to the port Port 2n of the second terminal through the port Port 1 , that is, the Port 2 in the first mapping relationship is Port 2n .
  • Port 2 in the second mapping relationship is also Port 2n , and the mapping relationship matches, and the source port of the first terminal successfully receives the first access request data packet.
  • the second terminal After the P2P connection is established between the first terminal and the second terminal, the second terminal sends the first data to be transmitted to the source port corresponding to the file descriptor of the first terminal through the first port; and/or the first terminal sends the first data to be transmitted through the first port
  • the source port corresponding to the file descriptor of the first terminal sends the second data to be transmitted to the first port to start data transmission. For example, data is transmitted via the above-mentioned Port 2n .
  • Fig. 3 shows the processing flow chart of a data sending method performed by a second terminal under symmetric NAT, including:
  • Step 302 Establish a queue for accommodating m file descriptors for n 1 first access request data packets, where 2 ⁇ m ⁇ n 1 ;
  • Step 304 Create the i-th file descriptor in the queue and send the i-th first access request data packet through the i-th file descriptor, and record the source port of the i-th file descriptor monitoring, wherein the i-th file descriptor and the i-th first access request data packet have the same source port, where 1 ⁇ i ⁇ n 1 ;
  • the i+1-th file descriptor is created in the queue, and the i+1-th first access is sent through the i+1-th file descriptor Request data packet, monitor the source port recorded by the i+1 th file descriptor, the i+1 th file descriptor has the same source port as the i+1 th first access request data packet, after creating the ith ith file descriptor
  • +1 file descriptor at the first preset time interval t 1 , create the i+2 th file descriptor in the queue, and send the i+2 th first access request data through the i+2 th file descriptor package, monitor the source port recorded by the i+2 file descriptor, the i+2 file descriptor has the same source port as the i+2 first access request data packet, and so on, let i Auto increment by 1, after each i increment by 1, the corresponding file descriptor is created and the
  • Step 308 Determine whether m*j ⁇ i ⁇ m*(j+1) is satisfied, if yes, go to step 310; if not, go to step 304;
  • Step 310 when the i-th file descriptor is created in the queue, end the monitoring of the i-m-th source port and destroy the corresponding file descriptor, and continue to perform step 312;
  • Step 312 Determine whether the first port has received a response data packet, if yes, go to Step 314; if not, go to Step 304;
  • Step 314 Stop monitoring other source ports, where j ⁇ 1, and the first port is any source port in a monitored state.
  • the terminal under the symmetric NAT uses a queue containing m file descriptors and sets an appropriate listening time for each file descriptor, so that the terminal side only uses m file descriptors to transmit
  • using fewer file descriptors provides a higher success rate for establishing a connection, and occupying fewer file descriptors can improve the utilization of file descriptors, save public resources, and implement with as few file descriptors as possible. Same function.
  • stopping monitoring of other source ports until the first port receives a response data packet includes:
  • the file descriptors corresponding to other source ports are destroyed.
  • the method before establishing a queue accommodating m file descriptors for the n 1 first access request data packets, the method further includes:
  • the method Before the sending the i-th first access request data packet through the i-th file descriptor, the method further includes:
  • the i-th first access request data packet is generated based on the received address information of the terminal to be accessed and the source port corresponding to the i-th file descriptor.
  • FIG. 4 shows a processing flow chart of a method for establishing a P2P connection provided by an embodiment of the present application, which specifically includes the following steps:
  • Step 402 The first terminal and the second terminal respectively send an information acquisition request to the STUN server, and receive the respective address information and NAT type sent by the STUN server.
  • the first terminal is under the port-restricted NAT
  • the second terminal is under the symmetric NAT.
  • the first terminal and the second terminal respectively obtain their own intranet, public network address quadruple and NAT type through the STUN server.
  • Step 404 The first terminal and the second terminal send the received respective address information and NAT type to the Tracker server, and receive the peer's intranet, public network address quadruple and NAT type fed back by the Tracker server.
  • the Tracker server can send information of nodes playing the same resource to each terminal according to the same requested resource ID.
  • the first terminal and the second terminal respectively obtain the internal network, the public network address quadruple and the NAT type of the opposite terminal.
  • Step 406 The first terminal sends one UDP packet every 50ms through a file descriptor, and a total of 400 UDP packets are sent, wherein the destination IP addresses in the 400 UDP packets are the same and the destination ports are different.
  • the destination IP addresses in the 400 UDP packets are the same, and they are all the external network IP addresses of the second terminal.
  • the destination ports of all UDP packets are different.
  • Setting the destination port in step 406 can be achieved by: setting the initial port of the second terminal
  • the ports from 0 to 1023 are ports of the inherent protocol. These ports will not be allocated during automatic allocation, which can improve the success rate of hole punching. Setting the destination port interval to this value can widen the interval between the ports, improve the matching degree between the mapping relationship of the second terminal and the destination port, and improve the success rate of P2P connection establishment. By allocating different initial ports and each subsequent port is spaced the same distance from the previous port, avoiding the first terminal when the first terminal establishes a connection with the third terminal or more other terminals overwrite the connection with the second terminal before The mapping information left on the port-restricted NAT makes the connection establishment of two terminals independent of each other, which can effectively improve the success rate of connection establishment.
  • Step 408 The second terminal corresponding to the destination IP address establishes a queue for 400 UDP packets to accommodate 20 file descriptors.
  • Step 410 The second terminal creates the first file descriptor in the queue, sends the first UDP packet through the first file descriptor, and monitors the source port recorded by the first file descriptor.
  • 1 file descriptor has the same source port as the first UDP packet.
  • Step 412 Every 50ms, continue to create file descriptors in the queue and send UDP packets based on the created file descriptors, monitor the source ports recorded by the created file descriptors, and set for each source port
  • the preset listening time is 1s, wherein each file descriptor records a different source port, and each file descriptor has the same source port as the UDP packet sent by using it.
  • Step 414 When the 21st file descriptor is created, the monitoring of the first source port is terminated and the corresponding file descriptor is destroyed.
  • Step 416 Repeat the above steps until 400 file descriptors are created.
  • Step 418 During the monitoring period of 40s of the source port of the first terminal, the port-restricted NAT monitors that the source port of the first terminal receives the UDP packet from the second terminal, and the first terminal obtains the UDP packet. address information in the message, and send a response packet to the obtained address information.
  • Step 420 The symmetric NAT monitors that the first port of the second terminal receives a response data packet, and stops monitoring other source ports, wherein the first port corresponds to the obtained address information.
  • the port corresponding to any file descriptor in the queue receives the response data packet from the first terminal, the address information corresponding to the file descriptor is recorded, and other file descriptors are destroyed.
  • the second terminal sends the first data to be transmitted to the source port corresponding to the file descriptor of the first terminal through the first port; and/or the first terminal sends the data to the first terminal through the source port corresponding to the file descriptor of the first terminal.
  • a port sends the second data to be transmitted to start data transmission.
  • only 20 file descriptors are used on the second terminal side by using a queue containing 20 file descriptors at the second terminal and setting an appropriate listening time of 1 s for each file descriptor Send 400 data packets, use fewer file descriptors to provide a higher success rate for establishing a connection, and occupy fewer file descriptors can improve the utilization of file descriptors, save public resources, and use as few file descriptors as possible. Same function.
  • FIG. 5 shows a schematic structural diagram of a data sending apparatus provided by an embodiment of the present application.
  • the device includes:
  • the establishment module 502 is configured to perform step S1: establish a queue for accommodating m file descriptors for n 1 first access request data packets, wherein 2 ⁇ m ⁇ n 1 ;
  • the creating and sending module 504 is configured to perform step S2: creating the i-th file descriptor in the queue and sending the i-th first access request data packet through the i-th file descriptor, and sending the i-th first access request data packet to the i-th file descriptor.
  • the source ports recorded by the i file descriptors are monitored, wherein the i-th file descriptor and the i-th first access request data packet have the same source port, where 1 ⁇ i ⁇ n 1 ;
  • the setting module 506 is configured to execute step S3: every first preset time interval t 1 , make i increment by 1, continue to execute step S2, and set a preset listening time T for each source port, wherein each source port
  • the stop monitoring module 508 is configured to perform step S4: in the case of m*j ⁇ i ⁇ m*(j+1), when the i-th file descriptor is created in the queue, end the monitoring of the i-m-th source Monitor the port and destroy the corresponding file descriptor until the first port receives a response packet, and stop monitoring other source ports, where j ⁇ 1, the first port is any one in the monitored state source port.
  • the data sending apparatus further includes:
  • the execution module is configured to: if no response data packet is received at the end of the preset listening time T of the source port recorded by the n1th file descriptor, re-execute the establishment of n1 first access request data packets Steps to hold a queue of m file descriptors.
  • the data sending apparatus further includes: a transmission module configured to send the first data to be transmitted and/or receive the second data to be transmitted through the first port.
  • the stop monitoring module is further configured to:
  • the data sending apparatus further includes:
  • a first sending module configured to send an information acquisition request to the traversal auxiliary server
  • a first receiving module configured to receive the address information and the NAT type of the terminal sent by the traversal auxiliary server
  • the second sending module is configured to send the received address information and the NAT type to the access management server;
  • the second receiving module is configured to receive the address information and the NAT type of the terminal to be accessed fed back by the access management server.
  • the data sending apparatus further includes:
  • the generating module is configured to generate the ith first access request data packet based on the received address information of the terminal to be accessed and the source port corresponding to the ith file descriptor.
  • using fewer file descriptors provides a higher success rate for establishing a connection, and occupying fewer file descriptors can improve the utilization rate of file descriptors, save public resources, and use as few files as possible.
  • Descriptors perform the same function.
  • the above is a schematic solution of a data sending apparatus according to this embodiment. It should be noted that the technical solution of the data sending device and the technical solution of the above-mentioned data sending method belong to the same concept, and the details that are not described in detail in the technical solution of the data sending device can be referred to the description of the technical solution of the above-mentioned data sending method. .
  • the present application also provides a system for establishing a P2P connection, as shown in FIG. 2 , including a port-restricted NAT, a first terminal under the port-restricted NAT, a symmetric NAT, and a second terminal under the symmetric NAT A terminal, the first terminal is configured to send n 2 second access request data packets at a second preset time interval t 2 through a file descriptor, wherein the destination IP address in the n 2 second access request data packets The address is the same and the destination port is different;
  • the second terminal corresponds to the destination IP address, and the second terminal is configured to perform the following steps:
  • S1 establish a queue accommodating m file descriptors for n 1 first access request data packets, where 2 ⁇ m ⁇ n 1;
  • S2 Create the i-th file descriptor in the queue, send the i-th first access request data packet through the i-th file descriptor, and perform the processing on the source port recorded by the i-th file descriptor monitoring, wherein the i-th file descriptor and the i-th first access request data packet have the same source port, where 1 ⁇ i ⁇ n 1 ;
  • the first terminal is configured to: within a listening time period of t 2 *n 2 +t 1 *n 1 of the source port of the first terminal, the port-restricted NAT listens to the first terminal's When the source port receives the first access request data packet from the second terminal, obtain the address information in the first access request data packet, and send a response data packet to the obtained address information;
  • the symmetric NAT is configured to: monitor that the first port of the second terminal receives a response data packet, and stop monitoring other source ports, wherein the first port corresponds to the obtained address information.
  • FIG. 6 shows a structural block diagram of a computing device 600 according to an embodiment of the present application.
  • Components of the computing device 600 include, but are not limited to, memory 610 and processor 620 .
  • the processor 620 is connected with the memory 610 through the bus 630, and the database 650 is used for storing data.
  • Computing device 600 also includes access device 640 that enables computing device 600 to communicate via one or more networks 660 .
  • 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 640 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 600 and other components not shown in FIG. 6 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. 6 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 600 may be any type of stationary or mobile computing device, including mobile computers or mobile computing devices (eg, tablet computers, personal digital assistants, laptop computers, 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 600 may also be a mobile or stationary server.
  • the steps of the data sending method are implemented when the processor 620 executes the instructions.
  • 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 data sending method belong to the same concept. For details not described in detail in the technical solution of the computing device, refer to the description of the technical solution of the above-mentioned data sending method.
  • 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, implements the steps of the foregoing data sending method.
  • 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 data sending method belong to the same concept, and the details not described in detail in the technical solution of the storage medium can be referred to the description of the technical solution of the above-mentioned data sending method.
  • 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 data sending method.
  • 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)

Abstract

本申请提供数据发送方法、装置以及建立P2P连接的方法及系统,其中数据发送方法包括:S1:为n 1个第一访问请求数据包建立容纳m个文件描述符的队列;S2:在队列中创建第i个文件描述符并通过第i个文件描述符发送第i个第一访问请求数据包,并对第i个文件描述符记录的源端口进行监控;S3:每间隔第一预设时间间隔t 1,令i自增1,继续执行步骤S2,并且为每个源端口设置预设监听时间T,T=t 1*m;S4:在m*j<i≤m*(j+1)的情况下,在队列中创建第i个文件描述符时,结束对第i-m个源端口的监听并销毁对应的文件描述符,直至监听到第一端口接收到响应数据包,停止对其他源端口的监听,第一端口为处于被监听状态的任意一个源端口。

Description

数据发送方法及装置、建立P2P连接的方法及系统
本申请要求于2021年1月6日提交中国专利局、申请号为202110011585.7、发明名称为“数据发送方法及装置、建立P2P连接的方法及系统”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请实施例涉及通信技术领域,特别涉及一种数据发送方法。本申请一个或者多个实施例同时涉及一种数据发送装置,一种建立P2P连接的方法及系统,一种计算设备,一种计算机可读存储介质,以及一种计算机程序产品。
背景技术
NAT技术是一种把内部网络私有IP地址转换为外部网络公共IP地址的技术,它使得一定范围内的多台主机只利用一个公共IP地址连接到外网。NAT技术虽然在一定程度上解决了IPv4地址短缺的问题,却破坏了端到端(P2P)的网络通信,主要原因是NAT不允许外网主机主动访问内网主机。NAT类型分为4种:全锥形、受限锥型、端口受限型与对称型,共有10种组合,其中,端口受限型-对称型和对称型-对称型两种组合类型还没有很好的打洞解决方案。因为若有一方是对称型NAT,路由器会根据目的地址的不同而映射到不同的地址和端口,只有当主机曾经给外部主机(IP_x,Port_x)发送过数据包时,来自外部主机(IP_x,Port_x)的数据包才能被对称型NAT路由器接收。
因此,需要提供端口受限型-对称型的一种打洞解决方案。
发明内容
有鉴于此,本申请实施例提供了一种数据发送方法。本申请一个或者多个实施例同时涉及一种数据发送装置,一种建立P2P连接的方法及系统,一种计算设备,一种计算机可读存储介质,以及一种计算机程序产品,以解决现有技术中存在的技术缺陷。
根据本申请实施例的第一方面,提供了一种数据发送方法,应用于处于对称型NAT下的终端,包括:
S1:为n 1个第一访问请求数据包建立容纳m个文件描述符的队列,其中,2≤m<n 1
S2:在所述队列中创建第i个文件描述符并通过所述第i个文件描述符发送第i个第一访问请求数据包,并对所述第i个文件描述符记录的源端口进行监控,其中,所述第i个文件描述符与所述第i个第一访问请求数据包具有相 同的源端口,其中1≤i≤n 1
S3:每间隔第一预设时间间隔t 1,令i自增1,继续执行步骤S2,并且为每个源端口设置预设监听时间T,其中,每个文件描述符记录不同源端口,T=t 1*m;
S4:在m*j<i≤m*(j+1)的情况下,在所述队列中创建第i个文件描述符时,结束对第i-m个源端口的监听并销毁对应的文件描述符,直至监听到第一端口接收到响应数据包,停止对其他源端口的监听,其中,j≥1,所述第一端口为处于被监听状态的任意一个源端口。
可选的,数据发送方法还包括:若在第n 1个文件描述符记录的源端口的预设监听时间T结束时仍没有接收到响应数据包,则重新执行为n 1个第一访问请求数据包建立容纳m个文件描述符的队列的步骤。
可选的,数据发送方法还包括:通过所述第一端口发送第一待传输数据和/或接收第二待传输数据。
可选的,所述直至监听到第一端口接收到响应数据包,停止对其他源端口的监听包括:
在监听到第一端口接收到响应数据包的情况下,销毁其他源端口对应的文件描述符。
可选的,在为n 1个第一访问请求数据包建立容纳m个文件描述符的队列之前,还包括:
向穿越辅助服务器发送信息获取请求;
接收所述穿越辅助服务器发送的所述终端的地址信息和NAT类型;
将所接收的地址信息和NAT类型发送至访问管理服务器;
接收所述访问管理服务器反馈的待访问端的地址信息和NAT类型。
可选的,所述通过所述第i个文件描述符发送第i个第一访问请求数据包之前,还包括:
基于所接收的所述待访问端的地址信息以及所述第i个文件描述符对应的源端口,生成所述第i个第一访问请求数据包。
根据本申请实施例的第二方面,提供了一种建立P2P连接的方法,包括:
第一终端通过一个文件描述符以第二预设时间间隔t 2发送n 2个第二访问请求数据包,其中,所述第一终端处于端口受限型NAT下,所述n 2个第二访问请求数据包中的目的IP地址相同且目的端口不同;
与所述目的IP地址对应的处于对称型NAT下的第二终端执行以下操作:
S1:为n 1个第一访问请求数据包建立容纳m个文件描述符的队列,其中,2≤m<n 1
S2:在所述队列中创建第i个文件描述符并通过所述第i个文件描述符发送第i个第一访问请求数据包,并对所述第i个文件描述符记录的源端口进行监控,其中,所述第i个文件描述符与所述第i个第一访问请求数据包具有相同的源端口,其中1≤i≤n 1
S3:每间隔第一预设时间间隔t 1,令i自增1,继续执行步骤S2,并且为每个源端口设置预设监听时间T,其中,每个文件描述符记录不同源端口,T=t 1*m;
S4:在m*j<i≤m*(j+1)的情况下,在所述队列中创建第i个文件描述符时,结束对第i-m个源端口的监听并销毁对应的文件描述符;
在所述第一终端的源端口的t 2*n 2+t 1*n 1监听时间段内,所述端口受限型NAT监听到所述第一终端的源端口接收到来自所述第二终端的第一访问请求数据包的情况下,所述第一终端获得第一访问请求数据包中的地址信息,并且向获得的地址信息发送响应数据包;
所述对称型NAT监听到所述第二终端的第一端口接收到响应数据包,停止对其他源端口的监听,其中,所述第一端口与所述获得的地址信息对应。
可选的,建立P2P连接的方法还包括:
若在第n 1个文件描述符记录的源端口的预设监听时间T结束时仍没有接收到响应数据包,则在预设条件下重新执行第一终端通过一个文件描述符以第二预设时间间隔t 2发送n 2个第二访问请求数据包的步骤。
可选的,在第一终端通过一个文件描述符以第二预设时间间隔t 2发送n 2个第二访问请求数据包之前,还包括:
所述第一终端和所述第二终端分别向穿越辅助服务器发送信息获取请求;
所述第一终端和所述第二终端分别接收所述穿越辅助服务器发送的各自的地址信息和NAT类型;
所述第一终端和所述第二终端将所接收的各自的地址信息和NAT类型发送至访问管理服务器;
所述第一终端接收所述访问管理服务器反馈的所述第二终端的地址信息和NAT类型,并且所述第二终端接收所述访问管理服务器反馈的所述第一终端的地址信息和NAT类型。
可选的,在第一终端通过一个文件描述符以第二预设时间间隔t 2发送n 2个第二访问请求数据包之前,还包括:
将第二终端的初始端口设置为随机数,并且为所述n 2个第二访问请求数据包设置端口编号之间的间隔相同的目的端口;
基于所接收的所述第二终端的地址信息中的IP地址、所设置的目的端口以及所述文件描述符对应的源端口,生成所述第二访问请求数据包。
可选的,所述将第二终端的初始端口设置为随机数,并且为所述n 2个第二访问请求数据包设置端口编号之间的间隔相同的目的端口,包括:
将第二终端的初始端口设置为与n 2相关的随机数与预设值之和;
将每个第二访问请求数据包的目的端口与前一第二访问请求数据包的目的端口间隔设置为与所述预设值相关的固定值。
可选的,在所述第一终端发送n 2个第二访问请求数据包时,建立第一终端的地址信息与所述第二终端的地址信息之间的第一映射关系,在所述第二终端发送n 1个第一访问请求数据包时,建立所述第二终端的地址信息与所述第一终端的地址信息之间的第二映射关系,所述监听到所述第一终端的源端口接收到来自所述第二终端的第一访问请求数据包包括:
将所述第一映射关系与所述第二映射关系进行比较,若有匹配的映射关系,则监听到所述第一终端的源端口接收到来自所述第二终端的第一访问请求数据包。
可选的,建立P2P连接的方法还包括:
由所述第二终端通过所述第一端口向所述第一终端的文件描述符对应的源端口发送第一待传输数据;和/或
由所述第一终端通过所述第一终端的文件描述符对应的源端口向所述第一端口发送第二待传输数据。
可选的,n 1=n 2且t 1=t 2
可选的,所述第一访问请求数据包和所述第二访问请求数据包包括UDP报文。
根据本申请实施例的第三方面,提供了一种数据发送装置,应用于处于对称型NAT下的终端,包括:
建立模块,被配置成执行步骤S1:为n 1个第一访问请求数据包建立容纳m个文件描述符的队列,其中,2≤m<n 1
创建发送模块,被配置成执行步骤S2:在所述队列中创建第i个文件描述符并通过所述第i个文件描述符发送第i个第一访问请求数据包,并对所述第i个文件描述符记录的源端口进行监控,其中,所述第i个文件描述符与所述第i个第一访问请求数据包具有相同的源端口,其中1≤i≤n 1
设置模块,被配置成执行步骤S3:每间隔第一预设时间间隔t 1,令i自增1,继续执行步骤S2,并且为每个源端口设置预设监听时间T,其中,每个文件描述符记录不同源端口,T=t 1*m;
停止监听模块,被配置成执行步骤S4:在m*j<i≤m*(j+1)的情况下,在所述队列中创建第i个文件描述符时,结束对第i-m个源端口的监听并销毁对应的文件描述符,直至监听到第一端口接收到响应数据包,停止对其他源端口的监听,其中,j≥1,所述第一端口为处于被监听状态的任意一个源端口。
根据本申请实施例的第四方面,提供了一种建立P2P连接的系统,包括端口受限型NAT、处于端口受限型NAT下的第一终端、对称型NAT及处于对称型NAT下的第二终端,
所述第一终端被配置成通过一个文件描述符以第二预设时间间隔t 2发送n 2个第二访问请求数据包,其中,所述n 2个第二访问请求数据包中的目的IP地址相同且目的端口不同;
所述第二终端与所述目的IP地址对应,并且所述第二终端被配置成执行以下步骤:
S1:为n 1个第一访问请求数据包建立容纳m个文件描述符的队列,其中,2≤m<n 1
S2:在所述队列中创建第i个文件描述符并通过所述第i个文件描述符发送第i个第一访问请求数据包,并对所述第i个文件描述符记录的源端口进行监控,其中,所述第i个文件描述符与所述第i个第一访问请求数据包具有相同的源端口,其中1≤i≤n 1
S3:每间隔第一预设时间间隔t 1,令i自增1,继续执行步骤S2,并且为每个源端口设置预设监听时间T,其中,每个文件描述符记录不同源端口,T=t 1*m;
S4:在m*j<i≤m*(j+1)的情况下,在所述队列中创建第i个文件描述符时,结束对第i-m个源端口的监听并销毁对应的文件描述符;
所述第一终端被配置成:在所述第一终端的源端口的t 2*n 2+t 1*n 1监听时间段内,所述端口受限型NAT监听到所述第一终端的源端口接收到来自所述第 二终端的第一访问请求数据包的情况下,获得第一访问请求数据包中的地址信息,并且向获得的地址信息发送响应数据包;
所述对称型NAT被配置成:监听到所述第二终端的第一端口接收到响应数据包,停止对其他源端口的监听,其中,所述第一端口与所述获得的地址信息对应。
根据本申请实施例的第五方面,提供了一种计算设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机指令,所述处理器执行所述计算机指令时实现所述数据发送方法的步骤。
根据本申请实施例的第六方面,提供了一种计算机可读存储介质,其存储有计算机指令,该计算机指令被处理器执行时实现所述数据发送方法的步骤。
根据本申请实施例的第七方面,提供了一种计算机程序产品,当所述计算机程序产品在计算机中执行时,令计算机执行任意上述数据发送方法的步骤。
本申请提供的数据发送方法,通过在处于对称型NAT下的终端利用容纳m个文件描述符的队列并且每个文件描述符设置合适的监听时间使得该终端侧仅利用m个文件描述符发送相对大量的数据包,使用较少文件描述符提供较高建立连接的成功率,占用较少的文件描述符可以提高文件描述符的利用率,节约公共资源,用尽可能少的文件描述符实现相同功能。
附图说明
图1是本申请一实施例提供的一种建立P2P连接的方法的流程图;
图2是本申请一实施例提供的一种P2P连接的系统的结构示意图;
图3是本申请一实施例提供的由处于对称型NAT下的第二终端执行的一种数据发送方法的处理流程图;
图4是本申请一实施例提供的一种建立P2P连接的方法的处理流程图;
图5是本申请一实施例提供的一种数据发送装置的结构示意图;
图6是本申请一实施例提供的一种计算设备的结构框图。
具体实施方式
在下面的描述中阐述了很多具体细节以便于充分理解本申请。但是本申请能够以很多不同于在此描述的其它方式来实施,本领域技术人员可以在不违背本申请内涵的情况下做类似推广,因此本申请不受下面公开的具体实施的限制。
在本申请一个或多个实施例中使用的术语是仅仅出于描述特定实施例的目的,而非旨在限制本申请一个或多个实施例。在本申请一个或多个实施例和所附权利要求书中所使用的单数形式的“一种”、“所述”和“该”也旨在包 括多数形式,除非上下文清楚地表示其他含义。还应当理解,本申请一个或多个实施例中使用的术语“和/或”是指并包含一个或多个相关联的列出项目的任何或所有可能组合。
应当理解,尽管在本申请一个或多个实施例中可能采用术语第一、第二等来描述各种信息,但这些信息不应限于这些术语。这些术语仅用来将同一类型的信息彼此区分开。例如,在不脱离本申请一个或多个实施例范围的情况下,第一也可以被称为第二,类似地,第二也可以被称为第一。取决于语境,如在此所使用的词语“如果”可以被解释成为“在……时”或“当……时”或“响应于确定”。
在本申请中,提供了一种数据发送方法,本申请同时涉及一种数据发送装置、一种建立P2P连接的方法、一种建立P2P连接的系统、一种计算设备、一种计算机可读存储介质以及一种计算机程序产品,在下面的实施例中逐一进行详细说明。
图1示出了根据本申请一实施例提供的一种建立P2P连接的方法的流程图,具体包括以下步骤:
步骤102:第一终端通过一个文件描述符以第二预设时间间隔t 2发送n 2个第二访问请求数据包,其中,所述第一终端处于端口受限型NAT下,所述n 2个第二访问请求数据包中的目的IP地址相同且目的端口不同。
在该步骤之前,第一终端和处于对称型NAT下的第二终端分别向穿越辅助服务器发送信息获取请求,穿越辅助服务器向第一终端和第二终端发送第一、第二终端各自的地址信息和NAT类型,第一终端和第二终端将所接收的各自的地址信息和NAT类型发送至访问管理服务器,访问管理服务器向第一终端反馈第二终端的地址信息和NAT类型,并且向第二终端反馈第一终端的地址信息和NAT类型。地址信息包括第一终端和第二终端的外网IP和外网端口以及内网IP和内网端口四元组即(IP-A、Port-A、IP-natA、Port-natA)、(IP-B、Port-B、IP-natB、Port-natB)。穿越辅助服务器是诸如STUN服务器的服务器,访问管理服务器是诸如Tracker服务器的服务器,访问管理服务器根据同一请求资源ID将播放相同资源的节点信息发送给各个终端,第一终端与第二终端分别获得对端的内网、公网地址四元组及NAT类型。
在第一终端获得第二终端的内网、公网地址四元组及NAT类型之后,第一终端利用之前与穿越辅助服务器建连的文件描述符以同一源端口以第二预设时间间隔t2发送第二访问请求数据包,第二访问请求数据包可以是UDP报文或TCP报文,在一种实施例中,采用UDP报文,实时性更佳。n 2个第二访 问请求数据包中,目的IP地址相同,均为第二终端的外网IP地址,n 2个第二访问请求数据包的目的IP地址为第二终端的外网IP地址,所有第二访问请求数据包的目的端口不同,其中,n 2可以根据经验确定,是预先确定的一定范围内的一个值。
在一种可选的实施例中,通过以下来实现使所有第二访问请求数据包的目的端口不同:
将第二终端的初始端口设置为随机数,并且为n 2个第二访问请求数据包设置端口编号之间的间隔相同的目的端口;
基于所接收的第二终端的地址信息中的IP地址、所设置的目的端口以及文件描述符对应的源端口,生成第二访问请求数据包。
每两个前后相继发送的第二访问请求数据包的目的端口号之间的间隔相同
在一种可选的实施例中,将第二终端的初始端口设置为随机数,并且为所述n 2个第二访问请求数据包设置端口编号之间的间隔相同的目的端口可以通过以下实现:
将第二终端的初始端口设置为与n 2相关的随机数与预设值之和;
将每个第二访问请求数据包的目的端口与前一第二访问请求数据包的目的端口间隔设置为与该预设值相关的固定值。
例如,在0至1023的端口为固有协议的端口的情况下,预设值可以设置为1024,则自动分配时不会分配这些端口,可以提高打洞成功率。具体地,例
Figure PCTCN2022070246-appb-000001
的端口间隔设置为该值可以将端口拉开间隔,第二终端映射关系与该目的端口匹配度提高,提高P2P连接建立的成功率。通过分配不同的初始端口并且之后的每个端口与前一端口间隔距离相同,避免在第一终端与第三终端或者更多其他终端建连时覆盖之前与第二终端建连时在第一终端的端口受限型NAT上留下的映射信息,使得两两终端的建连相互独立,能够有效地提高建连成功率。
第一终端通过一个文件描述符建立第二访问请求数据包,目的IP地址为第二终端的外网IP地址,目的端口为所设置的上述初始端口,第二访问请求数据包的发送次数记为count1=1。在第二预设时间间隔之后,利用同一文件描述符建立第二访问请求数据包,目的IP地址不变,目的端口变为
Figure PCTCN2022070246-appb-000002
第二访问请求数据包的发送次数count1=count1+1,每个第 二预设时间间隔执行上述操作,直至第二访问请求数据包的发送次数为n 2次,停止发送第二访问请求数据包。
尽管所有第二访问请求数据包都会被第二终端的对称型NAT丢弃,但是会在第一终端的端口受限型NAT下建立可以接收来自第二终端的对称型NAT的n 2个不同端口的数据包请求的映射关系,后续只要来自第二终端的对称型NAT的数据包属于这n 2个映射关系中的一个,则可以打洞成功。
步骤104:与所述目的IP地址对应的处于对称型NAT下的第二终端执行数据发送操作。
该数据发送操作包括:
S1:为n 1个第一访问请求数据包建立容纳m个文件描述符的队列,其中,2≤m<n 1
S2:在所述队列中创建第i个文件描述符并通过所述第i个文件描述符发送第i个第一访问请求数据包,并对所述第i个文件描述符记录的源端口进行监控,其中,所述第i个文件描述符与所述第i个第一访问请求数据包具有相同的源端口,其中1≤i≤n 1
S3:每间隔第一预设时间间隔t 1,令i自增1,继续执行步骤S2,并且为每个源端口设置预设监听时间T,其中,每个文件描述符记录不同源端口,T=t 1*m;
在创建第i个文件描述符之后间隔第一预设时间间隔t 1,在队列中创建第i+1个文件描述符,通过第i+1个文件描述符发送第i+1个第一访问请求数据包,对第i+1个文件描述符记录的源端口进行监控,第i+1个文件描述符与第i+1个第一访问请求数据包具有相同的源端口,在创建第i+1个文件描述符之后间隔第一预设时间间隔t 1,在队列中创建第i+2个文件描述符,通过第i+2个文件描述符发送第i+2个第一访问请求数据包,对第i+2个文件描述符记录的源端口进行监控,第i+2个文件描述符与第i+2个第一访问请求数据包具有相同的源端口,以此类推,令i自增1,在每次i自增1后,创建完相应文件描述符并基于文件描述符发送第一访问请求数据包之后,进入下一步骤。
S4:在m*j<i≤m*(j+1)的情况下,在所述队列中创建第i个文件描述符时,结束对第i-m个源端口的监听并销毁对应的文件描述符。
第二终端等待t 2*n 2时间段后,初始化一个可以容纳m个文件描述符的空队列,创建第一个文件描述符并添加至队列中,建立目的地址是第一终端的外 网IP地址和端口的第一访问请求数据包,通过该文件描述符进行发送,该文件描述符与第一访问请求数据包具有相同源端口。间隔第一预设时间间隔t 1之后,创建第二个文件描述符并且添加至队列中,建立目的地址是第一终端的IP地址和端口的第一访问请求数据包,通过第二个文件描述符进行发送,该文件描述符与该第一访问请求数据包具有相同源端口,源端口是系统自动分配的一个未使用的端口号作为发送端口,每个文件描述符设置有预设监听时间T=t 1*m。创建第m个文件描述符并通过该文件描述符发送第一访问请求数据包之后,在第一预设时间间隔t 1之后,创建第m+1个文件描述符,由于队列中的第一个文件描述符监听时间结束,因此结束对第一个文件描述符对应的第1个源端口的监听并销毁第一个文件描述符,并将新建的第m+1个文件描述符添加至队列,重复上述步骤,直至创建n 1个文件描述符。n 1与n 2可以相同也可以不同,并且第一预设时间间隔t 1与第二预设时间间隔t 2可以相同也可以不同。
第一预设时间间隔t 1可以根据访问请求数据包发送时的丢包率等来确定,若值太小,丢包率高,根据情况选择合适的第一预设时间间隔t 1。在一实施例中,第一预设时间间隔t 1设置为50ms。监听时间T=t 1*m,监听时间可以根据实际情况设置,若监听时间太短,可能第一终端给第二终端发送了响应包,但由于网络拥塞,导致还未收到就停止监听。若监听时间太长,导致建连时间太长,占用了建连后的P2P传输数据。在一种可选的实施例中,监听时间设置为1s。
步骤106:在所述第一终端的源端口的t 2*n 2+t 1*n 1监听时间段内,端口受限型NAT监听到所述第一终端的源端口接收到来自所述第二终端的第一访问请求数据包的情况下,所述第一终端获得第一访问请求数据包中的地址信息,并且向获得的地址信息发送响应数据包。
第一终端所使用的文件描述符设置的监听时间为t 2*n 2+t 1*n 1,若在该监听时间内,端口受限型NAT监听到该文件描述符对应的源端口接收到来自第二终端的对称型NAT的第一访问请求数据包,对第一访问请求数据包进行拆包,获得其中的地址信息,第一终端向该地址信息发送响应数据包。
步骤108:对称型NAT监听到第二终端的第一端口接收到响应数据包,停止对其他源端口的监听,其中,所述第一端口与所述获得的地址信息对应。
若队列中任一文件描述符对应的端口收到第一终端的响应数据包,则记录该文件描述符对应的地址信息,停止对其他源端口的监听,清空队列。
根据本实施例的建立P2P连接的方法,在端口受限型NAT侧使用1个文 件描述符、在对称型NAT侧使用m个文件描述符,利用较少文件描述符提供较高建立连接的成功率,占用较少的文件描述符可以提高文件描述符的利用率,节约公共资源,用尽可能少的文件描述符实现相同功能。
若在第n 1个文件描述符记录的源端口的预设监听时间T结束时仍没有接收到响应数据包,则在预设条件下重新执行第一终端通过一个文件描述符以第二预设时间间隔t 2发送n 2个第二访问请求数据包的步骤。
预设条件可以为重新检测到外网地址或者检测到网络切换,例如网络从移动网切换到WIFI或从WIFI切换到移动网,则重新建连,执行步骤102至108。
如图2所示,第一终端处于端口受限型NAT路由器203,也称端口受限型NAT,第二终端处于对称型NAT路由器204,也称对称型NAT。在第一终端发送n 2个第二访问请求数据包时,建立第一终端的地址信息与第二终端的地址信息之间的第一映射关系,在第二终端发送n 1个第一访问请求数据包时,建立第二终端的地址信息与第一终端的地址信息之间的第二映射关系,第一映射关系如图2中的201所示,第二映射关系如图2中的202所示。监听到所述第一终端的源端口接收到来自所述第二终端的第一访问请求数据包可以通过以下实现:
将第一映射关系与第二映射关系进行比较,若有匹配的映射关系,则监听到第一终端的源端口接收到来自第二终端的第一访问请求数据包。
发送n 2个第二访问请求数据包时,建立了n 2个第一映射关系(IP 1,Port 1,IP 2,Port 2),发送n 1个第一访问请求数据包时,建立了n 1个第二映射关系(IP 2,Port 2,IP 1,Port 1),两个映射关系中IP 1、IP 2以及Port 1是匹配的,若其中有一个第二映射关系中的Port 2与一个第一映射关系中的Port 2匹配,则可以监听到第一终端接收到第一访问请求数据包。例如,第一终端通过端口Port 1发送至第二终端的端口Port 2n,即第一映射关系中的Port 2为Port 2n,若第二终端通过端口Port 2n发送至第一终端的端口Port 1,即第二映射关系中的Port 2也为Port 2n,则映射关系匹配,第一终端的源端口成功接收到第一访问请求数据包。
在第一终端与第二终端之间建立P2P连接之后,由第二终端通过第一端口向第一终端的文件描述符对应的源端口发送第一待传输数据;和/或由第一终端通过第一终端的文件描述符对应的源端口向所述第一端口发送第二待传输数据,开始数据传输。例如通过上述Port 2n传输数据。
图3示出了由处于对称型NAT下的第二终端执行的一种数据发送方法的处理流程图,包括:
步骤302:为n 1个第一访问请求数据包建立容纳m个文件描述符的队列,其中,2≤m<n 1
步骤304:在所述队列中创建第i个文件描述符并通过所述第i个文件描述符发送第i个第一访问请求数据包,并对所述第i个文件描述符记录的源端口进行监控,其中,所述第i个文件描述符与所述第i个第一访问请求数据包具有相同的源端口,其中1≤i≤n 1
步骤306:每间隔第一预设时间间隔t 1,令i自增1,继续执行步骤304,并且为每个源端口设置预设监听时间T,其中,每个文件描述符记录不同源端口,T=t 1*m;
在创建第i个文件描述符之后间隔第一预设时间间隔t 1,在队列中创建第i+1个文件描述符,通过第i+1个文件描述符发送第i+1个第一访问请求数据包,对第i+1个文件描述符记录的源端口进行监控,第i+1个文件描述符与第i+1个第一访问请求数据包具有相同的源端口,在创建第i+1个文件描述符之后间隔第一预设时间间隔t 1,在队列中创建第i+2个文件描述符,通过第i+2个文件描述符发送第i+2个第一访问请求数据包,对第i+2个文件描述符记录的源端口进行监控,第i+2个文件描述符与第i+2个第一访问请求数据包具有相同的源端口,以此类推,令i自增1,在每次i自增1后,创建完相应文件描述符并基于文件描述符发送第一访问请求数据包。
步骤308:判断是否满足m*j<i≤m*(j+1),若是,则执行步骤310;若否则执行步骤304;
步骤310:在所述队列中创建第i个文件描述符时,结束对第i-m个源端口的监听并销毁对应的文件描述符,继续执行步骤312;
步骤312:判断是否监听到第一端口接收到响应数据包,若是,则执行步骤314;若否,则执行步骤304;
步骤314:停止对其他源端口的监听,其中,j≥1,所述第一端口为处于被监听状态的任意一个源端口。
根据本实施例的数据发送方法,通过在处于对称型NAT下的终端利用容纳m个文件描述符的队列并且每个文件描述符设置合适的监听时间使得该终端侧仅利用m个文件描述符发送相对大量的数据包,使用较少文件描述符提供较高建立连接的成功率,占用较少的文件描述符可以提高文件描述符的利用率,节约公共资源,用尽可能少的文件描述符实现相同功能。
可选地,若在第n 1个文件描述符记录的源端口的预设监听时间T结束时 仍没有接收到响应数据包,则重新执行为n 1个第一访问请求数据包建立容纳m个文件描述符的队列的步骤。
可选地,所述直至监听到第一端口接收到响应数据包,停止对其他源端口的监听包括:
可选地,在监听到第一端口接收到响应数据包的情况下,销毁其他源端口对应的文件描述符。
可选地,在为n 1个第一访问请求数据包建立容纳m个文件描述符的队列之前,还包括:
向穿越辅助服务器发送信息获取请求;
接收所述穿越辅助服务器发送的所述终端的地址信息和NAT类型;
将所接收的地址信息和NAT类型发送至访问管理服务器;
接收所述访问管理服务器反馈的待访问端的地址信息和NAT类型。
所述通过所述第i个文件描述符发送第i个第一访问请求数据包之前,还包括:
基于所接收的所述待访问端的地址信息以及所述第i个文件描述符对应的源端口,生成所述第i个第一访问请求数据包。
下述结合附图4,以本申请提供的建立P2P连接的方法的具体应用为例,对所述建立P2P连接的方法进行进一步说明。其中,图4示出了本申请一实施例提供的一种建立P2P连接的方法的处理流程图,具体包括以下步骤:
步骤402:第一终端和第二终端分别向STUN服务器发送信息获取请求,接收STUN服务器发送的各自的地址信息和NAT类型。
第一终端处于端口受限型NAT下,第二终端处于对称型NAT下。第一终端与第二终端分别通过STUN服务器获得自身的内网、公网地址四元组及NAT类型。
步骤404:第一终端和第二终端将接收的各自的地址信息和NAT类型发送至Tracker服务器,并且接收Tracker服务器反馈的对端的内网、公网地址四元组及NAT类型。
Tracker服务器可以根据同一请求资源ID将播放相同资源的节点信息发送给各个终端。第一终端和第二终端分别获得对端的内网、公网地址四元组及NAT类型。
步骤406:第一终端通过一个文件描述符每50ms发送1个UDP报文, 共发送400个UDP报文,其中,400个UDP报文中的目的IP地址相同且目的端口不同。
400个UDP报文中的目的IP地址相同,均为第二终端的外网IP地址,所有UDP报文的目的端口不同。
步骤406中设置目的端口可以通过以下实现:将第二终端的初始端口设置
Figure PCTCN2022070246-appb-000003
0至1023的端口为固有协议的端口,自动分配时不会分配这些端口,可以提高打洞成功率。将目的端口间隔设置为该值可以将端口拉开间隔,第二终端映射关系与该目的端口匹配度提高,提高P2P连接建立的成功率。通过分配不同的初始端口并且之后的每个端口与前一端口间隔距离相同,避免在第一终端与第三终端或者更多其他终端建连时覆盖之前与第二终端建连时在第一终端的端口受限型NAT上留下的映射信息,使得两两终端的建连相互独立,能够有效地提高建连成功率。
步骤408:与目的IP地址对应的第二终端为400个UDP报文建立容纳20个文件描述符的队列。
步骤410:第二终端在队列中创建第1个文件描述符并通过第1个文件描述符发送第1个UDP报文,并对第1个文件描述符记录的源端口进行监控,其中,第1个文件描述符与第1个UDP报文具有相同的源端口。
步骤412:每间隔50ms,继续执行在所述队列中创建文件描述符并且基于创建的文件描述符发送UDP报文,对创建的文件描述符记录的源端口进行监控,并且为每个源端口设置预设监听时间1s,其中,每个文件描述符记录不同源端口,每个文件描述符与利用其发送的UDP报文具有相同源端口。
步骤414:在创建第21个文件描述符时,结束对第1个源端口的监听并销毁对应的文件描述符。
步骤416:重复上述步骤,直至创建400个文件描述符。
步骤418:在第一终端的源端口的40s的监听时间段内,端口受限型NAT监听到第一终端的源端口接收到来自第二终端的UDP报文的情况下,第一终端获得UDP报文中的地址信息,并且向获得的地址信息发送响应数据包。
第一终端的源端口的监听时间段设置为50ms*400+50ms*400=40s。在该监听时间段收到报文,则获得该UDP报文中的地址信息
步骤420:对称型NAT监听到第二终端的第一端口接收到响应数据包, 停止对其他源端口的监听,其中,所述第一端口与所述获得的地址信息对应。
若队列中任一文件描述符对应的端口收到第一终端的响应数据包,则记录该文件描述符对应的地址信息,销毁其他文件描述符。由第二终端通过第一端口向第一终端的文件描述符对应的源端口发送第一待传输数据;和/或由第一终端通过第一终端的文件描述符对应的源端口向所述第一端口发送第二待传输数据,开始数据传输。
根据本实施例的建立P2P连接的方法,通过在第二终端利用容纳20个文件描述符的队列并且每个文件描述符设置合适的监听时间1s使得在第二终端侧仅利用20个文件描述符发送400个数据包,使用较少文件描述符提供较高建立连接的成功率,占用较少的文件描述符可以提高文件描述符的利用率,节约公共资源,用尽可能少的文件描述符实现相同功能。
与上述方法实施例相对应,本申请还提供了数据发送装置实施例,应用于处于对称型NAT下的终端。图5示出了本申请一实施例提供的一种数据发送装置的结构示意图。如图5所示,该装置包括:
建立模块502,被配置成执行步骤S1:为n 1个第一访问请求数据包建立容纳m个文件描述符的队列,其中,2≤m<n 1
创建发送模块504,被配置成执行步骤S2:在所述队列中创建第i个文件描述符并通过所述第i个文件描述符发送第i个第一访问请求数据包,并对所述第i个文件描述符记录的源端口进行监控,其中,所述第i个文件描述符与所述第i个第一访问请求数据包具有相同的源端口,其中1≤i≤n 1
设置模块506,被配置成执行步骤S3:每间隔第一预设时间间隔t 1,令i自增1,继续执行步骤S2,并且为每个源端口设置预设监听时间T,其中,每个文件描述符记录不同源端口,T=t 1*m;
停止监听模块508,被配置成执行步骤S4:在m*j<i≤m*(j+1)的情况下,在所述队列中创建第i个文件描述符时,结束对第i-m个源端口的监听并销毁对应的文件描述符,直至监听到第一端口接收到响应数据包,停止对其他源端口的监听,其中,j≥1,所述第一端口为处于被监听状态的任意一个源端口。
在一种可选的实施例中,数据发送装置还包括:
执行模块,被配置为:若在第n 1个文件描述符记录的源端口的预设监听时间T结束时仍没有接收到响应数据包,则重新执行为n 1个第一访问请求数据包建立容纳m个文件描述符的队列的步骤。
在一种可选的实施例中,数据发送装置还包括:传输模块,被配置为通过 所述第一端口发送第一待传输数据和/或接收第二待传输数据。
在一种可选的实施例中,所述停止监听模块还被配置为:
在监听到第一端口接收到响应数据包的情况下,销毁其他源端口对应的文件描述符。
在一种可选的实施例中,数据发送装置还包括:
第一发送模块,被配置为向穿越辅助服务器发送信息获取请求;
第一接收模块,被配置为接收所述穿越辅助服务器发送的所述终端的地址信息和NAT类型;
第二发送模块,被配置为将所接收的地址信息和NAT类型发送至访问管理服务器;
第二接收模块,被配置为接收所述访问管理服务器反馈的待访问端的地址信息和NAT类型。
在一种可选的实施例中,数据发送装置还包括:
生成模块,被配置为基于所接收的所述待访问端的地址信息以及所述第i个文件描述符对应的源端口,生成所述第i个第一访问请求数据包。
根据本实施例的数据发送装置,使用较少文件描述符提供较高建立连接的成功率,占用较少的文件描述符可以提高文件描述符的利用率,节约公共资源,用尽可能少的文件描述符实现相同功能。
上述为本实施例的一种数据发送装置的示意性方案。需要说明的是,该数据发送装置的技术方案与上述的数据发送方法的技术方案属于同一构思,数据发送装置的技术方案未详细描述的细节内容,均可以参见上述数据发送方法的技术方案的描述。
本申请还提供了一种建立P2P连接的系统,如图2所示,包括端口受限型NAT、处于端口受限型NAT下的第一终端、对称型NAT及处于对称型NAT下的第二终端,第一终端被配置成通过一个文件描述符以第二预设时间间隔t 2发送n 2个第二访问请求数据包,其中,所述n 2个第二访问请求数据包中的目的IP地址相同且目的端口不同;
所述第二终端与所述目的IP地址对应,并且所述第二终端被配置成执行以下步骤:
S1:为n 1个第一访问请求数据包建立容纳m个文件描述符的队列,其中,2≤m<n 1;
S2:在所述队列中创建第i个文件描述符并通过所述第i个文件描述符发送第i个第一访问请求数据包,并对所述第i个文件描述符记录的源端口进行监控,其中,所述第i个文件描述符与所述第i个第一访问请求数据包具有相同的源端口,其中1≤i≤n 1
S3:每间隔第一预设时间间隔t 1,令i自增1,继续执行步骤S2,并且为每个源端口设置预设监听时间T,其中,每个文件描述符记录不同源端口,T=t 1*m;
S4:在m*j<i≤m*(j+1)的情况下,在所述队列中创建第i个文件描述符时,结束对第i-m个源端口的监听并销毁对应的文件描述符;
所述第一终端被配置成:在所述第一终端的源端口的t 2*n 2+t 1*n 1监听时间段内,所述端口受限型NAT监听到所述第一终端的源端口接收到来自所述第二终端的第一访问请求数据包的情况下,获得第一访问请求数据包中的地址信息,并且向获得的地址信息发送响应数据包;
所述对称型NAT被配置成:监听到所述第二终端的第一端口接收到响应数据包,停止对其他源端口的监听,其中,所述第一端口与所述获得的地址信息对应。
图6示出了根据本申请一实施例提供的一种计算设备600的结构框图。该计算设备600的部件包括但不限于存储器610和处理器620。处理器620与存储器610通过总线630相连接,数据库650用于保存数据。
计算设备600还包括接入设备640,接入设备640使得计算设备600能够经由一个或多个网络660通信。这些网络的示例包括公用交换电话网(PSTN)、局域网(LAN)、广域网(WAN)、个域网(PAN)或诸如因特网的通信网络的组合。接入设备640可以包括有线或无线的任何类型的网络接口(例如,网络接口卡(NIC))中的一个或多个,诸如IEEE802.11无线局域网(WLAN)无线接口、全球微波互联接入(Wi-MAX)接口、以太网接口、通用串行总线(USB)接口、蜂窝网络接口、蓝牙接口、近场通信(NFC)接口,等等。
在本申请的一个实施例中,计算设备600的上述部件以及图6中未示出的其他部件也可以彼此相连接,例如通过总线。应当理解,图6所示的计算设备结构框图仅仅是出于示例的目的,而不是对本申请范围的限制。本领域技术人员可以根据需要,增添或替换其他部件。
计算设备600可以是任何类型的静止或移动计算设备,包括移动计算机或移动计算设备(例如,平板计算机、个人数字助理、膝上型计算机、笔记本计算机、上网本等)、移动电话(例如,智能手机)、可佩戴的计算设备(例如, 智能手表、智能眼镜等)或其他类型的移动设备,或者诸如台式计算机或PC的静止计算设备。计算设备600还可以是移动式或静止式的服务器。
其中,处理器620执行所述指令时实现所述的数据发送方法的步骤。
上述为本实施例的一种计算设备的示意性方案。需要说明的是,该计算设备的技术方案与上述的数据发送方法的技术方案属于同一构思,计算设备的技术方案未详细描述的细节内容,均可以参见上述数据发送方法的技术方案的描述。
本申请一实施例还提供一种计算机可读存储介质,其存储有计算机指令,该指令被处理器执行时实现如前所述数据发送方法的步骤。
上述为本实施例的一种计算机可读存储介质的示意性方案。需要说明的是,该存储介质的技术方案与上述的数据发送方法的技术方案属于同一构思,存储介质的技术方案未详细描述的细节内容,均可以参见上述数据发送方法的技术方案的描述。
本申请一实施例还提供一种计算机程序产品,当所述计算机程序产品在计算机中执行时,令计算机执行任意上述数据发送方法的步骤。
上述为本实施例的一种计算机程序产品的示意性方案。需要说明的是,该计算机程序产品的技术方案与上述的数据发送方法的技术方案属于同一构思,计算机程序产品的技术方案未详细描述的细节内容,均可以参见上述数据发送选择方法的技术方案的描述。
上述对本申请特定实施例进行了描述。其它实施例在所附权利要求书的范围内。在一些情况下,在权利要求书中记载的动作或步骤可以按照不同于实施例中的顺序来执行并且仍然可以实现期望的结果。另外,在附图中描绘的过程不一定要求示出的特定顺序或者连续顺序才能实现期望的结果。在某些实施方式中,多任务处理和并行处理也是可以的或者可能是有利的。
所述计算机可执行指令包括计算机程序代码,所述计算机程序代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。所述计算机可读存储介质可以包括:能够携带所述计算机程序代码的任何实体或装置、记录介质、U盘、移动硬盘、磁碟、光盘、计算机存储器、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、电载波信号、电信信号以及软件分发介质等。需要说明的是,所述计算机可读存储介质包含的内容可以根据司法管辖区内立法和专利实践的要求进行适当的增减,例如在某些司法管辖区,根据立法和专利实践,计算机可读存储介质不包括电载波信号和电信信号。
需要说明的是,对于前述的各方法实施例,为了简便描述,故将其都表述为一系列的动作组合,但是本领域技术人员应该知悉,本申请并不受所描述的动作顺序的限制,因为依据本申请,某些步骤可以采用其它顺序或者同时进行。其次,本领域技术人员也应该知悉,申请中所描述的实施例均属于优选实施例,所涉及的动作和模块并不一定都是本申请所必须的。
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其它实施例的相关描述。
以上公开的本申请优选实施例只是用于帮助阐述本申请。可选实施例并没有详尽叙述所有的细节,也不限制该发明仅为所述的具体实施方式。显然,根据本申请的内容,可作很多的修改和变化。本申请选取并具体描述这些实施例,是为了更好地解释本申请的原理和实际应用,从而使所属技术领域技术人员能很好地理解和利用本申请。本申请仅受权利要求书及其全部范围和等效物的限制。

Claims (20)

  1. 一种数据发送方法,应用于处于对称型NAT下的终端,其特征在于,包括:
    S1:为n 1个第一访问请求数据包建立容纳m个文件描述符的队列,其中,2≤m<n 1
    S2:在所述队列中创建第i个文件描述符并通过所述第i个文件描述符发送第i个第一访问请求数据包,并对所述第i个文件描述符记录的源端口进行监控,其中,所述第i个文件描述符与所述第i个第一访问请求数据包具有相同的源端口,其中1≤i≤n 1
    S3:每间隔第一预设时间间隔t 1,令i自增1,继续执行步骤S2,并且为每个源端口设置预设监听时间T,其中,每个文件描述符记录不同源端口,T=t 1*m;
    S4:在m*j<i≤m*(j+1)的情况下,在所述队列中创建第i个文件描述符时,结束对第i-m个源端口的监听并销毁对应的文件描述符,直至监听到第一端口接收到响应数据包,停止对其他源端口的监听,其中,j≥1,所述第一端口为处于被监听状态的任意一个源端口。
  2. 根据权利要求1所述的数据发送方法,其特征在于,还包括:若在第n 1个文件描述符记录的源端口的预设监听时间T结束时仍没有接收到响应数据包,则重新执行为n 1个第一访问请求数据包建立容纳m个文件描述符的队列的步骤。
  3. 根据权利要求1所述的数据发送方法,其特征在于,还包括:通过所述第一端口发送第一待传输数据和/或接收第二待传输数据。
  4. 根据权利要求1所述的数据发送方法,其特征在于,所述直至监听到第一端口接收到响应数据包,停止对其他源端口的监听包括:
    在监听到第一端口接收到响应数据包的情况下,销毁其他源端口对应的文件描述符。
  5. 根据权利要求1或2所述的数据发送方法,其特征在于,在为n 1个第一访问请求数据包建立容纳m个文件描述符的队列之前,还包括:
    向穿越辅助服务器发送信息获取请求;
    接收所述穿越辅助服务器发送的所述终端的地址信息和NAT类型;
    将所接收的地址信息和NAT类型发送至访问管理服务器;
    接收所述访问管理服务器反馈的待访问端的地址信息和NAT类型。
  6. 根据权利要求5所述的数据发送方法,其特征在于,所述通过所述第i个文件描述符发送第i个第一访问请求数据包之前,还包括:
    基于所接收的所述待访问端的地址信息以及所述第i个文件描述符对应的源端口,生成所述第i个第一访问请求数据包。
  7. 一种建立P2P连接的方法,其特征在于,包括:
    第一终端通过一个文件描述符以第二预设时间间隔t 2发送n 2个第二访问请求数据包,其中,所述第一终端处于端口受限型NAT下,所述n 2个第二访问请求数据包中的目的IP地址相同且目的端口不同;
    与所述目的IP地址对应的处于对称型NAT下的第二终端执行以下操作:
    S1:为n 1个第一访问请求数据包建立容纳m个文件描述符的队列,其中,2≤m<n 1
    S2:在所述队列中创建第i个文件描述符并通过所述第i个文件描述符发送第i个第一访问请求数据包,并对所述第i个文件描述符记录的源端口进行监控,其中,所述第i个文件描述符与所述第i个第一访问请求数据包具有相同的源端口,其中1≤i≤n 1
    S3:每间隔第一预设时间间隔t 1,令i自增1,继续执行步骤S2,并且为每个源端口设置预设监听时间T,其中,每个文件描述符记录不同源端口,T=t 1*m;
    S4:在m*j<i≤m*(j+1)的情况下,在所述队列中创建第i个文件描述符时,结束对第i-m个源端口的监听并销毁对应的文件描述符;
    在所述第一终端的源端口的t 2*n 2+t 1*n 1监听时间段内,所述端口受限型NAT监听到所述第一终端的源端口接收到来自所述第二终端的第一访问请求数据包的情况下,所述第一终端获得第一访问请求数据包中的地址信息,并且向获得的地址信息发送响应数据包;
    所述对称型NAT监听到所述第二终端的第一端口接收到响应数据包,停止对其他源端口的监听,其中,所述第一端口与所述获得的地址信息对应。
  8. 根据权利要求7所述的建立P2P连接的方法,其特征在于,还包括:
    若在第n 1个文件描述符记录的源端口的预设监听时间T结束时仍没有接收到响应数据包,则在预设条件下重新执行第一终端通过一个文件描述符以第二预设时间间隔t 2发送n 2个第二访问请求数据包的步骤。
  9. 根据权利要求7或8所述的建立P2P连接的方法,其特征在于,在第一终端通过一个文件描述符以第二预设时间间隔t 2发送n 2个第二访问请求数 据包之前,还包括:
    所述第一终端和所述第二终端分别向穿越辅助服务器发送信息获取请求;
    所述第一终端和所述第二终端分别接收所述穿越辅助服务器发送的各自的地址信息和NAT类型;
    所述第一终端和所述第二终端将所接收的各自的地址信息和NAT类型发送至访问管理服务器;
    所述第一终端接收所述访问管理服务器反馈的所述第二终端的地址信息和NAT类型,并且所述第二终端接收所述访问管理服务器反馈的所述第一终端的地址信息和NAT类型。
  10. 根据权利要求9所述的建立P2P连接的方法,其特征在于,在第一终端通过一个文件描述符以第二预设时间间隔t 2发送n 2个第二访问请求数据包之前,还包括:
    将第二终端的初始端口设置为随机数,并且为所述n 2个第二访问请求数据包设置端口编号之间的间隔相同的目的端口;
    基于所接收的所述第二终端的地址信息中的IP地址、所设置的目的端口以及所述文件描述符对应的源端口,生成所述第二访问请求数据包。
  11. 根据权利要求10所述的建立P2P连接的方法,其特征在于,所述将第二终端的初始端口设置为随机数,并且为所述n 2个第二访问请求数据包设置端口编号之间的间隔相同的目的端口,包括:
    将第二终端的初始端口设置为与n 2相关的随机数与预设值之和;
    将每个第二访问请求数据包的目的端口与前一第二访问请求数据包的目的端口间隔设置为与所述预设值相关的固定值。
  12. 根据权利要求7或8所述的建立P2P连接的方法,其特征在于,在所述第一终端发送n 2个第二访问请求数据包时,建立第一终端的地址信息与所述第二终端的地址信息之间的第一映射关系,在所述第二终端发送n 1个第一访问请求数据包时,建立所述第二终端的地址信息与所述第一终端的地址信息之间的第二映射关系,所述监听到所述第一终端的源端口接收到来自所述第二终端的第一访问请求数据包包括:
    将所述第一映射关系与所述第二映射关系进行比较,若有匹配的映射关系,则监听到所述第一终端的源端口接收到来自所述第二终端的第一访问请求数据包。
  13. 根据权利要求7或8所述的建立P2P连接的方法,其特征在于,还包 括:
    由所述第二终端通过所述第一端口向所述第一终端的文件描述符对应的源端口发送第一待传输数据;和/或
    由所述第一终端通过所述第一终端的文件描述符对应的源端口向所述第一端口发送第二待传输数据。
  14. 根据权利要求7或8所述的建立P2P连接的方法,其特征在于,n 1=n 2且t 1=t 2
  15. 根据权利要求7或8所述的建立P2P连接的方法,其特征在于,所述第一访问请求数据包和所述第二访问请求数据包包括UDP报文。
  16. 一种数据发送装置,应用于处于对称型NAT下的终端,其特征在于,包括:
    建立模块,被配置成执行步骤S1:为n 1个第一访问请求数据包建立容纳m个文件描述符的队列,其中,2≤m<n 1
    创建发送模块,被配置成执行步骤S2:在所述队列中创建第i个文件描述符并通过所述第i个文件描述符发送第i个第一访问请求数据包,并对所述第i个文件描述符记录的源端口进行监控,其中,所述第i个文件描述符与所述第i个第一访问请求数据包具有相同的源端口,其中1≤i≤n 1
    设置模块,被配置成执行步骤S3:每间隔第一预设时间间隔t 1,令i自增1,继续执行步骤S2,并且为每个源端口设置预设监听时间T,其中,每个文件描述符记录不同源端口,T=t 1*m;
    停止监听模块,被配置成执行步骤S4:在m*j<i≤m*(j+1)的情况下,在所述队列中创建第i个文件描述符时,结束对第i-m个源端口的监听并销毁对应的文件描述符,直至监听到第一端口接收到响应数据包,停止对其他源端口的监听,其中,j≥1,所述第一端口为处于被监听状态的任意一个源端口。
  17. 一种建立P2P连接的系统,包括端口受限型NAT、处于端口受限型NAT下的第一终端、对称型NAT及处于对称型NAT下的第二终端,其特征在于,
    所述第一终端被配置成通过一个文件描述符以第二预设时间间隔t 2发送n 2个第二访问请求数据包,其中,所述n 2个第二访问请求数据包中的目的IP地址相同且目的端口不同;
    所述第二终端与所述目的IP地址对应,并且所述第二终端被配置成执行以下步骤:
    S1:为n 1个第一访问请求数据包建立容纳m个文件描述符的队列,其中,2≤m<n 1
    S2:在所述队列中创建第i个文件描述符并通过所述第i个文件描述符发送第i个第一访问请求数据包,并对所述第i个文件描述符记录的源端口进行监控,其中,所述第i个文件描述符与所述第i个第一访问请求数据包具有相同的源端口,其中1≤i≤n 1
    S3:每间隔第一预设时间间隔t 1,令i自增1,继续执行步骤S2,并且为每个源端口设置预设监听时间T,其中,每个文件描述符记录不同源端口,T=t 1*m;
    S4:在m*j<i≤m*(j+1)的情况下,在所述队列中创建第i个文件描述符时,结束对第i-m个源端口的监听并销毁对应的文件描述符;
    所述第一终端被配置成:在所述第一终端的源端口的t 2*n 2+t 1*n 1监听时间段内,所述端口受限型NAT监听到所述第一终端的源端口接收到来自所述第二终端的第一访问请求数据包的情况下,获得第一访问请求数据包中的地址信息,并且向获得的地址信息发送响应数据包;
    所述对称型NAT被配置成:监听到所述第二终端的第一端口接收到响应数据包,停止对其他源端口的监听,其中,所述第一端口与所述获得的地址信息对应。
  18. 一种计算设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机指令,其特征在于,所述处理器执行所述计算机指令时实现权利要求1-6任意一项所述方法的步骤。
  19. 一种计算机可读存储介质,其存储有计算机指令,其特征在于,该计算机指令被处理器执行时实现权利要求1至6任意一项所述方法的步骤。
  20. 一种计算机程序产品,当所述计算机程序产品在计算机中执行时,令计算机执行权利要求1至6任意一项所述方法的步骤。
PCT/CN2022/070246 2021-01-06 2022-01-05 数据发送方法及装置、建立p2p连接的方法及系统 WO2022148364A1 (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
US18/271,024 US12010088B2 (en) 2021-01-06 2022-01-05 Data sending method and apparatus, and method and system for establishing P2P connection

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202110011585.7 2021-01-06
CN202110011585.7A CN112637382B (zh) 2021-01-06 2021-01-06 数据发送方法及装置、建立p2p连接的方法及系统

Publications (1)

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

Family

ID=75291478

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/070246 WO2022148364A1 (zh) 2021-01-06 2022-01-05 数据发送方法及装置、建立p2p连接的方法及系统

Country Status (3)

Country Link
US (1) US12010088B2 (zh)
CN (1) CN112637382B (zh)
WO (1) WO2022148364A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112637382B (zh) 2021-01-06 2022-04-26 上海哔哩哔哩科技有限公司 数据发送方法及装置、建立p2p连接的方法及系统

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102710807A (zh) * 2012-05-29 2012-10-03 北京中视里程科技有限公司 一种nat穿越方法
US9497160B1 (en) * 2013-06-24 2016-11-15 Bit Action, Inc. Symmetric NAT traversal for direct communication in P2P networks when some of the routing NATs are symmetric
CN109962987A (zh) * 2017-12-22 2019-07-02 杭州萤石软件有限公司 一种通信连接的建立方法、装置及系统
CN112637382A (zh) * 2021-01-06 2021-04-09 上海哔哩哔哩科技有限公司 数据发送方法及装置、建立p2p连接的方法及系统

Family Cites Families (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6029194A (en) * 1997-06-10 2000-02-22 Tektronix, Inc. Audio/video media server for distributed editing over networks
US7856506B2 (en) * 2008-03-05 2010-12-21 Sony Computer Entertainment Inc. Traversal of symmetric network address translator for multiple simultaneous connections
US20110035259A1 (en) * 2009-08-07 2011-02-10 Yahoo! Inc. Cost and participation models for exchange third-party integration in online advertising
US10511630B1 (en) * 2010-12-10 2019-12-17 CellSec, Inc. Dividing a data processing device into separate security domains
US9794186B2 (en) * 2014-03-27 2017-10-17 Nicira, Inc. Distributed network address translation for efficient cloud service access
WO2016000138A1 (zh) * 2014-06-30 2016-01-07 北京新媒传信科技有限公司 一种数据传输方法、终端和服务器
US9712546B2 (en) * 2014-09-12 2017-07-18 Level 3 Communications, Llc Dynamic configuration of settings in response to DDOS attack
SG11202000090QA (en) * 2017-07-12 2020-02-27 Visa Int Service Ass Systems and methods for generating behavior profiles for new entities
US11157312B2 (en) * 2018-09-17 2021-10-26 International Business Machines Corporation Intelligent input/output operation completion modes in a high-speed network
CN109600449A (zh) * 2018-12-24 2019-04-09 深圳市网心科技有限公司 一种p2p穿透方法、装置、系统及存储介质
WO2020202135A2 (en) * 2019-04-02 2020-10-08 Luminati Networks Ltd. System and method for managing non-direct url fetching service
CN114900496B (zh) * 2019-06-24 2024-03-15 华为技术有限公司 一种通信方法以及相关设备

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102710807A (zh) * 2012-05-29 2012-10-03 北京中视里程科技有限公司 一种nat穿越方法
US9497160B1 (en) * 2013-06-24 2016-11-15 Bit Action, Inc. Symmetric NAT traversal for direct communication in P2P networks when some of the routing NATs are symmetric
CN109962987A (zh) * 2017-12-22 2019-07-02 杭州萤石软件有限公司 一种通信连接的建立方法、装置及系统
CN112637382A (zh) * 2021-01-06 2021-04-09 上海哔哩哔哩科技有限公司 数据发送方法及装置、建立p2p连接的方法及系统

Also Published As

Publication number Publication date
CN112637382B (zh) 2022-04-26
US20240064124A1 (en) 2024-02-22
CN112637382A (zh) 2021-04-09
US12010088B2 (en) 2024-06-11

Similar Documents

Publication Publication Date Title
CN112887433B (zh) 基于quic协议的云端访问边缘服务的方法和系统
US9392081B2 (en) Method and device for sending requests
WO2022148363A1 (zh) 数据传输方法及数据传输服务器
WO2024037296A1 (zh) 基于协议族的quic数据传输方法及装置
WO2023005773A1 (zh) 基于远程直接数据存储的报文转发方法、装置、网卡及设备
CN113315845B (zh) 数据传输方法、装置及分布式存储系统
CN112637364B (zh) 建立p2p连接的方法、客户端及系统
RU2007148416A (ru) Объединенная архитектура для удаленного доступа к сети
WO2014082562A1 (en) Method, device, and system for information processing based on distributed buses
US10367893B1 (en) Method and apparatus of performing peer-to-peer communication establishment
WO2021068973A1 (zh) 一种基于应用层协议的数据通信方法及其装置
CN110609746B (zh) 管理网络系统的方法、设备和计算机可读介质
EP4221233A1 (en) Data download method and apparatus, computer device and storage medium
WO2022148364A1 (zh) 数据发送方法及装置、建立p2p连接的方法及系统
WO2024021414A1 (zh) 数据传输
CN114500633B (zh) 数据转发方法、相关装置、程序产品及数据传输系统
CN115297164A (zh) 网络代理方法、装置、电子设备及计算机可读存储介质
WO2022100199A1 (zh) 数据传输方法、装置、介质、电子设备及网络接入设备
CN112702338B (zh) Ike报文获取方法及装置
WO2023186109A1 (zh) 节点访问方法以及数据传输系统
CN111131470B (zh) 终端设备及其数据处理方法以及数据处理系统
CN115509435A (zh) 一种数据读写方法、装置、设备、介质
CN114363427A (zh) 一种基于浏览器实时获取主机设备信息的方法
CN108848175B (zh) 一种创建tcp连接的方法及装置
CN111949918A (zh) 基于分布式环境下的websocket连接优化方法及系统

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

Country of ref document: EP

Kind code of ref document: A1

WWE Wipo information: entry into national phase

Ref document number: 18271024

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 211123)