Logo Search packages:      
Sourcecode: kmess version File versions

P2PApplicationBase::UnAckedMessage * P2PApplicationBase::getUnAckedMessage ( const P2PMessage ackMessage  )  const [private]

Find the unacked message which corresponds with the received P2P ACK message.

This method compares the binary P2P fields to find the original message which was sent. The returned 'messageType' field is used later in gotAck() to handle ACKs for some specific messages.

Parameters:
ackMessage The ACK message to test for.
Returns:
The meta information about the original message ACKed by the contact.

Definition at line 238 of file p2papplicationbase.cpp.

References P2PApplicationBase::UnAckedMessage::ackSessionID, P2PMessage::getAckSessionID(), P2PMessage::getAckUniqueID(), P2PMessage::getDataSize(), P2PMessage::getFlags(), P2PApplicationBase::UnAckedMessage::messageID, P2PMessage::MSN_FLAG_ABORTED_RECEIVING, and P2PMessage::MSN_FLAG_ACK.

Referenced by gotMessage(), hasUnAckedMessage(), and testDataSendingAborted().

{
#ifdef KMESSTEST
  KMESS_ASSERT( ackMessage.getFlags() != 0 && ackMessage.getDataSize() == 0 );
#endif

  unsigned long ackSessionID = ackMessage.getAckSessionID();  // ackSid
  unsigned long ackUniqueID  = ackMessage.getAckUniqueID();   // ackUid
  unsigned long ackFlag      = ackMessage.getFlags();

  foreach( UnAckedMessage *unAcked, outgoingMessages_ )
  {
    // This works for normal ACKs (0x02) to P2P messages.
    // Ack message   | original message
    // -----------------------------------------
    // ackSid        = messageID
    // ackUid        = ackSid
    // ackSize       = size
    if( ackUniqueID == unAcked->ackSessionID )
    {
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
      kDebug() << "message is matched, option 1: "
                  "ackUniqueID = original uniqueID " << ackUniqueID << ".";
#endif
#ifdef KMESSTEST
      KMESS_ASSERT( ackFlag == P2PMessage::MSN_FLAG_ACK );
#endif
      // Found it, save reference
      return unAcked;
    }


    // This works for control messages (like 0x08):
    // uniqueID is reffers to uniqueID of original message.
    // Ack message   | original message
    // -----------------------------------------
    // total         = total
    // ackSid        = ackSid
    // ackUid        = 0
    // ackSize       = 0
    if( ackSessionID == unAcked->ackSessionID && ackUniqueID == 0 )
    {
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
      kDebug() << "message is matched, option 2: "
                  "ackSessionID = original uniqueID " << ackSessionID << ".";
#endif
#ifdef KMESSTEST
      KMESS_ASSERT( ackFlag == P2PMessage::MSN_FLAG_ERROR );
#endif
      // Found it, save reference
      return unAcked;
    }

    // Also attempt to match on the messageID alone if:
    // - it's a 0x80 message. In this case sendP2PMessageImpl() has overwritten the previous uniqueID.
    // - the UniqueID is not set. (also happens with normal ack messages in GAIM 1.5).
    //
    // This happens with 0x01 control messages:
    // Ack message   | original message
    // -----------------------------------------
    // ackSid        = messageID
    // ackUid        = 0
    // ackSize       = bytepos
    //
    // This happens with 0x80 messages:
    // Ack message   | original message
    // -----------------------------------------
    // ackSid        = messageID
    // ackUid        = new
    // ackSize       = size
    if( ackSessionID == unAcked->messageID
    &&  ( ackFlag == P2PMessage::MSN_FLAG_ABORTED_RECEIVING || ackUniqueID == 0 ) )
    {
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
      kDebug() << "message is matched, option 3: "
                  "ackMessageID = original messageID " << ackSessionID << ".";
#endif
#ifdef KMESSTEST
      KMESS_ASSERT( ackFlag == P2PMessage::MSN_FLAG_ABORTED_RECEIVING
           || ackFlag == P2PMessage::MSN_FLAG_NEGATIVE_ACK );
#endif

      // Found it, save reference
      return unAcked;
    }
  }

  return 0;
}


Generated by  Doxygen 1.6.0   Back to index