diff options
author | Dwayne Boone <dwayne@zeroc.com> | 2007-05-16 19:13:34 +0000 |
---|---|---|
committer | Dwayne Boone <dwayne@zeroc.com> | 2007-05-16 19:13:34 +0000 |
commit | d87f468730fd906d062e982bc401e450649d5576 (patch) | |
tree | 3a3c46780a818eeaa1ed3bea63593121ed9337c2 | |
parent | Bug 1625 - unused property warning (diff) | |
download | ice-d87f468730fd906d062e982bc401e450649d5576.tar.bz2 ice-d87f468730fd906d062e982bc401e450649d5576.tar.xz ice-d87f468730fd906d062e982bc401e450649d5576.zip |
Bug 1996 - multihomed hostnames
-rw-r--r-- | cpp/CHANGES | 4 | ||||
-rw-r--r-- | cpp/src/Ice/Network.cpp | 32 | ||||
-rw-r--r-- | cpp/src/Ice/Network.h | 1 | ||||
-rw-r--r-- | cpp/src/Ice/TcpEndpointI.cpp | 22 | ||||
-rw-r--r-- | cpp/src/Ice/UdpEndpointI.cpp | 22 | ||||
-rw-r--r-- | cpp/src/IceSSL/EndpointI.cpp | 22 | ||||
-rw-r--r-- | cs/CHANGES | 4 | ||||
-rwxr-xr-x | cs/src/Ice/Network.cs | 39 | ||||
-rwxr-xr-x | cs/src/Ice/TcpEndpointI.cs | 24 | ||||
-rwxr-xr-x | cs/src/Ice/UdpEndpointI.cs | 24 | ||||
-rwxr-xr-x | cs/src/IceSSL/EndpointI.cs | 24 | ||||
-rw-r--r-- | java/CHANGES | 4 | ||||
-rw-r--r-- | java/src/IceInternal/Network.java | 35 | ||||
-rw-r--r-- | java/src/IceInternal/TcpEndpointI.java | 25 | ||||
-rw-r--r-- | java/src/IceInternal/UdpEndpointI.java | 25 | ||||
-rw-r--r-- | java/ssl/jdk1.4/IceSSL/EndpointI.java | 25 | ||||
-rw-r--r-- | java/ssl/jdk1.5/IceSSL/EndpointI.java | 25 |
17 files changed, 340 insertions, 17 deletions
diff --git a/cpp/CHANGES b/cpp/CHANGES index 0aaf25ced36..4d6c32f6633 100644 --- a/cpp/CHANGES +++ b/cpp/CHANGES @@ -1,6 +1,10 @@ Changes since version 3.2.X (binary incompabible) ------------------------------------------------- +- If a client endpoint configuration contains a host which is multihomed, + the client will now use all the available ip addresses. Previously, + only the first in the address list was used and others were ignored. + - Added a new property, Ice.Warn.UnusedProperties. If set to 1, when the communicator is destroyed a warning will be printed listing all properties that were set, but never read. Default is 0. diff --git a/cpp/src/Ice/Network.cpp b/cpp/src/Ice/Network.cpp index 33bfec5739f..6e907c4bdbe 100644 --- a/cpp/src/Ice/Network.cpp +++ b/cpp/src/Ice/Network.cpp @@ -1260,6 +1260,38 @@ IceInternal::addrToString(const struct sockaddr_in& addr) } vector<string> +IceInternal::getHosts(const string& host) +{ + vector<string> result; + struct hostent* he = 0; + int retry = 5; + + do + { + he = gethostbyname(host.c_str()); + } + while(he == 0 && h_errno == TRY_AGAIN && --retry >= 0); + + if(he == 0) + { + DNSException ex(__FILE__, __LINE__); + ex.error = h_errno; + ex.host = host; + throw ex; + } + + char** ptr = he->h_addr_list; + while(*ptr) + { + struct in_addr* addr = reinterpret_cast<in_addr*>(*ptr); + result.push_back(inet_ntoa(*addr)); + ptr++; + } + + return result; +} + +vector<string> IceInternal::getLocalHosts() { vector<string> result; diff --git a/cpp/src/Ice/Network.h b/cpp/src/Ice/Network.h index 6ee6c80d72f..f03836965c6 100644 --- a/cpp/src/Ice/Network.h +++ b/cpp/src/Ice/Network.h @@ -107,6 +107,7 @@ ICE_API void fdToLocalAddress(SOCKET, struct sockaddr_in&); ICE_API bool fdToRemoteAddress(SOCKET, struct sockaddr_in&); ICE_API std::string addrToString(const struct sockaddr_in&); +ICE_API std::vector<std::string> getHosts(const std::string&); ICE_API std::vector<std::string> getLocalHosts(); #ifdef _WIN32 ICE_API std::vector<struct sockaddr_in> getLocalAddresses(); diff --git a/cpp/src/Ice/TcpEndpointI.cpp b/cpp/src/Ice/TcpEndpointI.cpp index 6cf54872826..1c336cb8afc 100644 --- a/cpp/src/Ice/TcpEndpointI.cpp +++ b/cpp/src/Ice/TcpEndpointI.cpp @@ -327,7 +327,27 @@ IceInternal::TcpEndpointI::expand(bool server) const } else { - endps.push_back(const_cast<TcpEndpointI*>(this)); + if(!server) + { + + vector<string> hosts = getHosts(_host); + if(hosts.size() > 1) + { + for(unsigned int i = 0; i < hosts.size(); ++i) + { + endps.push_back( + new TcpEndpointI(_instance, hosts[i], _port, _timeout, _connectionId, _compress, true)); + } + } + else + { + endps.push_back(const_cast<TcpEndpointI*>(this)); + } + } + else + { + endps.push_back(const_cast<TcpEndpointI*>(this)); + } } return endps; } diff --git a/cpp/src/Ice/UdpEndpointI.cpp b/cpp/src/Ice/UdpEndpointI.cpp index 6681e8becbf..0eef033dd06 100644 --- a/cpp/src/Ice/UdpEndpointI.cpp +++ b/cpp/src/Ice/UdpEndpointI.cpp @@ -492,7 +492,27 @@ IceInternal::UdpEndpointI::expand(bool server) const } else { - endps.push_back(const_cast<UdpEndpointI*>(this)); + if(!server) + { + + vector<string> hosts = getHosts(_host); + if(hosts.size() > 1) + { + for(unsigned int i = 0; i < hosts.size(); ++i) + { + endps.push_back( + new UdpEndpointI(_instance, hosts[i], _port, _connect, _connectionId, _compress, true)); + } + } + else + { + endps.push_back(const_cast<UdpEndpointI*>(this)); + } + } + else + { + endps.push_back(const_cast<UdpEndpointI*>(this)); + } } return endps; } diff --git a/cpp/src/IceSSL/EndpointI.cpp b/cpp/src/IceSSL/EndpointI.cpp index 69866544132..a14f152f3e1 100644 --- a/cpp/src/IceSSL/EndpointI.cpp +++ b/cpp/src/IceSSL/EndpointI.cpp @@ -327,7 +327,27 @@ IceSSL::EndpointI::expand(bool server) const } else { - endps.push_back(const_cast<EndpointI*>(this)); + if(!server) + { + + vector<string> hosts = IceInternal::getHosts(_host); + if(hosts.size() > 1) + { + for(unsigned int i = 0; i < hosts.size(); ++i) + { + endps.push_back( + new EndpointI(_instance, hosts[i], _port, _timeout, _connectionId, _compress, true)); + } + } + else + { + endps.push_back(const_cast<EndpointI*>(this)); + } + } + else + { + endps.push_back(const_cast<EndpointI*>(this)); + } } return endps; } diff --git a/cs/CHANGES b/cs/CHANGES index 1298ded0991..d0f18625885 100644 --- a/cs/CHANGES +++ b/cs/CHANGES @@ -1,6 +1,10 @@ Changes since version 3.2.X (binary incompabible) ------------------------------------------------- +- If a client endpoint configuration contains a host which is multihomed, + the client will now use all the available ip addresses. Previously, + only the first in the address list was used and others were ignored. + - Added a new property, Ice.Warn.UnusedProperties. If set to 1, when the communicator is destroyed a warning will be printed listing all properties that were set, but never read. Default is 0. diff --git a/cs/src/Ice/Network.cs b/cs/src/Ice/Network.cs index 0e30942dc87..9dd94ee1ae6 100755 --- a/cs/src/Ice/Network.cs +++ b/cs/src/Ice/Network.cs @@ -824,6 +824,45 @@ namespace IceInternal throw dns; } + public static string[] getHosts(string host) + { + ArrayList hosts; + + int retry = 5; + + repeatGetHostByName: + try + { + IPHostEntry e = Dns.GetHostEntry(host); + hosts = new ArrayList(); + for(int i = 0; i < e.AddressList.Length; ++i) + { + if(e.AddressList[i].AddressFamily != AddressFamily.InterNetworkV6) + { + hosts.Add(e.AddressList[i].ToString()); + } + } + } + catch(Win32Exception ex) + { + if(ex.NativeErrorCode == WSATRY_AGAIN && --retry >= 0) + { + goto repeatGetHostByName; + } + Ice.DNSException e = new Ice.DNSException(ex); + e.host = host; + throw e; + } + catch(System.Exception ex) + { + Ice.DNSException e = new Ice.DNSException(ex); + e.host = host; + throw e; + } + + return (string[])hosts.ToArray(typeof(string)); + } + public static string[] getLocalHosts() { ArrayList hosts; diff --git a/cs/src/Ice/TcpEndpointI.cs b/cs/src/Ice/TcpEndpointI.cs index be5f9a8068a..f6b7205bfd3 100755 --- a/cs/src/Ice/TcpEndpointI.cs +++ b/cs/src/Ice/TcpEndpointI.cs @@ -391,8 +391,28 @@ namespace IceInternal } else { - calcHashValue(); - endps.Add(this); + if(!server) + { + string[] hosts = Network.getHosts(_host); + if(hosts.Length > 1) + { + for(int i = 0; i < hosts.Length; ++i) + { + endps.Add( + new TcpEndpointI(instance_, hosts[i], _port, _timeout, _connectionId, _compress, true)); + } + } + else + { + calcHashValue(); + endps.Add(this); + } + } + else + { + calcHashValue(); + endps.Add(this); + } } return endps; } diff --git a/cs/src/Ice/UdpEndpointI.cs b/cs/src/Ice/UdpEndpointI.cs index 043ca36e4ba..598176603a7 100755 --- a/cs/src/Ice/UdpEndpointI.cs +++ b/cs/src/Ice/UdpEndpointI.cs @@ -540,8 +540,28 @@ namespace IceInternal } else { - calcHashValue(); - endps.Add(this); + if(!server) + { + string[] hosts = Network.getHosts(_host); + if(hosts.Length > 1) + { + for(int i = 0; i < hosts.Length; ++i) + { + endps.Add( + new UdpEndpointI(instance_, hosts[i], _port, _connect, _connectionId, _compress, true)); + } + } + else + { + calcHashValue(); + endps.Add(this); + } + } + else + { + calcHashValue(); + endps.Add(this); + } } return endps; } diff --git a/cs/src/IceSSL/EndpointI.cs b/cs/src/IceSSL/EndpointI.cs index bd5b8148e68..224269104a1 100755 --- a/cs/src/IceSSL/EndpointI.cs +++ b/cs/src/IceSSL/EndpointI.cs @@ -388,8 +388,28 @@ namespace IceSSL } else { - calcHashValue(); - endps.Add(this); + if(!server) + { + string[] hosts = IceInternal.Network.getHosts(_host); + if(hosts.Length > 1) + { + for(int i = 0; i < hosts.Length; ++i) + { + endps.Add( + new EndpointI(instance_, hosts[i], _port, _timeout, _connectionId, _compress, true)); + } + } + else + { + calcHashValue(); + endps.Add(this); + } + } + else + { + calcHashValue(); + endps.Add(this); + } } return endps; } diff --git a/java/CHANGES b/java/CHANGES index 4f51fadb3ff..1422898c28b 100644 --- a/java/CHANGES +++ b/java/CHANGES @@ -1,6 +1,10 @@ Changes since version 3.2.X (binary incompabible) ------------------------------------------------- +- If a client endpoint configuration contains a host which is multihomed, + the client will now use all the available ip addresses. Previously, + only the first in the address list was used and others were ignored. + - Added a new property, Ice.Warn.UnusedProperties. If set to 1, when the communicator is destroyed a warning will be printed listing all properties that were set, but never read. Default is 0. diff --git a/java/src/IceInternal/Network.java b/java/src/IceInternal/Network.java index 92a1547d234..cfa52fa0e4c 100644 --- a/java/src/IceInternal/Network.java +++ b/java/src/IceInternal/Network.java @@ -654,6 +654,41 @@ public final class Network } public static java.util.ArrayList + getHosts(String host) + { + java.util.ArrayList hosts = new java.util.ArrayList(); + try + { + java.net.InetAddress[] addrs = java.net.InetAddress.getAllByName(host); + for(int i = 0; i < addrs.length; ++i) + { + if(addrs[i] instanceof java.net.Inet4Address) + { + hosts.add(addrs[i].getHostAddress()); + } + } + } + catch(java.net.UnknownHostException ex) + { + Ice.DNSException e = new Ice.DNSException(); + e.host = host; + throw e; + } + + // + // No Inet4Address available. + // + if(hosts.size() == 0) + { + Ice.DNSException e = new Ice.DNSException(); + e.host = host; + throw e; + } + + return hosts; + } + + public static java.util.ArrayList getLocalHosts() { java.util.ArrayList hosts = new java.util.ArrayList(); diff --git a/java/src/IceInternal/TcpEndpointI.java b/java/src/IceInternal/TcpEndpointI.java index 21eb90d067c..e83c38ac416 100644 --- a/java/src/IceInternal/TcpEndpointI.java +++ b/java/src/IceInternal/TcpEndpointI.java @@ -388,8 +388,29 @@ final class TcpEndpointI extends EndpointI } else { - calcHashValue(); - endps.add(this); + if(!server) + { + java.util.ArrayList hosts = Network.getHosts(_host); + if(hosts.size() > 1) + { + java.util.Iterator iter = hosts.iterator(); + while(iter.hasNext()) + { + String host = (String)iter.next(); + endps.add(new TcpEndpointI(_instance, host, _port, _timeout, _connectionId, _compress, true)); + } + } + else + { + calcHashValue(); + endps.add(this); + } + } + else + { + calcHashValue(); + endps.add(this); + } } return endps; } diff --git a/java/src/IceInternal/UdpEndpointI.java b/java/src/IceInternal/UdpEndpointI.java index 6207a0499b8..44f3a01b5c0 100644 --- a/java/src/IceInternal/UdpEndpointI.java +++ b/java/src/IceInternal/UdpEndpointI.java @@ -523,8 +523,29 @@ final class UdpEndpointI extends EndpointI } else { - calcHashValue(); - endps.add(this); + if(!server) + { + java.util.ArrayList hosts = Network.getHosts(_host); + if(hosts.size() > 1) + { + java.util.Iterator iter = hosts.iterator(); + while(iter.hasNext()) + { + String host = (String)iter.next(); + endps.add(new UdpEndpointI(_instance, host, _port, _connect, _connectionId, _compress, true)); + } + } + else + { + calcHashValue(); + endps.add(this); + } + } + else + { + calcHashValue(); + endps.add(this); + } } return endps; } diff --git a/java/ssl/jdk1.4/IceSSL/EndpointI.java b/java/ssl/jdk1.4/IceSSL/EndpointI.java index 40c51386679..e164d10111d 100644 --- a/java/ssl/jdk1.4/IceSSL/EndpointI.java +++ b/java/ssl/jdk1.4/IceSSL/EndpointI.java @@ -388,8 +388,29 @@ final class EndpointI extends IceInternal.EndpointI } else { - calcHashValue(); - endps.add(this); + if(!server) + { + java.util.ArrayList hosts = IceInternal.Network.getHosts(_host); + if(hosts.size() > 1) + { + java.util.Iterator iter = hosts.iterator(); + while(iter.hasNext()) + { + String host = (String)iter.next(); + endps.add(new EndpointI(_instance, host, _port, _timeout, _connectionId, _compress, true)); + } + } + else + { + calcHashValue(); + endps.add(this); + } + } + else + { + calcHashValue(); + endps.add(this); + } } return endps; } diff --git a/java/ssl/jdk1.5/IceSSL/EndpointI.java b/java/ssl/jdk1.5/IceSSL/EndpointI.java index fb640240eff..1153d352f9d 100644 --- a/java/ssl/jdk1.5/IceSSL/EndpointI.java +++ b/java/ssl/jdk1.5/IceSSL/EndpointI.java @@ -388,8 +388,29 @@ final class EndpointI extends IceInternal.EndpointI } else { - calcHashValue(); - endps.add(this); + if(!server) + { + java.util.ArrayList hosts = IceInternal.Network.getHosts(_host); + if(hosts.size() > 1) + { + java.util.Iterator iter = hosts.iterator(); + while(iter.hasNext()) + { + String host = (String)iter.next(); + endps.add(new EndpointI(_instance, host, _port, _timeout, _connectionId, _compress, true)); + } + } + else + { + calcHashValue(); + endps.add(this); + } + } + else + { + calcHashValue(); + endps.add(this); + } } return endps; } |