fix: 代理探测只看学习站,手填地址只允许公网

This commit is contained in:
2026-11-16 09:29:45 +08:00
parent 89d9452967
commit 990b80c017
7 changed files with 152 additions and 42 deletions
+23 -1
View File
@@ -176,7 +176,7 @@ def probe(scheme: str, host: str, port: int) -> tuple[bool, int, str]:
follow_redirects=True,
headers={"User-Agent": USER_AGENT},
) as client:
for target in PROBE_URLS:
for target in (PROBE_URL,):
started = time.perf_counter()
try:
response = client.get(target)
@@ -201,6 +201,21 @@ def probe(scheme: str, host: str, port: int) -> tuple[bool, int, str]:
return True, average, ""
def _direct_reaches_target() -> bool:
"""节点全灭时对照直连,区分代理故障和目标站故障。"""
try:
with sync_httpx_client(
None,
timeout=LATENCY_LIMIT,
follow_redirects=True,
headers={"User-Agent": USER_AGENT},
) as client:
response = client.get(PROBE_URL)
return response.status_code < 500
except Exception:
return False
def _short_reason(exc: BaseException) -> str:
from python_socks import ProxyConnectionError, ProxyTimeoutError
@@ -360,6 +375,12 @@ def _refresh_body() -> dict:
]
results = _probe_many(snapshot)
probed = len(results)
failed = sum(1 for _node_id, ok, _latency, _reason in results if not ok)
if probed >= 3 and failed == probed and not _direct_reaches_target():
results = []
elif probed < 3:
results = [row for row in results if row[1]]
with SessionLocal() as db, _assign_lock:
sync = _sync_row(db)
for node_id, ok, latency, reason in results:
@@ -378,6 +399,7 @@ def _refresh_body() -> dict:
_evict_node(node.id)
sync.checked_at = _now()
sync.running = False
db.flush()
_store_counts(db, sync)
if sync.alive_count:
sync.message = ""