#NEWLINE# def sendPacket( self , messageType , payload ) : #NEWLINE# #INDENT# "\n        Sends a packet.  If it's been set up, compress the data, encrypt it,\n        and authenticate it before sending.  If key exchange is in progress and\n        the message is not part of key exchange, queue it to be sent later.\n\n        @param messageType: The type of the packet; generally one of the\n                            MSG_* values.\n        @type messageType: C{int}\n        @param payload: The payload for the message.\n        @type payload: C{str}\n        " #NEWLINE# if ( self . _keyExchangeState != self . _KEY_EXCHANGE_NONE ) : #NEWLINE# #INDENT# if ( not self . _allowedKeyExchangeMessageType ( lenPad ) ) : #NEWLINE# #INDENT# self . _blockedByKeyExchange . append ( ( messageType , payload ) ) #NEWLINE# return #NEWLINE# #UNINDENT# #UNINDENT# payload = ( chr ( messageType ) + payload ) #NEWLINE# if self . outgoingCompression : #NEWLINE# #INDENT# payload = ( self . outgoingCompression . compress ( payload ) + self . outgoingCompression . flush ( 2 ) ) #NEWLINE# #UNINDENT# bs = self . currentEncryptions . encBlockSize #NEWLINE# totalSize = ( 5 + len ( payload ) ) #NEWLINE# lenPad = ( bs - ( totalSize % bs ) ) #NEWLINE# if ( lenPad < 4 ) : #NEWLINE# #INDENT# lenPad = ( lenPad + bs ) #NEWLINE# #UNINDENT# packet = ( ( struct . pack ( '!LB' , ( ( totalSize + lenPad ) - 4 ) , lenPad ) + payload ) + randbytes . secureRandom ( lenPad ) ) #NEWLINE# encPacket = ( self . currentEncryptions . encrypt ( packet ) + self . currentEncryptions . makeMAC ( self . outgoingPacketSequence , packet ) ) #NEWLINE# self . transport . write ( encPacket ) #NEWLINE# self . outgoingPacketSequence += 1