mirror of
https://github.com/Simple-Tracker/qBittorrent-ClientBlocker.git
synced 2025-01-09 04:07:55 +08:00
Bug fix & Improve
This commit is contained in:
parent
660a1c5f05
commit
7aca091185
100
README.en.md
100
README.en.md
@ -109,64 +109,56 @@ A client blocker compatible with qBittorrent (4.1+)/Transmission (3.0+), which i
|
||||
|
||||
## 参数 Flag
|
||||
|
||||
| Parameter | Default | Note |
|
||||
| ----- | ----- | ----- |
|
||||
| -v/--version | false | Show program version and exit |
|
||||
| -c/--config | config.json | Config path |
|
||||
| -ca/--config_additional | config_additional.json | Additional config path |
|
||||
| --debug | false | Debug mode. Effective before loading config file |
|
||||
| --nochdir | false | Don't change working directory. Change to the program directory by default |
|
||||
|
||||
## 配置 Config
|
||||
|
||||
Docker version is configured through the same name variable configuration, which actually is implemented by automatically conversion environment variable as config file.
|
||||
|
||||
| Parameter | Default | Note |
|
||||
| ----- | ----- | ----- |
|
||||
| debug | false | Debug mode. Enable you can see more information, but it may disrupt the field of vision |
|
||||
| debug_CheckTorrent | false | Debug 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_CheckPeer | false | Debug mode (CheckPeer, must enable debug). If it's enabled, debug info will include each Torrent Peer, but the amount of information will be large |
|
||||
| interval | 6 (秒) | Ban Check Interval (Hot-reload is not supported). Each cycle interval will obtain relevant information from Web UI 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 |
|
||||
| cleanInterval | 3600 (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 |
|
||||
| updateInterval | 86400 (Sec) | List URL update interval (ipFilterURL/blockListURL). Reasonable intervals help improve update efficiency and reduce network usage |
|
||||
| torrentMapCleanInterval | 60 (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 |
|
||||
| banTime | 86400 (Sec) | Ban duration. Short interval will cause peer to be unblocked faster |
|
||||
| banAllPort | false | Block IP all port. Setting is currently not supported |
|
||||
| banIPCIDR | /32 | Block IPv4 CIDR. Used to expand Peer’s block IP range |
|
||||
| banIP6CIDR | /128 | Block IPv6 CIDR. Used to expand Peer’s block IP range |
|
||||
| ignoreEmptyPeer | true | Ignore peers without PeerID and UserAgent. Usually occurs on clients where connection is not fully established |
|
||||
| ignorePTTorrent | true | Ignore PT Torrent. If the main Tracker contains ```?passkey=```/```?authkey=```/```?secure=```/```A string of 32 digits consisting of uppercase and lowercase char or/and number``` |
|
||||
| startDelay | 0 (Sec, Disable) | Start delay. Special uses for some user |
|
||||
| sleepTime | 20 (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 |
|
||||
| timeout | 6 (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 |
|
||||
| longConnection | true | Long connection. Enable to reduce resource consumption |
|
||||
| logToFile | true | Log general information to file. If enabled, it can be used for general analysis and statistical purposes |
|
||||
| logDebug | false | Log 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 |
|
||||
| listen | :26262 | Listen port. Used to provide BlockPeerList to some client |
|
||||
| clientType | Empty | Client type. Prerequisite for using blocker, if client config file cannot be automatically detect, must be filled in correctly. Currently support ```qBittorrent```/```Transmission``` |
|
||||
| clientURL | Empty | Web UI or RPC 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``` |
|
||||
| clientUsername | Empty | Web UI 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 |
|
||||
| clientPassword | Empty | Web UI Password. If client "Skip local client authentication" is enabled, it can be left blank by default |
|
||||
| useBasicAuth | false | At the same time, authentication is performed through HTTP Basic Auth. It can be used to add/replace authentication method of Web UI through reverse proxy, etc |
|
||||
| skipCertVerification | false | Skip Web UI certificate verification. Suitable for self-signed and expired certificates |
|
||||
| blockList | Empty (Included in config.json) | Block client list. Judge PeerID or UserAgent at the same time, case-insensitive, support regular expression |
|
||||
| blockListURL | Empty | Block client list URL. Support format is same as blockList, one rule per line |
|
||||
| portBlockList | Empty | Block port list. If peer port matches any of ports, Peer will be automatically block |
|
||||
| ipBlockList | Empty | Block IP list. Support excluding ports IP (1.2.3.4) or IPCIDR (2.3.3.3/3) |
|
||||
| ipBlockListURL | Empty | Block IP list URL. Support format is same as ipBlockList, one rule per line |
|
||||
| ipUploadedCheck | false | IP upload incremental detection. After the following IP upload incremental conditions are met, Peer will be automatically block |
|
||||
| ipUpCheckInterval | 300 (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 |
|
||||
| ipUpCheckIncrementMB | 38000 (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 |
|
||||
| ipUpCheckPerTorrentRatio | 3 (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 |
|
||||
| maxIPPortCount | 0 (Disable) | Maximum number of ports per IP. If the number of IP ports is greater than the set value, Peer will be automatically block |
|
||||
| banByProgressUploaded | false | Enhanced 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 |
|
||||
| banByPUStartMB | 20 (MB) | Enhanced automatic blocking/Start size. If the client uploaded is greater than the set initial size, Peer will be automatically block |
|
||||
| banByPUStartPrecent | 2 (%) | Enhanced automatic blocking/Start progress. If the client upload progress is greater than the set start progress, Peer will be automatically block |
|
||||
| banByPUAntiErrorRatio | 3 (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 |
|
||||
| banByRelativeProgressUploaded | false | Enhanced 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 |
|
||||
| banByRelativePUStartMB | 20 (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 |
|
||||
| banByRelativePUStartPrecent | 2 (%) | 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 |
|
||||
| banByRelativePUAntiErrorRatio | 3 (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 |
|
||||
| Parameter | Type | Default | Note |
|
||||
| ----- | ----- | ----- | ----- |
|
||||
| debug | bool | false | Debug mode. Enable you can see more information, but it may disrupt the field of vision |
|
||||
| debug_CheckTorrent | string | false | Debug 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_CheckPeer | string | false | Debug mode (CheckPeer, must enable debug). If it's enabled, debug info will include each Torrent Peer, but the amount of information will be large |
|
||||
| interval | uint32 | 6 (秒) | Ban Check Interval (Hot-reload is not supported). Each cycle interval will obtain relevant information from Web UI 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 |
|
||||
| cleanInterval | uint32 | 3600 (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 |
|
||||
| updateInterval | uint32 | 86400 (Sec) | List URL update interval (ipFilterURL/blockListURL). Reasonable intervals help improve update efficiency and reduce network usage |
|
||||
| torrentMapCleanInterval | uint32 | 60 (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 |
|
||||
| banTime | uint32 | 86400 (Sec) | Ban duration. Short interval will cause peer to be unblocked faster |
|
||||
| banAllPort | bool | false | Block IP all port. Setting is currently not supported |
|
||||
| banIPCIDR | string | /32 | Block IPv4 CIDR. Used to expand Peer’s block IP range |
|
||||
| banIP6CIDR | string | /128 | Block IPv6 CIDR. Used to expand Peer’s block IP range |
|
||||
| ignoreEmptyPeer | bool | true | Ignore peers without PeerID and UserAgent. Usually occurs on clients where connection is not fully established |
|
||||
| ignorePTTorrent | bool | true | Ignore PT Torrent. If the main Tracker contains ```?passkey=```/```?authkey=```/```?secure=```/```A string of 32 digits consisting of uppercase and lowercase char or/and number``` |
|
||||
| startDelay | uint32 | 0 (Sec, Disable) | Start delay. Special uses for some user |
|
||||
| sleepTime | uint32 | 20 (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 |
|
||||
| timeout | uint32 | 6 (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 |
|
||||
| longConnection | bool | true | Long connection. Enable to reduce resource consumption |
|
||||
| logToFile | bool | true | Log general information to file. If enabled, it can be used for general analysis and statistical purposes |
|
||||
| logDebug | bool | false | Log 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 |
|
||||
| listen | string | :26262 | Listen port. Used to provide BlockPeerList to some client |
|
||||
| clientType | string | Empty | Client type. Prerequisite for using blocker, if client config file cannot be automatically detect, must be filled in correctly. Currently support ```qBittorrent```/```Transmission``` |
|
||||
| clientURL | string | Empty | Web UI or RPC 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``` |
|
||||
| clientUsername | string | Empty | Web UI 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 |
|
||||
| clientPassword | string | Empty | Web UI Password. If client "Skip local client authentication" is enabled, it can be left blank by default |
|
||||
| useBasicAuth | bool | false | At the same time, authentication is performed through HTTP Basic Auth. It can be used to add/replace authentication method of Web UI through reverse proxy, etc |
|
||||
| skipCertVerification | bool | false | Skip Web UI certificate verification. Suitable for self-signed and expired certificates |
|
||||
| blockList | []string | Empty (Included in config.json) | Block client list. Judge PeerID or UserAgent at the same time, case-insensitive, support regular expression |
|
||||
| blockListURL | string | Empty | Block client list URL. Support format is same as blockList, one rule per line |
|
||||
| portBlockList | []uint32 | Empty | Block port list. If peer port matches any of ports, Peer will be automatically block |
|
||||
| ipBlockList | []string | Empty | Block IP list. Support excluding ports IP (1.2.3.4) or IPCIDR (2.3.3.3/3) |
|
||||
| ipBlockListURL | string | Empty | Block IP list URL. Support format is same as ipBlockList, one rule per line |
|
||||
| ipUploadedCheck | bool | false | IP upload incremental detection. After the following IP upload incremental conditions are met, Peer will be automatically block |
|
||||
| ipUpCheckInterval | uint32 | 300 (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 |
|
||||
| ipUpCheckIncrementMB | uint32 | 38000 (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 |
|
||||
| ipUpCheckPerTorrentRatio | float64 | 3 (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 |
|
||||
| maxIPPortCount | uint32 | 0 (Disable) | Maximum number of ports per IP. If the number of IP ports is greater than the set value, Peer will be automatically block |
|
||||
| banByProgressUploaded | bool | false | Enhanced 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 |
|
||||
| banByPUStartMB | uint32 | 20 (MB) | Enhanced automatic blocking/Start size. If the client uploaded is greater than the set initial size, Peer will be automatically block |
|
||||
| banByPUStartPrecent | float64 | 2 (%) | Enhanced automatic blocking/Start progress. If the client upload progress is greater than the set start progress, Peer will be automatically block |
|
||||
| banByPUAntiErrorRatio | float64 | 3 (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 |
|
||||
| banByRelativeProgressUploaded | bool | false | Enhanced 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 |
|
||||
| banByRelativePUStartMB | uint32 | 20 (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 |
|
||||
| banByRelativePUStartPrecent | float64 | 2 (%) | 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 |
|
||||
| banByRelativePUAntiErrorRatio | float64 | 3 (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 |
|
||||
|
||||
## 反馈 Feedback
|
||||
User and developer can report bug through [Issue](https://github.com/Simple-Tracker/qBittorrent-ClientBlocker/issues), ask/discuss/share usage through [Discussion](https://github.com/Simple-Tracker/qBittorrent-ClientBlocker/discussions), contribute code improvement to blocker through [Pull Request](https://github.com/Simple-Tracker/qBittorrent-ClientBlocker/pulls).
|
||||
|
92
README.md
92
README.md
@ -124,52 +124,52 @@
|
||||
|
||||
Docker 版本通过相同名称的环境变量配置, 通过自动转换环境变量为配置文件实现.
|
||||
|
||||
| 设置项 | 默认值 | 配置说明 |
|
||||
| ----- | ----- | ----- |
|
||||
| debug | false (禁用) | 调试模式. 启用可看到更多信息, 但可能扰乱视野 |
|
||||
| debug_CheckTorrent | false (禁用) | 调试模式 (CheckTorrent, 须先启用 debug). 启用后调试信息会包括每个 Torrent Hash, 但信息量较大 |
|
||||
| debug_CheckPeer | false (禁用) | 调试模式 (CheckPeer, 须先启用 debug). 启用后调试信息会包括每个 Torrent Peer, 但信息量较大 |
|
||||
| interval | 6 (秒) | 屏蔽循环间隔 (不支持热重载). 每个循环间隔会从 Web UI 获取相关信息用于判断及屏蔽, 短间隔有助于降低封禁耗时但可能造成客户端卡顿, 长间隔有助于降低 CPU 资源占用 |
|
||||
| cleanInterval | 3600 (秒) | 屏蔽清理间隔. 短间隔会使过期 Peer 在达到屏蔽持续时间后更快被解除屏蔽, 长间隔有助于合并清理过期 Peer 日志 |
|
||||
| updateInterval | 86400 (秒) | 列表 URL 更新间隔 (ipFilterURL/blockListURL). 合理的间隔有助于提高更新效率并降低网络占用 |
|
||||
| torrentMapCleanInterval | 60 (秒) | Torrent Map 清理间隔 (启用 ipUploadedCheck+ipUpCheckPerTorrentRatio/banByRelativeProgressUploaded 后生效, 也是其判断间隔). 短间隔可使判断更频繁但可能造成滞后误判 |
|
||||
| banTime | 86400 (秒) | 屏蔽持续时间. 短间隔会使 Peer 更快被解除屏蔽 |
|
||||
| banAllPort | false (禁用) | 屏蔽 IP 所有端口. 当前不支持设置 |
|
||||
| banIPCIDR | /32 | 封禁 IPv4 CIDR. 可扩大单个 Peer 的封禁 IP 范围 |
|
||||
| banIP6CIDR | /128 | 封禁 IPv6 CIDR. 可扩大单个 Peer 的封禁 IP 范围 |
|
||||
| ignoreEmptyPeer | true (启用) | 忽略无 PeerID 及 UserAgent 的 Peer. 通常出现于连接未完全建立的客户端 |
|
||||
| ignorePTTorrent | true (启用) | 忽略 PT Torrent. 若主要 Tracker 包含 ```?passkey=```/```?authkey=```/```?secure=```/```32 位大小写英文及数字组成的字符串``` |
|
||||
| startDelay | 0 (秒, 禁用) | 启动延迟. 部分用户的特殊用途 |
|
||||
| sleepTime | 20 (毫秒) | 查询每个 Torrent Peers 的等待时间. 短间隔可使屏蔽 Peer 更快但可能造成客户端卡顿, 长间隔有助于平均 CPU 资源占用 |
|
||||
| timeout | 6 (秒) | 请求超时. 过短间隔可能会造成无法正确屏蔽 Peer, 过长间隔会使超时请求影响屏蔽其它 Peer 的性能 |
|
||||
| longConnection | true (启用) | 长连接. 启用可降低资源消耗 |
|
||||
| logToFile | true (启用) | 记录普通信息到日志. 启用后可用于一般的分析及统计用途 |
|
||||
| logDebug | false (禁用) | 记录调试信息到日志 (须先启用 debug 及 logToFile). 启用后可用于进阶的分析及统计用途, 但信息量较大 |
|
||||
| listen | :26262 | 监听端口. 用于向部分客户端提供 BlockPeerList |
|
||||
| clientType | 空 | 客户端类型. 使用客户端屏蔽器的前提条件, 若未能自动检测客户端类型, 则须正确填入. 目前支持 ```qBittorrent```/```Transmission``` |
|
||||
| clientURL | 空 | Web UI 或 RPC 地址. 使用客户端屏蔽器的前提条件, 若未能自动读取客户端配置文件, 则须正确填入. 前缀必须指定 http 或 https 协议, 如 ```http://127.0.0.1:990``` 或 ```http://127.0.0.1:9091/transmission/rpc```. |
|
||||
| clientUsername | 空 | Web UI 账号. 留空会跳过认证. 若启用客户端内 "跳过本机客户端认证" 可默认留空, 因可自动读取客户端配置文件并设置 |
|
||||
| clientPassword | 空 | Web UI 密码. 若启用客户端内 "跳过本机客户端认证" 可默认留空 |
|
||||
| useBasicAuth | false (禁用) | 同时通过 HTTP Basic Auth 进行认证. 适合只支持 Basic Auth 或通过反向代理等方式 增加/换用 认证方式的 Web UI |
|
||||
| skipCertVerification | false (禁用) | 跳过 Web UI 证书校验. 适合自签及过期证书 |
|
||||
| blockList | 空 (于 config.json 附带) | 屏蔽客户端列表. 同时判断 PeerID 及 UserAgent, 不区分大小写, 支持正则表达式 |
|
||||
| blockListURL | 空 | 屏蔽客户端列表 URL. 支持格式同 blockList, 一行一条 |
|
||||
| portBlockList | 空 | 屏蔽端口列表. 若 Peer 端口与列表内任意端口匹配, 则允许屏蔽 Peer |
|
||||
| ipBlockList | 空 | 屏蔽 IP 列表. 支持不包括端口的 IP (1.2.3.4) 及 IPCIDR (2.3.3.3/3) |
|
||||
| ipBlockListURL | 空 | 屏蔽 IP 列表 URL. 支持格式同 ipBlockList, 一行一条 |
|
||||
| ipUploadedCheck | false (禁用) | IP 上传增量检测. 在满足下列 IP 上传增量 条件后, 会自动屏蔽 Peer |
|
||||
| ipUpCheckInterval | 300 (秒) | IP 上传增量检测/检测间隔. 用于确定上一周期及当前周期, 以比对客户端对 IP 上传增量. 也顺便用于 maxIPPortCount |
|
||||
| ipUpCheckIncrementMB | 38000 (MB) | IP 上传增量检测/增量大小. 若 IP 全局上传增量大小大于设置增量大小, 则允许屏蔽 Peer |
|
||||
| ipUpCheckPerTorrentRatio | 3 (X) | IP 上传增量检测/增量倍率. 若 IP 单个 Torrent 上传增量大小大于设置增量倍率及 Torrent 大小之乘积, 则允许屏蔽 Peer |
|
||||
| maxIPPortCount | 0 (禁用) | 每 IP 最大端口数. 若 IP 端口数大于设置值, 会自动屏蔽 Peer |
|
||||
| banByProgressUploaded | false (禁用) | 增强自动屏蔽 (根据进度及上传量屏蔽 Peer, 未经测试验证). 在满足下列 增强自动屏蔽 条件后, 会自动屏蔽 Peer |
|
||||
| banByPUStartMB | 20 (MB) | 增强自动屏蔽/起始大小. 若客户端上传量大于起始大小, 则允许屏蔽 Peer |
|
||||
| banByPUStartPrecent | 2 (%) | 增强自动屏蔽/起始进度. 若客户端上传进度大于设置起始进度, 则允许屏蔽 Peer |
|
||||
| banByPUAntiErrorRatio | 3 (X) | 增强自动屏蔽/滞后防误判倍率. 若 Peer 报告下载进度与设置倍率及 Torrent 大小之乘积得到之下载量 比 客户端上传量 还低, 则允许屏蔽 Peer |
|
||||
| banByRelativeProgressUploaded | false (禁用) | 增强自动屏蔽_相对 (根据相对进度及相对上传量屏蔽 Peer, 未经测试验证). 在满足下列 增强自动屏蔽_相对 条件后, 会自动屏蔽 Peer |
|
||||
| banByRelativePUStartMB | 20 (MB) | 增强自动屏蔽_相对/起始大小. 若客户端相对上传量大于设置起始大小, 则允许屏蔽 Peer |
|
||||
| banByRelativePUStartPrecent | 2 (%) | 增强自动屏蔽_相对/起始进度. 若客户端相对上传进度大于设置起始进度, 则允许屏蔽 Peer |
|
||||
| banByRelativePUAntiErrorRatio | 3 (X) | 增强自动屏蔽_相对/滞后防误判倍率. 若 Peer 报告相对下载进度与设置倍率之乘积得到之相对下载进度 比 客户端相对上传进度 还低, 则允许屏蔽 Peer |
|
||||
| 设置项 | 类型 | 默认值 | 配置说明 |
|
||||
| ----- | ----- | ----- | ----- |
|
||||
| debug | bool | false (禁用) | 调试模式. 启用可看到更多信息, 但可能扰乱视野 |
|
||||
| debug_CheckTorrent | string | false (禁用) | 调试模式 (CheckTorrent, 须先启用 debug). 启用后调试信息会包括每个 Torrent Hash, 但信息量较大 |
|
||||
| debug_CheckPeer | string | false (禁用) | 调试模式 (CheckPeer, 须先启用 debug). 启用后调试信息会包括每个 Torrent Peer, 但信息量较大 |
|
||||
| interval | uint32 | 6 (秒) | 屏蔽循环间隔 (不支持热重载). 每个循环间隔会从 Web UI 获取相关信息用于判断及屏蔽, 短间隔有助于降低封禁耗时但可能造成客户端卡顿, 长间隔有助于降低 CPU 资源占用 |
|
||||
| cleanInterval | uint32 | 3600 (秒) | 屏蔽清理间隔. 短间隔会使过期 Peer 在达到屏蔽持续时间后更快被解除屏蔽, 长间隔有助于合并清理过期 Peer 日志 |
|
||||
| updateInterval | uint32 | 86400 (秒) | 列表 URL 更新间隔 (ipFilterURL/blockListURL). 合理的间隔有助于提高更新效率并降低网络占用 |
|
||||
| torrentMapCleanInterval | uint32 | 60 (秒) | Torrent Map 清理间隔 (启用 ipUploadedCheck+ipUpCheckPerTorrentRatio/banByRelativeProgressUploaded 后生效, 也是其判断间隔). 短间隔可使判断更频繁但可能造成滞后误判 |
|
||||
| banTime | uint32 | 86400 (秒) | 屏蔽持续时间. 短间隔会使 Peer 更快被解除屏蔽 |
|
||||
| banAllPort | bool | false (禁用) | 屏蔽 IP 所有端口. 当前不支持设置 |
|
||||
| banIPCIDR | string | /32 | 封禁 IPv4 CIDR. 可扩大单个 Peer 的封禁 IP 范围 |
|
||||
| banIP6CIDR | string | /128 | 封禁 IPv6 CIDR. 可扩大单个 Peer 的封禁 IP 范围 |
|
||||
| ignoreEmptyPeer | bool | true (启用) | 忽略无 PeerID 及 UserAgent 的 Peer. 通常出现于连接未完全建立的客户端 |
|
||||
| ignorePTTorrent | bool | true (启用) | 忽略 PT Torrent. 若主要 Tracker 包含 ```?passkey=```/```?authkey=```/```?secure=```/```32 位大小写英文及数字组成的字符串``` |
|
||||
| startDelay | uint32 | 0 (秒, 禁用) | 启动延迟. 部分用户的特殊用途 |
|
||||
| sleepTime | uint32 | 20 (毫秒) | 查询每个 Torrent Peers 的等待时间. 短间隔可使屏蔽 Peer 更快但可能造成客户端卡顿, 长间隔有助于平均 CPU 资源占用 |
|
||||
| timeout | uint32 | 6 (秒) | 请求超时. 过短间隔可能会造成无法正确屏蔽 Peer, 过长间隔会使超时请求影响屏蔽其它 Peer 的性能 |
|
||||
| longConnection | bool | true (启用) | 长连接. 启用可降低资源消耗 |
|
||||
| logToFile | bool | true (启用) | 记录普通信息到日志. 启用后可用于一般的分析及统计用途 |
|
||||
| logDebug | bool | false (禁用) | 记录调试信息到日志 (须先启用 debug 及 logToFile). 启用后可用于进阶的分析及统计用途, 但信息量较大 |
|
||||
| listen | string | :26262 | 监听端口. 用于向部分客户端提供 BlockPeerList |
|
||||
| clientType | string | 空 | 客户端类型. 使用客户端屏蔽器的前提条件, 若未能自动检测客户端类型, 则须正确填入. 目前支持 ```qBittorrent```/```Transmission``` |
|
||||
| clientURL | string | 空 | Web UI 或 RPC 地址. 使用客户端屏蔽器的前提条件, 若未能自动读取客户端配置文件, 则须正确填入. 前缀必须指定 http 或 https 协议, 如 ```http://127.0.0.1:990``` 或 ```http://127.0.0.1:9091/transmission/rpc```. |
|
||||
| clientUsername | string | 空 | Web UI 账号. 留空会跳过认证. 若启用客户端内 "跳过本机客户端认证" 可默认留空, 因可自动读取客户端配置文件并设置 |
|
||||
| clientPassword | string | 空 | Web UI 密码. 若启用客户端内 "跳过本机客户端认证" 可默认留空 |
|
||||
| useBasicAuth | bool | false (禁用) | 同时通过 HTTP Basic Auth 进行认证. 适合只支持 Basic Auth 或通过反向代理等方式 增加/换用 认证方式的 Web UI |
|
||||
| skipCertVerification | bool | false (禁用) | 跳过 Web UI 证书校验. 适合自签及过期证书 |
|
||||
| blockList | []string | 空 (于 config.json 附带) | 屏蔽客户端列表. 同时判断 PeerID 及 UserAgent, 不区分大小写, 支持正则表达式 |
|
||||
| blockListURL | string | 空 | 屏蔽客户端列表 URL. 支持格式同 blockList, 一行一条 |
|
||||
| portBlockList | []uint32 | 空 | 屏蔽端口列表. 若 Peer 端口与列表内任意端口匹配, 则允许屏蔽 Peer |
|
||||
| ipBlockList | []string | 空 | 屏蔽 IP 列表. 支持不包括端口的 IP (1.2.3.4) 及 IPCIDR (2.3.3.3/3) |
|
||||
| ipBlockListURL | string | 空 | 屏蔽 IP 列表 URL. 支持格式同 ipBlockList, 一行一条 |
|
||||
| ipUploadedCheck | bool | false (禁用) | IP 上传增量检测. 在满足下列 IP 上传增量 条件后, 会自动屏蔽 Peer |
|
||||
| ipUpCheckInterval | uint32 | 300 (秒) | IP 上传增量检测/检测间隔. 用于确定上一周期及当前周期, 以比对客户端对 IP 上传增量. 也顺便用于 maxIPPortCount |
|
||||
| ipUpCheckIncrementMB | uint32 | 38000 (MB) | IP 上传增量检测/增量大小. 若 IP 全局上传增量大小大于设置增量大小, 则允许屏蔽 Peer |
|
||||
| ipUpCheckPerTorrentRatio | float64 | 3 (X) | IP 上传增量检测/增量倍率. 若 IP 单个 Torrent 上传增量大小大于设置增量倍率及 Torrent 大小之乘积, 则允许屏蔽 Peer |
|
||||
| maxIPPortCount | uint32 | 0 (禁用) | 每 IP 最大端口数. 若 IP 端口数大于设置值, 会自动屏蔽 Peer |
|
||||
| banByProgressUploaded | bool | false (禁用) | 增强自动屏蔽 (根据进度及上传量屏蔽 Peer, 未经测试验证). 在满足下列 增强自动屏蔽 条件后, 会自动屏蔽 Peer |
|
||||
| banByPUStartMB | uint32 | 20 (MB) | 增强自动屏蔽/起始大小. 若客户端上传量大于起始大小, 则允许屏蔽 Peer |
|
||||
| banByPUStartPrecent | float64 | 2 (%) | 增强自动屏蔽/起始进度. 若客户端上传进度大于设置起始进度, 则允许屏蔽 Peer |
|
||||
| banByPUAntiErrorRatio | float64 | 3 (X) | 增强自动屏蔽/滞后防误判倍率. 若 Peer 报告下载进度与设置倍率及 Torrent 大小之乘积得到之下载量 比 客户端上传量 还低, 则允许屏蔽 Peer |
|
||||
| banByRelativeProgressUploaded | bool | false (禁用) | 增强自动屏蔽_相对 (根据相对进度及相对上传量屏蔽 Peer, 未经测试验证). 在满足下列 增强自动屏蔽_相对 条件后, 会自动屏蔽 Peer |
|
||||
| banByRelativePUStartMB | uint32 | 20 (MB) | 增强自动屏蔽_相对/起始大小. 若客户端相对上传量大于设置起始大小, 则允许屏蔽 Peer |
|
||||
| banByRelativePUStartPrecent | float64 | 2 (%) | 增强自动屏蔽_相对/起始进度. 若客户端相对上传进度大于设置起始进度, 则允许屏蔽 Peer |
|
||||
| banByRelativePUAntiErrorRatio | float64 | 3 (X) | 增强自动屏蔽_相对/滞后防误判倍率. 若 Peer 报告相对下载进度与设置倍率之乘积得到之相对下载进度 比 客户端相对上传进度 还低, 则允许屏蔽 Peer |
|
||||
|
||||
## 反馈 Feedback
|
||||
用户及开发者可以通过 [Issue](https://github.com/Simple-Tracker/qBittorrent-ClientBlocker/issues) 反馈 bug, 通过 [Discussion](https://github.com/Simple-Tracker/qBittorrent-ClientBlocker/discussions) 提问/讨论/分享 使用方法, 通过 [Pull Request](https://github.com/Simple-Tracker/qBittorrent-ClientBlocker/pulls) 向客户端屏蔽器贡献代码改进.
|
||||
|
@ -46,7 +46,7 @@ type ConfigStruct struct {
|
||||
SkipCertVerification bool
|
||||
BlockList []string
|
||||
BlockListURL string
|
||||
PortBlockList []int
|
||||
PortBlockList []uint32
|
||||
IPBlockList []string
|
||||
IPBlockListURL string
|
||||
IPUploadedCheck bool
|
||||
@ -131,7 +131,7 @@ var config = ConfigStruct {
|
||||
SkipCertVerification: false,
|
||||
BlockList: []string {},
|
||||
BlockListURL: "",
|
||||
PortBlockList: []int {},
|
||||
PortBlockList: []uint32 {},
|
||||
IPBlockList: []string {},
|
||||
IPBlockListURL: "",
|
||||
IPUploadedCheck: false,
|
||||
@ -176,7 +176,7 @@ func SetIPBlockListFromURL() bool {
|
||||
}
|
||||
|
||||
Log("Debug-SetIPBlockListFromURL_Compile", ":%d %s", false, ipBlockListLineNum, ipBlockListLine)
|
||||
cidr := ParseIP(ipBlockListLine)
|
||||
cidr := ParseIPCIDR(ipBlockListLine)
|
||||
if cidr == nil {
|
||||
Log("SetIPBlockListFromURL_Compile", GetLangText("Error-SetIPBlockListFromURL_Compile"), true, ipBlockListLineNum, ipBlockListLine)
|
||||
continue
|
||||
@ -392,7 +392,7 @@ func InitConfig() {
|
||||
for k, v := range config.IPBlockList {
|
||||
Log("Debug-LoadConfig_CompileIPBlockList", "%s", false, v)
|
||||
|
||||
cidr := ParseIP(v)
|
||||
cidr := ParseIPCIDR(v)
|
||||
if cidr == nil {
|
||||
Log("LoadConfig_CompileIPBlockList", GetLangText("Error-CompileIPBlockList"), true, v)
|
||||
continue
|
||||
|
23
console.go
23
console.go
@ -24,19 +24,20 @@ type ReleaseStruct struct {
|
||||
PreRelease bool `json:"prerelease`
|
||||
}
|
||||
|
||||
func ProcessVersion(version string) (int, int, int, int) {
|
||||
versionSplit := strings.SplitN(strings.SplitN(version, " ", 2)[0], ".", 2)
|
||||
func ProcessVersion(version string) (int, int, int, int, string) {
|
||||
version = strings.SplitN(version, " ", 2)[0]
|
||||
versionSplit := strings.SplitN(version, ".", 2)
|
||||
|
||||
if versionSplit[0] == "Unknown" || len(versionSplit) != 2 {
|
||||
return -1, 0, 0, 0
|
||||
return -1, 0, 0, 0, ""
|
||||
}
|
||||
|
||||
if strings.Contains(version, "(Nightly)") {
|
||||
return -2, 0, 0, 0
|
||||
return -2, 0, 0, 0, ""
|
||||
}
|
||||
|
||||
if strings.Contains(version, "-") {
|
||||
return -3, 0, 0, 0
|
||||
return -3, 0, 0, 0, ""
|
||||
}
|
||||
|
||||
mainVersion, err1 := strconv.Atoi(versionSplit[0])
|
||||
@ -61,10 +62,10 @@ func ProcessVersion(version string) (int, int, int, int) {
|
||||
sub2Version, err3 := strconv.Atoi(sub2VersionStr)
|
||||
|
||||
if err1 != nil || err2 != nil || err3 != nil {
|
||||
return -3, 0, 0, 0
|
||||
return -3, 0, 0, 0, ""
|
||||
}
|
||||
|
||||
return versionType, mainVersion, subVersion, sub2Version
|
||||
return versionType, mainVersion, subVersion, sub2Version, version
|
||||
}
|
||||
func CheckUpdate() {
|
||||
if (lastCheckUpdateTimestamp + 86400) > currentTimestamp {
|
||||
@ -73,7 +74,7 @@ func CheckUpdate() {
|
||||
|
||||
lastCheckUpdateTimestamp = currentTimestamp
|
||||
|
||||
currentVersionType, currentMainVersion, currentSubVersion, currentSub2Version := ProcessVersion(programVersion)
|
||||
currentVersionType, currentMainVersion, currentSubVersion, currentSub2Version, currentVersion := ProcessVersion(programVersion)
|
||||
|
||||
if currentVersionType == -1 {
|
||||
Log("CheckUpdate", GetLangText("CheckUpdate-Ignore_UnknownVersion"), false)
|
||||
@ -130,7 +131,7 @@ func CheckUpdate() {
|
||||
hasNewPreReleaseVersion := false
|
||||
|
||||
if matchLatestReleaseVersion {
|
||||
versionType, mainVersion, subVersion, sub2Version := ProcessVersion(latestReleaseStruct.TagName)
|
||||
versionType, mainVersion, subVersion, sub2Version, _ := ProcessVersion(latestReleaseStruct.TagName)
|
||||
|
||||
if versionType == 0 {
|
||||
if mainVersion > currentMainVersion {
|
||||
@ -146,7 +147,7 @@ func CheckUpdate() {
|
||||
}
|
||||
|
||||
if matchLatestPreReleaseVersion {
|
||||
versionType, mainVersion, subVersion, sub2Version := ProcessVersion(latestPreReleaseStruct.TagName)
|
||||
versionType, mainVersion, subVersion, sub2Version, _ := ProcessVersion(latestPreReleaseStruct.TagName)
|
||||
|
||||
if versionType == 1 {
|
||||
if versionType == currentVersionType {
|
||||
@ -163,7 +164,7 @@ func CheckUpdate() {
|
||||
}
|
||||
}
|
||||
|
||||
Log("CheckUpdate", GetLangText("CheckUpdate-ShowVersion"), true, programVersion, latestReleaseStruct.TagName, latestPreReleaseStruct.TagName)
|
||||
Log("CheckUpdate", GetLangText("CheckUpdate-ShowVersion"), true, currentVersion, latestReleaseStruct.TagName, latestPreReleaseStruct.TagName)
|
||||
|
||||
if hasNewReleaseVersion {
|
||||
Log("CheckUpdate", GetLangText("CheckUpdate-DetectNewVersion"), true, latestReleaseStruct.TagName, strings.Replace(latestReleaseStruct.Body, "\r", "", -1))
|
||||
|
40
ip.go
40
ip.go
@ -3,6 +3,7 @@ package main
|
||||
import "net"
|
||||
|
||||
type IPInfoStruct struct {
|
||||
Net *net.IPNet
|
||||
Port map[int]bool
|
||||
TorrentUploaded map[string]int64
|
||||
}
|
||||
@ -15,13 +16,14 @@ var ipMap = make(map[string]IPInfoStruct)
|
||||
var lastIPMap = make(map[string]IPInfoStruct)
|
||||
var lastIPCleanTimestamp int64 = 0
|
||||
|
||||
func AddIPInfo(peerIP string, peerPort int, torrentInfoHash string, peerUploaded int64) {
|
||||
func AddIPInfo(cidr *net.IPNet, peerIP string, peerPort int, torrentInfoHash string, peerUploaded int64) {
|
||||
if !(config.MaxIPPortCount > 0 || (config.IPUploadedCheck && config.IPUpCheckIncrementMB > 0)) {
|
||||
return
|
||||
}
|
||||
|
||||
var clientPortMap map[int]bool
|
||||
var clientTorrentUploadedMap map[string]int64
|
||||
|
||||
if info, exist := ipMap[peerIP]; !exist {
|
||||
clientPortMap = make(map[int]bool)
|
||||
clientTorrentUploadedMap = make(map[string]int64)
|
||||
@ -37,7 +39,7 @@ func AddIPInfo(peerIP string, peerPort int, torrentInfoHash string, peerUploaded
|
||||
clientTorrentUploadedMap[torrentInfoHash] += peerUploaded
|
||||
}
|
||||
|
||||
ipMap[peerIP] = IPInfoStruct { Port: clientPortMap, TorrentUploaded: clientTorrentUploadedMap }
|
||||
ipMap[peerIP] = IPInfoStruct { Net: cidr, Port: clientPortMap, TorrentUploaded: clientTorrentUploadedMap }
|
||||
}
|
||||
func IsIPTooHighUploaded(ipInfo IPInfoStruct, lastIPInfo IPInfoStruct) int64 {
|
||||
var totalUploaded int64 = 0
|
||||
@ -61,30 +63,18 @@ func IsIPTooHighUploaded(ipInfo IPInfoStruct, lastIPInfo IPInfoStruct) int64 {
|
||||
|
||||
return 0
|
||||
}
|
||||
func IsMatchCIDR(ip string) string {
|
||||
cidr := ""
|
||||
func IsMatchCIDR(ip string) (bool, *net.IPNet) {
|
||||
peerNet := ParseIPCIDRByConfig(ip)
|
||||
|
||||
if IsIPv6(ip) {
|
||||
if config.BanIP6CIDR != "/128" {
|
||||
cidr = config.BanIP6CIDR
|
||||
}
|
||||
} else {
|
||||
if config.BanIPCIDR != "/32" {
|
||||
cidr = config.BanIPCIDR
|
||||
if peerNet != nil {
|
||||
peerNetStr := peerNet.String()
|
||||
if _, exist := blockCIDRMap[peerNetStr]; exist {
|
||||
return true, peerNet
|
||||
}
|
||||
return false, peerNet
|
||||
}
|
||||
|
||||
if cidr != "" {
|
||||
peerNet := ParseIP(ip + cidr)
|
||||
if peerNet != nil {
|
||||
peerNetStr := peerNet.String()
|
||||
if _, exist := blockCIDRMap[peerNetStr]; exist {
|
||||
return peerNetStr
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
return false, nil
|
||||
}
|
||||
func CheckAllIP(ipMap map[string]IPInfoStruct, lastIPMap map[string]IPInfoStruct) int {
|
||||
if (config.MaxIPPortCount > 0 || (config.IPUploadedCheck && config.IPUpCheckIncrementMB > 0)) && len(lastIPMap) > 0 && currentTimestamp > (lastIPCleanTimestamp + int64(config.IPUpCheckInterval)) {
|
||||
@ -105,6 +95,9 @@ func CheckAllIP(ipMap map[string]IPInfoStruct, lastIPMap map[string]IPInfoStruct
|
||||
if config.MaxIPPortCount > 0 {
|
||||
if len(ipInfo.Port) > int(config.MaxIPPortCount) {
|
||||
Log("CheckAllIP_AddBlockPeer (Too many ports)", "%s:%d", true, ip, -1)
|
||||
if ipInfo.Net != nil {
|
||||
blockCIDRMap[ipInfo.Net.String()] = BlockCIDRInfoStruct { Timestamp: currentTimestamp, Net: ipInfo.Net }
|
||||
}
|
||||
ipBlockCount++
|
||||
AddBlockPeer(ip, -1, "")
|
||||
continue
|
||||
@ -114,6 +107,9 @@ func CheckAllIP(ipMap map[string]IPInfoStruct, lastIPMap map[string]IPInfoStruct
|
||||
if lastIPInfo, exist := lastIPMap[ip]; exist {
|
||||
if uploadDuring := IsIPTooHighUploaded(ipInfo, lastIPInfo); uploadDuring > 0 {
|
||||
Log("CheckAllIP_AddBlockPeer (Global-Too high uploaded)", "%s:%d (UploadDuring: %.2f MB)", true, ip, -1, uploadDuring)
|
||||
if ipInfo.Net != nil {
|
||||
blockCIDRMap[ipInfo.Net.String()] = BlockCIDRInfoStruct { Timestamp: currentTimestamp, Net: ipInfo.Net }
|
||||
}
|
||||
ipBlockCount++
|
||||
AddBlockPeer(ip, -1, "")
|
||||
}
|
||||
|
95
peer.go
95
peer.go
@ -6,6 +6,7 @@ import (
|
||||
)
|
||||
|
||||
type PeerInfoStruct struct {
|
||||
Net *net.IPNet
|
||||
Port map[int]bool
|
||||
Progress float64
|
||||
Uploaded int64
|
||||
@ -31,23 +32,10 @@ func AddBlockPeer(peerIP string, peerPort int, torrentInfoHash string) {
|
||||
blockPeerPortMap[peerPort] = true
|
||||
blockPeerMap[peerIP] = BlockPeerInfoStruct { Timestamp: currentTimestamp, Port: blockPeerPortMap, InfoHash: torrentInfoHash }
|
||||
|
||||
cidr := ""
|
||||
if IsIPv6(peerIP) {
|
||||
if config.BanIP6CIDR != "/128" {
|
||||
cidr = config.BanIP6CIDR
|
||||
}
|
||||
} else {
|
||||
if config.BanIPCIDR != "/32" {
|
||||
cidr = config.BanIPCIDR
|
||||
}
|
||||
}
|
||||
|
||||
if cidr != "" {
|
||||
peerNet := ParseIP(peerIP + cidr)
|
||||
if peerNet != nil {
|
||||
peerNetStr := peerNet.String()
|
||||
blockCIDRMap[peerNetStr] = BlockCIDRInfoStruct { Timestamp: currentTimestamp, Net: peerNet }
|
||||
}
|
||||
peerNet := ParseIPCIDRByConfig(peerIP)
|
||||
if peerNet != nil {
|
||||
peerNetStr := peerNet.String()
|
||||
blockCIDRMap[peerNetStr] = BlockCIDRInfoStruct { Timestamp: currentTimestamp, Net: peerNet }
|
||||
}
|
||||
}
|
||||
func ClearBlockPeer() int {
|
||||
@ -58,29 +46,17 @@ func ClearBlockPeer() int {
|
||||
cleanCount++
|
||||
delete(blockPeerMap, clientIP)
|
||||
|
||||
cidr := ""
|
||||
if IsIPv6(clientIP) {
|
||||
if config.BanIP6CIDR != "/128" {
|
||||
cidr = config.BanIP6CIDR
|
||||
}
|
||||
} else {
|
||||
if config.BanIPCIDR != "/32" {
|
||||
cidr = config.BanIPCIDR
|
||||
}
|
||||
}
|
||||
peerNet := ParseIPCIDRByConfig(clientIP)
|
||||
|
||||
if cidr != "" {
|
||||
peerNet := ParseIP(clientIP + cidr)
|
||||
if peerNet != nil {
|
||||
peerNetStr := peerNet.String()
|
||||
if blockCIDRInfo, exist := blockCIDRMap[peerNetStr]; exist {
|
||||
if blockCIDRInfo.Timestamp > currentTimestamp {
|
||||
clientInfo.Timestamp = blockCIDRInfo.Timestamp
|
||||
blockPeerMap[clientIP] = clientInfo
|
||||
continue
|
||||
}
|
||||
delete(blockCIDRMap, peerNetStr)
|
||||
if peerNet != nil {
|
||||
peerNetStr := peerNet.String()
|
||||
if blockCIDRInfo, exist := blockCIDRMap[peerNetStr]; exist {
|
||||
if blockCIDRInfo.Timestamp > currentTimestamp {
|
||||
clientInfo.Timestamp = blockCIDRInfo.Timestamp
|
||||
blockPeerMap[clientIP] = clientInfo
|
||||
continue
|
||||
}
|
||||
delete(blockCIDRMap, peerNetStr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -113,9 +89,9 @@ func IsBlockedPeer(peerIP string, peerPort int, updateTimestamp bool) bool {
|
||||
|
||||
return false
|
||||
}
|
||||
func CheckPeer(peerIP string, peerPort int, peerID string, peerClient string, peerProgress float64, peerUploaded int64, torrentInfoHash string, torrentTotalSize int64) int {
|
||||
func CheckPeer(peerIP string, peerPort int, peerID string, peerClient string, peerProgress float64, peerUploaded int64, torrentInfoHash string, torrentTotalSize int64) (int, *net.IPNet) {
|
||||
if peerIP == "" || CheckPrivateIP(peerIP) {
|
||||
return -1
|
||||
return -1, nil
|
||||
}
|
||||
|
||||
if IsBlockedPeer(peerIP, peerPort, true) {
|
||||
@ -126,24 +102,24 @@ func CheckPeer(peerIP string, peerPort int, peerID string, peerClient string, pe
|
||||
}
|
||||
*/
|
||||
if peerPort == -1 {
|
||||
return 3
|
||||
return 3, nil
|
||||
}
|
||||
return 2
|
||||
return 2, nil
|
||||
}
|
||||
|
||||
for port := range config.PortBlockList {
|
||||
if port == peerPort {
|
||||
Log("CheckPeer_AddBlockPeer (Bad-Port)", "%s:%d %s|%s (TorrentInfoHash: %s)", true, peerIP, peerPort, strconv.QuoteToASCII(peerID), strconv.QuoteToASCII(peerClient), torrentInfoHash)
|
||||
AddBlockPeer(peerIP, peerPort, torrentInfoHash)
|
||||
return 1
|
||||
return 1, nil
|
||||
}
|
||||
}
|
||||
|
||||
peerNetStr := IsMatchCIDR(peerIP)
|
||||
if peerNetStr != "" {
|
||||
Log("CheckPeer_AddBlockPeer (Bad-CIDR)", "%s:%d %s|%s (TorrentInfoHash: %s, Net: %s)", true, peerIP, peerPort, strconv.QuoteToASCII(peerID), strconv.QuoteToASCII(peerClient), torrentInfoHash, peerNetStr)
|
||||
matchCIDR, peerNet := IsMatchCIDR(peerIP)
|
||||
if matchCIDR {
|
||||
Log("CheckPeer_AddBlockPeer (Bad-CIDR)", "%s:%d %s|%s (TorrentInfoHash: %s, Net: %s)", true, peerIP, peerPort, strconv.QuoteToASCII(peerID), strconv.QuoteToASCII(peerClient), torrentInfoHash, peerNet.String())
|
||||
AddBlockPeer(peerIP, peerPort, torrentInfoHash)
|
||||
return 1
|
||||
return 1, peerNet
|
||||
}
|
||||
|
||||
hasPeerClient := (peerID != "" || peerClient != "")
|
||||
@ -151,7 +127,7 @@ func CheckPeer(peerIP string, peerPort int, peerID string, peerClient string, pe
|
||||
if (!config.IgnoreEmptyPeer || hasPeerClient) && IsProgressNotMatchUploaded(torrentTotalSize, peerProgress, peerUploaded) {
|
||||
Log("CheckPeer_AddBlockPeer (Bad-Progress_Uploaded)", "%s:%d %s|%s (TorrentInfoHash: %s, TorrentTotalSize: %.2f MB, Progress: %.2f%%, Uploaded: %.2f MB)", true, peerIP, peerPort, strconv.QuoteToASCII(peerID), strconv.QuoteToASCII(peerClient), torrentInfoHash, (float64(torrentTotalSize) / 1024 / 1024), (peerProgress * 100), (float64(peerUploaded) / 1024 / 1024))
|
||||
AddBlockPeer(peerIP, peerPort, torrentInfoHash)
|
||||
return 1
|
||||
return 1, peerNet
|
||||
}
|
||||
|
||||
if hasPeerClient {
|
||||
@ -162,7 +138,7 @@ func CheckPeer(peerIP string, peerPort int, peerID string, peerClient string, pe
|
||||
if (peerClient != "" && v.MatchString(peerClient)) || (peerID != "" && v.MatchString(peerID)) {
|
||||
Log("CheckPeer_AddBlockPeer (Bad-Client_Normal)", "%s:%d %s|%s (TorrentInfoHash: %s)", true, peerIP, peerPort, strconv.QuoteToASCII(peerID), strconv.QuoteToASCII(peerClient), torrentInfoHash)
|
||||
AddBlockPeer(peerIP, peerPort, torrentInfoHash)
|
||||
return 1
|
||||
return 1, peerNet
|
||||
}
|
||||
}
|
||||
for _, v := range blockListFromURLCompiled {
|
||||
@ -172,7 +148,7 @@ func CheckPeer(peerIP string, peerPort int, peerID string, peerClient string, pe
|
||||
if (peerClient != "" && v.MatchString(peerClient)) || (peerID != "" && v.MatchString(peerID)) {
|
||||
Log("CheckPeer_AddBlockPeer (Bad-Client_List)", "%s:%d %s|%s (TorrentInfoHash: %s)", true, peerIP, peerPort, strconv.QuoteToASCII(peerID), strconv.QuoteToASCII(peerClient), torrentInfoHash)
|
||||
AddBlockPeer(peerIP, peerPort, torrentInfoHash)
|
||||
return 1
|
||||
return 1, peerNet
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -188,7 +164,7 @@ func CheckPeer(peerIP string, peerPort int, peerID string, peerClient string, pe
|
||||
if v.Contains(ip) {
|
||||
Log("CheckPeer_AddBlockPeer (Bad-IP_Normal)", "%s:%d %s|%s (TorrentInfoHash: %s)", true, peerIP, -1, strconv.QuoteToASCII(peerID), strconv.QuoteToASCII(peerClient), torrentInfoHash)
|
||||
AddBlockPeer(peerIP, -1, torrentInfoHash)
|
||||
return 3
|
||||
return 3, peerNet
|
||||
}
|
||||
}
|
||||
for _, v := range ipBlockListFromURLCompiled {
|
||||
@ -198,20 +174,20 @@ func CheckPeer(peerIP string, peerPort int, peerID string, peerClient string, pe
|
||||
if v.Contains(ip) {
|
||||
Log("CheckPeer_AddBlockPeer (Bad-IP_Filter)", "%s:%d %s|%s (TorrentInfoHash: %s)", true, peerIP, -1, strconv.QuoteToASCII(peerID), strconv.QuoteToASCII(peerClient), torrentInfoHash)
|
||||
AddBlockPeer(peerIP, -1, torrentInfoHash)
|
||||
return 3
|
||||
return 3, peerNet
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (config.IgnoreEmptyPeer && !hasPeerClient) {
|
||||
return -2
|
||||
return -2, peerNet
|
||||
}
|
||||
|
||||
return 0
|
||||
return 0, peerNet
|
||||
}
|
||||
func ProcessPeer(peerIP string, peerPort int, peerID string, peerClient string, peerProgress float64, peerUploaded int64, torrentInfoHash string, torrentTotalSize int64, blockCount *int, ipBlockCount *int, badPeersCount *int, emptyPeersCount *int) {
|
||||
peerIP = ProcessIP(peerIP)
|
||||
peerStatus := CheckPeer(peerIP, peerPort, peerID, peerClient, peerProgress, peerUploaded, torrentInfoHash, torrentTotalSize)
|
||||
peerStatus, peerNet := CheckPeer(peerIP, peerPort, peerID, peerClient, peerProgress, peerUploaded, torrentInfoHash, torrentTotalSize)
|
||||
if config.Debug_CheckPeer {
|
||||
Log("Debug-CheckPeer", "%s:%d %s|%s (Status: %d)", false, peerIP, peerPort, strconv.QuoteToASCII(peerID), strconv.QuoteToASCII(peerClient), peerStatus)
|
||||
}
|
||||
@ -226,7 +202,12 @@ func ProcessPeer(peerIP string, peerPort int, peerID string, peerClient string,
|
||||
case -2:
|
||||
*emptyPeersCount++
|
||||
case 0:
|
||||
AddIPInfo(peerIP, peerPort, torrentInfoHash, peerUploaded)
|
||||
AddTorrentInfo(torrentInfoHash, torrentTotalSize, peerIP, peerPort, peerProgress, peerUploaded)
|
||||
if peerNet == nil {
|
||||
AddIPInfo(nil, peerIP, peerPort, torrentInfoHash, peerUploaded)
|
||||
AddTorrentInfo(torrentInfoHash, torrentTotalSize, nil, peerIP, peerPort, peerProgress, peerUploaded)
|
||||
} else {
|
||||
AddIPInfo(peerNet, peerNet.String(), peerPort, torrentInfoHash, peerUploaded)
|
||||
AddTorrentInfo(torrentInfoHash, torrentTotalSize, peerNet, peerNet.String(), peerPort, peerProgress, peerUploaded)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
14
torrent.go
14
torrent.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
"strings"
|
||||
)
|
||||
@ -14,7 +15,7 @@ var torrentMap = make(map[string]TorrentInfoStruct)
|
||||
var lastTorrentMap = make(map[string]TorrentInfoStruct)
|
||||
var lastTorrentCleanTimestamp int64 = 0
|
||||
|
||||
func AddTorrentInfo(torrentInfoHash string, torrentTotalSize int64, peerIP string, peerPort int, peerProgress float64, peerUploaded int64) {
|
||||
func AddTorrentInfo(torrentInfoHash string, torrentTotalSize int64, cidr *net.IPNet, peerIP string, peerPort int, peerProgress float64, peerUploaded int64) {
|
||||
if !((config.IPUploadedCheck && config.IPUpCheckPerTorrentRatio > 0) || config.BanByRelativeProgressUploaded) {
|
||||
return
|
||||
}
|
||||
@ -39,7 +40,7 @@ func AddTorrentInfo(torrentInfoHash string, torrentTotalSize int64, peerIP strin
|
||||
}
|
||||
peerPortMap[peerPort] = true
|
||||
|
||||
peers[peerIP] = PeerInfoStruct { Port: peerPortMap, Progress: peerProgress, Uploaded: peerUploaded }
|
||||
peers[peerIP] = PeerInfoStruct { Net: cidr, Port: peerPortMap, Progress: peerProgress, Uploaded: peerUploaded }
|
||||
torrentMap[torrentInfoHash] = TorrentInfoStruct { Size: torrentTotalSize, Peers: peers }
|
||||
}
|
||||
func IsProgressNotMatchUploaded(torrentTotalSize int64, clientProgress float64, clientUploaded int64) bool {
|
||||
@ -93,15 +94,15 @@ func CheckAllTorrent(torrentMap map[string]TorrentInfoStruct, lastTorrentMap map
|
||||
|
||||
for torrentInfoHash, torrentInfo := range torrentMap {
|
||||
for peerIP, peerInfo := range torrentInfo.Peers {
|
||||
peerIP = ProcessIP(peerIP)
|
||||
|
||||
if IsBlockedPeer(peerIP, -1, true) {
|
||||
continue
|
||||
}
|
||||
|
||||
if config.IPUploadedCheck && config.IPUpCheckPerTorrentRatio > 0 {
|
||||
if float64(peerInfo.Uploaded) > (float64(torrentInfo.Size) * peerInfo.Progress * config.IPUpCheckPerTorrentRatio) {
|
||||
Log("CheckAllTorrent_AddBlockPeer (PerTorrent-Too high uploaded)", "%s:%d (TorrentSize: %.2f MB, Uploaded: %.2f MB)", true, peerIP, -1, (float64(torrentInfo.Size) / 1024 / 1024), (float64(peerInfo.Uploaded) / 1024 / 1024))
|
||||
if peerInfo.Net != nil {
|
||||
blockCIDRMap[peerInfo.Net.String()] = BlockCIDRInfoStruct { Timestamp: currentTimestamp, Net: peerInfo.Net }
|
||||
}
|
||||
ipBlockCount++
|
||||
AddBlockPeer(peerIP, -1, torrentInfoHash)
|
||||
continue
|
||||
@ -115,6 +116,9 @@ func CheckAllTorrent(torrentMap map[string]TorrentInfoStruct, lastTorrentMap map
|
||||
if IsBlockedPeer(peerIP, port, true) {
|
||||
continue
|
||||
}
|
||||
if peerInfo.Net != nil {
|
||||
blockCIDRMap[peerInfo.Net.String()] = BlockCIDRInfoStruct { Timestamp: currentTimestamp, Net: peerInfo.Net }
|
||||
}
|
||||
blockCount++
|
||||
Log("CheckAllTorrent_AddBlockPeer (Bad-Relative_Progress_Uploaded)", "%s:%d (UploadDuring: %.2f MB)", true, peerIP, port, uploadDuring)
|
||||
AddBlockPeer(peerIP, port, torrentInfoHash)
|
||||
|
27
util.go
27
util.go
@ -45,7 +45,7 @@ func CheckPrivateIP(ip string) bool {
|
||||
}
|
||||
return ipParsed.IsPrivate()
|
||||
}
|
||||
func ParseIP(ip string) *net.IPNet {
|
||||
func ParseIPCIDR(ip string) *net.IPNet {
|
||||
if !strings.Contains(ip, "/") {
|
||||
if IsIPv6(ip) {
|
||||
ip += "/128"
|
||||
@ -61,6 +61,31 @@ func ParseIP(ip string) *net.IPNet {
|
||||
|
||||
return cidr
|
||||
}
|
||||
func ParseIPCIDRByConfig(ip string) *net.IPNet {
|
||||
cidr := ""
|
||||
|
||||
if IsIPv6(ip) {
|
||||
if config.BanIP6CIDR != "/128" {
|
||||
cidr = config.BanIP6CIDR
|
||||
}
|
||||
} else {
|
||||
if config.BanIPCIDR != "/32" {
|
||||
cidr = config.BanIPCIDR
|
||||
}
|
||||
}
|
||||
|
||||
if cidr == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
cidrNet := ParseIPCIDR(ip + cidr)
|
||||
|
||||
if cidrNet == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return cidrNet
|
||||
}
|
||||
func ProcessIP(ip string) string {
|
||||
ip = strings.ToLower(ip)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user