Files
autoreg-skills-max/skills/newapi-gh-oauth-farm/references/proxy-rotation-recipe.md

50 lines
3.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Прокси-ротация для GH-OAuth волн (recipe)
Рабочий `proxy_patch.py`: `C:/Users/User/tmp/regfarm/github_oauth/proxy_patch.py` (import + `apply()` в начале раннера, ДО `import reg_http`).
## Архитектура (проверено)
1. **Панельный HTTP (`newapi_lib.Panel`) — БЕЗ прокси, bind=False.** Прокси-IP банятся панелями 403; панель сама держит только свой rate-limit.
2. **GitHub (`gh_http.GHSession`) — через прокси.** GitHub 429 привязан к IP.
3. **Авто-ротация в GHSession**: обёртка `_req` — при `st == -1` (URLError/таймаут) до 3 ретраев; на каждом ретрае `next(itertools.cycle(live))` и ПОЛНАЯ пересборка opener:
```
[ProxyHandler({http:p, https:p}), HTTPSHandler(context=ctx), HTTPHandler(), NoRedirect, HTTPCookieProcessor(self.jar)]
```
CookieJar сохраняется (сессия GitHub продолжается), меняются только ProxyHandler+addheaders. Без пересборки opener молча держит мёртвый прокси → волна 0/150.
## Подготовка пула перед КАЖДОЙ волной
```python
# 1) alive-строки из БД бота
con = sqlite3.connect('C:/Users/User/Desktop/proxy_bot/proxies.db')
allp = [r[0] for r in con.execute("select proxy from pool where alive=1")]
# 2) re-verify ИМЕННО на github.com (не ip-api!) — ThreadPoolExecutor(40)
# GET https://github.com через прокси, timeout 12 → status 200 = good
# 3) json.dump(good, '_gh_proxies.json')
```
Порядок величин: БД 152 alive → ~11 живых для GitHub. `alive=1` протухает за дни.
## Диагностика мёртвой волны (0 ключей)
- `grep -E "!" _run_X.log | sort | uniq -c` — массовый `state fail: POST 429` = GitHub rate-limit; `URLError ... 10060` = мёртвый прокси без ротации.
- Ручной зонд панели: POST `/api/user/register` direct vs через 3-4 прокси — 403 = панель банит прокси-IP, 429 = панель банит домашний IP, 200 = путь свободен.
## Убийство зомби-волн (без taskkill /IM python.exe)
```python
import subprocess
ps = r'''
Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -match 'reg_proxy100' } |
ForEach-Object { Stop-Process -Id $_.ProcessId -Force; "killed $($_.ProcessId)" }
'''
subprocess.run(['powershell','-NoProfile','-Command',ps], capture_output=True, text=True)
```
Питфолы: wmic отсутствует в hermes-python; `$_`/`$(...)` внутри двойных кавычек из git-bash съедаются — powershell-скрипт только в python-heredoc с r''' строкой.
## Per-panel индексы акков
```python
used = {} # panel -> set(gh_login) из всех out/*.json где есть api_key
# idx = [i for i,a in enumerate(pool) if a['login'] not in used.get(panel,set())][:150]
# → _idx2_<panel>.txt
```
GitHub OAuth-приложения панелей независимы — один акк годен на каждой панели по разу. Глобальный «fresh» индекс занижает доступный пул.
## Очередь волн (сериализация обязательна)
`run(){ OUTNAME=out_${P}_big2 python reg_proxy100.py $P 0 0 $(cat _idx2_$P.txt) > _run_${P}_big2.log 2>&1; sleep 90-120; }` — фоновый background=true, persist_on_release. 2+ параллельные волны = глобальный GitHub 429 (E45002).