zapret-kvn/xray_fluent/diagnostics/path_test/verdicts.py
loop-uh a06dd17b2b Path-test (Windows): «Проверка соединения» on the logs page
DNS, TCP, platform TLS and the stock naive.exe (real config builder helper_config, dummy credentials, no own ClientHello) per
saved server host, one full log (text and JSONL, hosts masked unless ticked, also in the diagnostic archive). By button, one
selected server by default; all servers only on a tick, one at a time with 10-20 s pauses, cancel on the same button, gate
journal; egress allowlist entries with reasons. Work of the KVN session c_9doawlxyy2 (branch feat/path-test), squashed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-29 12:18:34 -05:00

52 lines
2.6 KiB
Python
Raw Permalink 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.

"""Вердикт по попыткам одного хоста. Чистые правила: без сокетов и часов; те же, что в Android-версии."""
from __future__ import annotations
from .model import HostVerdict, Outcome, Step, TargetResult, Verdict
CONTROL_MIN_SHARE = 0.5
def judge(result: TargetResult, control: TargetResult | None) -> HostVerdict:
attempts = result.attempts
def of(step: Step):
return [a for a in attempts if a.step is step]
dns, tcp = of(Step.DNS), of(Step.TCP)
platform = [a for a in of(Step.PLATFORM_TLS) if a.outcome is not Outcome.NOT_RUN]
real = [a for a in of(Step.REAL_CLIENT) if a.outcome is not Outcome.NOT_RUN]
real_ran = bool(real)
real_answered = sum(1 for a in real if a.outcome.answered)
platform_answered = sum(1 for a in platform if a.outcome.answered)
def verdict(value: Verdict) -> HostVerdict:
return HostVerdict(result.target, value, real_answered if real_ran else -1, len(real), platform_answered, len(platform))
if dns and not any(a.outcome.answered for a in dns):
return verdict(Verdict.DNS_FAILED)
if tcp and not any(a.outcome.answered for a in tcp):
return verdict(Verdict.CONTROL_ALSO_FAILS if _control_fails(control) else Verdict.TCP_BLOCKED)
if not real_ran:
return verdict(Verdict.NOT_RUN)
if real_answered == len(real):
# настоящего клиента обслужили; молчащий платформенный стек — отличие, которое стоит назвать
return verdict(Verdict.FINGERPRINT_DEPENDENT if platform and platform_answered == 0 else Verdict.OK)
if _control_fails(control):
return verdict(Verdict.CONTROL_ALSO_FAILS)
if real_answered == 0:
if platform and platform_answered == len(platform):
return verdict(Verdict.FINGERPRINT_DEPENDENT)
cut = sum(1 for a in real if a.outcome in (Outcome.RESET, Outcome.CLOSED))
return verdict(Verdict.RESET_AFTER_TCP if cut * 2 > len(real) else Verdict.SILENT_AFTER_TCP)
return verdict(Verdict.INTERMITTENT)
def _control_fails(control: TargetResult | None) -> bool:
"""Контрольный хост измерен и в основном молчит. Не измерен: никаких утверждений о сети."""
steps = [
a for a in (control.attempts if control else ())
if a.step in (Step.TCP, Step.PLATFORM_TLS, Step.REAL_CLIENT) and a.outcome is not Outcome.NOT_RUN
]
if not steps:
return False
return sum(1 for a in steps if a.outcome.answered) / len(steps) < CONTROL_MIN_SHARE