Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PCB 作弊快速测试支持 #459

Merged
merged 5 commits into from
Sep 11, 2024
Merged

PCB 作弊快速测试支持 #459

merged 5 commits into from
Sep 11, 2024

Conversation

Ghost-chu
Copy link
Collaborator

@Ghost-chu Ghost-chu commented Sep 11, 2024

简述

目前的 ProgressCheatBlocker 存在一个问题,也就是只有 Peer 完整的下载完一次文件,才能在下次重新连接时触发进度回退检测。
尽管这种手段非常有效,但是这最起码会对做种者产生 1.0 分享率的损失,并且发现速度较慢。

解决方案

目前常见的大部分吸血端在连接时都会以 0% 的进度连接,一旦连接断开,它们的进度就会重置。
本 PR 通过设置一个百分比,当对端吸血一定百分比的种子大小的文件数据时,PBH 就会短暂的封禁它们(默认为 15 秒)以便让下载器断开与他们的连接(并从内存 LRU 缓存中逐出(如果有))。
这样在封禁其结束后,吸血端重新以 0% 进度连接时就会立刻被 PCB 捕获。每次捕获在野恶意客户端可以节约 90% 流量的损失。当一个 PCB 特征组通过测试后,在 persist-duration 时间内不会在此对此特征组进行再次检查。
如果吸血端想要绕过此检查,则必须在内存或者 DB 中持久保存其记录的 bitfield 信息(因为胡编乱造一个会导致进度匹配不上,从而触发 PCB 的其它检查)。这无形之中对吸血者提出了更高硬件要求,增加了其吸血成本。
即使吸血者可绕过此次新增的检查,但依旧无法绕过此前已添加的 PCB 的其它检查。因此本 PR 的功能主要是帮助 PCB 的其它模块快速预热、加速恶意客户端的发现。

08b16c657567cec07ed70e1a42ddc58c
64bcbe285741baaa074983d44cb68e45

新增配置文件项

    # 快速 PCB 测试启动阈值
    # Fast PCB testing start threshold
    # 此选项将允许 PCB 在 Peer 下载指定量的数据后,将其短暂的封禁一段时间以便断开其连接
    # This option will allow PCB ban the Peer from downloader for disconnect it
    # 这有助于快速预热进度重置检查
    # Can heat up progress reset check quickly
    # 设置为 -1 以禁用
    # Set to -1 for disable it
    fast-pcb-test-percentage: 0.1
    # 快速 PCB 测试断开连接持续时间
    # The disconnect duration for fast PCB test
    # 更长的时间更容易使得恶意吸血者的临时记录从 LRU 缓存中逐出,以便 PBH 识别它;但也会影响正常下载者的速度和体验
    # The longer time can lead cheaters temp records be invalid and remove from LRU cache, then PBH can detect it; but it can also affect the normal peers speed and experience
    fast-pcb-test-block-duration: 30000

注意事项

与 qBittorrentEE 的 shadowBan 功能不兼容,在开启了 shadowBan 后,由于封禁不再切断连接,因此无法进行快速测试

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Introduced a "fast PCB testing" feature that allows for temporary bans of peers based on their upload behavior.
    • Added new configuration parameters for controlling the fast PCB test percentage and ban duration.
    • Enhanced peer banning logic with the addition of SILENT_BAN and BAN_FOR_DISCONNECT action types.
  • Bug Fixes

    • Improved logging practices to clarify ban actions and prevent unnecessary warnings for BAN_FOR_DISCONNECT.
  • Documentation

    • Updated configuration schema to reflect new features and parameters.

@Ghost-chu Ghost-chu requested a review from a team as a code owner September 11, 2024 12:20
Copy link
Contributor

coderabbitai bot commented Sep 11, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The changes introduce enhancements to the PeerBanHelper application, focusing on peer banning mechanisms, database upgrades, and configuration management. Key modifications include the addition of silent and disconnect ban actions, new parameters for fast PCB testing, and updates to database handling logic. Several classes have been modified to accommodate these changes, including adjustments to logging, concurrency management, and localization for user messages. The configuration files have also been updated to reflect new features and versioning.

Changes

Files Change Summary
src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java Expanded peer banning conditions to include SILENT_BAN and BAN_FOR_DISCONNECT, refined logging for these actions, and introduced a banWaveLock for concurrency management.
src/main/java/com/ghostchu/peerbanhelper/config/ProfileUpdateScript.java Added fastPcbTesting method to set configuration values for fast PCB testing.
src/main/java/com/ghostchu/peerbanhelper/database/DatabaseHelper.java Modified performUpgrade method for database versioning logic, including handling for version 5.
src/main/java/com/ghostchu/peerbanhelper/database/dao/impl/ProgressCheatBlockerPersistDao.java Added FastPcbTestExecuteAt parameter to fetchFromDatabase and flushDatabase methods for enhanced data handling.
src/main/java/com/ghostchu/peerbanhelper/database/table/ProgressCheatBlockerPersistEntity.java Introduced fastPcbTestExecuteAt field to the entity class.
src/main/java/com/ghostchu/peerbanhelper/module/PeerAction.java Added new enum values SILENT_BAN and BAN_FOR_DISCONNECT to expand peer action types.
src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java Introduced new fields for fast PCB test parameters and updated reloadConfig method to manage fast PCB test logic.
src/main/java/com/ghostchu/peerbanhelper/wrapper/BanMetadata.java Modified constructors to include a new parameter banForDisconnect for enhanced ban metadata handling.
src/main/resources/profile.yml Updated configuration version and added parameters for fast PCB testing.
src/main/resources/lang/en_us/messages.yml Added new entries for fast PCB test messages to enhance user communication.
src/main/resources/lang/messages_fallback.yml Added localized entries for fast PCB test messages.
src/main/resources/lang/zh_cn/messages.yml Added Chinese localized entries for fast PCB test messages.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant PeerBanHelper
    participant Database

    User->>PeerBanHelper: Initiate Peer Action
    PeerBanHelper->>Database: Check Peer Status
    alt Silent Ban
        PeerBanHelper->>User: Log Silent Ban
    else Disconnect Ban
        PeerBanHelper->>User: Log Disconnect Ban
    else Regular Ban
        PeerBanHelper->>Database: Update Peer Status to Banned
        PeerBanHelper->>User: Notify Ban Action
    end
Loading

🐰 In the meadow where rabbits play,
A helper hops to save the day!
With silent bans and tests so fast,
Cheating peers won't stand, alas!
Configuration sings a tune,
While logs keep track from morn till noon! 🌼


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Outside diff range and nitpick comments (1)
src/main/resources/profile.yml (1)

184-188: LGTM, but monitor the impact and adjust if needed.

The new fast-pcb-test-block-duration configuration option is well-explained, and the trade-offs between detecting malicious leechers and affecting normal downloaders are clearly outlined.

The default value of 30 seconds seems like a reasonable starting point. However, I recommend closely monitoring the real-world performance and impact of this setting on both malicious leechers and normal downloaders. Be prepared to adjust the value as needed to strike the right balance between detection effectiveness and user experience.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 94c3153 and 1fa7fbc.

Files selected for processing (12)
  • src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java (5 hunks)
  • src/main/java/com/ghostchu/peerbanhelper/config/ProfileUpdateScript.java (1 hunks)
  • src/main/java/com/ghostchu/peerbanhelper/database/DatabaseHelper.java (2 hunks)
  • src/main/java/com/ghostchu/peerbanhelper/database/dao/impl/ProgressCheatBlockerPersistDao.java (2 hunks)
  • src/main/java/com/ghostchu/peerbanhelper/database/table/ProgressCheatBlockerPersistEntity.java (1 hunks)
  • src/main/java/com/ghostchu/peerbanhelper/module/PeerAction.java (1 hunks)
  • src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java (6 hunks)
  • src/main/java/com/ghostchu/peerbanhelper/text/Lang.java (1 hunks)
  • src/main/resources/lang/en_us/messages.yml (1 hunks)
  • src/main/resources/lang/messages_fallback.yml (1 hunks)
  • src/main/resources/lang/zh_cn/messages.yml (1 hunks)
  • src/main/resources/profile.yml (2 hunks)
Additional context used
yamllint
src/main/resources/lang/messages_fallback.yml

[error] 372-372: no new line character at the end of file

(new-line-at-end-of-file)

src/main/resources/lang/en_us/messages.yml

[error] 372-372: no new line character at the end of file

(new-line-at-end-of-file)

Additional comments not posted (26)
src/main/java/com/ghostchu/peerbanhelper/database/table/ProgressCheatBlockerPersistEntity.java (1)

40-41: New field added. Verify its purpose and usage.

The addition of the fastPcbTestExecuteAt field is approved.

However, please provide more context on the purpose and usage of this field. Consider adding comments to clarify its role within the ProgressCheatBlockerPersistEntity class and how it interacts with the fast PCB test functionality.

src/main/java/com/ghostchu/peerbanhelper/database/DatabaseHelper.java (2)

47-47: LGTM!

The change to the version string is approved.


69-73: LGTM!

The changes to handle the database upgrade from version 5 to 6 are approved. The logic to drop and recreate the ProgressCheatBlockerPersistEntity table ensures a clean state after the upgrade.

src/main/java/com/ghostchu/peerbanhelper/database/dao/impl/ProgressCheatBlockerPersistDao.java (2)

49-50: LGTM!

The code changes are approved.

The FastPcbTestExecuteAt value is correctly added as an additional argument when creating a new instance of ProgressCheatBlocker.ClientTask. This change enhances the data being fetched from the database by incorporating the new attribute.


74-75: LGTM!

The code changes are approved.

The FastPcbTestExecuteAt value is correctly added as an argument when creating a new entity from ProgressCheatBlocker.ClientTaskRecord. This change ensures that the new attribute is persisted alongside other task details during the flushing operation.

src/main/java/com/ghostchu/peerbanhelper/text/Lang.java (2)

325-345: LGTM!

The code changes that add new constants to the Lang enum for GUI menu options are approved. The additions follow the existing naming convention, are properly formatted, and expand the functionality without introducing any issues.


345-346: LGTM!

The code changes that add new constants PCB_RULE_PEER_PROGRESS_CHEAT_TESTING and PCB_DESCRIPTION_PEER_PROGRESS_CHEAT_TESTING to the Lang enum are approved. The additions follow the existing naming convention, are properly formatted, and expand the functionality without introducing any issues.

src/main/java/com/ghostchu/peerbanhelper/config/ProfileUpdateScript.java (2)

28-32: LGTM! The new fastPcbTesting function looks good.

The changes introduce a new fastPcbTesting function annotated with @UpdateScript(version = 19), which sets two configuration parameters:

  • module.progress-cheat-blocker.fast-pcb-test-percentage is set to 0.1d.
  • module.progress-cheat-blocker.fast-pcb-test-block-duration is set to 30000.

Based on the naming, these settings seem to be related to a new "fast PCB testing" feature that allows temporarily banning peers who connect with 0% progress after downloading a certain percentage of the seed's file data. The fast-pcb-test-percentage likely represents this download percentage threshold, while fast-pcb-test-block-duration specifies the duration of the temporary ban in milliseconds.

This aligns with the PR summary that mentions introducing this mechanism to quickly detect leechers that reset their progress upon disconnection.


Line range hint 35-38: Skipped reviewing the banDelayWait function since it's unchanged in this diff.

src/main/java/com/ghostchu/peerbanhelper/module/impl/rule/ProgressCheatBlocker.java (5)

78-78: LGTM!

The code changes are approved.


79-79: LGTM!

The code changes are approved.


184-185: LGTM!

The code changes are approved.


373-373: LGTM!

The code changes are approved.


239-254: LGTM, but verify the changes are thoroughly tested.

The code changes are approved.

However, ensure that this change is thoroughly tested to confirm that it behaves as expected and captures the intended fast PCB test scenarios.

Run the following script to verify the changes:

Verification successful

Changes are present and initialized correctly, but ensure thorough testing.

The new logic for the fast PCB test is correctly implemented and the variables are initialized from the configuration. However, please ensure that this change is thoroughly tested to confirm that it behaves as expected and captures the intended fast PCB test scenarios.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the fast PCB test mechanism is working as expected.

# Test: Search for the fast PCB test logic. Expect: The new code block is present.
rg --type java -A 10 $'if \(fastPcbTestPercentage > 0\) \{'

# Test: Search for the usage of the new variables. Expect: They are initialized from the config and used in the new code block.
rg --type java -A 5 $'fastPcbTestPercentage|fastPcbTestBlockingDuration'

Length of output: 5333

src/main/resources/profile.yml (2)

1-1: LGTM!

The config-version update is approved as it reflects the changes made to the configuration schema.


175-183: LGTM!

The new fast-pcb-test-percentage configuration option is well-documented and provides a useful feature to quickly detect progress reset cheating by temporarily banning peers after they download a certain percentage of data.

The default value of 0.1 (10%) seems reasonable, and the ability to disable it by setting it to -1 provides flexibility.

src/main/resources/lang/zh_cn/messages.yml (3)

369-369: LGTM!

The code changes are approved.


370-370: LGTM, but please provide more context.

The localization message is correctly formatted.

However, it's unclear from the provided code what the "Peer 作弊快速测试" (Peer progress cheat quick test) rule does and how it fits into the overall functionality. Could you please provide more information about the purpose and behavior of this rule?


371-371: LGTM!

The code changes are approved. The message clearly communicates the temporary nature of the ban and the expected follow-up action to unban the peer.

src/main/resources/lang/messages_fallback.yml (1)

370-370: LGTM!

The new localized message string for the downloader statistics request failure scenario looks good.

src/main/resources/lang/en_us/messages.yml (3)

370-370: LGTM!

The code changes are approved.


371-371: LGTM!

The code changes are approved.


372-372: LGTM!

The code changes are approved.

Tools
yamllint

[error] 372-372: no new line character at the end of file

(new-line-at-end-of-file)

src/main/java/com/ghostchu/peerbanhelper/PeerBanHelperServer.java (3)

90-90: LGTM!

The addition of the banWaveLock is a good practice for managing concurrency during ban operations. It ensures that only one thread can execute the critical section at a time, preventing race conditions and inconsistent states.


Line range hint 470-483: LGTM!

The changes correctly handle the BAN and SILENT_BAN actions by:

  • Determining the actual ban duration.
  • Creating a BanMetadata object with the ban details.
  • Adding the BanMetadata to bannedPeers list.
  • Adding the torrent to relaunch list.
  • Calling banPeer method to ban the peer.
  • Logging a warning message only for non-silent bans.

The code is well-structured and follows the expected behavior.


766-768: LGTM!

The changes ensure that the result variable is updated with the current CheckResult when a BAN or SILENT_BAN action is encountered. This guarantees that the final result reflects the ban action if any module decides to ban the peer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants