feat(proxy): 增加代理池演练并修复账号密码提取,发布 0.5.1
This commit is contained in:
@@ -2,7 +2,8 @@
|
|||||||
import { computed, nextTick, ref } from 'vue'
|
import { computed, nextTick, ref } from 'vue'
|
||||||
import { useSettings, type RetryStage } from '@/composables/useSettings'
|
import { useSettings, type RetryStage } from '@/composables/useSettings'
|
||||||
import { useToast } from '@/composables/useToast'
|
import { useToast } from '@/composables/useToast'
|
||||||
import { TestProxy, FetchProxy } from '@wails/go/app/App'
|
import { TestProxy, FetchProxy, RunProxyDrill } from '@wails/go/app/App'
|
||||||
|
import { types } from '@wails/go/models'
|
||||||
|
|
||||||
const { settings, loadSettings, saveSettings } = useSettings()
|
const { settings, loadSettings, saveSettings } = useSettings()
|
||||||
const { showToast } = useToast()
|
const { showToast } = useToast()
|
||||||
@@ -36,6 +37,9 @@ const formData = ref({
|
|||||||
const testingProxy = ref(false)
|
const testingProxy = ref(false)
|
||||||
const testProxyResult = ref<{ success?: boolean; text?: string; error?: string } | null>(null)
|
const testProxyResult = ref<{ success?: boolean; text?: string; error?: string } | null>(null)
|
||||||
const fetchingProxy = ref(false)
|
const fetchingProxy = ref(false)
|
||||||
|
const drillAccounts = ref(30)
|
||||||
|
const drillRunning = ref(false)
|
||||||
|
const drillResult = ref<types.ProxyDrillResult | null>(null)
|
||||||
|
|
||||||
const proxyOverviewTitle = computed(() => (
|
const proxyOverviewTitle = computed(() => (
|
||||||
formData.value.proxyEnabled ? '代理已启用' : '代理未启用'
|
formData.value.proxyEnabled ? '代理已启用' : '代理未启用'
|
||||||
@@ -127,6 +131,32 @@ const handleFetchProxy = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleProxyDrill = async () => {
|
||||||
|
if (!formData.value.proxyApi.trim()) {
|
||||||
|
showToast('无法演练', '请先填写代理提取 API', 'error')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
drillRunning.value = true
|
||||||
|
drillResult.value = null
|
||||||
|
try {
|
||||||
|
const saved = await saveSettings(formData.value)
|
||||||
|
if (!saved) return
|
||||||
|
const res = await RunProxyDrill(types.ProxyDrillRequest.createFrom({
|
||||||
|
simulatedAccounts: drillAccounts.value
|
||||||
|
}))
|
||||||
|
drillResult.value = res
|
||||||
|
if (res.success) {
|
||||||
|
showToast('演练通过', `活动代理 ${res.healthyActive}/${res.activeCount},备用代理 ${res.healthyStandby}/${res.standbyCount}`, 'success', 5000)
|
||||||
|
} else {
|
||||||
|
showToast('演练未通过', res.error || '部分活动代理未通过业务请求验证', 'error', 6000)
|
||||||
|
}
|
||||||
|
} catch (e: any) {
|
||||||
|
showToast('演练失败', e.message || String(e), 'error')
|
||||||
|
} finally {
|
||||||
|
drillRunning.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const open = async (section = '') => {
|
const open = async (section = '') => {
|
||||||
await loadSettings()
|
await loadSettings()
|
||||||
formData.value = {
|
formData.value = {
|
||||||
@@ -134,6 +164,7 @@ const open = async (section = '') => {
|
|||||||
retryStages: settings.value.retryStages.map(s => ({ ...s }))
|
retryStages: settings.value.retryStages.map(s => ({ ...s }))
|
||||||
}
|
}
|
||||||
testProxyResult.value = null
|
testProxyResult.value = null
|
||||||
|
drillResult.value = null
|
||||||
visible.value = true
|
visible.value = true
|
||||||
if (section === 'proxy') {
|
if (section === 'proxy') {
|
||||||
await nextTick()
|
await nextTick()
|
||||||
@@ -301,7 +332,7 @@ defineExpose({ open, close })
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-hint">
|
<div class="form-hint">
|
||||||
品赞会自动识别并请求当前分组所需数量;账号密码模式请生成带 mode=auth 的 API,账号密码会写入代理 URL。注意:账号密码授权仍需先将执行提取的本机 IP 加入品赞白名单,白名单只用于提取 API。
|
品赞会自动识别并请求当前分组所需数量;账号密码模式请生成带 mode=auth 的 API,程序会自动改用 JSON 以取得每个代理的账号密码。账号密码授权仍需先将执行提取的本机 IP 加入品赞白名单,白名单只用于提取 API。
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -312,7 +343,79 @@ defineExpose({ open, close })
|
|||||||
<span class="checkbox-text">定时抢购触发前 30 秒自动预取并校验代理</span>
|
<span class="checkbox-text">定时抢购触发前 30 秒自动预取并校验代理</span>
|
||||||
</label>
|
</label>
|
||||||
<div class="form-hint">
|
<div class="form-hint">
|
||||||
仅对定时抢购生效。按“每组账号数”提取对应数量,先测斗鱼时间接口再启用;立即抢购会在开始前同步准备代理。建议使用 10 分钟以上时长,覆盖抢购与最长 180 秒支付。
|
仅对定时抢购生效。按“每组账号数”提取对应数量并校验;立即抢购会在开始前同步准备代理。建议使用 10 分钟以上时长,覆盖抢购与最长 180 秒支付。
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="proxy-drill">
|
||||||
|
<div class="proxy-drill-head">
|
||||||
|
<div>
|
||||||
|
<div class="proxy-drill-title">代理池演练</div>
|
||||||
|
<div class="form-hint">
|
||||||
|
手册活动使用只读商品接口,和平小店使用轻量接口兜底;不读取 CK,不锁单、不支付、不消耗账号积分。演练会先保存当前设置。
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="proxy-drill-actions">
|
||||||
|
<label class="proxy-drill-account">
|
||||||
|
<span>模拟账号</span>
|
||||||
|
<input
|
||||||
|
v-model.number="drillAccounts"
|
||||||
|
class="form-input"
|
||||||
|
type="number"
|
||||||
|
min="1"
|
||||||
|
max="200"
|
||||||
|
step="1"
|
||||||
|
>
|
||||||
|
</label>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="btn-action primary"
|
||||||
|
:disabled="drillRunning || !formData.proxyApi.trim()"
|
||||||
|
@click="handleProxyDrill"
|
||||||
|
>
|
||||||
|
{{ drillRunning ? '演练中...' : '开始演练' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-if="drillResult" class="proxy-drill-result">
|
||||||
|
<div class="proxy-drill-summary" :class="{ success: drillResult.success, error: !drillResult.success }">
|
||||||
|
<strong>{{ drillResult.success ? '演练通过' : '演练未通过' }}</strong>
|
||||||
|
<span>
|
||||||
|
{{ drillResult.simulatedAccounts }} 账号 →
|
||||||
|
{{ drillResult.activeCount }} 活动 + {{ drillResult.standbyCount }} 备用
|
||||||
|
</span>
|
||||||
|
<span>健康:{{ drillResult.healthyActive }}/{{ drillResult.activeCount }} 活动,{{ drillResult.healthyStandby }}/{{ drillResult.standbyCount }} 备用</span>
|
||||||
|
<span>耗时 {{ drillResult.durationMs }}ms</span>
|
||||||
|
</div>
|
||||||
|
<div v-if="drillResult.error" class="proxy-drill-error">{{ drillResult.error }}</div>
|
||||||
|
<div class="proxy-drill-endpoint" :title="drillResult.endpoint">
|
||||||
|
探测接口:{{ drillResult.endpoint }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="proxy-drill-list">
|
||||||
|
<div
|
||||||
|
v-for="item in drillResult.items"
|
||||||
|
:key="`${item.role}-${item.group}`"
|
||||||
|
class="proxy-drill-item"
|
||||||
|
:class="{ healthy: item.requests > 0 && item.success === item.requests }"
|
||||||
|
>
|
||||||
|
<div class="proxy-drill-item-head">
|
||||||
|
<span class="proxy-drill-role" :class="{ standby: item.role === '备用代理' }">
|
||||||
|
{{ item.role }} {{ item.group }}
|
||||||
|
</span>
|
||||||
|
<strong>{{ item.success }}/{{ item.requests }} 成功</strong>
|
||||||
|
</div>
|
||||||
|
<div class="proxy-drill-proxy" :title="item.proxy">{{ item.ip || item.proxy }}<span v-if="item.region"> · {{ item.region }}</span></div>
|
||||||
|
<div class="proxy-drill-metrics">
|
||||||
|
<span>平均 {{ item.avgLatencyMs }}ms</span>
|
||||||
|
<span>最慢 {{ item.maxLatencyMs }}ms</span>
|
||||||
|
<span>流量 {{ item.bytes }}B</span>
|
||||||
|
<span v-if="item.provider">{{ item.provider }}</span>
|
||||||
|
</div>
|
||||||
|
<div v-if="item.error" class="proxy-drill-item-error">{{ item.error }}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -1054,6 +1157,152 @@ defineExpose({ open, close })
|
|||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.proxy-drill {
|
||||||
|
margin: 14px 0;
|
||||||
|
padding: 12px;
|
||||||
|
border: 1px solid var(--accent-border);
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
background: var(--accent-soft);
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-head {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-start;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 12px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-title {
|
||||||
|
margin-bottom: 4px;
|
||||||
|
color: var(--text-strong);
|
||||||
|
font-size: 13px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-actions {
|
||||||
|
display: flex;
|
||||||
|
align-items: flex-end;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-account {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 4px;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-account .form-input {
|
||||||
|
width: 88px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-result {
|
||||||
|
margin-top: 12px;
|
||||||
|
padding-top: 12px;
|
||||||
|
border-top: 1px solid var(--accent-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-summary {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px 12px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
font-size: 11.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-summary strong {
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-summary.success strong {
|
||||||
|
color: var(--success);
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-summary.error strong,
|
||||||
|
.proxy-drill-error,
|
||||||
|
.proxy-drill-item-error {
|
||||||
|
color: var(--danger);
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-error {
|
||||||
|
margin-top: 8px;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-endpoint {
|
||||||
|
margin-top: 8px;
|
||||||
|
overflow: hidden;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 10.5px;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 6px;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-item {
|
||||||
|
padding: 9px 10px;
|
||||||
|
border: 1px solid var(--line);
|
||||||
|
border-radius: var(--radius-sm);
|
||||||
|
background: var(--surface);
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-item.healthy {
|
||||||
|
border-color: var(--success);
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-item-head,
|
||||||
|
.proxy-drill-metrics {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 8px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-item-head {
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-role {
|
||||||
|
color: var(--accent);
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-role.standby {
|
||||||
|
color: var(--warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-proxy {
|
||||||
|
margin-top: 5px;
|
||||||
|
overflow: hidden;
|
||||||
|
color: var(--text-strong);
|
||||||
|
font-size: 11.5px;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-metrics {
|
||||||
|
justify-content: flex-start;
|
||||||
|
margin-top: 5px;
|
||||||
|
color: var(--muted);
|
||||||
|
font-size: 10.5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.proxy-drill-item-error {
|
||||||
|
margin-top: 5px;
|
||||||
|
font-size: 10.5px;
|
||||||
|
line-height: 1.4;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
.proxy-config-area {
|
.proxy-config-area {
|
||||||
margin-top: 14px;
|
margin-top: 14px;
|
||||||
padding: 14px;
|
padding: 14px;
|
||||||
|
|||||||
+3
-2
@@ -48,7 +48,8 @@ type App struct {
|
|||||||
productsAt time.Time
|
productsAt time.Time
|
||||||
|
|
||||||
// accountsMu 串行化内部账号库修改,避免并发导入、编辑或删除互相覆盖。
|
// accountsMu 串行化内部账号库修改,避免并发导入、编辑或删除互相覆盖。
|
||||||
accountsMu sync.Mutex
|
accountsMu sync.Mutex
|
||||||
|
proxyDrillMu sync.Mutex
|
||||||
|
|
||||||
closeLog func()
|
closeLog func()
|
||||||
closeTrace func()
|
closeTrace func()
|
||||||
@@ -256,7 +257,7 @@ func (a *App) Startup(ctx context.Context) {
|
|||||||
|
|
||||||
proxyURL = a.effectiveProxyURL(a.getCfg())
|
proxyURL = a.effectiveProxyURL(a.getCfg())
|
||||||
if proxyURL != "" {
|
if proxyURL != "" {
|
||||||
if _, err := a.getClient().ProbeServerTime(); err != nil {
|
if _, err := a.getClient().ProbeProxyEndpoint(); err != nil {
|
||||||
logger.LogEvent("代理", "warn", "启动代理探测失败: %v", err)
|
logger.LogEvent("代理", "warn", "启动代理探测失败: %v", err)
|
||||||
currentCfg := a.getCfg()
|
currentCfg := a.getCfg()
|
||||||
if currentCfg.ProxyEnabled &&
|
if currentCfg.ProxyEnabled &&
|
||||||
|
|||||||
@@ -0,0 +1,312 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"douyu_go/internal/activity"
|
||||||
|
"douyu_go/internal/client"
|
||||||
|
"douyu_go/internal/constants"
|
||||||
|
"douyu_go/internal/logger"
|
||||||
|
proxyprovider "douyu_go/internal/proxy"
|
||||||
|
"douyu_go/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultProxyDrillAccounts = 30
|
||||||
|
maxProxyDrillAccounts = 200
|
||||||
|
proxyDrillExtractRounds = 3
|
||||||
|
proxyDrillMaxRounds = 20
|
||||||
|
)
|
||||||
|
|
||||||
|
type proxyDrillPlan struct {
|
||||||
|
accounts int
|
||||||
|
groupSize int
|
||||||
|
active int
|
||||||
|
standby int
|
||||||
|
}
|
||||||
|
|
||||||
|
type proxyDrillTarget struct {
|
||||||
|
role string
|
||||||
|
group int
|
||||||
|
requests int
|
||||||
|
endpoint proxyprovider.Endpoint
|
||||||
|
}
|
||||||
|
|
||||||
|
type proxyDrillProbe struct {
|
||||||
|
success bool
|
||||||
|
latency time.Duration
|
||||||
|
bytes int64
|
||||||
|
err error
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunProxyDrill 使用无需 Cookie 的商品接口验证代理池,不读取账号、不锁单、不支付。
|
||||||
|
func (a *App) RunProxyDrill(req types.ProxyDrillRequest) types.ProxyDrillResult {
|
||||||
|
a.proxyDrillMu.Lock()
|
||||||
|
defer a.proxyDrillMu.Unlock()
|
||||||
|
|
||||||
|
startedAt := time.Now()
|
||||||
|
cfg := a.getCfg()
|
||||||
|
if strings.TrimSpace(cfg.ProxyAPI) == "" {
|
||||||
|
return types.ProxyDrillResult{Error: "请先填写代理提取 API"}
|
||||||
|
}
|
||||||
|
if scheduler := a.getScheduler(); scheduler != nil && scheduler.IsRunning() {
|
||||||
|
return types.ProxyDrillResult{Error: "抢购任务运行中,不能同时执行代理池演练"}
|
||||||
|
}
|
||||||
|
|
||||||
|
act := activity.Get(cfg.Activity)
|
||||||
|
if act == nil {
|
||||||
|
act = activity.Default()
|
||||||
|
}
|
||||||
|
if strings.TrimSpace(act.StoreHomeURL) == "" {
|
||||||
|
return types.ProxyDrillResult{Error: "当前活动没有可用于代理演练的只读接口"}
|
||||||
|
}
|
||||||
|
probeEndpoint := act.StoreHomeURL
|
||||||
|
if act.IsXiaodian {
|
||||||
|
probeEndpoint = cfg.TimeAPIURL
|
||||||
|
}
|
||||||
|
|
||||||
|
accounts := req.SimulatedAccounts
|
||||||
|
if accounts <= 0 {
|
||||||
|
accounts = defaultProxyDrillAccounts
|
||||||
|
}
|
||||||
|
if accounts > maxProxyDrillAccounts {
|
||||||
|
accounts = maxProxyDrillAccounts
|
||||||
|
}
|
||||||
|
groupSize := cfg.AccountsPerProxy
|
||||||
|
if groupSize <= 0 {
|
||||||
|
groupSize = constants.DefaultAccountsPerProxy
|
||||||
|
}
|
||||||
|
if groupSize > constants.MaxAccountsPerProxy {
|
||||||
|
groupSize = constants.MaxAccountsPerProxy
|
||||||
|
}
|
||||||
|
plan := proxyDrillPlan{
|
||||||
|
accounts: accounts,
|
||||||
|
groupSize: groupSize,
|
||||||
|
active: (accounts + groupSize - 1) / groupSize,
|
||||||
|
}
|
||||||
|
plan.standby = proxyDrillStandbyCount(plan.active, cfg.ProxySparePercent)
|
||||||
|
desired := plan.active + plan.standby
|
||||||
|
|
||||||
|
result := types.ProxyDrillResult{
|
||||||
|
Endpoint: probeEndpoint,
|
||||||
|
SimulatedAccounts: plan.accounts,
|
||||||
|
AccountsPerProxy: plan.groupSize,
|
||||||
|
ActiveCount: plan.active,
|
||||||
|
StandbyCount: plan.standby,
|
||||||
|
Items: []types.ProxyDrillItem{},
|
||||||
|
}
|
||||||
|
logger.LogEvent("代理", "info", "开始代理池演练: 模拟账号=%d,活动代理=%d,备用代理=%d,接口=%s",
|
||||||
|
plan.accounts, plan.active, plan.standby, probeEndpoint)
|
||||||
|
|
||||||
|
endpoints, err := a.extractProxyDrillPool(cfg, desired)
|
||||||
|
if len(endpoints) < plan.active {
|
||||||
|
result.Error = fmt.Sprintf("代理数量不足: 需要%d个活动代理,实际%d个", plan.active, len(endpoints))
|
||||||
|
if err != nil {
|
||||||
|
result.Error += ";" + err.Error()
|
||||||
|
}
|
||||||
|
result.DurationMs = time.Since(startedAt).Milliseconds()
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
targets := buildProxyDrillTargets(plan, endpoints)
|
||||||
|
result.Items = make([]types.ProxyDrillItem, len(targets))
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
for i, target := range targets {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(index int, target proxyDrillTarget) {
|
||||||
|
defer wg.Done()
|
||||||
|
result.Items[index] = a.runProxyDrillTarget(act, cfg.TimeAPIURL, target)
|
||||||
|
}(i, target)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
for _, item := range result.Items {
|
||||||
|
if item.Success != item.Requests || item.Requests == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if item.Role == "活动代理" {
|
||||||
|
result.HealthyActive++
|
||||||
|
} else {
|
||||||
|
result.HealthyStandby++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.Success = result.HealthyActive >= plan.active && result.HealthyStandby >= plan.standby
|
||||||
|
if !result.Success {
|
||||||
|
result.Error = "活动代理或备用代理未全部通过演练"
|
||||||
|
}
|
||||||
|
result.DurationMs = time.Since(startedAt).Milliseconds()
|
||||||
|
logger.LogEvent("代理", "success", "代理池演练完成: 成功=%v,活动代理=%d/%d,备用代理=%d/%d,耗时=%s",
|
||||||
|
result.Success, result.HealthyActive, plan.active, result.HealthyStandby, plan.standby,
|
||||||
|
time.Duration(result.DurationMs)*time.Millisecond)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
func proxyDrillStandbyCount(activeCount, sparePercent int) int {
|
||||||
|
if activeCount <= 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
if sparePercent <= 0 {
|
||||||
|
sparePercent = constants.DefaultProxySparePercent
|
||||||
|
}
|
||||||
|
if sparePercent > constants.MaxProxySparePercent {
|
||||||
|
sparePercent = constants.MaxProxySparePercent
|
||||||
|
}
|
||||||
|
count := (activeCount*sparePercent + 99) / 100
|
||||||
|
if count < 1 {
|
||||||
|
count = 1
|
||||||
|
}
|
||||||
|
return count
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) extractProxyDrillPool(cfg types.Config, desired int) ([]proxyprovider.Endpoint, error) {
|
||||||
|
rounds := proxyDrillExtractRounds
|
||||||
|
if desired > rounds {
|
||||||
|
rounds = desired
|
||||||
|
}
|
||||||
|
if rounds > proxyDrillMaxRounds {
|
||||||
|
rounds = proxyDrillMaxRounds
|
||||||
|
}
|
||||||
|
|
||||||
|
seen := make(map[string]struct{}, desired)
|
||||||
|
endpoints := make([]proxyprovider.Endpoint, 0, desired)
|
||||||
|
var lastErr error
|
||||||
|
for round := 0; round < rounds && len(endpoints) < desired; round++ {
|
||||||
|
batch, err := extractProxyEndpoints(cfg, cfg.ProxyAPI, desired-len(endpoints))
|
||||||
|
if err != nil {
|
||||||
|
lastErr = err
|
||||||
|
if proxyprovider.IsFatal(err) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, endpoint := range batch {
|
||||||
|
if !endpoint.ExpiresAt.IsZero() && !time.Now().Before(endpoint.ExpiresAt) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if _, exists := seen[endpoint.URL]; exists {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
seen[endpoint.URL] = struct{}{}
|
||||||
|
endpoints = append(endpoints, endpoint)
|
||||||
|
if len(endpoints) >= desired {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if round < rounds-1 {
|
||||||
|
time.Sleep(200 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(endpoints) < desired {
|
||||||
|
if lastErr != nil {
|
||||||
|
return endpoints, lastErr
|
||||||
|
}
|
||||||
|
return endpoints, fmt.Errorf("代理 API 仅返回 %d/%d 个有效代理", len(endpoints), desired)
|
||||||
|
}
|
||||||
|
return endpoints, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildProxyDrillTargets(plan proxyDrillPlan, endpoints []proxyprovider.Endpoint) []proxyDrillTarget {
|
||||||
|
targets := make([]proxyDrillTarget, 0, len(endpoints))
|
||||||
|
remaining := plan.accounts
|
||||||
|
for i := 0; i < plan.active; i++ {
|
||||||
|
requests := min(plan.groupSize, remaining)
|
||||||
|
if requests < 1 {
|
||||||
|
requests = 1
|
||||||
|
}
|
||||||
|
remaining -= requests
|
||||||
|
targets = append(targets, proxyDrillTarget{
|
||||||
|
role: "活动代理",
|
||||||
|
group: i + 1,
|
||||||
|
requests: requests,
|
||||||
|
endpoint: endpoints[i],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
for i := plan.active; i < len(endpoints); i++ {
|
||||||
|
requests := min(plan.groupSize, plan.accounts)
|
||||||
|
if requests < 1 {
|
||||||
|
requests = 1
|
||||||
|
}
|
||||||
|
targets = append(targets, proxyDrillTarget{
|
||||||
|
role: "备用代理",
|
||||||
|
group: i - plan.active + 1,
|
||||||
|
requests: requests,
|
||||||
|
endpoint: endpoints[i],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return targets
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *App) runProxyDrillTarget(act *activity.Activity, timeAPIURL string, target proxyDrillTarget) types.ProxyDrillItem {
|
||||||
|
item := types.ProxyDrillItem{
|
||||||
|
Role: target.role,
|
||||||
|
Group: target.group,
|
||||||
|
Proxy: client.MaskProxyURL(target.endpoint.URL),
|
||||||
|
IP: target.endpoint.IP,
|
||||||
|
Region: target.endpoint.Region,
|
||||||
|
Provider: target.endpoint.Provider,
|
||||||
|
Requests: target.requests,
|
||||||
|
}
|
||||||
|
if !target.endpoint.ExpiresAt.IsZero() {
|
||||||
|
item.ExpiresAt = target.endpoint.ExpiresAt.UnixMilli()
|
||||||
|
}
|
||||||
|
proxyClient, err := client.NewWithProxy(act, timeAPIURL, a.getTrace(), target.endpoint.URL)
|
||||||
|
if err != nil {
|
||||||
|
item.Failed = target.requests
|
||||||
|
item.Error = err.Error()
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
defer closeProxyDrillClient(proxyClient)
|
||||||
|
|
||||||
|
results := make(chan proxyDrillProbe, target.requests)
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
for i := 0; i < target.requests; i++ {
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
probe, err := proxyClient.ProbeProxyEndpoint()
|
||||||
|
results <- proxyDrillProbe{
|
||||||
|
success: err == nil,
|
||||||
|
latency: probe.Latency,
|
||||||
|
bytes: probe.Bytes,
|
||||||
|
err: err,
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
close(results)
|
||||||
|
|
||||||
|
var totalLatency time.Duration
|
||||||
|
for probe := range results {
|
||||||
|
if probe.success {
|
||||||
|
item.Success++
|
||||||
|
} else {
|
||||||
|
item.Failed++
|
||||||
|
if item.Error == "" && probe.err != nil {
|
||||||
|
item.Error = probe.err.Error()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
totalLatency += probe.latency
|
||||||
|
item.Bytes += probe.bytes
|
||||||
|
if probe.latency > time.Duration(item.MaxLatencyMs)*time.Millisecond {
|
||||||
|
item.MaxLatencyMs = probe.latency.Milliseconds()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if target.requests > 0 {
|
||||||
|
item.AvgLatencyMs = (totalLatency / time.Duration(target.requests)).Milliseconds()
|
||||||
|
}
|
||||||
|
return item
|
||||||
|
}
|
||||||
|
|
||||||
|
func closeProxyDrillClient(cli *client.DouyuClient) {
|
||||||
|
if cli == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if cli.HTTPClient != nil {
|
||||||
|
cli.HTTPClient.CloseIdleConnections()
|
||||||
|
}
|
||||||
|
if cli.TimeHTTPClient != nil {
|
||||||
|
cli.TimeHTTPClient.CloseIdleConnections()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
proxyprovider "douyu_go/internal/proxy"
|
||||||
|
"douyu_go/internal/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestProxyDrillPlanAndTargets(t *testing.T) {
|
||||||
|
if got := proxyDrillStandbyCount(6, 25); got != 2 {
|
||||||
|
t.Fatalf("proxyDrillStandbyCount(6, 25)=%d, want 2", got)
|
||||||
|
}
|
||||||
|
plan := proxyDrillPlan{accounts: 30, groupSize: 5, active: 6, standby: 2}
|
||||||
|
endpoints := make([]proxyprovider.Endpoint, 8)
|
||||||
|
targets := buildProxyDrillTargets(plan, endpoints)
|
||||||
|
if len(targets) != 8 {
|
||||||
|
t.Fatalf("targets=%d, want 8", len(targets))
|
||||||
|
}
|
||||||
|
totalRequests := 0
|
||||||
|
for _, target := range targets {
|
||||||
|
totalRequests += target.requests
|
||||||
|
}
|
||||||
|
if totalRequests != 40 {
|
||||||
|
t.Fatalf("totalRequests=%d, want 40 virtual requests", totalRequests)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExtractProxyDrillPoolDeduplicates(t *testing.T) {
|
||||||
|
apiServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
for i := 0; i < 8; i++ {
|
||||||
|
fmt.Fprintf(w, "http://127.0.0.1:%d\n", 20000+i)
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
defer apiServer.Close()
|
||||||
|
|
||||||
|
app := &App{}
|
||||||
|
cfg := types.Config{ProxyAPI: apiServer.URL}
|
||||||
|
endpoints, err := app.extractProxyDrillPool(cfg, 8)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("extractProxyDrillPool() error = %v", err)
|
||||||
|
}
|
||||||
|
if len(endpoints) != 8 {
|
||||||
|
t.Fatalf("endpoints=%d, want 8", len(endpoints))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"douyu_go/internal/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
// BusinessProbeResult 是经过代理访问真实业务接口的探测结果。
|
||||||
|
type BusinessProbeResult struct {
|
||||||
|
Latency time.Duration
|
||||||
|
Bytes int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProbeBusinessEndpoint 使用当前代理访问无需账号的商品接口。
|
||||||
|
// 该接口只读、不下单、不支付,但会经过与真实抢购相同的斗鱼业务域名和浏览器请求头。
|
||||||
|
func (c *DouyuClient) ProbeBusinessEndpoint() (BusinessProbeResult, error) {
|
||||||
|
if c == nil || c.Activity == nil {
|
||||||
|
return BusinessProbeResult{}, errors.New("活动配置未初始化")
|
||||||
|
}
|
||||||
|
if strings.TrimSpace(c.Activity.StoreHomeURL) == "" {
|
||||||
|
return BusinessProbeResult{}, errors.New("当前活动没有可用的商品探测接口")
|
||||||
|
}
|
||||||
|
|
||||||
|
target := utils.AppendCacheBuster(c.Activity.StoreHomeURL)
|
||||||
|
req, err := http.NewRequest(http.MethodGet, target, nil)
|
||||||
|
if err != nil {
|
||||||
|
return BusinessProbeResult{}, err
|
||||||
|
}
|
||||||
|
if c.Activity.IsXiaodian {
|
||||||
|
c.setXiaodianHeaders(req)
|
||||||
|
} else {
|
||||||
|
c.setBrowserHeaders(req, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
start := time.Now()
|
||||||
|
body, err := c.doText(req, "代理业务演练", true)
|
||||||
|
latency := time.Since(start)
|
||||||
|
if err != nil {
|
||||||
|
return BusinessProbeResult{Latency: latency}, err
|
||||||
|
}
|
||||||
|
if len(body) < 32 {
|
||||||
|
return BusinessProbeResult{Latency: latency, Bytes: int64(len(body))},
|
||||||
|
fmt.Errorf("响应体过短: %d 字节", len(body))
|
||||||
|
}
|
||||||
|
if !json.Valid(body) {
|
||||||
|
return BusinessProbeResult{Latency: latency, Bytes: int64(len(body))},
|
||||||
|
errors.New("响应不是有效 JSON,可能被代理或网关改写")
|
||||||
|
}
|
||||||
|
|
||||||
|
var payload struct {
|
||||||
|
Error int `json:"error"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Msg string `json:"msg"`
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(body, &payload); err == nil && payload.Error != 0 {
|
||||||
|
message := strings.TrimSpace(payload.Message)
|
||||||
|
if message == "" {
|
||||||
|
message = strings.TrimSpace(payload.Msg)
|
||||||
|
}
|
||||||
|
if message == "" {
|
||||||
|
message = "业务接口返回错误"
|
||||||
|
}
|
||||||
|
return BusinessProbeResult{Latency: latency, Bytes: int64(len(body))},
|
||||||
|
fmt.Errorf("%s (error=%d)", message, payload.Error)
|
||||||
|
}
|
||||||
|
return BusinessProbeResult{
|
||||||
|
Latency: latency,
|
||||||
|
Bytes: int64(len(body)),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProbeProxyEndpoint 选择当前活动适合的代理质量探测方式。
|
||||||
|
// 手册活动访问真实商品列表接口;和平小店角色参数更复杂,保留时间接口兜底。
|
||||||
|
func (c *DouyuClient) ProbeProxyEndpoint() (BusinessProbeResult, error) {
|
||||||
|
if c != nil && c.Activity != nil && c.Activity.IsXiaodian {
|
||||||
|
sample, err := c.ProbeServerTime()
|
||||||
|
return BusinessProbeResult{Latency: sample.RTT}, err
|
||||||
|
}
|
||||||
|
return c.ProbeBusinessEndpoint()
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
package client
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"douyu_go/internal/activity"
|
||||||
|
"douyu_go/internal/trace"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestProbeBusinessEndpointAcceptsJSON(t *testing.T) {
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write([]byte(`{"error":0,"msg":"","data":{"list":[{"commodityId":"bag-1","commodityName":"测试商品","count":100}]}}`))
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
act := *activity.Get("peace")
|
||||||
|
act.StoreHomeURL = server.URL
|
||||||
|
cli, err := NewWithProxy(&act, server.URL, &trace.Recorder{}, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
result, err := cli.ProbeBusinessEndpoint()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("ProbeBusinessEndpoint() error = %v", err)
|
||||||
|
}
|
||||||
|
if result.Bytes < 64 || result.Latency <= 0 {
|
||||||
|
t.Fatalf("ProbeBusinessEndpoint()=%+v, want positive latency and body size", result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProbeBusinessEndpointRejectsNonJSON(t *testing.T) {
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
_, _ = w.Write([]byte(strings.Repeat("<html>proxy error</html>", 8)))
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
act := *activity.Get("peace")
|
||||||
|
act.StoreHomeURL = server.URL
|
||||||
|
cli, err := NewWithProxy(&act, server.URL, &trace.Recorder{}, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := cli.ProbeBusinessEndpoint(); err == nil {
|
||||||
|
t.Fatal("ProbeBusinessEndpoint() should reject non-JSON responses")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProbeBusinessEndpointAcceptsShortPeacematchResponse(t *testing.T) {
|
||||||
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write([]byte(`{"error":0,"msg":"","data":{"score":0,"list":[],"peacePass":0}}`))
|
||||||
|
}))
|
||||||
|
defer server.Close()
|
||||||
|
|
||||||
|
act := *activity.Get("peacematch")
|
||||||
|
act.StoreHomeURL = server.URL
|
||||||
|
cli, err := NewWithProxy(&act, server.URL, &trace.Recorder{}, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := cli.ProbeBusinessEndpoint(); err != nil {
|
||||||
|
t.Fatalf("ProbeBusinessEndpoint() rejected short valid JSON: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ package constants
|
|||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
// Version 应用版本号,与 wails.json version 同步。
|
// Version 应用版本号,与 wails.json version 同步。
|
||||||
const Version = "0.5.0"
|
const Version = "0.5.1"
|
||||||
|
|
||||||
// BuildTime 构建时间,由编译时 ldflags 注入。
|
// BuildTime 构建时间,由编译时 ldflags 注入。
|
||||||
var BuildTime = "unknown"
|
var BuildTime = "unknown"
|
||||||
|
|||||||
@@ -44,6 +44,10 @@ func (p *IPZanProvider) RequestURL(apiURL string, count int) (string, error) {
|
|||||||
}
|
}
|
||||||
query := u.Query()
|
query := u.Query()
|
||||||
query.Set("num", strconv.Itoa(count))
|
query.Set("num", strconv.Itoa(count))
|
||||||
|
if strings.EqualFold(strings.TrimSpace(query.Get("mode")), "auth") {
|
||||||
|
// txt 只返回 IP:端口,会丢失每个代理各自的账号密码,随后必然触发 407。
|
||||||
|
query.Set("format", "json")
|
||||||
|
}
|
||||||
u.RawQuery = query.Encode()
|
u.RawQuery = query.Encode()
|
||||||
return u.String(), nil
|
return u.String(), nil
|
||||||
}
|
}
|
||||||
@@ -74,6 +78,9 @@ func (p *IPZanProvider) Parse(apiURL string, body []byte) ([]Endpoint, error) {
|
|||||||
if len(payload.Data) > 0 {
|
if len(payload.Data) > 0 {
|
||||||
endpoints := parseEndpointJSON(payload.Data, protocolFromAPI(apiURL))
|
endpoints := parseEndpointJSON(payload.Data, protocolFromAPI(apiURL))
|
||||||
if len(endpoints) > 0 {
|
if len(endpoints) > 0 {
|
||||||
|
if err := validateIPZanAuthEndpoints(apiURL, endpoints); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return endpoints, nil
|
return endpoints, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -87,9 +94,29 @@ func (p *IPZanProvider) Parse(apiURL string, body []byte) ([]Endpoint, error) {
|
|||||||
Fatal: false,
|
Fatal: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err := validateIPZanAuthEndpoints(apiURL, endpoints); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return endpoints, nil
|
return endpoints, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func validateIPZanAuthEndpoints(apiURL string, endpoints []Endpoint) error {
|
||||||
|
u, err := url.Parse(strings.TrimSpace(apiURL))
|
||||||
|
if err != nil || !strings.EqualFold(strings.TrimSpace(u.Query().Get("mode")), "auth") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
for _, endpoint := range endpoints {
|
||||||
|
if strings.TrimSpace(endpoint.Username) == "" || strings.TrimSpace(endpoint.Password) == "" {
|
||||||
|
return &ProviderError{
|
||||||
|
Provider: "品赞",
|
||||||
|
Message: "账号密码模式返回缺少账号或密码;请移除 format=txt,让程序使用 JSON 格式提取",
|
||||||
|
Fatal: true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (p *IPZanProvider) EnsureWhitelist(ctx context.Context, httpClient *http.Client, cfg WhitelistConfig) error {
|
func (p *IPZanProvider) EnsureWhitelist(ctx context.Context, httpClient *http.Client, cfg WhitelistConfig) error {
|
||||||
if strings.TrimSpace(cfg.IP) == "" {
|
if strings.TrimSpace(cfg.IP) == "" {
|
||||||
return &ProviderError{Provider: "品赞", Message: "自动白名单缺少公网 IP", Fatal: true}
|
return &ProviderError{Provider: "品赞", Message: "自动白名单缺少公网 IP", Fatal: true}
|
||||||
|
|||||||
@@ -24,6 +24,35 @@ func TestIPZanRequestURLSetsRequestedCount(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIPZanRequestURLForcesJSONForAuthMode(t *testing.T) {
|
||||||
|
raw := "https://service.ipzan.com/core-extract?num=1&mode=auth&format=txt&secret=x"
|
||||||
|
got, err := NewIPZanProvider().RequestURL(raw, 8)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
u, err := url.Parse(got)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if mode := u.Query().Get("mode"); mode != "auth" {
|
||||||
|
t.Fatalf("mode=%q, want auth", mode)
|
||||||
|
}
|
||||||
|
if format := u.Query().Get("format"); format != "json" {
|
||||||
|
t.Fatalf("format=%q, want json", format)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestIPZanParseRejectsAuthModeWithoutCredentials(t *testing.T) {
|
||||||
|
body := []byte(`{"code":0,"status":200,"data":{"list":[{"ip":"1.2.3.4","port":8001}]}}`)
|
||||||
|
_, err := NewIPZanProvider().Parse(
|
||||||
|
"https://service.ipzan.com/core-extract?mode=auth&protocol=1",
|
||||||
|
body,
|
||||||
|
)
|
||||||
|
if err == nil || !IsFatal(err) {
|
||||||
|
t.Fatalf("expected fatal missing-credentials error, got %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestIPZanParseTextMultiple(t *testing.T) {
|
func TestIPZanParseTextMultiple(t *testing.T) {
|
||||||
body := []byte("1.2.3.4:8001\r\n5.6.7.8:8002\r\n")
|
body := []byte("1.2.3.4:8001\r\n5.6.7.8:8002\r\n")
|
||||||
got, err := NewIPZanProvider().Parse(
|
got, err := NewIPZanProvider().Parse(
|
||||||
|
|||||||
@@ -906,20 +906,16 @@ func (s *Scheduler) validateProxy(base *client.DouyuClient, proxyURL, source str
|
|||||||
}
|
}
|
||||||
var lastErr error
|
var lastErr error
|
||||||
for attempt := 0; attempt < proxyValidateAttempts; attempt++ {
|
for attempt := 0; attempt < proxyValidateAttempts; attempt++ {
|
||||||
sample, sampleErr := cli.ProbeServerTime()
|
probe, probeErr := cli.ProbeProxyEndpoint()
|
||||||
if sampleErr == nil {
|
if probeErr == nil {
|
||||||
return validatedProxy{
|
return validatedProxy{
|
||||||
url: proxyURL,
|
url: proxyURL,
|
||||||
client: cli,
|
client: cli,
|
||||||
rtt: sample.RTT,
|
rtt: probe.Latency,
|
||||||
source: source,
|
source: source,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
if sampleErr != nil {
|
lastErr = probeErr
|
||||||
lastErr = sampleErr
|
|
||||||
} else {
|
|
||||||
lastErr = errors.New("斗鱼时间接口测试失败")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if cli.HTTPClient != nil {
|
if cli.HTTPClient != nil {
|
||||||
cli.HTTPClient.CloseIdleConnections()
|
cli.HTTPClient.CloseIdleConnections()
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strconv"
|
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
@@ -98,6 +97,7 @@ func TestPrepareProxyGroupsRoutesAccountsToDistinctClients(t *testing.T) {
|
|||||||
defer apiServer.Close()
|
defer apiServer.Close()
|
||||||
|
|
||||||
act := *activity.Get("peace")
|
act := *activity.Get("peace")
|
||||||
|
act.StoreHomeURL = timeAPIURL
|
||||||
base := client.New(&act, timeAPIURL, &trace.Recorder{}, "")
|
base := client.New(&act, timeAPIURL, &trace.Recorder{}, "")
|
||||||
scheduler := New(base, types.AppPaths{}, nil, 8, 1, nil, types.SeckillModeAggressive)
|
scheduler := New(base, types.AppPaths{}, nil, 8, 1, nil, types.SeckillModeAggressive)
|
||||||
scheduler.UpdateProxySettings(types.Config{
|
scheduler.UpdateProxySettings(types.Config{
|
||||||
@@ -156,9 +156,8 @@ func TestPrepareProxyGroupsRoutesAccountsToDistinctClients(t *testing.T) {
|
|||||||
func newTimeProxyServer(t *testing.T) *httptest.Server {
|
func newTimeProxyServer(t *testing.T) *httptest.Server {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
now := strconv.FormatInt(time.Now().Unix(), 10)
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
fmt.Fprintf(w, `{"error":0,"data":{"preExchange":{"currentTime":%q}}}`, now)
|
fmt.Fprint(w, `{"error":0,"msg":"","data":{"list":[{"commodityId":"bag-1","commodityName":"测试商品"}]}}`)
|
||||||
}))
|
}))
|
||||||
t.Cleanup(server.Close)
|
t.Cleanup(server.Close)
|
||||||
return server
|
return server
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
// ProxyDrillRequest 配置一次不依赖真实账号的代理池演练。
|
||||||
|
type ProxyDrillRequest struct {
|
||||||
|
SimulatedAccounts int `json:"simulatedAccounts"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProxyDrillItem 是单个代理的演练结果。
|
||||||
|
type ProxyDrillItem struct {
|
||||||
|
Role string `json:"role"` // 活动代理 / 备用代理
|
||||||
|
Group int `json:"group"`
|
||||||
|
Proxy string `json:"proxy"`
|
||||||
|
IP string `json:"ip"`
|
||||||
|
Region string `json:"region"`
|
||||||
|
Provider string `json:"provider"`
|
||||||
|
Requests int `json:"requests"`
|
||||||
|
Success int `json:"success"`
|
||||||
|
Failed int `json:"failed"`
|
||||||
|
AvgLatencyMs int64 `json:"avgLatencyMs"`
|
||||||
|
MaxLatencyMs int64 `json:"maxLatencyMs"`
|
||||||
|
Bytes int64 `json:"bytes"`
|
||||||
|
ExpiresAt int64 `json:"expiresAt,omitempty"`
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// ProxyDrillResult 是代理池演练汇总。
|
||||||
|
type ProxyDrillResult struct {
|
||||||
|
Success bool `json:"success"`
|
||||||
|
Error string `json:"error,omitempty"`
|
||||||
|
Endpoint string `json:"endpoint"`
|
||||||
|
SimulatedAccounts int `json:"simulatedAccounts"`
|
||||||
|
AccountsPerProxy int `json:"accountsPerProxy"`
|
||||||
|
ActiveCount int `json:"activeCount"`
|
||||||
|
StandbyCount int `json:"standbyCount"`
|
||||||
|
HealthyActive int `json:"healthyActive"`
|
||||||
|
HealthyStandby int `json:"healthyStandby"`
|
||||||
|
DurationMs int64 `json:"durationMs"`
|
||||||
|
Items []ProxyDrillItem `json:"items"`
|
||||||
|
}
|
||||||
+2
-2
@@ -2,7 +2,7 @@
|
|||||||
"$schema": "https://wails.io/schemas/config.v2.json",
|
"$schema": "https://wails.io/schemas/config.v2.json",
|
||||||
"name": "douyu_go",
|
"name": "douyu_go",
|
||||||
"outputfilename": "douyu_go",
|
"outputfilename": "douyu_go",
|
||||||
"version": "0.5.0",
|
"version": "0.5.1",
|
||||||
"frontend:dir": "frontend",
|
"frontend:dir": "frontend",
|
||||||
"frontend:install": "npm install",
|
"frontend:install": "npm install",
|
||||||
"frontend:build": "npm run build",
|
"frontend:build": "npm run build",
|
||||||
@@ -15,6 +15,6 @@
|
|||||||
"email": "yml@example.com"
|
"email": "yml@example.com"
|
||||||
},
|
},
|
||||||
"info": {
|
"info": {
|
||||||
"productVersion": "0.5.0"
|
"productVersion": "0.5.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user