mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-04-01 23:00:58 +00:00
Apply proxy settings in mtproto-key-destroyer.
This commit is contained in:
parent
4478c0a143
commit
425e56b3ea
@ -1069,7 +1069,7 @@ void ProxiesBoxController::ShowApplyConfirmation(
|
|||||||
if (ranges::find(proxies, proxy) == end(proxies)) {
|
if (ranges::find(proxies, proxy) == end(proxies)) {
|
||||||
proxies.push_back(proxy);
|
proxies.push_back(proxy);
|
||||||
}
|
}
|
||||||
Messenger::Instance().mtp()->setCurrentProxy(proxy, true);
|
Messenger::Instance().setCurrentProxy(proxy, true);
|
||||||
Local::writeSettings();
|
Local::writeSettings();
|
||||||
if (const auto strong = box->data()) {
|
if (const auto strong = box->data()) {
|
||||||
strong->closeBox();
|
strong->closeBox();
|
||||||
@ -1230,7 +1230,7 @@ void ProxiesBoxController::applyItem(int id) {
|
|||||||
|
|
||||||
auto j = findByProxy(Global::SelectedProxy());
|
auto j = findByProxy(Global::SelectedProxy());
|
||||||
|
|
||||||
Messenger::Instance().mtp()->setCurrentProxy(item->data, true);
|
Messenger::Instance().setCurrentProxy(item->data, true);
|
||||||
saveDelayed();
|
saveDelayed();
|
||||||
|
|
||||||
if (j != end(_list)) {
|
if (j != end(_list)) {
|
||||||
@ -1251,7 +1251,7 @@ void ProxiesBoxController::setDeleted(int id, bool deleted) {
|
|||||||
_lastSelectedProxy = base::take(Global::RefSelectedProxy());
|
_lastSelectedProxy = base::take(Global::RefSelectedProxy());
|
||||||
if (Global::UseProxy()) {
|
if (Global::UseProxy()) {
|
||||||
_lastSelectedProxyUsed = true;
|
_lastSelectedProxyUsed = true;
|
||||||
Messenger::Instance().mtp()->setCurrentProxy(
|
Messenger::Instance().setCurrentProxy(
|
||||||
ProxyData(),
|
ProxyData(),
|
||||||
false);
|
false);
|
||||||
saveDelayed();
|
saveDelayed();
|
||||||
@ -1276,7 +1276,7 @@ void ProxiesBoxController::setDeleted(int id, bool deleted) {
|
|||||||
Assert(!Global::UseProxy());
|
Assert(!Global::UseProxy());
|
||||||
|
|
||||||
if (base::take(_lastSelectedProxyUsed)) {
|
if (base::take(_lastSelectedProxyUsed)) {
|
||||||
Messenger::Instance().mtp()->setCurrentProxy(
|
Messenger::Instance().setCurrentProxy(
|
||||||
base::take(_lastSelectedProxy),
|
base::take(_lastSelectedProxy),
|
||||||
true);
|
true);
|
||||||
} else {
|
} else {
|
||||||
@ -1381,7 +1381,7 @@ bool ProxiesBoxController::setProxyEnabled(bool enabled) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Messenger::Instance().mtp()->setCurrentProxy(
|
Messenger::Instance().setCurrentProxy(
|
||||||
Global::SelectedProxy(),
|
Global::SelectedProxy(),
|
||||||
enabled);
|
enabled);
|
||||||
saveDelayed();
|
saveDelayed();
|
||||||
|
@ -278,13 +278,42 @@ bool Messenger::eventFilter(QObject *object, QEvent *e) {
|
|||||||
return QObject::eventFilter(object, e);
|
return QObject::eventFilter(object, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Messenger::setCurrentProxy(
|
||||||
|
const ProxyData &proxy,
|
||||||
|
bool enabled) {
|
||||||
|
const auto key = [&](const ProxyData &proxy) {
|
||||||
|
if (proxy.type == ProxyData::Type::Mtproto) {
|
||||||
|
return std::make_pair(proxy.host, proxy.port);
|
||||||
|
}
|
||||||
|
return std::make_pair(QString(), uint32(0));
|
||||||
|
};
|
||||||
|
const auto previousKey = key(Global::UseProxy()
|
||||||
|
? Global::SelectedProxy()
|
||||||
|
: ProxyData());
|
||||||
|
Global::SetSelectedProxy(proxy);
|
||||||
|
Global::SetUseProxy(enabled);
|
||||||
|
Sandbox::refreshGlobalProxy();
|
||||||
|
if (_mtproto) {
|
||||||
|
_mtproto->restart();
|
||||||
|
if (previousKey != key(proxy)) {
|
||||||
|
_mtproto->reInitConnection(_mtproto->mainDcId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_mtprotoForKeysDestroy) {
|
||||||
|
_mtprotoForKeysDestroy->restart();
|
||||||
|
}
|
||||||
|
Global::RefConnectionTypeChanged().notify();
|
||||||
|
}
|
||||||
|
|
||||||
void Messenger::setMtpMainDcId(MTP::DcId mainDcId) {
|
void Messenger::setMtpMainDcId(MTP::DcId mainDcId) {
|
||||||
Expects(!_mtproto);
|
Expects(!_mtproto);
|
||||||
|
|
||||||
_private->mtpConfig.mainDcId = mainDcId;
|
_private->mtpConfig.mainDcId = mainDcId;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Messenger::setMtpKey(MTP::DcId dcId, const MTP::AuthKey::Data &keyData) {
|
void Messenger::setMtpKey(MTP::DcId dcId, const MTP::AuthKey::Data &keyData) {
|
||||||
Expects(!_mtproto);
|
Expects(!_mtproto);
|
||||||
|
|
||||||
_private->mtpConfig.keys.push_back(std::make_shared<MTP::AuthKey>(MTP::AuthKey::Type::ReadFromFile, dcId, keyData));
|
_private->mtpConfig.keys.push_back(std::make_shared<MTP::AuthKey>(MTP::AuthKey::Type::ReadFromFile, dcId, keyData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,6 +98,7 @@ public:
|
|||||||
MTP::DcOptions *dcOptions() {
|
MTP::DcOptions *dcOptions() {
|
||||||
return _dcOptions.get();
|
return _dcOptions.get();
|
||||||
}
|
}
|
||||||
|
void setCurrentProxy(const ProxyData &proxy, bool enabled);
|
||||||
|
|
||||||
// Set from legacy storage.
|
// Set from legacy storage.
|
||||||
void setMtpMainDcId(MTP::DcId mainDcId);
|
void setMtpMainDcId(MTP::DcId mainDcId);
|
||||||
|
@ -38,7 +38,6 @@ public:
|
|||||||
|
|
||||||
void start(Config &&config);
|
void start(Config &&config);
|
||||||
|
|
||||||
void setCurrentProxy(const ProxyData &proxy, bool enabled);
|
|
||||||
void resolveProxyDomain(const QString &host);
|
void resolveProxyDomain(const QString &host);
|
||||||
void setGoodProxyDomain(const QString &host, const QString &ip);
|
void setGoodProxyDomain(const QString &host, const QString &ip);
|
||||||
void suggestMainDcId(DcId mainDcId);
|
void suggestMainDcId(DcId mainDcId);
|
||||||
@ -274,28 +273,6 @@ void Instance::Private::start(Config &&config) {
|
|||||||
requestConfig();
|
requestConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::Private::setCurrentProxy(
|
|
||||||
const ProxyData &proxy,
|
|
||||||
bool enabled) {
|
|
||||||
const auto key = [&](const ProxyData &proxy) {
|
|
||||||
if (proxy.type == ProxyData::Type::Mtproto) {
|
|
||||||
return std::make_pair(proxy.host, proxy.port);
|
|
||||||
}
|
|
||||||
return std::make_pair(QString(), uint32(0));
|
|
||||||
};
|
|
||||||
const auto previousKey = key(Global::UseProxy()
|
|
||||||
? Global::SelectedProxy()
|
|
||||||
: ProxyData());
|
|
||||||
Global::SetSelectedProxy(proxy);
|
|
||||||
Global::SetUseProxy(enabled);
|
|
||||||
Sandbox::refreshGlobalProxy();
|
|
||||||
restart();
|
|
||||||
if (previousKey != key(proxy)) {
|
|
||||||
reInitConnection(mainDcId());
|
|
||||||
}
|
|
||||||
Global::RefConnectionTypeChanged().notify();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Instance::Private::resolveProxyDomain(const QString &host) {
|
void Instance::Private::resolveProxyDomain(const QString &host) {
|
||||||
if (!_domainResolver) {
|
if (!_domainResolver) {
|
||||||
_domainResolver = std::make_unique<DomainResolver>([=](
|
_domainResolver = std::make_unique<DomainResolver>([=](
|
||||||
@ -1467,10 +1444,6 @@ Instance::Instance(not_null<DcOptions*> options, Mode mode, Config &&config)
|
|||||||
_private->start(std::move(config));
|
_private->start(std::move(config));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Instance::setCurrentProxy(const ProxyData &proxy, bool enabled) {
|
|
||||||
_private->setCurrentProxy(proxy, enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Instance::resolveProxyDomain(const QString &host) {
|
void Instance::resolveProxyDomain(const QString &host) {
|
||||||
_private->resolveProxyDomain(host);
|
_private->resolveProxyDomain(host);
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,6 @@ public:
|
|||||||
Instance(const Instance &other) = delete;
|
Instance(const Instance &other) = delete;
|
||||||
Instance &operator=(const Instance &other) = delete;
|
Instance &operator=(const Instance &other) = delete;
|
||||||
|
|
||||||
void setCurrentProxy(const ProxyData &proxy, bool enabled);
|
|
||||||
void resolveProxyDomain(const QString &host);
|
void resolveProxyDomain(const QString &host);
|
||||||
void setGoodProxyDomain(const QString &host, const QString &ip);
|
void setGoodProxyDomain(const QString &host, const QString &ip);
|
||||||
void suggestMainDcId(DcId mainDcId);
|
void suggestMainDcId(DcId mainDcId);
|
||||||
|
Loading…
Reference in New Issue
Block a user