tdesktop/Telegram/SourceFiles/mtproto/details/mtproto_dcenter.h

71 lines
1.7 KiB
C
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
2019-12-02 13:10:19 +00:00
#include <QtCore/QReadWriteLock>
namespace MTP {
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;
2019-12-02 13:10:19 +00:00
namespace details {
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);
class Dcenter : public QObject {
public:
// Main thread.
Dcenter(DcId dcId, AuthKeyPtr &&key);
// Thread-safe.
[[nodiscard]] DcId id() const;
[[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);
bool destroyTemporaryKey(uint64 keyId);
bool destroyConfirmedForgottenKey(uint64 keyId);
2019-11-15 07:28:33 +00:00
[[nodiscard]] bool connectionInited() const;
void setConnectionInited(bool connectionInited = true);
private:
2019-11-21 10:37:39 +00:00
static constexpr auto kTemporaryKeysCount = 2;
const DcId _id = 0;
mutable QReadWriteLock _mutex;
2019-11-21 10:37:39 +00:00
AuthKeyPtr _temporaryKeys[kTemporaryKeysCount];
AuthKeyPtr _persistentKey;
bool _connectionInited = false;
2019-11-21 10:37:39 +00:00
std::atomic<bool> _creatingKeys[kTemporaryKeysCount] = { false };
};
2019-12-02 13:10:19 +00:00
} // namespace details
} // namespace MTP