From 6c02984a9808d8b3801c66f19addcffce02e5a7e Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Mon, 17 Apr 2017 20:49:06 -0700 Subject: [PATCH] Add an Onion exception for canceling connecting Tor --- onionshare/onion.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/onionshare/onion.py b/onionshare/onion.py index d81f23d8..f5f8954c 100644 --- a/onionshare/onion.py +++ b/onionshare/onion.py @@ -19,7 +19,7 @@ along with this program. If not, see . """ from stem.control import Controller -from stem import ProtocolError +from stem import ProtocolError, SocketClosed from stem.connection import MissingPassword, UnreadableCookieFile, AuthenticationFailure import os, sys, tempfile, shutil, urllib, platform, subprocess, time, shlex @@ -99,6 +99,12 @@ class BundledTorTimeout(Exception): but Tor doesn't finish connecting promptly. """ +class BundledTorCanceled(Exception): + """ + This exception is raised if onionshare is set to use the bundled Tor binary, + and the user cancels connecting to Tor + """ + class Onion(object): """ Onion is an abstraction layer for connecting to the Tor control port and @@ -197,7 +203,11 @@ class Onion(object): self.c.authenticate() while True: - res = self.c.get_info("status/bootstrap-phase") + try: + res = self.c.get_info("status/bootstrap-phase") + except SocketClosed: + raise BundledTorCanceled() + res_parts = shlex.split(res) progress = res_parts[2].split('=')[1] summary = res_parts[4].split('=')[1]