added downloadBlock function
parent
f4bb9ca093
commit
7f688e0696
|
@ -122,9 +122,23 @@ class OnionrCommunicate:
|
|||
'''
|
||||
for i in self._core.getBlockList(True).split("\n"):
|
||||
if i != "":
|
||||
print('UNSAVED BLOCK:', i)
|
||||
logger.warn('UNSAVED BLOCK:', i)
|
||||
data = self.downloadBlock(i)
|
||||
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'):
|
||||
'''Performs a request to a peer through Tor or i2p (currently only tor)'''
|
||||
if not peer.endswith('.onion') and not peer.endswith('.onion/'):
|
||||
|
|
Loading…
Reference in New Issue