added downloadBlock function
This commit is contained in:
		
							parent
							
								
									f4bb9ca093
								
							
						
					
					
						commit
						7f688e0696
					
				
					 1 changed files with 15 additions and 1 deletions
				
			
		|  | @ -122,9 +122,23 @@ class OnionrCommunicate: | ||||||
|         ''' |         ''' | ||||||
|         for i in self._core.getBlockList(True).split("\n"): |         for i in self._core.getBlockList(True).split("\n"): | ||||||
|             if i != "": |             if i != "": | ||||||
|                 print('UNSAVED BLOCK:', i) |                 logger.warn('UNSAVED BLOCK:', i) | ||||||
|  |                 data = self.downloadBlock(i) | ||||||
|         return |         return | ||||||
|      |      | ||||||
|  |     def downloadBlock(self, hash): | ||||||
|  |         peerList = self._core.listPeers() | ||||||
|  |         blocks = '' | ||||||
|  |         for i in peerList: | ||||||
|  |             hasher = hashlib.sha3_256() | ||||||
|  |             data = self.performGet('getData', i, hash) | ||||||
|  |             if data == False or len(data) > 10000000: | ||||||
|  |                 continue | ||||||
|  |             hasher.update(data.encode()) | ||||||
|  |             if hasher.hexdigest() == hash: | ||||||
|  |                 self._core.setData(data) | ||||||
|  |                 logger.info('Successfully obtained data for ' + hash) | ||||||
|  | 
 | ||||||
|     def performGet(self, action, peer, data=None, type='tor'): |     def performGet(self, action, peer, data=None, type='tor'): | ||||||
|         '''Performs a request to a peer through Tor or i2p (currently only tor)''' |         '''Performs a request to a peer through Tor or i2p (currently only tor)''' | ||||||
|         if not peer.endswith('.onion') and not peer.endswith('.onion/'): |         if not peer.endswith('.onion') and not peer.endswith('.onion/'): | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue