def downloadTorExits(proxyList, ipaddress, port=443, protocol=None): """Run a script which downloads a list of Tor exit relays which allow their clients to exit to the given **ipaddress** and **port**. :param proxyList: The :class:`ProxySet` instance from :mod:`bridgedb.Main`. :param str ipaddress: The IP address that each Tor exit relay should be capable of connecting to for clients, as specified by its ExitPolicy. :param int port: The port corresponding to the above **ipaddress** that each Tor exit relay should allow clients to exit to. (See https://check.torproject.org/cgi-bin/TorBulkExitList.py.) :type protocol: :api:`twisted.internet.protocol.Protocol` :param protocol: A :class:`~bridgedb.proxy.ExitListProtocol`, or any other :api:`~twisted.internet.protocol.Protocol` implementation for processing the results of a process which downloads a list of Tor exit relays. This parameter is mainly meant for use in testing, and should not be changed. :rtype: :class:`~twisted.internet.defer.Deferred` :returns: A deferred which will callback with a list, each item in the list is a string containing an IP of a Tor exit relay. """ proto = ExitListProtocol() if protocol is None else protocol() args = [proto.script, '--stdout', '-a', ipaddress, '-p', str(port)] proto.deferred.addCallback(proxyList.addExitRelays) proto.deferred.addErrback(logging.exception) transport = reactor.spawnProcess(proto, proto.script, args=args, env={}) return proto.deferred
def _callProtocolWithDeferred(protocol, executable, args, env, path, reactor=None): if reactor is None: from twisted.internet import reactor d = defer.Deferred() p = protocol(d) reactor.spawnProcess(p, executable, (executable,)+tuple(args), env, path) return d
def buildProtocol(self, addr): # create the protocol instance protocol = self.protocol or EventSocket p = protocol() p.factory = self p.password = self.password if self.__notifyTarget: self.__notifyTarget.inboundConnected(p) # tell the reconnecting factory code that we've connected properly self.resetDelay() return p
def _callProtocolWithDeferred(protocol, executable, args, env, path, reactor): d = defer.Deferred() p = protocol(d) reactor.spawnProcess(p, executable, (executable,) + tuple(args), env, path) return d