moved MTProtoSession and MTProtoConnection to MTP::internal:: namespace

This commit is contained in:
John Preston 2016-03-24 11:57:11 +03:00
parent 26e2918841
commit d9ef8217e5
15 changed files with 1247 additions and 1180 deletions

View File

@ -910,7 +910,7 @@ void AppClass::killDownloadSessions() {
for (QMap<int32, uint64>::iterator i = killDownloadSessionTimes.begin(); i != killDownloadSessionTimes.end(); ) {
if (i.value() <= ms) {
for (int j = 0; j < MTPDownloadSessionsCount; ++j) {
MTP::stopSession(MTP::dld(j) + i.key());
MTP::stopSession(MTP::dldDcId(i.key(), j));
}
i = killDownloadSessionTimes.erase(i);
} else {

View File

@ -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::uplDcId(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::uplDcId(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::uplDcId(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::uplDcId(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::uplDcId(i));
sentSizes[i] = 0;
}
killSessionsTimer.stop();

View File

@ -886,7 +886,7 @@ namespace {
stream >> dcIdWithShift >> flags >> ip >> port;
if (!_checkStreamStatus(stream)) return false;
if (_dcOpts) _dcOpts->insert(dcIdWithShift, MTP::DcOption(dcIdWithShift % _mtp_internal::dcShift, MTPDdcOption::Flags(flags), ip.toUtf8().constData(), port));
if (_dcOpts) _dcOpts->insert(dcIdWithShift, MTP::DcOption(MTP::bareDcId(dcIdWithShift), MTPDdcOption::Flags(flags), ip.toUtf8().constData(), port));
} break;
case dbiChatSizeMax: {
@ -931,7 +931,7 @@ namespace {
if (!_checkStreamStatus(stream)) return false;
DEBUG_LOG(("MTP Info: key found, dc %1, key: %2").arg(dcId).arg(Logs::mb(key, 256).str()));
dcId = dcId % _mtp_internal::dcShift;
dcId = MTP::bareDcId(dcId);
mtpAuthKeyPtr keyPtr(new mtpAuthKey());
keyPtr->setKey(key);
keyPtr->setDC(dcId);
@ -2142,7 +2142,7 @@ namespace Local {
const BuiltInDc *bdcs = builtInDcs();
for (int i = 0, l = builtInDcsCount(); i < l; ++i) {
MTPDdcOption::Flags flags = 0;
int idWithShift = bdcs[i].id + (flags * _mtp_internal::dcShift);
MTP::ShiftedDcId idWithShift = MTP::shiftDcId(bdcs[i].id, flags);
dcOpts.insert(idWithShift, MTP::DcOption(bdcs[i].id, flags, bdcs[i].ip, bdcs[i].port));
DEBUG_LOG(("MTP Info: adding built in DC %1 connect option: %2:%3").arg(bdcs[i].id).arg(bdcs[i].ip).arg(bdcs[i].port));
}
@ -2150,7 +2150,7 @@ namespace Local {
const BuiltInDc *bdcsipv6 = builtInDcsIPv6();
for (int i = 0, l = builtInDcsCountIPv6(); i < l; ++i) {
MTPDdcOption::Flags flags = MTPDdcOption::Flag::f_ipv6;
int idWithShift = bdcsipv6[i].id + (flags * _mtp_internal::dcShift);
MTP::ShiftedDcId idWithShift = MTP::shiftDcId(bdcsipv6[i].id, flags);
dcOpts.insert(idWithShift, MTP::DcOption(bdcsipv6[i].id, flags, bdcsipv6[i].ip, bdcsipv6[i].port));
DEBUG_LOG(("MTP Info: adding built in DC %1 IPv6 connect option: %2:%3").arg(bdcsipv6[i].id).arg(bdcsipv6[i].ip).arg(bdcsipv6[i].port));
}
@ -2189,7 +2189,7 @@ namespace Local {
const BuiltInDc *bdcs = builtInDcs();
for (int i = 0, l = builtInDcsCount(); i < l; ++i) {
MTPDdcOption::Flags flags = 0;
int idWithShift = bdcs[i].id + (flags * _mtp_internal::dcShift);
MTP::ShiftedDcId idWithShift = MTP::shiftDcId(bdcs[i].id, flags);
dcOpts.insert(idWithShift, MTP::DcOption(bdcs[i].id, flags, bdcs[i].ip, bdcs[i].port));
DEBUG_LOG(("MTP Info: adding built in DC %1 connect option: %2:%3").arg(bdcs[i].id).arg(bdcs[i].ip).arg(bdcs[i].port));
}
@ -2197,7 +2197,7 @@ namespace Local {
const BuiltInDc *bdcsipv6 = builtInDcsIPv6();
for (int i = 0, l = builtInDcsCountIPv6(); i < l; ++i) {
MTPDdcOption::Flags flags = MTPDdcOption::Flag::f_ipv6;
int idWithShift = bdcsipv6[i].id + (flags * _mtp_internal::dcShift);
MTP::ShiftedDcId idWithShift = MTP::shiftDcId(bdcsipv6[i].id, flags);
dcOpts.insert(idWithShift, MTP::DcOption(bdcsipv6[i].id, flags, bdcsipv6[i].ip, bdcsipv6[i].port));
DEBUG_LOG(("MTP Info: adding built in DC %1 IPv6 connect option: %2:%3").arg(bdcsipv6[i].id).arg(bdcsipv6[i].ip).arg(bdcsipv6[i].port));
}

View File

@ -83,7 +83,7 @@ QString _logsEntryStart() {
QDateTime tm(QDateTime::currentDateTime());
QThread *thread = QThread::currentThread();
MTPThread *mtpThread = qobject_cast<MTPThread*>(thread);
MTP::internal::Thread *mtpThread = qobject_cast<MTP::internal::Thread*>(thread);
uint threadId = mtpThread ? mtpThread->getThreadId() : 0;
return QString("[%1 %2-%3]").arg(tm.toString("hh:mm:ss.zzz")).arg(QString("%1").arg(threadId, 2, 10, QChar('0'))).arg(++index, 7, 10, QChar('0'));

File diff suppressed because it is too large Load Diff

View File

@ -23,50 +23,26 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "mtproto/core_types.h"
#include "mtproto/auth_key.h"
inline bool mtpRequestData::isSentContainer(const mtpRequest &request) { // "request-like" wrap for msgIds vector
if (request->size() < 9) return false;
return (!request->msDate && !(*request)[6]); // msDate = 0, seqNo = 0
}
inline bool mtpRequestData::isStateRequest(const mtpRequest &request) {
if (request->size() < 9) return false;
return (mtpTypeId((*request)[8]) == mtpc_msgs_state_req);
}
inline bool mtpRequestData::needAck(const mtpRequest &request) {
if (request->size() < 9) return false;
return mtpRequestData::needAckByType((*request)[8]);
}
inline bool mtpRequestData::needAckByType(mtpTypeId type) {
switch (type) {
case mtpc_msg_container:
case mtpc_msgs_ack:
case mtpc_http_wait:
case mtpc_bad_msg_notification:
case mtpc_msgs_all_info:
case mtpc_msgs_state_info:
case mtpc_msg_detailed_info:
case mtpc_msg_new_detailed_info:
return false;
}
return true;
}
namespace MTP {
namespace internal {
class MTProtoConnectionPrivate;
class MTPSessionData;
class ConnectionPrivate;
class SessionData;
class MTPThread : public QThread {
class Thread : public QThread {
Q_OBJECT
public:
MTPThread();
Thread();
uint32 getThreadId() const;
~MTPThread();
~Thread();
private:
uint32 _threadId;
};
class MTProtoConnection {
class Connection {
public:
enum ConnectionType {
@ -74,19 +50,13 @@ public:
HttpConnection
};
MTProtoConnection();
int32 start(MTPSessionData *data, int32 dc = 0); // return dc
Connection();
int32 start(SessionData *data, int32 dc = 0); // return dc
void kill();
void waitTillFinish();
~MTProtoConnection();
~Connection();
enum {
Disconnected = 0,
Connecting = 1,
Connected = 2,
UpdateAlways = 666
};
static const int UpdateAlways = 666;
int32 state() const;
QString transport() const;
@ -94,18 +64,22 @@ public:
private:
QThread *thread;
MTProtoConnectionPrivate *data;
ConnectionPrivate *data;
};
class MTPabstractConnection : public QObject {
class AbstractConnection : public QObject {
Q_OBJECT
typedef QList<mtpBuffer> BuffersQueue;
public:
MTPabstractConnection() : _sentEncrypted(false) {
AbstractConnection() : _sentEncrypted(false) {
}
AbstractConnection(const AbstractConnection &other) = delete;
AbstractConnection &operator=(const AbstractConnection &other) = delete;
virtual ~AbstractConnection() = 0{
}
void setSentEncrypted() {
@ -149,12 +123,14 @@ protected:
};
class MTPabstractTcpConnection : public MTPabstractConnection {
class AbstractTcpConnection : public AbstractConnection {
Q_OBJECT
public:
MTPabstractTcpConnection();
AbstractTcpConnection();
virtual ~AbstractTcpConnection() = 0 {
}
public slots:
@ -174,12 +150,12 @@ protected:
};
class MTPautoConnection : public MTPabstractTcpConnection {
class AutoConnection : public AbstractTcpConnection {
Q_OBJECT
public:
MTPautoConnection(QThread *thread);
AutoConnection(QThread *thread);
void sendData(mtpBuffer &buffer) override;
void disconnectFromServer() override;
@ -239,12 +215,12 @@ private:
};
class MTPtcpConnection : public MTPabstractTcpConnection {
class TCPConnection : public AbstractTcpConnection {
Q_OBJECT
public:
MTPtcpConnection(QThread *thread);
TCPConnection(QThread *thread);
void sendData(mtpBuffer &buffer) override;
void disconnectFromServer() override;
@ -287,12 +263,12 @@ private:
};
class MTPhttpConnection : public MTPabstractConnection {
class HTTPConnection : public AbstractConnection {
Q_OBJECT
public:
MTPhttpConnection(QThread *thread);
HTTPConnection(QThread *thread);
void sendData(mtpBuffer &buffer) override;
void disconnectFromServer() override;
@ -330,13 +306,13 @@ private:
};
class MTProtoConnectionPrivate : public QObject {
class ConnectionPrivate : public QObject {
Q_OBJECT
public:
MTProtoConnectionPrivate(QThread *thread, MTProtoConnection *owner, MTPSessionData *data, uint32 dc);
~MTProtoConnectionPrivate();
ConnectionPrivate(QThread *thread, Connection *owner, SessionData *data, uint32 dc);
~ConnectionPrivate();
void stop();
@ -361,7 +337,7 @@ signals:
void resendManyAsync(QVector<quint64> msgIds, quint64 msCanWait, bool forceContainer, bool sendMsgStateInfo);
void resendAllAsync();
void finished(MTProtoConnection *connection);
void finished(Connection *connection);
public slots:
@ -412,7 +388,7 @@ private:
void doDisconnect();
void createConn(bool createIPv4, bool createIPv6);
void destroyConn(MTPabstractConnection **conn = 0); // 0 - destory all
void destroyConn(AbstractConnection **conn = 0); // 0 - destory all
mtpMsgId placeToContainer(mtpRequest &toSendRequest, mtpMsgId &bigMsgId, mtpMsgId *&haveSentArr, mtpRequest &req);
mtpMsgId prepareToSend(mtpRequest &request, mtpMsgId currentLastId);
@ -427,7 +403,7 @@ private:
void clearMessages();
bool setState(int32 state, int32 ifState = MTProtoConnection::UpdateAlways);
bool setState(int32 state, int32 ifState = Connection::UpdateAlways);
mutable QReadWriteLock stateConnMutex;
int32 _state;
@ -435,8 +411,8 @@ private:
void resetSession();
uint32 dc;
MTProtoConnection *_owner;
MTPabstractConnection *_conn, *_conn4, *_conn6;
Connection *_owner;
AbstractConnection *_conn, *_conn4, *_conn6;
SingleTimer retryTimer; // exp retry timer
int retryTimeout;
@ -475,7 +451,8 @@ private:
uint64 keyId;
QReadWriteLock sessionDataMutex;
MTPSessionData *sessionData;
SessionData *sessionData;
bool myKeyLock;
void lockKey();
void unlockKey();
@ -523,3 +500,6 @@ private:
void clearAuthKeyData();
};
} // namespace internal
} // namespace MTP

View File

@ -22,35 +22,16 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "types.h"
#undef min
#undef max
namespace MTP {
//#define DEBUG_MTPPRIME
// type DcId represents actual data center id, while in most cases
// we use some shifted ids, like DcId() + X * DCShift
typedef int32 DcId;
typedef int32 ShiftedDcId;
}
#ifdef DEBUG_MTPPRIME
class mtpPrime { // for debug visualization, not like int32 :( in default constructor
public:
explicit mtpPrime() : _v(0) {
}
mtpPrime(int32 v) : _v(v) {
}
mtpPrime &operator=(int32 v) {
_v = v;
return (*this);
}
operator int32&() {
return _v;
}
operator const int32 &() const {
return _v;
}
private:
int32 _v;
};
#else
typedef int32 mtpPrime;
#endif
typedef int32 mtpRequestId;
typedef uint64 mtpMsgId;
typedef uint64 mtpPingId;
@ -1072,3 +1053,30 @@ extern const MTPVector<MTPMessageEntity> MTPnullEntities;
extern const MTPMessageFwdHeader MTPnullFwdHeader;
QString stickerSetTitle(const MTPDstickerSet &s);
inline bool mtpRequestData::isSentContainer(const mtpRequest &request) { // "request-like" wrap for msgIds vector
if (request->size() < 9) return false;
return (!request->msDate && !(*request)[6]); // msDate = 0, seqNo = 0
}
inline bool mtpRequestData::isStateRequest(const mtpRequest &request) {
if (request->size() < 9) return false;
return (mtpTypeId((*request)[8]) == mtpc_msgs_state_req);
}
inline bool mtpRequestData::needAck(const mtpRequest &request) {
if (request->size() < 9) return false;
return mtpRequestData::needAckByType((*request)[8]);
}
inline bool mtpRequestData::needAckByType(mtpTypeId type) {
switch (type) {
case mtpc_msg_container:
case mtpc_msgs_ack:
case mtpc_http_wait:
case mtpc_bad_msg_notification:
case mtpc_msgs_all_info:
case mtpc_msgs_state_info:
case mtpc_msg_detailed_info:
case mtpc_msg_new_detailed_info:
return false;
}
return true;
}

View File

@ -82,7 +82,7 @@ void mtpLogoutOtherDCs() {
}
for (int32 i = 0, cnt = dcs.size(); i != cnt; ++i) {
if (dcs[i] != MTP::maindc()) {
logoutGuestMap.insert(MTP::lgt + dcs[i], MTP::send(MTPauth_LogOut(), rpcDone(&logoutDone), rpcFail(&logoutDone), MTP::lgt + dcs[i]));
logoutGuestMap.insert(MTP::lgtDcId(dcs[i]), MTP::send(MTPauth_LogOut(), rpcDone(&logoutDone), rpcFail(&logoutDone), MTP::lgtDcId(dcs[i])));
}
}
}
@ -193,7 +193,7 @@ void mtpUpdateDcOptions(const QVector<MTPDcOption> &options) {
}
for (QVector<MTPDcOption>::const_iterator i = options.cbegin(), e = options.cend(); i != e; ++i) {
const MTPDdcOption &optData(i->c_dcOption());
int32 id = optData.vid.v, idWithShift = id + (optData.vflags.v * _mtp_internal::dcShift);
int32 id = optData.vid.v, idWithShift = MTP::shiftDcId(id, optData.vflags.v);
if (already.constFind(idWithShift) == already.cend()) {
already.insert(idWithShift);
auto a = opts.constFind(idWithShift);
@ -243,7 +243,7 @@ void MTProtoConfigLoader::done() {
_enumRequest = 0;
}
if (_enumCurrent) {
MTP::killSession(MTP::cfg + _enumCurrent);
MTP::killSession(MTP::cfgDcId(_enumCurrent));
_enumCurrent = 0;
}
emit loaded();
@ -257,14 +257,14 @@ void MTProtoConfigLoader::enumDC() {
if (!_enumCurrent) {
_enumCurrent = mainDC;
} else {
MTP::killSession(MTP::cfg + _enumCurrent);
MTP::killSession(MTP::cfgDcId(_enumCurrent));
}
OrderedSet<int32> dcs;
{
QReadLocker lock(mtpDcOptionsMutex());
const MTP::DcOptions &options(Global::DcOptions());
for (auto i = options.cbegin(), e = options.cend(); i != e; ++i) {
dcs.insert(i.key() % _mtp_internal::dcShift);
dcs.insert(MTP::bareDcId(i.key()));
}
}
OrderedSet<int32>::const_iterator i = dcs.constFind(_enumCurrent);
@ -273,7 +273,7 @@ void MTProtoConfigLoader::enumDC() {
} else {
_enumCurrent = i.key();
}
_enumRequest = MTP::send(MTPhelp_GetConfig(), rpcDone(configLoaded), rpcFail(configFailed), MTP::cfg + _enumCurrent);
_enumRequest = MTP::send(MTPhelp_GetConfig(), rpcDone(configLoaded), rpcFail(configFailed), MTP::cfgDcId(_enumCurrent));
_enumDCTimer.start(MTPEnumDCTimeout);
}

File diff suppressed because it is too large Load Diff

View File

@ -20,177 +20,227 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
*/
#pragma once
#include "mtproto/core_types.h"
#include "mtproto/session.h"
#include "mtproto/file_download.h"
namespace _mtp_internal {
MTProtoSession *getSession(int32 dc); // 0 - current set dc
bool paused();
void registerRequest(mtpRequestId requestId, int32 dc);
void unregisterRequest(mtpRequestId requestId);
static const uint32 dcShift = 10000;
mtpRequestId storeRequest(mtpRequest &request, const RPCResponseHandler &parser);
mtpRequest getRequest(mtpRequestId req);
void wrapInvokeAfter(mtpRequest &to, const mtpRequest &from, const mtpRequestMap &haveSent, int32 skipBeforeRequest = 0);
void clearCallbacks(mtpRequestId requestId, int32 errorCode = RPCError::NoError); // 0 - do not toggle onError callback
void clearCallbacksDelayed(const RPCCallbackClears &requestIds);
void performDelayedClear();
void execCallback(mtpRequestId requestId, const mtpPrime *from, const mtpPrime *end);
bool hasCallbacks(mtpRequestId requestId);
void globalCallback(const mtpPrime *from, const mtpPrime *end);
void onStateChange(int32 dcWithShift, int32 state);
void onSessionReset(int32 dcWithShift);
bool rpcErrorOccured(mtpRequestId requestId, const RPCFailHandlerPtr &onFail, const RPCError &err); // return true if need to clean request data
inline bool rpcErrorOccured(mtpRequestId requestId, const RPCResponseHandler &handler, const RPCError &err) {
return rpcErrorOccured(requestId, handler.onFail, err);
}
// used for:
// - resending requests by timer which were postponed by flood delay
// - destroying MTProtoConnections whose thread has finished
class GlobalSlotCarrier : public QObject {
Q_OBJECT
public:
GlobalSlotCarrier();
public slots:
void checkDelayed();
void connectionFinished(MTProtoConnection *connection);
private:
SingleTimer _timer;
};
GlobalSlotCarrier *globalSlotCarrier();
void queueQuittingConnection(MTProtoConnection *connection);
};
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
inline 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 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
namespace internal {
void start();
bool started();
void restart();
void restart(int32 dcMask);
Session *getSession(ShiftedDcId shiftedDcId); // 0 - current set dc
void pause();
void unpause();
bool paused();
void configure(int32 dc, int32 user);
void registerRequest(mtpRequestId requestId, int32 dc);
void unregisterRequest(mtpRequestId requestId);
void setdc(int32 dc, bool fromZeroOnly = false);
int32 maindc();
mtpRequestId storeRequest(mtpRequest &request, const RPCResponseHandler &parser);
mtpRequest getRequest(mtpRequestId req);
void wrapInvokeAfter(mtpRequest &to, const mtpRequest &from, const mtpRequestMap &haveSent, int32 skipBeforeRequest = 0);
void clearCallbacks(mtpRequestId requestId, int32 errorCode = RPCError::NoError); // 0 - do not toggle onError callback
void clearCallbacksDelayed(const RPCCallbackClears &requestIds);
void performDelayedClear();
void execCallback(mtpRequestId requestId, const mtpPrime *from, const mtpPrime *end);
bool hasCallbacks(mtpRequestId requestId);
void globalCallback(const mtpPrime *from, const mtpPrime *end);
void onStateChange(int32 dcWithShift, int32 state);
void onSessionReset(int32 dcWithShift);
bool rpcErrorOccured(mtpRequestId requestId, const RPCFailHandlerPtr &onFail, const RPCError &err); // return true if need to clean request data
inline bool rpcErrorOccured(mtpRequestId requestId, const RPCResponseHandler &handler, const RPCError &err) {
return rpcErrorOccured(requestId, handler.onFail, err);
}
int32 dcstate(int32 dc = 0);
QString dctransport(int32 dc = 0);
// used for:
// - resending requests by timer which were postponed by flood delay
// - destroying MTProtoConnections whose thread has finished
class GlobalSlotCarrier : public QObject {
Q_OBJECT
template <typename TRequest>
inline mtpRequestId send(const TRequest &request, RPCResponseHandler callbacks = RPCResponseHandler(), int32 dc = 0, uint64 msCanWait = 0, mtpRequestId after = 0) {
if (MTProtoSession *session = _mtp_internal::getSession(dc)) {
return session->send(request, callbacks, msCanWait, true, !dc, after);
}
return 0;
}
template <typename TRequest>
inline mtpRequestId send(const TRequest &request, RPCDoneHandlerPtr onDone, RPCFailHandlerPtr onFail = RPCFailHandlerPtr(), int32 dc = 0, uint64 msCanWait = 0, mtpRequestId after = 0) {
return send(request, RPCResponseHandler(onDone, onFail), dc, msCanWait, after);
}
inline void sendAnything(int32 dc = 0, uint64 msCanWait = 0) {
if (MTProtoSession *session = _mtp_internal::getSession(dc)) {
return session->sendAnything(msCanWait);
}
}
void ping();
void cancel(mtpRequestId req);
void killSession(int32 dc);
void stopSession(int32 dc);
public:
enum {
RequestSent = 0,
RequestConnecting = 1,
RequestSending = 2
};
int32 state(mtpRequestId req); // < 0 means waiting for such count of ms
GlobalSlotCarrier();
void finish();
public slots:
void authed(int32 uid);
int32 authedId();
void logoutKeys(RPCDoneHandlerPtr onDone, RPCFailHandlerPtr onFail);
void checkDelayed();
void connectionFinished(Connection *connection);
void setGlobalDoneHandler(RPCDoneHandlerPtr handler);
void setGlobalFailHandler(RPCFailHandlerPtr handler);
void setStateChangedHandler(MTPStateChangedHandler handler);
void setSessionResetHandler(MTPSessionResetHandler handler);
void clearGlobalHandlers();
void updateDcOptions(const QVector<MTPDcOption> &options);
template <typename T>
T nonce() {
T result;
memset_rand(&result, sizeof(T));
return result;
}
mtpKeysMap getKeys();
void setKey(int32 dc, mtpAuthKeyPtr key);
QReadWriteLock *dcOptionsMutex();
struct DcOption {
DcOption(int id, MTPDdcOption::Flags flags, const string &ip, int port) : id(id), flags(flags), ip(ip), port(port) {
}
int id;
MTPDdcOption::Flags flags;
string ip;
int port;
};
typedef QMap<int, DcOption> DcOptions;
private:
SingleTimer _timer;
};
template <typename TRequest>
mtpRequestId MTProtoSession::send(const TRequest &request, RPCResponseHandler callbacks, uint64 msCanWait, bool needsLayer, bool toMainDC, mtpRequestId after) {
mtpRequestId requestId = 0;
try {
uint32 requestSize = request.innerLength() >> 2;
mtpRequest reqSerialized(mtpRequestData::prepare(requestSize));
request.write(*reqSerialized);
GlobalSlotCarrier *globalSlotCarrier();
void queueQuittingConnection(Connection *connection);
DEBUG_LOG(("MTP Info: adding request to toSendMap, msCanWait %1").arg(msCanWait));
} // namespace internal
reqSerialized->msDate = getms(true); // > 0 - can send without container
reqSerialized->needsLayer = needsLayer;
if (after) reqSerialized->after = _mtp_internal::getRequest(after);
requestId = _mtp_internal::storeRequest(reqSerialized, callbacks);
sendPrepared(reqSerialized, msCanWait);
} catch (Exception &e) {
requestId = 0;
_mtp_internal::rpcErrorOccured(requestId, callbacks, rpcClientError("NO_REQUEST_ID", QString("send() failed to queue request, exception: %1").arg(e.what())));
}
if (requestId) _mtp_internal::registerRequest(requestId, toMainDC ? -getDcWithShift() : getDcWithShift());
return requestId;
constexpr ShiftedDcId DCShift = 10000;
constexpr DcId bareDcId(ShiftedDcId shiftedDcId) {
return (shiftedDcId % DCShift);
}
constexpr ShiftedDcId shiftDcId(DcId dcId, int value) {
return dcId + DCShift * value;
}
constexpr int getDcIdShift(ShiftedDcId shiftedDcId) {
return (shiftedDcId - bareDcId(shiftedDcId)) / DCShift;
}
// send(MTPhelp_GetConfig(), MTP::cfgDcId(dc)) - for dc enumeration
constexpr ShiftedDcId cfgDcId(DcId dcId) {
return shiftDcId(dcId, 0x01);
}
// send(MTPauth_LogOut(), MTP::lgtDcId(dc)) - for logout of guest dcs enumeration
constexpr ShiftedDcId lgtDcId(DcId dcId) {
return shiftDcId(dcId, 0x02);
}
namespace internal {
constexpr ShiftedDcId downloadDcId(DcId dcId, int index) {
static_assert(MTPDownloadSessionsCount < 0x10, "Too large MTPDownloadSessionsCount!");
return shiftDcId(dcId, 0x10 + index);
};
}
// send(req, callbacks, MTP::dldDcId(dc, index)) - for download shifted dc id
inline ShiftedDcId dldDcId(DcId dcId, int index) {
t_assert(index >= 0 && index < MTPDownloadSessionsCount);
return internal::downloadDcId(dcId, index);
}
constexpr bool isDldDcId(ShiftedDcId shiftedDcId) {
return (shiftedDcId >= internal::downloadDcId(0, 0)) && (shiftedDcId < internal::downloadDcId(0, MTPDownloadSessionsCount - 1) + DCShift);
}
namespace internal {
constexpr ShiftedDcId uploadDcId(DcId dcId, int index) {
static_assert(MTPUploadSessionsCount < 0x10, "Too large MTPUploadSessionsCount!");
return shiftDcId(dcId, 0x20 + index);
};
}
// send(req, callbacks, MTP::uplDcId(index)) - for upload shifted dc id
// uploading always to the main dc so bareDcId == 0
inline ShiftedDcId uplDcId(DcId dcId) {
return internal::uploadDcId(dcId, 0);
};
constexpr bool isUplDcId(ShiftedDcId shiftedDcId) {
return (shiftedDcId >= internal::uploadDcId(0, 0)) && (shiftedDcId < internal::uploadDcId(0, MTPUploadSessionsCount - 1) + DCShift);
}
void start();
bool started();
void restart();
void restart(int32 dcMask);
void pause();
void unpause();
void configure(int32 dc, int32 user);
void setdc(int32 dc, bool fromZeroOnly = false);
int32 maindc();
enum {
DisconnectedState = 0,
ConnectingState = 1,
ConnectedState = 2,
};
int32 dcstate(int32 dc = 0);
QString dctransport(int32 dc = 0);
template <typename TRequest>
inline mtpRequestId send(const TRequest &request, RPCResponseHandler callbacks = RPCResponseHandler(), int32 dc = 0, uint64 msCanWait = 0, mtpRequestId after = 0) {
if (internal::Session *session = internal::getSession(dc)) {
return session->send(request, callbacks, msCanWait, true, !dc, after);
}
return 0;
}
template <typename TRequest>
inline mtpRequestId send(const TRequest &request, RPCDoneHandlerPtr onDone, RPCFailHandlerPtr onFail = RPCFailHandlerPtr(), int32 dc = 0, uint64 msCanWait = 0, mtpRequestId after = 0) {
return send(request, RPCResponseHandler(onDone, onFail), dc, msCanWait, after);
}
inline void sendAnything(int32 dc = 0, uint64 msCanWait = 0) {
if (internal::Session *session = internal::getSession(dc)) {
return session->sendAnything(msCanWait);
}
}
void ping();
void cancel(mtpRequestId req);
void killSession(int32 dc);
void stopSession(int32 dc);
enum {
RequestSent = 0,
RequestConnecting = 1,
RequestSending = 2
};
int32 state(mtpRequestId req); // < 0 means waiting for such count of ms
void finish();
void authed(int32 uid);
int32 authedId();
void logoutKeys(RPCDoneHandlerPtr onDone, RPCFailHandlerPtr onFail);
void setGlobalDoneHandler(RPCDoneHandlerPtr handler);
void setGlobalFailHandler(RPCFailHandlerPtr handler);
void setStateChangedHandler(MTPStateChangedHandler handler);
void setSessionResetHandler(MTPSessionResetHandler handler);
void clearGlobalHandlers();
void updateDcOptions(const QVector<MTPDcOption> &options);
template <typename T>
T nonce() {
T result;
memset_rand(&result, sizeof(T));
return result;
}
mtpKeysMap getKeys();
void setKey(int32 dc, mtpAuthKeyPtr key);
QReadWriteLock *dcOptionsMutex();
struct DcOption {
DcOption(int id, MTPDdcOption::Flags flags, const string &ip, int port) : id(id), flags(flags), ip(ip), port(port) {
}
int id;
MTPDdcOption::Flags flags;
string ip;
int port;
};
typedef QMap<int, DcOption> DcOptions;
namespace internal {
template <typename TRequest>
mtpRequestId Session::send(const TRequest &request, RPCResponseHandler callbacks, uint64 msCanWait, bool needsLayer, bool toMainDC, mtpRequestId after) {
mtpRequestId requestId = 0;
try {
uint32 requestSize = request.innerLength() >> 2;
mtpRequest reqSerialized(mtpRequestData::prepare(requestSize));
request.write(*reqSerialized);
DEBUG_LOG(("MTP Info: adding request to toSendMap, msCanWait %1").arg(msCanWait));
reqSerialized->msDate = getms(true); // > 0 - can send without container
reqSerialized->needsLayer = needsLayer;
if (after) reqSerialized->after = MTP::internal::getRequest(after);
requestId = MTP::internal::storeRequest(reqSerialized, callbacks);
sendPrepared(reqSerialized, msCanWait);
} catch (Exception &e) {
requestId = 0;
MTP::internal::rpcErrorOccured(requestId, callbacks, rpcClientError("NO_REQUEST_ID", QString("send() failed to queue request, exception: %1").arg(e.what())));
}
if (requestId) MTP::internal::registerRequest(requestId, toMainDC ? -getDcWithShift() : getDcWithShift());
return requestId;
}
} // namespace internal
} // namespace MTP

View File

@ -352,9 +352,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::dldDcId(_dc, 0));
if (i == queues.cend()) {
i = queues.insert(MTP::dld(0) + _dc, FileLoaderQueue(MaxFileQueries));
i = queues.insert(MTP::dldDcId(_dc, 0), FileLoaderQueue(MaxFileQueries));
}
_queue = &i.value();
}
@ -368,9 +368,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::dldDcId(_dc, 0));
if (i == queues.cend()) {
i = queues.insert(MTP::dld(0) + _dc, FileLoaderQueue(MaxFileQueries));
i = queues.insert(MTP::dldDcId(_dc, 0), FileLoaderQueue(MaxFileQueries));
}
_queue = &i.value();
}
@ -432,7 +432,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::dldDcId(_dc, dcIndex), 50);
++_queue->queries;
dr.v[dcIndex] += limit;

View File

@ -22,7 +22,10 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "mtproto/session.h"
void MTPSessionData::clear() {
namespace MTP {
namespace internal {
void SessionData::clear() {
RPCCallbackClears clearCallbacks;
{
QReadLocker locker1(haveSentMutex()), locker2(toResendMutex()), locker3(haveReceivedMutex()), locker4(wereAckedMutex());
@ -63,11 +66,11 @@ void MTPSessionData::clear() {
QWriteLocker locker(receivedIdsMutex());
receivedIds.clear();
}
_mtp_internal::clearCallbacksDelayed(clearCallbacks);
clearCallbacksDelayed(clearCallbacks);
}
MTProtoSession::MTProtoSession(int32 dcenter) : QObject()
Session::Session(int32 dcenter) : QObject()
, _connection(0)
, _killed(false)
, _needToReceive(false)
@ -95,7 +98,7 @@ MTProtoSession::MTProtoSession(int32 dcenter) : QObject()
MTProtoDCMap &dcs(mtpDCMap());
_connection = new MTProtoConnection();
_connection = new Connection();
dcWithShift = _connection->start(&data, dcenter);
if (!dcWithShift) {
delete _connection;
@ -105,11 +108,11 @@ MTProtoSession::MTProtoSession(int32 dcenter) : QObject()
}
if (!dc) {
dcenter = dcWithShift;
int32 dcId = dcWithShift % _mtp_internal::dcShift;
int32 dcId = bareDcId(dcWithShift);
MTProtoDCMap::const_iterator dcIndex = dcs.constFind(dcId);
if (dcIndex == dcs.cend()) {
dc = MTProtoDCPtr(new MTProtoDC(dcId, mtpAuthKeyPtr()));
dcs.insert(dcWithShift % _mtp_internal::dcShift, dc);
dcs.insert(dcId, dc);
} else {
dc = dcIndex.value();
}
@ -124,7 +127,7 @@ MTProtoSession::MTProtoSession(int32 dcenter) : QObject()
}
}
void MTProtoSession::restart() {
void Session::restart() {
if (_killed) {
DEBUG_LOG(("Session Error: can't restart a killed session"));
return;
@ -132,7 +135,7 @@ void MTProtoSession::restart() {
emit needToRestart();
}
void MTProtoSession::stop() {
void Session::stop() {
if (_killed) {
DEBUG_LOG(("Session Error: can't kill a killed session"));
return;
@ -144,20 +147,20 @@ void MTProtoSession::stop() {
}
}
void MTProtoSession::kill() {
void Session::kill() {
stop();
_killed = true;
DEBUG_LOG(("Session Info: marked session dcWithShift %1 as killed").arg(dcWithShift));
}
void MTProtoSession::unpaused() {
void Session::unpaused() {
if (_needToReceive) {
_needToReceive = false;
QTimer::singleShot(0, this, SLOT(tryToReceive()));
}
}
void MTProtoSession::sendAnything(quint64 msCanWait) {
void Session::sendAnything(quint64 msCanWait) {
if (_killed) {
DEBUG_LOG(("Session Error: can't send anything in a killed session"));
return;
@ -187,7 +190,7 @@ void MTProtoSession::sendAnything(quint64 msCanWait) {
}
}
void MTProtoSession::needToResumeAndSend() {
void Session::needToResumeAndSend() {
if (_killed) {
DEBUG_LOG(("Session Info: can't resume a killed session"));
return;
@ -196,7 +199,7 @@ void MTProtoSession::needToResumeAndSend() {
DEBUG_LOG(("Session Info: resuming session dcWithShift %1").arg(dcWithShift));
MTProtoDCMap &dcs(mtpDCMap());
_connection = new MTProtoConnection();
_connection = new Connection();
if (!_connection->start(&data, dcWithShift)) {
delete _connection;
_connection = 0;
@ -213,11 +216,11 @@ void MTProtoSession::needToResumeAndSend() {
}
}
void MTProtoSession::sendPong(quint64 msgId, quint64 pingId) {
void Session::sendPong(quint64 msgId, quint64 pingId) {
send(MTP_pong(MTP_long(msgId), MTP_long(pingId)));
}
void MTProtoSession::sendMsgsStateInfo(quint64 msgId, QByteArray data) {
void Session::sendMsgsStateInfo(quint64 msgId, QByteArray data) {
MTPMsgsStateInfo req(MTP_msgs_state_info(MTP_long(msgId), MTPstring()));
string &info(req._msgs_state_info().vinfo._string().v);
info.resize(data.size());
@ -227,7 +230,7 @@ void MTProtoSession::sendMsgsStateInfo(quint64 msgId, QByteArray data) {
send(req);
}
void MTProtoSession::checkRequestsByTimer() {
void Session::checkRequestsByTimer() {
QVector<mtpMsgId> resendingIds;
QVector<mtpMsgId> removingIds; // remove very old (10 minutes) containers and resend requests
QVector<mtpMsgId> stateRequestIds;
@ -288,19 +291,19 @@ void MTProtoSession::checkRequestsByTimer() {
}
}
}
_mtp_internal::clearCallbacksDelayed(clearCallbacks);
clearCallbacksDelayed(clearCallbacks);
}
}
void MTProtoSession::onConnectionStateChange(qint32 newState) {
_mtp_internal::onStateChange(dcWithShift, newState);
void Session::onConnectionStateChange(qint32 newState) {
onStateChange(dcWithShift, newState);
}
void MTProtoSession::onResetDone() {
_mtp_internal::onSessionReset(dcWithShift);
void Session::onResetDone() {
onSessionReset(dcWithShift);
}
void MTProtoSession::cancel(mtpRequestId requestId, mtpMsgId msgId) {
void Session::cancel(mtpRequestId requestId, mtpMsgId msgId) {
if (requestId) {
QWriteLocker locker(data.toSendMutex());
data.toSendMap().remove(requestId);
@ -311,20 +314,20 @@ void MTProtoSession::cancel(mtpRequestId requestId, mtpMsgId msgId) {
}
}
void MTProtoSession::ping() {
void Session::ping() {
_ping = true;
sendAnything(0);
}
int32 MTProtoSession::requestState(mtpRequestId requestId) const {
int32 Session::requestState(mtpRequestId requestId) const {
int32 result = MTP::RequestSent;
bool connected = false;
if (_connection) {
int32 s = _connection->state();
if (s == MTProtoConnection::Connected) {
if (s == ConnectedState) {
connected = true;
} else if (s == MTProtoConnection::Connecting || s == MTProtoConnection::Disconnected) {
} else if (s == ConnectingState || s == DisconnectedState) {
if (result < 0 || result == MTP::RequestSent) {
result = MTP::RequestConnecting;
}
@ -349,14 +352,14 @@ int32 MTProtoSession::requestState(mtpRequestId requestId) const {
}
}
int32 MTProtoSession::getState() const {
int32 Session::getState() const {
int32 result = -86400000;
if (_connection) {
int32 s = _connection->state();
if (s == MTProtoConnection::Connected) {
if (s == ConnectedState) {
return s;
} else if (s == MTProtoConnection::Connecting || s == MTProtoConnection::Disconnected) {
} else if (s == ConnectingState || s == DisconnectedState) {
if (result < 0) {
return s;
}
@ -367,16 +370,16 @@ int32 MTProtoSession::getState() const {
}
}
if (result == -86400000) {
result = MTProtoConnection::Disconnected;
result = DisconnectedState;
}
return result;
}
QString MTProtoSession::transport() const {
QString Session::transport() const {
return _connection ? _connection->transport() : QString();
}
mtpRequestId MTProtoSession::resend(quint64 msgId, quint64 msCanWait, bool forceContainer, bool sendMsgStateInfo) {
mtpRequestId Session::resend(quint64 msgId, quint64 msCanWait, bool forceContainer, bool sendMsgStateInfo) {
mtpRequest request;
{
QWriteLocker locker(data.haveSentMutex());
@ -416,13 +419,13 @@ mtpRequestId MTProtoSession::resend(quint64 msgId, quint64 msCanWait, bool force
}
}
void MTProtoSession::resendMany(QVector<quint64> msgIds, quint64 msCanWait, bool forceContainer, bool sendMsgStateInfo) {
void Session::resendMany(QVector<quint64> msgIds, quint64 msCanWait, bool forceContainer, bool sendMsgStateInfo) {
for (int32 i = 0, l = msgIds.size(); i < l; ++i) {
resend(msgIds.at(i), msCanWait, forceContainer, sendMsgStateInfo);
}
}
void MTProtoSession::resendAll() {
void Session::resendAll() {
QVector<mtpMsgId> toResend;
{
QReadLocker locker(data.haveSentMutex());
@ -437,7 +440,7 @@ void MTProtoSession::resendAll() {
}
}
void MTProtoSession::sendPrepared(const mtpRequest &request, uint64 msCanWait, bool newRequest) { // returns true, if emit of needToSend() is needed
void Session::sendPrepared(const mtpRequest &request, uint64 msCanWait, bool newRequest) { // returns true, if emit of needToSend() is needed
{
QWriteLocker locker(data.toSendMutex());
data.toSendMap().insert(request->requestId, request);
@ -453,33 +456,33 @@ void MTProtoSession::sendPrepared(const mtpRequest &request, uint64 msCanWait, b
sendAnything(msCanWait);
}
QReadWriteLock *MTProtoSession::keyMutex() const {
QReadWriteLock *Session::keyMutex() const {
return dc->keyMutex();
}
void MTProtoSession::authKeyCreatedForDC() {
void Session::authKeyCreatedForDC() {
DEBUG_LOG(("AuthKey Info: MTProtoSession::authKeyCreatedForDC slot, emitting authKeyCreated(), dcWithShift %1").arg(dcWithShift));
data.setKey(dc->getKey());
emit authKeyCreated();
}
void MTProtoSession::notifyKeyCreated(const mtpAuthKeyPtr &key) {
void Session::notifyKeyCreated(const mtpAuthKeyPtr &key) {
DEBUG_LOG(("AuthKey Info: MTProtoSession::keyCreated(), setting, dcWithShift %1").arg(dcWithShift));
dc->setKey(key);
}
void MTProtoSession::layerWasInitedForDC(bool wasInited) {
void Session::layerWasInitedForDC(bool wasInited) {
DEBUG_LOG(("MTP Info: MTProtoSession::layerWasInitedForDC slot, dcWithShift %1").arg(dcWithShift));
data.setLayerWasInited(wasInited);
}
void MTProtoSession::notifyLayerInited(bool wasInited) {
void Session::notifyLayerInited(bool wasInited) {
DEBUG_LOG(("MTP Info: emitting MTProtoDC::layerWasInited(%1), dcWithShift %2").arg(Logs::b(wasInited)).arg(dcWithShift));
dc->setConnectionInited(wasInited);
emit dc->layerWasInited(wasInited);
}
void MTProtoSession::destroyKey() {
void Session::destroyKey() {
if (!dc) return;
if (data.getKey()) {
@ -491,16 +494,16 @@ void MTProtoSession::destroyKey() {
}
}
int32 MTProtoSession::getDcWithShift() const {
int32 Session::getDcWithShift() const {
return dcWithShift;
}
void MTProtoSession::tryToReceive() {
void Session::tryToReceive() {
if (_killed) {
DEBUG_LOG(("Session Error: can't receive in a killed session"));
return;
}
if (_mtp_internal::paused()) {
if (paused()) {
_needToReceive = true;
return;
}
@ -519,20 +522,23 @@ void MTProtoSession::tryToReceive() {
responses.erase(i);
}
if (requestId <= 0) {
if (dcWithShift < int(_mtp_internal::dcShift)) { // call globalCallback only in main session
_mtp_internal::globalCallback(response.constData(), response.constData() + response.size());
if (dcWithShift == bareDcId(dcWithShift)) { // call globalCallback only in main session
globalCallback(response.constData(), response.constData() + response.size());
}
} else {
_mtp_internal::execCallback(requestId, response.constData(), response.constData() + response.size());
execCallback(requestId, response.constData(), response.constData() + response.size());
}
++cnt;
}
}
MTProtoSession::~MTProtoSession() {
Session::~Session() {
t_assert(_connection == 0);
}
MTPrpcError rpcClientError(const QString &type, const QString &description) {
return MTP_rpc_error(MTP_int(0), MTP_string(("CLIENT_" + type + (description.length() ? (": " + description) : "")).toUtf8().constData()));
}
} // namespace internal
} // namespace MTP

View File

@ -24,15 +24,22 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
#include "mtproto/dcenter.h"
#include "mtproto/rpc_sender.h"
class MTProtoSession;
namespace MTP {
namespace internal {
class MTPSessionData {
class Session;
class SessionData {
public:
MTPSessionData(MTProtoSession *creator)
: _session(0), _salt(0)
, _messagesSent(0), _fakeRequestId(-2000000000)
, _owner(creator), _keyChecked(false), _layerInited(false) {
SessionData(Session *creator)
: _session(0)
, _salt(0)
, _messagesSent(0)
, _fakeRequestId(-2000000000)
, _owner(creator)
, _keyChecked(false)
, _layerInited(false) {
}
void setSession(uint64 session) {
@ -170,10 +177,10 @@ public:
return _fakeRequestId;
}
MTProtoSession *owner() {
Session *owner() {
return _owner;
}
const MTProtoSession *owner() const {
const Session *owner() const {
return _owner;
}
@ -192,7 +199,7 @@ private:
uint32 _messagesSent;
mtpRequestId _fakeRequestId;
MTProtoSession *_owner;
Session *_owner;
mtpAuthKeyPtr _authKey;
bool _keyChecked, _layerInited;
@ -217,12 +224,12 @@ private:
};
class MTProtoSession : public QObject {
class Session : public QObject {
Q_OBJECT
public:
MTProtoSession(int32 dcenter);
Session(int32 dcenter);
void restart();
void stop();
@ -231,7 +238,7 @@ public:
void unpaused();
int32 getDcWithShift() const;
~MTProtoSession();
~Session();
QReadWriteLock *keyMutex() const;
void notifyKeyCreated(const mtpAuthKeyPtr &key);
@ -278,12 +285,12 @@ public slots:
private:
MTProtoConnection *_connection;
Connection *_connection;
bool _killed;
bool _needToReceive;
MTPSessionData data;
SessionData data;
int32 dcWithShift;
MTProtoDCPtr dc;
@ -297,8 +304,11 @@ private:
};
inline QReadWriteLock *MTPSessionData::keyMutex() const {
inline QReadWriteLock *SessionData::keyMutex() const {
return _owner->keyMutex();
}
MTPrpcError rpcClientError(const QString &type, const QString &description = QString());
} // namespace internal
} // namespace MTP

View File

@ -18,6 +18,9 @@ to link the code of portions of this program with the OpenSSL library.
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org
*/
#define NOMINMAX // no min() and max() macro declarations
#ifdef TDESKTOP_WINRT
#include <wrl.h>

View File

@ -765,7 +765,7 @@ void Window::mtpStateChanged(int32 dc, int32 state) {
void Window::updateTitleStatus() {
int32 state = MTP::dcstate();
if (state == MTProtoConnection::Connecting || state == MTProtoConnection::Disconnected || (state < 0 && state > -600)) {
if (state == MTP::ConnectingState || state == MTP::DisconnectedState || (state < 0 && state > -600)) {
if (main || getms() > 5000 || _connecting) {
showConnecting(lang(lng_connecting));
}