internal static TcpClientChannel OpenConnection(ref NetworkPath actualPath, int timeoutInMsec, bool ignoreNodeDown) { NetworkPath networkPath = actualPath; NetworkTransportException ex = null; ITcpConnector tcpConnector = Dependencies.TcpConnector; TcpClientChannel tcpClientChannel = tcpConnector.TryConnect(networkPath, timeoutInMsec, out ex); if (tcpClientChannel != null) { return tcpClientChannel; } if (!networkPath.NetworkChoiceIsMandatory) { NetworkManager.TraceError("Attempting alternate routes", new object[0]); List<NetworkPath> list = null; ExchangeNetworkMap map = NetworkManager.GetMap(); if (map != null) { list = map.EnumeratePaths(networkPath.TargetNodeName, ignoreNodeDown); if (list != null) { NetworkPath networkPath2 = null; foreach (NetworkPath networkPath3 in list) { if (string.Equals(networkPath3.NetworkName, networkPath.NetworkName, DatabaseAvailabilityGroupNetwork.NameComparison)) { networkPath2 = networkPath3; break; } } if (networkPath2 != null) { list.Remove(networkPath2); } DagNetConfig dagConfig = DagNetEnvironment.FetchNetConfig(); foreach (NetworkPath networkPath4 in list) { networkPath4.Purpose = networkPath.Purpose; networkPath4.ApplyNetworkPolicy(dagConfig); tcpClientChannel = tcpConnector.TryConnect(networkPath, timeoutInMsec, out ex); if (tcpClientChannel != null) { actualPath = networkPath4; return tcpClientChannel; } } } } } throw ex; }
internal static NetworkPath InternalChooseDagNetworkPath(string targetName, string networkName, NetworkPath.ConnectionPurpose purpose) { string nodeNameFromFqdn = MachineName.GetNodeNameFromFqdn(targetName); NetworkManager manager = NetworkManager.GetManager(); NetworkPath networkPath = null; DagNetConfig dagNetConfig = null; manager.TryWaitForInitialization(); if (manager.m_netMap != null) { networkPath = manager.m_netMap.ChoosePath(nodeNameFromFqdn, networkName); } else { DagNetRoute dagNetRoute = null; DagNetRoute[] array = DagNetChooser.ProposeRoutes(targetName, out dagNetConfig); if (networkName != null) { foreach (DagNetRoute dagNetRoute2 in array) { if (StringUtil.IsEqualIgnoreCase(dagNetRoute2.NetworkName, networkName)) { dagNetRoute = dagNetRoute2; break; } } } else if (array != null && array.Length > 0) { dagNetRoute = array[0]; } if (dagNetRoute != null) { networkPath = new NetworkPath(targetName, dagNetRoute.TargetIPAddr, dagNetRoute.TargetPort, dagNetRoute.SourceIPAddr); networkPath.NetworkName = dagNetRoute.NetworkName; networkPath.CrossSubnet = dagNetRoute.IsCrossSubnet; } } if (networkPath == null) { networkPath = NetworkManager.BuildDnsNetworkPath(targetName, NetworkManager.GetReplicationPort()); } networkPath.Purpose = purpose; if (dagNetConfig == null) { dagNetConfig = DagNetEnvironment.FetchNetConfig(); } networkPath.ApplyNetworkPolicy(dagNetConfig); return networkPath; }