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
|
|
|
|
|
2017-12-18 12:40:15 +00:00
|
|
|
#include "mtproto/type_utils.h"
|
2017-02-24 17:15:41 +00:00
|
|
|
#include "mtproto/mtp_instance.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-03-24 08:57:11 +00:00
|
|
|
namespace MTP {
|
2019-12-02 13:10:19 +00:00
|
|
|
namespace details {
|
2016-03-24 08:57:11 +00:00
|
|
|
|
2019-09-13 16:45:48 +00:00
|
|
|
[[nodiscard]] bool paused();
|
2016-12-05 11:01:08 +00:00
|
|
|
void pause();
|
|
|
|
void unpause();
|
2020-06-11 16:09:46 +00:00
|
|
|
[[nodiscard]] rpl::producer<> unpaused();
|
2016-03-24 08:57:11 +00:00
|
|
|
|
2019-12-02 13:10:19 +00:00
|
|
|
} // namespace details
|
2014-11-12 20:30:26 +00:00
|
|
|
|
2017-02-25 16:44:02 +00:00
|
|
|
// send(MTPhelp_GetConfig(), MTP::configDcId(dc)) - for dc enumeration
|
|
|
|
constexpr ShiftedDcId configDcId(DcId dcId) {
|
2018-06-11 18:35:27 +00:00
|
|
|
return ShiftDcId(dcId, kConfigDcShift);
|
2016-03-24 08:57:11 +00:00
|
|
|
}
|
|
|
|
|
2017-02-25 16:44:02 +00:00
|
|
|
// send(MTPauth_LogOut(), MTP::logoutDcId(dc)) - for logout of guest dcs enumeration
|
|
|
|
constexpr ShiftedDcId logoutDcId(DcId dcId) {
|
2018-06-11 18:35:27 +00:00
|
|
|
return ShiftDcId(dcId, kLogoutDcShift);
|
2016-03-24 08:57:11 +00:00
|
|
|
}
|
|
|
|
|
2018-05-29 18:12:23 +00:00
|
|
|
// send(MTPupload_GetFile(), MTP::updaterDcId(dc)) - for autoupdater
|
|
|
|
constexpr ShiftedDcId updaterDcId(DcId dcId) {
|
2018-06-11 18:35:27 +00:00
|
|
|
return ShiftDcId(dcId, kUpdaterDcShift);
|
2018-05-29 18:12:23 +00:00
|
|
|
}
|
|
|
|
|
2022-02-25 11:14:15 +00:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2017-03-23 16:11:35 +00:00
|
|
|
constexpr auto kUploadSessionsCount = 2;
|
|
|
|
|
2019-12-02 13:10:19 +00:00
|
|
|
namespace details {
|
2016-12-05 11:01:08 +00:00
|
|
|
|
|
|
|
constexpr ShiftedDcId downloadDcId(DcId dcId, int index) {
|
2019-12-04 06:51:21 +00:00
|
|
|
Expects(index < kMaxMediaDcCount);
|
|
|
|
|
2018-06-11 18:35:27 +00:00
|
|
|
return ShiftDcId(dcId, kBaseDownloadDcShift + index);
|
2016-12-05 11:01:08 +00:00
|
|
|
};
|
|
|
|
|
2019-12-02 13:10:19 +00:00
|
|
|
} // namespace details
|
2016-03-24 08:57:11 +00:00
|
|
|
|
2017-02-25 16:44:02 +00:00
|
|
|
// 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);
|
2016-03-24 08:57:11 +00:00
|
|
|
}
|
2016-12-05 11:01:08 +00:00
|
|
|
|
2017-03-23 16:11:35 +00:00
|
|
|
inline constexpr bool isDownloadDcId(ShiftedDcId shiftedDcId) {
|
2019-12-02 13:10:19 +00:00
|
|
|
return (shiftedDcId >= details::downloadDcId(0, 0))
|
2019-12-04 06:51:21 +00:00
|
|
|
&& (shiftedDcId < details::downloadDcId(0, kMaxMediaDcCount - 1) + kDcShift);
|
2017-03-23 16:11:35 +00:00
|
|
|
}
|
|
|
|
|
2022-02-24 16:14:37 +00:00
|
|
|
inline constexpr bool isMediaClusterDcId(ShiftedDcId shiftedDcId) {
|
|
|
|
const auto shift = GetDcIdShift(shiftedDcId);
|
|
|
|
return isDownloadDcId(shiftedDcId)
|
|
|
|
|| (shift == kGroupCallStreamDcShift)
|
|
|
|
|| (shift == kExportMediaDcShift)
|
|
|
|
|| (shift == kUpdaterDcShift);
|
|
|
|
}
|
|
|
|
|
2017-03-23 16:11:35 +00:00
|
|
|
inline bool isCdnDc(MTPDdcOption::Flags flags) {
|
|
|
|
return (flags & MTPDdcOption::Flag::f_cdn);
|
2016-03-24 08:57:11 +00:00
|
|
|
}
|
|
|
|
|
2017-06-26 17:38:16 +00:00
|
|
|
inline bool isTemporaryDcId(ShiftedDcId shiftedDcId) {
|
2018-06-11 18:35:27 +00:00
|
|
|
auto dcId = BareDcId(shiftedDcId);
|
2020-06-17 09:36:25 +00:00
|
|
|
return (dcId >= Instance::Fields::kTemporaryMainDc);
|
2017-06-26 17:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline DcId getRealIdFromTemporaryDcId(ShiftedDcId shiftedDcId) {
|
2018-06-11 18:35:27 +00:00
|
|
|
auto dcId = BareDcId(shiftedDcId);
|
2020-06-17 09:36:25 +00:00
|
|
|
return (dcId >= Instance::Fields::kTemporaryMainDc) ? (dcId - Instance::Fields::kTemporaryMainDc) : 0;
|
2017-06-26 17:38:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline DcId getTemporaryIdFromRealDcId(ShiftedDcId shiftedDcId) {
|
2018-06-11 18:35:27 +00:00
|
|
|
auto dcId = BareDcId(shiftedDcId);
|
2020-06-17 09:36:25 +00:00
|
|
|
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 {
|
2016-12-05 11:01:08 +00:00
|
|
|
|
|
|
|
constexpr ShiftedDcId uploadDcId(DcId dcId, int index) {
|
2018-06-11 18:35:27 +00:00
|
|
|
static_assert(kUploadSessionsCount < kMaxMediaDcCount, "Too large MTPUploadSessionsCount!");
|
|
|
|
return ShiftDcId(dcId, kBaseUploadDcShift + index);
|
2016-12-05 11:01:08 +00:00
|
|
|
};
|
|
|
|
|
2019-12-02 13:10:19 +00:00
|
|
|
} // namespace details
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-02-25 16:44:02 +00:00
|
|
|
// send(req, callbacks, MTP::uploadDcId(index)) - for upload shifted dc id
|
2018-06-11 18:35:27 +00:00
|
|
|
// uploading always to the main dc so BareDcId(result) == 0
|
2017-02-25 16:44:02 +00:00
|
|
|
inline ShiftedDcId uploadDcId(int index) {
|
2017-03-23 16:11:35 +00:00
|
|
|
Expects(index >= 0 && index < kUploadSessionsCount);
|
2018-06-11 18:35:27 +00:00
|
|
|
|
2019-12-02 13:10:19 +00:00
|
|
|
return details::uploadDcId(0, index);
|
2016-03-24 08:57:11 +00:00
|
|
|
};
|
2016-12-05 11:01:08 +00:00
|
|
|
|
2017-02-25 16:44:02 +00:00
|
|
|
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);
|
2017-02-25 16:44:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline ShiftedDcId destroyKeyNextDcId(ShiftedDcId shiftedDcId) {
|
2018-06-11 18:35:27 +00:00
|
|
|
const auto shift = GetDcIdShift(shiftedDcId);
|
|
|
|
return ShiftDcId(BareDcId(shiftedDcId), shift ? (shift + 1) : kDestroyKeyStartDcShift);
|
2016-03-24 08:57:11 +00:00
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-02-24 17:15:41 +00:00
|
|
|
enum {
|
|
|
|
DisconnectedState = 0,
|
|
|
|
ConnectingState = 1,
|
|
|
|
ConnectedState = 2,
|
|
|
|
};
|
2015-10-15 10:18:24 +00:00
|
|
|
|
2017-02-24 17:15:41 +00:00
|
|
|
enum {
|
|
|
|
RequestSent = 0,
|
|
|
|
RequestConnecting = 1,
|
|
|
|
RequestSending = 2
|
|
|
|
};
|
2016-12-05 11:01:08 +00:00
|
|
|
|
2016-03-24 08:57:11 +00:00
|
|
|
} // namespace MTP
|