void Session::workNewSessionCreated(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workNewSessionCreated: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_NewSessionCreated);
    inboundPkt.fetchLong(); // first_msg_id; //XXX set is as m_clientLastMsgId??
    inboundPkt.fetchLong (); // unique_id
    m_dc->setServerSalt(inboundPkt.fetchLong()); // server_salt
}
void Session::workBadServerSalt(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workBadServerSalt: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_BadServerSalt);
    qint64 badMsgId = inboundPkt.fetchLong();
    inboundPkt.fetchInt(); // badMsgSeqNo
    inboundPkt.fetchInt(); // errorCode
    m_dc->setServerSalt(inboundPkt.fetchLong()); // new server_salt
    // resend the last query
    Query *q = m_pendingQueries.value(badMsgId);
    if(q)
        resendQuery(q);
}
Ejemplo n.º 3
0
void Session::workBadServerSalt(InboundPkt &inboundPkt, qint64 msgId) {
    Q_UNUSED(msgId)
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_BadServerSalt);
    qint64 badMsgId = inboundPkt.fetchLong();
    qint32 badMsgSeqNo = inboundPkt.fetchInt();
    qint32 errorCode = inboundPkt.fetchInt();
    qCDebug(TG_CORE_SESSION) << "workBadServerSalt: badMsgId =" << QString::number(badMsgId, 16)
            << ", badMsgSeqNo =" << badMsgSeqNo << ", errorCode =" << errorCode;
    m_dc->setServerSalt(inboundPkt.fetchLong()); // new server_salt
    Query *q = m_pendingQueries.take(badMsgId);
    qint64 newMsgId = recomposeAndSendQuery(q);
    if (newMsgId != 0) {
        Q_EMIT updateMessageId(badMsgId, newMsgId);
    }
}
void Session::workNewDetailedInfo(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workNewDetailedInfo: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_MsgNewDetailedInfo);
    inboundPkt.fetchLong(); // answer_msg_id
    inboundPkt.fetchInt(); // bytes
    inboundPkt.fetchInt(); // status
}
Ejemplo n.º 5
0
void Session::workBadMsgNotification(InboundPkt &inboundPkt, qint64 msgId) {
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_BadMsgNotification);
    qint64 badMsgId = inboundPkt.fetchLong();
    qint32 badMsgSeqNo = inboundPkt.fetchInt();
    qint32 errorCode = inboundPkt.fetchInt();
    qCWarning(TG_CORE_SESSION) << "workBadMsgNotification: badMsgId =" << QString::number(badMsgId, 16) <<
            ", badMsgSeqNo =" << badMsgSeqNo << ", errorCode =" << errorCode;
    switch (errorCode) {
    case 16:
    case 17:
    case 19:
    case 32:
    case 33:
    case 64:
        // update time sync difference and reset msgIds counter
        qint32 serverTime = msgId >> 32LL;
        mTimeDifference = QDateTime::currentDateTime().toTime_t() - serverTime;

        qint64 nextId = generatePlainNextMsgId();
        if (!m_pendingQueries.contains(nextId)) {
            m_clientLastMsgId = 0;
        }

        // read removing from pending queries, recompose and send the last query
        Query *q = m_pendingQueries.take(badMsgId);
        qint64 newMsgId = recomposeAndSendQuery(q);
        if (newMsgId != 0) {
            Q_EMIT updateMessageId(badMsgId, newMsgId);
        }
        break;
    }
}
void Session::workRpcResult(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workRpcResult: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_RpcResult);
    qint64 id = inboundPkt.fetchLong();
    qint32 op = inboundPkt.prefetchInt();
    if (op == (qint32)TL_RpcError) {
        queryOnError(inboundPkt, id);
    } else {
        queryOnResult(inboundPkt, id);
    }
}
void Session::workMsgsAck(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workMsgsAck: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_MsgsAck);
    mAsserter.check(inboundPkt.fetchInt () == (qint32)TL_Vector);
    qint32 n = inboundPkt.fetchInt();
    for (qint32 i = 0; i < n; i++) {
        qint64 id = inboundPkt.fetchLong ();
        Query *q = m_pendingQueries.value(id);
        if(!q)
            return;

        Q_ASSERT(q);
        q->setAcked(true);
    }
}
void Session::workContainer (InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workContainer: msgId =" << QString::number(msgId, 16);
    mAsserter.check(inboundPkt.fetchInt() == TL_MsgContainer);
    qint32 n = inboundPkt.fetchInt();
    for (qint32 i = 0; i < n; i++) { // message
        qint64 id = inboundPkt.fetchLong (); // msg_id
        if (id & 1) {
           addToPendingAcks(id);
        }
        inboundPkt.fetchInt (); // seq_no
        qint32 bytes = inboundPkt.fetchInt ();
        qint32 *t = inboundPkt.inEnd();
        inboundPkt.setInEnd(inboundPkt.inPtr() + (bytes / 4));
        rpcExecuteAnswer(inboundPkt, id);
        Q_ASSERT (inboundPkt.inPtr() == inboundPkt.inEnd());
        inboundPkt.setInEnd(t);
    }
}
void Session::workBadMsgNotification(InboundPkt &inboundPkt, qint64 msgId) {
    mAsserter.check(inboundPkt.fetchInt() == (qint32)TL_BadMsgNotification);
    qint64 badMsgId = inboundPkt.fetchLong();
    qint32 badMsgSeqNo = inboundPkt.fetchInt();
    qint32 errorCode = inboundPkt.fetchInt();
    qCWarning(TG_CORE_SESSION) << "workBadMsgNotification: msgId =" << badMsgId <<
                  ", seqNo =" << badMsgSeqNo << ", errorCode =" << errorCode;
    switch (errorCode) {
    case 16:
    case 17:
        // update time sync difference and reset msgIds counter
        qint32 serverTime = msgId >> 32LL;
        mTimeDifference = QDateTime::currentDateTime().toTime_t() - serverTime;
        m_clientLastMsgId = 0;
        // read removing from pending queries, recompose and send the last query
        Query *q = m_pendingQueries.take(badMsgId);
        recomposeAndSendQuery(q);
        break;
    }
}
void Session::workPong(InboundPkt &inboundPkt, qint64 msgId) {
    qCDebug(TG_CORE_SESSION) << "workPong: msgId =" << QString::number(msgId, 16);
    mAsserter.check (inboundPkt.fetchInt() == (qint32)TL_Pong);
    inboundPkt.fetchLong(); // msg_id
    inboundPkt.fetchLong(); // ping_id
}