#NEWLINE# @ tornado . web . asynchronous #NEWLINE# def get( self ) : #NEWLINE# #INDENT# failure_reason = '' #NEWLINE# warning_message = '' #NEWLINE# info_hash = self . get_argument ( 'info_hash' ) #NEWLINE# peer_id = self . get_argument ( 'peer_id' ) #NEWLINE# ip = self . request . remote_ip #NEWLINE# port = self . get_argument ( 'port' ) #NEWLINE# if ( not info_hash ) : #NEWLINE# #INDENT# return self . send_error ( MISSING_INFO_HASH ) #NEWLINE# #UNINDENT# if ( not peer_id ) : #NEWLINE# #INDENT# return self . send_error ( MISSING_PEER_ID ) #NEWLINE# #UNINDENT# if ( not port ) : #NEWLINE# #INDENT# return self . send_error ( MISSING_PORT ) #NEWLINE# #UNINDENT# if ( len ( info_hash ) != INFO_HASH_LEN ) : #NEWLINE# #INDENT# return self . send_error ( INVALID_INFO_HASH ) #NEWLINE# #UNINDENT# if ( len ( peer_id ) != PEER_ID_LEN ) : #NEWLINE# #INDENT# return self . send_error ( INVALID_PEER_ID ) #NEWLINE# #UNINDENT# info_hash = str ( info_hash ) #NEWLINE# compact = int ( self . get_argument ( 'compact' , 0 ) ) #NEWLINE# no_peer_id = int ( self . get_argument ( 'no_peer_id' , 0 ) ) #NEWLINE# event = self . get_argument ( 'event' , '' ) #NEWLINE# numwant = int ( self . get_argument ( 'numwant' , DEFAULT_ALLOWED_PEERS ) ) #NEWLINE# if ( numwant > MAX_ALLOWED_PEERS ) : #NEWLINE# #INDENT# return self . send_error ( INVALID_NUMWANT ) #NEWLINE# #UNINDENT# tracker_id = self . get_argument ( 'trackerid' , '' ) #NEWLINE# if event : #NEWLINE# #INDENT# store_peer_info ( info_hash , peer_id , ip , port , event ) #NEWLINE# #UNINDENT# response = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# response [ 'interval' ] = get_config ( ) . getint ( 'tracker' , 'interval' ) #NEWLINE# response [ 'min interval' ] = get_config ( ) . getint ( 'tracker' , 'min_interval' ) #NEWLINE# response [ 'tracker id' ] = tracker_id #NEWLINE# response [ 'complete' ] = no_of_seeders ( info_hash ) #NEWLINE# response [ 'incomplete' ] = no_of_leechers ( info_hash ) #NEWLINE# response [ 'peers' ] = get_peer_list ( info_hash , numwant , compact , no_peer_id ) #NEWLINE# if failure_reason : #NEWLINE# #INDENT# response [ 'failure reason' ] = failure_reason #NEWLINE# #UNINDENT# if warning_message : #NEWLINE# #INDENT# response [ 'warning message' ] = warning_message #NEWLINE# #UNINDENT# self . set_header ( 'Content-Type' , 'text/plain' ) #NEWLINE# self . write ( bencode ( response ) ) #NEWLINE# self . finish ( )