improved onionr startup and port binding
parent
2fd387eeb8
commit
1ae2725319
|
@ -492,7 +492,6 @@ class API:
|
||||||
self.http_server.serve_forever()
|
self.http_server.serve_forever()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
#app.run(host=self.host, port=bindPort, debug=False, threaded=True)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(str(e))
|
logger.error(str(e))
|
||||||
logger.fatal('Failed to start client on ' + self.host + ':' + str(bindPort) + ', exiting...')
|
logger.fatal('Failed to start client on ' + self.host + ':' + str(bindPort) + ', exiting...')
|
||||||
|
|
|
@ -97,7 +97,7 @@ DataDirectory data/tordata/
|
||||||
elif 'Opening Socks listener' in line.decode():
|
elif 'Opening Socks listener' in line.decode():
|
||||||
logger.debug(line.decode().replace('\n', ''))
|
logger.debug(line.decode().replace('\n', ''))
|
||||||
else:
|
else:
|
||||||
logger.fatal('Failed to start Tor. Try killing any other Tor processes owned by this user.')
|
logger.fatal('Failed to start Tor. Maybe a stray instance of Tor used by Onionr is still running?')
|
||||||
return False
|
return False
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
logger.fatal("Got keyboard interrupt.")
|
logger.fatal("Got keyboard interrupt.")
|
||||||
|
|
|
@ -138,10 +138,9 @@ class Onionr:
|
||||||
if type(config.get('client.hmac')) is type(None):
|
if type(config.get('client.hmac')) is type(None):
|
||||||
config.set('client.hmac', base64.b16encode(os.urandom(32)).decode('utf-8'), savefile=True)
|
config.set('client.hmac', base64.b16encode(os.urandom(32)).decode('utf-8'), savefile=True)
|
||||||
if type(config.get('client.port')) is type(None):
|
if type(config.get('client.port')) is type(None):
|
||||||
#while True:
|
randomPort = 0
|
||||||
randomPort = random.randint(1024, 65535)
|
while randomPort < 1024:
|
||||||
# if self.onionrUtils.checkPort(randomPort):
|
randomPort = self.onionrCore._crypto.secrets.randbelow(65535)
|
||||||
# break
|
|
||||||
config.set('client.port', randomPort, savefile=True)
|
config.set('client.port', randomPort, savefile=True)
|
||||||
if type(config.get('client.participate')) is type(None):
|
if type(config.get('client.participate')) is type(None):
|
||||||
config.set('client.participate', True, savefile=True)
|
config.set('client.participate', True, savefile=True)
|
||||||
|
@ -544,7 +543,17 @@ class Onionr:
|
||||||
Starts the Onionr communication daemon
|
Starts the Onionr communication daemon
|
||||||
'''
|
'''
|
||||||
communicatorDaemon = './communicator2.py'
|
communicatorDaemon = './communicator2.py'
|
||||||
if not os.environ.get("WERKZEUG_RUN_MAIN") == "true":
|
|
||||||
|
apiThread = Thread(target=api.API, args=(self.debug,))
|
||||||
|
apiThread.start()
|
||||||
|
try:
|
||||||
|
time.sleep(3)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
logger.info('Got keyboard interrupt')
|
||||||
|
time.sleep(1)
|
||||||
|
self.onionrUtils.localCommand('shutdown')
|
||||||
|
else:
|
||||||
|
if apiThread.isAlive():
|
||||||
if self._developmentMode:
|
if self._developmentMode:
|
||||||
logger.warn('DEVELOPMENT MODE ENABLED (THIS IS LESS SECURE!)', timestamp = False)
|
logger.warn('DEVELOPMENT MODE ENABLED (THIS IS LESS SECURE!)', timestamp = False)
|
||||||
net = NetController(config.get('client.port', 59496))
|
net = NetController(config.get('client.port', 59496))
|
||||||
|
@ -558,8 +567,12 @@ class Onionr:
|
||||||
subprocess.Popen([communicatorDaemon, "run", str(net.socksPort)])
|
subprocess.Popen([communicatorDaemon, "run", str(net.socksPort)])
|
||||||
logger.debug('Started communicator')
|
logger.debug('Started communicator')
|
||||||
events.event('daemon_start', onionr = self)
|
events.event('daemon_start', onionr = self)
|
||||||
self.api = api.API(self.debug)
|
try:
|
||||||
|
while True:
|
||||||
|
time.sleep(5)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
self.onionrCore.daemonQueueAdd('shutdown')
|
||||||
|
self.onionrUtils.localCommand('shutdown')
|
||||||
return
|
return
|
||||||
|
|
||||||
def killDaemon(self):
|
def killDaemon(self):
|
||||||
|
|
|
@ -553,6 +553,7 @@ class OnionrUtils:
|
||||||
'''
|
'''
|
||||||
Do a get request through a local tor or i2p instance
|
Do a get request through a local tor or i2p instance
|
||||||
'''
|
'''
|
||||||
|
retData = False
|
||||||
if proxyType == 'tor':
|
if proxyType == 'tor':
|
||||||
if port == 0:
|
if port == 0:
|
||||||
raise onionrexceptions.MissingPort('Socks port required for Tor HTTP get request')
|
raise onionrexceptions.MissingPort('Socks port required for Tor HTTP get request')
|
||||||
|
|
Loading…
Reference in New Issue