2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

API scheme updated to layer 66.

Support CDN file download.
This commit is contained in:
John Preston
2017-03-23 19:11:35 +03:00
parent 7dd24a30b5
commit 8d28d0691f
26 changed files with 873 additions and 418 deletions

View File

@@ -25,10 +25,12 @@ Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
#include "auth_session.h"
#include "messenger.h"
#include "mtproto/connection.h"
#include "mtproto/sender.h"
#include "mtproto/rsa_public_key.h"
namespace MTP {
class Instance::Private {
class Instance::Private : public Sender {
public:
Private(Instance *instance, DcOptions *options, Instance::Mode mode);
@@ -45,6 +47,7 @@ public:
DcOptions *dcOptions();
void configLoadRequest();
void cdnConfigLoadRequest();
void restart();
void restart(ShiftedDcId shiftedDcId);
@@ -116,6 +119,9 @@ private:
void configLoadDone(const MTPConfig &result);
bool configLoadFail(const RPCError &error);
void cdnConfigLoadDone(const MTPCdnConfig &result);
bool cdnConfigLoadFail(const RPCError &error);
void checkDelayedRequests();
Instance *_instance = nullptr;
@@ -133,6 +139,7 @@ private:
base::set_of_unique_ptr<internal::Connection> _quittingConnections;
std::unique_ptr<internal::ConfigLoader> _configLoader;
mtpRequestId _cdnConfigLoadRequestId = 0;
std::map<DcId, AuthKeyPtr> _keysForWrite;
mutable QReadWriteLock _keysForWriteLock;
@@ -174,7 +181,7 @@ private:
};
Instance::Private::Private(Instance *instance, DcOptions *options, Instance::Mode mode) : _instance(instance)
Instance::Private::Private(Instance *instance, DcOptions *options, Instance::Mode mode) : Sender(instance), _instance(instance)
, _dcOptions(options)
, _mode(mode) {
}
@@ -188,7 +195,6 @@ void Instance::Private::start(Config &&config) {
for (auto &key : config.keys) {
auto dcId = key->dcId();
auto shiftedDcId = dcId;
if (isKeysDestroyer()) {
shiftedDcId = MTP::destroyKeyNextDcId(shiftedDcId);
@@ -273,6 +279,22 @@ void Instance::Private::configLoadRequest() {
_configLoader->load();
}
void Instance::Private::cdnConfigLoadRequest() {
if (_cdnConfigLoadRequestId || _mainDcId == Config::kNoneMainDc) {
return;
}
_cdnConfigLoadRequestId = request(MTPhelp_GetCdnConfig()).done([this](const MTPCdnConfig &result) {
_cdnConfigLoadRequestId = 0;
Expects(result.type() == mtpc_cdnConfig);
dcOptions()->setCDNConfig(result.c_cdnConfig());
Local::writeSettings();
emit _instance->cdnConfigLoaded();
}).send();
}
void Instance::Private::restart() {
for (auto &session : _sessions) {
session.second->restart();
@@ -423,7 +445,7 @@ void Instance::Private::logout(RPCDoneHandlerPtr onDone, RPCFailHandlerPtr onFai
}
}
for (auto dcId : dcIds) {
if (dcId != mainDcId()) {
if (dcId != mainDcId() && dcOptions()->dcType(dcId) != DcType::Cdn) {
auto shiftedDcId = MTP::logoutDcId(dcId);
auto requestId = _instance->send(MTPauth_LogOut(), rpcDone([this](mtpRequestId requestId) {
logoutGuestDone(requestId);
@@ -1204,6 +1226,8 @@ void Instance::Private::prepareToDestroy() {
// It accesses Instance in destructor, so it should be destroyed first.
_configLoader.reset();
requestCancellingDiscard();
for (auto &session : base::take(_sessions)) {
session.second->kill();
}
@@ -1233,6 +1257,10 @@ void Instance::configLoadRequest() {
_private->configLoadRequest();
}
void Instance::cdnConfigLoadRequest() {
_private->cdnConfigLoadRequest();
}
void Instance::connectionFinished(internal::Connection *connection) {
_private->connectionFinished(connection);
}