mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-26 22:37:11 -05:00
#493, #500 - detect if the Tor connection (bundled, TorBrowser or otherwise) has been lost while the app is open. Stop a running share if so
This commit is contained in:
parent
5c390f1bd9
commit
bcd4363769
@ -375,6 +375,12 @@ class Onion(object):
|
|||||||
# ephemeral stealth onion services are not supported
|
# ephemeral stealth onion services are not supported
|
||||||
self.supports_stealth = False
|
self.supports_stealth = False
|
||||||
|
|
||||||
|
def is_authenticated(self):
|
||||||
|
"""
|
||||||
|
Returns True if the Tor connection is still working, or False otherwise.
|
||||||
|
"""
|
||||||
|
return self.c.is_authenticated()
|
||||||
|
|
||||||
def start_onion_service(self, port):
|
def start_onion_service(self, port):
|
||||||
"""
|
"""
|
||||||
Start a onion service on port 80, pointing to the given port, and
|
Start a onion service on port 80, pointing to the given port, and
|
||||||
|
@ -219,6 +219,11 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
def reload_settings():
|
def reload_settings():
|
||||||
common.log('OnionShareGui', 'open_settings', 'settings have changed, reloading')
|
common.log('OnionShareGui', 'open_settings', 'settings have changed, reloading')
|
||||||
self.settings.load()
|
self.settings.load()
|
||||||
|
# We might've stopped the main requests timer if a Tor connection failed.
|
||||||
|
# If we've reloaded settings, we probably succeeded in obtaining a new
|
||||||
|
# connection. If so, restart the timer.
|
||||||
|
if not self.timer.isActive():
|
||||||
|
self.timer.start()
|
||||||
|
|
||||||
d = SettingsDialog(self.onion, self.qtapp, self.config)
|
d = SettingsDialog(self.onion, self.qtapp, self.config)
|
||||||
d.settings_saved.connect(reload_settings)
|
d.settings_saved.connect(reload_settings)
|
||||||
@ -389,6 +394,18 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
"""
|
"""
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
# Have we lost connection to Tor somehow?
|
||||||
|
try:
|
||||||
|
# Tor Browser may not even have been open when we started OnionShare,
|
||||||
|
# in which case onion.is_authenticated() throws a NoneType error
|
||||||
|
self.onion
|
||||||
|
if not self.onion.is_authenticated():
|
||||||
|
self.timer.stop()
|
||||||
|
self.start_server_error(strings._('error_tor_protocol_error'))
|
||||||
|
self._tor_connection_canceled()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# scroll to the bottom of the dl progress bar log pane
|
# scroll to the bottom of the dl progress bar log pane
|
||||||
# if a new download has been added
|
# if a new download has been added
|
||||||
if self.new_download:
|
if self.new_download:
|
||||||
|
@ -459,26 +459,31 @@ class SettingsDialog(QtWidgets.QDialog):
|
|||||||
# If Tor isn't connected, or if Tor settings have changed, Reinitialize
|
# If Tor isn't connected, or if Tor settings have changed, Reinitialize
|
||||||
# the Onion object
|
# the Onion object
|
||||||
reboot_onion = False
|
reboot_onion = False
|
||||||
if self.onion.connected_to_tor:
|
try:
|
||||||
def changed(s1, s2, keys):
|
self.onion
|
||||||
"""
|
if self.onion.is_authenticated():
|
||||||
Compare the Settings objects s1 and s2 and return true if any values
|
def changed(s1, s2, keys):
|
||||||
have changed for the given keys.
|
"""
|
||||||
"""
|
Compare the Settings objects s1 and s2 and return true if any values
|
||||||
for key in keys:
|
have changed for the given keys.
|
||||||
if s1.get(key) != s2.get(key):
|
"""
|
||||||
return True
|
for key in keys:
|
||||||
return False
|
if s1.get(key) != s2.get(key):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
if changed(settings, self.old_settings, [
|
if changed(settings, self.old_settings, [
|
||||||
'connection_type', 'control_port_address',
|
'connection_type', 'control_port_address',
|
||||||
'control_port_port', 'socks_address', 'socks_port',
|
'control_port_port', 'socks_address', 'socks_port',
|
||||||
'socket_file_path', 'auth_type', 'auth_password']):
|
'socket_file_path', 'auth_type', 'auth_password']):
|
||||||
|
|
||||||
|
reboot_onion = True
|
||||||
|
|
||||||
|
else:
|
||||||
|
# Tor isn't connected, so try connecting
|
||||||
reboot_onion = True
|
reboot_onion = True
|
||||||
|
except:
|
||||||
else:
|
# We definitely aren't connected, as the onion object had no attribute is_authenticated()
|
||||||
# Tor isn't connected, so try connecting
|
|
||||||
reboot_onion = True
|
reboot_onion = True
|
||||||
|
|
||||||
# Do we need to reinitialize Tor?
|
# Do we need to reinitialize Tor?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user