2017-06-26 17:38:16 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-06-26 17:38:16 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-06-26 17:38:16 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "base/timer.h"
|
2017-11-30 17:33:27 +00:00
|
|
|
#include "base/weak_ptr.h"
|
2018-05-02 19:07:34 +00:00
|
|
|
#include "base/bytes.h"
|
2019-11-18 09:28:14 +00:00
|
|
|
#include "mtproto/mtproto_rpc_sender.h"
|
2017-06-26 17:38:16 +00:00
|
|
|
|
|
|
|
namespace MTP {
|
|
|
|
|
|
|
|
class SpecialConfigRequest;
|
|
|
|
class Instance;
|
|
|
|
|
|
|
|
namespace internal {
|
|
|
|
|
2017-11-30 17:33:27 +00:00
|
|
|
class ConfigLoader : public base::has_weak_ptr {
|
2017-06-26 17:38:16 +00:00
|
|
|
public:
|
2018-05-02 19:27:03 +00:00
|
|
|
ConfigLoader(
|
|
|
|
not_null<Instance*> instance,
|
|
|
|
const QString &phone,
|
|
|
|
RPCDoneHandlerPtr onDone,
|
2019-07-10 17:28:33 +00:00
|
|
|
RPCFailHandlerPtr onFail);
|
2017-06-26 17:38:16 +00:00
|
|
|
~ConfigLoader();
|
|
|
|
|
|
|
|
void load();
|
2018-05-02 19:27:03 +00:00
|
|
|
void setPhone(const QString &phone);
|
2017-06-26 17:38:16 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
mtpRequestId sendRequest(ShiftedDcId shiftedDcId);
|
2018-05-02 19:27:03 +00:00
|
|
|
void addSpecialEndpoint(
|
|
|
|
DcId dcId,
|
|
|
|
const std::string &ip,
|
|
|
|
int port,
|
|
|
|
bytes::const_span secret);
|
2017-06-26 17:38:16 +00:00
|
|
|
void sendSpecialRequest();
|
|
|
|
void enumerate();
|
2018-05-02 19:27:03 +00:00
|
|
|
void refreshSpecialLoader();
|
2017-06-26 17:38:16 +00:00
|
|
|
void createSpecialLoader();
|
|
|
|
DcId specialToRealDcId(DcId specialDcId);
|
|
|
|
void specialConfigLoaded(const MTPConfig &result);
|
|
|
|
void terminateRequest();
|
|
|
|
void terminateSpecialRequest();
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
not_null<Instance*> _instance;
|
2017-06-26 17:38:16 +00:00
|
|
|
base::Timer _enumDCTimer;
|
|
|
|
DcId _enumCurrent = 0;
|
|
|
|
mtpRequestId _enumRequest = 0;
|
|
|
|
|
|
|
|
struct SpecialEndpoint {
|
|
|
|
DcId dcId;
|
|
|
|
std::string ip;
|
|
|
|
int port;
|
2018-05-02 19:07:34 +00:00
|
|
|
bytes::vector secret;
|
2017-06-26 17:38:16 +00:00
|
|
|
};
|
|
|
|
friend bool operator==(const SpecialEndpoint &a, const SpecialEndpoint &b);
|
|
|
|
std::unique_ptr<SpecialConfigRequest> _specialLoader;
|
|
|
|
std::vector<SpecialEndpoint> _specialEndpoints;
|
|
|
|
std::vector<SpecialEndpoint> _triedSpecialEndpoints;
|
|
|
|
base::Timer _specialEnumTimer;
|
|
|
|
DcId _specialEnumCurrent = 0;
|
|
|
|
mtpRequestId _specialEnumRequest = 0;
|
2018-05-02 19:27:03 +00:00
|
|
|
QString _phone;
|
2017-06-26 17:38:16 +00:00
|
|
|
|
|
|
|
RPCDoneHandlerPtr _doneHandler;
|
|
|
|
RPCFailHandlerPtr _failHandler;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
inline bool operator==(const ConfigLoader::SpecialEndpoint &a, const ConfigLoader::SpecialEndpoint &b) {
|
|
|
|
return (a.dcId == b.dcId) && (a.ip == b.ip) && (a.port == b.port);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace MTP
|