def init_socks_port(self, tor_cfg, socks_port): """Check SOCKS port and Tor config inputs.""" if tor_cfg not in [cm.USE_RUNNING_TOR, cm.LAUNCH_NEW_TBB_TOR]: raise TBDriverConfigError("Unrecognized Tor config (tor_cfg)") if socks_port is None: if tor_cfg == cm.USE_RUNNING_TOR: socks_port = cm.DEFAULT_SOCKS_PORT # 9050 else: socks_port = cm.TBB_SOCKS_PORT # 9150 if tor_cfg == cm.LAUNCH_NEW_TBB_TOR: if is_connectable(socks_port): raise TBDriverPortError("SOCKS port %s is already in use" % socks_port) if socks_port != cm.TBB_SOCKS_PORT: # No support for launching TBB's Tor on a custom port, use Stem raise TBDriverPortError("Can only launch Tor on TBB's default" "port (9150). Use Stem for launching" "Tor on a custom SOCKS port") elif tor_cfg == cm.USE_RUNNING_TOR: if not is_connectable(socks_port): raise TBDriverPortError("SOCKS port %s is not listening" % socks_port) self.socks_port = socks_port
def init_ports(self, tor_cfg, socks_port, control_port): """Check SOCKS port and Tor config inputs.""" if tor_cfg == cm.LAUNCH_NEW_TBB_TOR: raise TBDriverConfigError( """`LAUNCH_NEW_TBB_TOR` config is not supported anymore. Use USE_RUNNING_TOR or USE_STEM""") if tor_cfg not in [cm.USE_RUNNING_TOR, cm.USE_STEM]: raise TBDriverConfigError("Unrecognized tor_cfg: %s" % tor_cfg) if socks_port is None: if tor_cfg == cm.USE_RUNNING_TOR: socks_port = cm.DEFAULT_SOCKS_PORT # 9050 else: socks_port = cm.STEM_SOCKS_PORT if control_port is None: if tor_cfg == cm.USE_RUNNING_TOR: control_port = cm.DEFAULT_CONTROL_PORT else: control_port = cm.STEM_CONTROL_PORT if not is_busy(socks_port): raise TBDriverPortError("SOCKS port %s is not listening" % socks_port) self.socks_port = socks_port self.control_port = control_port
def init_ports(self, tor_cfg, socks_port, control_port): """Check SOCKS port and Tor config inputs.""" if tor_cfg not in [cm.USE_RUNNING_TOR, cm.LAUNCH_NEW_TBB_TOR]: raise TBDriverConfigError("Unrecognized tor_cfg: %s" % tor_cfg) if socks_port is None: if tor_cfg == cm.USE_RUNNING_TOR: socks_port = cm.DEFAULT_SOCKS_PORT # 9050 else: socks_port = cm.TBB_SOCKS_PORT # 9150 if control_port is None: if tor_cfg == cm.USE_RUNNING_TOR: control_port = cm.DEFAULT_CONTROL_PORT # 9051 else: control_port = cm.TBB_CONTROL_PORT # 9151 if tor_cfg == cm.LAUNCH_NEW_TBB_TOR: if is_busy(socks_port): raise TBDriverPortError("SOCKS port %s is already in use" % socks_port) if is_busy(control_port): raise TBDriverPortError("Control port %s is already in use" % control_port) if socks_port != cm.TBB_SOCKS_PORT or\ control_port != cm.TBB_CONTROL_PORT: # No support for launching TBB's Tor on a custom port, use Stem raise TBDriverPortError("Can only launch Tor on TBB's default" "ports (9150-9151). Use Stem for" "launching Tor on a custom ports") elif tor_cfg == cm.USE_RUNNING_TOR: if not is_busy(socks_port): raise TBDriverPortError("SOCKS port %s is not listening" % socks_port) self.socks_port = socks_port self.control_port = control_port