Categorygithub.com/Simple-Tracker/qBittorrent-ClientBlocker
modulepackage
0.0.0-20241026154627-1da13359e0a0
Repository: https://github.com/simple-tracker/qbittorrent-clientblocker.git
Documentation: pkg.go.dev

# README

qBittorrent-ClientBlocker

中文 (默认, Beta 版本) English (Default, Beta Version)
中文 (Public 正式版) English (Public version)

A client blocker compatible with qBittorrent (4.1+)/Transmission (3.0+, Beta)/BitComet (2.0+, Beta, Partial), which is prohibited to include but not limited to clients such as Xunlei.

  • Support many platforms
  • Support log and hot-reload config
  • Support ignore private ip
  • Support custom blockList (Case-Inensitive, Support regular expression)
  • Supports a variety of clients and their authentication, and can automatically detect some clients (Currently supports qBittorrent. Errors that occur when detecting clients can be ignored)
  • Support enhanced automatic ban (Default disable): Automatically ban peer based on the default or set related parameter
  • Under Windows, support show and hide window through systray or window hotkey (Ctrl+Alt+B) (Some users feedback it may affect ban. Due to unknown reason, the function can be avoided if related problem are encountered)

Usually, occasional errors can be ignored. The reasons may be: 1. Network problems; 2. Client timeout; 3. Transmission periodically rotates CSRF Token; ...

Preview

使用 Usage

Prerequisite

  • Client Web UI must be enabled.

Use conventional version

  1. Download compressed from GitHub Release and decompress it;

    View common platform download version of comparison table
    OSProcessor ArchProcessor IntegersDownload VersionNote
    macOSARM6464-bitdarwin-arm64Common in Apple M series
    macOSAMD6464-bitdarwin-amd64Common in Intel series
    WindowsAMD6464-bitwindows-amd64Common in most modern PC
    Windowsi38632-bitwindows-386Occasionally on some old PC
    WindowsARM6464-bitwindows-arm64Common on new platform, it's applied to some tablet/notebooks/minority special hardware
    WindowsARMv632-bitwindows-armRare platform, applied to some ancient hardware, such as Surface RT, etc
    LinuxAMD6464-bitlinux-amd64Common NAS and server
    Linuxi38632-bitlinux-386Rarely in some old NAS and server
    LinuxARM6464-bitlinux-arm64Common server and development board, such as Oracle or Raspberry Pi, etc
    LinuxARMv*32-bitlinux-armv*Rarely in some old server and development board, Check /proc/cpuinfo or try which version can run from high to low

    Other versions of Linux/Netbsd/FreeBSD/OpenBSD/Solaris can use this form as an example, and select one that suits you in the list.

  2. After decompression, you may need to modify the attached config file config.json;

    • You can set config according to high-level needs. See 配置 Config.
    • If blocker runs on this machine, but client "Skip client certification" is disabled (and password is not empty and does not manually set password in blocker), you must modify config file and fill in clientPassword.
    • If blocker is not running on this machine or client is not installed on the default path or using blocker with 2.4 and below version, config file must be modified and fills in clientURL/clientUsername/clientPassword.
  3. Start blocker and observe whether the information output is normal;

    For Windows, you can choose shortcut of client, put your own blocker path, and run client and blocker at the same time;

    qBittorrent: C:\Windows\System32\cmd.exe /c "(tasklist | findstr qBittorrent-ClientBlocker || start C:\Users\Example\qBittorrent-ClientBlocker\qBittorrent-ClientBlocker.exe) && start qbittorrent.exe"

    For macOS, You can choose a basic LaunchAgent for starting from OS start and background run;

    For Linux, You can choose a basic Systemd service for starting from OS start and background run;

Use Docker version

  • Pull image from Docker Hub.

    docker pull simpletracker/qbittorrent-clientblocker:latest
    
  • Configuration method 1: Use config file mapping

    1. Create a new config.json in right location, as a configuration file, the specific config can refer config.json and 配置 Config;

    2. Fills in clientURL/clientUsername/clientPassword;

      • You can set config according to high-level needs. See 配置 Config.
      • If client "IP subnet whitelist" is enabled, you don't need fill in clientUsername and clientPassword.
    3. Run docker image and view log to observe whether the information output is normal;

      The following command templates are used as a reference only, please replace /path/config.json to your config path.

      docker run -d \
          --name=qbittorrent-clientblocker --network=bridge --restart unless-stopped \
          -v /path/config.json:/app/config.json \
          simpletracker/qbittorrent-clientblocker:latest
      
  • Configuration method 1: Use environment variable

    • Prerequisite: Set the useENV environment variable is true.

    • Use environment variables to configure settings on demand. For details, see 配置 Config.

    • If config is complicated, blockList may not take effect. Therefore, if you need to configure this setting, it's not recommended to use environment variable.

    • The following command templates are used as a reference only.

      docker run -d \
          --name=qbittorrent-clientblocker --network=bridge --restart unless-stopped \
          -e useENV=true \
          -e debug=false \
          -e logPath=logs \
          -e blockList='["ExampleBlockList1", "ExampleBlockList2"]' \
          -e clientURL=http://example.com \
          -e clientUsername=exampleUser \
          -e clientPassword=examplePass \
          simpletracker/qbittorrent-clientblocker:latest
      

参数 Flag

ParameterDefaultNote
-v/--versionfalseShow program version and exit
-c/--configconfig.jsonConfig path
-ca/--config_additionalconfig_additional.jsonAdditional config path
--debugfalseDebug mode. Effective before loading config file
--startdelay0 (Sec, Disable)Start delay. Special uses for some user
--nochdirfalseDon't change working directory. Change to the program directory by default
--hidewindowfalseHide window by default. Only available on Windows
--hidesystrayfalseHide systray by default. Only available on Windows

配置 Config

Docker version is configured through the same name variable configuration, which actually is implemented by automatically conversion environment variable as config file.

ParameterTypeDefaultNote
checkUpdatebooltrueCheck update. Automatically checks for update by default
debugboolfalseDebug mode. Enable you can see more information, but it may disrupt the field of vision
debug_CheckTorrentstringfalseDebug mode (CheckTorrent, must enable debug). If it's enabled, debug info will include each Torrent Hash, but the amount of information will be large
debug_CheckPeerstringfalseDebug mode (CheckPeer, must enable debug). If it's enabled, debug info will include each Torrent Peer, but the amount of information will be large
intervaluint326 (秒)Ban Check Interval (Hot-reload is not supported). Each cycle interval will obtain relevant information from backend for judgment and blocking. Short interval can help reduce ban time but may cause client to freeze, but Long interval can help reduce CPU usage
cleanIntervaluint323600 (Sec)Clean blocked peer interval. Short interval will cause expired Peer to be unblocked faster after blocking duration is reached, but Long interval will help merge and clean up expired Peer log
updateIntervaluint3286400 (Sec)List URL update interval (blockListURL/ipBlockListURL). Reasonable intervals help improve update efficiency and reduce network usage
restartIntervaluint326 (Sec)Restart Torrent interval. This is a measure to solve the problem that the blocklist of some clients (Transmission) cannot be effective. It is implemented by restarting Torrent. Too short an interval may cause the blocking to be ineffective
torrentMapCleanIntervaluint3260 (Sec)Torrent Map Clean Interval (Only useful after enable ipUploadedCheck+ipUpCheckPerTorrentRatio/banByRelativeProgressUploaded, It's also the judgment interval). Short interval can make judgments more frequent but may cause delayed misjudgments
banTimeuint3286400 (Sec)Ban duration. Short interval will cause peer to be unblocked faster
banAllPortbooltrueBlock IP all port. Enabled by default and setting is not currently supported
banIPCIDRstring/32Block IPv4 CIDR. Used to expand Peer’s block IP range
banIP6CIDRstring/128Block IPv6 CIDR. Used to expand Peer’s block IP range
ignoreEmptyPeerbooltrueIgnore peers without PeerID and ClientName. Usually occurs on clients where connection is not fully established
ignoreNoLeechersTorrentboolfalseIgnore torrent without leechers. Enabling may improve performance, but may cause inaccuracies with some clients (such as qBittorrent)
ignorePTTorrentbooltrueIgnore PT Torrent. If the main Tracker contains ?passkey=/?authkey=/?secure=/A string of 32 digits consisting of uppercase and lowercase char or/and number
ignoreFailureExitboolfalseIgnore failure exit. If enabled, it will continue to retry after first detection of the client fails or authentication fails
sleepTimeuint3220 (MicroSec)Query waiting time of each Torrent Peers. Short interval can make blocking Peer faster but may cause client lag, Long interval can help average CPU usage
timeoutuint326 (MillSec)Request timeout. If interval is too short, peer may not be properly blocked. If interval is too long, timeout request will affect blocking other peer
proxystringAutoUse proxy. Still automatically detect proxy on first load. Empty: Disable proxy; Auto: Automatic (use proxy only for external requests); All: Use proxy for all requests
longConnectionbooltrueLong connection. Enable to reduce resource consumption
logPathstringlogsLog path. Must enable logToFile
logToFilebooltrueLog general information to file. If enabled, it can be used for general analysis and statistical purposes
logDebugboolfalseLog debug information to file (Must enable debug and logToFile). If enabled, it can be used for advanced analysis and statistical purposes, but the amount of information is large
listenstring127.0.0.1:26262Listen port. Used to provide BlockPeerList to some client (Transmission). For non-localhost, you can change to <Host>:<Port>
clientTypestringEmptyClient type. Available Web API or RPC address. Prerequisite for using blocker, if client config file cannot be automatically detect, must be filled in correctly. Currently support qBittorrent/Transmission/BitComet
clientURLstringEmptyClient address. Prerequisite for using blocker, if client config file cannot be automatically read, must be filled in correctly. Prefix must specify http or https protocol, such as http://127.0.0.1:990 or http://127.0.0.1:9091/transmission/rpc
clientUsernamestringEmptyClient username. Leaving it blank will skip authentication. If you enable client "Skip local client authentication", you can leave it blank by default, because the client config file can be automatically read and set
clientPasswordstringEmptyClient password. If client "Skip local client authentication" is enabled, it can be left blank by default
useBasicAuthboolfalseAlso authenticates via HxTTP Basic Auth. Suitable for backend that only support Basic Auth (such as Transmission/BitComet) or add/change authentication methods via reverse proxy, etc
useShadowBanbooltrueUse ShadowBan API to ban peer. Only works with clients that support ShadowBan API (such as qBEE). If the relevant API is not available when loading the configuration, it will be automatically disabled
skipCertVerificationboolfalseSkip Web API certificate verification. Suitable for self-signed and expired certificates
fetchFailedThresholdint0 (Disable)Maximum number of fetch failures. When set number is exceeded, execCommand_FetchFailed will be executed
execCommand_FetchFailedstringEmptyExecute external command (FetchFailed). First parameter is regarded as an external program path, execute the command when number of fetch failures exceeds set threshold
execCommand_RunstringEmptyExecute external command (Run). First parameter is regarded as an external program path, execute the command when program starts
execCommand_BanstringEmptyExecute external command (Ban). First parameter is regarded as an external program path, and each parameter should be separated by |, command can use {peerIP}/{peerPort}/{torrentInfoHash} to use related info (peerPort=-1 means ban all port)
execCommand_BanstringEmptyExecute external command (Ban). First parameter is regarded as an external program path, and each parameter should be separated by |, command can use {peerIP}/{peerPort}/{torrentInfoHash} to use related info (peerPort=-1 means ban all port)
execCommand_UnbanstringEmptyExecute external command (Unban). First parameter is regarded as an external program path, and each parameter should be separated by |, command can use {peerIP}/{peerPort}/{torrentInfoHash} to use related info (peerPort=-1 means ban all port)
syncServerURLstringEmptySync server URL. Sync server will submit TorrentMap to server and receive BlockIPCIDR from server
syncServerTokenstringEmptySync server Token. Some sync server may require authentication
blockList[]stringEmpty (Included in config.json)Block client list. Judge PeerID or ClientName at the same time, case-insensitive, support regular expression
blockListURL[]stringEmptyBlock client list URL. Support format is same as blockList, one rule per line
blockListFile[]stringEmptyBlock client list File. Support format is same as blockList, one rule per line
portBlockList[]uint32EmptyBlock port list. If peer port matches any of ports, Peer will be automatically block
ipBlockList[]stringEmptyBlock IP list. Support excluding ports IP (1.2.3.4) or IPCIDR (2.3.3.3/3)
ipBlockListURL[]stringEmptyBlock IP list URL. Support format is same as ipBlockList, one rule per line
ipBlockListFile[]stringEmptyBlock IP list File. Support format is same as ipBlockList, one rule per line
genIPDatuint320 (Disable)1: Generate IPBlockList.dat. Include All Peer IPCIDR, support format is same as ipBlockList; 2: Generate IPFilter.dat. Include All Peer IP; One rule per line
ipUploadedCheckboolfalseIP upload incremental detection. After the following IP upload incremental conditions are met, Peer will be automatically block
ipUpCheckIntervaluint32300 (Sec)IP upload incremental detection/Interval. Used to determine the previous cycle and the current cycle to compare Peer's IP upload increment. It is also used for maxIPPortCount
ipUpCheckIncrementMBuint3238000 (MB)IP upload incremental detection/Increment size. If the IP global upload increment size is greater than the set increment size, Peer will be automatically block
ipUpCheckPerTorrentRatiofloat643 (X)IP upload incremental detection/Increment ratio. If the IP single torrent upload increment size is greater than the product of the set increment ratio and the torrent size, Peer will be automatically block
maxIPPortCountuint320 (Disable)Maximum number of ports per IP. If the number of IP ports is greater than the set value, Peer will be automatically block
banByProgressUploadedboolfalseEnhanced automatic blocking (blocking Peer based on progress and uploaded, not verified by testing). After the following enhanced automatic blocking conditions are met, Peer will be automatically blocked
banByPUStartMBuint3220 (MB)Enhanced automatic blocking/Start size. If the client uploaded is greater than the set initial size, Peer will be automatically block
banByPUStartPrecentfloat642 (%)Enhanced automatic blocking/Start progress. If the client upload progress is greater than the set start progress, Peer will be automatically block
banByPUAntiErrorRatiofloat643 (X)Enhanced automatic blocking/Lag anti-misjudgment ratio. If the downloaded obtained by the Peer's reported download progress multiplied by the set ratio and the torrent size is lower than Peer's uploaded, Peer will be automatically block
banByRelativeProgressUploadedboolfalseEnhanced automatic blocking_Relative (Block Peer based on relative progress and relative uploaded, not verified by testing). After the following Enhanced automatic blocking_Relative conditions are met, Peer will be automatically block
banByRelativePUStartMBuint3220 (MB)Enhanced automatic blocking_Relative/Start size. If the relative uploaded of the client is greater than the set start size, Peer will be automatically block
banByRelativePUStartPrecentfloat642 (%)Enhanced automatic blocking_Relative/Start progress. If the relative upload progress of the client is greater than the set start progress, Peer will be automatically block
banByRelativePUAntiErrorRatiofloat643 (X)Enhanced automatic blocking_Relative/Lag anti-misjudgment ratio. If the relative download progress obtained by the product of the relative download progress reported by the peer and the set ratio is lower than the relative upload progress of the client, Peer will be automatically block
ignoreByDownloadeduint32100 (MB)Enhanced automatic blocking*/Max downloaded. If downloaded from Peer is greater than this value, enhanced automatic blocking will be skipped

反馈 Feedback

User and developer can report bug through Issue, ask/discuss/share usage through Discussion, contribute code improvement to blocker through Pull Request.
Note: Should be based on dev branch. When opening a Pull Request for a Feature, please do not create an Issue simultaneously.

致谢 Credit

  1. We partially referenced jinliming2/qbittorrent-ban-xunlei during early development of blocker. We may also refer to other similar project to optimize this project, but they will not be listed separately here;
  2. We will thank the user and developer who contributed code improvement to blocker through Pull Request in Release Note;

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Source: https://stackoverflow.com/questions/51459083/deep-copying-maps-in-golang.
No description provided by the author
No description provided by the author
No description provided by the author
EraseSyncMap is a helper function to erase all elements in a sync.Map.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
重复判断 nil 是因为输出的类型转换 (qB_MainDataStruct -> interface{}) 会导致 nil 比较失效.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author