#NEWLINE# def rpc_find_node( self , sender , nodeid , key , challenge , signature ) : #NEWLINE# #INDENT# nodeIdHex = nodeid . encode ( 'hex' ) . upper ( ) #NEWLINE# logger ( self . sourceNode , 'finding neighbors of {} in local table' . format ( long ( nodeIdHex , 16 ) ) ) #NEWLINE# source = Node ( nodeid , sender [ 0 ] , sender [ 1 ] ) #NEWLINE# cert_stored = self . searchForCertificate ( nodeIdHex ) #NEWLINE# if ( cert_stored == None ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# private = OpenSSL . crypto . load_privatekey ( OpenSSL . crypto . FILETYPE_PEM , self . priv_key , '' ) #NEWLINE# signature = OpenSSL . crypto . sign ( private , challenge , 'sha256' ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logger ( self . sourceNode , 'RETNONE: Failed make signature for find node' ) #NEWLINE# return None #NEWLINE# #UNINDENT# logger ( self . sourceNode , 'Certificate for {} not found in store' . format ( source ) ) #NEWLINE# return { #NEWLINE# #INDENT# 'NACK' : None , #NEWLINE# 'signature' : signature , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# sourceNodeIdHex = self . sourceNode . id . encode ( 'hex' ) . upper ( ) #NEWLINE# payload = '{}{}' . format ( sourceNodeIdHex , challenge ) #NEWLINE# OpenSSL . crypto . verify ( cert_stored , signature , payload , 'sha256' ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logger ( self . sourceNode , 'RETNONE: Bad signature for sender of find_node: {}' . format ( source ) ) #NEWLINE# return None #NEWLINE# #UNINDENT# self . router . addContact ( source ) #NEWLINE# node = Node ( key ) #NEWLINE# bucket = map ( list , self . router . findNeighbors ( node , exclude = source ) ) #NEWLINE# try : #NEWLINE# #INDENT# private = OpenSSL . crypto . load_privatekey ( OpenSSL . crypto . FILETYPE_PEM , self . priv_key , '' ) #NEWLINE# signature = OpenSSL . crypto . sign ( private , challenge , 'sha256' ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logger ( self . sourceNode , 'RETNONE: Signing of rpc_find_node failed' ) #NEWLINE# return None #NEWLINE# #UNINDENT# value = { #NEWLINE# #INDENT# 'bucket' : bucket , #NEWLINE# 'signature' : signature , #NEWLINE# #UNINDENT# } #NEWLINE# return value