Logo Search packages:      
Sourcecode: kmess version File versions  Download package

void P2PApplication::sendP2PAck ( int  ackType = P2PMessage::MSN_FLAG_ACK  )  [private]

Send a P2P ACK message. MSN sends an P2P ACK for each received P2P message, which turns the P2P communication into a stop-and-wait protocol.

Parameters:
ackType The ACK type (flag) to use, defaults to MSN_FLAG_ACK.

Definition at line 1525 of file p2papplication.cpp.

References MimeMessage::addField(), generateID(), P2PMessage::insertBytes(), and MimeMessage::setBinaryData().

Referenced by gotAck(), gotDataFragment(), gotDataPreparation(), gotMessage(), gotNegotiationMessage(), gotSlpBye(), gotSlpStatus(), and sendCancelMessage().

{
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
  if(ackType == P2PMessage::MSN_FLAG_ACK)
  {
    if(messageID_ == 0)
    {
      kdDebug() << "P2PApplication: Sending P2P ACK (INVITE-ACK)" << endl;
    }
    else
    {
      kdDebug() << "P2PApplication: Sending P2P ACK" << endl;
    }
  }
  else if(ackType == P2PMessage::MSN_FLAG_ERROR)
  {
    kdDebug() << "P2PApplication: Sending P2P ACK (Error-response)" << endl;
  }
  else if(ackType == P2PMessage::MSN_FLAG_WAITING)
  {
    kdDebug() << "P2PApplication: Sending P2P ACK (Timeout-response)" << endl;
  }
  else if(ackType == P2PMessage::MSN_FLAG_CLOSING_ACK)
  {
    kdDebug() << "P2PApplication: Sending P2P ACK (Closing-ACK)" << endl;
  }
  else
  {
    kdDebug() << "P2PApplication: Sending P2P ACK (Unknown-type)" << endl;
  }
#endif
#ifdef KMESSTEST
  ASSERT( shouldSendAck_ );
#endif

  MimeMessage message;


  // Fill the header:
  //
  // 0    4    8        16        24   28   32   36   40        48
  // |....|....|....|....|....|....|....|....|....|....|....|....|
  // |sid |mid |offset   |totalsize|size|flag|asid|auid|a-datasz |
  //

  QByteArray header(48);
  header.fill(0x00);

  // Determine the message ID
  if(messageID_ == 0)
  {
    // We don't have a message ID set yet, we're acknowledging
    // the first INVITE message. Generate an ID

    messageID_ = generateID();
    P2PMessage::insertBytes(header, messageID_, 4);

    // Somehow, the next message we send (200 OK) should contain a messageID - 3:
    // We decrement the messageID with 4 because it will be incremented in the next call.
    messageID_ -= 4;
  }
  else
  {
    messageID_++;
    P2PMessage::insertBytes(header, messageID_, 4);
  }


  // Insert the bytes
  P2PMessage::insertBytes(header, originalSessionID_,     0); // SessionID
  // Message ID was set earlier
  P2PMessage::insertBytes(header, originalTotalSize_,    16); // Confirm total size set in previous message
  P2PMessage::insertBytes(header, ackType,               28); // Set the ACK flag.
  P2PMessage::insertBytes(header, originalMessageID_,    32); // Set the ACK message ID
  P2PMessage::insertBytes(header, originalAckMessageID_, 36); // Set the ACK Unique ID field.
  P2PMessage::insertBytes(header, originalDataSize_,     40); // Set the ACK data size with the previous message size.


  // Footer
  char footer[4];
  footer[0] = 0x00;
  footer[1] = 0x00;
  footer[2] = 0x00;
  footer[3] = 0x00;


  // Assign the message fields
  message.addField("MIME-Version", "1.0");
  message.addField("Content-Type", "application/x-msnmsgrp2p");
  message.addField("P2P-Dest",     contactHandle_);
  message.setBinaryData(header.data(), 0, footer, 0);


  // Send the message
  emit putMsg(message);
  shouldSendAck_ = false;


#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
  kdDebug() << "P2PApplication: ACK Transmitted (flags=" << ackType << ")." << endl;
#endif
}


Generated by  Doxygen 1.6.0   Back to index