def connect(self, protocolfactory): last_error = None # XXX fix in socks.py stuff for socks_username, socks_password if self._socks_username or self._socks_password: raise RuntimeError( "txtorcon socks support doesn't yet do username/password" ) if self._socks_endpoint is not None: socks_ep = TorSocksEndpoint( self._socks_endpoint, self.host, self.port, self._tls, ) # forward the address to any listeners we have socks_ep._get_address().addCallback(self._when_address.fire) proto = yield socks_ep.connect(protocolfactory) defer.returnValue(proto) else: for socks_port in self._socks_port_iter: tor_ep = TCP4ClientEndpoint( self._reactor, "127.0.0.1", # XXX socks_hostname, no? socks_port, ) socks_ep = TorSocksEndpoint(tor_ep, self.host, self.port, self._tls) # forward the address to any listeners we have socks_ep._get_address().addCallback(self._when_address.fire) try: proto = yield socks_ep.connect(protocolfactory) defer.returnValue(proto) except error.ConnectError as e0: last_error = e0 if last_error is not None: raise last_error
def endpointForURI(self, uri): return TorSocksEndpoint( self._proxy_ep.when_fired(), uri.host, uri.port, tls=(uri.scheme == b'https'), )
def endpointForURI(self, uri): """IAgentEndpointFactory API""" torsocks = TorSocksEndpoint( self._socks_ep, uri.host, uri.port, tls=uri.scheme == b'https', ) from txtorcon.circuit import TorCircuitEndpoint return TorCircuitEndpoint( self._reactor, self._circ._torstate, self._circ, torsocks, )
def build_irc(self): """The main starting method that creates a protocol object according to the config variables, ready for whenever the reactor starts running. """ wlog('building irc') if self.tx_irc_client: raise Exception('irc already built') if self.usessl.lower() == 'true': ctx = ClientContextFactory() if self.usessl.lower() == 'true' and not self.socks5.lower() == 'true': factory = TxIRCFactory(self) reactor.connectSSL(self.serverport[0], self.serverport[1], factory, ctx) elif self.socks5.lower() == 'true': factory = TxIRCFactory(self) #str() casts needed else unicode error torEndpoint = TCP4ClientEndpoint(reactor, str(self.socks5_host), self.socks5_port) if self.usessl.lower() == 'true': use_tls = ctx else: use_tls = False ircEndpoint = TorSocksEndpoint(torEndpoint, self.serverport[0], self.serverport[1], tls=use_tls) myRS = ClientService(ircEndpoint, factory) myRS.startService() else: try: factory = TxIRCFactory(self) wlog('build_irc: ', self.serverport[0], str(self.serverport[1]), self.channel) self.tcp_connector = reactor.connectTCP( self.serverport[0], self.serverport[1], factory) except Exception as e: wlog('error in buildirc: ' + repr(e))