work on sockets

master
Kevin Froman 2018-09-20 12:41:34 -05:00
parent 7fa41f31e7
commit d3f4e912f9
5 changed files with 17 additions and 12 deletions

View File

@ -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):

View File

@ -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()

View File

@ -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):

View File

@ -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

View File

@ -18,7 +18,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
'''
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: