mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-08-28 05:07:45 +00:00
Optional upload/download speed boost
New JSON config option: net_speed_boost Values: null (default), "low", "medium", "high". Taken from TDMT: https://github.com/mediatube/tdesktop Warning: can work bad with low connection speeds. Reference: https://github.com/telegramdesktop/tdesktop/pull/6442#issuecomment-525663010
This commit is contained in:
parent
2d05a9fe8e
commit
6e9ab9aea9
@ -17,6 +17,7 @@ https://github.com/kotatogram/kotatogram-desktop/blob/dev/LEGAL
|
||||
#include <QtCore/QJsonDocument>
|
||||
#include <QtCore/QJsonObject>
|
||||
#include <QtCore/QJsonArray>
|
||||
#include <QtCore/QJsonValue>
|
||||
|
||||
namespace KotatoSettings {
|
||||
namespace {
|
||||
@ -177,6 +178,46 @@ bool Manager::readCustomFile() {
|
||||
if (settingsShowChatIdIterator != settings.constEnd() && (*settingsShowChatIdIterator).isBool()) {
|
||||
cSetShowChatId((*settingsShowChatIdIterator).toBool());
|
||||
}
|
||||
|
||||
const auto settingsNetSpeedIterator = settings.constFind(qsl("net_speed_boost"));
|
||||
if (settingsNetSpeedIterator != settings.constEnd()) {
|
||||
if ((*settingsNetSpeedIterator).isString()) {
|
||||
|
||||
const auto option = (*settingsNetSpeedIterator).toString();
|
||||
if (option == "high") {
|
||||
cSetNetRequestsCount(8);
|
||||
cSetNetDownloadSessionsCount(8);
|
||||
cSetNetUploadSessionsCount(8);
|
||||
cSetNetMaxFileQueries(64);
|
||||
cSetNetUploadRequestInterval(200);
|
||||
} else if (option == "medium") {
|
||||
cSetNetRequestsCount(6);
|
||||
cSetNetDownloadSessionsCount(6);
|
||||
cSetNetUploadSessionsCount(6);
|
||||
cSetNetMaxFileQueries(48);
|
||||
cSetNetUploadRequestInterval(300);
|
||||
} else if (option == "low") {
|
||||
cSetNetRequestsCount(4);
|
||||
cSetNetDownloadSessionsCount(4);
|
||||
cSetNetUploadSessionsCount(4);
|
||||
cSetNetMaxFileQueries(32);
|
||||
cSetNetUploadRequestInterval(400);
|
||||
} else {
|
||||
cSetNetRequestsCount(2);
|
||||
cSetNetDownloadSessionsCount(2);
|
||||
cSetNetUploadSessionsCount(2);
|
||||
cSetNetMaxFileQueries(16);
|
||||
cSetNetUploadRequestInterval(500);
|
||||
}
|
||||
|
||||
} else if ((*settingsNetSpeedIterator).isNull()) {
|
||||
cSetNetRequestsCount(2);
|
||||
cSetNetDownloadSessionsCount(2);
|
||||
cSetNetUploadSessionsCount(2);
|
||||
cSetNetMaxFileQueries(16);
|
||||
cSetNetUploadRequestInterval(500);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -208,6 +249,7 @@ void Manager::writeDefaultFile() {
|
||||
settings.insert(qsl("big_emoji_outline"), cBigEmojiOutline());
|
||||
settings.insert(qsl("always_show_scheduled"), cAlwaysShowScheduled());
|
||||
settings.insert(qsl("show_chat_id"), cShowChatId());
|
||||
settings.insert(qsl("net_speed_boost"), QJsonValue(QJsonValue::Null));
|
||||
|
||||
auto document = QJsonDocument();
|
||||
document.setObject(settings);
|
||||
|
@ -1273,9 +1273,9 @@ void ConnectionPrivate::onSentSome(uint64 size) {
|
||||
}
|
||||
}
|
||||
if (isUploadDcId(_shiftedDcId)) {
|
||||
remain *= kUploadSessionsCount;
|
||||
remain *= cNetUploadSessionsCount();
|
||||
} else if (isDownloadDcId(_shiftedDcId)) {
|
||||
remain *= kDownloadSessionsCount;
|
||||
remain *= cNetDownloadSessionsCount();
|
||||
}
|
||||
_waitForReceivedTimer.callOnce(remain);
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ void DedicatedLoader::startLoading() {
|
||||
}
|
||||
|
||||
void DedicatedLoader::sendRequest() {
|
||||
if (_requests.size() >= kRequestsCount || _offset >= _size) {
|
||||
if (_requests.size() >= cNetRequestsCount() || _offset >= _size) {
|
||||
return;
|
||||
}
|
||||
const auto offset = _offset;
|
||||
@ -320,7 +320,7 @@ void DedicatedLoader::sendRequest() {
|
||||
MTP::updaterDcId(_dcId));
|
||||
_offset += kChunkSize;
|
||||
|
||||
if (_requests.size() < kRequestsCount) {
|
||||
if (_requests.size() < cNetRequestsCount()) {
|
||||
App::CallDelayed(kNextRequestDelay, this, [=] { sendRequest(); });
|
||||
}
|
||||
}
|
||||
|
@ -37,10 +37,13 @@ constexpr ShiftedDcId updaterDcId(DcId dcId) {
|
||||
constexpr auto kDownloadSessionsCount = 2;
|
||||
constexpr auto kUploadSessionsCount = 2;
|
||||
|
||||
constexpr auto kDownloadSessionsCountMax = 8;
|
||||
constexpr auto kUploadSessionsCountMax = 8;
|
||||
|
||||
namespace internal {
|
||||
|
||||
constexpr ShiftedDcId downloadDcId(DcId dcId, int index) {
|
||||
static_assert(kDownloadSessionsCount < kMaxMediaDcCount, "Too large MTPDownloadSessionsCount!");
|
||||
static_assert(kDownloadSessionsCountMax < kMaxMediaDcCount, "Too large MTPDownloadSessionsCount!");
|
||||
return ShiftDcId(dcId, kBaseDownloadDcShift + index);
|
||||
};
|
||||
|
||||
@ -48,12 +51,12 @@ constexpr ShiftedDcId downloadDcId(DcId dcId, int index) {
|
||||
|
||||
// send(req, callbacks, MTP::downloadDcId(dc, index)) - for download shifted dc id
|
||||
inline ShiftedDcId downloadDcId(DcId dcId, int index) {
|
||||
Expects(index >= 0 && index < kDownloadSessionsCount);
|
||||
Expects(index >= 0 && index < cNetDownloadSessionsCount());
|
||||
return internal::downloadDcId(dcId, index);
|
||||
}
|
||||
|
||||
inline constexpr bool isDownloadDcId(ShiftedDcId shiftedDcId) {
|
||||
return (shiftedDcId >= internal::downloadDcId(0, 0)) && (shiftedDcId < internal::downloadDcId(0, kDownloadSessionsCount - 1) + kDcShift);
|
||||
return (shiftedDcId >= internal::downloadDcId(0, 0)) && (shiftedDcId < internal::downloadDcId(0, kDownloadSessionsCountMax - 1) + kDcShift);
|
||||
}
|
||||
|
||||
inline bool isCdnDc(MTPDdcOption::Flags flags) {
|
||||
@ -78,7 +81,7 @@ inline DcId getTemporaryIdFromRealDcId(ShiftedDcId shiftedDcId) {
|
||||
namespace internal {
|
||||
|
||||
constexpr ShiftedDcId uploadDcId(DcId dcId, int index) {
|
||||
static_assert(kUploadSessionsCount < kMaxMediaDcCount, "Too large MTPUploadSessionsCount!");
|
||||
static_assert(kUploadSessionsCountMax < kMaxMediaDcCount, "Too large MTPUploadSessionsCount!");
|
||||
return ShiftDcId(dcId, kBaseUploadDcShift + index);
|
||||
};
|
||||
|
||||
@ -87,13 +90,13 @@ constexpr ShiftedDcId uploadDcId(DcId dcId, int index) {
|
||||
// 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);
|
||||
Expects(index >= 0 && index < cNetUploadSessionsCount());
|
||||
|
||||
return internal::uploadDcId(0, index);
|
||||
};
|
||||
|
||||
constexpr bool isUploadDcId(ShiftedDcId shiftedDcId) {
|
||||
return (shiftedDcId >= internal::uploadDcId(0, 0)) && (shiftedDcId < internal::uploadDcId(0, kUploadSessionsCount - 1) + kDcShift);
|
||||
return (shiftedDcId >= internal::uploadDcId(0, 0)) && (shiftedDcId < internal::uploadDcId(0, kUploadSessionsCountMax - 1) + kDcShift);
|
||||
}
|
||||
|
||||
inline ShiftedDcId destroyKeyNextDcId(ShiftedDcId shiftedDcId) {
|
||||
|
@ -214,3 +214,9 @@ int gStickerHeight = 128;
|
||||
bool gBigEmojiOutline = false;
|
||||
bool gAlwaysShowScheduled = true;
|
||||
bool gShowChatId = true;
|
||||
|
||||
int gNetRequestsCount = 2;
|
||||
int gNetDownloadSessionsCount = 2;
|
||||
int gNetUploadSessionsCount = 2;
|
||||
int gNetMaxFileQueries = 16;
|
||||
int gNetUploadRequestInterval = 500;
|
||||
|
@ -188,3 +188,9 @@ DeclareSetting(int, StickerHeight);
|
||||
DeclareSetting(bool, BigEmojiOutline);
|
||||
DeclareSetting(bool, AlwaysShowScheduled);
|
||||
DeclareSetting(bool, ShowChatId);
|
||||
|
||||
DeclareSetting(int, NetRequestsCount);
|
||||
DeclareSetting(int, NetDownloadSessionsCount);
|
||||
DeclareSetting(int, NetUploadSessionsCount);
|
||||
DeclareSetting(int, NetMaxFileQueries);
|
||||
DeclareSetting(int, NetUploadRequestInterval);
|
||||
|
@ -55,7 +55,7 @@ void Downloader::clearPriorities() {
|
||||
}
|
||||
|
||||
void Downloader::requestedAmountIncrement(MTP::DcId dcId, int index, int amount) {
|
||||
Expects(index >= 0 && index < MTP::kDownloadSessionsCount);
|
||||
Expects(index >= 0 && index < cNetDownloadSessionsCount());
|
||||
|
||||
using namespace rpl::mappers;
|
||||
|
||||
@ -95,7 +95,7 @@ void Downloader::killDownloadSessions() {
|
||||
auto ms = crl::now(), left = MTP::kAckSendWaiting + kKillSessionTimeout;
|
||||
for (auto i = _killDownloadSessionTimes.begin(); i != _killDownloadSessionTimes.end(); ) {
|
||||
if (i->second <= ms) {
|
||||
for (int j = 0; j < MTP::kDownloadSessionsCount; ++j) {
|
||||
for (int j = 0; j < cNetDownloadSessionsCount(); ++j) {
|
||||
MTP::stopSession(MTP::downloadDcId(i->first, j));
|
||||
}
|
||||
i = _killDownloadSessionTimes.erase(i);
|
||||
@ -115,7 +115,7 @@ int Downloader::chooseDcIndexForRequest(MTP::DcId dcId) const {
|
||||
auto result = 0;
|
||||
auto it = _requestedBytesAmount.find(dcId);
|
||||
if (it != _requestedBytesAmount.cend()) {
|
||||
for (auto i = 1; i != MTP::kDownloadSessionsCount; ++i) {
|
||||
for (auto i = 1; i != cNetDownloadSessionsCount(); ++i) {
|
||||
if (it->second[i] < it->second[result]) {
|
||||
result = i;
|
||||
}
|
||||
@ -128,7 +128,7 @@ not_null<Downloader::Queue*> Downloader::queueForDc(MTP::DcId dcId) {
|
||||
const auto i = _queuesForDc.find(dcId);
|
||||
const auto result = (i != end(_queuesForDc))
|
||||
? i
|
||||
: _queuesForDc.emplace(dcId, Queue(kMaxFileQueries)).first;
|
||||
: _queuesForDc.emplace(dcId, Queue(cNetMaxFileQueries())).first;
|
||||
return &result->second;
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ private:
|
||||
base::Observable<void> _taskFinishedObservable;
|
||||
int _priority = 1;
|
||||
|
||||
using RequestedInDc = std::array<int64, MTP::kDownloadSessionsCount>;
|
||||
using RequestedInDc = std::array<int64, MTP::kDownloadSessionsCountMax>;
|
||||
std::map<MTP::DcId, RequestedInDc> _requestedBytesAmount;
|
||||
|
||||
base::flat_map<MTP::DcId, crl::time> _killDownloadSessionTimes;
|
||||
|
@ -237,7 +237,7 @@ void Uploader::currentFailed() {
|
||||
dcMap.clear();
|
||||
uploadingId = FullMsgId();
|
||||
sentSize = 0;
|
||||
for (int i = 0; i < MTP::kUploadSessionsCount; ++i) {
|
||||
for (int i = 0; i < cNetUploadSessionsCount(); ++i) {
|
||||
sentSizes[i] = 0;
|
||||
}
|
||||
|
||||
@ -245,13 +245,13 @@ void Uploader::currentFailed() {
|
||||
}
|
||||
|
||||
void Uploader::stopSessions() {
|
||||
for (int i = 0; i < MTP::kUploadSessionsCount; ++i) {
|
||||
for (int i = 0; i < cNetUploadSessionsCount(); ++i) {
|
||||
MTP::stopSession(MTP::uploadDcId(i));
|
||||
}
|
||||
}
|
||||
|
||||
void Uploader::sendNext() {
|
||||
if (sentSize >= kMaxUploadFileParallelSize || _pausedId.msg) return;
|
||||
if (sentSize >= (cNetUploadSessionsCount() * 512 * 1024) || _pausedId.msg) return;
|
||||
|
||||
bool stopping = stopSessionsTimer.isActive();
|
||||
if (queue.empty()) {
|
||||
@ -275,7 +275,7 @@ void Uploader::sendNext() {
|
||||
auto &uploadingData = i->second;
|
||||
|
||||
auto todc = 0;
|
||||
for (auto dc = 1; dc != MTP::kUploadSessionsCount; ++dc) {
|
||||
for (auto dc = 1; dc != cNetUploadSessionsCount(); ++dc) {
|
||||
if (sentSizes[dc] < sentSizes[todc]) {
|
||||
todc = dc;
|
||||
}
|
||||
@ -453,7 +453,7 @@ void Uploader::sendNext() {
|
||||
|
||||
parts.erase(part);
|
||||
}
|
||||
nextTimer.start(kUploadRequestInterval);
|
||||
nextTimer.start(crl::time(cNetUploadRequestInterval()));
|
||||
}
|
||||
|
||||
void Uploader::cancel(const FullMsgId &msgId) {
|
||||
@ -490,7 +490,7 @@ void Uploader::clear() {
|
||||
docRequestsSent.clear();
|
||||
dcMap.clear();
|
||||
sentSize = 0;
|
||||
for (int i = 0; i < MTP::kUploadSessionsCount; ++i) {
|
||||
for (int i = 0; i < cNetUploadSessionsCount(); ++i) {
|
||||
MTP::stopSession(MTP::uploadDcId(i));
|
||||
sentSizes[i] = 0;
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ private:
|
||||
base::flat_map<mtpRequestId, int32> docRequestsSent;
|
||||
base::flat_map<mtpRequestId, int32> dcMap;
|
||||
uint32 sentSize = 0;
|
||||
uint32 sentSizes[MTP::kUploadSessionsCount] = { 0 };
|
||||
uint32 sentSizes[MTP::kUploadSessionsCountMax] = { 0 };
|
||||
|
||||
FullMsgId uploadingId;
|
||||
FullMsgId _pausedId;
|
||||
|
Loading…
x
Reference in New Issue
Block a user