* fixed broken local command

* work on communicator2 block syncing
This commit is contained in:
Kevin Froman 2018-06-15 14:09:41 -05:00
parent e339b78e88
commit 31a35472ce
No known key found for this signature in database
GPG Key ID: 0D414D0FE405B63B
2 changed files with 20 additions and 9 deletions

View File

@ -58,10 +58,10 @@ class OnionrCommunicatorDaemon:
self.getOnlinePeers() self.getOnlinePeers()
OnionrCommunicatorTimers(self, self.daemonCommands, 5) OnionrCommunicatorTimers(self, self.daemonCommands, 5)
OnionrCommunicatorTimers(self, self.detectAPICrash, 12) OnionrCommunicatorTimers(self, self.detectAPICrash, 5)
OnionrCommunicatorTimers(self, self.getOnlinePeers, 60) OnionrCommunicatorTimers(self, self.getOnlinePeers, 60)
OnionrCommunicatorTimers(self, self.lookupBlocks, 120) #OnionrCommunicatorTimers(self, self.lookupBlocks, 120)
OnionrCommunicatorTimers(self, self.getBlocks, 30) #OnionrCommunicatorTimers(self, self.getBlocks, 30)
# Main daemon loop, mainly for calling timers, do not do any complex operations here # Main daemon loop, mainly for calling timers, do not do any complex operations here
while not self.shutdown: while not self.shutdown:
@ -82,13 +82,18 @@ class OnionrCommunicatorDaemon:
if self._core.utils.validateHash(i): if self._core.utils.validateHash(i):
# if newline seperated string is valid hash # if newline seperated string is valid hash
if not os.path.exists('data/blocks/' + i + '.db'): if not os.path.exists('data/blocks/' + i + '.db'):
# if block does not exist on disk # if block does not exist on disk and is not already in block queue
self.blockQueue.append(i) if i not in self.blockQueue:
self.blockQueue.append(i)
self.decrementThreadCount('lookupBlocks') self.decrementThreadCount('lookupBlocks')
return return
def getBlocks(self): def getBlocks(self):
'''download new blocks''' '''download new blocks'''
for blockHash in self.blockQueue:
content = self.peerAction(self.pickOnlinePeer(), 'getData', data=blockHash)
if content != False:
newBlock = block.Block()
return return
def pickOnlinePeer(self): def pickOnlinePeer(self):
@ -159,8 +164,11 @@ class OnionrCommunicatorDaemon:
logger.info('Performing ' + action + ' with ' + peer + ' on port ' + str(self.proxyPort)) logger.info('Performing ' + action + ' with ' + peer + ' on port ' + str(self.proxyPort))
retData = self._core._utils.doGetRequest('http://' + peer + '/public/?action=' + action + '&data=' + data, port=self.proxyPort) retData = self._core._utils.doGetRequest('http://' + peer + '/public/?action=' + action + '&data=' + data, port=self.proxyPort)
if retData == False: if retData == False:
self.onlinePeers.remove(peer) try:
self.getOnlinePeers() # Will only add a new peer to pool if needed self.onlinePeers.remove(peer)
self.getOnlinePeers() # Will only add a new peer to pool if needed
except ValueError:
pass
return retData return retData
def heartbeat(self): def heartbeat(self):
@ -202,7 +210,7 @@ class OnionrCommunicatorDaemon:
def detectAPICrash(self): def detectAPICrash(self):
'''exit if the api server crashes/stops''' '''exit if the api server crashes/stops'''
if self._core._utils.localCommand('ping') != 'pong': if self._core._utils.localCommand('ping', silent=False) != 'pong':
for i in range(5): for i in range(5):
if self._core._utils.localCommand('ping') == 'pong': if self._core._utils.localCommand('ping') == 'pong':
break # break for loop break # break for loop

View File

@ -176,8 +176,11 @@ class OnionrUtils:
config.reload() config.reload()
self.getTimeBypassToken() self.getTimeBypassToken()
# TODO: URL encode parameters, just as an extra measure. May not be needed, but should be added regardless. # TODO: URL encode parameters, just as an extra measure. May not be needed, but should be added regardless.
with open('data/host.txt', 'r') as host:
hostname = host.read()
payload = 'http://%s:%s/client/?action=%s&token=%s&timingToken=%s' % (hostname, config.get('client.port'), command, config.get('client.hmac'), self.timingToken)
try: try:
retData = requests.get('http://%s:%s/client/?action=%s&token=%s&timingToken=' % (open('data/host.txt', 'r').read(), config.get('client.port', 59496), command, config.get('client.hmac'), self.timingToken)).text retData = requests.get(payload).text
except Exception as error: except Exception as error:
if not silent: if not silent:
logger.error('Failed to make local request (command: %s).' % command, error=error) logger.error('Failed to make local request (command: %s).' % command, error=error)