zapret-kvn/xray_fluent/diagnostics/path_test/model.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

103 lines
4 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.

from __future__ import annotations
from dataclasses import dataclass
from enum import Enum
class Step(str, Enum):
DNS = "dns"
TCP = "tcp"
PLATFORM_TLS = "platform_tls" # платформенный TLS: контроль, не клиент
REAL_CLIENT = "real_client" # stock naive.exe с поддельными учётными данными
class Outcome(Enum):
"""Что пришло в ответ. Имена идут в журнал и совпадают с Android: их передают из рук в руки, держите стабильными."""
OK = ("ok", True)
HANDSHAKE_OK = ("handshake_ok", True)
TUNNEL_UP = ("tunnel_up", True) # сервер ответил на поддельный вход: туннель с настоящим видом клиента поднялся
ALERT = ("alert", True) # TLS-alert / сертификат увидели: сервер отвечает
SILENT = ("silent", False) # TCP открыт, в ответ ни байта
RESET = ("reset", False)
CLOSED = ("closed", False)
TIMEOUT = ("timeout", False)
REFUSED = ("refused", False)
UNREACHABLE = ("unreachable", False)
DNS_FAILED = ("dns_failed", False)
NOT_RUN = ("not_run", False) # шаг не мог запуститься: это не свидетельство о сети
def __init__(self, ident: str, answered: bool) -> None:
self.ident = ident
self.answered = answered
@dataclass(frozen=True, slots=True)
class Attempt:
step: Step
outcome: Outcome
millis: int
detail: str = "" # коротко и машинно, без секретов и адресов: bytes=517, ERR_TIMED_OUT
at: float = 0.0 # unix-время
@dataclass(frozen=True, slots=True)
class Target:
ref: str # стабильная маска узла (как в диагностике)
host: str
port: int
control: bool = False
kind: str = "" # схема узла: naive, vless, ...; шаг настоящего клиента есть только у naive
@dataclass(frozen=True, slots=True)
class TargetResult:
target: Target
attempts: tuple[Attempt, ...]
class Verdict(Enum):
OK = ("ok", "The connection reaches the server and the client's own handshake is answered.")
DNS_FAILED = ("dns_failed", "The name does not resolve on this network.")
TCP_BLOCKED = ("tcp_blocked", "TCP to the server never opens: the network or the server drops the connection.")
SILENT_AFTER_TCP = (
"silent_after_tcp",
"TCP opens but nothing answers the handshake. The server's front is silent, or something on the path drops the hello.",
)
RESET_AFTER_TCP = ("reset_after_tcp", "TCP opens and the handshake is cut with a reset or a close: something on the path interferes.")
INTERMITTENT = ("intermittent", "Only some attempts are answered: an overloaded server or an unstable path, not a fixed rule.")
FINGERPRINT_DEPENDENT = (
"fingerprint_dependent",
"The platform TLS stack is answered but the real client is not (or the reverse): the look of the client's hello matters on this path.",
)
CONTROL_ALSO_FAILS = ("control_also_fails", "The control host fails too: the network on this device is the problem, not this server.")
NOT_RUN = (
"not_run",
"The real-client step did not run for this server (only naive is covered in this release, or the client could not start), so only DNS and TCP are reliable here.",
)
def __init__(self, ident: str, plain: str) -> None:
self.ident = ident
self.plain = plain
@dataclass(frozen=True, slots=True)
class HostVerdict:
target: Target
verdict: Verdict
real_answered: int # -1: шаг не выполнялся
real_total: int
platform_answered: int
platform_total: int
@dataclass(frozen=True, slots=True)
class Environment:
app_name: str
app_version: str
started_at: float
timezone: str
network_type: str
vpn_active: bool
client_binary: str
notes: tuple[str, ...] = ()