diff --git a/onionr/communicator2.py b/onionr/communicator2.py index 01af7270..e8f5e7f3 100755 --- a/onionr/communicator2.py +++ b/onionr/communicator2.py @@ -469,9 +469,7 @@ class OnionrCommunicatorDaemon: # Create a socket or connect to one. # The socket handler (such as the plugin or app using it) is specified in startData['reason] startData = json.loads(cmd[1]) - rCallback = onionrsockets.getSocketCallbackRecieveHandler(self._core, startData['reason'], startData['create']) - sCallback = onionrsockets.getSocketCallbackSendHandler(self._core, startData['reason'], startData['create']) - self.onionrsockets.append(onionrsockets.OnionrSockets(self._core, startData, recieveCallback=rCallback, sendCallback=sCallback)) + self.onionrsockets.append(onionrsockets.OnionrSockets(self._core, startData)) else: logger.info('Recieved daemonQueue command:' + cmd[0]) diff --git a/onionr/onionr.py b/onionr/onionr.py index c8bb2873..1a50783b 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -26,6 +26,7 @@ if sys.version_info[0] == 2 or sys.version_info[1] < 5: print('Error, Onionr requires Python 3.4+') sys.exit(1) import os, base64, random, getpass, shutil, subprocess, requests, time, platform, datetime, re, json, getpass, sqlite3 +import webbrowser from threading import Thread import api, core, config, logger, onionrplugins as plugins, onionrevents as events import onionrutils @@ -217,6 +218,8 @@ class Onionr: 'getpasswd': self.printWebPassword, 'get-passwd': self.printWebPassword, + 'chat': self.onionrCore.chatInst.connect() + 'friend': self.friendCmd } @@ -826,7 +829,6 @@ class Onionr: logger.error('%s add-file ' % sys.argv[0], timestamp = False) def openUI(self): - import webbrowser url = 'http://127.0.0.1:%s/ui/index.html?timingToken=%s' % (config.get('client.port', 59496), self.onionrUtils.getTimeBypassToken()) print('Opening %s ...' % url) diff --git a/onionr/onionrsockets.py b/onionr/onionrsockets.py index 2a63613c..610074c6 100644 --- a/onionr/onionrsockets.py +++ b/onionr/onionrsockets.py @@ -36,7 +36,7 @@ def getSocketCallbackSendHandler(coreInst, reason, create): retData = coreInst.chatInst.sendMessage class OnionrSockets: - def __init__(self, coreInst, socketInfo, recieveCallback=None, sendCallback=None): + def __init__(self, coreInst, socketInfo): '''Create a new Socket object. This interface is named a bit misleadingly and does not actually forward network requests. @@ -48,12 +48,6 @@ class OnionrSockets: self.socketID = secrets.token_hex(32) # Generate an ID for this socket self._core = coreInst self.socketInfo = socketInfo - - if not callable(sendCallback) or not callable(recieveCallback) - raise ValueError("callback must be a function") - - self.sendCallback = sendCallback - self.recieveCallback = recieveCallback # Make sure socketInfo provides all necessary values for i in ('peer', 'address', 'create', 'port'): @@ -69,6 +63,9 @@ class OnionrSockets: self.serverAddress = socketInfo['address'] self.connected = False + self.readData = [] + self.sendData = 0 + if self.isServer: self.createServer() else: @@ -117,11 +114,25 @@ class OnionrSockets: data = conn.recv(1024) if data: data = data.decode() - self.callback(self, data) + self.readData.append(data) else: sel.unregister(conn) conn.close() + def sendData(self, data): + try: + data = data.encode() + except AttributeError: + pass + self.sendData = data + + def readData(self): + try: + data = self.readData.pop(0) + except IndexError: + data = '' + return data + def connectServer(self): # Set the Tor proxy socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', config.get('tor.socksport'), rdns=True) @@ -131,5 +142,7 @@ class OnionrSockets: with remoteSocket as s: s.connect((self.serverAddress, self.port)) data = s.recv(1024) - data.send(self.sendCallback(self, data.decode())) + if self.sendData != 0: + s.send(self.sendData) + self.sendData = 0 return \ No newline at end of file