Пример #1
0
 def _new_conn(self):
     logger.debug('[MyHTTPSConnection] new conn %s:%i', self.host, self.port)
     try:
         self._tor_stream = self._circuit.create_stream((self.host, self.port))
         logger.debug('[MyHTTPSConnection] tor_stream create_socket')
         return self._tor_stream.create_socket()
     except TimeoutError:
         logger.error('TimeoutError')
         raise ConnectTimeoutError(
             self, 'Connection to %s timed out. (connect timeout=%s)' % (self.host, self.timeout)
         )
     except Exception as e:
         logger.error('NewConnectionError')
         raise NewConnectionError(self, 'Failed to establish a new connection: %s' % e)
Пример #2
0
 def connect(self):
     logger.debug('[MyHTTPConnection] connect %s:%i', self.host, self.port)
     try:
         self._tor_stream = self._circuit.create_stream_(
             (self.host, self.port))
         logger.debug('[MyHTTPConnection] tor_stream create_socket')
         self.sock = self._tor_stream.create_socket()
         if self._tunnel_host:
             self._tunnel()
     except TimeoutError as e:
         logger.error("TimeoutError")
         raise ConnectTimeoutError(
             self, "Connection to %s timed out. (connect timeout=%s)" %
             (self.host, self.timeout))
     except Exception as e:
         logger.error("NewConnectionError")
         raise NewConnectionError(
             self, "Failed to establish a new connection: %s" % e)
Пример #3
0
    def _new_conn(self):
        extra_kw = {}
        if self.source_address:
            extra_kw['source_address'] = self.source_address

        if getattr(self, 'socket_options', None):
            extra_kw['socket_options'] = self.socket_options

        dest_host = self.dest_ip if self.dest_ip else self.host

        try:
            conn = connection.create_connection(
                (dest_host, self.port), self.timeout, **extra_kw)

        except SocketTimeout as e:
            raise ConnectTimeoutError(
                self, "Connection to %s timed out. (connect timeout=%s)" %
                (self.host, self.timeout))

        except SocketError as e:
            raise NewConnectionError(
                self, "Failed to establish a new connection: %s" % e)

        return conn