added processBlocks function
This commit is contained in:
parent
3f3a29439e
commit
67a84e2a19
@ -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))
|
||||
|
||||
|
@ -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.')
|
||||
|
@ -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):
|
||||
'''
|
||||
@ -217,3 +228,10 @@ class Core:
|
||||
'''
|
||||
key = base64.b64encode(os.urandom(32))
|
||||
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
|
Loading…
Reference in New Issue
Block a user