ZaStoGram_desktop/Telegram/SourceFiles/zsg_pathtest/pathtest_probe.h
loop-uh 755fe43c87 Check connection: a path test that runs the real client code and writes one log
Desktop twin of the Android module (zsg_pathtest). For every proxy of the list, the official WSS route and two
control hosts it makes 12 attempts 1.5 s apart through the real client code and writes one log,
tdata/pathtest/path-test-YYYYMMDD-HHMMSS.txt with a JSONL twin: per-attempt lines (server_hello, alert, rst, fin,
silent, connect_failed with time to first byte, DNS and TCP times), a summary table and a plain verdict per host and
profile. Same format and same ep-<8 hex> host ids as Android (golden files from the Java implementation are
reproduced byte for byte by tests/run_pathtest_core_test.sh).

The probe is not a second client: WssClientConfig and Zsg::Naive::NaiveClientConfig are now the single builders of the
zsgnaive config for both the real sockets and the probe, and FakeTLS profiles go through PrepareClientHelloRules +
PrepareClientHello, the calls TlsSocket::sendClientHello makes. Secrets are never read (random FakeTLS key, throw-away
Naive credentials, only the cover domain of a secret); every log field is a closed-vocabulary token.

UI: a section in the proxy box, an offer once in 30 minutes when the retry link appears. Guards: test_zsg_pathtest.py,
test_proxy_wss_default.py updated for the shared config builder.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-29 12:37:16 +00:00

78 lines
2.7 KiB
C++

/*
ZaStoGram "Check connection" module: the probe (see pathtest_core.h for the log).
Nothing here builds a hello of its own. A WSS or Naive attempt drives the zsgnaive library (the Chrome 158 handshake
the client really uses) through the very config the real sockets build (WssClientConfig, Zsg::Naive::NaiveClientConfig);
a FakeTLS attempt sends the bytes of the real PrepareClientHello. The probe only watches: it peeks the first bytes the
server sends to classify the answer, and times the steps. Every function blocks, so call them from a worker thread.
*/
#pragma once
#include <QtCore/QByteArray>
#include <QtCore/QString>
#include <cstdint>
#include <string>
namespace MTP::details {
struct WssRoute;
} // namespace MTP::details
namespace Zsg::PathTest {
struct ProbeResult {
// server_hello | alert | rst | fin | silent | connect_failed | other
std::string cls = "silent";
int64_t tcpMs = -1;
int64_t ttfbMs = -1; // from TCP connected to the first byte of the server's answer
int64_t totalMs = 0;
// tunnel_open | tunnel_refused | upgrade_ok | upgrade_refused | timeout, or empty
std::string app;
// Closed vocabulary (see SafeToken).
std::string detail;
};
// "server_hello", "alert" or "other" from the first bytes of a server answer.
[[nodiscard]] const char *ClassifyFirstBytes(const QByteArray &head);
// Lower-cases and reduces free text to the closed vocabulary, at most 48 characters.
[[nodiscard]] std::string Token(const QString &text);
// The WSS client (Chrome 158 handshake) against |address|:|port|, configured from |route| exactly as the real socket.
[[nodiscard]] ProbeResult ProbeWss(
const MTP::details::WssRoute &route,
const QString &address,
int port,
int timeoutMs,
int afterTlsMs);
// The Naive client against the server |host|:|port| dialled at |address|, with throw-away credentials: a healthy
// server refuses them (tunnel_refused), which proves its TLS and HTTP/2 are up.
[[nodiscard]] ProbeResult ProbeNaive(
const QString &host,
int port,
const QString &address,
int timeoutMs,
int afterTlsMs);
// Plain TCP connect only (no bytes sent): cls is "ok" or "connect_failed", ttfbMs stays -1.
[[nodiscard]] ProbeResult ProbeTcp(
const QString &address,
int port,
int timeoutMs);
// Plain TCP, send |hello| (a complete TLS record from the real ClientHello builder), classify the first bytes.
[[nodiscard]] ProbeResult ProbeRawHello(
const QString &address,
int port,
const QByteArray &hello,
int timeoutMs);
// The platform TLS stack (Qt) to the same host: a second opinion that is not our fingerprint. result: ok or the class.
[[nodiscard]] ProbeResult ProbePlatformTls(
const QString &address,
int port,
const QString &sni,
int timeoutMs);
} // namespace Zsg::PathTest