added processBlocks function

This commit is contained in:
Kevin Froman 2018-01-25 16:39:09 -06:00
parent 3f3a29439e
commit 67a84e2a19
3 changed files with 31 additions and 8 deletions

View File

@ -129,11 +129,7 @@ class API:
pass
elif action == 'getPGP':
resp = Response(self._utils.exportMyPubkey())
elif action == 'setData':
if data == None:
abort(401)
else:
self._core.setData(data)
# setData should be something the communicator initiates, not this api
elif action == 'getData':
resp = Response(self._core.getData(data))

View File

@ -28,6 +28,8 @@ class OnionrCommunicate:
This class handles communication with nodes in the Onionr network.
'''
self._core = core.Core()
blockProcessTimer = 0
blockProccesAmount = 5
if debug:
print('Communicator debugging enabled')
torID = open('data/hs/hostname').read()
@ -42,8 +44,15 @@ class OnionrCommunicate:
while True:
command = self._core.daemonQueue()
# Process blocks based on a timer
blockProcessTimer += 1
if blockProcessTimer == blockProcessAmount:
self._core.processBlocks()
blockProcessTimer = 0
if debug:
print('Daemon heartbeat')
print('Communicator daemon heartbeat')
if command != False:
if command[0] == 'shutdown':
print('Daemon recieved exit command.')

View File

@ -134,7 +134,18 @@ class Core:
def setData(self, data):
'''set the data assciated with a hash'''
hasher = hashlib.sha3_256
data = data.encode()
hasher = hashlib.sha3_256()
hasher.update(data)
dataHash = hasher.hexdigest()
blockFileName = self.blockDataLocation + dataHash + '.dat'
if os.path.exists(blockFileName):
raise Exception("Data is already set for " + dataHash)
else:
blockFile = open(blockFileName, 'w')
blockFile.write(data)
blockFile.close()
return dataHash
def dataDirEncrypt(self, password):
'''
@ -216,4 +227,11 @@ class Core:
generate and return an HMAC key
'''
key = base64.b64encode(os.urandom(32))
return key
return key
def processBlocks(self):
'''
Work with the block database and download any missing blocks
This is meant to be called from the communicator daemon on its timer.
'''
return