onionr now responds with data properly
This commit is contained in:
parent
50e6537e80
commit
5457e1fdb7
@ -138,7 +138,13 @@ class API:
|
||||
resp = Response(self._utils.exportMyPubkey())
|
||||
# setData should be something the communicator initiates, not this api
|
||||
elif action == 'getData':
|
||||
resp = Response(self._core.getData(data))
|
||||
resp = self._core.getData(data)
|
||||
if resp == False:
|
||||
abort(404)
|
||||
resp = ""
|
||||
resp = Response(resp)
|
||||
else:
|
||||
resp = Response("")
|
||||
|
||||
return resp
|
||||
|
||||
|
@ -31,6 +31,8 @@ class OnionrCommunicate:
|
||||
self._utils = onionrutils.OnionrUtils(self._core)
|
||||
blockProcessTimer = 0
|
||||
blockProcessAmount = 5
|
||||
heartBeatTimer = 0
|
||||
heartBeatRate = 10
|
||||
logger.debug('Communicator debugging enabled.')
|
||||
torID = open('data/hs/hostname').read()
|
||||
|
||||
@ -45,14 +47,17 @@ class OnionrCommunicate:
|
||||
self._core.clearDaemonQueue()
|
||||
while True:
|
||||
command = self._core.daemonQueue()
|
||||
|
||||
# Process blocks based on a timer
|
||||
blockProcessTimer += 1
|
||||
heartBeatTimer += 1
|
||||
if heartBeatRate == heartBeatTimer:
|
||||
logger.debug('Communicator heartbeat')
|
||||
heartBeatTimer = 0
|
||||
if blockProcessTimer == blockProcessAmount:
|
||||
self.lookupBlocks()
|
||||
self._core.processBlocks()
|
||||
blockProcessTimer = 0
|
||||
logger.debug('Communicator daemon heartbeat')
|
||||
#logger.debug('Communicator daemon heartbeat')
|
||||
if command != False:
|
||||
if command[0] == 'shutdown':
|
||||
logger.warn('Daemon recieved exit command.')
|
||||
|
@ -45,6 +45,8 @@ class Core:
|
||||
|
||||
if not os.path.exists('data/'):
|
||||
os.mkdir('data/')
|
||||
if not os.path.exists('data/blocks/'):
|
||||
os.mkdir('data/blocks/')
|
||||
|
||||
if not os.path.exists(self.blockDB):
|
||||
self.createBlockDB()
|
||||
@ -142,9 +144,12 @@ class Core:
|
||||
|
||||
def getData(self,hash):
|
||||
'''simply return the data associated to a hash'''
|
||||
try:
|
||||
dataFile = open(self.blockDataLocation + hash + '.dat')
|
||||
data = dataFile.read()
|
||||
dataFile.close()
|
||||
except FileNotFoundError:
|
||||
data = False
|
||||
return data
|
||||
|
||||
def setData(self, data):
|
||||
@ -158,7 +163,7 @@ class Core:
|
||||
raise Exception("Data is already set for " + dataHash)
|
||||
else:
|
||||
blockFile = open(blockFileName, 'w')
|
||||
blockFile.write(data)
|
||||
blockFile.write(data.decode())
|
||||
blockFile.close()
|
||||
return dataHash
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user