Remove mtproto/facade.h from main pch.

This commit is contained in:
John Preston 2019-11-13 11:31:12 +03:00
parent 0c0c8f3584
commit 2577bedeac
33 changed files with 133 additions and 73 deletions

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "boxes/calendar_box.h"
#include "mtproto/rpc_sender.h"
#include "ui/widgets/buttons.h"
#include "lang/lang_keys.h"
#include "ui/effects/ripple_animation.h"

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once
#include "boxes/abstract_box.h"
#include "mtproto/rpc_sender.h"
namespace Main {
class Session;

View file

@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "numbers.h"
#include "app.h"
#include "lang/lang_keys.h"
#include "mtproto/facade.h"
#include "styles/style_layers.h"
#include "styles/style_boxes.h"

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/abstract_box.h"
#include "base/timer.h"
#include "ui/widgets/input_fields.h"
#include "mtproto/rpc_sender.h"
namespace Ui {
class InputField;

View file

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "storage/storage_media_prepare.h"
#include "ui/wrap/slide_wrap.h"
#include "media/clip/media_clip_reader.h"
#include "mtproto/rpc_sender.h"
namespace ChatHelpers {
class TabbedPanel;

View file

@ -10,6 +10,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/abstract_box.h"
#include "base/unique_qptr.h"
class RPCError;
namespace Ui {
class FlatLabel;
class LinkButton;

View file

@ -14,6 +14,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/buttons.h"
#include "ui/widgets/input_fields.h"
#include "ui/toast/toast.h"
#include "mtproto/facade.h"
#include "mainwindow.h"
#include "styles/style_layers.h"
#include "styles/style_boxes.h"

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once
#include "boxes/abstract_box.h"
#include "mtproto/rpc_sender.h"
namespace Ui {
template <typename Enum>

View file

@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/timer.h"
#include "ui/effects/animations.h"
#include "ui/effects/round_checkbox.h"
#include "mtproto/rpc_sender.h"
enum class SendMenuType;

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once
#include "boxes/abstract_box.h"
#include "mtproto/rpc_sender.h"
namespace Ui {
class UsernameInput;

View file

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/rp_widget.h"
#include "base/flags.h"
#include "base/object_ptr.h"
#include "mtproto/rpc_sender.h"
namespace Main {
class Session;

View file

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/scroll_area.h"
#include "ui/special_buttons.h"
#include "api/api_single_message_search.h"
#include "mtproto/rpc_sender.h"
namespace Main {
class Session;

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once
#include "mtproto/auth_key.h"
#include "mtproto/mtp_instance.h"
#include "base/weak_ptr.h"
namespace Main {

View file

@ -15,6 +15,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
class ApiWrap;
namespace MTP {
class Instance;
} // namespace MTP
namespace Support {
class Helper;
class Templates;

View file

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/effects/animations.h"
#include "media/player/media_player_float.h"
#include "data/data_pts_waiter.h"
#include "mtproto/rpc_sender.h"
struct HistoryMessageMarkupButton;
class MainWindow;

View file

@ -14,6 +14,29 @@ extern "C" {
namespace MTP {
AuthKey::AuthKey(Type type, DcId dcId, const Data &data)
: _type(type)
, _dcId(dcId)
, _key(data) {
countKeyId();
}
AuthKey::AuthKey(const Data &data) : _type(Type::Local), _key(data) {
countKeyId();
}
AuthKey::Type AuthKey::type() const {
return _type;
}
int AuthKey::dcId() const {
return _dcId;
}
AuthKey::KeyId AuthKey::keyId() const {
return _keyId;
}
void AuthKey::prepareAES_oldmtp(const MTPint128 &msgKey, MTPint256 &aesKey, MTPint256 &aesIV, bool send) const {
uint32 x = send ? 0 : 8;
@ -72,6 +95,41 @@ void AuthKey::prepareAES(const MTPint128 &msgKey, MTPint256 &aesKey, MTPint256 &
memcpy(iv + 8 + 16, sha256_b + 24, 8);
}
const void *AuthKey::partForMsgKey(bool send) const {
return _key.data() + 88 + (send ? 0 : 8);
}
void AuthKey::write(QDataStream &to) const {
to.writeRawData(reinterpret_cast<const char*>(_key.data()), _key.size());
}
bytes::const_span AuthKey::data() const {
return _key;
}
bool AuthKey::equals(const std::shared_ptr<AuthKey> &other) const {
return other ? (_key == other->_key) : false;
}
void AuthKey::FillData(Data &authKey, bytes::const_span computedAuthKey) {
auto computedAuthKeySize = computedAuthKey.size();
Assert(computedAuthKeySize <= kSize);
auto authKeyBytes = gsl::make_span(authKey);
if (computedAuthKeySize < kSize) {
bytes::set_with_const(authKeyBytes.subspan(0, kSize - computedAuthKeySize), gsl::byte());
bytes::copy(authKeyBytes.subspan(kSize - computedAuthKeySize), computedAuthKey);
} else {
bytes::copy(authKeyBytes, computedAuthKey);
}
}
void AuthKey::countKeyId() {
auto sha1 = hashSha1(_key.data(), _key.size());
// Lower 64 bits = 8 bytes of 20 byte SHA1 hash.
_keyId = *reinterpret_cast<KeyId*>(sha1.data() + 12);
}
void aesIgeEncryptRaw(const void *src, void *dst, uint32 len, const void *key, const void *iv) {
uchar aes_key[32], aes_iv[32];
memcpy(aes_key, key, 32);

View file

@ -7,9 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "base/bytes.h"
#include <array>
#include <memory>
#include "base/bytes.h"
namespace MTP {
@ -24,65 +24,29 @@ public:
ReadFromFile,
Local,
};
AuthKey(Type type, DcId dcId, const Data &data) : _type(type), _dcId(dcId), _key(data) {
countKeyId();
}
AuthKey(const Data &data) : _type(Type::Local), _key(data) {
countKeyId();
}
AuthKey(Type type, DcId dcId, const Data &data);
explicit AuthKey(const Data &data);
AuthKey(const AuthKey &other) = delete;
AuthKey &operator=(const AuthKey &other) = delete;
Type type() const {
return _type;
}
int dcId() const {
return _dcId;
}
KeyId keyId() const {
return _keyId;
}
Type type() const;
int dcId() const;
KeyId keyId() const;
void prepareAES_oldmtp(const MTPint128 &msgKey, MTPint256 &aesKey, MTPint256 &aesIV, bool send) const;
void prepareAES(const MTPint128 &msgKey, MTPint256 &aesKey, MTPint256 &aesIV, bool send) const;
const void *partForMsgKey(bool send) const {
return _key.data() + 88 + (send ? 0 : 8);
}
const void *partForMsgKey(bool send) const;
void write(QDataStream &to) const {
to.writeRawData(reinterpret_cast<const char*>(_key.data()), _key.size());
}
bytes::const_span data() const {
return _key;
}
void write(QDataStream &to) const;
bytes::const_span data() const;
bool equals(const std::shared_ptr<AuthKey> &other) const;
bool equals(const std::shared_ptr<AuthKey> &other) const {
return other ? (_key == other->_key) : false;
}
static void FillData(Data &authKey, bytes::const_span computedAuthKey) {
auto computedAuthKeySize = computedAuthKey.size();
Assert(computedAuthKeySize <= kSize);
auto authKeyBytes = gsl::make_span(authKey);
if (computedAuthKeySize < kSize) {
bytes::set_with_const(authKeyBytes.subspan(0, kSize - computedAuthKeySize), gsl::byte());
bytes::copy(authKeyBytes.subspan(kSize - computedAuthKeySize), computedAuthKey);
} else {
bytes::copy(authKeyBytes, computedAuthKey);
}
}
static void FillData(Data &authKey, bytes::const_span computedAuthKey);
private:
void countKeyId() {
auto sha1 = hashSha1(_key.data(), _key.size());
// Lower 64 bits = 8 bytes of 20 byte SHA1 hash.
_keyId = *reinterpret_cast<KeyId*>(sha1.data() + 12);
}
void countKeyId();
Type _type = Type::Generated;
DcId _dcId = 0;

View file

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/mtp_instance.h"
#include "mtproto/rpc_sender.h"
#include "mtproto/facade.h"
namespace MTP {

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "mtproto/config_loader.h"
#include "mtproto/facade.h"
#include "mtproto/dc_options.h"
#include "mtproto/mtp_instance.h"
#include "mtproto/special_config_request.h"

View file

@ -1187,7 +1187,7 @@ void ConnectionPrivate::connectToServer(bool afterConfig) {
if (_testConnections.empty()) {
if (_instance->isKeysDestroyer()) {
LOG(("MTP Error: DC %1 options for not found for auth key destruction!").arg(_shiftedDcId));
emit _instance->keyDestroyed(_shiftedDcId);
_instance->checkIfKeyWasDestroyed(_shiftedDcId);
return;
} else if (afterConfig) {
LOG(("MTP Error: DC %1 options for not found right after config load!").arg(_shiftedDcId));
@ -2606,7 +2606,7 @@ void ConnectionPrivate::updateAuthKey() {
} else if (_instance->isKeysDestroyer()) {
// We are here to destroy an old key, so we're done.
LOG(("MTP Error: No key %1 in updateAuthKey() for destroying.").arg(_shiftedDcId));
emit _instance->keyDestroyed(_shiftedDcId);
_instance->checkIfKeyWasDestroyed(_shiftedDcId);
return;
}
@ -3104,15 +3104,17 @@ void ConnectionPrivate::handleError(int errorCode) {
_waitForConnectedTimer.cancel();
if (errorCode == -404) {
if (_instance->isKeysDestroyer()) {
LOG(("MTP Info: -404 error received on destroying key %1, assuming it is destroyed.").arg(_shiftedDcId));
emit _instance->keyDestroyed(_shiftedDcId);
return;
} else if (_dcType == DcType::Cdn) {
if (_dcType == DcType::Cdn) {
LOG(("MTP Info: -404 error received in CDN dc %1, assuming it was destroyed, recreating.").arg(_shiftedDcId));
clearMessages();
keyId = kRecreateKeyId;
return restart();
} else {
LOG(("MTP Info: -404 error received, informing instance."));
_instance->checkIfKeyWasDestroyed(_shiftedDcId);
if (_instance->isKeysDestroyer()) {
return;
}
}
}
MTP_LOG(_shiftedDcId, ("Restarting after error in connection, error code: %1...").arg(errorCode));

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/auth_key.h"
#include "mtproto/dc_options.h"
#include "mtproto/connection_abstract.h"
#include "mtproto/facade.h"
#include "base/openssl_help.h"
#include "base/timer.h"

View file

@ -11,6 +11,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/bytes.h"
namespace MTP {
class Instance;
namespace internal {
struct ConnectionOptions;

View file

@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "mtproto/connection_resolving.h"
#include "mtproto/mtp_instance.h"
namespace MTP {
namespace internal {
namespace {

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "mtproto/dc_options.h"
#include "mtproto/facade.h"
#include "storage/serialize_common.h"
#include "mtproto/connection_tcp.h"

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "mtproto/dedicated_file_loader.h"
#include "mtproto/facade.h"
#include "main/main_session.h"
#include "main/main_account.h" // Account::sessionChanges.
#include "core/application.h"

View file

@ -7,9 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
namespace MTP {
#include "mtproto/mtp_instance.h"
class Instance;
namespace MTP {
class WeakInstance : private QObject, private base::Subscriber {
public:

View file

@ -17,8 +17,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "mtproto/rsa_public_key.h"
#include "storage/localstorage.h"
#include "calls/calls_instance.h"
#include "main/main_account.h"
#include "main/main_session.h"
#include "main/main_session.h" // Session::Exists.
#include "main/main_account.h" // Account::configUpdated.
#include "apiwrap.h"
#include "core/application.h"
#include "lang/lang_instance.h"
@ -26,7 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/unixtime.h"
#include "base/call_delayed.h"
#include "base/timer.h"
#include "facades.h"
#include "facades.h" // Proxies list.
namespace MTP {
namespace {
@ -246,10 +246,6 @@ void Instance::Private::start(Config &&config) {
_deviceModel = std::move(config.deviceModel);
_systemVersion = std::move(config.systemVersion);
if (isKeysDestroyer()) {
_instance->connect(_instance, SIGNAL(keyDestroyed(qint32)), _instance, SLOT(onKeyDestroyed(qint32)), Qt::QueuedConnection);
}
for (auto &key : config.keys) {
auto dcId = key->dcId();
auto shiftedDcId = dcId;
@ -1487,10 +1483,10 @@ void Instance::Private::performKeyDestroy(ShiftedDcId shiftedDcId) {
} break;
case mtpc_destroy_auth_key_none: LOG(("MTP Info: key %1 already destroyed.").arg(shiftedDcId)); break;
}
emit _instance->keyDestroyed(shiftedDcId);
_instance->checkIfKeyWasDestroyed(shiftedDcId);
}), rpcFail([this, shiftedDcId](const RPCError &error) {
LOG(("MTP Error: key %1 destruction resulted in error: %2").arg(shiftedDcId).arg(error.type()));
emit _instance->keyDestroyed(shiftedDcId);
_instance->checkIfKeyWasDestroyed(shiftedDcId);
return true;
}), shiftedDcId);
}
@ -1749,9 +1745,16 @@ void Instance::scheduleKeyDestroy(ShiftedDcId shiftedDcId) {
_private->scheduleKeyDestroy(shiftedDcId);
}
void Instance::onKeyDestroyed(qint32 shiftedDcId) {
_private->completedKeyDestroy(shiftedDcId);
void Instance::checkIfKeyWasDestroyed(ShiftedDcId shiftedDcId) {
crl::on_main(this, [=] {
if (isKeysDestroyer()) {
LOG(("MTP Info: checkIfKeyWasDestroyed on destroying key %1, "
"assuming it is destroyed.").arg(shiftedDcId));
_private->completedKeyDestroy(shiftedDcId);
}
});
}
void Instance::sendRequest(
mtpRequestId requestId,
SecureRequest &&request,

View file

@ -173,6 +173,7 @@ public:
bool isKeysDestroyer() const;
void scheduleKeyDestroy(ShiftedDcId shiftedDcId);
void checkIfKeyWasDestroyed(ShiftedDcId shiftedDcId);
void requestConfig();
void requestConfigIfOld();
@ -190,16 +191,12 @@ public slots:
signals:
void configLoaded();
void cdnConfigLoaded();
void keyDestroyed(qint32 shiftedDcId);
void allKeysDestroyed();
void proxyDomainResolved(
QString host,
QStringList ips,
qint64 expireAt);
private slots:
void onKeyDestroyed(qint32 shiftedDcId);
private:
void sendRequest(
mtpRequestId requestId,

View file

@ -8,6 +8,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once
#include "base/variant.h"
#include "mtproto/rpc_sender.h"
#include "mtproto/mtp_instance.h"
#include "mtproto/facade.h"
namespace MTP {

View file

@ -120,7 +120,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/utils.h"
#include "config.h"
#include "mtproto/facade.h"
#include "scheme.h"
#include "mtproto/type_utils.h"
#include "ui/style/style_core.h"
#include "styles/palette.h"

View file

@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/timer.h"
#include "base/binary_guard.h"
#include "data/data_file_origin.h"
#include "mtproto/facade.h"
#include <QtNetwork/QNetworkReply>

View file

@ -8,6 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#pragma once
#include "api/api_common.h"
#include "mtproto/facade.h"
#include <QtCore/QTimer>

View file

@ -10,6 +10,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/buttons.h"
#include "ui/effects/radial_animation.h"
#include "ui/ui_utility.h"
#include "mtproto/facade.h"
#include "window/themes/window_theme.h"
#include "boxes/connection_box.h"
#include "boxes/abstract_box.h"