mirror of
https://github.com/onionshare/onionshare.git
synced 2025-02-05 17:35:35 -05:00
Merge branch 'no_available_port_error' of https://github.com/mig5/onionshare into mig5-no_available_port_error
This commit is contained in:
commit
ed2c55c097
@ -196,8 +196,8 @@ def get_available_port(min_port, max_port):
|
|||||||
try:
|
try:
|
||||||
tmpsock.bind(("127.0.0.1", random.randint(min_port, max_port)))
|
tmpsock.bind(("127.0.0.1", random.randint(min_port, max_port)))
|
||||||
break
|
break
|
||||||
except OSError:
|
except OSError as e:
|
||||||
pass
|
raise OSError(e)
|
||||||
_, port = tmpsock.getsockname()
|
_, port = tmpsock.getsockname()
|
||||||
return port
|
return port
|
||||||
|
|
||||||
|
@ -171,10 +171,16 @@ class Onion(object):
|
|||||||
if self.system == 'Windows':
|
if self.system == 'Windows':
|
||||||
# Windows needs to use network ports, doesn't support unix sockets
|
# Windows needs to use network ports, doesn't support unix sockets
|
||||||
torrc_template = open(common.get_resource_path('torrc_template-windows')).read()
|
torrc_template = open(common.get_resource_path('torrc_template-windows')).read()
|
||||||
|
try:
|
||||||
self.tor_control_port = common.get_available_port(1000, 65535)
|
self.tor_control_port = common.get_available_port(1000, 65535)
|
||||||
|
except:
|
||||||
|
raise OSError(strings._('no_available_port'))
|
||||||
self.tor_control_socket = None
|
self.tor_control_socket = None
|
||||||
self.tor_cookie_auth_file = os.path.join(self.tor_data_directory.name, 'cookie')
|
self.tor_cookie_auth_file = os.path.join(self.tor_data_directory.name, 'cookie')
|
||||||
|
try:
|
||||||
self.tor_socks_port = common.get_available_port(1000, 65535)
|
self.tor_socks_port = common.get_available_port(1000, 65535)
|
||||||
|
except:
|
||||||
|
raise OSError(strings._('no_available_port'))
|
||||||
self.tor_torrc = os.path.join(self.tor_data_directory.name, 'torrc')
|
self.tor_torrc = os.path.join(self.tor_data_directory.name, 'torrc')
|
||||||
else:
|
else:
|
||||||
# Linux and Mac can use unix sockets
|
# Linux and Mac can use unix sockets
|
||||||
@ -183,7 +189,10 @@ class Onion(object):
|
|||||||
self.tor_control_port = None
|
self.tor_control_port = None
|
||||||
self.tor_control_socket = os.path.join(self.tor_data_directory.name, 'control_socket')
|
self.tor_control_socket = os.path.join(self.tor_data_directory.name, 'control_socket')
|
||||||
self.tor_cookie_auth_file = os.path.join(self.tor_data_directory.name, 'cookie')
|
self.tor_cookie_auth_file = os.path.join(self.tor_data_directory.name, 'cookie')
|
||||||
|
try:
|
||||||
self.tor_socks_port = common.get_available_port(1000, 65535)
|
self.tor_socks_port = common.get_available_port(1000, 65535)
|
||||||
|
except:
|
||||||
|
raise OSError(strings._('no_available_port'))
|
||||||
self.tor_torrc = os.path.join(self.tor_data_directory.name, 'torrc')
|
self.tor_torrc = os.path.join(self.tor_data_directory.name, 'torrc')
|
||||||
|
|
||||||
torrc_template = torrc_template.replace('{{data_directory}}', self.tor_data_directory.name)
|
torrc_template = torrc_template.replace('{{data_directory}}', self.tor_data_directory.name)
|
||||||
|
@ -20,7 +20,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
import os, shutil
|
import os, shutil
|
||||||
|
|
||||||
from . import common
|
from . import common, strings
|
||||||
|
|
||||||
class OnionShare(object):
|
class OnionShare(object):
|
||||||
"""
|
"""
|
||||||
@ -64,7 +64,10 @@ class OnionShare(object):
|
|||||||
common.log('OnionShare', 'start_onion_service')
|
common.log('OnionShare', 'start_onion_service')
|
||||||
|
|
||||||
# Choose a random port
|
# Choose a random port
|
||||||
|
try:
|
||||||
self.port = common.get_available_port(17600, 17650)
|
self.port = common.get_available_port(17600, 17650)
|
||||||
|
except:
|
||||||
|
raise OSError(strings._('no_available_port'))
|
||||||
|
|
||||||
if self.local_only:
|
if self.local_only:
|
||||||
self.onion_host = '127.0.0.1:{0:d}'.format(self.port)
|
self.onion_host = '127.0.0.1:{0:d}'.format(self.port)
|
||||||
@ -72,6 +75,7 @@ class OnionShare(object):
|
|||||||
|
|
||||||
if self.shutdown_timeout > 0:
|
if self.shutdown_timeout > 0:
|
||||||
self.shutdown_timer = common.close_after_seconds(self.shutdown_timeout)
|
self.shutdown_timer = common.close_after_seconds(self.shutdown_timeout)
|
||||||
|
|
||||||
self.onion_host = self.onion.start_onion_service(self.port)
|
self.onion_host = self.onion.start_onion_service(self.port)
|
||||||
|
|
||||||
if self.stealth:
|
if self.stealth:
|
||||||
|
@ -250,7 +250,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
self.app.start_onion_service()
|
self.app.start_onion_service()
|
||||||
self.starting_server_step2.emit()
|
self.starting_server_step2.emit()
|
||||||
|
|
||||||
except (TorTooOld, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError, BundledTorTimeout) as e:
|
except (TorTooOld, TorErrorInvalidSetting, TorErrorAutomatic, TorErrorSocketPort, TorErrorSocketFile, TorErrorMissingPassword, TorErrorUnreadableCookieFile, TorErrorAuthError, TorErrorProtocolError, BundledTorTimeout, OSError) as e:
|
||||||
self.starting_server_error.emit(e.args[0])
|
self.starting_server_error.emit(e.args[0])
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -348,7 +348,11 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
common.log('OnionShareGui', 'stop_server')
|
common.log('OnionShareGui', 'stop_server')
|
||||||
|
|
||||||
if self.server_status.status != self.server_status.STATUS_STOPPED:
|
if self.server_status.status != self.server_status.STATUS_STOPPED:
|
||||||
|
try:
|
||||||
web.stop(self.app.port)
|
web.stop(self.app.port)
|
||||||
|
except:
|
||||||
|
# Probably we had no port to begin with (Onion service didn't start)
|
||||||
|
pass
|
||||||
self.app.cleanup()
|
self.app.cleanup()
|
||||||
self.filesize_warning.hide()
|
self.filesize_warning.hide()
|
||||||
self.stop_server_finished.emit()
|
self.stop_server_finished.emit()
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
"ctrlc_to_stop": "Press Ctrl-C to stop server",
|
"ctrlc_to_stop": "Press Ctrl-C to stop server",
|
||||||
"not_a_file": "{0:s} is not a file.",
|
"not_a_file": "{0:s} is not a file.",
|
||||||
"not_a_readable_file": "{0:s} is not a readable file.",
|
"not_a_readable_file": "{0:s} is not a readable file.",
|
||||||
|
"no_available_port": "Could not start the Onion service as there was no available port.",
|
||||||
"download_page_loaded": "Download page loaded",
|
"download_page_loaded": "Download page loaded",
|
||||||
"other_page_loaded": "URL loaded",
|
"other_page_loaded": "URL loaded",
|
||||||
"close_on_timeout": "Closing automatically because timeout was reached",
|
"close_on_timeout": "Closing automatically because timeout was reached",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user