IP blocking method based on bidirectional queue sliding window

By using a sliding window structure based on a bidirectional queue, the problem of quickly identifying and blocking illegal IPs in the database gateway within a very short time is solved, achieving efficient IP blocking and space utilization optimization.

CN116248331BActive Publication Date: 2026-12-04SHANGHAI GUAN AN INFORMATION TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202211626779.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-16
Publication Date
2026-12-04
Estimated Expiration
2042-12-16

AI Technical Summary

Technical Problem

Existing technologies struggle to identify and block unauthorized IPs in database gateways within extremely short timeframes (seconds), and existing algorithm structures result in significant space consumption and limited performance improvements.

Method used

A sliding window structure based on a bidirectional queue is adopted. By constructing a bidirectional queue and a counter, the queue and counter are updated according to the blocking log information to determine whether the blocking conditions are met, so as to achieve fast IP blocking.

Benefits of technology

It can identify and block IPs in a very short time (seconds) and complete the task within a constant range, reducing space usage and improving performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116248331B_ABST
    Figure CN116248331B_ABST
Patent Text Reader

Abstract

This invention relates to an IP blocking method based on a sliding window using a bidirectional queue, comprising the following steps: S1, constructing a bidirectional queue; S2, constructing a counter; S3, extracting information from blocking logs; S4, inserting new blocking information into the bidirectional queue; S5, calculating the value of the bidirectional queue; and S6, determining whether to block. Its advantages lie in that, due to the use of a bidirectional queue data structure, IPs can be identified and blocked within an extremely short time (in seconds), and the blocking time is within a constant range. The space occupied by this application is reduced compared to existing technologies, resulting in a significant performance improvement.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of database security gateway technology, and in particular to an IP blocking method based on a sliding window of a bidirectional queue. Background Technology

[0002] With the introduction of data security protection laws, major enterprises are paying increasing attention to data security, especially the IP monitoring of database gateways. If an IP address consistently violates rules within a given time period, typically within one hour, then that IP address needs to be blocked.

[0003] Since the database gateway handles nearly 10,000 concurrent connections, the amount of data per second is very large, reaching 100,000. The technical problem of how to identify and block IPs in a very short time (seconds) while keeping the time within a constant range has not yet been properly solved. Summary of the Invention

[0004] To address the shortcomings of existing technologies, the purpose of this invention is to provide an IP blocking method based on a sliding window of a bidirectional queue, which solves the technical problem of how to identify and block IPs in a very short time (seconds) while keeping the time within a constant range during IP monitoring.

[0005] The above-mentioned objective of this invention is achieved through the following technical solutions: This invention provides an IP blocking method based on a sliding window with a bidirectional queue, comprising the following steps: S1. Construct a double-ended queue: The number of double-ended queues is determined by the number of IPs, and the queue size of a double-ended queue is k. S2, Construct a counter: The counter count is based on the number of IPs; S3. Extract information from the blocking log: Extract the sessionId, corresponding IP address, and blocking information of the blocked session; S4. Insert the new blocking information into the bidirectional queue: If the blocking information of the data at the head of the queue is equal to the new blocking information, then the count in the data at the head of the queue is incremented by 1; If the blocking information of the data at the head of the queue is less than the new blocking information, then determine whether the queue is full; If the queue is not full, insert the new blocking information directly at the head of the queue. If the queue is full, delete the last element and add a record to the first element. If the last element is deleted, the counter is reduced by the count of the last element. If no deletion occurs, increment the counter by 1. S5. Calculate the value of the double-ended queue: The value of the double-ended queue is equal to the value of the counter; S6. Determine if blocking is possible: If the value of the bidirectional queue is greater than or equal to the threshold, then the queue is blocked.

[0006] As one of the embodiments, in step S1: a bidirectional queue is constructed corresponding to one IP, 1≤k≤3600.

[0007] As one of the embodiments, in step S2: a counter is constructed corresponding to one IP, and the structure of the counter is time + number.

[0008] In some embodiments, the blocking information in steps S3 and S4 is the blocking time.

[0009] The beneficial technical effects of this invention are as follows: This invention discloses an IP blocking method based on a sliding window of a bidirectional queue. Due to the use of a bidirectional queue data structure, it can identify and block IPs in an ultra-short second time, and the blocking time is within a constant range. Compared with the prior art, the space ratio of this application is reduced and the performance is greatly improved. Attached Figure Description

[0010] Figure 1 This is a structural diagram of a bidirectional queue in an embodiment of the present invention. Detailed Implementation

[0011] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. All other embodiments obtained by those skilled in the art based on the embodiments of this application without creative effort are within the scope of protection of this application. Example

[0012] like Figure 1 As shown, the present invention discloses an IP blocking method based on a sliding window of a bidirectional queue, comprising the following steps: S1. Construct a double-ended queue: The number of double-ended queues is based on the number of IPs. One double-ended queue corresponds to one IP. The size of the double-ended queue is k, where 1≤k≤3600. New data is inserted at the head of the queue, and redundant data is deleted at the tail. That is, data is only updated at the head and tail of the queue.

[0013] S2, Construct a counter: The number of counters is built based on the number of IPs, with one counter corresponding to one IP. The structure of the counter is time + count.

[0014] S3. Extract information from the blocking log: Extract the sessionId, corresponding IP address, and blocking time of the blocked session.

[0015] S4. Insert the new blocking time into the double-ended queue: If the blocking time of the data at the head of the queue is equal to the new blocking time, then the count in the data at the head of the queue is incremented by 1; If the blocking time of the data at the head of the queue is less than the new blocking time, then determine whether the queue is full. If the queue is not full, the new blocking time will be inserted directly at the head of the queue. If the queue is full, delete the last element and add a record to the first element. If the last element is deleted, the counter is reduced by the count of the last element. If no deletion occurs, the counter is incremented by 1.

[0016] S5. Calculate the value of the double-ended queue: Because an IP counter is used, the value of the double-ended queue is equal to the value of the counter.

[0017] S6. Determine if blocking is possible: If the value of the bidirectional queue is greater than or equal to the threshold, then the connection is blocked. The threshold is set according to the actual situation.

[0018] Based on the characteristic that the generated data is generated in chronological order, this application uses a doubly queue data structure, which enables the insertion of new blocking times to be within a constant range.

[0019] Traditional IP surveillance typically employs brute-force or max-heap algorithms, but these methods have less than ideal time complexity. In this application, for a data stream of N elements, the time complexity is O(N) (where N is the number of blocking times and k is the window size), significantly less than other structures. The space complexity is O(N), similar to other structures. Therefore, this application reduces space consumption and significantly improves performance.

[0020] The advantage of this embodiment is that, due to the adoption of a bidirectional queue data structure, it can identify and block IPs in an ultra-short second time, and the blocking time is within a constant range. The space ratio of this application is reduced compared with the prior art, and the performance is greatly improved.

[0021] The embodiments described herein are preferred embodiments of the present invention and are not intended to limit the scope of protection of the present invention. Furthermore, the above embodiments can be combined with each other for use. Therefore, all equivalent changes made in accordance with the structure, shape, and principle of the present invention should be covered within the scope of protection of the present invention.