mirror of
https://github.com/isboyjc/GoProxy.git
synced 2026-05-07 08:02:58 +08:00
feat: ✨ enhance proxy validation logic and update configuration parameters
- Added detailed rejection counts for proxies based on exit IP, latency, geo-blocking, and pool capacity. - Updated latency thresholds in configuration for improved performance. - Revised README to reflect changes in latency settings and added capacity limitation notes.
This commit is contained in:
25
README.md
25
README.md
@@ -417,24 +417,33 @@ proxies = {'http': 'http://myuser:secure_pass_123@server-ip:7777', 'https': '...
|
||||
|
||||
| 参数 | 默认值 | 说明 | 推荐范围 |
|
||||
| --- | --- | --- | --- |
|
||||
| `pool_max_size` | `100` | 代理池总容量 | 50-500 |
|
||||
| `pool_max_size` | `100` | 代理池总容量 | 50-150 ⚠️ |
|
||||
| `pool_http_ratio` | `0.5` | HTTP 协议占比 | 0.3-0.8 |
|
||||
| `pool_min_per_protocol` | `10` | 每协议最少保证数量 | 5-50 |
|
||||
|
||||
**延迟标准配置**
|
||||
> ⚠️ **容量限制说明**:公开代理源质量有限,验证通过率通常只有 1-3%。受地理过滤、延迟标准、出口检测等因素影响,**实际填充率约为 70-90%**。如设置 150 容量,实际可能稳定在 105-135 个。建议根据实际需求设置合理容量。
|
||||
|
||||
**延迟标准配置** ⚡
|
||||
|
||||
| 参数 | 默认值 | 说明 | 推荐范围 |
|
||||
| --- | --- | --- | --- |
|
||||
| `max_latency_ms` | `2000` | 标准模式最大延迟(毫秒) | 1000-3000 |
|
||||
| `max_latency_healthy` | `1500` | 健康模式严格延迟(毫秒) | 800-2000 |
|
||||
| `max_latency_emergency` | `3000` | 紧急模式放宽延迟(毫秒) | 2000-5000 |
|
||||
| `max_latency_ms` | `2500` | 标准模式最大延迟(毫秒) | 2000-3500 |
|
||||
| `max_latency_healthy` | `2000` | 健康模式严格延迟(毫秒) | 1500-2500 |
|
||||
| `max_latency_emergency` | `4000` | 紧急/补充模式放宽延迟(毫秒) | 3000-5000 |
|
||||
|
||||
**验证与健康检查配置**
|
||||
> 💡 **状态与延迟**:`emergency/critical/warning` 状态下使用 `max_latency_emergency`(4000ms),`healthy` 状态使用 `max_latency_healthy`(2000ms)。这确保在池子容量不足时能快速补充。
|
||||
|
||||
**验证配置**
|
||||
|
||||
| 参数 | 默认值 | 说明 | 推荐范围 |
|
||||
| --- | --- | --- | --- |
|
||||
| `validate_concurrency` | `300` | 验证并发数 | 200-500 |
|
||||
| `validate_timeout` | `10` | 验证超时(秒) | 8-15 |
|
||||
|
||||
**健康检查配置**
|
||||
|
||||
| 参数 | 默认值 | 说明 | 推荐范围 |
|
||||
| --- | --- | --- | --- |
|
||||
| `validate_concurrency` | `300` | 并发验证数量 | 100-500 |
|
||||
| `validate_timeout` | `8` | 验证超时(秒) | 5-15 |
|
||||
| `health_check_interval` | `5` | 检查间隔(分钟) | 3-15 |
|
||||
| `health_check_batch_size` | `20` | 每批检查数量 | 10-50 |
|
||||
|
||||
|
||||
@@ -155,14 +155,14 @@ func DefaultConfig() *Config {
|
||||
PoolMinPerProtocol: 10, // 每协议最少10个
|
||||
|
||||
// 延迟标准配置
|
||||
MaxLatencyMs: 2000, // 标准2秒
|
||||
MaxLatencyEmergency: 3000, // 紧急3秒
|
||||
MaxLatencyHealthy: 1500, // 健康1.5秒
|
||||
MaxLatencyMs: 2500, // 标准2.5秒
|
||||
MaxLatencyEmergency: 4000, // 紧急4秒
|
||||
MaxLatencyHealthy: 2000, // 健康2秒
|
||||
MaxLatencyDegradation: 5000, // 降级5秒
|
||||
|
||||
// 验证配置
|
||||
ValidateConcurrency: 300,
|
||||
ValidateTimeout: 8,
|
||||
ValidateTimeout: 10, // 从8秒增加到10秒
|
||||
ValidateURL: "http://www.gstatic.com/generate_204",
|
||||
|
||||
// 健康检查配置
|
||||
@@ -350,7 +350,8 @@ func (c *Config) GetLatencyThreshold(poolStatus string) int {
|
||||
case "critical":
|
||||
return c.MaxLatencyEmergency
|
||||
case "warning":
|
||||
return c.MaxLatencyMs
|
||||
// warning状态使用紧急标准,加快填充速度
|
||||
return c.MaxLatencyEmergency
|
||||
case "healthy":
|
||||
return c.MaxLatencyHealthy
|
||||
default:
|
||||
|
||||
31
main.go
31
main.go
@@ -159,6 +159,10 @@ func smartFetchAndFill(fetch *fetcher.Fetcher, validate *validator.Validator, st
|
||||
// 严格验证并尝试入池
|
||||
addedCount := 0
|
||||
validCount := 0
|
||||
rejectedNoExit := 0
|
||||
rejectedLatency := 0
|
||||
rejectedGeo := 0
|
||||
rejectedFull := 0
|
||||
|
||||
for result := range validate.ValidateStream(candidates) {
|
||||
if !result.Valid {
|
||||
@@ -172,8 +176,15 @@ func smartFetchAndFill(fetch *fetcher.Fetcher, validate *validator.Validator, st
|
||||
cfg := config.Get()
|
||||
maxLatency := cfg.GetLatencyThreshold(status.State)
|
||||
|
||||
// 必须满足:有出口IP、有位置、延迟达标
|
||||
if result.ExitIP == "" || result.ExitLocation == "" || latencyMs > maxLatency {
|
||||
// 检查:有出口IP、有位置
|
||||
if result.ExitIP == "" || result.ExitLocation == "" {
|
||||
rejectedNoExit++
|
||||
continue
|
||||
}
|
||||
|
||||
// 检查:延迟达标
|
||||
if latencyMs > maxLatency {
|
||||
rejectedLatency++
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -186,8 +197,19 @@ func smartFetchAndFill(fetch *fetcher.Fetcher, validate *validator.Validator, st
|
||||
Latency: latencyMs,
|
||||
}
|
||||
|
||||
if added, _ := poolMgr.TryAddProxy(proxyToAdd); added {
|
||||
if added, reason := poolMgr.TryAddProxy(proxyToAdd); added {
|
||||
addedCount++
|
||||
} else if reason == "slots_full" {
|
||||
rejectedFull++
|
||||
} else if len(result.ExitLocation) >= 2 {
|
||||
// 检查是否被地理过滤
|
||||
countryCode := result.ExitLocation[:2]
|
||||
for _, blocked := range cfg.BlockedCountries {
|
||||
if countryCode == blocked {
|
||||
rejectedGeo++
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果是紧急模式且已达到最小要求,停止验证
|
||||
@@ -208,8 +230,9 @@ func smartFetchAndFill(fetch *fetcher.Fetcher, validate *validator.Validator, st
|
||||
|
||||
// 最终状态
|
||||
finalStatus, _ := poolMgr.GetStatus()
|
||||
log.Printf("[main] 填充完成: 验证%d 通过%d 入池%d | 最终状态: %s HTTP=%d SOCKS5=%d",
|
||||
log.Printf("[main] 填充完成: 验证%d 通过%d 入池%d | 拒绝[无出口:%d 延迟:%d 地理:%d 满:%d] | 最终: %s HTTP=%d SOCKS5=%d",
|
||||
len(candidates), validCount, addedCount,
|
||||
rejectedNoExit, rejectedLatency, rejectedGeo, rejectedFull,
|
||||
finalStatus.State, finalStatus.HTTP, finalStatus.SOCKS5)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user