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