From d3f4e912f97c7c79d454a0ab22d5c403d085d096 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Thu, 20 Sep 2018 12:41:34 -0500 Subject: [PATCH] work on sockets --- onionr/communicator2.py | 2 +- onionr/netcontroller.py | 2 ++ onionr/onionr.py | 3 ++- onionr/onionrchat.py | 9 +++++---- onionr/onionrsockets.py | 13 +++++++------ 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/onionr/communicator2.py b/onionr/communicator2.py index 6716dcbe..7c8b6c0b 100755 --- a/onionr/communicator2.py +++ b/onionr/communicator2.py @@ -489,7 +489,7 @@ class OnionrCommunicatorDaemon: else: del self.sockets[mySocket.socketID] # Delete socket if we have no handler for it - threading.Thread(target=sockProgram, args=(self, mySocket)).start() + threading.Thread(target=sockProgram, args=(self, mySocket.socketID)).start() mySocket.startConn() def uploadBlock(self): diff --git a/onionr/netcontroller.py b/onionr/netcontroller.py index 56b12573..69dd8aeb 100644 --- a/onionr/netcontroller.py +++ b/onionr/netcontroller.py @@ -72,6 +72,8 @@ class NetController: controlPort = random.randint(1025, 65535) + config.set('tor.controlPort', controlPort, savefile=True) + hashedPassword = subprocess.Popen([self.torBinary, '--hash-password', plaintext], stdout=subprocess.PIPE, stderr=subprocess.PIPE) for line in iter(hashedPassword.stdout.readline, b''): password = line.decode() diff --git a/onionr/onionr.py b/onionr/onionr.py index bb2114ca..12e9b2fd 100755 --- a/onionr/onionr.py +++ b/onionr/onionr.py @@ -271,7 +271,8 @@ class Onionr: ''' def startChat(self): - socketInfo = json.dumps({'peer': '', 'address': '', 'port': 1337, 'create': True, 'reason': 'chat'}) + peer = sys.argv[2] + socketInfo = json.dumps({'peer': '', 'address': peer, 'port': 1337, 'create': True, 'reason': 'chat'}) self.onionrCore.daemonQueueAdd('startSocket', socketInfo) def getCommands(self): diff --git a/onionr/onionrchat.py b/onionr/onionrchat.py index f37f270e..33981d41 100644 --- a/onionr/onionrchat.py +++ b/onionr/onionrchat.py @@ -19,12 +19,13 @@ ''' import logger, time class OnionrChat: - def __init__(self, communicatorInst, socketInst): + def __init__(self, communicatorInst, socketID): self.communicator = communicatorInst - self.socket = socketInst + self.socket = self.communicator.sockets[socketID] while True: time.sleep(2) - logger.info(self.socket.readData()) - self.socket.sendData('rekt') + logger.info('Chat: got %s' % (self.socket.getReadData(),)) + time.sleep(1) + self.socket.addSendData('rekt') return \ No newline at end of file diff --git a/onionr/onionrsockets.py b/onionr/onionrsockets.py index 740c9054..dc9702c1 100644 --- a/onionr/onionrsockets.py +++ b/onionr/onionrsockets.py @@ -18,7 +18,7 @@ along with this program. If not, see . ''' import stem.control -import socket, selectors, socks, config +import socket, selectors, socks, config, uuid import onionrexceptions, time, onionrchat from dependencies import secrets sel = selectors.DefaultSelector() @@ -53,8 +53,9 @@ class OnionrSockets: self.readData = [] self.sendData = 0 + config.reload() - def startConn(): + def startConn(self): if self.isServer: self.createServer() else: @@ -68,8 +69,8 @@ class OnionrSockets: ourInternalPort = 1338 # Setup the empheral HS - with stem.control.Controller.from_port() as controller: - controller.authenticate() + with stem.control.Controller.from_port(port=config.get('tor.controlPort')) as controller: + controller.authenticate(config.get('tor.controlpassword')) socketHS = controller.create_ephemeral_hidden_service({ourPort: ourInternalPort}, await_publication = True) ourAddress = socketHS.service_id @@ -108,14 +109,14 @@ class OnionrSockets: sel.unregister(conn) conn.close() - def sendData(self, data): + def addSendData(self, data): try: data = data.encode() except AttributeError: pass self.sendData = data - def readData(self): + def getReadData(self): try: data = self.readData.pop(0) except IndexError: