#NEWLINE# def gen_handler( self ) : #NEWLINE# #INDENT# p = self . protocol #NEWLINE# if self . is_client : #NEWLINE# #INDENT# ts_init = time . time ( ) #NEWLINE# hs_mine = self . generate_request ( ) #NEWLINE# p . transport . writeSequence ( ( self . version_packet , hs_mine ) ) #NEWLINE# #UNINDENT# s = ( yield 1 ) #NEWLINE# ( version_other , ) = _s_uchar . unpack ( s . read ( 1 ) ) #NEWLINE# if ( not self . version_supported ( version_other ) ) : #NEWLINE# #INDENT# self . defaultHandshakeFailed ( 'protocol version mismatch' ) #NEWLINE# return #NEWLINE# #UNINDENT# s = ( yield self . packet_bytes ) #NEWLINE# hs_other = s . read ( self . packet_bytes ) #NEWLINE# if ( not self . is_client ) : #NEWLINE# #INDENT# ts_init = time . time ( ) #NEWLINE# hs_mine = self . generate_request ( context = hs_other ) #NEWLINE# p . transport . writeSequence ( ( self . version_packet , hs_mine ) ) #NEWLINE# #UNINDENT# p . transport . write ( self . generate_response ( hs_other ) ) #NEWLINE# s = ( yield self . packet_bytes ) #NEWLINE# hs_response = buffer ( s . read ( self . packet_bytes ) ) #NEWLINE# ts_received_back = time . time ( ) #NEWLINE# if ( not self . verify_response ( hs_mine , hs_response ) ) : #NEWLINE# #INDENT# self . defaultHandshakeFailed ( 'response verification failed' ) #NEWLINE# return #NEWLINE# #UNINDENT# p . handshakeSucceeded ( ( ts_init - self . epoch ) , ( ts_received_back - ts_init ) )