Every session dialled a proxy on its own with nothing in between, so a cold start or a proxy switch opened one socket per session per account in the same millisecond. A public mtproxy answers about two parallel handshakes and silently drops the rest, which the client read back as client_hello_sent_no_server_hello or connected_no_mtproto_data across the whole batch - including on a dd-secret proxy that sends no ClientHello at all and therefore cannot be fingerprint-blocked. Replace the machinery that was supposed to prevent this with a rate limiter that actually does. ProxyDialLease keeps at most two unproven handshakes in flight per proxy server, spaces the rest apart and stretches the spacing after a run of attempts that proved nothing, so a blackholed proxy is no longer redialled by every session on its own eight second timer. Everything that reacted to failure by changing its own behaviour is gone: EndpointAdmissionArbiter, EndpointLivePool, ConnectionBroker, session_proxy_adapter, SessionProxyPort, HandshakeGate, open_scheduler, endpoint_health, adaptive_policy and ProxyRotationManager. A fingerprint filter is deterministic, so rotating emulated ClientHello profiles only hands the other side more of them, and escalated recipes (fragmentation, pacing) make the flow less browser-like rather than more - while the signal that drove the escalation could not tell a DPI box from a proxy refusing extra connections. The ClientHello templates themselves are untouched and the profile is now whatever the user configured, fixed. Also: ServerHello budget 2.5s -> 5s, mtproxy status reduces through the same ProxyConnectionStatus path as every other proxy type, and route memory is wired back up so an address that answered is dialled first and one that failed is dialled last. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
87 lines
2.1 KiB
C++
87 lines
2.1 KiB
C++
/*
|
|
This file is part of Telegram Desktop,
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
For license and copyright information please follow this link:
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
*/
|
|
#include "mtproto/proxy/proxy_endpoint_context.h"
|
|
|
|
#include <utility>
|
|
|
|
namespace MTP {
|
|
|
|
ProxyRuntimeId ProxyEndpointContext::registerRuntime() {
|
|
QMutexLocker lock(&_mutex);
|
|
const auto result = ++_lastRuntimeId;
|
|
_runtimes.emplace(result);
|
|
return result;
|
|
}
|
|
|
|
void ProxyEndpointContext::unregisterRuntime(ProxyRuntimeId runtimeId) {
|
|
QMutexLocker lock(&_mutex);
|
|
_runtimes.erase(runtimeId);
|
|
for (auto i = begin(_activeTraces); i != end(_activeTraces);) {
|
|
if (i->second.runtimeId == runtimeId) {
|
|
i = _activeTraces.erase(i);
|
|
} else {
|
|
++i;
|
|
}
|
|
}
|
|
}
|
|
|
|
ProxyTraceId ProxyEndpointContext::nextTraceId(
|
|
ProxyConnectionAttempt attempt) {
|
|
QMutexLocker lock(&_mutex);
|
|
const auto result = ++_lastTraceId;
|
|
attempt.traceId = result;
|
|
_activeTraces.emplace(result, std::move(attempt));
|
|
return result;
|
|
}
|
|
|
|
void ProxyEndpointContext::updateTraceAttempt(
|
|
const ProxyConnectionAttempt &attempt) {
|
|
if (!attempt.traceId) {
|
|
return;
|
|
}
|
|
QMutexLocker lock(&_mutex);
|
|
const auto i = _activeTraces.find(attempt.traceId);
|
|
if (i != end(_activeTraces)) {
|
|
i->second = attempt;
|
|
}
|
|
}
|
|
|
|
bool ProxyEndpointContext::traceActive(ProxyTraceId traceId) const {
|
|
if (!traceId) {
|
|
return false;
|
|
}
|
|
QMutexLocker lock(&_mutex);
|
|
return _activeTraces.contains(traceId);
|
|
}
|
|
|
|
auto ProxyEndpointContext::activeTracesForRuntime(
|
|
ProxyRuntimeId runtimeId) const
|
|
-> std::vector<ProxyConnectionAttempt> {
|
|
auto result = std::vector<ProxyConnectionAttempt>();
|
|
QMutexLocker lock(&_mutex);
|
|
for (const auto &[traceId, attempt] : _activeTraces) {
|
|
if (attempt.runtimeId == runtimeId) {
|
|
result.push_back(attempt);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
bool ProxyEndpointContext::finishTrace(ProxyTraceId traceId) {
|
|
if (!traceId) {
|
|
return false;
|
|
}
|
|
QMutexLocker lock(&_mutex);
|
|
return _activeTraces.erase(traceId) > 0;
|
|
}
|
|
|
|
std::shared_ptr<ProxyEndpointContext> CreateProxyEndpointContext() {
|
|
return std::make_shared<ProxyEndpointContext>();
|
|
}
|
|
|
|
} // namespace MTP
|