A connection management method for secure shell protocol connections of different hosts

By using a combination of two security threads and connection selectors, caches, and blocking queues in secure shell protocol connection management, the problem of only supporting connection management of the same host in the existing technology is solved, and connection management and control of different hosts are realized. Reuse improves connection freshness and system efficiency.

CN118193331BActive Publication Date: 2024-09-24TIANJIN NANKAI UNIV GENERAL DATA TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410612547.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-17
Publication Date
2024-09-24
Estimated Expiration
2044-05-17

AI Technical Summary

Technical Problem

The existing Secure Shell protocol connection manager only supports connection management and reuse for the same host, which is difficult to meet the needs of multi-host scenarios, resulting in low connection management efficiency.

Method used

Two security threads are used to regularly check and manage the usage status and life cycle of the secure shell protocol, dynamically create or reuse connections, realize connection management of different hosts through connection selectors, caches and blocking queues, and regularly check and recycle expired unused ones. connection.

Benefits of technology

It realizes the effective management and reuse of secure shell protocol connections of different hosts, ensures the freshness and availability of connections, avoids long-term idle connections occupying resources, and improves the efficiency and resource utilization of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118193331B
    Figure CN118193331B
Patent Text Reader

Abstract

The present invention provides a connection management method for secure shell protocol connections of different hosts, comprising the following steps: initializing the connection component of the secure shell protocol, using two secure threads to periodically check and manage the use status and life cycle of the secure shell protocol respectively; dynamically creating or reusing secure shell protocol connections according to business needs and the current status of the threads, continuously scanning and updating the connection status of the secure shell protocol, and executing closing and recycling operations of expired and unused secure shell protocols according to the current connection status. The present invention has the beneficial effects of realizing management and reuse of secure shell protocol connections for different hosts, selecting appropriate connections according to the characteristics of different hosts, ensuring effective management of connections of different hosts, avoiding long-term idle connections from occupying resources, and ensuring the freshness and availability of connections.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of network connection management, and in particular relates to a connection management method for secure shell protocol connections of different hosts. Background Art

[0002] Many business scenarios involve using the secure shell protocol to establish connections with different hosts. Because establishing connections takes a lot of time and affects the execution efficiency of the program, the connection manager of the secure shell protocol connection is often used to manage and reuse previously created connections.

[0003] However, the existing secure shell protocol connection manager only supports the management and reuse of secure shell protocol connections of the same host, which is difficult to meet the needs of many business scenarios. Summary of the invention

[0004] In view of this, the present invention aims to propose a connection management method for secure shell protocol connections of different hosts, in order to solve at least one of the above-mentioned technical problems.

[0005] To achieve the above object, the technical solution of the present invention is achieved as follows:

[0006] A connection management method for secure shell protocol connections of different hosts, comprising the following steps:

[0007] Initialize the connection component of the secure shell protocol, and use two security threads to periodically check and manage the usage status and life cycle of the secure shell protocol;

[0008] Dynamically create or reuse secure shell protocol connections based on business needs and the current state of the thread, continuously scan and update the connection state of the secure shell protocol, and close and recycle expired and unused secure shell protocols based on the current connection state.

[0009] Further, the connection components of the secure shell protocol include a selector, a cache, and a blocking queue;

[0010] The connection selector of the secure shell protocol selects the corresponding shell protocol connection according to different network communication requirements;

[0011] The secure shell protocol connection cache stores established containers for searching and reusing shell protocol connections;

[0012] The connection blocking queue of the secure shell protocol is used as a thread-safe structure to internally store shell protocol connections to be closed and recycled.

[0013] Further, the safety thread includes a check thread;

[0014] The checking thread periodically checks the connection status of all existing secure shell protocols to determine whether the connection status of the current secure shell protocol is expired and no longer in use;

[0015] If so, remove the current secure shell protocol from the connection cache and place it in the connection blocking queue; otherwise, check the next one.

[0016] Furthermore, the security thread also includes a monitoring thread;

[0017] The monitoring thread continuously monitors the connection blocking queue, and when it monitors that there is a connection to be closed in the connection blocking queue, it immediately closes the current connection and performs resource cleaning and memory release operations;

[0018] After the execution is completed, check whether the related resources of the connection have been recycled.

[0019] Furthermore, the specific process of the checking thread determining whether the connection status of the current secure shell protocol is expired and unused includes:

[0020] Check whether the connection status has expired:

[0021] When using a secure shell protocol connection, check whether the difference between the last use time and the current time exceeds the set maximum timeout. If it exceeds the maximum timeout, the connection is considered expired. If it does not exceed the maximum timeout, reset the last use time to the current time.

[0022] Check if the connection is not in use:

[0023] When using a secure shell protocol connection, apply for a lock on the connection holder object. When the use ends or an exception occurs, release the lock on the connection holder object. If the lock on the connection holder object is not held by any thread at a certain moment, the current connection is not in use.

[0024] Furthermore, the connection creation process of the secure shell protocol includes:

[0025] A1. Get and search whether there is a created connection set of the current thread in the connection cache. If so, execute A2; otherwise, execute A4.

[0026] A2. Traverse the created connection set to find out whether there is a created connection with the same connection attributes as the connection to be created. If so, execute A3; otherwise, execute A4.

[0027] A3. Determine whether the created connection has expired. If it has not expired, execute A5. Otherwise, add the currently created connection to the blocking queue and return to A2.

[0028] A4. Create a new connection and add the new connection to the collection of created connections of the current thread.

[0029] Compared with the prior art, the connection management method for secure shell protocol connections of different hosts described in the present invention has the following beneficial effects:

[0030] Implemented management and reuse of secure shell protocol connections for different hosts:

[0031] The shell protocol connection selector is responsible for selecting the shell protocol connection suitable for the current host. It can select the appropriate connection according to the characteristics of different hosts, thereby realizing connection management for different hosts;

[0032] Maintain a set of created connections for each thread. These connection sets are matched according to the properties of the current thread and the properties of the connection to be created, ensuring effective management of connections on different hosts.

[0033] Check the connection regularly to see if it has expired. Expired connections will be closed and recycled in a timely manner to avoid long-term idle connections occupying resources while ensuring the freshness and availability of the connection. BRIEF DESCRIPTION OF THE DRAWINGS

[0034] The accompanying drawings constituting a part of the present invention are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the accompanying drawings:

[0035] Figure 1 The present invention is a schematic diagram of a specific execution flow of a connection management method for secure shell protocol connections of different hosts according to an embodiment of the present invention. DETAILED DESCRIPTION

[0036] It should be noted that, in the absence of conflict, the embodiments of the present invention and the features in the embodiments may be combined with each other.

[0037] The present invention will be described in detail below with reference to the accompanying drawings and in conjunction with embodiments.

[0038] A connection management method for secure shell protocol connections of different hosts, comprising the following steps:

[0039] Initialize the connection component of the secure shell protocol, and use two security threads to periodically check and manage the usage status and life cycle of the secure shell protocol;

[0040] Dynamically create or reuse secure shell protocol connections based on business needs and the current state of the thread, continuously scan and update the connection state of the secure shell protocol, and close and recycle expired and unused secure shell protocols based on the current connection state.

[0041] The specific execution process is as follows:

[0042] Step 1: Create an initialization manager;

[0043] Initialization Manager: During the system startup phase, an initialization manager is created to manage and set the connection components of the secure shell protocol to ensure the effective management and maintenance of the shell protocol connection in the future;

[0044] The connection components of the secure shell protocol include a selector, a cache, and a blocking queue;

[0045] Wherein, the connection selector of the secure shell protocol selects the corresponding shell protocol connection according to different network communication requirements;

[0046] The connection cache of the secure shell protocol stores containers of established shell protocol connections for searching and reusing, which helps to quickly search and reuse existing connections;

[0047] The connection blocking queue of the secure shell protocol is used as a thread-safe structure to internally store shell protocol connections to be closed and recycled.

[0048] Step 2: Start the connection life management thread of the secure shell protocol:

[0049] The security thread includes a checking thread and a listening thread;

[0050] The checking thread is responsible for periodically checking all existing shell protocol connections to determine whether the connection status of the current secure shell protocol is expired and unused;

[0051] If an expired connection is detected, the current secure shell protocol is removed from the connection cache and placed in the blocking queue of the secure shell protocol connections to be closed, waiting for further processing; otherwise, the next one is checked;

[0052] The monitoring thread acts as a consumer and continuously monitors the blocking queue of the secure shell protocol connection to be closed. When a connection to be closed is found in the queue, the monitoring thread immediately performs the closing operation, including cleaning up resources and releasing memory.

[0053] After the execution is completed, it is checked whether the related resources of the connection have been recycled to ensure that the related resources of the connection are properly recycled. This mechanism ensures the efficiency and resource utilization of the system and avoids long-term unused connections occupying unnecessary system resources.

[0054] Step 3: Establish a secure shell protocol connection:

[0055] The specific process of the checking thread determining whether the connection status of the current secure shell protocol is expired and unused includes:

[0056] Check whether the connection status has expired:

[0057] When using a secure shell protocol connection, check whether the difference between the last use time and the current time exceeds the set maximum timeout. If it exceeds the maximum timeout, the connection is considered expired. If it does not exceed the maximum timeout, reset the last use time to the current time.

[0058] Check if the connection is not in use:

[0059] When using a secure shell protocol connection, apply for a lock on the connection holder object. When the use ends or an exception occurs, release the lock on the connection holder object. If the lock on the connection holder object is not held by any thread at a certain moment, the current connection is not in use.

[0060] The connection creation process of the secure shell protocol includes:

[0061] A1. Get and search whether there is a created connection set of the current thread in the connection cache. If so, execute A2; otherwise, execute A4.

[0062] A2. Traverse the created connection set to find out whether there is a created connection with the same connection attributes as the connection to be created. If so, execute A3; otherwise, execute A4.

[0063] A3. Determine whether the created connection has expired. If it has not expired, execute A5. Otherwise, add the currently created connection to the blocking queue and return to A2.

[0064] A4. Create a new connection and add the new connection to the collection of created connections of the current thread.

[0065] Those of ordinary skill in the art will appreciate that the units and method steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0066] In the several embodiments provided in the present application, it should be understood that the disclosed methods and systems can be implemented in other ways. For example, the division of the units described above is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. The above-mentioned units may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of the present invention.

[0067] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein by equivalents. These modifications or replacements do not make the essence of the corresponding technical solutions deviate from the scope of the technical solutions of the embodiments of the present invention, and they should all be included in the scope of the claims and specification of the present invention.

[0068] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims

1. A connection management method for secure shell protocol connections of different hosts, characterized in that: The steps include: Initialize the connection component of the secure shell protocol, and use two security threads to periodically check and manage the usage status and life cycle of the secure shell protocol; Dynamically create or reuse secure shell protocol connections based on business needs and the current state of the thread, continuously scan and update the connection state of the secure shell protocol, and close and recycle expired and unused secure shell protocols based on the current connection state; The connection components of the secure shell protocol include a selector, a cache, and a blocking queue; The connection selector of the secure shell protocol selects the corresponding shell protocol connection according to different network communication requirements; The secure shell protocol connection cache stores established containers for searching and reusing shell protocol connections; The connection blocking queue of the secure shell protocol is used as a thread-safe structure to store the shell protocol connections to be closed and recycled; The safety thread includes a check thread; The checking thread periodically checks the connection status of all existing secure shell protocols to determine whether the connection status of the current secure shell protocol is expired and unused; If yes, the current secure shell protocol is removed from the connection cache and placed in the connection blocking queue; Otherwise check the next one; The specific process of the checking thread determining whether the connection status of the current secure shell protocol is expired and unused includes: Check whether the connection status has expired: When using a secure shell protocol connection, check whether the difference between the last use time and the current time exceeds the set maximum timeout. If it exceeds the maximum timeout, the connection is considered expired. If it does not exceed the maximum timeout, reset the last use time to the current time. Check if the connection is not in use: When using a secure shell protocol connection, apply for a lock on the connection holder object. When the use ends or an exception occurs, release the lock on the connection holder object. If the lock on the connection holder object is not held by any thread at a certain moment, the current connection is not in use.

2. A connection management method for secure shell protocol connections of different hosts according to claim 1, characterized in that: The security thread also includes a monitoring thread; The monitoring thread continuously monitors the connection blocking queue, and when it monitors that there is a connection to be closed in the connection blocking queue, it immediately closes the current connection and performs resource cleaning and memory release operations; After the execution is completed, check whether the related resources of the connection have been recycled.

3. A connection management method for secure shell protocol connections of different hosts according to claim 1, characterized in that: The connection creation process of the secure shell protocol includes: A1. Get and search whether there is a created connection set of the current thread in the connection cache. If so, execute A2; otherwise, execute A4. A2. Traverse the created connection set to find out whether there is a created connection with the same connection attributes as the connection to be created. If so, execute A3; otherwise, execute A4. A3. Determine whether the created connection has expired. If it has not expired, execute A4. Otherwise, add the currently created connection to the blocking queue and return to A2. A4. Create a new connection and add the new connection to the collection of created connections of the current thread.