• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python txtorcon.launch_tor函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中txtorcon.launch_tor函数的典型用法代码示例。如果您正苦于以下问题:Python launch_tor函数的具体用法?Python launch_tor怎么用?Python launch_tor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了launch_tor函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: startTor

def startTor():
    def updates(prog, tag, summary):
        print("%d%%: %s" % (prog, summary))

    tempfile.tempdir = os.path.join(_repo_dir, 'tmp')
    if not os.path.isdir(tempfile.gettempdir()):
        os.makedirs(tempfile.gettempdir())
    _temp_dir = tempfile.mkdtemp()

    torconfig = TorConfig()
    torconfig.SocksPort = config.main.socks_port
    if config.main.tor2webmode:
        torconfig.Tor2webMode = 1
        torconfig.CircuitBuildTimeout = 60
    if config.main.tor_datadir is None:
        log.warn("Option 'tor_datadir' in oonib.conf is unspecified!")
        log.msg("Creating tmp directory in current directory for datadir.")
        log.debug("Using %s" % _temp_dir)
        datadir = _temp_dir
    else:
        datadir = config.main.tor_datadir
    torconfig.DataDirectory = datadir
    torconfig.save()
    if config.main.tor_binary is not None:
        d = launch_tor(torconfig, reactor,
                       tor_binary=config.main.tor_binary,
                       progress_updates=updates)
    else:
        d = launch_tor(torconfig, reactor, progress_updates=updates)
    d.addCallback(setupCollector, datadir)
    if ooniBouncer:
        d.addCallback(setupBouncer, datadir)
    d.addErrback(txSetupFailed)
开发者ID:waaaaargh,项目名称:ooni-backend,代码行数:33,代码来源:runner.py


示例2: _create_my_own_tor

    def _create_my_own_tor(self):
        _start_launch = self._timing.add_event("launch tor")
        start = time.time()
        config = self.config = txtorcon.TorConfig()
        if 0:
            # The default is for launch_tor to create a tempdir itself, and
            # delete it when done. We only need to set a DataDirectory if we
            # want it to be persistent.
            import tempfile
            datadir = tempfile.mkdtemp()
            config.DataDirectory = datadir

        #config.ControlPort = allocate_tcp_port() # defaults to 9052
        #print("setting config.ControlPort to", config.ControlPort)
        config.SocksPort = allocate_tcp_port()
        self._tor_socks_port = config.SocksPort
        print("setting config.SocksPort to", config.SocksPort)

        tpp = yield txtorcon.launch_tor(config, self._reactor,
                                        #tor_binary=
                                        )
        # gives a TorProcessProtocol with .tor_protocol
        self._tor_protocol = tpp.tor_protocol
        print("tp:", self._tor_protocol)
        print("elapsed:", time.time() - start)
        self._timing.finish_event(_start_launch)
        returnValue(True)
开发者ID:asymmetric,项目名称:magic-wormhole,代码行数:27,代码来源:tor_manager.py


示例3: main

def main(reactor, tor_binary):
    config = txtorcon.TorConfig()
    config.ORPort = 0
    config.SOCKSPort = 0
    config.Tor2WebMode = 1
    # leaving ControlPort unset; launch_tor will choose one

    print "Launching tor...", tor_binary
    try:
        yield txtorcon.launch_tor(
            config,
            reactor,
            tor_binary=tor_binary,
            stdout=sys.stdout
        )
        print "success! We support Tor2Web mode"

    except RuntimeError as e:
        print "There was a problem:", str(e)
        print "We do NOT support Tor2Web mode"
        return

    print "quitting in 5 seconds"
    reactor.callLater(5, lambda: reactor.stop())
    yield Deferred()  # wait forever because we never .callback()
开发者ID:coffeemakr,项目名称:txtorcon,代码行数:25,代码来源:launch_tor2web.py


示例4: main

def main(reactor):
    config = txtorcon.TorConfig()
    config.OrPort = 1234
    config.SocksPort = 9999
    try:
        yield txtorcon.launch_tor(config, reactor, stdout=stdout)

    except RuntimeError as e:
        print "Error:", e
        return

    proto = config.protocol
    print "Connected to Tor version", proto.version

    state = yield txtorcon.TorState.from_protocol(proto)
    print "This Tor has PID", state.tor_pid
    print "This Tor has the following %d Circuits:" % len(state.circuits)
    for c in state.circuits.values():
        print c

    print "Changing our config (SOCKSPort=9876)"
    config.SOCKSPort = 9876
    yield config.save()

    print "Querying to see it changed:"
    socksport = yield proto.get_conf("SOCKSPort")
    print "SOCKSPort", socksport
开发者ID:coffeemakr,项目名称:txtorcon,代码行数:27,代码来源:launch_tor.py


示例5: _launch_tor

 def _launch_tor(self):
     return launch_tor(self.tor_config, reactor,
                       tor_binary=config.advanced.tor_binary,
                       progress_updates=self._progress_updates,
                       stdout=self.tor_output,
                       timeout=self.timeout,
                       stderr=self.tor_output)
开发者ID:vmon,项目名称:ooni-probe,代码行数:7,代码来源:onion.py


示例6: test_tor_connection_fails

    def test_tor_connection_fails(self):
        """
        We fail to connect once, and then successfully connect --
        testing whether we're retrying properly on each Bootstrapped
        line from stdout.
        """

        config = TorConfig()
        config.OrPort = 1234
        config.SocksPort = 9999

        class Connector:
            count = 0

            def __call__(self, proto, trans):
                self.count += 1
                if self.count < 2:
                    return defer.fail(error.CannotListenError(None, None, None))

                proto._set_valid_events('STATUS_CLIENT')
                proto.makeConnection(trans)
                proto.post_bootstrap.callback(proto)
                return proto.post_bootstrap

        def on_protocol(proto):
            proto.outReceived('Bootstrapped 90%\n')
            proto.outReceived('Bootstrapped 100%\n')

        trans = FakeProcessTransport()
        trans.protocol = self.protocol
        self.othertrans = trans
        creator = functools.partial(Connector(), self.protocol, self.transport)
        d = launch_tor(config, FakeReactor(self, trans, on_protocol), connection_creator=creator, tor_binary='/bin/echo')
        d.addCallback(self.setup_complete_fails)
        return self.assertFailure(d, Exception)
开发者ID:biddyweb,项目名称:txtorcon,代码行数:35,代码来源:test_torconfig.py


示例7: _connect

    def _connect(self, reactor, update_status):
        # create a new Tor
        config = self.config = txtorcon.TorConfig()
        if self._data_directory:
            # The default is for launch_tor to create a tempdir itself, and
            # delete it when done. We only need to set a DataDirectory if we
            # want it to be persistent. This saves some startup time, because
            # we cache the descriptors from last time. On one of my hosts,
            # this reduces connect from 20s to 15s.
            if not os.path.exists(self._data_directory):
                # tor will mkdir this, but txtorcon wants to chdir to it
                # before spawning the tor process, so (for now) we need to
                # mkdir it ourselves. TODO: txtorcon should take
                # responsibility for this.
                os.mkdir(self._data_directory)
            config.DataDirectory = self._data_directory

        #config.ControlPort = allocate_tcp_port() # defaults to 9052
        config.SocksPort = allocate_tcp_port()
        socks_desc = "tcp:127.0.0.1:%d" % config.SocksPort
        self._socks_desc = socks_desc # stash for tests
        socks_endpoint = clientFromString(reactor, socks_desc)

        with add_context(update_status, "launching Tor"):
            tpp = yield txtorcon.launch_tor(config, reactor,
                                            tor_binary=self._tor_binary)
        #print "launched"
        # gives a TorProcessProtocol with .tor_protocol
        self._tor_protocol = tpp.tor_protocol
        returnValue(socks_endpoint)
开发者ID:warner,项目名称:foolscap,代码行数:30,代码来源:tor.py


示例8: test_basic_launch

    def test_basic_launch(self):
        config = TorConfig()
        config.OrPort = 1234
        config.SocksPort = 9999

        def connector(proto, trans):
            proto._set_valid_events('STATUS_CLIENT')
            proto.makeConnection(trans)
            proto.post_bootstrap.callback(proto)
            return proto.post_bootstrap

        class OnProgress:
            def __init__(self, test, expected):
                self.test = test
                self.expected = expected

            def __call__(self, percent, tag, summary):
                self.test.assertEqual(self.expected[0], (percent, tag, summary))
                self.expected = self.expected[1:]
                self.test.assertTrue('"' not in summary)
                self.test.assertTrue(percent >= 0 and percent <= 100)            
            
        def on_protocol(proto):
            proto.outReceived('Bootstrapped 100%\n')
            proto.progress = OnProgress(self, [(90, 'circuit_create', 'Establishing a Tor circuit'),
                                               (100, 'done', 'Done')])

        trans = FakeProcessTransport()
        trans.protocol = self.protocol
        self.othertrans = trans
        creator = functools.partial(connector, self.protocol, self.transport)
        d = launch_tor(config, FakeReactor(self, trans, on_protocol), connection_creator=creator)
        d.addCallback(self.setup_complete_no_errors, config)
        return d
开发者ID:aagbsn,项目名称:txtorcon,代码行数:34,代码来源:test_torconfig.py


示例9: test_no_tor_binary

    def test_no_tor_binary(self):
        """FIXME: do I really need all this crap in here?"""
        from txtorcon import torconfig
        oldone = torconfig.find_tor_binary
        self.transport = proto_helpers.StringTransport()
        config = TorConfig()
        d = None

        class Connector:
            def __call__(self, proto, trans):
                proto._set_valid_events('STATUS_CLIENT')
                proto.makeConnection(trans)
                proto.post_bootstrap.callback(proto)
                return proto.post_bootstrap

        try:
            self.protocol = FakeControlProtocol([])
            torconfig.find_tor_binary = lambda: None
            trans = FakeProcessTransport()
            trans.protocol = self.protocol
            self.othertrans = trans
            creator = functools.partial(Connector(), self.protocol, self.transport)
            try:
                d = launch_tor(config, FakeReactor(self, trans, lambda x: None), connection_creator=creator)
                self.fail()

            except TorNotFound:
                pass  # success!
        finally:
            torconfig.find_tor_binary = oldone

        return d
开发者ID:biddyweb,项目名称:txtorcon,代码行数:32,代码来源:test_torconfig.py


示例10: test_tor_connection_user_control_port

    def test_tor_connection_user_control_port(self):
        """
        Confirm we use a user-supplied control-port properly
        """

        config = TorConfig()
        config.OrPort = 1234
        config.ControlPort = 4321

        class Connector:
            def __call__(self, proto, trans):
                proto._set_valid_events('STATUS_CLIENT')
                proto.makeConnection(trans)
                proto.post_bootstrap.callback(proto)
                return proto.post_bootstrap

        def on_protocol(proto):
            proto.outReceived('Bootstrapped 90%\n')
            proto.outReceived('Bootstrapped 100%\n')

        trans = FakeProcessTransport()
        trans.protocol = self.protocol
        self.othertrans = trans
        creator = functools.partial(Connector(), self.protocol, self.transport)
        d = launch_tor(config, FakeReactor(self, trans, on_protocol), connection_creator=creator)

        def check_control_port(proto, tester):
            ## we just want to ensure launch_tor() didn't mess with
            ## the controlport we set
            tester.assertEquals(config.ControlPort, 4321)

        d.addCallback(check_control_port, self)
        d.addErrback(self.fail)
        return d
开发者ID:aagbsn,项目名称:txtorcon,代码行数:34,代码来源:test_torconfig.py


示例11: test_tor_connection_user_data_dir

    def test_tor_connection_user_data_dir(self):
        """
        Test that we don't delete a user-supplied data directory.
        """

        config = TorConfig()
        config.OrPort = 1234

        class Connector:
            def __call__(self, proto, trans):
                proto._set_valid_events('STATUS_CLIENT')
                proto.makeConnection(trans)
                proto.post_bootstrap.callback(proto)
                return proto.post_bootstrap

        def on_protocol(proto):
            proto.outReceived('Bootstrapped 90%\n')
            proto.outReceived('Bootstrapped 100%\n')

        my_dir = tempfile.mkdtemp(prefix='tortmp')
        config.DataDirectory = my_dir
        trans = FakeProcessTransport()
        trans.protocol = self.protocol
        self.othertrans = trans
        creator = functools.partial(Connector(), self.protocol, self.transport)
        d = launch_tor(config, FakeReactor(self, trans, on_protocol), connection_creator=creator)
        def still_have_data_dir(proto, tester):
            proto.cleanup()             # FIXME? not really unit-testy as this is sort of internal function
            tester.assertTrue(os.path.exists(my_dir))
            delete_file_or_tree(my_dir)
        d.addCallback(still_have_data_dir, self)
        d.addErrback(self.fail)
        return d
开发者ID:aagbsn,项目名称:txtorcon,代码行数:33,代码来源:test_torconfig.py


示例12: test_tor_produces_stderr_output

    def test_tor_produces_stderr_output(self):
        config = TorConfig()
        config.OrPort = 1234
        config.SocksPort = 9999

        def connector(proto, trans):
            proto._set_valid_events('STATUS_CLIENT')
            proto.makeConnection(trans)
            proto.post_bootstrap.callback(proto)
            return proto.post_bootstrap

        def on_protocol(proto):
            proto.errReceived('Something went horribly wrong!\n')

        trans = FakeProcessTransport()
        trans.protocol = self.protocol
        self.othertrans = trans
        fakeout = StringIO()
        fakeerr = StringIO()
        creator = functools.partial(connector, self.protocol, self.transport)
        d = launch_tor(config, FakeReactor(self, trans, on_protocol),
                       connection_creator=creator, tor_binary='/bin/echo',
                       stdout=fakeout, stderr=fakeerr)
        d.addCallback(self.fail)        # should't get callback
        d.addErrback(self.setup_fails_stderr, fakeout, fakeerr)
        self.assertFalse(self.protocol.on_disconnect)
        return d
开发者ID:arlolra,项目名称:txtorcon,代码行数:27,代码来源:test_torconfig.py


示例13: test_tor_connection_default_control_port

    def test_tor_connection_default_control_port(self):
        """
        Confirm a default control-port is set if not user-supplied.
        """

        config = TorConfig()

        class Connector:
            def __call__(self, proto, trans):
                proto._set_valid_events('STATUS_CLIENT')
                proto.makeConnection(trans)
                proto.post_bootstrap.callback(proto)
                return proto.post_bootstrap

        def on_protocol(proto):
            proto.outReceived('Bootstrapped 90%\n')
            proto.outReceived('Bootstrapped 100%\n')

        trans = FakeProcessTransport()
        trans.protocol = self.protocol
        self.othertrans = trans
        creator = functools.partial(Connector(), self.protocol, self.transport)
        d = launch_tor(config, FakeReactor(self, trans, on_protocol), connection_creator=creator)

        def check_control_port(proto, tester):
            ## ensure ControlPort was set to a default value
            tester.assertEquals(config.ControlPort, 9052)

        d.addCallback(check_control_port, self)
        d.addErrback(self.fail)
        return d
开发者ID:aagbsn,项目名称:txtorcon,代码行数:31,代码来源:test_torconfig.py


示例14: main

def main(reactor):
    config = txtorcon.TorConfig()
    config.ORPort = 0
    config.SocksPort = 9998
    try:
        os.mkdir('tor-data')
    except OSError:
        pass
    config.DataDirectory = './tor-data'

    try:
        process = yield txtorcon.launch_tor(
            config, reactor, progress_updates=progress
        )
    except Exception as e:
        print("Error launching tor:", e)
        return

    protocol = process.tor_protocol
    print("Tor has launched.")
    print("Protocol:", protocol)
    info = yield protocol.get_info('traffic/read', 'traffic/written')
    print(info)

    # explicitly stop tor by either disconnecting our protocol or the
    # Twisted IProcessProtocol (or just exit our program)
    print("Killing our tor, PID={pid}".format(pid=process.transport.pid))
    yield process.transport.signalProcess('TERM')
开发者ID:coffeemakr,项目名称:txtorcon,代码行数:28,代码来源:1_launch.py


示例15: main

def main(launch_tor=False):
    log.startLogging(sys.stdout)

    control_port = 9051
    if launch_tor:
        control_port = 9151
        config = txtorcon.TorConfig()
        config.ControlPort = control_port
        config.SocksPort = 0
        d = txtorcon.launch_tor(config, reactor, progress_updates=progress)

        ## launch_tor returns a TorProcessProtocol
        ## ...so we grab out the TorControlProtocol instance in order
        ## to simply use the same callback on "d" below
        d.addCallback(lambda pp: pp.tor_protocol)

    else:
        ## if build_state=True, then we get a TorState() object back
        d = txtorcon.build_tor_connection((reactor, '127.0.0.1', control_port),
                                          build_state=False)

    d.addCallback(setup_complete).addErrback(an_error)

    try:
        reactor.run()

    except KeyboardInterrupt:
        pass  # ctrl+c
开发者ID:meejah,项目名称:bulb,代码行数:28,代码来源:server.py


示例16: main

def main(progress_updates=updates, data_directory=None):
    """
    Start logging, apaf services, and tor.

    :param progress_updates: a callback fired during tor's bootstrap.
    :ret: a twisted Deferred object for setting up callbacks in case of
          sucess/errors.
    """
    ## start the logger. ##
    log.startLogging(sys.stdout)
    torconfig = txtorcon.TorConfig()

    ## start apaf. ##
    panel.start_panel(torconfig)
    core.start_services(torconfig)

    torconfig.HiddenServices = [x.hs for x in apaf.hiddenservices]
    torconfig.save()

    ## start tor. ##
    try:
        return txtorcon.launch_tor(torconfig, reactor,
                                   progress_updates=progress_updates,
                                   data_directory=data_directory,
                                   tor_binary=config.tor_binary,
        )
    except OSError as exc:
        print  >> sys.stderr, "Failing to launch tor executable (%s)" % ecx
        sys.exit(1)  # return error status.
开发者ID:djon3s,项目名称:APAF,代码行数:29,代码来源:base.py


示例17: test_full_tor_connection

    def test_full_tor_connection(self):
        def getTransport(address):
            """
            If the address of the bridge starts with a valid c identifier then
            we consider it to be a bridge.
            Returns:
                The transport_name if it's a transport.
                None if it's not a obfsproxy bridge.
            """
            transport_name = address.split(' ')[0]
            transport_name_chars = string.ascii_letters + string.digits
            if all(c in transport_name_chars for c in transport_name):
                return transport_name
            else:
                return None

        config = txtorcon.TorConfig()
        config.ControlPort = random.randint(2**14, 2**16)
        config.SocksPort = random.randint(2**14, 2**16)
        
        transport_name = getTransport(self.bridge)
        if transport_name and self.pyobfsproxy_bin:
            config.ClientTransportPlugin = "%s exec %s managed" % (transport_name, self.pyobfsproxy_bin)
            self.report['transport_name'] = transport_name
            self.report['bridge_address'] = self.bridge.split(' ')[1]
        elif transport_name and not self.pyobfsproxy_bin:
            log.err("Unable to test bridge because pyobfsproxy is not installed")
            self.report['success'] = None
            return
        else:
            self.report['bridge_address'] = self.bridge.split(' ')[0]

        config.Bridge = self.bridge
        config.UseBridges = 1
        config.save()

        def updates(prog, tag, summary):
            log.msg("%s: %s%%" % (self.bridge, prog))
            self.report['tor_progress'] = int(prog)
            self.report['tor_progress_tag'] = tag
            self.report['tor_progress_summary'] = summary

        d = txtorcon.launch_tor(config, reactor, timeout=self.timeout,
                                progress_updates=updates)
        @d.addCallback
        def setup_complete(proto):
            try:
                proto.transport.signalProcess('TERM')
            except error.ProcessExitedAlready:
                proto.transport.loseConnection()
            log.msg("Successfully connected to %s" % self.bridge)
            self.report['success'] = True

        @d.addErrback
        def setup_failed(failure):
            log.msg("Failed to connect to %s" % self.bridge)
            self.report['success'] = False

        return d
开发者ID:jacobhaven,项目名称:ooni-probe,代码行数:59,代码来源:bridge_reachability.py


示例18: _do_launch_tor

 def _do_launch_tor(self):
     tconfig = TorConfig()
     #tconfig.ControlPort = allocate_tcp_port() # defaults to 9052
     tconfig.SocksPort = allocate_tcp_port()
     socks_desc = "tcp:127.0.0.1:%d" % tconfig.SocksPort
     # this could take tor_binary=
     tproto = yield launch_tor(tconfig, self._reactor)
     returnValue((tproto, tconfig, socks_desc))
开发者ID:meejah,项目名称:magic-wormhole,代码行数:8,代码来源:tor_manager.py


示例19: startTor

def startTor():
    def updates(prog, tag, summary):
        print("%d%%: %s" % (prog, summary))

    torconfig = TorConfig()
    torconfig.SocksPort = config.main.socks_port
    if config.main.tor2webmode:
        torconfig.Tor2webMode = 1
        torconfig.CircuitBuildTimeout = 60
    torconfig.save()
    if config.main.tor_binary is not None:
        d = launch_tor(torconfig, reactor,
                       tor_binary=config.main.tor_binary,
                       progress_updates=updates)
    else:
        d = launch_tor(torconfig, reactor, progress_updates=updates)
    d.addCallback(setupCollector)
    d.addErrback(txSetupFailed)
开发者ID:stephen-soltesz,项目名称:ooni-backend,代码行数:18,代码来源:runner.py


示例20: startTor

def startTor(torconfig):
    def updates(prog, tag, summary):
        print("%d%%: %s" % (prog, summary))

    if config.main.socks_port:
        torconfig.SocksPort = config.main.socks_port
    if config.main.control_port:
        torconfig.ControlPort = config.main.control_port
    if config.main.tor2webmode:
        torconfig.Tor2webMode = 1
        torconfig.CircuitBuildTimeout = 60
    if config.main.tor_datadir is None:
        temporary_data_dir = tempfile.mkdtemp()
        log.warn("Option 'tor_datadir' in oonib.conf is unspecified!")
        log.warn("Using %s" % temporary_data_dir)
        torconfig.DataDirectory = temporary_data_dir
    else:
        if os.path.exists(config.main.tor_datadir):
            torconfig.DataDirectory = os.path.abspath(config.main.tor_datadir)
        else:
            raise Exception

    tor_log_file = os.path.join(torconfig.DataDirectory, "tor.log")
    torconfig.Log = ["notice stdout", "notice file %s" % tor_log_file]
    torconfig.save()
    if not hasattr(torconfig, 'ControlPort'):
        control_port = int(randomFreePort())
        torconfig.ControlPort = control_port
        config.main.control_port = control_port

    if not hasattr(torconfig, 'SocksPort'):
        socks_port = int(randomFreePort())
        torconfig.SocksPort = socks_port
        config.main.socks_port = socks_port

    torconfig.save()

    if config.main.tor_binary is not None:
        d = launch_tor(torconfig, reactor,
                       tor_binary=config.main.tor_binary,
                       progress_updates=updates)
    else:
        d = launch_tor(torconfig, reactor, progress_updates=updates)
    return d
开发者ID:NotYours180,项目名称:ooni-backend,代码行数:44,代码来源:onion.py



注:本文中的txtorcon.launch_tor函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python txtorcon.Circuit类代码示例发布时间:2022-05-27
下一篇:
Python txtorcon.build_tor_connection函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap