当前位置: 首页>>代码示例>>Python>>正文


Python txtorcon.launch_tor函数代码示例

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


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


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