try connecting to Tor SOCKS5 server on ports 9050 and 9150, instead of just 9150 (#136)

This commit is contained in:
Micah Lee 2014-09-03 14:23:03 -07:00
parent a314ca891d
commit bfcd5190bd
2 changed files with 20 additions and 9 deletions

View File

@ -91,15 +91,16 @@ class OnionShare(object):
self.cleanup_filenames.append(hidserv_dir)
# connect to the tor controlport
controlports = [9051, 9151]
controller = False
for controlport in controlports:
tor_control_ports = [9051, 9151]
for tor_control_port in tor_control_ports:
try:
controller = Controller.from_port(port=controlport)
controller = Controller.from_port(port=tor_control_port)
break
except SocketError:
pass
if not controller:
raise NoTor(strings._("cant_connect_ctrlport").format(controlports))
raise NoTor(strings._("cant_connect_ctrlport").format(tor_control_ports))
controller.authenticate()
# set up hidden service
@ -129,11 +130,20 @@ class OnionShare(object):
# so no need to set the socks5 proxy
urllib2.urlopen('http://{0}'.format(self.onion_host))
else:
s = socks.socksocket()
s.setproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', 9150)
s.connect((self.onion_host, 80))
#s.sendall('GET / HTTP/1.1\r\n\r\n')
s.close()
tor_exists = False
tor_socks_ports = [9050, 9150]
for tor_socks_port in tor_socks_ports:
try:
s = socks.socksocket()
s.setproxy(socks.PROXY_TYPE_SOCKS5, '127.0.0.1', tor_socks_port)
s.connect((self.onion_host, 80))
s.close()
tor_exists = True
break
except socks.ProxyConnectionError:
pass
if not tor_exists:
raise NoTor(strings._("cant_connect_socksport").format(tor_socks_ports))
ready = True
sys.stdout.write('{0}\n'.format(strings._('wait_for_hs_yup')))

View File

@ -2,6 +2,7 @@
"calculating_sha1": "Calculating SHA1 checksum.",
"connecting_ctrlport": "Connecting to Tor control port to set up hidden service on port {0}.",
"cant_connect_ctrlport": "Cannot connect to Tor control port on port {0}. Is Tor running?",
"cant_connect_socksport": "Cannot connect to Tor SOCKS5 server on port {0}. Is Tor running?",
"preparing_files": "Preparing files to share.",
"wait_for_hs": "Waiting for HS to be ready:",
"wait_for_hs_trying": "Trying...",