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