added downloadBlock function

This commit is contained in:
Kevin Froman 2018-01-28 16:14:19 -06:00
parent f4bb9ca093
commit 7f688e0696
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B

View File

@ -122,8 +122,22 @@ 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)'''