From 70e2ccbc0a6c27d94cdfc8ca6bc73d4be3c82c40 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Sat, 22 Sep 2018 20:21:39 -0500 Subject: [PATCH] work on sockets --- onionr/communicator2.py | 13 +++++++++---- onionr/onionrsockets.py | 7 ++++--- .../default-plugins/metadataprocessor/main.py | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/onionr/communicator2.py b/onionr/communicator2.py index 108ecf0d..00e80e13 100755 --- a/onionr/communicator2.py +++ b/onionr/communicator2.py @@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ''' -import sys, os, core, config, json, requests, time, logger, threading, base64, onionr +import sys, os, core, config, json, requests, time, logger, threading, base64, onionr, uuid import onionrexceptions, onionrpeers, onionrevents as events, onionrplugins as plugins, onionrblockapi as block import onionrdaemontools, onionrsockets, onionrchat from dependencies import secrets @@ -471,12 +471,17 @@ class OnionrCommunicatorDaemon: self.blockToUpload = cmd[1] threading.Thread(target=self.uploadBlock).start() elif cmd[0] == 'startSocket': + # Create our own socket server socketInfo = json.loads(cmd[1]) peer = socketInfo['peer'] reason = socketInfo['reason'] - self.socketServer.addSocket(peer, reason) - elif cmd[0] == 'connectSocket': - pass + threading.Thread(target=self.socketServer.addSocket, args=(peer, reason)).start() + elif cmd[0] == 'addSocket': + # Socket server was created for us + socketInfo = json.loads(cmd[1]) + peer = socketInfo['peer'] + reason = socketInfo['reason'] + threading.Thread(target=self.socketClient.startSocket, args=(peer, reason)).start() else: logger.info('Recieved daemonQueue command:' + cmd[0]) diff --git a/onionr/onionrsockets.py b/onionr/onionrsockets.py index 73920f27..735b22c6 100644 --- a/onionr/onionrsockets.py +++ b/onionr/onionrsockets.py @@ -18,6 +18,7 @@ along with this program. If not, see . ''' import stem.control +import threading import socks, config, uuid import onionrexceptions, time, requests, onionrblockapi from dependencies import secrets @@ -36,7 +37,7 @@ class OnionrSocketServer: app = flask.Flask(__name__) http_server = WSGIServer((socket.service_id, bindPort), app) - http_server.serve_forever() + threading.Thread(target=http_server.serve_forever).start() @app.route('/dc/', methods=['POST']) def acceptConn(self): @@ -67,7 +68,7 @@ class OnionrSocketServer: self.responseData[socket.service_id] = '' - self._core.insertBlock(uuid.uuid4(), header='startSocket', sign=True, encryptType='asym', asymPeer=peer, meta={'reason': reason}) + self._core.insertBlock(uuid.uuid4(), header='socket', sign=True, encryptType='asym', asymPeer=peer, meta={'reason': reason}) while not self.killSocket: time.sleep(3) @@ -85,7 +86,7 @@ class OnionrSocketClient: self.connected = False self.killSocket = False - def startSocket(self, peer): + def startSocket(self, peer, reason): address = '' # Find the newest open socket for a given peer for block in self._core.getBlocksByType('openSocket'): diff --git a/onionr/static-data/default-plugins/metadataprocessor/main.py b/onionr/static-data/default-plugins/metadataprocessor/main.py index 85b7d9de..2b4deb86 100644 --- a/onionr/static-data/default-plugins/metadataprocessor/main.py +++ b/onionr/static-data/default-plugins/metadataprocessor/main.py @@ -75,7 +75,7 @@ def on_processBlocks(api): if api.data['validSig'] == True: _processForwardKey(api, myBlock) # socket blocks - elif blockType == 'openSocket': + elif blockType == 'socket': if api.data['validSig'] == True and myBlock.decrypted: # we check if it is decrypted as a way of seeing if it was for us try: address = api.data['address']