#NEWLINE# def _handle_valuable_blob_response( self , response_dict , peer , request ) : #NEWLINE# #INDENT# if ( not ( request . response_identifier in response_dict ) ) : #NEWLINE# #INDENT# return InvalidResponseError ( 'response identifier not in response' ) #NEWLINE# #UNINDENT# response = response_dict [ request . response_identifier ] #NEWLINE# if ( 'error' in response ) : #NEWLINE# #INDENT# if ( response [ 'error' ] == 'RATE_UNSET' ) : #NEWLINE# #INDENT# return 0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return InvalidResponseError ( ( 'Got an unknown error from the peer: %s' % ( response [ 'error' ] , ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not ( 'valuable_blob_hashes' in response ) ) : #NEWLINE# #INDENT# return InvalidResponseError ( "Missing the required field 'valuable_blob_hashes'" ) #NEWLINE# #UNINDENT# hashes = response [ 'valuable_blob_hashes' ] #NEWLINE# log . info ( 'Handling %s valuable blob hashes from %s' , str ( len ( hashes ) ) , str ( peer ) ) #NEWLINE# expire_time = ( datetime . datetime . now ( ) + datetime . timedelta ( minutes = 10 ) ) #NEWLINE# reference = None #NEWLINE# unique_hashes = set ( ) #NEWLINE# if ( 'reference' in response ) : #NEWLINE# #INDENT# reference = response [ 'reference' ] #NEWLINE# #UNINDENT# for ( blob_hash , peer_score ) in hashes : #NEWLINE# #INDENT# if ( reference is None ) : #NEWLINE# #INDENT# reference = blob_hash #NEWLINE# #UNINDENT# self . _last_blob_hashes_from_peers [ peer ] = ( blob_hash , expire_time ) #NEWLINE# if ( not ( ( blob_hash in self . _valuable_hashes ) or ( blob_hash in self . _blob_infos ) ) ) : #NEWLINE# #INDENT# self . _valuable_hashes [ blob_hash ] = ( peer_score , reference , peer ) #NEWLINE# #UNINDENT# unique_hashes . add ( blob_hash ) #NEWLINE# #UNINDENT# if len ( unique_hashes ) : #NEWLINE# #INDENT# self . _update_local_score ( peer , len ( unique_hashes ) ) #NEWLINE# peer . update_stats ( 'downloaded_valuable_blob_hashes' , len ( unique_hashes ) ) #NEWLINE# peer . update_score ( len ( unique_hashes ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . _update_local_score ( peer , ( - 0.0001 ) ) #NEWLINE# #UNINDENT# return len ( unique_hashes )