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

39 lines
2.1 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.

"""Какие хосты проверяются. По умолчанию ОДИН выбранный сервер (правило шлюза проверок: по кнопке — по одному серверу,
требование незаметности); все сохранённые (без повторов по host:port, naive первыми, не больше MAX_SERVERS) — только по явной отметке.
Контрольный хост не сохранённый сервер, а адрес, который отвечает везде (тот же, что у Android-версии)."""
from __future__ import annotations
from collections.abc import Iterable
from typing import Any
from ..runtime_logging import node_ref
from .model import Target
MAX_SERVERS = 6
CONTROL_HOST = "cp.cloudflare.com"
def from_nodes(nodes: Iterable[Any], control_host: str = CONTROL_HOST, control_port: int = 443,
max_servers: int = MAX_SERVERS, *, selected_id: str | None = None, all_servers: bool = False) -> list[Target]:
seen: set[str] = set()
found: list[Target] = []
nodes = list(nodes)
if not all_servers:
# Один сервер: выбранный; если выбора нет — первый naive, иначе первый по порядку.
pick = next((n for n in nodes if selected_id and getattr(n, "id", None) == selected_id), None)
if pick is None:
pick = next((n for n in nodes if getattr(n, "scheme", "") == "naive"), nodes[0] if nodes else None)
nodes = [pick] if pick is not None else []
for node in nodes:
host = str(getattr(node, "server", "") or "").strip()
if not host:
continue
port = int(getattr(node, "port", 0) or 443)
key = f"{host.lower()}:{port}"
if key in seen:
continue
seen.add(key)
found.append(Target(node_ref(getattr(node, "id", "")), host, port, kind=str(getattr(node, "scheme", "") or "")))
chosen = sorted(found, key=lambda t: 0 if t.kind == "naive" else 1)[:max_servers]
return [Target("ep-control", control_host, control_port, control=True, kind="control"), *chosen]