Пример #1
0
        private IPAddressInfo GetNextIPAddressInfo()
        {
            IPHostEntry ipHostEntry;

            lock (this) {
                GlobalLog.Print("m_CurrentAddressInfoIndex = " + m_CurrentAddressInfoIndex);
                GlobalLog.Print("m_ConnectionsSinceDns = " + m_ConnectionsSinceDns);
                GlobalLog.Print("m_IPHostEntryInfos = " + m_IPHostEntryInfos);
                m_CurrentAddressInfoIndex++;
                if (m_ConnectionsSinceDns < 0 || (m_ConnectionsSinceDns > 0 && m_IPHostEntryInfos != null && m_IPHostEntryInfos.IPAddressInfoList != null && m_CurrentAddressInfoIndex == m_IPHostEntryInfos.IPAddressInfoList.Length))
                {
                    //
                    // it's either the first time we get here or we reached the end
                    // of the list of valid IPAddressInfo that we can connect to.
                    // in this second case, since at least one of the IPAddressInfo we got
                    // from DNS was valid, we'll query DNS again in case we just need to
                    // refresh our internal list. note that we don't need to assert DnsPermission
                    // since the internal method we're calling (Dns.InternalResolve()) doesn't Demand() any
                    //
                    m_ConnectionsSinceDns = 0;
                    try {
                        GlobalLog.Print("ServicePoint::GetNextIPAddressInfo() calling Dns.InternalResolve() for:" + m_Address.Host);
                        ipHostEntry = Dns.InternalResolve(m_Address.Host);
                        GlobalLog.Print("ServicePoint::GetNextIPAddressInfo() Dns.InternalResolve() returns:" + ValidationHelper.ToString(ipHostEntry));
                        if (ipHostEntry != null && ipHostEntry.AddressList != null && ipHostEntry.AddressList.Length > 0)
                        {
                            //
                            // this call will reset m_IPHostEntryInfos
                            //
                            m_CurrentAddressInfoIndex = 0;
                            m_IPHostEntryInfos        = SetAddressList(ipHostEntry);
                        }
                        else
                        {
                            GlobalLog.Print("Dns.InternalResolve() failed with null");
                            m_IPHostEntryInfos = null;
                        }
                    }
                    catch (Exception e) {
                        GlobalLog.Print("Dns.InternalResolve() failed with exception: " + e.Message + " " + e.StackTrace);
                        m_IPHostEntryInfos = null;
                    }
                }
                if (m_IPHostEntryInfos != null && m_IPHostEntryInfos.IPAddressInfoList != null && m_CurrentAddressInfoIndex < m_IPHostEntryInfos.IPAddressInfoList.Length)
                {
                    GlobalLog.Print("GetNextIPAddressInfo() returning " + m_IPHostEntryInfos.IPAddressInfoList[m_CurrentAddressInfoIndex]);
                    return(m_IPHostEntryInfos.IPAddressInfoList[m_CurrentAddressInfoIndex]);
                }
                // If we walked the whole list in failure, than reset and retry DNS
                if (m_IPHostEntryInfos == null || m_IPHostEntryInfos.IPAddressInfoList == null || m_CurrentAddressInfoIndex >= m_IPHostEntryInfos.IPAddressInfoList.Length)
                {
                    GlobalLog.Print("setting m_ConnectionsSinceDns to -1");
                    m_ConnectionsSinceDns = -1;
                }
            }
            GlobalLog.Print("GetNextIPAddressInfo() returning null");
            return(null);
        }
Пример #2
0
 private IPAddressInfo GetNextIPAddressInfo() {
     IPHostEntry ipHostEntry;
     lock (this) {
         GlobalLog.Print("m_CurrentAddressInfoIndex = "+m_CurrentAddressInfoIndex);
         GlobalLog.Print("m_ConnectionsSinceDns = "+m_ConnectionsSinceDns);
         GlobalLog.Print("m_IPHostEntryInfos = "+m_IPHostEntryInfos);
         m_CurrentAddressInfoIndex++;
         if (m_ConnectionsSinceDns<0 || (m_ConnectionsSinceDns>0 && m_IPHostEntryInfos!=null && m_IPHostEntryInfos.IPAddressInfoList!=null && m_CurrentAddressInfoIndex==m_IPHostEntryInfos.IPAddressInfoList.Length)) {
             //
             // it's either the first time we get here or we reached the end
             // of the list of valid IPAddressInfo that we can connect to.
             // in this second case, since at least one of the IPAddressInfo we got
             // from DNS was valid, we'll query DNS again in case we just need to
             // refresh our internal list. note that we don't need to assert DnsPermission
             // since the internal method we're calling (Dns.InternalResolve()) doesn't Demand() any
             //
             m_ConnectionsSinceDns = 0;
             try {
                 GlobalLog.Print("ServicePoint::GetNextIPAddressInfo() calling Dns.InternalResolve() for:" + m_Address.Host);
                 ipHostEntry = Dns.InternalResolve(m_Address.Host);
                 GlobalLog.Print("ServicePoint::GetNextIPAddressInfo() Dns.InternalResolve() returns:" + ValidationHelper.ToString(ipHostEntry));
                 if (ipHostEntry!=null && ipHostEntry.AddressList!=null && ipHostEntry.AddressList.Length>0) {
                     //
                     // this call will reset m_IPHostEntryInfos
                     //
                     m_CurrentAddressInfoIndex = 0;
                     m_IPHostEntryInfos = SetAddressList(ipHostEntry);
                 }
                 else {
                     GlobalLog.Print("Dns.InternalResolve() failed with null");
                     m_IPHostEntryInfos = null;
                 }
             }
             catch {
                 GlobalLog.Print("Dns.InternalResolve() failed with exception");
                 m_IPHostEntryInfos = null;
             }
         }
         if (m_IPHostEntryInfos!=null && m_IPHostEntryInfos.IPAddressInfoList!=null && m_CurrentAddressInfoIndex<m_IPHostEntryInfos.IPAddressInfoList.Length) {
             GlobalLog.Print("GetNextIPAddressInfo() returning "+m_IPHostEntryInfos.IPAddressInfoList[m_CurrentAddressInfoIndex]);
             return m_IPHostEntryInfos.IPAddressInfoList[m_CurrentAddressInfoIndex];
         }
         // If we walked the whole list in failure, than reset and retry DNS
         if (m_IPHostEntryInfos==null || m_IPHostEntryInfos.IPAddressInfoList==null || m_CurrentAddressInfoIndex>=m_IPHostEntryInfos.IPAddressInfoList.Length) {
             GlobalLog.Print("setting m_ConnectionsSinceDns to -1");
             m_ConnectionsSinceDns = -1;
         }
     }
     GlobalLog.Print("GetNextIPAddressInfo() returning null");
     return null;
 }
Пример #3
0
        /*++

            SetAddressList - Set the list of IP addresses for this service point.

            This is a method called when the underlying code has resolved the
            destination to a list of IP addressess. We actually maintain some
            information about the viable IP addresses for this service point,
            like whether or not they're loopback, etc. So we walk through the
            list and set up an array of structures corresponding to the IP
            addresses.

            Note that it's possible to have some IP addresses be loopbacked
            and some not. This can happen if a server name maps to multiple
            physical servers and we're one of those servers.

            Input:
                    addressList     - Array of resolved IP addresses.

            Returns: Nothing.

        --*/
        private IPHostEntryInfo SetAddressList(IPHostEntry ipHostEntry) {
            GlobalLog.Print("SetAddressList("+ipHostEntry.HostName+")");
            //
            // Create an array of IPAddressInfo of the appropriate size, then
            // get a list of our local addresses. Walk through the input
            // address list. Copy each address in the address list into
            // our array, and if the address is a loopback address, mark it as
            // such.
            //
            IPAddress[] addressList = ipHostEntry.AddressList;
            IPAddressInfo[] TempInfo = new IPAddressInfo[addressList.Length];

            //
            // Walk through each member of the input list, copying it into our temp array.
            //
            int i, k;
            IPHostEntry ipLocalHostEntry = Dns.LocalHost;
            for (i = 0; i < addressList.Length; i++) {
                TempInfo[i] = new IPAddressInfo(addressList[i]);

                // First, check to see if the current address is a  loopback
                // address.

                if (IPAddress.IsLoopback(TempInfo[i].Address)) {
                    TempInfo[i].IsLoopback = true;
                    continue;
                }

                // See if the current IP address is a local address, and if
                // so mark it as such.

                for (k = 0; k < ipLocalHostEntry.AddressList.Length; k++) {
                    if (TempInfo[i].Address.Address == ipLocalHostEntry.AddressList[k].Address) {
                        TempInfo[i].IsLoopback = true;
                        break;
                    }
                }
            }

            //
            // now look for connection group objects that don't have
            // an IP address associated with them. When it finds one, it updates
            // the IP address and tries to update the connection limit.
            //
            lock (this) {
                // Walk through the connection groups on this service
                // point, and update the ones we need to with an IP
                // address.
                //

                IDictionaryEnumerator CGEnumerator;

                CGEnumerator = m_ConnectionGroupList.GetEnumerator();

                while (CGEnumerator.MoveNext()) {
                    ConnectionGroup CurrentCG = (ConnectionGroup)CGEnumerator.Value;

                    // If this connection group doesn't have an IP address
                    // assigned to it, give it one.

                    if (CurrentCG.RemoteIPAddress == null) {
                        GlobalLog.Print("ServicePoint::UpdateConnectionGroupAddresses null CurrentCG.RemoteIPAddress");

                        // Update the address.

                        CurrentCG.RemoteIPAddress = TempInfo[0].Address;

                        // Now update the connection limit based on what we know.

                        CurrentCG.InternalConnectionLimit = TempInfo[0].IsLoopback ? LoopbackConnectionLimit : m_ConnectionLimit;

                        GlobalLog.Print("ServicePoint::UpdateConnectionGroupAddresses CurrentCG.InternalConnectionLimit:" + CurrentCG.InternalConnectionLimit.ToString());
                    }

                    GlobalLog.Print("ServicePoint::UpdateConnectionGroupAddresses CurrentCG.RemoteIPAddress:" + CurrentCG.RemoteIPAddress.ToString());
                }
            }

            IPHostEntryInfo ipAddressInfoList = new IPHostEntryInfo(TempInfo, ipHostEntry.HostName);
            return ipAddressInfoList ;
        }
Пример #4
0
        /*++
         *
         *  SetAddressList - Set the list of IP addresses for this service point.
         *
         *  This is a method called when the underlying code has resolved the
         *  destination to a list of IP addressess. We actually maintain some
         *  information about the viable IP addresses for this service point,
         *  like whether or not they're loopback, etc. So we walk through the
         *  list and set up an array of structures corresponding to the IP
         *  addresses.
         *
         *  Note that it's possible to have some IP addresses be loopbacked
         *  and some not. This can happen if a server name maps to multiple
         *  physical servers and we're one of those servers.
         *
         *  Input:
         *          addressList     - Array of resolved IP addresses.
         *
         *  Returns: Nothing.
         *
         * --*/
        private IPHostEntryInfo SetAddressList(IPHostEntry ipHostEntry)
        {
            GlobalLog.Print("SetAddressList(" + ipHostEntry.HostName + ")");
            //
            // Create an array of IPAddressInfo of the appropriate size, then
            // get a list of our local addresses. Walk through the input
            // address list. Copy each address in the address list into
            // our array, and if the address is a loopback address, mark it as
            // such.
            //
            IPAddress[]     addressList = ipHostEntry.AddressList;
            IPAddressInfo[] TempInfo    = new IPAddressInfo[addressList.Length];

            //
            // Walk through each member of the input list, copying it into our temp array.
            //
            int         i, k;
            IPHostEntry ipLocalHostEntry = null;

            try {
                ipLocalHostEntry = Dns.LocalHost;
            }
            catch (Exception exception) {
                GlobalLog.Print("ServicePoint#" + ValidationHelper.HashString(this) + "::SetAddressList() Dns.LocalHost threw exception:[" + ValidationHelper.ToString(exception) + "]");
            }
            for (i = 0; i < addressList.Length; i++)
            {
                TempInfo[i] = new IPAddressInfo(addressList[i]);

                // First, check to see if the current address is a  loopback
                // address.

                if (IPAddress.IsLoopback(TempInfo[i].Address))
                {
                    TempInfo[i].IsLoopback = true;
                    continue;
                }

                // See if the current IP address is a local address, and if
                // so mark it as such.
                if (ipLocalHostEntry != null)
                {
                    for (k = 0; k < ipLocalHostEntry.AddressList.Length; k++)
                    {
                        //
                        // IPv6 Changes: Use .Equals for this check !
                        //
                        if (TempInfo[i].Address.Equals(ipLocalHostEntry.AddressList[k]))
                        {
                            TempInfo[i].IsLoopback = true;
                            break;
                        }
                    }
                }
            }

            //
            // now look for connection group objects that don't have
            // an IP address associated with them. When it finds one, it updates
            // the IP address and tries to update the connection limit.
            //
            lock (this) {
                // Walk through the connection groups on this service
                // point, and update the ones we need to with an IP
                // address.
                //

                IDictionaryEnumerator CGEnumerator;

                CGEnumerator = m_ConnectionGroupList.GetEnumerator();

                while (CGEnumerator.MoveNext())
                {
                    ConnectionGroup CurrentCG = (ConnectionGroup)CGEnumerator.Value;

                    // If this connection group doesn't have an IP address
                    // assigned to it, give it one.

                    if (CurrentCG.RemoteIPAddress == null)
                    {
                        GlobalLog.Print("ServicePoint::UpdateConnectionGroupAddresses null CurrentCG.RemoteIPAddress");

                        // Update the address.

                        CurrentCG.RemoteIPAddress = TempInfo[0].Address;

                        // Now update the connection limit based on what we know.

                        CurrentCG.InternalConnectionLimit = TempInfo[0].IsLoopback ? LoopbackConnectionLimit : m_ConnectionLimit;

                        GlobalLog.Print("ServicePoint::UpdateConnectionGroupAddresses CurrentCG.InternalConnectionLimit:" + CurrentCG.InternalConnectionLimit.ToString());
                    }

                    GlobalLog.Print("ServicePoint::UpdateConnectionGroupAddresses CurrentCG.RemoteIPAddress:" + CurrentCG.RemoteIPAddress.ToString());
                }
            }

            IPHostEntryInfo ipAddressInfoList = new IPHostEntryInfo(TempInfo, ipHostEntry.HostName);

            return(ipAddressInfoList);
        }