zapretgui/tests/test_tcp_info.py
loop-uh c4a468dea5
All checks were successful
Zapret source guards / validate (push) Successful in 8s
Platform layer: netprobe and autostart behind the interface
Platform.netprobe (ICMP ping and trace hop, DNS query of the system servers,
TCP server window, hosts path) and Platform.autostart (enable, disable,
ensure_current). Windows keeps ICMP/dnsapi/SIO_TCP_INFO and the scheduler
task code in platforms/windows (moved from utils/ and autostart/); Linux
uses unprivileged ICMP sockets, the dns_wire UDP client against
/etc/resolv.conf (systemd-resolved upstreams preferred), TCP_INFO and an
XDG autostart entry in ~/.config/autostart. Results and the Windows DNS
status numbers are in the neutral platforms/netprobe_types.py; the hosts
lookup is neutral (utils/hosts_lookup.py). tests/conftest.py swaps the
platform probes for the safe stub outside Windows so tests never measure
the real network. Windows API list: 53 files.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 14:42:24 -05:00

35 lines
1.3 KiB
Python

"""Окно приёма сервера (``platforms.current().netprobe.tcp_server_window``): Windows — SIO_TCP_INFO, Linux — TCP_INFO (ядро 6.2+), иначе честное «не известно»."""
from __future__ import annotations
import socket
import sys
import unittest
from platforms import current as current_platform
class ServerWindowTests(unittest.TestCase):
def test_unknown_outside_windows_and_without_a_connection(self) -> None:
listener = socket.socket()
listener.bind(("127.0.0.1", 0))
listener.listen(1)
self.addCleanup(listener.close)
port = listener.getsockname()[1]
window = current_platform().netprobe.tcp_server_window("127.0.0.1", port=port, timeout=1.0)
if sys.platform == "win32":
self.assertGreater(window or 0, 0)
else:
# Linux: the peer window appears in TCP_INFO from kernel 6.2; older kernels answer "unknown".
self.assertTrue(window is None or window > 0)
closed = socket.socket()
closed.bind(("127.0.0.1", 0))
free_port = closed.getsockname()[1]
closed.close()
self.assertIsNone(current_platform().netprobe.tcp_server_window("127.0.0.1", port=free_port, timeout=1.0))
if __name__ == "__main__":
unittest.main()