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

void P2PApplication::gotAck ( const P2PMessage message  )  [private]

Parse the ACK message. In certain situations we need to activate some methods.

Definition at line 275 of file p2papplication.cpp.

References contactStarted4_ContactConfirmsPreparation(), and sendP2PAck().

Referenced by gotMessage().

{

  // Are we waiting for the contact to accept our invitation (e.g. send "200 OK")?
  if(waitingState_ == P2P_WAIT_CONTACT_ACCEPT)
  {
    // Don't change the waiting state yet
    waitingTimer_->start(30000, true); // 30 sec
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
    kdDebug() << "P2PApplication: Got an ACK message (INVITE ACK, still waiting for 200 OK)." << endl;
#endif
    return;
  }


  // Are we waiting for the contact to send the BYE message?
  if(waitingState_ == P2P_WAIT_FOR_SLP_BYE)
  {
    // Don't change the waiting state yet
    waitingTimer_->start(30000, true); // 30 sec
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
    kdDebug() << "P2PApplication: Got an ACK message (still waiting for BYE)." << endl;
#endif
    return;
  }


  // Are we waiting for the ACK to confirm our "200 OK" message?
  if(waitingState_ == P2P_WAIT_FOR_SLP_OK_ACK)
  {
    waitingState_ = P2P_WAIT_DEFAULT;

#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
    kdDebug() << "P2PApplication: Got an ACK message (200 OK ACK)." << endl;
#endif

    // This should happen after the "200 OK" message is sent.

    // If the user started the inviation,
    // we send the SLP OK ack, not receive it
    if(isUserStartedApp())
    {
      // We received an 200 OK ACK but didn't expect it.
      kdWarning() << "P2PApplication: P2P message can't be handled, "
                  << "unexpected ACK response, waiting for 200 OK ACK (contact=" << contactHandle_ << ")." << endl;
      shouldSendAck_ = true;  // ASSERT in sendP2PAck would fail otherwise
      sendP2PAck(P2PMessage::MSN_FLAG_ERROR);
      endApplication( i18n("The invitation was cancelled.  The contact sent bad data, or KMess doesn't support it.") );
      return;
    }


    // App started by contact,
    // this is truely the right message.
    // Dispatch to derived implementation
    contactStarted3_ContactConfirmsAccept( (const MimeMessage&) message ); // The message is empty, but pass it anyway.


#ifdef KMESSTEST
    ASSERT( waitingState_ == P2P_WAIT_DEFAULT || waitingState_ == P2P_WAIT_FOR_PREPARE_ACK );
#endif

    // If the contactStarted3() didn't sent anything, we'll wait for incoming file data.
    if(waitingState_ == P2P_WAIT_DEFAULT)
    {
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
      kdDebug() << "P2PApplication: Waiting state not changed, waiting for file data..." << endl;
#endif

      // For Pictures, the contact must send the data preparation ACK at this point (P2P_WAIT_FOR_PREPARE_ACK)
      // For Files, the contact must initiate the data transfer now. (P2P_WAIT_DEFAULT)
      // TODO: trillian does not initiate the file transfer here, why?!?)
      waitingState_ = P2P_WAIT_FOR_FILE_DATA;
      waitingTimer_->start(30000, true); // 30 sec
    }

    return;
  }


  // Are we waiting for the ACK to confirm our data preparation message?
  if(waitingState_ == P2P_WAIT_FOR_PREPARE_ACK)
  {
    waitingState_ = P2P_WAIT_DEFAULT;

#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
    kdDebug() << "P2PApplication: Got an ACK message (data-preparation ACK)." << endl;
#endif

    // This should happen after the data preparation message is sent.

    // If the user sent the invitation,
    // we shouldn't receive the prepare-ack, but sent it.
    if(isUserStartedApp())
    {
      // We received a data preparation ACK but didn't expect it.
      kdWarning() << "P2PApplication: P2P message can't be handled, "
                  << "unexpected ACK response, waiting for data-preparation-ACK (contact=" << contactHandle_ << ")." << endl;
      shouldSendAck_ = true;  // ASSERT in sendP2PAck would fail otherwise
      sendP2PAck(P2PMessage::MSN_FLAG_ERROR);
      endApplication( i18n("The invitation was cancelled.  The contact sent bad data, or KMess doesn't support it.") );
      return;
    }


    // Dispatch to derived implementation
    contactStarted4_ContactConfirmsPreparation();
    return;
  }


  // Are we waiting for the BYE ACK to send our closing-ACK?
  if(waitingState_ == P2P_WAIT_FOR_SLP_BYE_ACK)
  {
    waitingState_ = P2P_WAIT_DEFAULT;

#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
    kdDebug() << "P2PApplication: Got an ACK message (Last ACK, sending Closing-ACK)." << endl;
#endif

    // This happens if the BYE message was already send.
    shouldSendAck_ = true;  // ASSERT in sendP2PAck would fail otherwise
    sendP2PAck(P2PMessage::MSN_FLAG_CLOSING_ACK);

#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
    kdDebug() << "P2PApplication: Terminating session." << endl;
#endif

    // Transfer complete.
    endApplication();
    return;
  }


  // Are we waiting for the final closing ACK?
  if(waitingState_ == P2P_WAIT_FOR_CLOSING_ACK)
  {
    // HACK: This code is added to support broken clients, the flag field should be 0x40 instead. (not 0x02)

    waitingState_ = P2P_WAIT_DEFAULT;

#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
    kdDebug() << "P2PApplication: Got an ACK message (Closing ACK, terminating application)." << endl;
#endif

    endApplication();
    return;
  }


  // Are we waiting for the SLP Error message to be ACK-ed?
  if(waitingState_ == P2P_WAIT_FOR_SLP_ERR_ACK)
  {
    waitingState_ = P2P_WAIT_DEFAULT;

    if(! isUserStartedApp())
    {
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
      kdDebug() << "P2PApplication: Got an ACK message (Confirmed SLP Error, waiting for BYE)." << endl;
#endif

      // We wait for the BYE
      waitingState_ = P2P_WAIT_FOR_SLP_BYE;
      waitingTimer_->start(30000, true); // 30 sec

      return;
    }
    else
    {
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
      kdDebug() << "P2PApplication: Got an ACK message (Confirmed SLP Error, terminating)." << endl;
#endif
      // TODO: send BYE here?
      endApplication();
      return;
    }
  }


  // Last option: This should be a normal ACK message.
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
  kdDebug() << "P2PApplication: Got an ACK message." << endl;
#endif

#ifdef KMESSTEST
  // If we were waiting: the timer is stopped and you forgot an if-block in this method
  ASSERT( waitingState_ == P2P_WAIT_DEFAULT );
  if(waitingState_ != P2P_WAIT_DEFAULT)
  {
    kdDebug() << "P2PApplication: Waiting state is " << waitingState_ << "!" << endl;
  }
#endif

  if(waitingState_ != P2P_WAIT_DEFAULT)
  {
    // Make sure the object will be killed eventually.
    waitingTimer_->start(30000, true); // 30 sec
  }
}


Generated by  Doxygen 1.6.0   Back to index