TECHNICAL FIELD
[0002] This application relates to network address translation technologies in the communications
field, and in particular, to a NAT traversal method, a device, and a system.
BACKGROUND
[0003] Network address translation (network address translation, NAT) traversal is a very
important technology in the field of peer-to-peer (peer-to-peer, P2P) real-time audio
and videos. The NAT traversal technology may enable clients to directly communicate
with each other, thereby reducing a peer-to-peer delay, and reducing pressure and
costs of a server.
[0004] The NAT technology is a technology for translating an internal network address into
an external network address. This technology can not only resolve a problem of insufficient
Internet protocol (Internet protocol, IP) addresses, but also effectively avoid an
attack from outside a network, and hide and protect a terminal inside the network.
[0005] A main working process of NAT is modifying a source address and a destination address
of a data packet to implement address mapping. In addition, an external network can
send data to an internal network terminal only after the internal network terminal
actively sends data to the external network. A source address of a data packet sent
from an internal network to the external network is modified, and a destination address
of a data packet sent from the external network to the internal network is modified.
To be specific, external data can reach the internal network terminal through a NAT
device only when data is first sent from inside the NAT device. If an internal packet
is not sent first, the NAT device discards received external data (where this data
is referred to as "unsolicited" data). In addition, currently, many NAT devices have
a time sequence requirement. To be specific, when receiving the "unsolicited" data,
in addition to discarding the data, the NAT device may blacklist a source IP address
and a port (port) from which the "unsolicited" data is sent. Data sent from the address
or the port cannot enter the NAT device once the source IP address and the port are
blacklisted. Therefore, if the NAT device has the time sequence requirement, NAT traversal
cannot be performed, and peer-to-peer communication cannot be implemented.
SUMMARY
[0006] Embodiments of this application provide a NAT traversal method, a device, and a system,
to resolve a problem of a low traversal success rate of a NAT device having a time
sequence requirement.
[0007] According to a first aspect, a NAT traversal method is provided, and the method is
applied to a system in which a first terminal communicates with a second terminal.
The first terminal is a terminal in a network constructed by a first NAT device, the
second terminal is a terminal in a network constructed by a second NAT device, and
the first NAT device is different from the second NAT device. The method includes:
Step 1: The first terminal sets first time to live (TTL). Step 2: The first terminal
determines whether the first terminal receives, within the set TTL, a first passthrough
message sent by the second terminal. When the first terminal does not receive the
first passthrough message within the set TTL, the first terminal sends a second passthrough
message to the second terminal, and determines whether the first terminal receives
a first response message sent by the second terminal. Step 3: If the first terminal
receives the first response message sent by the second terminal, the first terminal
determines that NAT traversal succeeds, or if the first terminal does not receive
the first response message sent by the second terminal, after changing an external
network address corresponding to the first terminal and resetting the TTL, the first
terminal repeats step 2 until the first terminal receives the first passthrough message
or the first response message; and determines that NAT traversal succeeds.
[0008] With reference to the first aspect, in some implementations of the first aspect,
that the first terminal repeats step 2 after resetting the value of the TTL includes:
The first terminal sets second TTL, and determines whether the first terminal receives,
within the second TTL, the first passthrough message resent by the second terminal,
where the second TTL is different from the first TTL. When receiving the first passthrough
message within the second TTL, the first terminal determines that the NAT traversal
succeeds. When the first terminal does not receive the first passthrough message within
the second TTL, the first terminal sends the second passthrough message to the second
terminal. If the first terminal does not receive the first response message sent by
the second terminal, the first terminal changes the external network address corresponding
to the first terminal again and resets the TTL. If the first terminal receives the
first response message sent by the second terminal, the first terminal determines
that the NAT traversal succeeds.
[0009] With reference to the first aspect, in some implementations of the first aspect,
the method further includes: When the first terminal receives the second passthrough
message sent by the second terminal, the first terminal sends a second response message
to the second terminal.
[0010] With reference to the first aspect, in some implementations of the first aspect,
the first TTL is not greater than a smaller value of a first hop count and a second
hop count. The first hop count is a quantity of network segments between the first
terminal and the first NAT device, and the second hop count is a quantity of network
segments between the second terminal and the second NAT device.
[0011] With reference to the first aspect, in some implementations of the first aspect,
the first NAT device and the second NAT device are cone NAT devices.
[0012] With reference to the first aspect, in some implementations of the first aspect,
the first terminal sends first query information to a network device through the first
NAT device, where the first query information is used to query the external network
address corresponding to the first terminal. The first terminal receives first response
information sent by the network device, where the first response information includes
the external network address corresponding to the first terminal.
[0013] According to a second aspect, a NAT traversal method is provided, and the method
is applied to a system in which a first terminal communicates with a second terminal.
The first terminal is a terminal in a network constructed by a first NAT device, the
second terminal is a terminal in a network constructed by a second NAT device, and
the first NAT device is different from the second NAT device. The method includes:
Step 1: The second terminal sends a first passthrough message to the first terminal.
Step 2: The second terminal determines whether the second terminal receives a second
response message sent by the first terminal. If the second terminal does not receive
the second response message, the second terminal changes an external network address
corresponding to the second device and sets first TTL. Step 3: The second terminal
determines whether the second terminal receives, within the set TTL, a second passthrough
message sent by the first terminal. If the second terminal receives the second passthrough
message, the second terminal determines that NAT traversal succeeds, and sends a first
response message to the first terminal. Alternatively, the second terminal repeats
step 1 and step 2 if the second terminal does not receive the second passthrough message,
until the second terminal receives the second passthrough message or the second response
message, and determines that NAT traversal succeeds.
[0014] With reference to the second aspect, in some implementations of the second aspect,
that the second terminal repeats step 1 and step 2 if the second terminal does not
receive the second passthrough message includes: When the second terminal does not
receive the second passthrough message, the second terminal sends the first passthrough
message to the first terminal, and determines whether the second terminal receives
the first response message sent by the first terminal. When the first terminal receives
the first response message, the second terminal determines that the NAT traversal
succeeds. When the first terminal does not receive the first response message, the
second terminal changes the external network address corresponding to the second terminal
again and sets second TTL. The second TTL is different from the first TTL.
[0015] With reference to the second aspect, in some implementations of the second aspect,
the first TTL is not greater than a smaller value of a first hop count and a second
hop count. The first hop count is a quantity of network segments between the first
terminal and the first NAT device, and the second hop count is a quantity of network
segments between the second terminal and the second NAT device.
[0016] With reference to the second aspect, in some implementations of the second aspect,
the first NAT device and the second NAT device are cone NAT devices.
[0017] With reference to the second aspect, in some implementations of the second aspect,
that the second terminal changes an external network address corresponding to the
second terminal includes: The second terminal sends second query information to a
network device through the second NAT device. The second query information is used
to query an external network address corresponding to the first terminal. The second
terminal receives second response information sent by the network device. The second
response information includes the external network address corresponding to the second
terminal.
[0018] According to a third aspect, a NAT traversal method is provided, and the method is
applied to a system in which a first terminal communicates with a second terminal.
The first terminal is a terminal in a network constructed by a first NAT device, the
second terminal is a terminal in a network constructed by a second NAT device, and
the first NAT device is different from the second NAT device. The method includes:
The first NAT device determines whether the first NAT device receives, within first
TTL, a first hole punching message sent by the first terminal. If the first NAT device
does not receive the first hole punching message, when receiving a first passthrough
message sent by the second terminal, the first NAT device blacklists an external network
address corresponding to the second terminal. The first NAT device sends a second
passthrough message to a changed external network address of the second terminal.
When the second passthrough message is not received by the second terminal, the first
NAT device resets an external network address corresponding to the first terminal;
after the TTL is reset, repeats the process until the first NAT device receives the
first hole punching message or the first terminal receives the first passthrough message;
and that NAT traversal succeeds.
[0019] With reference to the third aspect, in some implementations of the third aspect,
repeating the process after the TTL is reset includes: The first NAT device determines
whether the first NAT device receives, within second TTL, the first hole punching
message sent by the first terminal, where the second TTL is greater than the first
TTL. If the first NAT device does not receive the first hole punching message, when
receiving the first passthrough message sent by the second terminal, the first NAT
device blacklists the changed external network address corresponding to the second
terminal, and repeats the process again after the value of the TTL is reset again.
[0020] With reference to the third aspect, in some implementations of the third aspect,
the method further includes: when the second passthrough message is not received by
the second terminal, the first NAT device reallocates an external network address
or a port to the first terminal.
[0021] With reference to the third aspect, in some implementations of the third aspect,
the first TTL is not greater than a smaller value of a first hop count and a second
hop count. The first hop count is a quantity of network segments between the first
terminal and the first NAT device, and the second hop count is a quantity of network
segments between the second terminal and the second NAT device.
[0022] With reference to the third aspect, in some implementations of the third aspect,
the first NAT device and the second NAT device are cone NAT devices.
[0023] With reference to the third aspect, in some implementations of the third aspect,
the method further includes: The first NAT device receives first query information
sent by the first terminal, where the first query information is used to query the
external network address corresponding to the first terminal. The first NAT device
sends the first query information to a network device. The first NAT device configures
the external network address corresponding to the first terminal, and sends the external
network address to the network device. The first NAT device receives first response
information sent by the network device, where the first response information includes
the external network address corresponding to the first terminal. The first NAT device
sends the first response information to the first terminal.
[0024] According to a fourth aspect, a NAT traversal method is provided, and the method
is applied to a system in which a first terminal communicates with a second terminal.
The first terminal is a terminal in a network constructed by a first NAT device, the
second terminal is a terminal in a network constructed by a second NAT device, and
the first NAT device is different from the second NAT device. The method includes:
The second NAT device sends a first passthrough message to the first terminal. If
the first passthrough message is not received by the first terminal, the second NAT
device resets an external network address corresponding to the second terminal, and
determines whether the second NAT device receives, within first TTL, a second hole
punching message sent by the second terminal. When the second NAT device does not
receive the second hole punching message, if the second NAT device receives a second
passthrough message sent by the first terminal, the second NAT device blacklists an
external network address corresponding to the first terminal; after the value of the
TTL is reset, repeats the process until the first passthrough message is received
by the first terminal or the second NAT device receives the second hole punching message;
and determines that NAT traversal succeeds.
[0025] With reference to the fourth aspect, in some implementations of the fourth aspect,
repeating the process after the value of the TTL is reset includes: The second NAT
device sends the first passthrough message to the first terminal within second TTL,
where the second TTL is greater than the first TTL. If the first passthrough message
cannot be received by the first terminal, the second NAT device determines whether
the hole punching message sent by the second terminal is received. When the second
NAT device does not receive the hole punching message, if the second NAT device receives
the second passthrough message sent by the first terminal, the second NAT device blacklists
a changed external network address corresponding to the first terminal, and after
the value of the TTL is reset again, repeats the process.
[0026] With reference to the fourth aspect, in some implementations of the fourth aspect,
the first TTL is not greater than a smaller value of a first hop count and a second
hop count. The first hop count is a quantity of network segments between the first
terminal and the first NAT device, and the second hop count is a quantity of network
segments between the second terminal and the second NAT device.
[0027] With reference to the fourth aspect, in some implementations of the fourth aspect,
the first NAT device and the second NAT device are cone NAT devices.
[0028] With reference to the fourth aspect, in some implementations of the fourth aspect,
the method further includes: The second NAT device receives second query information
sent by the second terminal, where the second query information is used to query the
external network address corresponding to the second terminal. The second NAT device
sends the second query information to a network device. The second NAT device configures
the external network address corresponding to the second terminal, and sends the external
network address to the network device. The second NAT device receives second response
information sent by the network device, where the second response information includes
the external network address corresponding to the second terminal. The second NAT
device sends the second response information to the second terminal.
[0029] According to a fifth aspect, a terminal device is provided, including: a processing
module, configured to: set first TTL, and determine whether a first terminal can receive,
within the first TTL, a first passthrough message sent by a second terminal; and a
sending module, configured to: when the first terminal does not receive the first
passthrough message within the set TTL, send a second passthrough message to the second
terminal. The processing module is further configured to determine whether a first
response message sent by the second terminal is received. If the first terminal receives
the first response message sent by the second terminal, the processing module is further
configured to determine that NAT traversal succeeds. If the first terminal does not
receive the first response message sent by the second terminal, the processing module
is further configured to: after changing an external network address corresponding
to the first terminal and resetting the TTL, repeat the process until the first terminal
receives the first passthrough message or the first response message, and determine
that NAT traversal succeeds.
[0030] With reference to the fifth aspect, in some implementations of the fifth aspect,
that the processing module repeats the process after resetting the TTL includes: The
processing module sets second TTL, where the second TTL is different from the first
TTL. The processing module determines whether the first passthrough message can be
received within the second TTL. When the first terminal does not receive the first
passthrough message, the sending module sends a second passthrough message to the
second terminal. The processing module determines whether the first response message
sent by the second terminal is received. If the first terminal receives the first
response message sent by the second terminal, the processing module is further configured
to determine that the NAT traversal succeeds. If the first terminal does not receive
the first response message sent by the second terminal, the processing module is further
configured to: change the external network address corresponding to the first terminal,
and reset the TTL.
[0031] With reference to the fifth aspect, in some implementations of the fifth aspect,
the first TTL is not greater than a smaller value of a first hop count and a second
hop count. The first hop count is a quantity of network segments between the first
terminal and a first NAT device, and the second hop count is a quantity of network
segments between the second terminal and a second NAT device.
[0032] With reference to the fifth aspect, in some implementations of the fifth aspect,
the first NAT device and the second NAT device are cone NAT devices.
[0033] With reference to the fifth aspect, in some implementations of the fifth aspect,
the sending module is further configured to send first query information to a network
device through the first NAT device, where the first query information is used to
query the external network address corresponding to the first terminal. The terminal
further includes a receiving module, and the receiving module is configured to receive
first response information sent by the network device, and the first response information
includes the external network address corresponding to the first terminal. According
to a sixth aspect, a NAT device is provided, and the NAT device is used in a system
in which a first terminal communicates with a second terminal. The first terminal
is a terminal in a network constructed by a first NAT device, the second terminal
is a terminal in a network constructed by a second NAT device, and the first NAT device
is different from the second NAT device. The NAT device includes: a sending module,
configured to send a first passthrough message to the first terminal within first
TTL; and a processing module, configured to: if the first passthrough message cannot
be received by the first terminal, determine whether a hole punching message sent
by the second terminal is received. The processing module is further configured to:
when the second NAT device does not receive the hole punching message, if the second
NAT device receives a second passthrough message sent by the first terminal, blacklist
an external network address corresponding to the first terminal, and after the value
of the TTL is reset, repeat the process until the first terminal receives the first
passthrough message or the first NAT device receives the hole punching message.
[0034] With reference to the sixth aspect, in some implementations of the sixth aspect,
repeating the process after the value of the TTL is reset includes: The sending module
sends the first passthrough message to the first terminal within second TTL, where
the second TTL is greater than the first TTL. If the first passthrough message cannot
be received by the first terminal, the processing module is further configured to
determine whether the hole punching message sent by the second terminal is received.
When the second NAT device does not receive the hole punching message, if the second
NAT device receives the second passthrough message sent by the first terminal, the
processing module is further configured to: blacklist a changed external network address
corresponding to the first terminal, and after the value of the TTL is reset again,
repeat the process.
[0035] With reference to the sixth aspect, in some implementations of the sixth aspect,
the first TTL is not greater than a smaller value of a first hop count and a second
hop count. The first hop count is a quantity of hops between the first terminal and
the first NAT device, and the second hop count is a quantity of hops between the second
terminal and the second NAT device.
[0036] With reference to the sixth aspect, in some implementations of the sixth aspect,
the first NAT device and the second NAT device are cone NAT devices.
[0037] According to a seventh aspect, a communications device is provided. The communications
device includes at least one processor and a communications interface. The communications
interface is used by the communications device to exchange information with another
communications device. When program instructions are executed in the at least one
processor, the communications device is enabled to implement a function of either
of the following devices in the method according to any one of the implementations
of the first aspect or the second aspect: the first terminal and the second terminal.
[0038] According to an eighth aspect, a communications system is provided, including at
least one terminal, at least one NAT device, and a server. The terminal is configured
to perform the method according to any one of the implementations of the first aspect
or the second aspect. The NAT device is configured to perform the method according
to any one of the implementations of the third aspect or the fourth aspect.
[0039] According to the NAT traversal method provided in the embodiments of this application,
TTL of sending messages by a local end and a peer end is detected and the TTL values
are dynamically adjusted, to determine that a message sent by one end in peer-to-peer
communication can exactly reach a NAT device at the end but does not reach a NAT device
at the peer end. In this way, one end generates a mapping table, and an external network
address of the end is not blacklisted, so that NAT traversal is finally implemented,
and NAT traversal efficiency is improved.
BRIEF DESCRIPTION OF DRAWINGS
[0040]
FIG. 1 is a schematic diagram of a working process of a NAT device;
FIG. 2(a) is a schematic diagram of a working principle of a cone NAT device;
FIG. 2(b) is a schematic diagram of a working principle of a symmetric NAT device;
FIG. 3 is a schematic diagram of a NAT traversal process based on a cone-cone combination;
FIG. 4 is a schematic diagram of a NAT traversal process;
FIG. 5 is a schematic diagram of a NAT traversal process according to an embodiment
of this application;
FIG. 6 is a schematic diagram of applying a NAT traversal method to a peer-to-peer
communication scenario according to an embodiment of this application;
FIG. 7 is a schematic diagram of a structure of a terminal device according to an
embodiment of this application; and
FIG. 8 is a schematic diagram of a structure of a NAT device according to an embodiment
of this application.
DESCRIPTION OF EMBODIMENTS
[0041] The following clearly and completely describes the technical solutions in the embodiments
of this application with reference to the accompanying drawings in the embodiments
of this application. Clearly, the described embodiments are some but not all of the
embodiments of this application. All other embodiments obtained by a person of ordinary
skill in the art based on the embodiments of this application without creative efforts
shall fall within the protection scope of this application.
[0042] The technical solutions in the embodiments of this application may be applied to
various communications systems, for example, a global system for mobile communications
(global system for mobile communications, GSM), a code division multiple access (code
division multiple access, CDMA) system, a wideband code division multiple access (wideband
code division multiple access, WCDMA) system, a general packet radio service (general
packet radio service, GPRS) system, a long term evolution (long term evolution, LTE)
system, an LTE frequency division duplex (frequency division duplex, FDD) system,
an LTE time division duplex (time division duplex, TDD) system, a universal mobile
telecommunications system (universal mobile telecommunications system, UMTS), a worldwide
interoperability for microwave access (worldwide interoperability for microwave access,
WiMAX) communications system, a future 5th generation (5th generation, 5G) system,
or a new radio (new radio, NR) system.
[0043] A terminal in the embodiments of this application may be user equipment, an access
terminal, a subscriber unit, a remote terminal, a mobile device, a user terminal,
a terminal, a wireless communications device, a user agent, or a user apparatus. The
terminal device may alternatively be a cellular phone, a cordless phone, a session
initiation protocol (session initiation protocol, SIP) phone, a wireless local loop
(wireless local loop, WLL) station, a personal digital assistant (personal digital
assistant, PDA), a handheld device having a wireless communication function, a computing
device, another processing device connected to a wireless modem, a vehicle-mounted
device, a wearable device, a terminal device in a future 5G network, a terminal device
in a future evolved public land mobile communication network (public land mobile network,
PLMN), or the like. This is not limited in the embodiments of this application.
[0044] For ease of understanding, a NAT technology is first described with reference to
the accompanying drawings.
[0045] FIG. 1 is a schematic diagram of a working process of a NAT device.
[0046] As shown in FIG. 1, the NAT device maintains an address mapping table. An internal
network address, a mapped external network address, and a destination address of a
terminal are recorded in the address mapping table, and the mapping table is initially
empty. For example, source addresses and mapped addresses of a terminal 1 and a terminal
2 are recorded in the address mapping table shown in FIG. 1. Addresses of the terminal
1 are used as an example. An internal network address of the terminal 1 is 192.168.0.100:10000,
a destination address for peer-to-peer communication is 210.15.27.166:8000, and an
external network address obtained after the NAT device maps the internal network address
of the terminal 1 is 210.21.12.140:2000. When the terminal 1 communicates with a peer
end at the destination address, the mapped external network address needs to be used
for communication. A specific communication process is described below.
[0047] NAT types may be specifically classified into cone NAT (cone NAT) (as shown in FIG.
2a) and symmetric NAT (symmetric NAT) (as shown in FIG. 2b). Therefore, mapping between
an internal network address and an external network address may be one-to-one mapping,
or may be one-to-many mapping. For example, when the NAT type is cone NAT, a cone
NAT device fixedly translates one internal network address into one external network
address. In this case, the one-to-one mapping is performed. When the NAT type is symmetric
NAT, a symmetric NAT device may translate one internal network address into a plurality
of external network addresses. In this case, the one-to-many mapping is performed.
[0048] An example in which the terminal 1 (where the internal network address is 192.168.0.100:10000)
sends a data packet to a server 1 (where the destination address is 210.15.27.166:8000)
is used to describe the working process of the NAT device. The process of the NAT
device is as follows. The internal network address of the terminal may also be referred
to as a source address of the terminal.
- (1) When the terminal 1 needs to send the data packet to the server 1 through the
NAT device, the NAT device needs to obtain, from the mapping table, a record about
the source address 192.168.0.100:10000. It should be understood that, if the terminal
1 sends the data packet to the server 1 for the first time, the record about the source
address 192.168.0.100:10000 is not yet created in the mapping table of the NAT device.
In this case, the record about the source address 192.168.0.100:10000 needs to be
created in the mapping table, and an external network port or an external network
address needs to be allocated. For example, the NAT device allocates an external network
address or an external network port 210.21.12.140:2000 to the terminal 1.
[0049] It should be understood that the NAT device may allocate an external network address
and/or an external network port to the terminal. For ease of description, in this
embodiment of this application, the external network address and the external network
port allocated by the NAT device to the terminal are collectively referred to as the
external network address allocated by the NAT device to the terminal.
(2) The NAT device modifies a source address of the data packet, and then sends the
data packet to an external network. Modifying the source address of the data packet
by the NAT device is modifying the source address corresponding to the data packet
to an external network address, that is, modifying 192.168.0.100:10000 to 210.21.12.140:2000.
Then, all data packets with the source address 192.168.0.100:10000 and the destination
address 210.15.27.166:8000 are modified as described above.
[0050] Because the terminal sends the data packet to the external network, the external
network may then send a data packet to the internal network terminal through the NAT
device. A process is as follows:
(3) The NAT device receives a data packet sent by the server 1 to the external network
address (210.21.12.140:2000) through the destination address (210.15.27.166:8000),
and the NAT device may obtain, by querying the mapping table, the internal network
address 192.168.0.100:10000 that has a mapping relationship with the external network
address 210.21.12.140:2000.
(4) The NAT device modifies the destination address of the data packet, and then sends
the data packet to the terminal 1 in an internal network. Modifying the destination
address of the data packet by the NAT device is modifying the external network address
(210.21.12.140:2000) to the internal network address (210.15.27.166:8000) mapped to
the external network address.
[0051] It can be learned from the working process of the NAT device that the NAT device
implements address mapping by modifying the source address and the destination address
of the data packet. A working principle of the NAT device may be summarized as follows:
The external network may send data to the internal network terminal only when the
internal network terminal actively sends data to the external network. A source address
of data sent from the internal network to the external network is modified, and a
destination address of a data packet sent from the external network to the internal
network is modified.
[0052] It should be understood that either of two terminals behind different NAT devices,
such as a first terminal and a second terminal, may directly send a user datagram
protocol (user datagram protocol, UDP) packet to an external network address of the
other terminal for communication if the terminal knows the external network address
mapped by a NAT device of the other terminal. In other words, NAT traversal is implemented.
However, the terminal cannot directly obtain a NAT external network address of the
terminal. Generally, a network device (for example, a server) needs to be introduced
to help the terminal obtain the external network address of the terminal. The following
uses a cone NAT-cone NAT combination as an example to describe a NAT traversal process.
[0053] FIG. 3 is a schematic diagram of a NAT traversal process based on the cone NAT-cone
NAT combination. The following steps are included:
S101: A first terminal sends a query message to a network device through a first NAT
device, to query an external network address of the first terminal, and the network
device returns the external network address of the first terminal to the first terminal.
The external network address of the first terminal may be configured by the first
NAT device. A specific process may be as follows: After the first terminal sends the
query message to the network device through the first NAT device, the first NAT device
configures, for the first terminal based on the query message, the external network
address corresponding to the first terminal, and then the network device sends the
external network address information to the first terminal.
S 102: A second terminal sends a data packet to the network device through a second
NAT device, to query an external network address of the second terminal, and the network
device returns the external network address of the second terminal to the second terminal.
S103: The network device sends the external network address of the first terminal
to the second terminal.
It should be understood that the network device sends the external network address
of the second terminal to the second terminal through the first NAT device.
S104: The network device sends the external network address of the second terminal
to the first terminal.
It should be understood that the network device sends the external network address
of the second terminal to the first terminal through the second NAT device.
S105: The first terminal sends a hole punching message to the external network address
of the second terminal, where the hole punching message is used to generate a mapping
table of a second external network address by the first NAT device.
S 106: The second NAT device sends a passthrough request message to the first terminal,
to attempt to establish a P2P channel.
[0054] It should be understood that, when the second NAT device sends the passthrough request
message for the first terminal, the second NAT device generates a mapping table of
a first external network address. The first NAT device already generates the mapping
table of the second external network address in advance in step S105. Therefore, in
this step, the passthrough request message sent through the second external network
address may reach the first terminal. S107: After receiving the passthrough request
message sent through the second external network address, the first terminal sends
a passthrough response message to the second external network address. In step S106,
the mapping table of the first external network address is generated when the second
terminal sends the passthrough request message to the first external network address
through the second external network address. Therefore, the mapping table of the first
external network address may be found on the second NAT device. The passthrough response
message can reach the second terminal, so that NAT traversal is implemented, and the
P2P channel is successfully established. It should be understood that a working principle
of the NAT device is as follows: An external packet may reach an internal network
terminal through the NAT device only when a packet is first sent from inside the NAT
device. Therefore, if the internal packet is not sent first, when receiving the external
packet, the NAT device discards the external packet because the NAT device cannot
find a mapping table. For ease of understanding, the external packet in this case
is referred to an "unsolicited" packet. As technologies develop, currently, many NAT
devices have a time sequence requirement. To be specific, after discarding the "unsolicited"
packet, the NAT device blacklists a source IP address and a port that are used to
send the "unsolicited" packet (where the source IP address and the port may be automatically
deleted after a period of time). Once the source IP address is blacklisted, a packet
sent from the source IP address cannot enter the NAT device. Therefore, when the NAT
device has the time sequence requirement, NAT traversal cannot be implemented.
[0055] The following describes a process in which the NAT traversal fails due to the time
sequence requirement of the NAT device with reference to the accompanying drawings.
[0056] FIG. 4 is a schematic diagram of a NAT traversal process. The following steps are
included: S201: A first terminal sends a query message to a network device, to query
an external network address of the first terminal, and the network device returns
a first external network address of the first terminal to the first terminal. S202:
A second terminal sends a query message to the network device, to query an external
network address of the second terminal, and the network device returns a second external
network address of the second terminal to the second terminal.
[0057] S203: The network device sends the first external network address of the first terminal
to the second terminal.
[0058] S204: The network device sends the second external network address of the second
terminal to the first terminal.
[0059] S205: The first terminal sends a hole punching message to the second external network
address, where when the hole punching message is sent from a first NAT device, the
first NAT device generates a mapping table of the second external network address;
because a mapping table of the first external network address cannot be found on a
second NAT device, the hole punching message is an "unsolicited" packet; and the first
external network address is blacklisted. S206: The second terminal sends a passthrough
request message to the first terminal, where when the passthrough request message
is sent from the second NAT device, the second NAT device generates the mapping table
of the first external network address; and because in step S205, the first NAT device
already generates the mapping table of the second external network address in advance,
the passthrough request message may reach the first terminal.
[0060] S207: After receiving the passthrough request message, the first terminal sends a
passthrough response message to the second external network address, where it should
be understood that in this case, although the mapping table of the first external
network address can be found on the second NAT device, because the first external
network address is already blacklisted, the passthrough response message cannot reach
the second terminal, and a P2P channel fails to be established.
[0061] For the foregoing problem of a NAT traversal failure caused by a time sequence of
a NAT device, currently, time to live (time to live, TTL) may be set, so that a hole
punching message can be sent from a local NAT device but cannot reach a peer NAT device,
and the local NAT device can generate a mapping table. In this way, an external packet
may be sent in without making the hole punching message "unsolicited", to prevent
a local external network address from being blacklisted.
[0062] However, in a currently used method, TTL is set to a fixed empirical value, and existing
network devices vary greatly. For example, quantities of hops between terminals and
NAT devices are different. As shown in FIG. 4, the first terminal needs to reach the
local NAT device through three hops, but the second terminal can reach the local NAT
device through two hops. Therefore, setting the TTL to a fixed value has a great limitation.
As long as TTL of a traversal party does not meet the set empirical value, the traversal
fails.
[0063] To address the foregoing problem, an embodiment of this application provides a NAT
traversal method. TTL is bidirectionally dynamically detected by a local end and a
peer end, to adapt to NAT devices with different TTL in an existing network, so as
to resolve a problem of low traversal efficiency of a NAT device having a time sequence
requirement.
[0064] FIG. 5 is a schematic diagram of a NAT traversal process according to an embodiment
of this application.
[0065] It should be understood that the NAT traversal method provided in this embodiment
of this application may be applied to a system that includes at least one terminal
and in which different terminals are located in networks constructed by different
NAT devices, for example, applied to a system in which a first terminal communicates
with a second terminal. The first terminal is a terminal in a network constructed
by a first NAT device, the second terminal is a terminal in a network constructed
by a second NAT device, and the first NAT device is different from the second NAT
device. Both the first NAT device and the second NAT device may be cone NAT devices.
The NAT traversal process includes the following steps.
[0066] S301: The first terminal sends a first query message to a network device, to query
an external network address corresponding to the first terminal, and the network device
sends the external network address of the first terminal to the first terminal based
on the first query message.
[0067] It should be understood that the first terminal is one of at least one terminal in
the network constructed by the first NAT device, and the first NAT device may be a
cone NAT device.
[0068] In an implementation, the first terminal may send the first query message to the
network device through the first NAT device. The first NAT device independently configures
the corresponding external network address for the first terminal based on the first
query message, and then a server S sends the external network address to the first
terminal through the first NAT device.
[0069] S302: The second terminal sends a second query message to the network device, to
query an external network address corresponding to the second terminal, and the network
device sends the external network address of the second terminal to the second terminal
based on the second query message.
[0070] It should be understood that the second terminal is one of at least one terminal
in the network constructed by the second NAT device. The second NAT device may be
a cone NAT device, and the second NAT device is different from the first NAT device.
[0071] In an implementation, the second terminal may send the second query message to the
network device through the second NAT device. The second NAT device independently
configures the corresponding external network address for the second terminal based
on the second query message, and then the server S sends the external network address
to the second terminal through the second NAT device.
[0072] S303: The network device sends the external network address corresponding to the
second terminal to the first terminal. It should be understood that the network device
sends the external network address corresponding to the second terminal to the first
terminal through the first NAT device.
[0073] S304: The network device sends the external network address corresponding to the
first terminal to the second terminal. It should be understood that the network device
sends the external network address corresponding to the first terminal to second terminal
through the second NAT device.
[0074] S305: The first terminal sets first TTL.
[0075] In an implementation, a value of the first TTL may be less than a smaller value of
a first hop count and a second hop count. The first hop count is a quantity of network
segments between the first terminal and the first NAT device, or a quantity of network
segments that a message sent by the first terminal needs to pass to reach the first
NAT device. The second hop count is a quantity of network segments between the second
terminal and the second NAT device, or a quantity of network segments that a message
sent by the second terminal needs to pass to reach the second NAT device. The first
TTL may be, for example, 1.
[0076] S306: The first terminal determines whether the first terminal receives, within the
set TTL, a first passthrough message sent by the second terminal, and when the first
terminal does not receive the first passthrough message within the set TTL, the first
terminal sends a second passthrough message to the second terminal, and determines
whether the first terminal receives a first response message sent by the second terminal.
[0077] Because the first TTL in step S305 is a value tentatively set by the first terminal,
the first terminal needs to determine, based on whether a passthrough message sent
by a peer end can be received within the first TTL, whether NAT traversal succeeds.
Whether the first terminal can receive the first passthrough message sent by the second
terminal depends on whether the first NAT device already generates an address mapping
table in advance, that is, whether the first NAT device receives a hole punching message
sent by the first terminal.
[0078] In an implementation, after setting the first TTL, the first terminal sends a first
hole punching message to the first NAT device. If the first hole punching message
can reach the first NAT device within the first TTL, the first NAT device may establish
a mapping table of a destination address corresponding to the first hole punching
message, namely, a mapping table of the external network address corresponding to
the second terminal, and the first passthrough message subsequently sent by the second
terminal to the first terminal may be successfully transmitted to the first terminal.
In this case, the first terminal device may send a second response message to the
second terminal device. If the first hole punching message does not reach the first
NAT device within the first TTL, the first NAT device does not generate a mapping
table of the external network address corresponding to the first terminal. When the
first NAT device subsequently receives the first passthrough message sent by the second
terminal to the first terminal, the message is not transmitted to the first terminal
in an internal network. In other words, the first terminal cannot receive the first
passthrough message. In addition, due to a time sequence requirement of a NAT device,
the external network address corresponding to the second terminal is blacklisted.
In this case, the NAT traversal fails. In other words, if the first NAT device does
not generate the mapping table of the destination address when the first terminal
sets time to live to the first TTL, when receiving a first passthrough request message
sent by the second terminal, the first NAT device cannot find, in the mapping table,
information about the external network address corresponding to the second terminal.
The passthrough request message is considered as an "unsolicited" message, and the
first NAT device blacklists the external network address corresponding to the second
terminal.
[0079] It should be understood that the TTL is a maximum quantity of network segments (namely,
hops) that a data packet is allowed to pass before being discarded by a router. When
the value of the TTL is less than a hop count between a terminal and a NAT device,
a hole punching message cannot reach the NAT device. The NAT device cannot generate
a mapping table of a destination address, and therefore, the NAT traversal fails.
In this case, the value of the TTL needs to be reset until the value of the TTL is
equal to the smaller value of the first hop count and the second hop count, so that
the NAT traversal can succeed. For example, in a network scenario shown in FIG. 5,
a quantity of hops that the hole punching message needs to pass from the first terminal
to the first NAT device is 4, and TTL of the hole punching message is 1. Therefore,
the hole punching message cannot reach the first NAT device within the first TTL,
and the first NAT device cannot generate the mapping table of the external network
address corresponding to the second terminal. Consequently, hole punching fails.
[0080] In an implementation, after the first NAT device blacklists the external network
address corresponding to the second terminal, the second terminal can no longer receive
the message sent by the first terminal. When the second terminal determines that the
second response message sent by the first terminal is not received within a specific
period of time, the second terminal may determine that the external network address
of the second terminal is blacklisted. In this case, the second terminal may re-request,
from the network device, to change the external network address corresponding to the
second terminal. The network device may reconfigure an external network address for
the second terminal through the second NAT device.
[0081] In an implementation, when the first terminal does not receive the first passthrough
message within the first TTL, the NAT traversal fails. In this case, the second terminal
may detect whether the NAT traversal can be implemented within the first TTL. Specifically,
after changing the external network address corresponding to the second terminal,
the second terminal sets the first TTL, and sends a second hole punching message to
the second NAT device within the first TTL. Within the first TTL, if the second hole
punching message can reach the second NAT device, the NAT device may generate the
mapping table of the destination address. In this case, the second terminal may receive
the second passthrough message sent by the first terminal. If the second hole punching
message cannot reach the second NAT device, the NAT device cannot generate the mapping
table of the destination address. In this case, the second terminal cannot receive
the second passthrough message sent by the first terminal.
[0082] It should be understood that the first terminal may periodically send the first passthrough
message to the second terminal, and the second terminal may also periodically send
the second passthrough message to the first terminal.
[0083] For example, in the network scenario shown in FIG. 5, a quantity of hops that the
second hole punching message needs to pass from the second terminal to the second
NAT device is 5, and TTL of the hole punching message is 1. Therefore, the hole punching
message cannot reach the second NAT device when the TTL is the first TTL, and the
second NAT device cannot generate the mapping table of the external network address
corresponding to the second terminal. Consequently, the hole punching fails.
[0084] In an implementation, if the second terminal receives the second passthrough message
sent by the first terminal, the second terminal determines that the NAT traversal
succeeds, and the second terminal may send the first response message to the first
terminal. In this case, the first terminal may determine, based on whether the first
response message is received, whether the second passthrough message is received by
the second terminal, that is, whether the NAT traversal succeeds.
[0085] S307: If the first terminal receives the first response message sent by the second
terminal, the first terminal determines that the NAT traversal succeeds; or if the
first terminal does not receive the first response message sent by the second terminal,
after changing the external network address corresponding to the first terminal and
resetting the TTL, the first terminal repeats the foregoing process until the first
terminal receives the first passthrough message or the first response message, and
determines that the NAT traversal succeeds.
[0086] In an implementation, if the second hole punching message reaches the second NAT
device within the first TTL, the second NAT device generates the mapping table of
the external network address corresponding to the second terminal. When the second
NAT device subsequently receives the second passthrough message sent by the first
terminal to the second terminal, the message is transmitted to the second terminal,
and the second terminal sends the first response message to the first terminal. In
this case, the NAT traversal succeeds.
[0087] In an implementation, if the second hole punching message does not reach the second
NAT device within the first TTL, the second NAT device does not generate the mapping
table of the external network address corresponding to the second terminal. When the
second NAT device subsequently receives the second passthrough message sent by the
first terminal to the second terminal, the message is not transmitted to the second
terminal, and the second terminal does not send the first response message to the
first terminal. When the first terminal does not receive the first response message
within a specific period of time, it is determined that the external network address
corresponding to the first terminal is blacklisted.
[0088] In an implementation, after the external network address corresponding to the first
terminal is blacklisted, the first terminal may re-request, from the network device,
to change the external network address. The network device may reallocate, to the
first terminal, an external network address corresponding to the first terminal, that
is, change the external network address corresponding to the first terminal.
[0089] In an implementation, when the second passthrough message is not received by the
second terminal, the first terminal resets the value of the TTL, for example, sets
the value to second TTL. The second TTL is different from the first TTL. For example,
the second TTL may be greater than the first TTL.
[0090] In an implementation, after resetting the value of the TTL, the first terminal repeatedly
determines whether the first passthrough message is received. If the first passthrough
message is received, the NAT traversal succeeds. If the first passthrough message
is not received, the first terminal sends the second passthrough message to the second
terminal again. When the second passthrough message is received by the second terminal,
the first terminal receives the first response message sent by the second terminal.
In this case, the NAT traversal succeeds. When the second passthrough message is not
received by the second terminal, and the external network address corresponding to
the first terminal is blacklisted by the second NAT device, the first terminal changes
the external network address corresponding to the first terminal, resets the TTL,
and repeats the foregoing process until the first terminal can receive the first passthrough
message or the first response message when the TTL is set to a value, that is, until
the NAT traversal succeeds.
[0091] It should be understood that operation steps of the second terminal correspond to
those of the first terminal, and details are not described herein again.
[0092] It should be understood that, when it is determined, by using the foregoing steps,
that the first terminal or the second terminal do not receive, within the first TTL,
the passthrough message sent by the peer end, the value of the TTL needs to be reset.
For example, the value of the TTL may be increased, and the foregoing processes of
the two terminals are repeated until the value of the TTL can enable the NAT traversal
to succeed.
[0093] In an example, the second TTL is reset, where the second TTL is greater than the
first TTL. For example, the second TTL is 4. It is determined whether the hole punching
message sent by the first terminal can reach the external network address corresponding
to the first terminal within the second TTL (where the external network address is
a changed external network address). In the scenario shown in FIG. 5, the hole punching
message sent by the first terminal needs to pass four hops to reach the first NAT
device. When the second TTL is 4, the hole punching message can exactly reach the
first NAT device but cannot reach the second NAT device. Therefore, the hole punching
message is successfully sent from the local NAT device, the first NAT device may generate
the mapping table of the external network address corresponding to the second terminal,
and the hole punching succeeds.
[0094] In an implementation, after the hole punching succeeds, if the second terminal sends
the first passthrough request message to the first terminal through the external network
address, because the first NAT device already generates the mapping table of the external
network address corresponding to the second terminal in advance, the first NAT device
may find, in the mapping table, mapping information of the external network address
corresponding to the second terminal, and the passthrough request message may reach
the first terminal. In this process, the second NAT device sends the passthrough request
message for the first terminal. Therefore, the second NAT device may generate the
mapping table of the external network address corresponding to the first terminal.
[0095] According to the NAT traversal method provided in this embodiment of this application,
TTL of sending messages by a local end and a peer end is detected and the TTL values
are dynamically adjusted, to determine that a message sent by one end in peer-to-peer
communication can exactly reach a NAT device at the end but does not reach a NAT device
at the peer end. In this way, one end generates a mapping table and an external network
address of the end is not blacklisted, so that the NAT traversal is finally implemented.
[0096] It should be understood that the value of the TTL may be tested from a relatively
small value that can be obtained for the TTL. For example, if quantities of hops between
terminals and corresponding NAT devices at ends are roughly determined, and the value
of the TTL should not be greater than a smallest quantity of hops in the quantities
of hops at the ends. When the value of the TTL is relatively small, and hole punching
messages sent by the terminals at the ends do not reach the corresponding NAT devices,
the value of the TTL is appropriately increased, and the foregoing determining process
is repeated until a hole punching message sent by a terminal at an end can reach a
corresponding NAT device and does not reach a NAT device at a peer end. In this case,
the hole punching succeeds. The end at which the hole punching message first reaches
the corresponding NAT device but does not reach the NAT device at the peer end may
be an end that has a smallest quantity of hops between a terminal and a corresponding
NAT device.
[0097] With reference to the accompanying drawings, the following describes a scenario to
which the NAT traversal method provided in the embodiments of this application may
be applied.
[0098] FIG. 6 is a schematic diagram of applying the NAT traversal method to a peer-to-peer
communication scenario according to an embodiment of this application.
[0099] It should be understood that the NAT traversal method provided in the embodiments
of this application may be applied to the P2P communication scenario, for example,
a scenario in which users perform an Internet call (for example, a voice call or a
video call). As shown in FIG. 6, when a NAT device in a network in which a first user
is located may be a cone NAT device having a time sequence requirement, and a NAT
device in a network in which a second user is located may also be a cone NAT device
having a time sequence requirement, NAT traversal may be implemented by using a bidirectional
TTL detection method provided in this embodiment of this application. The following
briefly describes the NAT traversal method provided in the embodiments of this application
in this scenario.
[0100] S401: The first user initiates a call to the second user through a server.
[0101] It should be understood that the call initiated by the first user may be, for example,
a voice call or a video call. S402: After a call request reaches the second user,
the first user and the second user may implement the NAT traversal by using the NAT
traversal method provided in the embodiments of this application. For a specific process
of the NAT traversal method, refer to related descriptions in FIG. 5. To avoid repetition,
details are not described herein again. S403: The first user and the second user perform
a P2P network call, where the P2P network call is performed without using the server.
[0102] According to the NAT traversal method provided in the embodiments of this application,
the NAT traversal is performed by using the bidirectional TTL detection solution,
so that the NAT traversal can be successfully completed when a NAT device has the
time sequence requirement, so as to implement peer-to-peer communication. In addition,
in the NAT traversal method provided in the embodiments of this application, the NAT
traversal may be successfully implemented as long as TTL at one of two or more ends
at which the NAT traversal is performed ensures that a hole punching message is sent
from a NAT device at the end and does not reach a NAT device at another end.
[0103] FIG. 7 is a schematic diagram of a structure of a terminal device according to an
embodiment of this application. A terminal device 700 includes a processing module
710 and a sending module 720.
[0104] In an implementation, the processing module 710 is configured to: set first time
to live (TTL), and determine whether a first terminal can receive, within the first
TTL, a first passthrough message sent by a second terminal.
[0105] In an implementation, the sending module 720 is configured to: when the first terminal
does not receive the first passthrough message, send a second passthrough message
to the second terminal.
[0106] In an implementation, the processing module 710 is further configured to: if the
second passthrough message is not received by the second terminal, reset the value
of the TTL until the first terminal receives the first passthrough message or the
second terminal receives the second passthrough message, and determine that NAT traversal
succeeds. In an implementation, that the processing module 710 resets the value of
the TTL and repeats the foregoing process includes: The processing module 710 resets
the value of the TTL to second TTL, where the second TTL is greater than the first
TTL. The processing module 710 determines whether the first passthrough message can
be received within the second TTL. When the first terminal does not receive the first
passthrough message, the sending module 720 sends the second passthrough message to
the second terminal through a changed external network address. When the second passthrough
message is not received by the second terminal, the processing module 710 resets the
value of the TTL again.
[0107] In an implementation, the first TTL is not greater than a smaller value of a first
hop count and a second hop count. The first hop count is a quantity of network segments
between the first terminal and a first NAT device, and the second hop count is a quantity
of network segments between the second terminal and a second NAT device.
[0108] It should be understood that the first NAT device and the second NAT device in this
embodiment of this application may be cone NAT devices.
[0109] In an implementation, the sending module 720 is further configured to send first
query information to a network device through the first NAT device. The first query
information is used to query an external network address corresponding to the first
terminal. The terminal further includes a receiving module, and the receiving module
is configured to receive first response information sent by the network device. The
first response information includes the external network address corresponding to
the first terminal.
[0110] FIG. 8 is a schematic diagram of a structure of a NAT device according to an embodiment
of this application. The NAT device is used in a system in which a first terminal
communicates with a second terminal. The first terminal is a terminal in a network
constructed by a first NAT device, the second terminal is a terminal in a network
constructed by a second NAT device, and the first NAT device is different from the
second NAT device. The structure of the NAT device shown in FIG. 8 may be a structural
diagram of the first NAT device or a structural diagram of the second NAT device in
this embodiment of this application. A NAT device 800 includes a sending module 810
and a processing module 820.
[0111] In an implementation, the sending module 810 is configured to send a first passthrough
message to the first terminal when TTL is first TTL.
[0112] In an implementation, the processing module 820 is configured to: if the first passthrough
message cannot be received by the first terminal, determine whether a hole punching
message sent by the second terminal is received.
[0113] In an implementation, the processing module 820 is further configured to: when the
second NAT device does not receive the hole punching message, if the second NAT device
receives a second passthrough message sent by the first terminal, blacklist an external
network address corresponding to the first terminal, and after resetting the value
of the TTL, repeats the foregoing process until the first passthrough message is received
by the first terminal or the first NAT device receives the hole punching message.
[0114] In an implementation, the sending module 810 is further configured to send the first
passthrough message to the first terminal within second TTL, where the second TTL
is greater than the first TTL. If the first passthrough message cannot be received
by the first terminal, the processing module 820 is further configured to determine
whether the hole punching message sent by the second terminal is received. When the
second NAT device does not receive the hole punching message, if the second NAT device
receives the second passthrough message sent by the first terminal, the processing
module 820 is configured to: blacklist a changed external network address corresponding
to the first terminal, and after resetting the value of the TTL again, repeat the
foregoing process.
[0115] In an implementation, the first TTL is not greater than a smaller value of a first
hop count and a second hop count. The first hop count is a quantity of hops between
the first terminal and the first NAT device, and the second hop count is a quantity
of hops between the second terminal and the second NAT device.
[0116] It should be understood that the first NAT device and the second NAT device in this
embodiment of this application may be cone NAT devices.
[0117] In addition, an embodiment of this application further provides a communications
system. The communications system includes at least one terminal device, at least
one NAT device, and a server. The terminal device and the NAT device are configured
to perform the method provided in the embodiments of this application.
[0118] A person of ordinary skill in the art may be aware that units and algorithm steps
in the examples described with reference to the embodiments disclosed in this specification
can be implemented by electronic hardware or a combination of computer software and
electronic hardware. Whether the functions are performed by hardware or software depends
on particular applications and design constraint conditions of the technical solutions.
A person skilled in the art may use different methods to implement the described functions
for each particular application, but it should not be considered that the implementation
goes beyond the scope of this application.
[0119] It may be clearly understood by a person skilled in the art that, for the purpose
of convenient and brief description, for a detailed working process of the foregoing
system, apparatus, and unit, refer to a corresponding process in the foregoing method
embodiments, and details are not described herein again.
[0120] In the several embodiments provided in this application, it should be understood
that the disclosed system, apparatus, and method may be implemented in other manners.
For example, the described apparatus embodiment is merely an example. For example,
division into the units is merely logical function division and may be other division
in an actual implementation. For example, a plurality of units or components may be
combined or integrated into another system, or some features may be ignored or not
performed. In addition, the displayed or discussed mutual couplings or direct couplings
or communication connections may be implemented through some interfaces. The indirect
couplings or communication connections between the apparatuses or units may be implemented
in electronic, mechanical, or other forms.
[0121] The units described as separate parts may or may not be physically separate, and
parts displayed as units may or may not be physical units, may be located in one location,
or may be distributed on a plurality of network units. A part or all of the units
may be selected based on an actual requirement to achieve the objectives of the solutions
of the embodiments.
[0122] In addition, function units in the embodiments of this application may be integrated
into one processing unit, or each of the units may exist alone physically, or two
or more units may be integrated into one unit.
[0123] When the functions are implemented in a form of a software functional unit and sold
or used as an independent product, the functions may be stored in a computer-readable
storage medium. Based on such an understanding, the technical solutions of this application
essentially, or the part contributing to the conventional technology, or some of the
technical solutions may be implemented in a form of a software product. The computer
software product is stored in a storage medium, and includes several instructions
for instructing a computer device (which may be a personal computer, a server, or
a network device) to perform all or some of the steps of the methods described in
the embodiments of this application. The foregoing storage medium includes: any medium
that can store program code, such as a USB flash drive, a removable hard disk, a read-only
memory (read-only memory, ROM), a random access memory (random access memory, RAM),
a magnetic disk, or an optical disc.
[0124] The foregoing descriptions are merely specific implementations of this application,
but are not intended to limit the protection scope of this application. Any variation
or replacement readily figured out by a person skilled in the art within the technical
scope disclosed in this application shall fall within the protection scope of this
application. Therefore, the protection scope of this application shall be subject
to the protection scope of the claims.