tdesktop/Telegram/SourceFiles/mtproto/facade.h

132 lines
3.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
#include "mtproto/type_utils.h"
#include "mtproto/mtp_instance.h"
namespace MTP {
2019-12-02 13:10:19 +00:00
namespace details {
2019-09-13 16:45:48 +00:00
[[nodiscard]] bool paused();
void pause();
void unpause();
[[nodiscard]] rpl::producer<> unpaused();
2019-12-02 13:10:19 +00:00
} // namespace details
// send(MTPhelp_GetConfig(), MTP::configDcId(dc)) - for dc enumeration
constexpr ShiftedDcId configDcId(DcId dcId) {
return ShiftDcId(dcId, kConfigDcShift);
}
// send(MTPauth_LogOut(), MTP::logoutDcId(dc)) - for logout of guest dcs enumeration
constexpr ShiftedDcId logoutDcId(DcId dcId) {
return ShiftDcId(dcId, kLogoutDcShift);
}
// send(MTPupload_GetFile(), MTP::updaterDcId(dc)) - for autoupdater
constexpr ShiftedDcId updaterDcId(DcId dcId) {
return ShiftDcId(dcId, kUpdaterDcShift);
}
// send(MTPupload_GetFile(), MTP::groupCallStreamDcId(dc)) - for group call stream
2021-03-08 14:39:36 +00:00
constexpr ShiftedDcId groupCallStreamDcId(DcId dcId) {
return ShiftDcId(dcId, kGroupCallStreamDcShift);
}
constexpr auto kUploadSessionsCount = 2;
2019-12-02 13:10:19 +00:00
namespace details {
constexpr ShiftedDcId downloadDcId(DcId dcId, int index) {
Expects(index < kMaxMediaDcCount);
return ShiftDcId(dcId, kBaseDownloadDcShift + index);
};
2019-12-02 13:10:19 +00:00
} // namespace details
// send(req, callbacks, MTP::downloadDcId(dc, index)) - for download shifted dc id
inline ShiftedDcId downloadDcId(DcId dcId, int index) {
2019-12-02 13:10:19 +00:00
return details::downloadDcId(dcId, index);
}
inline constexpr bool isDownloadDcId(ShiftedDcId shiftedDcId) {
2019-12-02 13:10:19 +00:00
return (shiftedDcId >= details::downloadDcId(0, 0))
&& (shiftedDcId < details::downloadDcId(0, kMaxMediaDcCount - 1) + kDcShift);
}
inline constexpr bool isMediaClusterDcId(ShiftedDcId shiftedDcId) {
const auto shift = GetDcIdShift(shiftedDcId);
return isDownloadDcId(shiftedDcId)
|| (shift == kGroupCallStreamDcShift)
|| (shift == kExportMediaDcShift)
|| (shift == kUpdaterDcShift);
}
inline bool isCdnDc(MTPDdcOption::Flags flags) {
return (flags & MTPDdcOption::Flag::f_cdn);
}
2017-06-26 17:38:16 +00:00
inline bool isTemporaryDcId(ShiftedDcId shiftedDcId) {
auto dcId = BareDcId(shiftedDcId);
return (dcId >= Instance::Fields::kTemporaryMainDc);
2017-06-26 17:38:16 +00:00
}
inline DcId getRealIdFromTemporaryDcId(ShiftedDcId shiftedDcId) {
auto dcId = BareDcId(shiftedDcId);
return (dcId >= Instance::Fields::kTemporaryMainDc) ? (dcId - Instance::Fields::kTemporaryMainDc) : 0;
2017-06-26 17:38:16 +00:00
}
inline DcId getTemporaryIdFromRealDcId(ShiftedDcId shiftedDcId) {
auto dcId = BareDcId(shiftedDcId);
return (dcId < Instance::Fields::kTemporaryMainDc) ? (dcId + Instance::Fields::kTemporaryMainDc) : 0;
2017-06-26 17:38:16 +00:00
}
2019-12-02 13:10:19 +00:00
namespace details {
constexpr ShiftedDcId uploadDcId(DcId dcId, int index) {
static_assert(kUploadSessionsCount < kMaxMediaDcCount, "Too large MTPUploadSessionsCount!");
return ShiftDcId(dcId, kBaseUploadDcShift + index);
};
2019-12-02 13:10:19 +00:00
} // namespace details
// send(req, callbacks, MTP::uploadDcId(index)) - for upload shifted dc id
// uploading always to the main dc so BareDcId(result) == 0
inline ShiftedDcId uploadDcId(int index) {
Expects(index >= 0 && index < kUploadSessionsCount);
2019-12-02 13:10:19 +00:00
return details::uploadDcId(0, index);
};
constexpr bool isUploadDcId(ShiftedDcId shiftedDcId) {
2019-12-02 13:10:19 +00:00
return (shiftedDcId >= details::uploadDcId(0, 0))
&& (shiftedDcId < details::uploadDcId(0, kUploadSessionsCount - 1) + kDcShift);
}
inline ShiftedDcId destroyKeyNextDcId(ShiftedDcId shiftedDcId) {
const auto shift = GetDcIdShift(shiftedDcId);
return ShiftDcId(BareDcId(shiftedDcId), shift ? (shift + 1) : kDestroyKeyStartDcShift);
}
enum {
DisconnectedState = 0,
ConnectingState = 1,
ConnectedState = 2,
};
enum {
RequestSent = 0,
RequestConnecting = 1,
RequestSending = 2
};
} // namespace MTP