/// <summary>
        /// Returns a <see cref="RelayNodeClusterDefinition"/> for the current environment that contains
        /// the a node configured to listen on the
        /// </summary>
        /// <param name="address"></param>
        /// <param name="portNumber"></param>
        /// <returns></returns>
        internal RelayNodeClusterDefinition GetClusterFor(IPAddress address, int portNumber)
        {
            RelayNodeClusterDefinition[] clusters = null;
            EnvironmentDefinition        env      = GetEnvironment();

            if (env != null)
            {
                clusters = env.RelayNodeClusters;
            }
            else
            {
                clusters = DefaultRelayNodeClusters;
            }

            RelayNodeClusterDefinition clusterDefinition = null;

            if (clusters != null)
            {
                foreach (RelayNodeClusterDefinition cluster in clusters)
                {
                    if (cluster.ContainsNode(address, portNumber))
                    {
                        clusterDefinition = cluster;
                        break;
                    }
                }
            }
            return(clusterDefinition);
        }
Exemple #2
0
        /// <summary>
        /// Returns a <see cref="RelayNodeClusterDefinition"/> for the current environment that contains
        /// the a node configured to listen on the
        /// </summary>
        /// <param name="address">The address.</param>
        /// <param name="portNumber">The port number.</param>
        /// <param name="clusterIndex">Index of the cluster.</param>
        /// <returns></returns>
        internal RelayNodeClusterDefinition GetClusterFor(IPAddress address, int portNumber, out int clusterIndex)
        {
            RelayNodeClusterDefinition[] clusters = null;
            EnvironmentDefinition        env      = GetEnvironment();

            clusterIndex = -1;
            if (env != null)
            {
                clusters = env.RelayNodeClusters;
            }
            else
            {
                clusters = DefaultRelayNodeClusters;
            }

            RelayNodeClusterDefinition clusterDefinition = null;

            if (clusters != null)
            {
                for (int i = 0; i < clusters.Length; i++)
                {
                    if (clusters[i].ContainsNode(address, portNumber))
                    {
                        clusterDefinition = clusters[i];
                        clusterIndex      = i;
                        break;
                    }
                }
            }

            return(clusterDefinition);
        }
        /// <summary>
        /// Returns a <see cref="RelayNodeDefinition"/> of a node configured to listen
        /// on a given address and port contained in any cluster for the current environment.
        /// </summary>
        /// <param name="address">The <see cref="IPAddress"/> to look for.</param>
        /// <param name="listenPort">The port that the node is listening on.</param>
        /// <returns>Returns a definition if found; otherwise, returns null.</returns>
        public RelayNodeDefinition GetNodeFor(IPAddress address, int listenPort)
        {
            RelayNodeDefinition nodeDefinition = null;
            var defaultSettings = DefaultRelayNodeClusters;

            RelayNodeClusterDefinition[] clusters = defaultSettings;
            EnvironmentDefinition        env      = GetEnvironment();

            if (env != null)
            {
                clusters = env.RelayNodeClusters;
            }

            foreach (RelayNodeClusterDefinition cluster in clusters)
            {
                nodeDefinition = cluster.GetNodeFor(address, listenPort);
                if (nodeDefinition != null)
                {
                    break;
                }
            }

            return(nodeDefinition);
        }