Esempio n. 1
0
    def __new__(cls, uri, **config):
        from neobolt.addressing import SocketAddress
        from neobolt.direct import ConnectionPool, DEFAULT_PORT, connect
        from neobolt.security import ENCRYPTION_OFF, ENCRYPTION_ON, SSL_AVAILABLE, SecurityPlan
        cls._check_uri(uri)
        if SocketAddress.parse_routing_context(uri):
            raise ValueError("Parameters are not supported with scheme 'bolt'. Given URI: '%s'." % uri)
        instance = object.__new__(cls)
        # We keep the address containing the host name or IP address exactly
        # as-is from the original URI. This means that every new connection
        # will carry out DNS resolution, leading to the possibility that
        # the connection pool may contain multiple IP address keys, one for
        # an old address and one for a new address.
        instance.address = SocketAddress.from_uri(uri, DEFAULT_PORT)
        if config.get("encrypted") is None:
            config["encrypted"] = ENCRYPTION_ON if SSL_AVAILABLE else ENCRYPTION_OFF
        instance.security_plan = security_plan = SecurityPlan.build(**config)
        instance.encrypted = security_plan.encrypted

        def connector(address, **kwargs):
            return connect(address, **dict(config, **kwargs))

        pool = ConnectionPool(connector, instance.address, **config)
        pool.release(pool.acquire())
        instance._pool = pool
        instance._max_retry_time = config.get("max_retry_time", default_config["max_retry_time"])
        return instance
Esempio n. 2
0
    def __new__(cls, uri, **config):
        from neobolt.addressing import SocketAddress
        from neobolt.direct import DEFAULT_PORT, connect
        from neobolt.routing import RoutingConnectionPool
        from neobolt.security import ENCRYPTION_OFF, ENCRYPTION_ON, SSL_AVAILABLE, SecurityPlan
        cls._check_uri(uri)
        instance = object.__new__(cls)
        instance.initial_address = initial_address = SocketAddress.from_uri(uri, DEFAULT_PORT)
        if config.get("encrypted") is None:
            config["encrypted"] = ENCRYPTION_ON if SSL_AVAILABLE else ENCRYPTION_OFF
        instance.security_plan = security_plan = SecurityPlan.build(**config)
        instance.encrypted = security_plan.encrypted
        routing_context = SocketAddress.parse_routing_context(uri)
        if not security_plan.routing_compatible:
            # this error message is case-specific as there is only one incompatible
            # scenario right now
            raise ValueError("TRUST_ON_FIRST_USE is not compatible with routing")

        def connector(address, **kwargs):
            return connect(address, **dict(config, **kwargs))

        pool = RoutingConnectionPool(connector, initial_address, routing_context, initial_address, **config)
        try:
            pool.update_routing_table()
        except:
            pool.close()
            raise
        else:
            instance._pool = pool
            instance._max_retry_time = config.get("max_retry_time", default_config["max_retry_time"])
            return instance
Esempio n. 3
0
    def __new__(cls, uri, **config):
        from neobolt.addressing import SocketAddress
        from neobolt.direct import DEFAULT_PORT, connect
        from neobolt.routing import RoutingConnectionPool
        from neobolt.security import make_ssl_context
        cls._check_uri(uri)
        instance = object.__new__(cls)
        instance.initial_address = initial_address = SocketAddress.from_uri(
            uri, DEFAULT_PORT)
        if config.get("encrypted") is None:
            config["encrypted"] = False
        instance._ssl_context = make_ssl_context(**config)
        instance.encrypted = instance._ssl_context is not None
        routing_context = SocketAddress.parse_routing_context(uri)

        def connector(address, **kwargs):
            return connect(address, **dict(config, **kwargs))

        pool = RoutingConnectionPool(connector, initial_address,
                                     routing_context, initial_address,
                                     **config)
        try:
            pool.update_routing_table()
        except:
            pool.close()
            raise
        else:
            instance._pool = pool
            instance._max_retry_time = config.get(
                "max_retry_time", default_config["max_retry_time"])
            return instance