ZaStoGram/TMessagesProj/jni/tgnet/pathtest/PathTestProbe.h
loop-uh a918b73f48
Some checks failed
Build three ZaStoGram APKs / build (armeabi-v7a, ZaStoGram-standalone-armeabi-v7a, Armv7, armv7) (push) Failing after 49s
Build three ZaStoGram APKs / build (arm64-v8a, ZaStoGram-standalone-arm64-v8a, Arm64, arm64) (push) Failing after 51s
ZaStoGram source guards / guards (push) Failing after 40s
Build three ZaStoGram APKs / build (x86, ZaStoGram-standalone-x86, X86, x86) (push) Failing after 1m8s
Check connection: a path test that runs the real client code and writes one log
New module (jni/tgnet/pathtest, org.telegram.zastogram.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 text log with a
JSONL twin into the logs folder (so the logs screen and its zip export carry it): 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.

The probe is not a second client: Naive entries go through naive::CreateFor, the WSS route through the real
wss::Socket (setDiagnosticProbe switches off route-health writes), FakeTLS profiles through composeFakeTlsClientHello,
now the single place ConnectionSocket also builds its hello. The probe peeks the first server bytes to classify the
answer. Secrets are never read (random FakeTLS key, throw-away Naive credentials, only the cover domain of a secret),
hosts are ep-<8 hex of sha256(host:port)> unless real names are ticked, every log field is a closed-vocabulary token.

UI: a row in the proxy settings, an offer after a failed proxy check, share button. Tests: JVM tests of the pure
logic, a native host test against the real WssSocket.cpp and local servers (silent, fin, rst, alert, http, overloaded),
guards updated for the shared hello composer. Verified on an x86_64 emulator against lab shapes and the real relay.

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

53 lines
2.4 KiB
C++

/*
* "Check connection" probe: measures what a network does to the REAL client.
*
* Nothing here builds a hello of its own. A WSS or Naive attempt drives the real transport::Socket (wss::Socket,
* naive::Socket: the libzsgnaive Chrome handshake the app really uses) from a private poll loop; a FakeTLS attempt
* sends the bytes of composeFakeTlsClientHello (the composer ConnectionSocket uses). The probe only watches: before
* the real socket consumes its input it peeks the first bytes to classify the answer, and it times the steps.
*/
#ifndef TGNET_PATHTEST_PROBE_H
#define TGNET_PATHTEST_PROBE_H
#include <stdint.h>
#include <sys/socket.h>
#include <string>
#include "../transport/TransportSocket.h"
namespace tgnet {
namespace pathtest {
struct Result {
// server_hello | alert | rst | fin | silent | connect_failed | other
std::string cls = "silent";
int64_t tcpMs = -1; // TCP connect time, -1 if it never connected
int64_t ttfbMs = -1; // time from TCP connected to the first byte of the server's answer, -1 if none
int64_t totalMs = 0;
// What happened after TLS: tunnel_open | tunnel_refused | upgrade_ok | upgrade_refused | timeout, or empty.
std::string app;
// Closed vocabulary (lower case, [a-z0-9_.:=-]): the real socket's own diagnostic, normalised.
std::string detail;
};
// Drives |socket| (already configured; for a wss::Socket setDiagnosticProbe(true) must have been called) from open()
// to the end of the handshake. After TLS is ready it waits up to |afterTlsMs| for the application-level outcome.
Result ProbeTransport(transport::Socket &socket, const sockaddr *address, socklen_t length, int timeoutMs, int afterTlsMs);
// Plain TCP connect, send |hello| (a complete TLS record, e.g. from composeFakeTlsClientHello), wait for the
// server's first bytes and classify them.
Result ProbeRawHello(const sockaddr *address, socklen_t length, const uint8_t *hello, uint32_t helloSize, int timeoutMs);
// Classification of the first bytes of a server answer (at least 1 byte): "server_hello", "alert" or "other".
const char *ClassifyFirstBytes(const uint8_t *data, size_t size);
// Lower-cases and reduces free text to the closed vocabulary, at most 48 characters.
std::string Token(const std::string &text);
// "class=...;tcp_ms=...;ttfb_ms=...;total_ms=...;app=...;detail=..." (what the Java runner parses).
std::string Encode(const Result &result);
} // namespace pathtest
} // namespace tgnet
#endif