work on sockets
parent
7fa41f31e7
commit
d3f4e912f9
|
@ -489,7 +489,7 @@ class OnionrCommunicatorDaemon:
|
||||||
else:
|
else:
|
||||||
del self.sockets[mySocket.socketID] # Delete socket if we have no handler for it
|
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()
|
mySocket.startConn()
|
||||||
|
|
||||||
def uploadBlock(self):
|
def uploadBlock(self):
|
||||||
|
|
|
@ -72,6 +72,8 @@ class NetController:
|
||||||
|
|
||||||
controlPort = random.randint(1025, 65535)
|
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)
|
hashedPassword = subprocess.Popen([self.torBinary, '--hash-password', plaintext], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
for line in iter(hashedPassword.stdout.readline, b''):
|
for line in iter(hashedPassword.stdout.readline, b''):
|
||||||
password = line.decode()
|
password = line.decode()
|
||||||
|
|
|
@ -271,7 +271,8 @@ class Onionr:
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def startChat(self):
|
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)
|
self.onionrCore.daemonQueueAdd('startSocket', socketInfo)
|
||||||
|
|
||||||
def getCommands(self):
|
def getCommands(self):
|
||||||
|
|
|
@ -19,12 +19,13 @@
|
||||||
'''
|
'''
|
||||||
import logger, time
|
import logger, time
|
||||||
class OnionrChat:
|
class OnionrChat:
|
||||||
def __init__(self, communicatorInst, socketInst):
|
def __init__(self, communicatorInst, socketID):
|
||||||
self.communicator = communicatorInst
|
self.communicator = communicatorInst
|
||||||
self.socket = socketInst
|
self.socket = self.communicator.sockets[socketID]
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
logger.info(self.socket.readData())
|
logger.info('Chat: got %s' % (self.socket.getReadData(),))
|
||||||
self.socket.sendData('rekt')
|
time.sleep(1)
|
||||||
|
self.socket.addSendData('rekt')
|
||||||
return
|
return
|
|
@ -18,7 +18,7 @@
|
||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
import stem.control
|
import stem.control
|
||||||
import socket, selectors, socks, config
|
import socket, selectors, socks, config, uuid
|
||||||
import onionrexceptions, time, onionrchat
|
import onionrexceptions, time, onionrchat
|
||||||
from dependencies import secrets
|
from dependencies import secrets
|
||||||
sel = selectors.DefaultSelector()
|
sel = selectors.DefaultSelector()
|
||||||
|
@ -53,8 +53,9 @@ class OnionrSockets:
|
||||||
|
|
||||||
self.readData = []
|
self.readData = []
|
||||||
self.sendData = 0
|
self.sendData = 0
|
||||||
|
config.reload()
|
||||||
|
|
||||||
def startConn():
|
def startConn(self):
|
||||||
if self.isServer:
|
if self.isServer:
|
||||||
self.createServer()
|
self.createServer()
|
||||||
else:
|
else:
|
||||||
|
@ -68,8 +69,8 @@ class OnionrSockets:
|
||||||
ourInternalPort = 1338
|
ourInternalPort = 1338
|
||||||
|
|
||||||
# Setup the empheral HS
|
# Setup the empheral HS
|
||||||
with stem.control.Controller.from_port() as controller:
|
with stem.control.Controller.from_port(port=config.get('tor.controlPort')) as controller:
|
||||||
controller.authenticate()
|
controller.authenticate(config.get('tor.controlpassword'))
|
||||||
socketHS = controller.create_ephemeral_hidden_service({ourPort: ourInternalPort}, await_publication = True)
|
socketHS = controller.create_ephemeral_hidden_service({ourPort: ourInternalPort}, await_publication = True)
|
||||||
ourAddress = socketHS.service_id
|
ourAddress = socketHS.service_id
|
||||||
|
|
||||||
|
@ -108,14 +109,14 @@ class OnionrSockets:
|
||||||
sel.unregister(conn)
|
sel.unregister(conn)
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
def sendData(self, data):
|
def addSendData(self, data):
|
||||||
try:
|
try:
|
||||||
data = data.encode()
|
data = data.encode()
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
self.sendData = data
|
self.sendData = data
|
||||||
|
|
||||||
def readData(self):
|
def getReadData(self):
|
||||||
try:
|
try:
|
||||||
data = self.readData.pop(0)
|
data = self.readData.pop(0)
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
|
Loading…
Reference in New Issue