#NEWLINE# def bootstrap( self , addrs ) : #NEWLINE# #INDENT# '\n        Bootstrap the server by connecting to other known nodes in the network.\n\n        Args:\n            addrs: A `list` of (ip, port) `tuple` pairs.  Note that only IP addresses\n                   are acceptable - hostnames will cause an error.\n        ' #NEWLINE# if ( self . protocol . transport is None ) : #NEWLINE# #INDENT# return task . deferLater ( reactor , 1 , self . bootstrap , addrs ) #NEWLINE# #UNINDENT# def initTable( results , challenge , id ) : #NEWLINE# #INDENT# nodes = [ ] #NEWLINE# for ( addr , result ) in results . items ( ) : #NEWLINE# #INDENT# ip = addr [ 0 ] #NEWLINE# port = addr [ 1 ] #NEWLINE# if result [ 0 ] : #NEWLINE# #INDENT# resultSign = result [ 1 ] [ 'signature' ] #NEWLINE# resultId = result [ 1 ] [ 'id' ] #NEWLINE# resultIdHex = resultId . encode ( 'hex' ) . upper ( ) #NEWLINE# data = self . protocol . certificateExists ( resultIdHex ) #NEWLINE# if ( not data ) : #NEWLINE# #INDENT# identifier = digest ( '{}cert' . format ( resultIdHex ) ) #NEWLINE# self . protocol . callCertFindValue ( Node ( resultId , ip , port ) , Node ( identifier ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cert_stored = self . protocol . searchForCertificate ( resultIdHex ) #NEWLINE# try : #NEWLINE# #INDENT# OpenSSL . crypto . verify ( cert_stored , resultSign , challenge , 'sha256' ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logger ( self . protocol . sourceNode , 'Failed verification of challenge during bootstrap' ) #NEWLINE# #UNINDENT# nodes . append ( Node ( resultId , ip , port ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# spider = NodeSpiderCrawl ( self . protocol , self . node , nodes , self . ksize , self . alpha ) #NEWLINE# return spider . find ( ) #NEWLINE# #UNINDENT# ds = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# challenge = generate_challenge ( ) #NEWLINE# id = None #NEWLINE# if addrs : #NEWLINE# #INDENT# data = addrs [ 0 ] #NEWLINE# addr = ( data [ 0 ] , data [ 1 ] ) #NEWLINE# logger ( self . protocol . sourceNode , '\n########### DOING BOOTSTRAP ###########' ) #NEWLINE# try : #NEWLINE# #INDENT# cert = OpenSSL . crypto . load_certificate ( OpenSSL . crypto . FILETYPE_PEM , data [ 2 ] ) #NEWLINE# fingerprint = cert . digest ( 'sha256' ) #NEWLINE# id = fingerprint . replace ( ':' , '' ) [ ( - 40 ) : ] #NEWLINE# private = OpenSSL . crypto . load_privatekey ( OpenSSL . crypto . FILETYPE_PEM , self . protocol . priv_key , '' ) #NEWLINE# signature = OpenSSL . crypto . sign ( private , '{}{}' . format ( id , challenge ) , 'sha256' ) #NEWLINE# ds [ addr ] = self . protocol . ping ( addr , self . node . id , challenge , signature , self . protocol . getOwnCert ( ) ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# logger ( self . protocol . sourceNode , 'Certificate creation failed' ) #NEWLINE# #UNINDENT# self . protocol . storeCert ( data [ 2 ] , id ) #NEWLINE# node = Node ( id . decode ( 'hex' ) , data [ 0 ] , data [ 1 ] ) #NEWLINE# if self . protocol . router . isNewNode ( node ) : #NEWLINE# #INDENT# return deferredDict ( ds ) . addCallback ( initTable , challenge , id ) #NEWLINE# #UNINDENT# #UNINDENT# return deferredDict ( ds )