def launch_tor_service(self, logfile='/dev/null'): """Launch Tor service and return the process.""" self.log_file = logfile self.tmp_tor_data_dir = ut.clone_dir_with_timestap( cm.get_tor_data_path(self.tbb_version)) self.torrc_dict.update({ 'DataDirectory': self.tmp_tor_data_dir, 'Log': ['INFO file %s' % logfile] }) wl_log.debug("Tor config: %s" % self.torrc_dict) try: self.tor_process = stem.process.launch_tor_with_config( config=self.torrc_dict, init_msg_handler=self.tor_log_handler, tor_cmd=cm.get_tor_bin_path(self.tbb_version), timeout=270) self.controller = Controller.from_port() self.controller.authenticate() return self.tor_process except stem.SocketError as exc: wl_log.critical("Unable to connect to tor on port %s: %s" % (cm.SOCKS_PORT, exc)) sys.exit(1) except: # most of the time this is due to another instance of # tor running on the system wl_log.critical("Error launching Tor", exc_info=True) sys.exit(1) wl_log.info("Tor running at port {0} & controller port {1}.".format( cm.SOCKS_PORT, cm.CONTROLLER_PORT)) return self.tor_process
def test_get_tor_bin_path(self): ver_str = "2.3.25-16" tor_bin_path_v2_3_25_16 = cm.get_tor_bin_path(ver_str) self.assert_(cm.TBB_BASE_DIR in tor_bin_path_v2_3_25_16) self.assert_(cm.TOR_V2_BINARY_PATH in tor_bin_path_v2_3_25_16) self.assert_(cm.get_tbb_dirname(ver_str) in tor_bin_path_v2_3_25_16) tor_bin_path_v3_5 = cm.get_tor_bin_path(cm.TBB_V_3_5) self.assert_(cm.TBB_BASE_DIR in tor_bin_path_v3_5) self.assert_(cm.TOR_V3_BINARY_PATH in tor_bin_path_v3_5) self.assert_(cm.get_tbb_dirname(cm.TBB_V_3_5) in tor_bin_path_v3_5) tor_bin_path_v4_0_8 = cm.get_tor_bin_path(cm.TBB_V_4_0_8) self.assert_(cm.TBB_BASE_DIR in tor_bin_path_v4_0_8) self.assert_(cm.TOR_V4_BINARY_PATH in tor_bin_path_v4_0_8) self.assert_(cm.get_tbb_dirname(cm.TBB_V_4_0_8) in tor_bin_path_v4_0_8)
def __init__(self, torrc_dict, tbb_version, tor_log='/dev/null'): self.torrc_dict = torrc_dict self.controller = None self.tbb_version = tbb_version self.tmp_tor_data_dir = None self.tor_process = None self.log_file = tor_log if tbb_version: tbb_path = cm.get_tbb_path(self.tbb_version) print(tbb_path) tor_binary_path = cm.get_tor_bin_path(self.tbb_version) tor_profile_path = cm.get_tbb_profile_path(self.tbb_version) tor_data_path = cm.get_tor_data_path(self.tbb_version) self.tor_binary_path = tor_binary_path self.tor_data_path = tor_data_path self.tor_profile_path = tor_profile_path self.control_port = int(self.torrc_dict['controlport']) self.socks_port = int(self.torrc_dict['socksport']) self.export_lib_path()
def export_lib_path(self): os.environ["LD_LIBRARY_PATH"] = os.path.dirname( cm.get_tor_bin_path(self.tbb_version))