From 786959eed3f590387e012c4477b804100e2f4ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Espen=20K=C3=A5sa=20Notodden?= Date: Sat, 24 May 2014 10:45:16 +0200 Subject: [PATCH 1/2] remove bogus return.. --- onionshare.py | 1 - 1 file changed, 1 deletion(-) diff --git a/onionshare.py b/onionshare.py index 6d413fc1..9ed05e37 100755 --- a/onionshare.py +++ b/onionshare.py @@ -73,7 +73,6 @@ def load_strings(default="en"): translated = json.loads(open('{0}/strings.json'.format( os.path.dirname(__file__))).read()) strings = translated[default] - return lc, enc = locale.getdefaultlocale() if lc: lang = lc[:2] From c22937bdca04be09c7aeef5483ac8a00cb6f1266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Espen=20K=C3=A5sa=20Notodden?= Date: Sat, 24 May 2014 23:40:08 +0200 Subject: [PATCH 2/2] Let the OS choose a port instead of using a random integer (avoid collisions).. --- onionshare.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/onionshare.py b/onionshare.py index 9ed05e37..291cc108 100755 --- a/onionshare.py +++ b/onionshare.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import os, sys, subprocess, time, hashlib, platform, json, locale +import os, sys, subprocess, time, hashlib, platform, json, locale, socket from random import randint from functools import wraps @@ -100,8 +100,11 @@ if __name__ == '__main__': filehash = hasher.hexdigest() filesize = os.path.getsize(filename) - # choose a port - port = randint(1025, 65535) + # let the OS choose a port + tmpsock = socket.socket() + tmpsock.bind(("127.0.0.1", 0)) + port = tmpsock.getsockname()[1] + tmpsock.close() # connect to the tor controlport print strings["connecting_ctrlport"].format(port)