This fork extends TDLib with Telegram network quality testing.
Original TDLib repository: tdlib/td
The network check is a utility feature that estimates how stable and fast a Telegram client can work under current network conditions. It runs a sequence of measurements and returns a final score with detailed diagnostics.
All network check implementation code in this fork is located in tg-connection-core/.
- availability and latency to current Telegram DCs;
- TCP connection stability (success rate, p50/p95, jitter);
- MTProto response performance (via
testProxy); - Telegram media loading speed;
- indirect signs of unstable connectivity (frequent reconnects).
- before sensitive flows (login, sync, media loading);
- to choose retry timing and strategy;
- to show network status and recommendations to users;
- for internal monitoring of real-world connection quality.
#include "tg-connection-core/connection/TdConnection.h"
class MyLogger final : public ExternalLogger {
public:
void log(int level, const std::string &message) override {
std::cout << "[" << level << "] " << message << std::endl;
}
};
int main() {
TdConnection::TdlibCredentials creds;
creds.api_id = 123456;
creds.api_hash = "your_api_hash";
auto logger = std::make_unique<MyLogger>();
TdConnection connection(std::move(logger), std::move(creds));
connection.start("./td_db", "./td_files", "");
ConnectionTestResult result = connection.check_connection(60000);
std::cout << result.summary() << std::endl;
connection.quit();
return 0;
}Native create now accepts TDLib credentials (apiId, apiHash).
Kotlin/Java declaration example:
private external fun nativeCreate(
nativeLogger: NativeLogger,
apiId: Int,
apiHash: String
): LongUsage example:
val nativePtr = nativeCreate(logger, apiId, apiHash)
nativeStart(nativePtr, databaseDir, filesDir, caPath)
val result = nativeCheckConnection(nativePtr, 60_000)From repository root:
cd tg-connection-core/android
./build-openssl.sh <ANDROID_SDK_ROOT> <ANDROID_NDK_VERSION> third-party/openssl OpenSSL_1_1_1wExample:
./build-openssl.sh ~/Android/Sdk 23.2.8568313 third-party/openssl OpenSSL_1_1_1wThis also builds cURL into tg-connection-core/android/third-party/curl/<abi>/....
./build-tdlib.sh <ANDROID_SDK_ROOT> <ANDROID_NDK_VERSION> third-party/openssl c++_static JavaExample:
./build-tdlib.sh ~/Android/Sdk 23.2.8568313 third-party/openssl c++_static JavaMain output directory:
tg-connection-core/android/tdlib/libs/<abi>/
Artifacts include:
libtdjni.so(your JNI bridge with network check);libtd*.soproduced by TDLib build;- optionally
libcrypto.soandlibssl.soif shared OpenSSL was built; libc++_shared.soif built withc++_shared.
Additionally, packaged archives are created in:
tg-connection-core/android/tdlib/tdlib.ziptg-connection-core/android/tdlib/tdlib-debug.zip
Copy all .so files per ABI into your Android module:
app/src/main/jniLibs/arm64-v8a/*.soapp/src/main/jniLibs/armeabi-v7a/*.soapp/src/main/jniLibs/x86_64/*.soapp/src/main/jniLibs/x86/*.so
Then:
- load native library in app startup (usually
System.loadLibrary("tdjni")); - pass
apiIdandapiHashtonativeCreate(...); - call
nativeStart(...)andnativeCheckConnection(...)from your wrapper.
Create tg-connection-core/cpp/tdlib_credentials.env from example:
cp tg-connection-core/cpp/tdlib_credentials.env.example tg-connection-core/cpp/tdlib_credentials.envSet values:
API_ID=123456
API_HASH=your_api_hash_hereFrom repository root:
cmake -S tg-connection-core/cpp -B tg-connection-core/cpp/build-local
cmake --build tg-connection-core/cpp/build-local --config Release -j./tg-connection-core/cpp/build-local/connection_testInteractive commands:
cruns connection test;qquits.
Telegram connection quality: Excellent (96.8/100)
MTProto score: 82.9/100
TCP score: 89.5/100
Media score: 89.5/100
TestProxy:
p50=161.8ms, p95=163.3ms, jitter=0.6ms, success=100.0%
TCP (best DCs):
149.154.167.51:80 p50=0.2ms p95=0.3ms success=100.0%
149.154.171.5:80 p50=0.3ms p95=0.4ms success=100.0%
149.154.167.91:443 p50=0.2ms p95=0.5ms success=100.0%
149.154.171.5:5222 p50=0.3ms p95=0.3ms success=100.0%
149.154.171.5:443 p50=0.2ms p95=0.4ms success=100.0%
Connection states:
Ready: 1
TG Connection is a diagnostic app for analyzing the quality, stability, and reliability of your connection to Telegram servers. If messages are delayed, media is loading inconsistently, or you suspect network issues, the app can help you understand the cause.