Wait tor connections until tor client startup
This commit is contained in:
parent
d125551c0d
commit
329e885da7
1 changed files with 11 additions and 1 deletions
|
@ -36,6 +36,8 @@ class TorManager(object):
|
||||||
self.start_onions = None
|
self.start_onions = None
|
||||||
self.conn = None
|
self.conn = None
|
||||||
self.lock = RLock()
|
self.lock = RLock()
|
||||||
|
self.starting = True
|
||||||
|
self.event_started = gevent.event.AsyncResult()
|
||||||
|
|
||||||
if config.tor == "disable":
|
if config.tor == "disable":
|
||||||
self.enabled = False
|
self.enabled = False
|
||||||
|
@ -57,6 +59,7 @@ class TorManager(object):
|
||||||
self.proxy_port = int(self.proxy_port)
|
self.proxy_port = int(self.proxy_port)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
self.starting = True
|
||||||
try:
|
try:
|
||||||
if not self.connect():
|
if not self.connect():
|
||||||
raise Exception("No connection")
|
raise Exception("No connection")
|
||||||
|
@ -106,6 +109,8 @@ class TorManager(object):
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
self.log.error(u"Error starting Tor client: %s" % Debug.formatException(str(err).decode("utf8", "ignore")))
|
self.log.error(u"Error starting Tor client: %s" % Debug.formatException(str(err).decode("utf8", "ignore")))
|
||||||
self.enabled = False
|
self.enabled = False
|
||||||
|
self.starting = False
|
||||||
|
self.event_started.set(False)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def isSubprocessRunning(self):
|
def isSubprocessRunning(self):
|
||||||
|
@ -201,6 +206,8 @@ class TorManager(object):
|
||||||
assert float(version.replace(".", "0", 2)) >= 207.5, "Tor version >=0.2.7.5 required, found: %s" % version
|
assert float(version.replace(".", "0", 2)) >= 207.5, "Tor version >=0.2.7.5 required, found: %s" % version
|
||||||
|
|
||||||
self.setStatus(u"Connected (%s)" % res_auth)
|
self.setStatus(u"Connected (%s)" % res_auth)
|
||||||
|
self.event_started.set(True)
|
||||||
|
self.connecting = False
|
||||||
self.conn = conn
|
self.conn = conn
|
||||||
except Exception, err:
|
except Exception, err:
|
||||||
self.conn = None
|
self.conn = None
|
||||||
|
@ -319,6 +326,9 @@ class TorManager(object):
|
||||||
if not self.enabled:
|
if not self.enabled:
|
||||||
return False
|
return False
|
||||||
self.log.debug("Creating new Tor socket to %s:%s" % (onion, port))
|
self.log.debug("Creating new Tor socket to %s:%s" % (onion, port))
|
||||||
|
if self.starting:
|
||||||
|
self.log.debug("Waiting for startup...")
|
||||||
|
self.event_started.get()
|
||||||
if config.tor == "always": # Every socket is proxied by default, in this mode
|
if config.tor == "always": # Every socket is proxied by default, in this mode
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue