summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMicah Lee <micah@micahflee.com>2019-03-22 18:00:05 -0700
committerGitHub <noreply@github.com>2019-03-22 18:00:05 -0700
commitc1023647d1850c64a20514721d4397ff3c360671 (patch)
tree34fae23b20add4780e71ffeaf6f8c65f21ce4afe
parenta9f3accf69e1560404433137dd2d84433171170d (diff)
parent9a66e331b40311db59f0f4fdc503841233b07d24 (diff)
downloadonionshare-c1023647d1850c64a20514721d4397ff3c360671.tar.gz
onionshare-c1023647d1850c64a20514721d4397ff3c360671.zip
Merge pull request #941 from mig5/configurable_connect_timeout
Allow the bundled Tor connection timeout to be configurable from the CLI
-rw-r--r--onionshare/__init__.py4
-rw-r--r--onionshare/onion.py16
-rw-r--r--share/locale/en.json1
3 files changed, 13 insertions, 8 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..5cb11e27 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
@@ -283,14 +283,16 @@ class Onion(object):
if self.settings.get('tor_bridges_use_custom_bridges') or \
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
+ # Only override timeout if a custom timeout has not been passed in
+ if connect_timeout == 120:
+ connect_timeout = 150
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
diff --git a/share/locale/en.json b/share/locale/en.json
index f7af9a80..9dd0648e 100644
--- a/share/locale/en.json
+++ b/share/locale/en.json
@@ -16,6 +16,7 @@
"help_local_only": "Don't use Tor (only for development)",
"help_stay_open": "Continue sharing after files have been sent",
"help_shutdown_timeout": "Stop sharing after a given amount of seconds",
+ "help_connect_timeout": "Give up connecting to Tor after a given amount of seconds (default: 120)",
"help_stealth": "Use client authorization (advanced)",
"help_receive": "Receive shares instead of sending them",
"help_debug": "Log OnionShare errors to stdout, and web errors to disk",