#NEWLINE# def _handle_info_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 ( 'blob_lengths' in response ) ) : #NEWLINE# #INDENT# return InvalidResponseError ( "Missing the required field 'blob_lengths'" ) #NEWLINE# #UNINDENT# raw_blob_lengths = response [ 'blob_lengths' ] #NEWLINE# log . info ( 'Handling %s blob lengths from %s' , str ( len ( raw_blob_lengths ) ) , str ( peer ) ) #NEWLINE# log . debug ( 'blobs: %s' , str ( raw_blob_lengths ) ) #NEWLINE# infos = [ ] #NEWLINE# unique_hashes = set ( ) #NEWLINE# for ( blob_hash , length ) in raw_blob_lengths : #NEWLINE# #INDENT# if ( blob_hash in self . _valuable_hashes ) : #NEWLINE# #INDENT# ( peer_score , reference , peer ) = self . _valuable_hashes [ blob_hash ] #NEWLINE# del self . _valuable_hashes [ blob_hash ] #NEWLINE# infos . append ( ValuableBlobInfo ( blob_hash , length , reference , peer , peer_score ) ) #NEWLINE# unique_hashes . add ( blob_hash ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( blob_hash in request . request_dict [ 'blob_length' ] [ 'blob_hashes' ] ) : #NEWLINE# #INDENT# unique_hashes . add ( blob_hash ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# d = self . info_manager . save_blob_infos ( infos ) #NEWLINE# d . addCallback ( ( lambda _ : self . download_manager . add_blobs_to_download ( infos ) ) ) #NEWLINE# def pay_or_penalize_peer( ) : #NEWLINE# #INDENT# if len ( unique_hashes ) : #NEWLINE# #INDENT# self . _update_local_score ( peer , len ( unique_hashes ) ) #NEWLINE# peer . update_stats ( 'downloaded_valuable_blob_infos' , 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 ) #NEWLINE# #UNINDENT# d . addCallback ( ( lambda _ : pay_or_penalize_peer ( ) ) ) #NEWLINE# return self