2017-02-23 09:57:04 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-02-23 09:57:04 +03:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-02-23 09:57:04 +03:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-04-06 17:38:10 +03:00
|
|
|
#include "base/observer.h"
|
2018-04-24 23:09:20 +04:00
|
|
|
#include "base/bytes.h"
|
2017-03-23 19:11:35 +03:00
|
|
|
#include "mtproto/rsa_public_key.h"
|
2017-02-23 09:57:04 +03:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
namespace MTP {
|
|
|
|
|
2017-03-23 19:11:35 +03:00
|
|
|
enum class DcType {
|
|
|
|
Regular,
|
2017-06-26 20:38:16 +03:00
|
|
|
Temporary,
|
2017-03-23 19:11:35 +03:00
|
|
|
MediaDownload,
|
|
|
|
Cdn,
|
|
|
|
};
|
2017-02-23 09:57:04 +03:00
|
|
|
class DcOptions {
|
|
|
|
public:
|
|
|
|
// construct methods don't notify "changed" subscribers.
|
|
|
|
void constructFromSerialized(const QByteArray &serialized);
|
|
|
|
void constructFromBuiltIn();
|
2018-04-24 23:09:20 +04:00
|
|
|
void constructAddOne(
|
|
|
|
int id,
|
|
|
|
MTPDdcOption::Flags flags,
|
|
|
|
const std::string &ip,
|
|
|
|
int port);
|
2017-02-23 09:57:04 +03:00
|
|
|
QByteArray serialize() const;
|
|
|
|
|
|
|
|
using Ids = std::vector<DcId>;
|
|
|
|
base::Observable<Ids> &changed() const {
|
|
|
|
return _changed;
|
|
|
|
}
|
|
|
|
void setFromList(const MTPVector<MTPDcOption> &options);
|
|
|
|
void addFromList(const MTPVector<MTPDcOption> &options);
|
2017-03-23 19:11:35 +03:00
|
|
|
void addFromOther(DcOptions &&options);
|
2017-02-23 09:57:04 +03:00
|
|
|
|
2017-03-23 19:11:35 +03:00
|
|
|
Ids configEnumDcIds() const;
|
2017-02-23 09:57:04 +03:00
|
|
|
|
|
|
|
struct Endpoint {
|
|
|
|
std::string ip;
|
|
|
|
int port = 0;
|
2018-04-24 23:09:20 +04:00
|
|
|
bytes::vector protocolSecret;
|
2017-02-23 09:57:04 +03:00
|
|
|
};
|
|
|
|
struct Variants {
|
2018-04-24 23:09:20 +04:00
|
|
|
enum Address {
|
2017-02-23 09:57:04 +03:00
|
|
|
IPv4 = 0,
|
|
|
|
IPv6 = 1,
|
|
|
|
AddressTypeCount = 2,
|
|
|
|
};
|
2018-04-24 23:09:20 +04:00
|
|
|
enum Protocol {
|
2017-02-23 09:57:04 +03:00
|
|
|
Tcp = 0,
|
|
|
|
Http = 1,
|
|
|
|
ProtocolCount = 2,
|
|
|
|
};
|
2018-04-24 23:09:20 +04:00
|
|
|
std::vector<Endpoint> data[AddressTypeCount][ProtocolCount];
|
2017-02-23 09:57:04 +03:00
|
|
|
};
|
2018-04-24 23:09:20 +04:00
|
|
|
Variants lookup(DcId dcId, DcType type, bool throughProxy) const;
|
2017-03-23 19:11:35 +03:00
|
|
|
DcType dcType(ShiftedDcId shiftedDcId) const;
|
|
|
|
|
|
|
|
void setCDNConfig(const MTPDcdnConfig &config);
|
|
|
|
bool hasCDNKeysForDc(DcId dcId) const;
|
|
|
|
bool getDcRSAKey(DcId dcId, const QVector<MTPlong> &fingerprints, internal::RSAPublicKey *result) const;
|
2017-02-23 09:57:04 +03:00
|
|
|
|
2017-03-01 20:22:37 +03:00
|
|
|
// Debug feature for now.
|
|
|
|
bool loadFromFile(const QString &path);
|
|
|
|
bool writeToFile(const QString &path) const;
|
|
|
|
|
2017-02-23 09:57:04 +03:00
|
|
|
private:
|
|
|
|
struct Option {
|
|
|
|
Option(DcId id, MTPDdcOption::Flags flags, const std::string &ip, int port) : id(id), flags(flags), ip(ip), port(port) {
|
|
|
|
}
|
|
|
|
|
|
|
|
DcId id;
|
|
|
|
MTPDdcOption::Flags flags;
|
|
|
|
std::string ip;
|
|
|
|
int port;
|
|
|
|
};
|
|
|
|
bool applyOneGuarded(DcId dcId, MTPDdcOption::Flags flags, const std::string &ip, int port);
|
|
|
|
|
|
|
|
void processFromList(const QVector<MTPDcOption> &options, bool overwrite);
|
2017-03-23 19:11:35 +03:00
|
|
|
void computeCdnDcIds();
|
|
|
|
|
|
|
|
void readBuiltInPublicKeys();
|
|
|
|
|
|
|
|
class WriteLocker;
|
|
|
|
friend class WriteLocker;
|
|
|
|
|
|
|
|
class ReadLocker;
|
|
|
|
friend class ReadLocker;
|
2017-02-23 09:57:04 +03:00
|
|
|
|
2018-04-24 23:09:20 +04:00
|
|
|
std::map<ShiftedDcId, std::vector<Option>> _data;
|
2017-03-23 19:11:35 +03:00
|
|
|
std::set<DcId> _cdnDcIds;
|
|
|
|
std::map<uint64, internal::RSAPublicKey> _publicKeys;
|
|
|
|
std::map<DcId, std::map<uint64, internal::RSAPublicKey>> _cdnPublicKeys;
|
|
|
|
mutable QReadWriteLock _useThroughLockers;
|
2017-02-23 09:57:04 +03:00
|
|
|
|
|
|
|
mutable base::Observable<Ids> _changed;
|
|
|
|
|
2017-03-01 20:22:37 +03:00
|
|
|
// True when we have overriden options from a .tdesktop-endpoints file.
|
|
|
|
bool _immutable = false;
|
|
|
|
|
2017-02-23 09:57:04 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace MTP
|