#NEWLINE# def listen_tcp_proc( self , coro = None ) : #NEWLINE# #INDENT# coro . set_daemon ( ) #NEWLINE# tcp_sock = asyncoro . AsyncSocket ( socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) ) #NEWLINE# tcp_sock . setsockopt ( socket . SOL_SOCKET , socket . SO_REUSEADDR , 1 ) #NEWLINE# tcp_sock . bind ( ( '' , self . listen_port ) ) #NEWLINE# tcp_sock . listen ( 8 ) #NEWLINE# auth_len = len ( dispy . auth_code ( '' , '' ) ) #NEWLINE# def tcp_task( conn , addr , coro = None ) : #NEWLINE# #INDENT# conn . settimeout ( 5 ) #NEWLINE# try : #NEWLINE# #INDENT# msg = ( yield conn . recvall ( auth_len ) ) #NEWLINE# msg = ( yield conn . recv_msg ( ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logger . debug ( traceback . format_exc ( ) ) #NEWLINE# logger . debug ( 'Ignoring invalid TCP message from %s:%s' , addr [ 0 ] , addr [ 1 ] ) #NEWLINE# raise StopIteration #NEWLINE# #UNINDENT# finally : #NEWLINE# #INDENT# conn . close ( ) #NEWLINE# #UNINDENT# logger . debug ( 'Ping message from %s (%s)' , addr [ 0 ] , addr [ 1 ] ) #NEWLINE# try : #NEWLINE# #INDENT# info = asyncoro . unserialize ( msg [ len ( 'PING:' . encode ( ) ) : ] ) #NEWLINE# if ( info [ 'version' ] != __version__ ) : #NEWLINE# #INDENT# logger . warning ( 'Ignoring %s due to version mismatch: %s / %s' , info [ 'ip_addrs' ] , info [ 'version' ] , __version__ ) #NEWLINE# raise StopIteration #NEWLINE# #UNINDENT# self . scheduler_ip_addrs = ( info [ 'ip_addrs' ] + [ addr [ 0 ] ] ) #NEWLINE# self . scheduler_port = info [ 'port' ] #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logger . debug ( 'Ignoring ping message from %s (%s)' , addr [ 0 ] , addr [ 1 ] ) #NEWLINE# logger . debug ( traceback . format_exc ( ) ) #NEWLINE# raise StopIteration #NEWLINE# #UNINDENT# if info . get ( 'relay' , None ) : #NEWLINE# #INDENT# logger . debug ( 'Ignoring ping back (from %s)' , addr [ 0 ] ) #NEWLINE# raise StopIteration #NEWLINE# #UNINDENT# logger . debug ( 'relaying ping from %s / %s' , info [ 'ip_addrs' ] , addr [ 0 ] ) #NEWLINE# if ( self . node_port == self . listen_port ) : #NEWLINE# #INDENT# info [ 'relay' ] = 'y' #NEWLINE# #UNINDENT# bc_sock = asyncoro . AsyncSocket ( socket . socket ( socket . AF_INET , socket . SOCK_DGRAM ) ) #NEWLINE# bc_sock . setsockopt ( socket . SOL_SOCKET , socket . SO_BROADCAST , 1 ) #NEWLINE# ( yield bc_sock . sendto ( ( 'PING:' . encode ( ) + asyncoro . serialize ( info ) ) , ( '<broadcast>' , self . node_port ) ) ) #NEWLINE# bc_sock . close ( ) #NEWLINE# #UNINDENT# while 1 : #NEWLINE# #INDENT# ( conn , addr ) = ( yield tcp_sock . accept ( ) ) #NEWLINE# asyncoro . Coro ( tcp_task , conn , addr )