A method, device and server for determining a NAT type of a terminal device

By constructing a network topology and identifying key terminal devices, and periodically probing their NAT types, the problem of wasted resources in NAT type detection for terminal devices in large-scale network environments is solved, and efficient NAT type determination is achieved.

CN123145232APending Publication Date: 2026-11-20ZHEJIANG DAHUA TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611601468.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-15
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

In large-scale network environments, existing technologies detect NAT types independently and periodically on each terminal device, leading to a waste of network bandwidth and server computing resources. How can we reduce the overall overhead of NAT type detection?

Method used

By acquiring the routing path information of the terminal devices managed by the server, a network topology is constructed, key terminal devices and their associated terminal devices are identified, and the NAT type of key terminal devices is periodically detected. The real-time NAT type of all terminal devices is determined using the topology and baseline NAT type.

Benefits of technology

This reduces redundant detection, lowers the overall overhead for terminal devices to determine the NAT type, and improves resource utilization efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123145232A_ABST
    Figure CN123145232A_ABST
Patent Text Reader

Abstract

The application relates to a method, device and server for determining the NAT type of a terminal device, the method comprising: acquiring routing path information of each terminal device managed by the server, and constructing a network topology structure according to the routing path information of all terminal devices; acquiring a reference NAT type of each terminal device, and identifying a key terminal device and associated terminal devices associated with the key terminal device from all terminal devices according to the network topology structure and the reference NAT type of each terminal device; periodically detecting the NAT type of each key terminal device to obtain a detection result of the key terminal device, and determining the real-time NAT type of the key terminal device and the associated terminal devices of the key terminal device in a current detection period according to the detection result of the key terminal device. The application can reduce the overall cost of NAT type detection.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of communication technology, and in particular to a method, apparatus, and server for determining the NAT type of a terminal device. Background Technology

[0002] Network Address Translation (NAT) is a technology that translates private IP addresses into public IP addresses when passing through routers or firewalls. The NAT type of a terminal device refers to the method by which the NAT device maps its private IP address to the public network when the device communicates with the external network. Terminal device NAT types include at least cone and symmetric. In the field of P2P (Peer-to-Peer) communication, terminal devices with cone NAT types are more likely to establish P2P connections than those with symmetric NAT types. Therefore, accurately determining the NAT type of each terminal device is crucial for selecting the optimal traversal strategy and improving connection success rates.

[0003] Currently, mainstream NAT type detection schemes determine the NAT type of each terminal device by having each terminal device independently and periodically send detection requests to the server. This end-to-end detection method is acceptable in small-scale network environments, but in large-scale terminal deployment scenarios, a large number of terminal devices simultaneously or periodically initiating detection will consume a lot of network bandwidth and server computing resources, resulting in a significant waste of resources.

[0004] Therefore, how to reduce the overall overhead of NAT type detection in large-scale network environments has become a key technical problem that urgently needs to be solved in this field. Summary of the Invention

[0005] In view of this, this application provides a method, apparatus, and server for determining the NAT type of a terminal device, so as to reduce the overall overhead of NAT type detection.

[0006] Firstly, this embodiment provides a method for determining the NAT type of a terminal device, the method being applied to a server, the method comprising:

[0007] Obtain the routing path information of each terminal device managed by the server, and construct the network topology based on the routing path information of all terminal devices;

[0008] Obtain the baseline NAT type of each terminal device, and based on the network topology and the baseline NAT type of each terminal device, identify the key terminal devices and the associated terminal devices associated with the key terminal devices from all terminal devices;

[0009] For each critical terminal device, the NAT type of the critical terminal device is periodically probed to obtain the probe results of the critical terminal device. Based on the probe results of the critical terminal device, the real-time NAT type of the critical terminal device and its associated terminal devices in the current probe period is determined.

[0010] Secondly, this embodiment provides an apparatus for determining the NAT type of a terminal device. The apparatus is applied to a server and includes:

[0011] The construction module is used to obtain the routing path information of each terminal device managed by the server, and to construct the network topology based on the routing path information of all terminal devices.

[0012] The identification module is used to obtain the baseline NAT type of each terminal device, and based on the network topology and the baseline NAT type of each terminal device, identify key terminal devices and associated terminal devices from all terminal devices.

[0013] The determination module is used to periodically probe the NAT type of each key terminal device, obtain the probe results of the key terminal device, and determine the real-time NAT type of the key terminal device and its associated terminal devices in the current probe period based on the probe results of the key terminal device.

[0014] Thirdly, this embodiment provides a server including a memory and a processor, the memory storing a computer program, and the processor being configured to run the computer program to perform the method for determining the NAT type of a terminal device as described in the first aspect.

[0015] The method, apparatus, and server provided in this application for determining the NAT type of terminal devices obtain routing path information of each terminal device managed by the server, construct a network topology based on the routing path information of all terminal devices, and then obtain the baseline NAT type of each terminal device. Based on the network topology and the baseline NAT type of each terminal device, key terminal devices and their associated terminal devices are identified from all terminal devices. For each key terminal device, its NAT type is periodically probed to obtain the probe result. Based on the probe result, the real-time NAT type of the key terminal device and its associated terminal devices is determined in the current probe period. In this way, the NAT type of all terminal devices can be determined in real time by periodically probing the NAT type of only a limited number of key terminal devices, eliminating the need for all terminal devices to periodically initiate probes, reducing redundant probes, and lowering the overall overhead of determining the NAT type of terminal devices. Attached Figure Description

[0016] Figure 1 A flowchart of an embodiment of the method for determining the NAT type of a terminal device provided in this application;

[0017] Figure 2 This is a schematic diagram illustrating a constructed network topology as an exemplary embodiment of this application;

[0018] Figure 3 for Figure 2 A schematic diagram of the tree branching corresponding to the network topology shown;

[0019] Figure 4 A flowchart of Embodiment 2 of the method for determining the NAT type of a terminal device provided in this application;

[0020] Figure 5 A flowchart of Embodiment 3 of the method for determining the NAT type of a terminal device provided in this application;

[0021] Figure 6 A flowchart of Embodiment 4 of the method for determining the NAT type of a terminal device provided in this application;

[0022] Figure 7 A flowchart of Embodiment 5 of the method for determining the NAT type of a terminal device provided in this application;

[0023] Figure 8 A schematic diagram of the device for determining the NAT type of a terminal device provided in this application. Detailed Implementation

[0024] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application.

[0025] The terminology used in this application is for the purpose of describing particular embodiments only and is not intended to be limiting of the application. The singular forms “a,” “the,” and “the” used herein are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used herein refers to and includes any and all possible combinations of one or more of the associated listed items.

[0026] It should be understood that although the terms first, second, third, etc., may be used in this application to describe various information, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, without departing from the scope of this application, first information may also be referred to as second information, and similarly, second information may also be referred to as first information. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to determination."

[0027] The following specific embodiments are given to illustrate the technical solution of this application in detail.

[0028] Figure 1 This is a flowchart of an embodiment of the method for determining the NAT type of a terminal device provided in this application. Please refer to... Figure 1 The method provided in this embodiment is applied to a server, and the method may include:

[0029] Step S101: Obtain the routing path information of each terminal device managed by the server, and construct the network topology based on the routing path information of all terminal devices.

[0030] Before introducing the method for determining the NAT type of a terminal device provided in this application, let's briefly describe the application scenario. Specifically, the method for determining the NAT type of a terminal device provided in this application is applied to a server in a communication system. This communication system includes a server, terminal devices managed by the server, and NAT devices. Each terminal device accesses the server through one or more cascaded NAT devices. Each NAT device is associated with at least one terminal device, and the communication paths from different terminal devices to the server contain partially overlapping or completely different NAT devices. It can be understood that NAT devices are used to translate private IP addresses into public IP addresses, enabling terminal devices to communicate with the server over the public network.

[0031] The method for determining the NAT type of a terminal device provided in this application is described below.

[0032] Specifically, in step S101, firstly, the routing path information of each terminal device managed by the server is obtained, which is used to characterize the routing path between the terminal device and the server.

[0033] Routing path information can be obtained by each terminal device and reported to the server. For example, the process of the server obtaining routing path information can be implemented through the following steps:

[0034] (1) Each terminal device actively probes the complete routing path information from the terminal device to the server through network segment detection technology. The routing path information is represented as an ordered sequence of routing node addresses, and each element in the routing node address sequence is the IP address of the NAT device that passes through.

[0035] (2) All terminal devices will report the obtained routing path information and their own IP address to the server.

[0036] (3) The server receives and stores the routing path information reported by different terminal devices, as well as the IP address and serial number of each terminal device.

[0037] Optionally, in one possible implementation, the server obtains and stores the routing path information of each terminal device, resulting in a routing path information table as shown in Table 1:

[0038] Table 1: Routing path information for each terminal device obtained by the server

[0039]

[0040] Then, a network topology is constructed based on the routing path information of all terminal devices. This network topology is used to characterize the network connection relationship between the server and the terminal devices.

[0041] Specifically, the server parses the routing path information reported by each terminal device, identifies the network connection relationship between the server and each terminal device, and constructs the network topology.

[0042] For example, in one possible implementation, the process of constructing the above network topology specifically includes:

[0043] (1) For each terminal device, a tree branch is constructed using the address of the bottom routing node in the routing path information of the terminal device as the leaf node and the address of the top routing node in the routing path information as the root node, and the terminal device is associated with the leaf node of the tree branch.

[0044] (2) Aggregate all tree branches to obtain the network topology.

[0045] Specifically, referring to the example above, in this step, the server constructs a tree branch based on the routing path information reported by each terminal device. The bottom-level routing node in the routing path information, i.e., the leftmost IP address in the routing path information in Table 1, which is the IP address of the NAT device closest to the terminal device, is used as the leaf node. The top-level routing node address in the routing path information, i.e., the rightmost IP address in the routing path information in Table 1, which is the IP address of the NAT device closest to the server, is used as the root node. At the same time, the terminal device is associated with the leaf node of this tree branch.

[0046] Furthermore, the server aggregates all tree branches to obtain the aforementioned network topology. Specifically, Figure 2 This is a schematic diagram illustrating a constructed network topology as shown in an exemplary embodiment of this application. Please refer to... Figure 2 Understandably, the server generates a globally unique topology identifier for each tree branch and associates all terminal devices on that tree branch with that topology identifier. Furthermore, the same terminal device can be located on different tree branches, meaning that the terminal device can be bound to the topology identifiers of multiple tree branches simultaneously.

[0047] Specifically, Figure 3 for Figure 2 The diagram shows a tree branching pattern corresponding to the network topology. Please refer to it. Figure 3 ,exist Figure 2 The network topology shown has 4 tree branches.

[0048] Step S102: Obtain the baseline NAT type of each terminal device, and based on the network topology and the baseline NAT type of each terminal device, identify the key terminal devices and the associated terminal devices associated with the key terminal devices from all terminal devices.

[0049] Specifically, first, the server obtains the baseline NAT type of each terminal device. For example, this can be achieved in the following way:

[0050] The server starts multiple STUN (Session Travesal Utilities for NAT) services, each bound to a different port. The terminal device sends STUN requests to the multiple STUN services to obtain the external IP address and port after passing through the exit NAT device. If the external port numbers returned by the multiple STUN services are consistent, the base NAT type of the terminal device can be determined to be cone; otherwise, the base NAT type of the terminal device can be determined to be symmetric.

[0051] Then, based on the network topology and the baseline NAT type of each terminal device, the server identifies the key terminal devices and the associated terminal devices associated with the key terminal devices from all terminal devices.

[0052] Among them, key terminal equipment refers to the terminal equipment selected from all terminal equipment based on the network topology and the baseline NAT type of each terminal equipment, which is used to determine the real-time NAT type of itself and associated terminal equipment.

[0053] Furthermore, the key terminal equipment includes the first type of key terminal equipment with a symmetric NAT type as the baseline, and the second type of key terminal equipment with a cone-shaped NAT type as the baseline.

[0054] It should be noted that in the network topology constructed in this application, the NAT device node closest to the server in each tree branch is determined as the root node, and the NAT device node closest to the terminal device is determined as the leaf node; the term "downstream direction" in this application refers to the direction from the root node to the leaf node, "upstream direction" refers to the direction from the leaf node to the root node, and "same level" refers to two terminal devices being associated with the same NAT device.

[0055] It is understandable that the NAT type of a terminal device may appear externally as symmetrical or cone-shaped, each with the following characteristics: Because symmetrical NAT devices have stricter mapping rules, once a symmetrical NAT device exists in the communication path of a terminal device, the traffic of the terminal device directly associated with that symmetrical NAT device, as well as all terminal devices downstream of that symmetrical NAT device, will pass through that symmetrical NAT device, thus inheriting its symmetrical characteristics. In other words, the symmetrical characteristics are passed along the tree branch from the symmetrical NAT device to its downstream terminal devices. The NAT type of that terminal device, its peer terminal devices, and its downstream terminal devices are all symmetrical.

[0056] Conversely, if a terminal device actually exhibits a cone-shaped NAT type, it means that there are no symmetric NAT devices on the path from that terminal device to the root node; otherwise, the terminal device will also exhibit a symmetric NAT type due to inheriting the symmetric NAT characteristic. Therefore, on the path from this cone-shaped terminal device to the root node, all terminal devices have a cone-shaped NAT type, unaffected by the symmetric NAT rule. In other words, the NAT type of this cone-shaped terminal device, its peers, and its upstream terminals are all cone-shaped.

[0057] Therefore, for a given terminal device, if the detection result shows that the NAT type of that terminal device is symmetrical, then the NAT types of its peers and downstream terminals are also symmetrical. If the detection result shows that the NAT type of that terminal device is cone-shaped, then the NAT types of its peers and upstream terminals are also cone-shaped. Therefore, combining the above NAT type characteristics with network topology relationships, it can be seen that not all terminal devices need to actually perform NAT type detection. Several key terminal devices can be identified in the network topology, allowing the NAT type detection results of these key terminal devices to cover their peers, downstream, or upstream terminals, thereby covering all terminal devices in the entire communication system. In other words, because there is a network topology relationship between the terminal devices in the communication system, and the symmetrical NAT and cone-shaped NAT characteristics are transmitted downstream and upstream respectively, it is possible to associate and cover all terminal devices in the entire communication system through a limited number of key terminal devices. Thus, by periodically detecting the NAT types of these key terminal devices, the NAT types of all terminal devices in the entire communication system can be determined based on the NAT type detection results of these key terminal devices and the network topology of the communication system.

[0058] As described above, by using all key terminal devices, based on the principle that symmetric NAT propagates downstream and conical NAT propagates upstream, terminal devices at the same level, downstream or upstream of each key terminal device can be covered respectively, thereby connecting all terminal devices in the entire communication system.

[0059] It is understandable that when a critical terminal device is a Type I critical terminal device (symmetric NAT type), terminal devices at the same level as that critical terminal device, as well as terminal devices downstream of that critical terminal device, are considered associated terminal devices of that critical terminal device. When a critical terminal device is a Type II critical terminal device (conical NAT type), terminal devices at the same level as that critical terminal device, as well as terminal devices upstream of that critical terminal device, are considered associated terminal devices of that critical terminal device. Every terminal device in a communication system is either a critical terminal device itself or an associated terminal device of a certain critical terminal device.

[0060] Therefore, we can first identify the aforementioned key terminal devices to perform periodic NAT type detection tasks. Then, based on the real-time NAT type of the key terminal devices and the network topology of the communication system, we can determine the associated terminal devices of the key terminal devices, and thus determine the real-time NAT type of all terminal devices in the entire communication system.

[0061] Step S103: For each critical terminal device, periodically probe the NAT type of the critical terminal device, obtain the probe result of the critical terminal device, and determine the real-time NAT type of the critical terminal device and its associated terminal devices in the current probe period based on the probe result of the critical terminal device.

[0062] Specifically, referring to the description above, after identifying the key terminal devices and their associated terminal devices, it is only necessary to detect the NAT type of the key terminal devices to determine the NAT types of all terminal devices. Therefore, for each key terminal device, its NAT type is periodically detected to obtain the detection result, which is the real-time NAT type of the key terminal device in the current detection period. Based on the detection result of the key terminal device, the real-time NAT types of its associated terminal devices are determined. In other words, the key terminal device shares its own real-time NAT type with its associated terminal devices.

[0063] The method for determining the NAT type of a terminal device provided in this embodiment is applied to a server. It obtains the routing path information of each terminal device managed by the server, constructs a network topology based on the routing path information of all terminal devices, and then obtains the baseline NAT type of each terminal device. Based on the network topology and the baseline NAT type of each terminal device, it identifies key terminal devices and associated terminal devices from all terminal devices. For each key terminal device, it periodically probes the NAT type of the key terminal device to obtain the probe result of the key terminal device. Based on the probe result of the key terminal device, it determines the real-time NAT type of the key terminal device and its associated terminal devices in the current probe period. In this way, the server parses the routing path information of the terminal devices, constructs the network topology, and, based on the network topology and the baseline NAT type of each terminal device, identifies the key terminal devices and the associated terminal devices. It then probes the key terminal devices and determines the NAT type of the associated terminal devices based on the characteristics of the NAT type. In this way, the NAT type of all terminal devices in the communication system can be obtained. Thus, in this scheme, the NAT type of all terminal devices can be determined in real time by periodically probing the NAT type of only a limited number of key terminal devices, without requiring all terminal devices to periodically initiate probes, reducing redundant probes and lowering the overall overhead of determining the NAT type of terminal devices.

[0064] Figure 4 A flowchart illustrating a second embodiment of the method for determining the NAT type of a terminal device provided in this application. Please refer to... Figure 4Based on the above embodiments, in one possible implementation, the identification of key terminal devices and associated terminal devices from all terminal devices according to the network topology and the baseline NAT type of each terminal device includes:

[0065] Step S401: Identify key terminal devices from all terminal devices based on the network topology and the baseline NAT type of each terminal device.

[0066] Among them, the key terminal equipment is the terminal equipment that performs periodic NAT type probes.

[0067] Specifically, as described above, key terminal devices can be identified based on the baseline NAT type of each terminal device and the network topology of the communication system.

[0068] The specific implementation process of this step will be described in detail in the following embodiments, and will not be repeated here.

[0069] Step S402: For each critical terminal device, based on the baseline NAT type and network topology of the critical terminal device, identify the associated terminal devices of the critical terminal device from other terminal devices besides all critical terminal devices.

[0070] As described above, critical terminal equipment includes Class I critical terminal equipment with a baseline NAT type of symmetry and Class II critical terminal equipment with a baseline NAT type of cone.

[0071] Specifically, after identifying all key terminal devices, the next step is to determine the associated terminal devices among the other terminal devices besides the key terminal devices. The specific steps are as follows:

[0072] For the first type of critical terminal device, namely the critical terminal device with a symmetric NAT type, firstly, the tree branch associated with the first type of critical terminal device is found in the network topology; then, for each tree branch associated with the first type of critical terminal device, the terminal devices at the same level as the first type of critical terminal device, as well as all terminal devices downstream of the first type of critical terminal device, are identified as the associated terminal devices of the first type of critical terminal device.

[0073] Similarly, for the second type of critical terminal device, namely the critical terminal device with a cone-shaped base NAT type, firstly, the tree branch associated with the second type of critical terminal device is found in the network topology; then, the terminal devices at the same level as the second type of critical terminal device, as well as all terminal devices upstream of the second type of critical terminal device, are identified as the associated terminal devices of the second type of critical terminal device.

[0074] The method for determining the NAT type of a terminal device provided in this application first identifies key terminal devices from all terminal devices based on the network topology and the baseline NAT type of each terminal device. Then, for each key terminal device, it identifies associated terminal devices from other terminal devices based on the baseline NAT type of that key terminal device and the network topology. This ensures that there is a clear NAT type sharing relationship between associated terminal devices and key terminal devices, guaranteeing the reliability of subsequent NAT type determination. At the same time, since the associated terminal devices are determined based on the baseline NAT type of the key terminal devices and the network topology, subsequent periodic probing of the key terminal devices is sufficient to determine the real-time NAT type of their associated terminal devices based on the probing results. This eliminates the need for all terminal devices to independently and periodically initiate probing requests to the server, significantly reducing the number of probing requests and overall overhead.

[0075] Furthermore, in this embodiment, the key terminal device and associated terminal device are identified based on the tree branches and their upstream and downstream relationships in the network topology. Even if the terminal devices are located in different network segments in actual deployment, as long as they are in the same tree branch and have an upstream and downstream relationship with the key terminal device, they can share the NAT type detection results of the key terminal device. Therefore, this solution is applicable to complex network environments where terminal devices are distributed in multiple different network segments and different tree branches. That is, it can not only realize NAT type sharing within the same network, but also NAT type sharing across network segments.

[0076] Figure 5 A flowchart of Embodiment 3 of the method for determining the NAT type of a terminal device provided in this application. Please refer to [link to flowchart illustration]. Figure 5 In one possible implementation, the above-mentioned identification of key terminal devices from all terminal devices based on the network topology and the baseline NAT type of each terminal device includes:

[0077] Step S501: For each tree branch in the network topology, search for candidate terminal devices from that tree branch to obtain the candidate terminal devices corresponding to that tree branch; wherein, the candidate terminal devices include a first type of candidate terminal devices and a second type of candidate terminal devices; the first type of candidate terminal devices are the terminal devices closest to the root node of the tree branch and whose base NAT type is symmetric; the second type of candidate terminal devices are the terminal devices closest to the leaf nodes of the tree branch and whose base NAT type is cone.

[0078] Specifically, for each tree branch in the network topology, a first type of candidate terminal device and a second type of candidate terminal device are searched from that tree branch. The baseline NAT type for the first type of candidate terminal device is symmetric, and the baseline NAT type for the second type of candidate terminal device is cone.

[0079] The method for finding the first type of candidate terminal devices is as follows: for each tree branch, traverse from its root node to its leaf node, and determine the first terminal device with a symmetric NAT type as the first type of candidate terminal device; the method for finding the second type of candidate terminal devices is as follows: for each tree branch, traverse from its leaf node to its root node, and determine the first terminal device with a cone NAT type as the second type of candidate terminal device.

[0080] It is understandable that, since the baseline NAT type of terminal devices includes both symmetric and cone types, each tree branch may simultaneously have one or more first-type alternative terminal devices and one or more second-type alternative terminal devices, or it may only have one or more first-type alternative terminal devices and no second-type alternative terminal devices, or it may only have one or more second-type alternative terminal devices and no first-type alternative terminal devices.

[0081] Continue with Figure 3 Taking the tree branching shown as an example, assume that the baseline NAT type of each terminal device is as shown in Table 2:

[0082] Table 2. Baseline NAT Type Table for Terminal Devices

[0083]

[0084] Referring to Table 2, the available terminal devices for each tree branch are analyzed:

[0085] For tree branch 1, traverse from the root node to the leaf node to find the first baseline NAT type symmetric terminal device as the first type of candidate terminal device, namely terminal device 2 and terminal device 4. Traverse from the leaf node to the root node to find the first baseline NAT type cone terminal device as the second type of candidate terminal device, namely terminal device 1. In the same way, traverse tree branches 2, 3, and 4. The first type of candidate terminal devices for tree branch 2 are terminal device 2 and terminal device 4, and the second type of candidate terminal device is terminal device 1. The first type of candidate terminal device for tree branch 3 is terminal device 8, and the second type of candidate terminal devices are terminal device 3 and terminal device 5. There is no first type of candidate terminal device for tree branch 4, and the second type of candidate terminal device is terminal device 9.

[0086] Furthermore, the first and second category candidate terminal devices for each tree branch are summarized, and the summary results are shown in Table 3:

[0087] Table 3 Summary of candidate terminal devices for each tree branch

[0088]

[0089] Step S502: Aggregate the first type of candidate terminal devices corresponding to all tree branches to obtain a first set, and aggregate the second type of candidate terminal devices corresponding to all tree branches to obtain a second set.

[0090] Specifically, all candidate terminal devices of the first category are aggregated, and duplicate terminal devices are removed to obtain a first set. All candidate terminal devices of the second category are aggregated, and duplicate terminal devices are removed to obtain a second set.

[0091] Referring to Table 3, it can be seen that after aggregation, the first set includes terminal devices 2, 4, and 8 with a baseline NAT type of symmetry; the second set includes terminal devices 1, 3, 5, and 9 with a baseline NAT type of cone.

[0092] Step S503: Determine the key terminal devices based on the first set and the second set.

[0093] In practice, the key terminal devices corresponding to the first set can be determined based on the upstream and downstream relationships of the terminal devices in the first set. Similarly, the key terminal devices corresponding to the second set can be determined based on the upstream and downstream relationships in the second set.

[0094] Specifically, in one implementation, terminal devices in the first set and the second set can be identified as key terminal devices.

[0095] The method provided in this embodiment finds the candidate terminal devices corresponding to each tree branch by bidirectionally traversing the tree branches, and uses the candidate terminal devices as key terminal devices to perform subsequent NAT type detection tasks. This avoids all terminal devices performing detection tasks individually and periodically, reduces redundant detection, and thus reduces the overall overhead of NAT type detection for terminal devices.

[0096] Optionally, Figure 6 A flowchart of embodiment four of the method for determining the NAT type of a terminal device provided in this application. For another implementation, please refer to... Figure 6 The determination of key terminal devices based on the first set and the second set may include:

[0097] Step S601: For each candidate terminal device in the first set and the second set, determine the number of tree branches associated with that candidate terminal device.

[0098] Specifically, in this step, the number of tree branches associated with each candidate terminal device in the first set and the second set is counted.

[0099] Step S602: When the above quantity equals 1, the candidate terminal device is determined as the key terminal device.

[0100] Step S603: When the number is greater than 1, determine whether there is a target terminal device in the tree branch associated with the candidate terminal device. If yes, determine the target terminal device as a key terminal device. If no, determine the candidate terminal device as a key terminal device. The target terminal device is a terminal device that can perform the detection task in place of the candidate terminal device.

[0101] Specifically, when the number of tree branches associated with the candidate terminal device is greater than 1, for each tree branch associated with the candidate terminal device, it is determined whether the target terminal device exists in the tree branch associated with the candidate terminal device. If the target terminal device exists, the target terminal device is identified as the key terminal device in the tree branch; if the target terminal device does not exist, the candidate terminal device is identified as the key terminal device in the tree branch.

[0102] Furthermore, in one possible implementation, determining whether the target terminal device exists in the tree branch associated with the candidate terminal device includes the following steps:

[0103] (1) Determine whether the first terminal device exists in the tree branch associated with the candidate terminal device; wherein the distance between the first terminal device and the boundary node corresponding to the candidate terminal device is less than the distance between the candidate terminal device and the boundary node, or the number of tree branches associated with the first terminal device is higher than the number of tree branches associated with the candidate terminal device.

[0104] Specifically, when the candidate terminal device is a first type of candidate terminal device, the aforementioned boundary node is the root node of the tree branch associated with the candidate terminal device; when the candidate terminal device is a second type of candidate terminal device, the aforementioned boundary node is the leaf node of the tree branch associated with the candidate terminal device.

[0105] It is important to understand that the first terminal device and the alternative terminal devices have the same NAT type. Only when the first terminal device exists can it be identified as the target terminal device, and then the target terminal device can be identified as the critical terminal device.

[0106] Specifically, when the candidate terminal device is a first-type candidate terminal device, the distance between the first terminal device and the root node corresponding to the candidate terminal device is less than the distance between the candidate terminal device and the root node. That is, on the tree branch associated with the candidate terminal device, there is a terminal device with a baseline NAT type of symmetric upstream of the candidate terminal device. In this case, the symmetric terminal device located upstream of the candidate terminal device is determined as the first terminal device. Optionally, when there are multiple symmetric terminal devices located upstream of the candidate terminal device, the most upstream symmetric terminal device can be determined as the first terminal device.

[0107] Similarly, when the candidate terminal device is a second type of candidate terminal device, the distance from the first terminal device to the leaf node corresponding to the candidate terminal device is less than the distance from the candidate terminal device to the leaf node. That is, on the tree branch associated with the candidate terminal device, there is a terminal device with a base NAT type of cone downstream of the candidate terminal device. In this case, the cone-shaped terminal device located downstream of the candidate terminal device is determined as the first terminal device. Optionally, when there are multiple cone-shaped terminal devices located downstream of the candidate terminal device, the most downstream cone-shaped terminal device can be determined as the first terminal device.

[0108] (2) If so, the first terminal device is identified as the target terminal device.

[0109] Referring to the preceding description, in this case, the terminal device closer to the boundary node and with the same NAT type as the candidate terminal device is identified as the first terminal device. This positions it closer to the root node or leaf node in the tree branch, allowing its NAT type detection results to cover more associated terminal devices downstream or upstream. This expands the NAT type sharing range of a single key terminal device and reduces the number of terminal devices that need to perform periodic detection. Alternatively, the terminal device with more tree branches and the same NAT type as the candidate terminal device is identified as the first terminal device. This allows its NAT type detection results to be shared across more tree branches, improving the reuse rate of detection results for a single key terminal device. This allows fewer key terminal devices to cover more terminal devices in more tree branches, further reducing redundant detection and lowering the overall system overhead of NAT type detection.

[0110] (3) If not, determine whether there is a second terminal device in the tree branch associated with the candidate terminal device; wherein the number of tree branches associated with the second terminal device is the same as the number of tree branches associated with the candidate terminal device, and the resource abundance of the second terminal device is higher than the resource abundance of the candidate terminal device.

[0111] Resource abundance is used to characterize the resource status of terminal devices, including but not limited to CPU utilization, memory idle rate, power status, and current network load.

[0112] Specifically, when there is no first terminal device, that is, when the candidate terminal device is a first-type candidate terminal device, there is no symmetrical terminal device upstream in its associated tree branch; when the candidate terminal device is a second-type candidate terminal device, there is no conical terminal device downstream in its associated tree branch. In this case, it is necessary to determine whether a second terminal device exists among the terminal devices at the same level as the candidate terminal device. In other words, it is necessary to compare the resource abundance of the terminal devices at the same level with that of the candidate terminal device. If the resource abundance of the terminal devices at the same level is higher than that of the candidate terminal device, then the terminal device at the same level is identified as the second terminal device; otherwise, it is determined that no second terminal device exists.

[0113] Understandably, by identifying terminal devices with higher resource abundance as secondary terminal devices, and then designating them as target / critical terminal devices, the system prioritizes terminal devices with lower CPU utilization, higher memory idle rate, more stable power status, and lighter current network load to perform periodic NAT type detection tasks, provided that the number of association tree branches is the same, i.e., the detection result coverage is the same. This ensures that the NAT type shared coverage is not reduced, while avoiding the impact on their own services or detection interruption caused by terminal devices with limited resources undertaking detection tasks. This achieves detection load balancing among critical terminal devices, improves the stability and continuity of NAT type detection, and further reduces the overall system overhead of NAT type detection.

[0114] (4) When there is a second terminal device in the tree branch associated with the candidate terminal device, the second terminal device is determined as the target terminal device.

[0115] (5) If there is no second terminal device in the tree branch associated with the candidate terminal device, it is determined that there is no target terminal device.

[0116] Continuing with the example above, through step S601, we know that the first set includes the following candidate terminal devices: terminal device 2, terminal device 4, and terminal device 8. Terminal devices 2 and 4 are associated with 2 tree branches each; terminal device 8 is associated with 1 tree branch. Similarly, the second set includes the following candidate terminal devices: terminal device 1, terminal device 3, terminal device 5, and terminal device 9; terminal device 1 is associated with 4 tree branches each; terminal device 3 is associated with 2 tree branches each; terminal device 5 is associated with 2 tree branches each; and terminal device 9 is associated with 1 tree branch.

[0117] As can be seen from step S602, terminal device 8 is a key terminal device; terminal device 9 is a key terminal device.

[0118] Through step S603, it can be seen that terminal device 9 is a key terminal device; further, assuming that the resource abundance of terminal device 2 is greater than that of its peer terminal device 4, then terminal device 2 is also a key terminal device.

[0119] In summary, the key terminal devices of the communication system can be identified as terminal device 2, terminal device 8, and terminal device 9.

[0120] Furthermore, based on the network topology, we know that terminal device 2 is associated with the following terminal devices: terminal device 4, terminal device 6, and terminal device 7; terminal device 8 has no associated terminal devices; and terminal device 9 is associated with the following terminal devices: terminal device 1, terminal device 3, and terminal device 5.

[0121] The method for determining the NAT type of a terminal device provided in this embodiment further locates key terminal devices through cross-tree branching, which can deepen the analysis of the logical relationships between various terminal devices. Under the premise of ensuring that all terminal devices in the communication system are covered, it determines the minimum set of key terminal devices, further reducing redundant detection and lowering the overall overhead required to determine the NAT type of a terminal device.

[0122] In some embodiments, based on the above embodiments, the method further includes:

[0123] For each critical terminal device, continuously detect the real-time NAT type of that critical terminal device; when a change in the real-time NAT type of any critical terminal device is detected, repeat the step of obtaining the baseline NAT type of each terminal device.

[0124] Specifically, for each critical terminal device, the server continuously monitors its real-time NAT type. When a change in the real-time NAT type of any critical terminal device is detected—for example, if a critical terminal device changes its NAT type due to changes in the network environment or NAT device configuration—it is necessary to re-determine the critical terminal device among the terminal devices. Understandably, the network topology of the server and each terminal device has not changed at this time. Therefore, it is only necessary to start from the step of "obtaining the baseline NAT type of each terminal device" and repeat the above method for determining the NAT type of the terminal device to update the critical terminal devices and associated terminal devices, ensuring that the sharing policy is always consistent with the current network state.

[0125] The method for determining the NAT type of a terminal device provided in this embodiment improves the real-time performance and accuracy of NAT type determination by continuously monitoring changes in the NAT type of actual critical terminal devices and automatically triggering updates when changes occur.

[0126] Optionally, in one possible implementation, in some embodiments, based on the above embodiments, the method further includes:

[0127] When a device addition event is detected, the new routing path information and base NAT type of the new terminal device corresponding to the device addition event are obtained. The network topology is updated according to the new routing path information. Then, the steps of identifying key terminal devices and associated terminal devices from all terminal devices according to the network topology and the base NAT type of each terminal device are executed again.

[0128] And / or,

[0129] When a device change event is detected, the network topology is updated according to the device change event, and the steps of identifying key terminal devices and associated terminal devices from all terminal devices based on the network topology and the baseline NAT type of each terminal device are executed again.

[0130] Among these, a "device addition" event refers to a new terminal device joining the current communication system. In practical applications, the newly added terminal device sends registration or routing path information to the server, which is then detected by the server. A "device change" event refers to a terminal device in the current communication system going offline, exiting, or having its routing path changed. In practical applications, each terminal device connected to the server can maintain its connection with the server through heartbeat messages, etc. Therefore, in the current communication system, the server can detect the offline, exiting, or routing path change of any terminal device.

[0131] Specifically, when the server detects that a new terminal device has been added to the current communication system, in one implementation, the server obtains the new routing path information and the base NAT type of the new terminal device, updates the network topology based on the new routing path information, and starts from the step of "identifying key terminal devices and associated terminal devices from all terminal devices based on the network topology and the base NAT type of each terminal device" again, and executes the above method for determining the NAT type of the terminal device to update the key terminal devices and associated terminal devices.

[0132] Optionally, in another implementation, after obtaining the base NAT type of the newly added terminal device and updating the network topology based on the obtained new routing path information, the server can first determine whether the base NAT type of the newly added terminal device is symmetrical or conical, and then determine the position of the newly added terminal device in the updated network topology, thereby identifying the new critical terminal device. Specifically: if the base NAT type of the newly added terminal device is symmetrical, and the distance of the newly added terminal device from the root node of the tree branch it is associated with is closer than the distance of the current first-type critical terminal device from the root node, then the newly added terminal device is identified as a first-type critical terminal device, and the original first-type critical terminal device to be replaced is identified as the associated terminal device of the newly added terminal device; if the base NAT type of the newly added terminal device is conical, and the distance of the newly added terminal device from the leaf node of the tree branch it is associated with is closer than the distance of the current second-type critical terminal device from the leaf node, then the newly added terminal device is identified as a second-type critical terminal device, and the original second-type critical terminal device to be replaced is identified as the associated terminal device of the newly added terminal device; otherwise, the status quo is maintained. Compared to re-executing the entire identification process, this method can adapt to new device access scenarios more quickly.

[0133] Similarly, when the server detects a device change event in the current network structure, in one implementation, the server updates the network topology based on the device change event, and starts from the step of "identifying key terminal devices and associated terminal devices from all terminal devices based on the network topology and the baseline NAT type of each terminal device", and executes the above method for determining the NAT type of terminal devices again to update the key terminal devices and associated terminal devices.

[0134] Optionally, in another implementation, when the server detects a device change event, the server determines whether the changed terminal device is a critical terminal device. If the changed terminal device is not a critical terminal device, the change event is ignored. If the changed terminal device is a critical terminal device, the server starts from the step of "identifying the critical terminal device and the associated terminal devices from all terminal devices according to the network topology and the baseline NAT type of each terminal device" and executes the above-mentioned method for determining the NAT type of the terminal device again to update the critical terminal device and the associated terminal devices.

[0135] The method for determining the NAT type of a terminal device provided in this embodiment, through dynamic network adaptation processing, can automatically adjust the detection strategy when a new terminal device is added, a terminal device goes offline, exits, or the routing path changes, thus avoiding problems such as incomplete detection coverage or outdated results.

[0136] Figure 7A flowchart of embodiment five of the method for determining the NAT type of a terminal device provided in this application. See also... Figure 7 The method for determining the NAT type of a terminal device includes:

[0137] Step S701: Obtain the routing path information of each terminal device managed by the server, and construct the network topology based on the routing path information of all terminal devices.

[0138] Step S702: Obtain the baseline NAT type for each terminal device.

[0139] Step S703: For each tree branch in the network topology, search for candidate terminal devices on that tree branch to obtain the candidate terminal devices corresponding to that tree branch. The candidate terminal devices include first-type candidate terminal devices and second-type candidate terminal devices.

[0140] Step S704: Aggregate the first type of candidate terminal devices corresponding to all tree branches to obtain a first set, and aggregate the second type of candidate terminal devices corresponding to all tree branches to obtain a second set.

[0141] Step S705: Determine the key terminal devices based on the first set and the second set.

[0142] Step S706: For each critical terminal device, based on the baseline NAT type and network topology of the critical terminal device, identify the associated terminal devices of the critical terminal device from other terminal devices besides all critical terminal devices.

[0143] Step S707: For each critical terminal device, periodically probe the NAT type of the critical terminal device, obtain the probe result of the critical terminal device, and determine the real-time NAT type of the critical terminal device and its associated terminal devices in the current probe period based on the probe result of the critical terminal device.

[0144] Specifically, the implementation principles and processes of steps S701 to S707 can be found in the descriptions in the previous embodiments, and will not be repeated here.

[0145] The method for determining the NAT type of a terminal device provided in this embodiment obtains the routing path information of each terminal device managed by the server, constructs a network topology based on the routing path information of all terminal devices, obtains the baseline NAT type of each terminal device, searches for candidate terminal devices on each tree branch in the network topology, obtains the first type of candidate terminal devices and the second type of candidate terminal devices corresponding to the tree branch, aggregates the first type of candidate terminal devices corresponding to all tree branches to obtain a first set, and aggregates the second type of candidate terminal devices corresponding to all tree branches to obtain a second set, determines the key terminal devices based on the first set and the second set, and then uses each The baseline NAT type and network topology of key terminal devices are used to identify associated terminal devices. Then, for each key terminal device, the NAT type of that key terminal device is periodically probed to obtain the probe results. Based on the probe results of that key terminal device, the real-time NAT type of that key terminal device and its associated terminal devices in the current probe period is determined. In this way, only a small number of key terminal devices are identified, and the real-time NAT type of all terminal devices in the entire communication system can be determined by periodically initiating probes from a small number of key terminal devices. This reduces the overall overhead of NAT type probe in large-scale, cross-segment network environments.

[0146] Corresponding to the aforementioned embodiment of a method for determining the NAT type of a terminal device, this application also provides an embodiment of an apparatus for determining the NAT type of a terminal device.

[0147] Figure 8 A schematic diagram of the apparatus for determining the NAT type of a terminal device provided in this application. Please refer to... Figure 8 The apparatus provided in this embodiment is applied to a server, and the apparatus includes:

[0148] Module 10 is used to obtain the routing path information of each terminal device managed by the server, and to construct the network topology based on the routing path information of all terminal devices.

[0149] The identification module 20 is used to obtain the baseline NAT type of each terminal device, and to identify key terminal devices and associated terminal devices from all terminal devices based on the network topology and the baseline NAT type of each terminal device.

[0150] The determination module 30 is used to periodically detect the NAT type of each key terminal device, obtain the detection results of the key terminal device, and determine the real-time NAT type of the key terminal device and its associated terminal devices in the current detection period based on the detection results of the key terminal device.

[0151] This application also provides a server, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to perform any of the methods described above for determining the NAT type of a terminal device.

[0152] The specific implementation process of the functions and roles of each unit in the above device can be found in the implementation process of the corresponding steps in the above method, and will not be repeated here.

[0153] For the device embodiments, since they basically correspond to the method embodiments, the relevant parts can be referred to in the description of the method embodiments. The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this application according to actual needs. Those skilled in the art can understand and implement this without creative effort.

[0154] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of protection of this application.

Claims

1. A method for determining the NAT type of a terminal device, characterized in that, The method is applied to a server, and the method includes: Obtain the routing path information of each terminal device managed by the server, and construct the network topology based on the routing path information of all terminal devices; Obtain the baseline NAT type of each terminal device, and based on the network topology and the baseline NAT type of each terminal device, identify the key terminal devices and the associated terminal devices associated with the key terminal devices from all terminal devices; For each critical terminal device, the NAT type of the critical terminal device is periodically probed to obtain the probe results of the critical terminal device. Based on the probe results of the critical terminal device, the real-time NAT type of the critical terminal device and its associated terminal devices in the current probe period is determined.

2. The method according to claim 1, characterized in that, The network topology is constructed based on the routing path information of all terminal devices, including: For each terminal device, a tree branch is constructed using the address of the bottom routing node in the routing path information of the terminal device as the leaf node and the address of the top routing node in the routing path information as the root node, and the terminal device is associated with the leaf node of the tree branch. All tree branches are aggregated to obtain the network topology.

3. The method according to claim 1 or 2, characterized in that, The step of identifying key terminal devices and associated terminal devices from all terminal devices based on the network topology and the baseline NAT type of each terminal device includes: Based on the network topology and the baseline NAT type of each terminal device, identify key terminal devices from all terminal devices; For each critical terminal device, based on the baseline NAT type of the critical terminal device and the network topology, the associated terminal devices of the critical terminal device are identified from other terminal devices besides all critical terminal devices.

4. The method according to claim 3, characterized in that, The step of identifying key terminal devices from all terminal devices based on the network topology and the baseline NAT type of each terminal device includes: For each tree branch in the network topology, candidate terminal devices are searched from that tree branch to obtain the candidate terminal devices corresponding to that tree branch; wherein, the candidate terminal devices include a first type of candidate terminal devices and a second type of candidate terminal devices; the first type of candidate terminal devices are the terminal devices closest to the root node of the tree branch and whose base NAT type is symmetric; the second type of candidate terminal devices are the terminal devices closest to the leaf nodes of the tree branch and whose base NAT type is cone; Aggregate the first type of candidate terminal devices corresponding to all tree branches to obtain a first set, and aggregate the second type of candidate terminal devices corresponding to all tree branches to obtain a second set; The key terminal devices are determined based on the first set and the second set.

5. The method according to claim 4, characterized in that, The step of determining the key terminal device based on the first set and the second set includes: For each candidate terminal device in the first set and the second set, determine the number of tree branches associated with that candidate terminal device; When the number equals 1, the candidate terminal device is determined as the key terminal device. When the number is greater than 1, it is determined whether the tree branch associated with the candidate terminal device contains a target terminal device. If it does, the target terminal device is identified as a key terminal device; otherwise, the candidate terminal device is identified as a key terminal device. The target terminal device is a terminal device that can replace the candidate terminal device to perform the detection task.

6. The method according to claim 5, characterized in that, Determining whether the target terminal device exists in the tree branch associated with the candidate terminal device includes: Determine whether the tree branch associated with the candidate terminal device contains the first terminal device; wherein, the distance between the first terminal device and the boundary node corresponding to the candidate terminal device is less than the distance between the candidate terminal device and the boundary node, or, the number of tree branches associated with the first terminal device is greater than the number of tree branches associated with the candidate terminal device. If so, the first terminal device is identified as the target terminal device; If not, determine whether there is a second terminal device in the tree branch associated with the candidate terminal device; wherein the number of tree branches associated with the second terminal device is the same as the number of tree branches associated with the candidate terminal device, and the resource abundance of the second terminal device is higher than that of the candidate terminal device. If a second terminal device exists in the tree branch associated with the candidate terminal device, the second terminal device is determined as the target terminal device; if a second terminal device does not exist in the tree branch associated with the candidate terminal device, it is determined that no target terminal device exists.

7. The method according to claim 1, characterized in that, The method further includes: For each critical terminal device, continuously detect the real-time NAT type of that critical terminal device; When a change in the real-time NAT type of any critical terminal device is detected, the step of obtaining the baseline NAT type of each terminal device is executed again.

8. The method according to claim 1, characterized in that, The method further includes: When a device addition event is detected, the new routing path information and base NAT type of the new terminal device corresponding to the device addition event are obtained. The network topology is updated according to the new routing path information. Then, the steps of identifying key terminal devices and associated terminal devices from all terminal devices according to the network topology and the base NAT type of each terminal device are executed again. And / or, When a device change event is detected, the network topology is updated according to the device change event, and the steps of identifying key terminal devices and associated terminal devices from all terminal devices based on the network topology and the baseline NAT type of each terminal device are executed again.

9. An apparatus for determining the NAT type of a terminal device, characterized in that, The device is used in a server, and the device includes: The construction module is used to obtain the routing path information of each terminal device managed by the server, and to construct the network topology based on the routing path information of all terminal devices. The identification module is used to obtain the baseline NAT type of each terminal device, and based on the network topology and the baseline NAT type of each terminal device, identify key terminal devices and associated terminal devices from all terminal devices. The determination module is used to periodically probe the NAT type of each key terminal device, obtain the probe results of the key terminal device, and determine the real-time NAT type of the key terminal device and its associated terminal devices in the current probe period based on the probe results of the key terminal device.

10. A server, comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the method for determining the NAT type of a terminal device as claimed in any one of claims 1 to 8.