Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Map TAG= to bootstrap phase info #16

Merged
merged 3 commits into from Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -1528,6 +1528,21 @@ def __init__(self, main):
self.previous_status = ''
bootstrap_percent = 0
#self.is_running = False
'''The TAG to phase mapping is mainly according to:
https://gitweb.torproject.org/tor-launcher.git/tree/src/chrome/locale/en/torlauncher.properties
'''
self.tag_phase = {'starting': 'Starting',
'conn_dir': 'Connecting to a relay directory',
'handshake_dir': 'Establishing an encrypted directory connection',
'requesting_status': 'Retrieving network status',
'loading_status': 'Loading network status',
'loading_keys': 'Loading authority certificates',
'requesting_descriptors': 'Requesting relay information',
'loading_descriptors': 'Loading relay information',
'conn_or': 'Connecting to the Tor network',
'handshake_or': 'Establishing a Tor circuit',
'done': 'Connected to the Tor network!'}


def connect_to_control_port(self):
import stem
Expand Down Expand Up @@ -1590,11 +1605,26 @@ def connect_to_control_port(self):

def run(self):
self.tor_controller = self.connect_to_control_port()
'''if DisableNetwork is 1, then toggle it to 0
because we really want Tor connect to the network'''
if self.tor_controller.get_conf('DisableNetwork') is '1':
self.tor_controller.set_conf('DisableNetwork', '0')

bootstrap_percent = 0
while bootstrap_percent < 100:
bootstrap_status = self.tor_controller.get_info("status/bootstrap-phase")
bootstrap_phase = re.search(r'SUMMARY=(.*)', bootstrap_status).group(1)

bootstrap_percent = int(re.match('.* PROGRESS=([0-9]+).*', bootstrap_status).group(1))
bootstrap_tag = re.search(r'TAG=(.*) +SUMMARY', bootstrap_status).group(1)
''' Use TAG= keyword for bootstrap_phase, according to:
https://gitweb.torproject.org/tor-launcher.git/plain/README-BOOTSTRAP
'''
if bootstrap_tag in self.tag_phase:
bootstrap_phase = self.tag_phase[bootstrap_tag]
else:
# Only use SUMMARY= as phase info when the TAG= is not in the dictionary
bootstrap_phase = re.search(r'SUMMARY=(.*)', bootstrap_status).group(1)

# bootstrap_status_test = self.tor_controller.get_info("")
# print(bootstrap_status_test)
if bootstrap_status != self.previous_status:
Expand Down
Expand Up @@ -77,6 +77,10 @@ def set_enabled():
if tor_status_code != 0:
return 'cannot_connect', tor_status_code

## we have to reload to open /var/run/tor/control and create /var/run/tor/control.authcookie
command = 'systemctl reload tor@default.service'
tor_status_code = call(command, shell=True)

command = 'systemctl --no-pager status tor@default'
tor_status_code= call(command, shell=True)

Expand Down