예제 #1
0
 /// <summary>
 /// Create TLS socket and update node statistics.
 /// </summary>
 public TlsConnection(TlsPolicy policy, string tlsName, IPEndPoint address, int timeoutMillis, Pool <Connection> pool, Node node)
     : this(policy, tlsName, address, timeoutMillis, pool)
 {
     Interlocked.Increment(ref node.connsOpened);
 }
예제 #2
0
        public Cluster(ClientPolicy policy, Host[] hosts)
        {
            this.clusterName = policy.clusterName;
            tlsPolicy        = policy.tlsPolicy;
            this.authMode    = policy.authMode;

            // Default TLS names when TLS enabled.
            if (tlsPolicy != null)
            {
                bool useClusterName = HasClusterName;

                for (int i = 0; i < hosts.Length; i++)
                {
                    Host host = hosts[i];

                    if (host.tlsName == null)
                    {
                        string tlsName = useClusterName ? clusterName : host.name;
                        hosts[i] = new Host(host.name, tlsName, host.port);
                    }
                }
            }
            else
            {
                if (authMode == AuthMode.EXTERNAL)
                {
                    throw new AerospikeException("TLS is required for authentication mode: " + authMode);
                }
            }

            this.seeds = hosts;

            if (policy.user != null && policy.user.Length > 0)
            {
                this.user = ByteUtil.StringToUtf8(policy.user);

                // Only store clear text password if external authentication is used.
                if (authMode != AuthMode.INTERNAL)
                {
                    this.password = ByteUtil.StringToUtf8(policy.password);
                }

                string pass = policy.password;

                if (pass == null)
                {
                    pass = "";
                }

                if (!(pass.Length == 60 && pass.StartsWith("$2a$")))
                {
                    pass = AdminCommand.HashPassword(pass);
                }
                this.passwordHash = ByteUtil.StringToUtf8(pass);
            }

            if (policy.maxSocketIdle < 0)
            {
                throw new AerospikeException("Invalid maxSocketIdle: " + policy.maxSocketIdle);
            }

            if (policy.maxSocketIdle == 0)
            {
                maxSocketIdleMillisTran = 0.0;
                maxSocketIdleMillisTrim = 55000.0;
            }
            else
            {
                maxSocketIdleMillisTran = (double)(policy.maxSocketIdle * 1000);
                maxSocketIdleMillisTrim = maxSocketIdleMillisTran;
            }

            minConnsPerNode = policy.minConnsPerNode;
            maxConnsPerNode = policy.maxConnsPerNode;

            if (minConnsPerNode > maxConnsPerNode)
            {
                throw new AerospikeException("Invalid connection range: " + minConnsPerNode + " - " + maxConnsPerNode);
            }

            connPoolsPerNode     = policy.connPoolsPerNode;
            maxErrorRate         = policy.maxErrorRate;
            errorRateWindow      = policy.errorRateWindow;
            connectionTimeout    = policy.timeout;
            loginTimeout         = policy.loginTimeout;
            tendInterval         = policy.tendInterval;
            ipMap                = policy.ipMap;
            useServicesAlternate = policy.useServicesAlternate;
            rackAware            = policy.rackAware;
            rackId               = policy.rackId;

            aliases      = new Dictionary <Host, Node>();
            nodesMap     = new Dictionary <string, Node>();
            nodes        = new Node[0];
            partitionMap = new Dictionary <string, Partitions>();
            cancel       = new CancellationTokenSource();
            cancelToken  = cancel.Token;
        }
예제 #3
0
        public Cluster(ClientPolicy policy, Host[] hosts)
        {
            this.clusterName = policy.clusterName;
            tlsPolicy        = policy.tlsPolicy;
            this.authMode    = policy.authMode;

            // Default TLS names when TLS enabled.
            if (tlsPolicy != null)
            {
                bool useClusterName = HasClusterName;

                for (int i = 0; i < hosts.Length; i++)
                {
                    Host host = hosts[i];

                    if (host.tlsName == null)
                    {
                        string tlsName = useClusterName ? clusterName : host.name;
                        hosts[i] = new Host(host.name, tlsName, host.port);
                    }
                }
            }
            else
            {
                if (authMode == AuthMode.EXTERNAL)
                {
                    throw new AerospikeException("TLS is required for authentication mode: " + authMode);
                }
            }

            this.seeds = hosts;

            if (policy.user != null && policy.user.Length > 0)
            {
                this.user = ByteUtil.StringToUtf8(policy.user);

                // Only store clear text password if external authentication is used.
                if (authMode != AuthMode.INTERNAL)
                {
                    this.password = ByteUtil.StringToUtf8(policy.password);
                }

                string pass = policy.password;

                if (pass == null)
                {
                    pass = "";
                }

                if (!(pass.Length == 60 && pass.StartsWith("$2a$")))
                {
                    pass = AdminCommand.HashPassword(pass);
                }
                this.passwordHash = ByteUtil.StringToUtf8(pass);
            }

            connectionQueueSize = policy.maxConnsPerNode;
            connPoolsPerNode    = policy.connPoolsPerNode;
            connectionTimeout   = policy.timeout;
            loginTimeout        = policy.loginTimeout;
            maxSocketIdleMillis = 1000 * ((policy.maxSocketIdle <= MaxSocketIdleSecondLimit) ? policy.maxSocketIdle : MaxSocketIdleSecondLimit);
            tendInterval        = policy.tendInterval;
            ipMap = policy.ipMap;
            requestProleReplicas = policy.requestProleReplicas;
            useServicesAlternate = policy.useServicesAlternate;

            aliases      = new Dictionary <Host, Node>();
            nodesMap     = new Dictionary <string, Node>();
            nodes        = new Node[0];
            partitionMap = new Dictionary <string, Partitions>();
            cancel       = new CancellationTokenSource();
            cancelToken  = cancel.Token;
        }
예제 #4
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 public TlsPolicy(TlsPolicy other)
 {
     this.protocols          = other.protocols;
     this.revokeCertificates = other.revokeCertificates;
     this.clientCertificates = other.clientCertificates;
 }