Closed PluieM closed 1 week ago
The changes introduced a new state machine-based banning mechanism by adding multiple classes and modifying existing ones to manage peer connections and bans more efficiently. Key additions include constructing state machines, updating peer conditions, and enhanced rule matching. The updated logic significantly improves how peer bans are managed, focusing on modular rule handling and better configuration.
File Path | Change Summary |
---|---|
pom.xml |
Added a new dependency for state machine functionality. |
src/main/java/com/ghostchu/.../PeerBanHelperServer.java |
Added state machine logic, new fields, and refactored existing methods for better peer management. |
src/main/java/com/ghostchu/.../config/ProfileUpdateScript.java |
Introduced and modified methods for updating module configuration settings. |
src/main/java/com/ghostchu/.../database/DatabaseHelper.java |
Renamed IPBanRuleUpdateType to RuleUpdateType affecting method signatures and usage. |
src/main/java/com/ghostchu/.../database/RuleSubLog.java |
Updated to reflect the renaming of rule update types and affected fields. |
src/main/java/com/ghostchu/.../module/AbstractRuleBlocker.java |
Introduced an abstract class with methods for rule blocking and state machine management. |
src/main/java/com/ghostchu/.../module/MatchEvents.java |
Added enum to define various match events for state transitions. |
src/main/java/com/ghostchu/.../module/MatchResultDetail.java |
Added new class for capturing match result details with context and reasons. |
src/main/java/com/ghostchu/.../module/PeerMatchContext.java |
Added new class encapsulating peer match operations with state machine. |
src/main/java/com/ghostchu/.../module/PeerState.java |
Added enum defining various states of a peer in the state machine. |
src/main/java/com/ghostchu/.../module/RuleBlocker.java |
Added interface defining methods for rule-based blocking and state machine interactions. |
src/main/java/com/ghostchu/.../impl/rule/PeerIdBlocker.java |
Implemented class for blocking peers based on IDs with configuration parsing and rule evaluations. |
src/main/java/com/ghostchu/.../impl/rule/RuleSubBlocker.java |
Renamed and refactored old class to improve rule handling and added new matcher types. |
src/main/java/com/ghostchu/.../impl/webapi/RuleSubController.java |
Refactored API module methods and updated to reflect renamed classes and types. |
src/main/java/com/ghostchu/.../text/Lang.java |
Updated multiple strings related to subscription rules and added new entries. |
src/main/java/com/ghostchu/.../util/rule/RuleMatcher.java |
Introduced new utility for rule matching. |
sequenceDiagram
actor Admin
participant PeerBanHelperServer
participant RuleBlocker
participant StateMachine
participant PeerMatchRecord
Admin ->> PeerBanHelperServer: Initialize Server
PeerBanHelperServer ->> RuleBlocker: registerModules()
RuleBlocker ->> StateMachine: Initialize StateMachine
RuleBlocker ->> PeerMatchRecord: Create matchRecords map
PeerMatchRecord ->> StateMachine: Evaluate match with rules
StateMachine ->> PeerMatchRecord: Update state based on events
RuleBlocker ->> PeerBanHelperServer: Update peer state
PeerBanHelperServer ->> Admin: Inform about ban wave
In the land of code and peers, Where modules and state machines steer, A rabbit hops through lines of might, Banning those who flee in fright. Rules are strict, yet fair in kind, Connection safe, with peace of mind.
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
这可真是个大的变更,能不能多描述一下状态机的实现
该邮件从移动设备发送
主要有两点更新 1、按照 #156 中 @Gaojianli 提供的思路 新增基于状态机模型的规则模块,并基于这个模块重构了订阅规则模块和PeerID黑名单模块 2、#155 拓展规则订阅支持的规则类型,现在支持如下几种类型IP/PEER_ID_CONTAINS/PEER_ID_STARTS_WITH/CLIENT_NAME_CONTAINS/CLIENT_NAME_STARTS_WITH
You can view, comment on, or merge this pull request online at:
https://github.com/PBH-BTN/PeerBanHelper/pull/160
Commit Summary
2f7f213 1、新增一个基于状态机模型的规则模块
b0cce39 规则订阅支持订阅以下匹配类型 IP/PEER_ID_CONTAINS/PEER_ID_STARTS_WITH/CLIENT_NAME_CONTAINS/CLIENT_NAME_STARTS_WITH
File Changes
(22 files)
M pom.xml (5)
M src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java (109)
M src/main/java/com/ghostchu/peerbanhelper/config/ProfileUpdateScript.java (11)
M src/main/java/com/ghostchu/peerbanhelper/database/DatabaseHelper.java (6)
M src/main/java/com/ghostchu/peerbanhelper/database/RuleSubLog.java (4)
A src/main/java/com/ghostchu/peerbanhelper/module/AbstractRuleBlocker.java (43)
A src/main/java/com/ghostchu/peerbanhelper/module/MatchEvents.java (27)
A src/main/java/com/ghostchu/peerbanhelper/module/MatchResultDetail.java (5)
A src/main/java/com/ghostchu/peerbanhelper/module/PeerMatchRecord.java (21)
A src/main/java/com/ghostchu/peerbanhelper/module/PeerState.java (27)
A src/main/java/com/ghostchu/peerbanhelper/module/RuleBlocker.java (115)
R src/main/java/com/ghostchu/peerbanhelper/module/RuleUpdateType.java (2)
A src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/PeerIdBlocker.java (65)
R src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/RuleSubBlocker.java (248)
M src/main/java/com/ghostchu/peerbanhelper/module/impl/webapi/RuleSubController.java (90)
M src/main/java/com/ghostchu/peerbanhelper/text/Lang.java (59)
A src/main/java/com/ghostchu/peerbanhelper/util/rule/RuleMatcher.java (35)
A src/main/java/com/ghostchu/peerbanhelper/util/rule/RuleType.java (27)
R src/main/java/com/ghostchu/peerbanhelper/util/rule/matcher/IPMatcher.java (31)
A src/main/java/com/ghostchu/peerbanhelper/util/rule/matcher/PrefixMatcher.java (48)
A src/main/java/com/ghostchu/peerbanhelper/util/rule/matcher/SubStrMatcher.java (48)
M src/main/resources/profile.yml (6)
Patch Links:
https://github.com/PBH-BTN/PeerBanHelper/pull/160.patch
https://github.com/PBH-BTN/PeerBanHelper/pull/160.diff
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
PBH 对于 ClientName、PeerID 和 IP 匹配(本地)都有缓存机制,检查只会执行一次,我在考虑这个状态机是否放在其它地方会好一点。
状态机的优点是近似检测,比如如果不命中XL规则,那么XL0019就不用看了
该邮件从移动设备发送
PBH 对于 ClientName、PeerID 和 IP 匹配(本地)都有缓存机制,检查只会执行一次,我在考虑这个状态机是否放在其它地方会好一点。
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>
@PluieM 简单看了下代码,前缀树的构造在哪个部分呀,没找到呀
还没调整完毕,容我稍后画图解释
@coderabbitai 详细解释此PR,如果可以的话,请再画一个图
[!TIP] For best results, initiate chat on the files or code changes.
@Ghost-chu, here's a detailed explanation of the changes introduced in PR #160, along with a diagram to visually represent the new architecture.
This PR introduces a significant update to the PeerBanHelper project, focusing on enhancing the rule-based peer banning system through a state machine model and expanding the rule types supported by the system.
State Machine-Based Rule Module:
AbstractRuleBlocker
) has been introduced. This model serves as the foundation for handling different states of peer connections and deciding the actions based on various match events.INIT
, MATCH
, BAN
, ACTIVE
, and END
based on events such as MATCH
, HIT
, PASS
, DISCONNECT
, and TIMEOUT
.Refactoring of Modules:
Expansion of Rule Types:
IP
, PEER_ID_CONTAINS
, PEER_ID_STARTS_WITH
, CLIENT_NAME_CONTAINS
, and CLIENT_NAME_STARTS_WITH
. This enhancement broadens the scope of the rules that can be applied, making the system more versatile.Integration with Existing Components:
PeerBanHelperServer
, ProfileUpdateScript
, and DatabaseHelper
to integrate the new rule module and support the expanded rule types.Below is a diagram illustrating the integration of the state machine model with the rule modules:
flowchart TD
A[PeerBanHelperServer] -->|Manages| B[AbstractRuleBlocker]
B -->|Utilizes| C[StateMachine]
C --> D[PeerState]
D --> E[MatchEvents]
B -->|Controls| F[RuleBlocker]
F -->|Implements| G[PeerIdBlocker]
F -->|Implements| H[RuleSubBlocker]
C -->|Triggers| I[MatchResultDetail]
I --> J[PeerMatchRecord]
This diagram shows how PeerBanHelperServer
manages instances of AbstractRuleBlocker
, which utilize a StateMachine
to handle different PeerStates
based on MatchEvents
. The RuleBlocker
interface is implemented by specific blockers like PeerIdBlocker
and RuleSubBlocker
, which are responsible for the actual rule enforcement based on the state transitions.
I hope this provides a clear understanding of the changes and the architecture introduced in this PR. If you have any more questions or need further clarification, feel free to ask!
@coderabbitai 详细解释此PR,如果可以的话,请再画一个图
@coderabbitai 请详细描述一下 Peer 在此 PR 是如何匹配的。简述各种情况下状态机发生的变化。
[!TIP] For best results, initiate chat on the files or code changes.
@Ghost-chu, as requested, here's a more detailed explanation of the changes introduced in PR #160, along with a diagram to visually represent the new architecture.
This PR introduces a significant update to the PeerBanHelper project, focusing on enhancing the rule-based peer banning system through a state machine model and expanding the rule types supported by the system.
State Machine-Based Rule Module:
AbstractRuleBlocker
) has been introduced. This model serves as the foundation for handling different states of peer connections and deciding the actions based on various match events.INIT
, MATCH
, BAN
, ACTIVE
, and END
based on events such as MATCH
, HIT
, PASS
, DISCONNECT
, and TIMEOUT
.Refactoring of Modules:
Expansion of Rule Types:
IP
, PEER_ID_CONTAINS
, PEER_ID_STARTS_WITH
, CLIENT_NAME_CONTAINS
, and CLIENT_NAME_STARTS_WITH
. This enhancement broadens the scope of the rules that can be applied, making the system more versatile.Integration with Existing Components:
PeerBanHelperServer
, ProfileUpdateScript
, and DatabaseHelper
to integrate the new rule module and support the expanded rule types.Below is a diagram illustrating the integration of the state machine model with the rule modules:
flowchart TD
A[PeerBanHelperServer] -->|Manages| B[AbstractRuleBlocker]
B -->|Utilizes| C[StateMachine]
C --> D[PeerState]
D --> E[MatchEvents]
B -->|Controls| F[RuleBlocker]
F -->|Implements| G[PeerIdBlocker]
F -->|Implements| H[RuleSubBlocker]
C -->|Triggers| I[MatchResultDetail]
I --> J[PeerMatchRecord]
This diagram shows how PeerBanHelperServer
manages instances of AbstractRuleBlocker
, which utilize a StateMachine
to handle different PeerStates
based on MatchEvents
. The RuleBlocker
interface is implemented by specific blockers like PeerIdBlocker
and RuleSubBlocker
, which are responsible for the actual rule enforcement based on the state transitions.
I hope this provides a clear understanding of the changes and the architecture introduced in this PR. If you have any more questions or need further clarification, feel free to ask!
[!TIP] For best results, initiate chat on the files or code changes.
@Ghost-chu, 在此 PR 中,Peer 的匹配和状态机的变化是通过新引入的基于状态机模型的规则模块来管理的。这里是详细的解释:
这个状态机模型允许系统灵活地处理各种 Peer 状态和事件,确保根据实时数据动态调整 Peer 的处理。如果您需要更多信息或有其他问题,请随时提问!
@coderabbitai summary
感觉没对齐,能看下qq群吗? @PluieM 我说的是类似NFA的文法状态机
主要有两点更新 1、按照 #156 中 @Gaojianli 提供的思路 新增基于状态机模型的规则模块,并基于这个模块重构了订阅规则模块和PeerID黑名单模块 2、#155 拓展规则订阅支持的规则类型,现在支持如下几种类型IP/PEER_ID_CONTAINS/PEER_ID_STARTS_WITH/CLIENT_NAME_CONTAINS/CLIENT_NAME_STARTS_WITH
Summary by CodeRabbit
New Features
AbstractRuleBlocker
and related classes.MatchEvents
,MatchResultDetail
,PeerMatchContext
,PeerState
, andRuleBlocker
for comprehensive rule matching.PeerIdBlocker
for blocking peers based on IDs.subModuleUpdate()
inProfileUpdateScript
.Bug Fixes
Refactor
Style
Lang.java
for improved localization and clarity.