mirror of
https://github.com/onionshare/onionshare.git
synced 2025-06-19 12:04:09 -04:00
Show a dialog while waiting for Tor rendezvous nodes to close, and let the user quit early
This commit is contained in:
parent
184f126189
commit
134611a325
4 changed files with 80 additions and 36 deletions
|
@ -729,7 +729,7 @@ class Onion(object):
|
||||||
"Onion", "stop_onion_service", f"failed to remove {onion_host}"
|
"Onion", "stop_onion_service", f"failed to remove {onion_host}"
|
||||||
)
|
)
|
||||||
|
|
||||||
def cleanup(self, stop_tor=True):
|
def cleanup(self, stop_tor=True, wait=True):
|
||||||
"""
|
"""
|
||||||
Stop onion services that were created earlier. If there's a tor subprocess running, kill it.
|
Stop onion services that were created earlier. If there's a tor subprocess running, kill it.
|
||||||
"""
|
"""
|
||||||
|
@ -756,42 +756,45 @@ class Onion(object):
|
||||||
if stop_tor:
|
if stop_tor:
|
||||||
# Stop tor process
|
# Stop tor process
|
||||||
if self.tor_proc:
|
if self.tor_proc:
|
||||||
# Wait for Tor rendezvous circuits to close
|
if wait:
|
||||||
# Catch exceptions to prevent crash on Ctrl-C
|
# Wait for Tor rendezvous circuits to close
|
||||||
try:
|
# Catch exceptions to prevent crash on Ctrl-C
|
||||||
rendevouz_circuit_ids = []
|
try:
|
||||||
for c in self.c.get_circuits():
|
rendevouz_circuit_ids = []
|
||||||
if (
|
|
||||||
c.purpose == "HS_SERVICE_REND"
|
|
||||||
and c.rend_query in self.graceful_close_onions
|
|
||||||
):
|
|
||||||
rendevouz_circuit_ids.append(c.id)
|
|
||||||
|
|
||||||
symbols = [c for c in "\\|/-"]
|
|
||||||
symbols_i = 0
|
|
||||||
|
|
||||||
while True:
|
|
||||||
num_rend_circuits = 0
|
|
||||||
for c in self.c.get_circuits():
|
for c in self.c.get_circuits():
|
||||||
if c.id in rendevouz_circuit_ids:
|
if (
|
||||||
num_rend_circuits += 1
|
c.purpose == "HS_SERVICE_REND"
|
||||||
|
and c.rend_query in self.graceful_close_onions
|
||||||
|
):
|
||||||
|
rendevouz_circuit_ids.append(c.id)
|
||||||
|
|
||||||
if num_rend_circuits == 0:
|
symbols = [c for c in "\\|/-"]
|
||||||
print("\rTor rendezvous circuits have closed" + " " * 20)
|
symbols_i = 0
|
||||||
break
|
|
||||||
|
|
||||||
if num_rend_circuits == 1:
|
while True:
|
||||||
circuits = "circuit"
|
num_rend_circuits = 0
|
||||||
else:
|
for c in self.c.get_circuits():
|
||||||
circuits = "circuits"
|
if c.id in rendevouz_circuit_ids:
|
||||||
print(
|
num_rend_circuits += 1
|
||||||
f"\rWaiting for {num_rend_circuits} Tor rendezvous {circuits} to close {symbols[symbols_i]} ",
|
|
||||||
end="",
|
if num_rend_circuits == 0:
|
||||||
)
|
print(
|
||||||
symbols_i = (symbols_i + 1) % len(symbols)
|
"\rTor rendezvous circuits have closed" + " " * 20
|
||||||
time.sleep(1)
|
)
|
||||||
except:
|
break
|
||||||
pass
|
|
||||||
|
if num_rend_circuits == 1:
|
||||||
|
circuits = "circuit"
|
||||||
|
else:
|
||||||
|
circuits = "circuits"
|
||||||
|
print(
|
||||||
|
f"\rWaiting for {num_rend_circuits} Tor rendezvous {circuits} to close {symbols[symbols_i]} ",
|
||||||
|
end="",
|
||||||
|
)
|
||||||
|
symbols_i = (symbols_i + 1) % len(symbols)
|
||||||
|
time.sleep(1)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
self.tor_proc.terminate()
|
self.tor_proc.terminate()
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
|
@ -30,6 +30,7 @@ from .widgets import Alert
|
||||||
from .update_checker import UpdateThread
|
from .update_checker import UpdateThread
|
||||||
from .tab_widget import TabWidget
|
from .tab_widget import TabWidget
|
||||||
from .gui_common import GuiCommon
|
from .gui_common import GuiCommon
|
||||||
|
from .threads import OnionCleanupThread
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QtWidgets.QMainWindow):
|
class MainWindow(QtWidgets.QMainWindow):
|
||||||
|
@ -287,7 +288,30 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
def cleanup(self):
|
def cleanup(self):
|
||||||
self.common.log("MainWindow", "cleanup")
|
self.common.log("MainWindow", "cleanup")
|
||||||
self.tabs.cleanup()
|
self.tabs.cleanup()
|
||||||
self.common.gui.onion.cleanup()
|
|
||||||
|
alert = Alert(
|
||||||
|
self.common,
|
||||||
|
strings._("gui_rendezvous_cleanup"),
|
||||||
|
QtWidgets.QMessageBox.Information,
|
||||||
|
buttons=QtWidgets.QMessageBox.NoButton,
|
||||||
|
autostart=False,
|
||||||
|
)
|
||||||
|
quit_early_button = QtWidgets.QPushButton(
|
||||||
|
strings._("gui_rendezvous_cleanup_quit_early")
|
||||||
|
)
|
||||||
|
alert.addButton(quit_early_button, QtWidgets.QMessageBox.RejectRole)
|
||||||
|
|
||||||
|
self.onion_cleanup_thread = OnionCleanupThread(self.common)
|
||||||
|
self.onion_cleanup_thread.finished.connect(alert.accept)
|
||||||
|
self.onion_cleanup_thread.start()
|
||||||
|
|
||||||
|
alert.exec_()
|
||||||
|
if alert.clickedButton() == quit_early_button:
|
||||||
|
self.common.log("MainWindow", "cleanup", "quitting early")
|
||||||
|
if self.onion_cleanup_thread.isRunning():
|
||||||
|
self.onion_cleanup_thread.terminate()
|
||||||
|
self.onion_cleanup_thread.wait()
|
||||||
|
self.common.gui.onion.cleanup(wait=False)
|
||||||
|
|
||||||
# Wait 1 second for threads to close gracefully, so tests finally pass
|
# Wait 1 second for threads to close gracefully, so tests finally pass
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
|
@ -187,5 +187,7 @@
|
||||||
"settings_error_unreadable_cookie_file": "Connected to the Tor controller, but password may be wrong, or your user is not permitted to read the cookie file.",
|
"settings_error_unreadable_cookie_file": "Connected to the Tor controller, but password may be wrong, or your user is not permitted to read the cookie file.",
|
||||||
"settings_error_bundled_tor_not_supported": "Using the Tor version that comes with OnionShare does not work in developer mode on Windows or macOS.",
|
"settings_error_bundled_tor_not_supported": "Using the Tor version that comes with OnionShare does not work in developer mode on Windows or macOS.",
|
||||||
"settings_error_bundled_tor_timeout": "Taking too long to connect to Tor. Maybe you aren't connected to the Internet, or have an inaccurate system clock?",
|
"settings_error_bundled_tor_timeout": "Taking too long to connect to Tor. Maybe you aren't connected to the Internet, or have an inaccurate system clock?",
|
||||||
"settings_error_bundled_tor_broken": "OnionShare could not connect to Tor:\n{}"
|
"settings_error_bundled_tor_broken": "OnionShare could not connect to Tor:\n{}",
|
||||||
|
"gui_rendezvous_cleanup": "Waiting for Tor rendezvous circuits to close to be sure that the files you shared downloaded successfully.\n\nThis might take a few minutes.",
|
||||||
|
"gui_rendezvous_cleanup_quit_early": "Quit Early"
|
||||||
}
|
}
|
|
@ -252,3 +252,18 @@ class EventHandlerThread(QtCore.QThread):
|
||||||
if self.should_quit:
|
if self.should_quit:
|
||||||
break
|
break
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
||||||
|
|
||||||
|
class OnionCleanupThread(QtCore.QThread):
|
||||||
|
"""
|
||||||
|
Wait for Tor rendezvous circuits to close in a separate thread
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, common):
|
||||||
|
super(OnionCleanupThread, self).__init__()
|
||||||
|
self.common = common
|
||||||
|
self.common.log("OnionCleanupThread", "__init__")
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.common.log("OnionCleanupThread", "run")
|
||||||
|
self.common.gui.onion.cleanup()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue