Skip to content

Commit

Permalink
Add IgnoreFailureExit
Browse files Browse the repository at this point in the history
  • Loading branch information
Simple-Tracker committed Aug 27, 2024
1 parent 2e7b86c commit b37446e
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
1 change: 1 addition & 0 deletions README.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Docker version is configured through the same name variable configuration, which
| ignoreEmptyPeer | bool | true | Ignore peers without PeerID and ClientName. Usually occurs on clients where connection is not fully established |
| ignoreNoLeechersTorrent | bool | false | Ignore torrent without leechers. Enabling may improve performance, but may cause inaccuracies with some clients (such as qBittorrent) |
| 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``` |
| ignoreFailureExit | bool | false | Ignore failure exit. If enabled, it will continue to retry after first detection of the client fails or authentication fails |
| 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 |
| proxy | string | Auto | Use proxy. Set to empty to disable this behavior but still automatically detect proxy on first load |
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ Docker 版本通过相同名称的环境变量配置, 通过自动转换环境
| ignoreEmptyPeer | bool | true (启用) | 忽略无 PeerID 及 ClientName 的 Peer. 通常出现于连接未完全建立的客户端 |
| ignoreNoLeechersTorrent | bool | false (禁用) | 忽略没有下载者的 Torrent. 启用后有助于提高性能, 但部分客户端 (如 qBittorrent) 可能会出现不准确的问题 |
| ignorePTTorrent | bool | true (启用) | 忽略 PT Torrent. 若主要 Tracker 包含 ```?passkey=```/```?authkey=```/```?secure=```/```32 位大小写英文及数字组成的字符串``` |
| ignoreFailureExit | bool | false (禁用) | 忽略失败退出. 启用后会使得首次检测客户端失败或认证失败后继续重试 |
| sleepTime | uint32 | 20 (毫秒) | 查询每个 Torrent Peers 的等待时间. 短间隔可使屏蔽 Peer 更快但可能造成客户端卡顿, 长间隔有助于平均 CPU 资源占用 |
| timeout | uint32 | 6 (秒) | 请求超时. 过短间隔可能会造成无法正确屏蔽 Peer, 过长间隔会使超时请求影响屏蔽其它 Peer 的性能 |
| proxy | string | Auto (自动) | 使用代理. 设置为空可以禁止此行为, 但仍会在首次加载配置文件时自动检测代理 |
Expand Down
14 changes: 9 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type ConfigStruct struct {
IgnoreEmptyPeer bool
IgnoreNoLeechersTorrent bool
IgnorePTTorrent bool
IgnoreFailureExit bool
SleepTime uint32
Timeout uint32
Proxy string
Expand Down Expand Up @@ -148,6 +149,7 @@ var config = ConfigStruct{
IgnoreEmptyPeer: true,
IgnoreNoLeechersTorrent: false,
IgnorePTTorrent: true,
IgnoreFailureExit: false,
SleepTime: 20,
Timeout: 6,
Proxy: "Auto",
Expand Down Expand Up @@ -541,8 +543,6 @@ func InitConfig() {
}
}
func LoadInitConfig(firstLoad bool) bool {
lastURL = config.ClientURL

loadConfigStatus := LoadConfig(configFilename, true)

if loadConfigStatus < -1 {
Expand Down Expand Up @@ -570,11 +570,15 @@ func LoadInitConfig(firstLoad bool) bool {

if config.ClientURL != "" {
if lastURL != config.ClientURL {
DetectClient()
InitClient()
if firstLoad && !Login() {
if !DetectClient() {
Log("LoadInitConfig", GetLangText("LoadInitConfig_DetectClientFailed"), true)
return false
}
if !Login() {
Log("LoadInitConfig", GetLangText("LoadInitConfig_AuthFailed"), true)
return false
}
InitClient()
SubmitBlockPeer(nil)
lastURL = config.ClientURL
}
Expand Down
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"ignoreEmptyPeer": true,
"ignoreNoLeechersTorrent": true,
"ignorePTTorrent": true,
"ignoreAuthFailed": false,
"sleepTime": 20,
"proxy": "Auto",
"longConnection": true,
Expand Down
14 changes: 8 additions & 6 deletions console.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,11 @@ func RunConsole() {
time.Sleep(time.Duration(startDelay) * time.Second)
}

if !LoadInitConfig(true) {
Log("RunConsole", GetLangText("RunConsole_AuthFailed"), true)
for !LoadInitConfig(true) {
time.Sleep(2 * time.Second)
os.Exit(1)
if !config.IgnoreFailureExit {
os.Exit(1)
}
}

isRunning = true
Expand Down Expand Up @@ -390,10 +391,11 @@ func RunConsole() {
tmpCurrentTimestamp := time.Now().Unix()
if (currentTimestamp + int64(config.Interval)) <= tmpCurrentTimestamp {
currentTimestamp = tmpCurrentTimestamp
LoadInitConfig(false)
go CheckUpdate()
Task()
GC()
if LoadInitConfig(false) {
Task()
GC()
}
}
}
}
3 changes: 2 additions & 1 deletion i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ var defaultLangContent = map[string]string{
"HideWindow": "默认隐藏窗口 (仅 Windows)",
"HideSystray": "默认隐藏托盘图标 (仅 Windows)",
"RunConsole_StartDelay": "启动延迟: %d 秒",
"RunConsole_AuthFailed": "认证失败",
"RunConsole_ProgramHasStarted": "程序已启动",
"LoadInitConfig_DetectClientFailed": "检测客户端失败",
"LoadInitConfig_AuthFailed": "认证失败",
"Task_BanInfo": "此次封禁客户端: %d 个, 当前封禁客户端: %d 个",
"Task_BanInfoWithIP": "此次封禁客户端: %d 个, 此次封禁 IP: %d 个, 当前封禁 IP 及客户端: %d 个",
"GC_IPMap": "触发垃圾回收 (ipMap): %d",
Expand Down
3 changes: 2 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
"HideWindow": "Hide window by default (Only Windows)",
"HideSystray": "Hide systray by default (Only Windows)",
"RunConsole_StartDelay": "Start delay: %d Sec",
"RunConsole_AuthFailed": "Authentication failed",
"RunConsole_ProgramHasStarted": "Program has started",
"LoadInitConfig_DetectClientFailed": "Detect client failed",
"LoadInitConfig_AuthFailed": "Authentication failed",
"Task_BanInfo": "Ban Client (This time): %d, Ban Client (Current): %d",
"Task_BanInfoWithIP": "Ban Client (This time): %d, Ban IP (This time): %d, Ban IP/Client (Current): %d",
"GC_IPMap": "Trigger GC (ipMap): %d",
Expand Down

0 comments on commit b37446e

Please sign in to comment.