From c5a0b299889a33d395c7e142887e7966c72abc93 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Mon, 7 Jan 2019 15:09:58 -0600 Subject: [PATCH] communicator db responses probably finished --- onionr/api.py | 7 +++++-- onionr/communicator2.py | 5 +++-- onionr/core.py | 3 ++- onionr/onionr.py | 12 ++++++++---- onionr/onionrutils.py | 1 - 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/onionr/api.py b/onionr/api.py index 62467631..48c70d37 100755 --- a/onionr/api.py +++ b/onionr/api.py @@ -296,10 +296,13 @@ class API: @app.route('/queueResponse/') def queueResponse(name): + resp = '' try: - res = self.queueResponse[name] + resp = self.queueResponse[name] except KeyError: - resp = '' + pass + else: + del self.queueResponse[name] return Response(resp) @app.route('/ping') diff --git a/onionr/communicator2.py b/onionr/communicator2.py index 6adb1f2c..cf04a755 100755 --- a/onionr/communicator2.py +++ b/onionr/communicator2.py @@ -507,9 +507,10 @@ class OnionrCommunicatorDaemon: else: logger.info('Recieved daemonQueue command:' + cmd[0]) - if cmd[4] != '': + if cmd[4] != '' and cmd[0] not in ('', None): if response != '': - self._core._utils.localCommand('queueResponseAdd', data='/' + cmd[4], post=True, postData=response) + self._core._utils.localCommand('queueResponseAdd/' + cmd[4], post=True, postData={'data': response}) + response = '' self.decrementThreadCount('daemonCommands') diff --git a/onionr/core.py b/onionr/core.py index ce29a0a2..c41537a5 100644 --- a/onionr/core.py +++ b/onionr/core.py @@ -384,7 +384,8 @@ class Core: Get a response sent by communicator to the API, by requesting to the API ''' assert len(responseID) > 0 - resp = self._utils.localCommand('queueResponse', data='/' + responseID, post=True) + resp = self._utils.localCommand('queueResponse/' + responseID) + return resp def clearDaemonQueue(self): ''' diff --git a/onionr/onionr.py b/onionr/onionr.py index 979ad189..ab184a1f 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -397,11 +397,15 @@ class Onionr: randID = str(uuid.uuid4()) self.onionrCore.daemonQueueAdd('connectedPeers', responseID=randID) while True: - time.sleep(1) - peers = self.onionrCore.daemonQueueGetResponse(randID) - if peers not in ('', None): - print(peers) + try: + time.sleep(3) + peers = self.onionrCore.daemonQueueGetResponse(randID) + except KeyboardInterrupt: break + if not type(peers) is None: + if peers not in ('', None): + print(peers) + break def listPeers(self): logger.info('Peer transport address list:') diff --git a/onionr/onionrutils.py b/onionr/onionrutils.py index 18b3e5ca..883b9756 100644 --- a/onionr/onionrutils.py +++ b/onionr/onionrutils.py @@ -173,7 +173,6 @@ class OnionrUtils: if data != '': data = '&data=' + urllib.parse.quote_plus(data) payload = 'http://%s:%s/%s%s' % (hostname, config.get('client.client.port'), command, data) - try: if post: retData = requests.post(payload, data=postData, headers={'token': config.get('client.webpassword')}).text