2014-05-30 08:53:19 +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.
|
2014-05-30 08:53:19 +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
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2019-12-02 13:10:19 +00:00
|
|
|
#include <QtCore/QReadWriteLock>
|
|
|
|
|
2016-03-24 12:57:10 +00:00
|
|
|
namespace MTP {
|
2017-02-24 17:15:41 +00:00
|
|
|
|
|
|
|
class Instance;
|
2017-06-26 17:38:16 +00:00
|
|
|
class AuthKey;
|
|
|
|
using AuthKeyPtr = std::shared_ptr<AuthKey>;
|
2019-12-28 10:52:29 +00:00
|
|
|
enum class DcType;
|
2017-02-24 17:15:41 +00:00
|
|
|
|
2019-12-02 13:10:19 +00:00
|
|
|
namespace details {
|
2016-03-24 12:57:10 +00:00
|
|
|
|
2019-11-21 10:37:39 +00:00
|
|
|
enum class TemporaryKeyType {
|
|
|
|
Regular,
|
|
|
|
MediaCluster
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class CreatingKeyType {
|
|
|
|
None,
|
|
|
|
Persistent,
|
|
|
|
TemporaryRegular,
|
|
|
|
TemporaryMediaCluster
|
|
|
|
};
|
|
|
|
|
2019-12-28 10:52:29 +00:00
|
|
|
[[nodiscard]] TemporaryKeyType TemporaryKeyTypeByDcType(DcType type);
|
|
|
|
|
2016-03-24 12:57:10 +00:00
|
|
|
class Dcenter : public QObject {
|
2014-05-30 08:53:19 +00:00
|
|
|
public:
|
2019-11-15 13:04:32 +00:00
|
|
|
// Main thread.
|
|
|
|
Dcenter(DcId dcId, AuthKeyPtr &&key);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2019-11-15 13:04:32 +00:00
|
|
|
// Thread-safe.
|
|
|
|
[[nodiscard]] DcId id() const;
|
2019-11-19 10:10:51 +00:00
|
|
|
[[nodiscard]] AuthKeyPtr getPersistentKey() const;
|
2019-11-21 10:37:39 +00:00
|
|
|
[[nodiscard]] AuthKeyPtr getTemporaryKey(TemporaryKeyType type) const;
|
2019-12-28 10:52:29 +00:00
|
|
|
[[nodiscard]] CreatingKeyType acquireKeyCreation(DcType type);
|
2019-11-21 10:37:39 +00:00
|
|
|
bool releaseKeyCreationOnDone(
|
|
|
|
CreatingKeyType type,
|
|
|
|
const AuthKeyPtr &temporaryKey,
|
|
|
|
const AuthKeyPtr &persistentKeyUsedForBind);
|
|
|
|
void releaseKeyCreationOnFail(CreatingKeyType type);
|
2019-11-19 10:10:51 +00:00
|
|
|
bool destroyTemporaryKey(uint64 keyId);
|
2019-11-15 13:04:32 +00:00
|
|
|
bool destroyConfirmedForgottenKey(uint64 keyId);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2019-11-15 07:28:33 +00:00
|
|
|
[[nodiscard]] bool connectionInited() const;
|
|
|
|
void setConnectionInited(bool connectionInited = true);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
private:
|
2019-11-21 10:37:39 +00:00
|
|
|
static constexpr auto kTemporaryKeysCount = 2;
|
|
|
|
|
2019-11-15 13:04:32 +00:00
|
|
|
const DcId _id = 0;
|
|
|
|
mutable QReadWriteLock _mutex;
|
|
|
|
|
2019-11-21 10:37:39 +00:00
|
|
|
AuthKeyPtr _temporaryKeys[kTemporaryKeysCount];
|
2019-11-19 10:10:51 +00:00
|
|
|
AuthKeyPtr _persistentKey;
|
2017-02-24 17:15:41 +00:00
|
|
|
bool _connectionInited = false;
|
2019-11-21 10:37:39 +00:00
|
|
|
std::atomic<bool> _creatingKeys[kTemporaryKeysCount] = { false };
|
2016-10-05 16:56:27 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
};
|
|
|
|
|
2019-12-02 13:10:19 +00:00
|
|
|
} // namespace details
|
2016-03-24 12:57:10 +00:00
|
|
|
} // namespace MTP
|