Method, device, equipment and medium for establishing TCP (Transmission Control Protocol) connection through user-defined DNS (Domain Name Server) analysis

Through custom DNS resolution of concurrent TCP handshake, the problem of slow TCP connection speed during domain name access is solved, and the rapid establishment of TCP connections is achieved and the success rate is improved, which improves network connection efficiency.

CN120583141APending Publication Date: 2025-09-02ZIXUN TECHNOLOGY (FUJIAN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510897564.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-01
Publication Date
2025-09-02

AI Technical Summary

Technical Problem

During the existing domain name access process, TCP connection speed is slow and the probability of success is low, especially when the public network DNS resolution encounters a timeout, it is necessary to try the connection multiple times.

Method used

Through custom DNS resolution methods, pre-stored IPs are obtained and combined into a handshake IP library. The concurrency mechanism is used to perform TCP handshake at the same time, quickly select the fastest successful IP as the subsequent operation address, and quickly switch to other IPs when the TLS handshake fails to try again.

Benefits of technology

This has achieved a significant improvement in TCP connection speed and an improvement in success rate, reducing connection time and improving the overall efficiency of network connections.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120583141A_ABST
    Figure CN120583141A_ABST
Patent Text Reader

Abstract

The invention provides a method, a device, equipment and a medium for establishing TCP (Transmission Control Protocol) connection through user-defined DNS (Domain Name Server) analysis, and the method comprises the following steps: obtaining a domain name accessed by a user, and obtaining two public network IPs (Internet Protocol) through public network DNS analysis; extracting a pre-stored IP corresponding to the domain name from a user-defined DNS library according to the domain name; the method comprises the following steps: combining a public network IP and a pre-stored IP into a handshake IP library, carrying out TCP handshake on each IP in the handshake IP library at the same time, taking a corresponding first IP as a subsequent operation address after the handshake is successfully returned as soon as possible, and closing TCP handshake of other IPs; the TCP connection can be quickly completed, and the success probability of the TCP connection can be greatly increased.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of network connection technology, and in particular to a method, device, equipment and medium for establishing a TCP connection through custom DNS resolution. Background Art

[0002] The existing domain name access process requires a TCP handshake, which is used to establish a reliable transport layer connection. The TCP handshake is the process used in the TCP protocol to establish a connection, ensuring that both parties can send and receive data correctly. It is completed in three stages:

[0003] 1.SYN (Synchronize Sequence Number): The client sends a SYN packet to request to establish a connection.

[0004] 2SYN-ACK (Synchronize + Acknowledge): The server responds to the client's SYN packet and sends a SYN-ACK packet to indicate that it agrees to establish a connection and confirms the client's sequence number.

[0005] 3. ACK (confirmation): The client sends an ACK packet again to confirm the server's SYN-ACK packet, and the connection establishment is complete.

[0006] For example, in existing domain name access, for example, public DNS resolution of the domain name www.baidu.com yields two IP addresses. If the total timeout is 6 seconds, a TCP handshake is performed through the first IP address. If the handshake fails within 3 seconds, a TCP handshake is performed through the second IP address, which still has a 3-second timeout. If the handshake fails, it will take a total of 6 seconds to provide feedback to the client. If the handshake succeeds, it will also take 3 seconds to establish a connection. Therefore, this TCP connection method is slow. Summary of the Invention

[0007] The technical problem to be solved by the present invention is to provide a method, device, equipment and medium for establishing a TCP connection through custom DNS resolution, which greatly improves the speed of establishing a TCP connection and increases the probability of a successful connection.

[0008] In a first aspect, the present invention provides a method for establishing a TCP connection by customizing DNS resolution, comprising the following steps:

[0009] Step 1: Obtain the domain name accessed by the user and resolve it through the public DNS to obtain two public IP addresses;

[0010] Step 2: Get the pre-stored IP address corresponding to the domain name from the custom DNS database.

[0011] Step 3: Combine the public IP and pre-stored IP into a handshake IP library, and perform TCP handshake on each IP in the handshake IP library at the same time. After the fastest return of handshake success, use the corresponding first IP as the subsequent operation address and close the TCP handshake of other IPs.

[0012] In a second aspect, the present invention provides a device for establishing a TCP connection by customizing DNS resolution, comprising:

[0013] The public network DNS resolution module obtains the domain name accessed by the user and obtains two public network IP addresses through public network DNS resolution;

[0014] The custom IP module retrieves the pre-stored IP corresponding to the domain name from the custom DNS library according to the domain name;

[0015] The synchronous handshake module combines public IP and pre-stored IP into a handshake IP library, and performs TCP handshake on each IP in the handshake IP library at the same time. After the fastest return of handshake success, the corresponding first IP is used as the subsequent operation address, and the TCP handshake of other IPs is closed.

[0016] In a third aspect, the present invention provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the method described in the first aspect when executing the program.

[0017] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, which implements the method described in the first aspect when the program is executed by a processor.

[0018] One or more technical solutions provided by the present invention have at least the following technical effects or advantages:

[0019] The present invention realizes simultaneous batch TCP handshakes, can quickly establish TCP connections, improves the overall speed, and no longer needs to try to connect one by one, and then proceed to the next one after a timeout, which greatly improves the connection efficiency; and in the case that the TCP handshake succeeds but the TLS handshake fails, the failed IP can be quickly excluded, the TCP handshake can be re-established, and then the TLS handshake can be performed, which greatly increases the efficiency of the network connection.

[0020] The above description is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present invention more obvious and easy to understand, the specific implementation methods of the present invention are specifically listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0022] Figure 1 This is a flowchart of the method in Example 1 of the present invention;

[0023] Figure 2 This is a schematic diagram of the structure of the device in Example 2 of the present invention. DETAILED DESCRIPTION

[0024] The technical solutions in the embodiments of this application have the following general ideas:

[0025] 1. DNS resolution of the domain name www.baidu.com yields two public IP addresses

[0026] 2. Customize the DNS database to retrieve the IP address stored in the domain name www.baidu.com

[0027] 3. Customize the DNS and public IP addresses and set a single timeout, for example, 1 second. TCP handshakes are performed in batches within 1 second. When the fastest IP returns a successful handshake, the server stops waiting and closes all other connections.

[0028] One implementation method is to establish a Racer, which is a competitive executor implemented in the Go language. Its core function is to prioritize the execution of the main task and automatically execute the backup task after failure or timeout. Specifically:

[0029] 1. Competitive execution mode

[0030] / / Create a Racer, main task + multiple backup tasks

[0031] racer:=New(ctx,primaryTask,fallbackTask1,fallbackTask2)

[0032] 2. Execution Strategy

[0033] Prioritize the primary task

[0034] Automatically start all fallback tasks if the primary task fails or times out

[0035] The first completed task returns the result, and other tasks continue to run in the background

[0036] Key Features

[0037] 1. Timeout control

[0038] racer.WithTimeWait(5*time.Second) / / Main task timeout of 5 seconds

[0039] 2. Concurrency Control

[0040] racer.WithMaxGoroutines(10) / / Up to 10 goroutines

[0041] 3. Result processing

[0042] racer.WithOnClose(func(resultT){

[0043] / / Process the results of each completed task

[0044] })

[0045] 4. Close

[0046] racer.Close() / / Asynchronous close racer.CloseWait() / / Synchronous wait for all tasks to complete Usage scenario

[0047] 1. Multi-source data acquisition

[0048]

[0049] 2. Service degradation

[0050]

[0051] 3. Network request retry

[0052]

[0053] Key implementation details

[0054] 1. State Management

[0055]

[0056]

[0057] 2. Task Scheduling

[0058] Use pool.ContextPool to manage goroutines

[0059] Support graceful shutdown and resource cleanup through taskCh and retCh for task distribution and result collection

[0060] 3. Race Condition Handling

[0061]

[0062] Usage Examples

[0063]

[0064]

[0065] Racer is a very practical concurrent mode implementation, especially suitable for scenarios that require high availability and low latency, such as service calls and data acquisition in microservice architectures.

[0066] Example 1

[0067] like Figure 1 As shown, this embodiment provides a method for establishing a TCP connection by customizing DNS resolution, including the following steps:

[0068] Step 1: Obtain the domain name accessed by the user and resolve it through the public DNS to obtain two public IP addresses;

[0069] Step 2: Get the pre-stored IP address corresponding to the domain name from the custom DNS database.

[0070] Step 3: Combine the public IP and pre-stored IP into a handshake IP library, and perform TCP handshake on each IP in the handshake IP library at the same time. After the fastest return of handshake success, use the corresponding first IP as the subsequent operation address and close the TCP handshake of other IPs.

[0071] In this embodiment, preferably, step 4 is also included. After completing the TCP handshake, a TLS handshake is performed according to the first IP. If the TLS handshake is successful, a network connection is established; if the TLS handshake fails, the first IP is removed from the handshake IP library to obtain a removed IP library. After the handshake is successfully returned as soon as possible, the corresponding second IP is used as the subsequent operation address, the TCP handshakes of other IPs are closed, and a TLS handshake is performed through the second IP.

[0072] In this embodiment, preferably, the step 2 specifically includes: establishing a custom DNS library, storing the domain name and the corresponding IP value in the custom DNS library, and taking out the pre-stored IP corresponding to the domain name from the custom DNS library according to the domain name.

[0073] In this embodiment, preferably, step 3 is specifically as follows: a handshake IP library is formed by combining the public IP and the pre-stored IP, and a TCP handshake is performed on each IP in the handshake IP library at the same time. After the fastest return of the handshake success, the corresponding first IP is used as the subsequent operation address, and the TCP handshakes of other IPs are closed; if the handshake is not successful within the set timeout period, the connection failure is returned to the user.

[0074] Based on the same inventive concept, this application also provides a device corresponding to the method in Example 1, see Example 2 for details.

[0075] Example 2

[0076] like Figure 2As shown, in this embodiment, a device for establishing a TCP connection by customizing DNS resolution is provided, including:

[0077] The public network DNS resolution module obtains the domain name accessed by the user and obtains two public network IP addresses through public network DNS resolution;

[0078] The custom IP module retrieves the pre-stored IP corresponding to the domain name from the custom DNS library according to the domain name;

[0079] The synchronous handshake module combines public IP and pre-stored IP into a handshake IP library, and performs TCP handshake on each IP in the handshake IP library at the same time. After the fastest return of handshake success, the corresponding first IP is used as the subsequent operation address, and the TCP handshake of other IPs is closed.

[0080] In this embodiment, preferably, it also includes a TLS handshake module. After completing the TCP handshake, a TLS handshake is performed according to the first IP. If the TLS handshake is successful, a network connection is established; if the TLS handshake fails, the first IP is removed from the handshake IP library to obtain a removed IP library. After the handshake success is returned as soon as possible, the corresponding second IP is used as the subsequent operation address, the TCP handshakes of other IPs are closed, and a TLS handshake is performed through the second IP.

[0081] In this embodiment, preferably, the custom IP module specifically establishes a custom DNS library, stores the domain name and the corresponding IP value in the custom DNS library, and retrieves the pre-stored IP corresponding to the domain name from the custom DNS library according to the domain name.

[0082] In this embodiment, preferably, the synchronous handshake module is specifically as follows: a handshake IP library is formed by combining public network IP and pre-stored IP, and a TCP handshake is performed on each IP in the handshake IP library at the same time. After the fastest return of handshake success, the corresponding first IP is used as the subsequent operation address, and the TCP handshakes of other IPs are closed; if no handshake is successful within the set timeout period, the connection failure is returned to the user.

[0083] Since the device described in the second embodiment of the present invention is used to implement the method of the first embodiment of the present invention, those skilled in the art will be able to understand the specific structure and variations of the device based on the method described in the first embodiment of the present invention, and therefore will not be described in detail here. All devices used in the method of the first embodiment of the present invention fall within the scope of protection of the present invention.

[0084] Based on the same inventive concept, this application provides an electronic device embodiment corresponding to the first embodiment, see the third embodiment for details.

[0085] Example 3

[0086] This embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, any implementation method in the first embodiment can be implemented.

[0087] Since the electronic device described in this embodiment is the device used to implement the method in Example 1 of this application, based on the method described in Example 1 of this application, those skilled in the art will be able to understand the specific implementation of the electronic device of this embodiment and its various variations. Therefore, how the electronic device implements the method in the embodiment of this application will not be described in detail here. As long as the device used by those skilled in the art to implement the method in the embodiment of this application falls within the scope of protection to be provided by this application.

[0088] Based on the same inventive concept, this application provides a storage medium corresponding to Example 1, see Example 4 for details.

[0089] Example 4

[0090] This embodiment provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, any implementation method in the first embodiment can be implemented.

[0091] The technical solutions provided in the embodiments of this application have at least the following technical effects or advantages:

[0092] The present invention implements batch TCP handshakes simultaneously, allowing for rapid TCP connection establishment and improved overall speed. This eliminates the need for previously attempted connections, requiring only one connection at a timeout before proceeding to the next, significantly improving connection efficiency. Furthermore, if the TCP handshake succeeds but the TLS handshake fails, the failed IP address can be quickly removed, the TCP handshake re-established, and then the TLS handshake performed, significantly increasing network connection efficiency.

[0093] 1. Bulk TCP handshake

[0094] Traditional network connection methods typically use a one-by-one connection attempt. For example, when connecting to multiple destinations, the system attempts each address in turn. If a connection to one address fails (e.g., due to a timeout), the system waits until the timeout expires before trying the next address. This method is inefficient, especially when dealing with multiple destinations, significantly increasing overall connection time.

[0095] The present invention solves this problem by enabling simultaneous batch TCP handshakes. Specifically, the present invention utilizes a concurrent mechanism to simultaneously initiate TCP connection requests to multiple target addresses. This allows multiple connection attempts to proceed in parallel, significantly reducing the overall connection time. For example, if there are 10 target addresses, a traditional method might require trying each address in turn, requiring a total of 10 times the time of a single connection attempt. However, the present invention can attempt all 10 addresses simultaneously, resulting in a total connection time close to that of a single connection attempt, significantly improving efficiency.

[0096] 2. Quickly exclude failed IPs

[0097] In real-world network communications, after a successful TCP handshake, a TLS handshake may be required to establish a secure connection. However, the TLS handshake may fail for various reasons, such as certificate verification failure or protocol mismatch. In such cases, the traditional approach is to wait until the current connection attempt fails completely before trying the next address. This approach not only wastes time but may also result in connection failure.

[0098] The present invention immediately initiates a TLS handshake after a successful TCP handshake. If the TLS handshake fails, the system quickly identifies and eliminates the failed IP address, then reselects another available IP address for the TCP handshake and attempts the TLS handshake again. This process is automated, and thanks to the use of a batch TCP handshake mechanism, a new target can be quickly selected from multiple candidate addresses, significantly improving the success rate and efficiency of connections.

[0099] It will be understood by those skilled in the art that embodiments of the present invention may be provided as methods, systems, or computer program products. Thus, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware. Furthermore, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0100] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowcharts and / or block diagrams. Figure 1 a process or multiple processes and / or boxes Figure 1A device that provides the functions specified in a block or multiple blocks.

[0101] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work in a specific manner, so that the instructions stored in the computer readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.

[0102] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.

[0103] Although the specific embodiments of the present invention are described above, those skilled in the art should understand that the specific embodiments described are merely illustrative and are not intended to limit the scope of the present invention. Equivalent modifications and changes made by those skilled in the art in accordance with the spirit of the present invention should be included within the scope of protection of the claims of the present invention.

Claims

1. A method for establishing a TCP connection by customizing DNS resolution, characterized by: The steps include: Step 1: Obtain the domain name accessed by the user and resolve it through the public DNS to obtain two public IP addresses; Step 2: Get the pre-stored IP address corresponding to the domain name from the custom DNS database. Step 3: Combine the public IP and pre-stored IP into a handshake IP library, and perform TCP handshake on each IP in the handshake IP library at the same time. After the fastest return of handshake success, use the corresponding first IP as the subsequent operation address and close the TCP handshake of other IPs.

2. The method for establishing a TCP connection by using a custom DNS resolution according to claim 1, wherein: The method also includes step 4: after completing the TCP handshake, performing a TLS handshake according to the first IP address, and establishing a network connection if the TLS handshake succeeds; If the TLS handshake fails, the first IP is removed from the handshake IP library to obtain a removed IP library. After the fastest return of handshake success, the corresponding second IP is used as the subsequent operation address, the TCP handshake of other IPs is closed, and the TLS handshake is performed through the second IP.

3. The method for establishing a TCP connection by using a custom DNS resolution according to claim 1, wherein: The step 2 is specifically as follows: establishing a custom DNS library, storing the domain name and the corresponding IP value in the custom DNS library, and taking out the pre-stored IP corresponding to the domain name from the custom DNS library according to the domain name.

4. The method for establishing a TCP connection by using a custom DNS resolution according to claim 1, wherein: The step 3 is specifically as follows: a handshake IP library is formed by combining public network IPs and pre-stored IPs, a TCP handshake is performed on each IP in the handshake IP library at the same time, and after the fastest handshake success is returned, the corresponding first IP is used as the subsequent operation address, and the TCP handshake of other IPs is closed; If the handshake is not successful within the set timeout period, a connection failure is returned to the user.

5. A device for establishing a TCP connection by customizing DNS resolution, characterized in that: include: The public network DNS resolution module obtains the domain name accessed by the user and obtains two public network IP addresses through public network DNS resolution; The custom IP module retrieves the pre-stored IP corresponding to the domain name from the custom DNS library according to the domain name; The synchronous handshake module combines public IP and pre-stored IP into a handshake IP library, and performs TCP handshake on each IP in the handshake IP library at the same time. After the fastest return of handshake success, the corresponding first IP is used as the subsequent operation address, and the TCP handshake of other IPs is closed.

6. The device for establishing a TCP connection by using a custom DNS resolution according to claim 5, characterized in that: It also includes a TLS handshake module, which performs a TLS handshake based on the first IP after completing the TCP handshake. If the TLS handshake is successful, a network connection is established; If the TLS handshake fails, the first IP is removed from the handshake IP library to obtain a removed IP library. After the fastest return of handshake success, the corresponding second IP is used as the subsequent operation address, the TCP handshake of other IPs is closed, and the TLS handshake is performed through the second IP.

7. The device for establishing a TCP connection by using a custom DNS resolution according to claim 5, wherein: The custom IP module specifically establishes a custom DNS library, stores the domain name and the corresponding IP value in the custom DNS library, and retrieves the pre-stored IP corresponding to the domain name from the custom DNS library according to the domain name.

8. The device for establishing a TCP connection by using a custom DNS resolution according to claim 5, wherein: The synchronous handshake module specifically comprises: combining a public network IP and a pre-stored IP into a handshake IP library, performing a TCP handshake on each IP in the handshake IP library at the same time, and after the fastest return of a successful handshake, using the corresponding first IP as the subsequent operation address and closing the TCP handshake of other IPs; If the handshake is not successful within the set timeout period, a connection failure is returned to the user.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the program, the method according to any one of claims 1 to 4 is implemented.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 4 is implemented.