From 08072346fd77be9f9de4f8641d77527a627817b1 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 29 Feb 2016 14:34:44 +0300 Subject: [PATCH] fixed crash in next/previous_chat(), MTP::dld/upl -> functions, download and upload sessions count reduced to 2 --- Telegram/SourceFiles/config.h | 4 ++-- Telegram/SourceFiles/dialogswidget.cpp | 10 ++++++++++ Telegram/SourceFiles/fileuploader.cpp | 10 +++++----- Telegram/SourceFiles/mtproto/mtp.cpp | 16 ++-------------- Telegram/SourceFiles/mtproto/mtp.h | 10 ++++++++-- Telegram/SourceFiles/mtproto/mtpConnection.cpp | 4 ++-- Telegram/SourceFiles/mtproto/mtpFileLoader.cpp | 10 +++++----- 7 files changed, 34 insertions(+), 30 deletions(-) diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index 7c0ab7da0..1bffe5ad4 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -51,8 +51,8 @@ enum { MTPIPv4ConnectionWaitTimeout = 1000, // 1 seconds waiting for ipv4, until we accept ipv6 MTPMillerRabinIterCount = 30, // 30 Miller-Rabin iterations for dh_prime primality check - MTPUploadSessionsCount = 4, // max 4 upload sessions is created - MTPDownloadSessionsCount = 4, // max 4 download sessions is created + MTPUploadSessionsCount = 2, // max 2 upload sessions is created + MTPDownloadSessionsCount = 2, // max 2 download sessions is created MTPKillFileSessionTimeout = 5000, // how much time without upload / download causes additional session kill MTPEnumDCTimeout = 8000, // 8 seconds timeout for help_getConfig to work (then move to other dc) diff --git a/Telegram/SourceFiles/dialogswidget.cpp b/Telegram/SourceFiles/dialogswidget.cpp index 29d3437f0..c2b685e27 100644 --- a/Telegram/SourceFiles/dialogswidget.cpp +++ b/Telegram/SourceFiles/dialogswidget.cpp @@ -1522,6 +1522,11 @@ void DialogsInner::destroyData() { } void DialogsInner::peerBefore(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const { + if (!inPeer) { + outPeer = 0; + outMsg = 0; + return; + } if (_state == DefaultState) { DialogsList::RowByPeer::const_iterator i = dialogs.list.rowByPeer.constFind(inPeer->id); if (i == dialogs.list.rowByPeer.constEnd()) { @@ -1606,6 +1611,11 @@ void DialogsInner::peerBefore(const PeerData *inPeer, MsgId inMsg, PeerData *&ou } void DialogsInner::peerAfter(const PeerData *inPeer, MsgId inMsg, PeerData *&outPeer, MsgId &outMsg) const { + if (!inPeer) { + outPeer = 0; + outMsg = 0; + return; + } if (_state == DefaultState) { DialogsList::RowByPeer::const_iterator i = dialogs.list.rowByPeer.constFind(inPeer->id); if (i == dialogs.list.rowByPeer.constEnd()) { diff --git a/Telegram/SourceFiles/fileuploader.cpp b/Telegram/SourceFiles/fileuploader.cpp index 1bb0eb42e..a9388ad85 100644 --- a/Telegram/SourceFiles/fileuploader.cpp +++ b/Telegram/SourceFiles/fileuploader.cpp @@ -103,7 +103,7 @@ void FileUploader::currentFailed() { void FileUploader::killSessions() { for (int i = 0; i < MTPUploadSessionsCount; ++i) { - MTP::stopSession(MTP::upl[i]); + MTP::stopSession(MTP::upl(i)); } } @@ -187,9 +187,9 @@ void FileUploader::sendNext() { } mtpRequestId requestId; if (i->docSize > UseBigFilesFrom) { - requestId = MTP::send(MTPupload_SaveBigFilePart(MTP_long(i->id()), MTP_int(i->docSentParts), MTP_int(i->docPartsCount), MTP_string(toSend)), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl[todc]); + requestId = MTP::send(MTPupload_SaveBigFilePart(MTP_long(i->id()), MTP_int(i->docSentParts), MTP_int(i->docPartsCount), MTP_string(toSend)), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl(todc)); } else { - requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(i->id()), MTP_int(i->docSentParts), MTP_string(toSend)), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl[todc]); + requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(i->id()), MTP_int(i->docSentParts), MTP_string(toSend)), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl(todc)); } docRequestsSent.insert(requestId, i->docSentParts); dcMap.insert(requestId, todc); @@ -200,7 +200,7 @@ void FileUploader::sendNext() { } else { UploadFileParts::iterator part = parts.begin(); - mtpRequestId requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(partsOfId), MTP_int(part.key()), MTP_string(part.value())), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl[todc]); + mtpRequestId requestId = MTP::send(MTPupload_SaveFilePart(MTP_long(partsOfId), MTP_int(part.key()), MTP_string(part.value())), rpcDone(&FileUploader::partLoaded), rpcFail(&FileUploader::partFailed), MTP::upl(todc)); requestsSent.insert(requestId, part.value()); dcMap.insert(requestId, todc); sentSize += part.value().size(); @@ -246,7 +246,7 @@ void FileUploader::clear() { dcMap.clear(); sentSize = 0; for (int32 i = 0; i < MTPUploadSessionsCount; ++i) { - MTP::stopSession(MTP::upl[i]); + MTP::stopSession(MTP::upl(i)); sentSizes[i] = 0; } killSessionsTimer.stop(); diff --git a/Telegram/SourceFiles/mtproto/mtp.cpp b/Telegram/SourceFiles/mtproto/mtp.cpp index 781e6f2ff..1770bcef1 100644 --- a/Telegram/SourceFiles/mtproto/mtp.cpp +++ b/Telegram/SourceFiles/mtproto/mtp.cpp @@ -627,20 +627,8 @@ namespace MTP { const uint32 cfg = 1 * _mtp_internal::dcShift; // send(MTPhelp_GetConfig(), MTP::cfg + dc) - for dc enum const uint32 lgt = 2 * _mtp_internal::dcShift; // send(MTPauth_LogOut(), MTP::lgt + dc) - for logout of guest dcs enum - const uint32 dld[MTPDownloadSessionsCount] = { // send(req, callbacks, MTP::dld[i] + dc) - for download - 0x10 * _mtp_internal::dcShift, - 0x11 * _mtp_internal::dcShift, - 0x12 * _mtp_internal::dcShift, - 0x13 * _mtp_internal::dcShift, - }; - const uint32 upl[MTPUploadSessionsCount] = { // send(req, callbacks, MTP::upl[i] + dc) - for upload - 0x20 * _mtp_internal::dcShift, - 0x21 * _mtp_internal::dcShift, - 0x22 * _mtp_internal::dcShift, - 0x23 * _mtp_internal::dcShift, - }; - const uint32 dldStart = dld[0], dldEnd = dld[(sizeof(dld) / sizeof(dld[0])) - 1] + _mtp_internal::dcShift; - const uint32 uplStart = upl[0], uplEnd = upl[(sizeof(upl) / sizeof(upl[0])) - 1] + _mtp_internal::dcShift; + const uint32 dldStart = dld(0), dldEnd = dld(MTPDownloadSessionsCount - 1) + _mtp_internal::dcShift; + const uint32 uplStart = upl(0), uplEnd = upl(MTPUploadSessionsCount - 1) + _mtp_internal::dcShift; void start() { if (started()) return; diff --git a/Telegram/SourceFiles/mtproto/mtp.h b/Telegram/SourceFiles/mtproto/mtp.h index ed2882e24..ac79f5e3c 100644 --- a/Telegram/SourceFiles/mtproto/mtp.h +++ b/Telegram/SourceFiles/mtproto/mtp.h @@ -70,8 +70,14 @@ namespace MTP { extern const uint32 cfg; // send(MTPhelp_GetConfig(), MTP::cfg + dc) - for dc enum extern const uint32 lgt; // send(MTPauth_LogOut(), MTP::lgt + dc) - for logout of guest dcs enum - extern const uint32 dld[MTPDownloadSessionsCount]; // send(req, callbacks, MTP::dld[i] + dc) - for download - extern const uint32 upl[MTPUploadSessionsCount]; // send(req, callbacks, MTP::upl[i] + dc) - for upload + inline const uint32 dld(int32 index) { // send(req, callbacks, MTP::dld(i) + dc) - for download + t_assert(index >= 0 && index < MTPDownloadSessionsCount); + return (0x10 + index) * _mtp_internal::dcShift; + }; + inline const uint32 upl(int32 index) { // send(req, callbacks, MTP::upl[i] + dc) - for upload + t_assert(index >= 0 && index < MTPUploadSessionsCount); + return (0x20 + index) * _mtp_internal::dcShift; + }; extern const uint32 dldStart, dldEnd; // dc >= dldStart && dc < dldEnd => dc in dld extern const uint32 uplStart, uplEnd; // dc >= uplStart && dc < uplEnd => dc in upl diff --git a/Telegram/SourceFiles/mtproto/mtpConnection.cpp b/Telegram/SourceFiles/mtproto/mtpConnection.cpp index 9e0e10a49..e5959811b 100644 --- a/Telegram/SourceFiles/mtproto/mtpConnection.cpp +++ b/Telegram/SourceFiles/mtproto/mtpConnection.cpp @@ -2119,9 +2119,9 @@ void MTProtoConnectionPrivate::onSentSome(uint64 size) { DEBUG_LOG(("Checking connect for request with size %1 bytes, delay will be %2").arg(size).arg(remain)); } } - if (dc >= MTP::upl[0] && dc < MTP::upl[MTPUploadSessionsCount - 1] + _mtp_internal::dcShift) { + if (dc >= MTP::uplStart && dc < MTP::uplEnd) { remain *= MTPUploadSessionsCount; - } else if (dc >= MTP::dld[0] && dc < MTP::dld[MTPDownloadSessionsCount - 1] + _mtp_internal::dcShift) { + } else if (dc >= MTP::dldStart && dc < MTP::dldEnd) { remain *= MTPDownloadSessionsCount; } _waitForReceivedTimer.start(remain); diff --git a/Telegram/SourceFiles/mtproto/mtpFileLoader.cpp b/Telegram/SourceFiles/mtproto/mtpFileLoader.cpp index 04a7b68eb..6fdf6c5e1 100644 --- a/Telegram/SourceFiles/mtproto/mtpFileLoader.cpp +++ b/Telegram/SourceFiles/mtproto/mtpFileLoader.cpp @@ -349,9 +349,9 @@ mtpFileLoader::mtpFileLoader(const StorageImageLocation *location, int32 size, L , _location(location) , _id(0) , _access(0) { - LoaderQueues::iterator i = queues.find(MTP::dld[0] + _dc); + LoaderQueues::iterator i = queues.find(MTP::dld(0) + _dc); if (i == queues.cend()) { - i = queues.insert(MTP::dld[0] + _dc, FileLoaderQueue(MaxFileQueries)); + i = queues.insert(MTP::dld(0) + _dc, FileLoaderQueue(MaxFileQueries)); } _queue = &i.value(); } @@ -365,9 +365,9 @@ mtpFileLoader::mtpFileLoader(int32 dc, const uint64 &id, const uint64 &access, L , _location(0) , _id(id) , _access(access) { - LoaderQueues::iterator i = queues.find(MTP::dld[0] + _dc); + LoaderQueues::iterator i = queues.find(MTP::dld(0) + _dc); if (i == queues.cend()) { - i = queues.insert(MTP::dld[0] + _dc, FileLoaderQueue(MaxFileQueries)); + i = queues.insert(MTP::dld(0) + _dc, FileLoaderQueue(MaxFileQueries)); } _queue = &i.value(); } @@ -405,7 +405,7 @@ bool mtpFileLoader::loadPart() { App::app()->killDownloadSessionsStop(_dc); - mtpRequestId reqId = MTP::send(MTPupload_GetFile(MTPupload_getFile(loc, MTP_int(offset), MTP_int(limit))), rpcDone(&mtpFileLoader::partLoaded, offset), rpcFail(&mtpFileLoader::partFailed), MTP::dld[dcIndex] + _dc, 50); + mtpRequestId reqId = MTP::send(MTPupload_GetFile(MTPupload_getFile(loc, MTP_int(offset), MTP_int(limit))), rpcDone(&mtpFileLoader::partLoaded, offset), rpcFail(&mtpFileLoader::partFailed), MTP::dld(dcIndex) + _dc, 50); ++_queue->queries; dr.v[dcIndex] += limit;