diff --git a/Telegram/SourceFiles/boxes/connection_box.cpp b/Telegram/SourceFiles/boxes/connection_box.cpp index 15c1bc5c2..66d6557cb 100644 --- a/Telegram/SourceFiles/boxes/connection_box.cpp +++ b/Telegram/SourceFiles/boxes/connection_box.cpp @@ -1108,7 +1108,7 @@ void ProxiesBoxController::refreshChecker(Item &item) { checker->connectToServer( QString::fromStdString(endpoints.front().ip), endpoints.front().port, - endpoints.front().protocolSecret, + endpoints.front().secret, dcId); } }; diff --git a/Telegram/SourceFiles/mtproto/config_loader.cpp b/Telegram/SourceFiles/mtproto/config_loader.cpp index 0eb3742ed..4caa94a0f 100644 --- a/Telegram/SourceFiles/mtproto/config_loader.cpp +++ b/Telegram/SourceFiles/mtproto/config_loader.cpp @@ -52,7 +52,7 @@ mtpRequestId ConfigLoader::sendRequest(ShiftedDcId shiftedDcId) { } DcId ConfigLoader::specialToRealDcId(DcId specialDcId) { - return Instance::Config::kTemporaryMainDc + specialDcId; + return getTemporaryIdFromRealDcId(specialDcId); } void ConfigLoader::terminateRequest() { @@ -139,15 +139,18 @@ void ConfigLoader::sendSpecialRequest() { const auto weak = base::make_weak(this); const auto index = rand_value() % _specialEndpoints.size(); - const auto secret = bytes::vector(); const auto endpoint = _specialEndpoints.begin() + index; _specialEnumCurrent = specialToRealDcId(endpoint->dcId); + + using Flag = MTPDdcOption::Flag; + const auto flags = Flag::f_tcpo_only + | (endpoint->secret.empty() ? Flag(0) : Flag::f_secret); _instance->dcOptions()->constructAddOne( _specialEnumCurrent, - MTPDdcOption::Flag::f_tcpo_only, + flags, endpoint->ip, endpoint->port, - secret); + endpoint->secret); _specialEnumRequest = _instance->send( MTPhelp_GetConfig(), rpcDone([weak](const MTPConfig &result) { diff --git a/Telegram/SourceFiles/mtproto/config_loader.h b/Telegram/SourceFiles/mtproto/config_loader.h index 5c4abd66e..1728853e2 100644 --- a/Telegram/SourceFiles/mtproto/config_loader.h +++ b/Telegram/SourceFiles/mtproto/config_loader.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/timer.h" #include "base/weak_ptr.h" +#include "base/bytes.h" #include "mtproto/rpc_sender.h" namespace MTP { @@ -45,6 +46,7 @@ private: DcId dcId; std::string ip; int port; + bytes::vector secret; }; friend bool operator==(const SpecialEndpoint &a, const SpecialEndpoint &b); std::unique_ptr _specialLoader; diff --git a/Telegram/SourceFiles/mtproto/connection.cpp b/Telegram/SourceFiles/mtproto/connection.cpp index 46956239d..77f6592b5 100644 --- a/Telegram/SourceFiles/mtproto/connection.cpp +++ b/Telegram/SourceFiles/mtproto/connection.cpp @@ -415,7 +415,6 @@ ConnectionPrivate::ConnectionPrivate( , _state(DisconnectedState) , _shiftedDcId(shiftedDcId) , _owner(owner) -, _configWasFineAt(getms(true)) , _retryTimer(thread, [=] { retryByTimer(); }) , _oldConnectionTimer(thread, [=] { markConnectionOld(); }) , _waitForConnectedTimer(thread, [=] { waitConnectedFailed(); }) @@ -1120,7 +1119,7 @@ void ConnectionPrivate::connectToServer(bool afterConfig) { static_cast(protocol), QString::fromStdString(endpoint.ip), endpoint.port, - endpoint.protocolSecret); + endpoint.secret); } } } @@ -1142,7 +1141,9 @@ void ConnectionPrivate::connectToServer(bool afterConfig) { return; } - if (getms(true) - _configWasFineAt > kRequestConfigTimeout) { + if (!_startedConnectingAt) { + _startedConnectingAt = getms(true); + } else if (getms(true) - _startedConnectingAt > kRequestConfigTimeout) { InvokeQueued(_instance, [instance = _instance] { instance->requestConfigIfOld(); }); @@ -1549,6 +1550,7 @@ void ConnectionPrivate::handleReceived() { DEBUG_LOG(("MTP Info: marked auth key as checked")); sessionData->setCheckedKey(true); } + _startedConnectingAt = TimeMs(0); if (!wasConnected) { if (getState() == ConnectedState) { @@ -2456,8 +2458,6 @@ void ConnectionPrivate::updateAuthKey() { QReadLocker lockFinished(&sessionDataMutex); if (!sessionData || !_connection) return; - _configWasFineAt = getms(true); - DEBUG_LOG(("AuthKey Info: Connection updating key from Session, dc %1").arg(_shiftedDcId)); uint64 newKeyId = 0; { diff --git a/Telegram/SourceFiles/mtproto/connection.h b/Telegram/SourceFiles/mtproto/connection.h index f77b870ce..e19f89a8f 100644 --- a/Telegram/SourceFiles/mtproto/connection.h +++ b/Telegram/SourceFiles/mtproto/connection.h @@ -227,7 +227,7 @@ private: not_null _owner; ConnectionPointer _connection; std::vector _testConnections; - TimeMs _configWasFineAt = 0; + TimeMs _startedConnectingAt = 0; base::Timer _retryTimer; // exp retry timer int _retryTimeout = 1; diff --git a/Telegram/SourceFiles/mtproto/dc_options.cpp b/Telegram/SourceFiles/mtproto/dc_options.cpp index d9f97c3a8..2ab6281af 100644 --- a/Telegram/SourceFiles/mtproto/dc_options.cpp +++ b/Telegram/SourceFiles/mtproto/dc_options.cpp @@ -62,7 +62,9 @@ AQIDAQAB\n\ class DcOptions::WriteLocker { public: - WriteLocker(DcOptions *that) : _that(that), _lock(&_that->_useThroughLockers) { + WriteLocker(not_null that) + : _that(that) + , _lock(&_that->_useThroughLockers) { } ~WriteLocker() { _that->computeCdnDcIds(); @@ -76,7 +78,8 @@ private: class DcOptions::ReadLocker { public: - ReadLocker(const DcOptions *that) : _lock(&that->_useThroughLockers) { + ReadLocker(not_null that) + : _lock(&that->_useThroughLockers) { } private: @@ -105,28 +108,18 @@ void DcOptions::constructFromBuiltIn() { auto bdcs = builtInDcs(); for (auto i = 0, l = builtInDcsCount(); i != l; ++i) { - const auto flags = MTPDdcOption::Flags(0); + const auto flags = Flag::f_static | 0; const auto bdc = bdcs[i]; - const auto idWithShift = MTP::shiftDcId(bdc.id, flags); - _data.emplace( - idWithShift, - std::vector