Limit special config request types.

This commit is contained in:
John Preston 2023-01-10 15:03:37 +04:00
parent 05911a7172
commit 1176421bf2
4 changed files with 25 additions and 14 deletions

View File

@ -116,7 +116,7 @@ void ConfigLoader::enumerate() {
}
void ConfigLoader::refreshSpecialLoader() {
if (_proxyEnabled) {
if (_proxyEnabled || _instance->isKeysDestroyer()) {
_specialLoader.reset();
return;
}
@ -136,6 +136,7 @@ void ConfigLoader::setPhone(const QString &phone) {
}
void ConfigLoader::createSpecialLoader() {
const auto testMode = _instance->isTestMode();
_triedSpecialEndpoints.clear();
_specialLoader = std::make_unique<SpecialConfigRequest>([=](
DcId dcId,
@ -147,7 +148,7 @@ void ConfigLoader::createSpecialLoader() {
} else {
addSpecialEndpoint(dcId, ip, port, secret);
}
}, _instance->configValues().txtDomainString, _phone);
}, testMode, _instance->configValues().txtDomainString, _phone);
}
void ConfigLoader::addSpecialEndpoint(

View File

@ -542,7 +542,7 @@ void Instance::Private::syncHttpUnixtime() {
InvokeQueued(_instance, [=] {
_httpUnixtimeLoader = nullptr;
});
}, configValues().txtDomainString);
}, isTestMode(), configValues().txtDomainString);
}
void Instance::Private::restartedByTimeout(ShiftedDcId shiftedDcId) {

View File

@ -188,6 +188,7 @@ SpecialConfigRequest::SpecialConfigRequest(
int port,
bytes::const_span secret)> callback,
Fn<void()> timeDoneCallback,
bool isTestMode,
const QString &domainString,
const QString &phone)
: _callback(std::move(callback))
@ -219,14 +220,9 @@ SpecialConfigRequest::SpecialConfigRequest(
_attempts = {};
_attempts.push_back({ Type::Google, "dns.google.com" });
_attempts.push_back({ Type::Google, takeDomain(), "dns" });
_attempts.push_back({ Type::Mozilla, "mozilla.cloudflare-dns.com" });
_attempts.push_back({ Type::RemoteConfig, "firebaseremoteconfig" });
while (!domains.empty()) {
_attempts.push_back({ Type::Google, takeDomain(), "dns" });
}
if (!_timeDoneCallback) {
_attempts.push_back({ Type::Realtime, "firebaseio.com" });
_attempts.push_back({ Type::FireStore, "firestore" });
for (const auto &domain : DnsDomains()) {
_attempts.push_back({ Type::FireStore, domain, "firestore" });
@ -234,12 +230,15 @@ SpecialConfigRequest::SpecialConfigRequest(
}
shuffle(0, 2);
shuffle(2, 4);
if (!_timeDoneCallback) {
shuffle(
_attempts.size() - (2 + domainsCount),
_attempts.size() - domainsCount);
shuffle(_attempts.size() - domainsCount, _attempts.size());
shuffle(_attempts.size() - (domainsCount + 1), _attempts.size());
}
if (isTestMode) {
_attempts.erase(ranges::remove_if(_attempts, [](
const Attempt &attempt) {
return (attempt.type != Type::Google)
&& (attempt.type != Type::Mozilla);
}), _attempts.end());
}
ranges::reverse(_attempts); // We go from last to first.
@ -252,17 +251,25 @@ SpecialConfigRequest::SpecialConfigRequest(
const std::string &ip,
int port,
bytes::const_span secret)> callback,
bool isTestMode,
const QString &domainString,
const QString &phone)
: SpecialConfigRequest(std::move(callback), nullptr, domainString, phone) {
: SpecialConfigRequest(
std::move(callback),
nullptr,
isTestMode,
domainString,
phone) {
}
SpecialConfigRequest::SpecialConfigRequest(
Fn<void()> timeDoneCallback,
bool isTestMode,
const QString &domainString)
: SpecialConfigRequest(
nullptr,
std::move(timeDoneCallback),
isTestMode,
domainString,
QString()) {
}

View File

@ -25,10 +25,12 @@ public:
const std::string &ip,
int port,
bytes::const_span secret)> callback,
bool isTestMode,
const QString &domainString,
const QString &phone);
SpecialConfigRequest(
Fn<void()> timeDoneCallback,
bool isTestMode,
const QString &domainString);
private:
@ -52,6 +54,7 @@ private:
int port,
bytes::const_span secret)> callback,
Fn<void()> timeDoneCallback,
bool isTestMode,
const QString &domainString,
const QString &phone);