improved onionr startup and port binding
parent
2fd387eeb8
commit
1ae2725319
|
@ -492,7 +492,6 @@ class API:
|
|||
self.http_server.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
#app.run(host=self.host, port=bindPort, debug=False, threaded=True)
|
||||
except Exception as e:
|
||||
logger.error(str(e))
|
||||
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():
|
||||
logger.debug(line.decode().replace('\n', ''))
|
||||
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
|
||||
except KeyboardInterrupt:
|
||||
logger.fatal("Got keyboard interrupt.")
|
||||
|
|
|
@ -138,10 +138,9 @@ class Onionr:
|
|||
if type(config.get('client.hmac')) is type(None):
|
||||
config.set('client.hmac', base64.b16encode(os.urandom(32)).decode('utf-8'), savefile=True)
|
||||
if type(config.get('client.port')) is type(None):
|
||||
#while True:
|
||||
randomPort = random.randint(1024, 65535)
|
||||
# if self.onionrUtils.checkPort(randomPort):
|
||||
# break
|
||||
randomPort = 0
|
||||
while randomPort < 1024:
|
||||
randomPort = self.onionrCore._crypto.secrets.randbelow(65535)
|
||||
config.set('client.port', randomPort, savefile=True)
|
||||
if type(config.get('client.participate')) is type(None):
|
||||
config.set('client.participate', True, savefile=True)
|
||||
|
@ -544,7 +543,17 @@ class Onionr:
|
|||
Starts the Onionr communication daemon
|
||||
'''
|
||||
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:
|
||||
logger.warn('DEVELOPMENT MODE ENABLED (THIS IS LESS SECURE!)', timestamp = False)
|
||||
net = NetController(config.get('client.port', 59496))
|
||||
|
@ -558,8 +567,12 @@ class Onionr:
|
|||
subprocess.Popen([communicatorDaemon, "run", str(net.socksPort)])
|
||||
logger.debug('Started communicator')
|
||||
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
|
||||
|
||||
def killDaemon(self):
|
||||
|
|
|
@ -553,6 +553,7 @@ class OnionrUtils:
|
|||
'''
|
||||
Do a get request through a local tor or i2p instance
|
||||
'''
|
||||
retData = False
|
||||
if proxyType == 'tor':
|
||||
if port == 0:
|
||||
raise onionrexceptions.MissingPort('Socks port required for Tor HTTP get request')
|
||||
|
|
Loading…
Reference in New Issue