Logo Search packages:      
Sourcecode: kmess version File versions

void P2PApplicationBase::sendDirectConnectionHandshake ( const QString &  nonce  )  [protected, inherited]

Send the direct connection handshake.

This message contains the Nonce field, used by the other contact to authenticate the direct connection. The confirmation message is identical to the handshake message.

Definition at line 1283 of file p2papplicationbase.cpp.

References ApplicationList::getDirectConnection(), ApplicationList::hasDirectConnection(), P2PMessage::MSN_FLAG_DC_HANDSHAKE, P2PApplicationBase::P2P_WAIT_FOR_CONNECTION2, P2PApplicationBase::P2P_WAIT_FOR_HANDSHAKE, P2PApplicationBase::P2P_WAIT_FOR_HANDSHAKE_OK, and MsnDirectConnection::sendMessage().

Referenced by P2PApplication::gotDirectConnectionHandshake(), and P2PApplication::slotConnectionEstablished().

{
#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
  kDebug() << "Sending direct connection handshake "
            << "(nonce=" << nonce << ").";
#endif
#ifdef KMESSTEST
  KMESS_ASSERT( applicationList_->hasDirectConnection() );
#endif
#ifdef KMESSTEST
  // NOTE: the handshake could happen while the file transfer was in progress, or even completed already.
  KMESS_ASSERT( waitingState_ == P2P_WAIT_FOR_CONNECTION2   // we just established connection, send the first handshake
       || waitingState_ == P2P_WAIT_FOR_HANDSHAKE     // contact established connection, waiting to receive first handshake
       || waitingState_ == P2P_WAIT_FOR_HANDSHAKE_OK  // we sent the first handshake, waiting for contact to return second.
       );
#endif

  // Message flag is 0x100
  const int handshakeFlag = P2PMessage::MSN_FLAG_DC_HANDSHAKE;

  // Prepare the header
  QByteArray header( 48, 0x00 );
  nextMessageID_++;

  // Insert the bytes
  P2PMessage::insertBytes(header, 0,               0);   // 1: SessionID
  P2PMessage::insertBytes(header, nextMessageID_,  4);   // 2: MessageID
  // offset and total size are 0
  P2PMessage::insertBytes(header, handshakeFlag,  28);   // 6: Message type (flags)

  // Insert the nonce at fields 7-9
  P2PMessage::insertNonce(header, nonce);


#ifdef KMESSDEBUG_P2PAPPLICATION_GENERAL
  // Display binary data as hexadecimal string
  const int nonceOffset = 32;
  const char hexMap[] = "0123456789ABCDEF";
  QString hex;
  for(int i = 0; i < 16; i++)
  {
    if( i == 4 || i == 6 || i == 8 || i == 10 )
    {
      hex += "-";
    }
    int upper = (header[nonceOffset + i] & 0xf0) >> 4;
    int lower = (header[nonceOffset + i] & 0x0f);
    hex += hexMap[upper];
    hex += hexMap[lower];
  }
  kDebug() << "copied nonce '" << nonce << "' to p2p message header as '" << hex << "'.";
#endif

  // Forcefully Send the message over the direct connection
  applicationList_->getDirectConnection()->sendMessage( header );

  // Not updating the waiting state here.
  // The handshake process could happen while the data transfer is already in progress
}


Generated by  Doxygen 1.6.0   Back to index