summaryrefslogtreecommitdiff
path: root/onionshare
diff options
context:
space:
mode:
authorMiguel Jacq <mig@mig5.net>2019-03-12 15:29:07 +1100
committerMiguel Jacq <mig@mig5.net>2019-03-12 15:29:07 +1100
commit99505a4c7df690ccd0f6262595b4ea4d61125207 (patch)
tree10431369b0cab30b9beb55da38a1e565655ea267 /onionshare
parent3af05dcc2041026380a71b8aed1af9af849416a5 (diff)
downloadonionshare-99505a4c7df690ccd0f6262595b4ea4d61125207.tar.gz
onionshare-99505a4c7df690ccd0f6262595b4ea4d61125207.zip
Allow the bundled Tor connection timeout to be configurable from the CLI
Diffstat (limited to 'onionshare')
-rw-r--r--onionshare/__init__.py4
-rw-r--r--onionshare/onion.py12
2 files changed, 9 insertions, 7 deletions
diff --git a/onionshare/__init__.py b/onionshare/__init__.py
index 2f44c846..cbfe222c 100644
--- a/onionshare/__init__.py
+++ b/onionshare/__init__.py
@@ -54,6 +54,7 @@ def main(cwd=None):
parser.add_argument('--local-only', action='store_true', dest='local_only', help=strings._("help_local_only"))
parser.add_argument('--stay-open', action='store_true', dest='stay_open', help=strings._("help_stay_open"))
parser.add_argument('--shutdown-timeout', metavar='<int>', dest='shutdown_timeout', default=0, help=strings._("help_shutdown_timeout"))
+ parser.add_argument('--connect-timeout', metavar='<int>', dest='connect_timeout', default=120, help=strings._("help_connect_timeout"))
parser.add_argument('--stealth', action='store_true', dest='stealth', help=strings._("help_stealth"))
parser.add_argument('--receive', action='store_true', dest='receive', help=strings._("help_receive"))
parser.add_argument('--config', metavar='config', default=False, help=strings._('help_config'))
@@ -69,6 +70,7 @@ def main(cwd=None):
debug = bool(args.debug)
stay_open = bool(args.stay_open)
shutdown_timeout = int(args.shutdown_timeout)
+ connect_timeout = int(args.connect_timeout)
stealth = bool(args.stealth)
receive = bool(args.receive)
config = args.config
@@ -111,7 +113,7 @@ def main(cwd=None):
# Start the Onion object
onion = Onion(common)
try:
- onion.connect(custom_settings=False, config=config)
+ onion.connect(custom_settings=False, config=config, connect_timeout=connect_timeout)
except KeyboardInterrupt:
print("")
sys.exit()
diff --git a/onionshare/onion.py b/onionshare/onion.py
index ed4fde7b..03d1a1b0 100644
--- a/onionshare/onion.py
+++ b/onionshare/onion.py
@@ -152,7 +152,7 @@ class Onion(object):
# Start out not connected to Tor
self.connected_to_tor = False
- def connect(self, custom_settings=False, config=False, tor_status_update_func=None):
+ def connect(self, custom_settings=False, config=False, tor_status_update_func=None, connect_timeout=120):
self.common.log('Onion', 'connect')
# Either use settings that are passed in, or use them from common
@@ -284,13 +284,13 @@ class Onion(object):
self.settings.get('tor_bridges_use_obfs4') or \
self.settings.get('tor_bridges_use_meek_lite_azure'):
connect_timeout = 150
- else:
- # Timeout after 120 seconds
- connect_timeout = 120
if time.time() - start_ts > connect_timeout:
print("")
- self.tor_proc.terminate()
- raise BundledTorTimeout(strings._('settings_error_bundled_tor_timeout'))
+ try:
+ self.tor_proc.terminate()
+ raise BundledTorTimeout(strings._('settings_error_bundled_tor_timeout'))
+ except FileNotFoundError:
+ pass
elif self.settings.get('connection_type') == 'automatic':
# Automatically try to guess the right way to connect to Tor Browser