diff options
author | Benoit Foucher <benoit@zeroc.com> | 2007-12-19 22:06:38 +0100 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2007-12-19 22:06:38 +0100 |
commit | f6121ea342641eb36f7cd67c7c877a1c70ec3055 (patch) | |
tree | b545f3a2548b81fd8dd56a87a58f98b992c0066b /java/src | |
parent | Merge branch 'master' of ssh://cvs.zeroc.com/home/git/ice (diff) | |
download | ice-f6121ea342641eb36f7cd67c7c877a1c70ec3055.tar.bz2 ice-f6121ea342641eb36f7cd67c7c877a1c70ec3055.tar.xz ice-f6121ea342641eb36f7cd67c7c877a1c70ec3055.zip |
- Merge IPv6 support from Dwayne's branch.
- Reviewed and fixed IPv6 bugs.
- Fixed bug in the outgoing connection factory where an assert could be
triggered if the proxy contained identical endpoints
Diffstat (limited to 'java/src')
27 files changed, 542 insertions, 243 deletions
diff --git a/java/src/Ice/ConnectionI.java b/java/src/Ice/ConnectionI.java index 425bdba5d14..e8bf82da12d 100644 --- a/java/src/Ice/ConnectionI.java +++ b/java/src/Ice/ConnectionI.java @@ -1827,12 +1827,9 @@ public final class ConnectionI extends IceInternal.EventHandler unregisterWithPool(); } - if(_state >= StateNotValidated) - { - _transceiver.shutdownWrite(); - } + _transceiver.shutdownWrite(); } - else if(_startCallback == null && _state <= StateNotValidated || _threadPerConnection) + else if(_state <= StateNotValidated || _threadPerConnection) { // // If we are in thread per connection mode and the thread is started, we diff --git a/java/src/Ice/ObjectAdapterI.java b/java/src/Ice/ObjectAdapterI.java index 1b39ac340e6..73dfcea8ba3 100644 --- a/java/src/Ice/ObjectAdapterI.java +++ b/java/src/Ice/ObjectAdapterI.java @@ -932,11 +932,11 @@ public final class ObjectAdapterI implements ObjectAdapter java.util.ArrayList endpoints; if(endpointInfo.length() == 0) { - endpoints = parseEndpoints(properties.getProperty(_name + ".Endpoints")); + endpoints = parseEndpoints(properties.getProperty(_name + ".Endpoints"), true); } else { - endpoints = parseEndpoints(endpointInfo); + endpoints = parseEndpoints(endpointInfo, true); } for(int i = 0; i < endpoints.size(); ++i) { @@ -1103,7 +1103,7 @@ public final class ObjectAdapterI implements ObjectAdapter } private java.util.ArrayList - parseEndpoints(String endpts) + parseEndpoints(String endpts, boolean oaEndpoints) { int beg; int end = 0; @@ -1119,10 +1119,47 @@ public final class ObjectAdapterI implements ObjectAdapter break; } - end = endpts.indexOf(':', beg); - if(end == -1) + end = beg; + while(true) { - end = endpts.length(); + end = endpts.indexOf(':', end); + if(end == -1) + { + end = endpts.length(); + break; + } + else + { + boolean quoted = false; + int quote = beg; + while(true) + { + quote = endpts.indexOf('\"', quote); + if(quote == -1 || end < quote) + { + break; + } + else + { + quote = endpts.indexOf('\"', ++quote); + if(quote == -1) + { + break; + } + else if(end < quote) + { + quoted = true; + break; + } + ++quote; + } + } + if(!quoted) + { + break; + } + ++end; + } } if(end == beg) @@ -1132,7 +1169,7 @@ public final class ObjectAdapterI implements ObjectAdapter } String s = endpts.substring(beg, end); - IceInternal.EndpointI endp = _instance.endpointFactoryManager().create(s, true); + IceInternal.EndpointI endp = _instance.endpointFactoryManager().create(s, oaEndpoints); if(endp == null) { Ice.EndpointParseException e = new Ice.EndpointParseException(); @@ -1155,15 +1192,21 @@ public final class ObjectAdapterI implements ObjectAdapter // instead of the connection factory Endpoints. // String endpts = _instance.initializationData().properties.getProperty(_name + ".PublishedEndpoints"); - java.util.ArrayList endpoints = parseEndpoints(endpts); - if(endpoints.size() == 0) + java.util.ArrayList endpoints = parseEndpoints(endpts, false); + if(!endpoints.isEmpty()) { - for(int i = 0; i < _incomingConnectionFactories.size(); ++i) - { - IceInternal.IncomingConnectionFactory factory = - (IceInternal.IncomingConnectionFactory)_incomingConnectionFactories.get(i); - endpoints.add(factory.endpoint()); - } + return endpoints; + } + + // + // If the PublishedEndpoints property isn't set, we compute the published enpdoints + // from the OA endpoints. + // + for(int i = 0; i < _incomingConnectionFactories.size(); ++i) + { + IceInternal.IncomingConnectionFactory factory = + (IceInternal.IncomingConnectionFactory)_incomingConnectionFactories.get(i); + endpoints.add(factory.endpoint()); } // @@ -1174,9 +1217,7 @@ public final class ObjectAdapterI implements ObjectAdapter java.util.Iterator p = endpoints.iterator(); while(p.hasNext()) { - IceInternal.EndpointI endp = (IceInternal.EndpointI)p.next(); - java.util.List endps = endp.expand(); - expandedEndpoints.addAll(endps); + expandedEndpoints.addAll(((IceInternal.EndpointI)p.next()).expand()); } return expandedEndpoints; } diff --git a/java/src/Ice/SysLoggerI.java b/java/src/Ice/SysLoggerI.java index 2466c80882c..51974c45d02 100644 --- a/java/src/Ice/SysLoggerI.java +++ b/java/src/Ice/SysLoggerI.java @@ -27,7 +27,7 @@ public final class SysLoggerI implements Logger // try { - _host = IceInternal.Network.getLocalAddress(); + _host = IceInternal.Network.getLocalAddress(IceInternal.Network.EnableBoth); _socket = new DatagramSocket(); _socket.connect(_host, _port); } diff --git a/java/src/Ice/Util.java b/java/src/Ice/Util.java index bbe1df80580..ce557ccd558 100644 --- a/java/src/Ice/Util.java +++ b/java/src/Ice/Util.java @@ -277,7 +277,7 @@ public final class Util if(_localAddress == null) { - java.net.InetAddress addr = IceInternal.Network.getLocalAddress(); + java.net.InetAddress addr = IceInternal.Network.getLocalAddress(IceInternal.Network.EnableBoth); byte[] ip = addr.getAddress(); _localAddress = ""; diff --git a/java/src/IceInternal/EndpointFactory.java b/java/src/IceInternal/EndpointFactory.java index 05d05f48e25..2a55a48a32a 100644 --- a/java/src/IceInternal/EndpointFactory.java +++ b/java/src/IceInternal/EndpointFactory.java @@ -13,7 +13,7 @@ public interface EndpointFactory { short type(); String protocol(); - EndpointI create(String str, boolean server); + EndpointI create(String str, boolean oaEndpoint); EndpointI read(BasicStream s); void destroy(); } diff --git a/java/src/IceInternal/EndpointFactoryManager.java b/java/src/IceInternal/EndpointFactoryManager.java index fc772b3f6fe..841d4dd4440 100644 --- a/java/src/IceInternal/EndpointFactoryManager.java +++ b/java/src/IceInternal/EndpointFactoryManager.java @@ -45,7 +45,7 @@ public final class EndpointFactoryManager } public synchronized EndpointI - create(String str, boolean server) + create(String str, boolean oaEndpoint) { String s = str.trim(); if(s.length() == 0) @@ -72,12 +72,12 @@ public final class EndpointFactoryManager EndpointFactory f = (EndpointFactory)_factories.get(i); if(f.protocol().equals(protocol)) { - return f.create(s.substring(m.end()), server); + return f.create(s.substring(m.end()), oaEndpoint); // Code below left in place for debugging. /* - EndpointI e = f.create(s.substring(m.end()), server); + EndpointI e = f.create(s.substring(m.end()), oaEndpoint); BasicStream bs = new BasicStream(_instance, true); e.streamWrite(bs); java.nio.ByteBuffer buf = bs.getBuffer(); diff --git a/java/src/IceInternal/EndpointHostResolver.java b/java/src/IceInternal/EndpointHostResolver.java index 4ef6d756e0f..85319c347a5 100644 --- a/java/src/IceInternal/EndpointHostResolver.java +++ b/java/src/IceInternal/EndpointHostResolver.java @@ -89,7 +89,8 @@ public class EndpointHostResolver resolve = (ResolveEntry)_queue.removeFirst(); } - resolve.callback.connectors(resolve.endpoint.connectors(Network.getAddresses(resolve.host, resolve.port))); + resolve.callback.connectors(resolve.endpoint.connectors( + Network.getAddresses(resolve.host, resolve.port, _instance.protocolSupport()))); } java.util.Iterator p = _queue.iterator(); diff --git a/java/src/IceInternal/EndpointI.java b/java/src/IceInternal/EndpointI.java index 3be504cada4..70f93e43ab0 100644 --- a/java/src/IceInternal/EndpointI.java +++ b/java/src/IceInternal/EndpointI.java @@ -100,7 +100,7 @@ abstract public class EndpointI implements Ice.Endpoint, java.lang.Comparable // // Expand endpoint out in to separate endpoints for each local - // host if listening on INADDR_NAY. + // host if listening on INADDR_ANY. // public abstract java.util.List expand(); diff --git a/java/src/IceInternal/Instance.java b/java/src/IceInternal/Instance.java index aea0de5b8e7..34bd6363a79 100644 --- a/java/src/IceInternal/Instance.java +++ b/java/src/IceInternal/Instance.java @@ -125,6 +125,17 @@ public final class Instance return _objectAdapterFactory; } + public synchronized int + protocolSupport() + { + if(_state == StateDestroyed) + { + throw new Ice.CommunicatorDestroyedException(); + } + + return _protocolSupport; + } + public synchronized ThreadPool clientThreadPool() { @@ -646,6 +657,24 @@ public final class Instance _proxyFactory = new ProxyFactory(this); + boolean ipv4 = _initData.properties.getPropertyAsIntWithDefault("Ice.IPv4", 1) > 0; + boolean ipv6 = _initData.properties.getPropertyAsIntWithDefault("Ice.IPv6", 0) > 0; + if(!ipv4 && !ipv6) + { + throw new Ice.InitializationException("Both IPV4 and IPv6 support cannot be disabled."); + } + else if(ipv4 && ipv6) + { + _protocolSupport = Network.EnableBoth; + } + else if(ipv4) + { + _protocolSupport = Network.EnableIPv4; + } + else + { + _protocolSupport = Network.EnableIPv6; + } _endpointFactoryManager = new EndpointFactoryManager(this); EndpointFactory tcpEndpointFactory = new TcpEndpointFactory(this); _endpointFactoryManager.add(tcpEndpointFactory); @@ -998,6 +1027,7 @@ public final class Instance private ConnectionMonitor _connectionMonitor; private ObjectFactoryManager _servantFactoryManager; private ObjectAdapterFactory _objectAdapterFactory; + private int _protocolSupport; private ThreadPool _clientThreadPool; private ThreadPool _serverThreadPool; private SelectorThread _selectorThread; diff --git a/java/src/IceInternal/Network.java b/java/src/IceInternal/Network.java index 5971e1122d5..a74fae2846e 100644 --- a/java/src/IceInternal/Network.java +++ b/java/src/IceInternal/Network.java @@ -11,6 +11,11 @@ package IceInternal; public final class Network { + // ProtocolSupport + public final static int EnableIPv4 = 0; + public final static int EnableIPv6 = 1; + public final static int EnableBoth = 2; + public static boolean connectionLost(java.io.IOException ex) { @@ -748,32 +753,15 @@ public final class Network } public static java.net.InetSocketAddress - getAddress(String host, int port) + getAddress(String host, int port, int protocol) { - 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) - { - return new java.net.InetSocketAddress(addrs[i], port); - } - } - } - catch(java.net.UnknownHostException ex) - { - Ice.DNSException e = new Ice.DNSException(); - e.host = host; - throw e; - } + return getAddressImpl(host, port, protocol, false); + } - // - // No Inet4Address available. - // - Ice.DNSException e = new Ice.DNSException(); - e.host = host; - throw e; + public static java.net.InetSocketAddress + getAddressForServer(String host, int port, int protocol) + { + return getAddressImpl(host, port, protocol, true); } public static int @@ -790,7 +778,16 @@ public final class Network byte[] larr = addr1.getAddress().getAddress(); byte[] rarr = addr2.getAddress().getAddress(); + if(larr.length < rarr.length) + { + return -1; + } + else if(rarr.length < larr.length) + { + return 1; + } assert(larr.length == rarr.length); + for(int i = 0; i < larr.length; i++) { if(larr[i] < rarr[i]) @@ -807,7 +804,7 @@ public final class Network } public static java.net.InetAddress - getLocalAddress() + getLocalAddress(int protocol) { java.net.InetAddress addr = null; @@ -828,31 +825,30 @@ public final class Network // } - if(addr == null || addr instanceof java.net.Inet6Address) + if(addr == null || + (addr instanceof java.net.Inet4Address && protocol == EnableIPv6) || + (addr instanceof java.net.Inet6Address && protocol == EnableIPv4)) { // // Iterate over the network interfaces and pick an IP // address (preferably not the loopback address). // - java.net.InetAddress loopback = null; - java.util.ArrayList addrs = getLocalAddresses(); + java.util.ArrayList addrs = getLocalAddresses(protocol); java.util.Iterator iter = addrs.iterator(); while(addr == null && iter.hasNext()) { java.net.InetAddress a = (java.net.InetAddress)iter.next(); - if(!a.isLoopbackAddress()) + if(protocol == EnableBoth || + (protocol == EnableIPv4 && a instanceof java.net.Inet4Address) || + (protocol == EnableIPv6 && a instanceof java.net.Inet6Address)) { addr = a; } - else - { - loopback = a; - } } if(addr == null) { - addr = loopback; // Use the loopback address as the last resort. + addr = getLoopbackAddresses(protocol)[0]; // Use the loopback address as the last resort. } } @@ -861,70 +857,55 @@ public final class Network } public static java.util.ArrayList - getAddresses(String host, int port) + getAddresses(String host, int port, int protocol) { java.util.ArrayList addresses = new java.util.ArrayList(); - if(host.equals("0.0.0.0")) - { - java.util.ArrayList hosts = getLocalHosts(); - java.util.Iterator p = hosts.iterator(); - while(p.hasNext()) - { - addresses.add(getAddress((String)p.next(), port)); - } - } - else + try { - try + java.net.InetAddress[] addrs; + if(host == null || host.length() == 0) { - java.net.InetAddress[] addrs = java.net.InetAddress.getAllByName(host); - for(int i = 0; i < addrs.length; ++i) - { - if(addrs[i] instanceof java.net.Inet4Address) - { - addresses.add(new java.net.InetSocketAddress(addrs[i], port)); - } - } + addrs = getLoopbackAddresses(protocol); } - catch(java.net.UnknownHostException ex) + else { - Ice.DNSException e = new Ice.DNSException(); - e.host = host; - throw e; + addrs = java.net.InetAddress.getAllByName(host); } - // - // No Inet4Address available. - // - if(addresses.size() == 0) + for(int i = 0; i < addrs.length; ++i) { - Ice.DNSException e = new Ice.DNSException(); - e.host = host; - throw e; + if(protocol == EnableBoth || + (protocol == EnableIPv4 && addrs[i] instanceof java.net.Inet4Address) || + (protocol == EnableIPv6 && addrs[i] instanceof java.net.Inet6Address)) + { + addresses.add(new java.net.InetSocketAddress(addrs[i], port)); + } } } - - return addresses; - } - - public static java.util.ArrayList - getLocalHosts() - { - java.util.ArrayList hosts = new java.util.ArrayList(); - java.util.ArrayList addrs = getLocalAddresses(); - java.util.Iterator iter = addrs.iterator(); - while(iter.hasNext()) + catch(java.net.UnknownHostException ex) + { + Ice.DNSException e = new Ice.DNSException(); + e.host = host; + throw e; + } + + // + // No Inet4Address/Inet6Address available. + // + if(addresses.size() == 0) { - hosts.add(((java.net.InetAddress)iter.next()).getHostAddress()); + Ice.DNSException e = new Ice.DNSException(); + e.host = host; + throw e; } - return hosts; + + return addresses; } public static java.util.ArrayList - getLocalAddresses() + getLocalAddresses(int protocol) { java.util.ArrayList result = new java.util.ArrayList(); - try { java.util.Enumeration ifaces = java.net.NetworkInterface.getNetworkInterfaces(); @@ -935,9 +916,14 @@ public final class Network while(addrs.hasMoreElements()) { java.net.InetAddress addr = (java.net.InetAddress)addrs.nextElement(); - if(addr instanceof java.net.Inet4Address) + if(!addr.isLoopbackAddress()) { - result.add(addr); + if(protocol == EnableBoth || + (protocol == EnableIPv4 && addr instanceof java.net.Inet4Address) || + (protocol == EnableIPv6 && addr instanceof java.net.Inet6Address)) + { + result.add(addr); + } } } } @@ -1016,6 +1002,55 @@ public final class Network return fds; } + + public static java.util.ArrayList + getHostsForEndpointExpand(String host, int protocolSupport) + { + boolean wildcard = (host == null || host.length() == 0); + if(!wildcard) + { + try + { + wildcard = java.net.InetAddress.getByName(host).isAnyLocalAddress(); + } + catch(java.net.UnknownHostException ex) + { + } + } + + java.util.ArrayList hosts = new java.util.ArrayList(); + if(wildcard) + { + java.util.ArrayList addrs = getLocalAddresses(protocolSupport); + java.util.Iterator p = addrs.iterator(); + while(p.hasNext()) + { + // + // NOTE: We don't publish link-local IPv6 addresses as these addresses can only + // be accessed in general with a scope-id. + // + java.net.InetAddress addr = (java.net.InetAddress)p.next(); + if(!addr.isLinkLocalAddress()) + { + hosts.add(addr.getHostAddress()); + } + } + + if(hosts.isEmpty()) + { + if(protocolSupport != EnableIPv6) + { + hosts.add("127.0.0.1"); + } + + if(protocolSupport != EnableIPv4) + { + hosts.add("0:0:0:0:0:0:0:1"); + } + } + } + return hosts; + } public static void setTcpBufSize(java.nio.channels.SocketChannel socket, Ice.Properties properties, Ice.Logger logger) @@ -1187,4 +1222,99 @@ public final class Network ex.getMessage().indexOf("Interrupted system call") >= 0 || ex.getMessage().indexOf("A system call received an interrupt") >= 0; // AIX JDK 1.4.2 } + + private static java.net.InetSocketAddress + getAddressImpl(String host, int port, int protocol, boolean server) + { + try + { + java.net.InetAddress[] addrs; + if(host == null || host.length() == 0) + { + if(server) + { + addrs = getWildcardAddresses(protocol); + } + else + { + addrs = getLoopbackAddresses(protocol); + } + } + else + { + addrs = java.net.InetAddress.getAllByName(host); + } + + for(int i = 0; i < addrs.length; ++i) + { + if(protocol == EnableBoth || + (protocol == EnableIPv4 && addrs[i] instanceof java.net.Inet4Address) || + (protocol == EnableIPv6 && addrs[i] instanceof java.net.Inet6Address)) + { + return new java.net.InetSocketAddress(addrs[i], port); + } + } + } + catch(java.net.UnknownHostException ex) + { + Ice.DNSException e = new Ice.DNSException(); + e.host = host; + throw e; + } + + // + // No Inet4Address/Inet6Address available. + // + Ice.DNSException e = new Ice.DNSException(); + e.host = host; + throw e; + } + + private static java.net.InetAddress[] + getLoopbackAddresses(int protocol) + { + try + { + java.net.InetAddress[] addrs = new java.net.InetAddress[protocol == EnableBoth ? 2 : 1]; + int i = 0; + if(protocol != EnableIPv6) + { + addrs[i++] = java.net.InetAddress.getByName("127.0.0.1"); + } + if(protocol != EnableIPv4) + { + addrs[i++] = java.net.InetAddress.getByName("::1"); + } + return addrs; + } + catch(java.net.UnknownHostException ex) + { + assert(false); + return null; + } + } + + private static java.net.InetAddress[] + getWildcardAddresses(int protocol) + { + try + { + java.net.InetAddress[] addrs = new java.net.InetAddress[protocol == EnableBoth ? 2 : 1]; + int i = 0; + if(protocol != EnableIPv4) + { + addrs[i++] = java.net.InetAddress.getByName("::0"); + } + if(protocol != EnableIPv6) + { + addrs[i++] = java.net.InetAddress.getByName("0.0.0.0"); + } + return addrs; + } + catch(java.net.UnknownHostException ex) + { + assert(false); + return null; + } + } } diff --git a/java/src/IceInternal/OutgoingConnectionFactory.java b/java/src/IceInternal/OutgoingConnectionFactory.java index 107ec4986a7..c94b50c5b86 100644 --- a/java/src/IceInternal/OutgoingConnectionFactory.java +++ b/java/src/IceInternal/OutgoingConnectionFactory.java @@ -738,12 +738,16 @@ public final class OutgoingConnectionFactory // // No connection to any of our endpoints exists yet; we add the given connectors to // the _pending set to indicate that we're attempting connection establishment to - // these connectors. + // these connectors. We might attempt to connect to the same connector multiple times. // p = connectors.iterator(); while(p.hasNext()) { - _pending.put(p.next(), new java.util.HashSet()); + Object obj = p.next(); + if(!_pending.containsKey(obj)) + { + _pending.put(obj, new java.util.HashSet()); + } } } @@ -820,7 +824,11 @@ public final class OutgoingConnectionFactory java.util.Iterator p = connectors.iterator(); while(p.hasNext()) { - callbacks.addAll((java.util.Set)_pending.remove(p.next())); + java.util.Set cbs = (java.util.Set)_pending.remove(p.next()); + if(cbs != null) + { + callbacks.addAll(cbs); + } } notifyAll(); diff --git a/java/src/IceInternal/PropertyNames.java b/java/src/IceInternal/PropertyNames.java index f2875dea766..2bdb69b07e5 100644 --- a/java/src/IceInternal/PropertyNames.java +++ b/java/src/IceInternal/PropertyNames.java @@ -68,7 +68,8 @@ public final class PropertyNames new Property("Ice\\.Default\\.Router\\.CollocationOptimized", false, null), new Property("Ice\\.Default\\.Router\\.ThreadPerConnection", false, null), new Property("Ice\\.Default\\.Router", false, null), - new Property("Ice\\.EventLog\\.Source", false, null), + new Property("Ice\\.IPv4", false, null), + new Property("Ice\\.IPv6", false, null), new Property("Ice\\.GC\\.Interval", false, null), new Property("Ice\\.ImplicitContext", false, null), new Property("Ice\\.InitPlugins", false, null), diff --git a/java/src/IceInternal/ProtocolPluginFacade.java b/java/src/IceInternal/ProtocolPluginFacade.java index 8423491d10f..3e4cc9f66e4 100644 --- a/java/src/IceInternal/ProtocolPluginFacade.java +++ b/java/src/IceInternal/ProtocolPluginFacade.java @@ -23,6 +23,11 @@ public interface ProtocolPluginFacade IceInternal.EndpointHostResolver getEndpointHostResolver(); // + // Get the protocol support. + // + int getProtocolSupport(); + + // // Get the default hostname to be used in endpoints. // String getDefaultHost(); diff --git a/java/src/IceInternal/ProtocolPluginFacadeI.java b/java/src/IceInternal/ProtocolPluginFacadeI.java index 1dacd623499..a87791f1053 100644 --- a/java/src/IceInternal/ProtocolPluginFacadeI.java +++ b/java/src/IceInternal/ProtocolPluginFacadeI.java @@ -38,6 +38,14 @@ public class ProtocolPluginFacadeI implements ProtocolPluginFacade } // + // Get the protocol support. + // + public int + getProtocolSupport() + { + return _instance.protocolSupport(); + } + // // Get the default hostname to be used in endpoints. // public String diff --git a/java/src/IceInternal/ReferenceFactory.java b/java/src/IceInternal/ReferenceFactory.java index 37f24e64c56..d8a7bd2e5ec 100644 --- a/java/src/IceInternal/ReferenceFactory.java +++ b/java/src/IceInternal/ReferenceFactory.java @@ -418,10 +418,47 @@ public final class ReferenceFactory { beg = end + 1; - end = s.indexOf(':', beg); - if(end == -1) + end = beg; + while(true) { - end = s.length(); + end = s.indexOf(':', end); + if(end == -1) + { + end = s.length(); + break; + } + else + { + boolean quoted = false; + int quote = beg; + while(true) + { + quote = s.indexOf('\"', quote); + if(quote == -1 || end < quote) + { + break; + } + else + { + quote = s.indexOf('\"', ++quote); + if(quote == -1) + { + break; + } + else if(end < quote) + { + quoted = true; + break; + } + ++quote; + } + } + if(!quoted) + { + break; + } + ++end; + } } String es = s.substring(beg, end); diff --git a/java/src/IceInternal/TcpAcceptor.java b/java/src/IceInternal/TcpAcceptor.java index 72eaec50cf9..95d16d6bd90 100644 --- a/java/src/IceInternal/TcpAcceptor.java +++ b/java/src/IceInternal/TcpAcceptor.java @@ -218,7 +218,7 @@ class TcpAcceptor implements Acceptor // Network.setReuseAddress(_fd, true); } - _addr = new java.net.InetSocketAddress(host, port); + _addr = Network.getAddressForServer(host, port, _instance.protocolSupport()); if(_traceLevels.network >= 2) { String s = "attempting to bind to tcp socket " + toString(); diff --git a/java/src/IceInternal/TcpEndpointFactory.java b/java/src/IceInternal/TcpEndpointFactory.java index 7fb5572e391..1bc9e326d66 100644 --- a/java/src/IceInternal/TcpEndpointFactory.java +++ b/java/src/IceInternal/TcpEndpointFactory.java @@ -29,9 +29,9 @@ final class TcpEndpointFactory implements EndpointFactory } public EndpointI - create(String str, boolean server) + create(String str, boolean oaEndpoint) { - return new TcpEndpointI(_instance, str, server); + return new TcpEndpointI(_instance, str, oaEndpoint); } public EndpointI diff --git a/java/src/IceInternal/TcpEndpointI.java b/java/src/IceInternal/TcpEndpointI.java index e4a62706b19..5c6fb7dfbfc 100644 --- a/java/src/IceInternal/TcpEndpointI.java +++ b/java/src/IceInternal/TcpEndpointI.java @@ -26,7 +26,7 @@ final class TcpEndpointI extends EndpointI } public - TcpEndpointI(Instance instance, String str, boolean server) + TcpEndpointI(Instance instance, String str, boolean oaEndpoint) { _instance = instance; _host = null; @@ -55,6 +55,10 @@ final class TcpEndpointI extends EndpointI if(i < arr.length && arr[i].charAt(0) != '-') { argument = arr[i++]; + if(argument.charAt(0) == '\"' && argument.charAt(argument.length() - 1) == '\"') + { + argument = argument.substring(1, argument.length() - 1); + } } switch(option.charAt(1)) @@ -134,22 +138,24 @@ final class TcpEndpointI extends EndpointI if(_host == null) { _host = _instance.defaultsAndOverrides().defaultHost; - if(_host == null) + } + else if(_host.equals("*")) + { + if(oaEndpoint) { - if(server) - { - _host = "0.0.0.0"; - } - else - { - _host = "127.0.0.1"; - } + _host = null; + } + else + { + throw new Ice.EndpointParseException("tcp " + str); } } - else if(_host.equals("*")) + + if(_host == null) { - _host = "0.0.0.0"; + _host = ""; } + calcHashValue(); } @@ -194,7 +200,25 @@ final class TcpEndpointI extends EndpointI // these features. Please review for all features that depend on the // format of proxyToString() before changing this and related code. // - String s = "tcp -h " + _host + " -p " + _port; + String s = "tcp"; + + if(_host != null && _host.length() > 0) + { + s += " -h "; + boolean addQuote = _host.indexOf(':') != -1; + if(addQuote) + { + s += "\""; + } + s += _host; + if(addQuote) + { + s += "\""; + } + } + + s += " -p " + _port; + if(_timeout != -1) { s += " -t " + _timeout; @@ -335,7 +359,7 @@ final class TcpEndpointI extends EndpointI public java.util.List connectors() { - return connectors(Network.getAddresses(_host, _port)); + return connectors(Network.getAddresses(_host, _port, _instance.protocolSupport())); } public void @@ -355,7 +379,8 @@ final class TcpEndpointI extends EndpointI acceptor(EndpointIHolder endpoint, String adapterName) { TcpAcceptor p = new TcpAcceptor(_instance, _host, _port); - endpoint.value = new TcpEndpointI(_instance, _host, p.effectivePort(), _timeout, _connectionId, _compress); + endpoint.value = + new TcpEndpointI(_instance, _host, p.effectivePort(), _timeout, _connectionId, _compress); return p; } @@ -367,22 +392,18 @@ final class TcpEndpointI extends EndpointI expand() { java.util.ArrayList endps = new java.util.ArrayList(); - if(_host.equals("0.0.0.0")) + java.util.ArrayList hosts = Network.getHostsForEndpointExpand(_host, _instance.protocolSupport()); + if(hosts == null || hosts.isEmpty()) { - java.util.ArrayList hosts = Network.getLocalHosts(); - java.util.Iterator iter = hosts.iterator(); - while(iter.hasNext()) - { - String host = (String)iter.next(); - if(hosts.size() == 1 || !host.equals("127.0.0.1")) - { - endps.add(new TcpEndpointI(_instance, host, _port, _timeout, _connectionId, _compress)); - } - } + endps.add(this); } else { - endps.add(this); + java.util.Iterator p = hosts.iterator(); + while(p.hasNext()) + { + endps.add(new TcpEndpointI(_instance, (String)p.next(), _port, _timeout, _connectionId, _compress)); + } } return endps; } @@ -497,15 +518,7 @@ final class TcpEndpointI extends EndpointI private void calcHashValue() { - try - { - java.net.InetSocketAddress addr = Network.getAddress(_host, _port); - _hashCode = addr.getAddress().getHostAddress().hashCode(); - } - catch(Ice.DNSException ex) - { - _hashCode = _host.hashCode(); - } + _hashCode = _host.hashCode(); _hashCode = 5 * _hashCode + _port; _hashCode = 5 * _hashCode + _timeout; _hashCode = 5 * _hashCode + _connectionId.hashCode(); diff --git a/java/src/IceInternal/ThreadPool.java b/java/src/IceInternal/ThreadPool.java index 2ba09235fec..cfdfc734bff 100644 --- a/java/src/IceInternal/ThreadPool.java +++ b/java/src/IceInternal/ThreadPool.java @@ -145,7 +145,6 @@ public final class ThreadPool assert(!_destroyed); assert(_handlerMap.isEmpty()); - assert(_workItems.isEmpty()); _destroyed = true; setInterrupt(); } diff --git a/java/src/IceInternal/UdpEndpointFactory.java b/java/src/IceInternal/UdpEndpointFactory.java index 767f803b17c..76a98188408 100644 --- a/java/src/IceInternal/UdpEndpointFactory.java +++ b/java/src/IceInternal/UdpEndpointFactory.java @@ -29,9 +29,9 @@ final class UdpEndpointFactory implements EndpointFactory } public EndpointI - create(String str, boolean server) + create(String str, boolean oaEndpoint) { - return new UdpEndpointI(_instance, str, server); + return new UdpEndpointI(_instance, str, oaEndpoint); } public EndpointI diff --git a/java/src/IceInternal/UdpEndpointI.java b/java/src/IceInternal/UdpEndpointI.java index 190fdf061c2..a038a2a50ca 100644 --- a/java/src/IceInternal/UdpEndpointI.java +++ b/java/src/IceInternal/UdpEndpointI.java @@ -33,7 +33,7 @@ final class UdpEndpointI extends EndpointI } public - UdpEndpointI(Instance instance, String str, boolean server) + UdpEndpointI(Instance instance, String str, boolean oaEndpoint) { _instance = instance; _host = null; @@ -66,6 +66,10 @@ final class UdpEndpointI extends EndpointI if(i < arr.length && arr[i].charAt(0) != '-') { argument = arr[i++]; + if(argument.charAt(0) == '\"' && argument.charAt(argument.length() - 1) == '\"') + { + argument = argument.substring(1, argument.length() - 1); + } } if(option.equals("-v")) @@ -247,22 +251,24 @@ final class UdpEndpointI extends EndpointI if(_host == null) { _host = _instance.defaultsAndOverrides().defaultHost; - if(_host == null) + } + else if(_host.equals("*")) + { + if(oaEndpoint) { - if(server) - { - _host = "0.0.0.0"; - } - else - { - _host = "127.0.0.1"; - } + _host = null; + } + else + { + throw new Ice.EndpointParseException("udp " + str); } } - else if(_host.equals("*")) + + if(_host == null) { - _host = "0.0.0.0"; + _host = ""; } + calcHashValue(); } @@ -350,7 +356,22 @@ final class UdpEndpointI extends EndpointI + "." + (_encodingMinor < 0 ? (int)_encodingMinor + 255 : _encodingMinor); } - s += " -h " + _host + " -p " + _port; + if(_host != null && _host.length() > 0) + { + s += " -h "; + boolean addQuote = _host.indexOf(':') != -1; + if(addQuote) + { + s += "\""; + } + s += _host; + if(addQuote) + { + s += "\""; + } + } + + s += " -p " + _port; if(_mcastInterface.length() != 0) { @@ -504,7 +525,7 @@ final class UdpEndpointI extends EndpointI public java.util.List connectors() { - return connectors(Network.getAddresses(_host, _port)); + return connectors(Network.getAddresses(_host, _port, _instance.protocolSupport())); } public void @@ -535,24 +556,20 @@ final class UdpEndpointI extends EndpointI expand() { java.util.ArrayList endps = new java.util.ArrayList(); - if(_host.equals("0.0.0.0")) + java.util.ArrayList hosts = Network.getHostsForEndpointExpand(_host, _instance.protocolSupport()); + if(hosts == null || hosts.isEmpty()) { - java.util.ArrayList hosts = Network.getLocalHosts(); - java.util.Iterator iter = hosts.iterator(); - while(iter.hasNext()) - { - String host = (String)iter.next(); - if(hosts.size() == 1 || !host.equals("127.0.0.1")) - { - endps.add(new UdpEndpointI(_instance, host, _port, _mcastInterface, _mcastTtl, _protocolMajor, - _protocolMinor, _encodingMajor, _encodingMinor, _connect, - _connectionId, _compress)); - } - } + endps.add(this); } else { - endps.add(this); + java.util.Iterator p = hosts.iterator(); + while(p.hasNext()) + { + endps.add(new UdpEndpointI(_instance, (String)p.next(), _port, _mcastInterface, _mcastTtl, + _protocolMajor, _protocolMinor, _encodingMajor, _encodingMinor, + _connect, _connectionId, _compress)); + } } return endps; } @@ -572,6 +589,7 @@ final class UdpEndpointI extends EndpointI { return false; } + return udpEndpointI._host.equals(_host) && udpEndpointI._port == _port; } @@ -720,15 +738,7 @@ final class UdpEndpointI extends EndpointI private void calcHashValue() { - try - { - java.net.InetSocketAddress addr = Network.getAddress(_host, _port); - _hashCode = addr.getAddress().getHostAddress().hashCode(); - } - catch(Ice.DNSException ex) - { - _hashCode = _host.hashCode(); - } + _hashCode = _host.hashCode(); _hashCode = 5 * _hashCode + _port; _hashCode = 5 * _hashCode + _mcastInterface.hashCode(); _hashCode = 5 * _hashCode + _mcastTtl; diff --git a/java/src/IceInternal/UdpTransceiver.java b/java/src/IceInternal/UdpTransceiver.java index cebd0876374..91c85cb4408 100644 --- a/java/src/IceInternal/UdpTransceiver.java +++ b/java/src/IceInternal/UdpTransceiver.java @@ -437,7 +437,7 @@ final class UdpTransceiver implements Transceiver _fd = Network.createUdpSocket(); setBufSize(instance); Network.setBlock(_fd, false); - _addr = new java.net.InetSocketAddress(host, port); + _addr = Network.getAddressForServer(host, port, instance.protocolSupport()); if(_traceLevels.network >= 2) { String s = "attempting to bind to udp socket " + Network.addrToString(_addr); @@ -446,7 +446,7 @@ final class UdpTransceiver implements Transceiver if(_addr.getAddress().isMulticastAddress()) { Network.setReuseAddress(_fd, true); - Network.doBind(_fd, Network.getAddress("0.0.0.0", port)); + Network.doBind(_fd, Network.getAddress("0.0.0.0", port, Network.EnableIPv4)); configureMulticast(_addr, mcastInterface, -1); mcastServer = true; } @@ -585,7 +585,7 @@ final class UdpTransceiver implements Transceiver intf = java.net.NetworkInterface.getByName(interfaceAddr); if(intf == null) { - java.net.InetSocketAddress addr = Network.getAddress(interfaceAddr, 0); + java.net.InetSocketAddress addr = Network.getAddress(interfaceAddr, 0, Network.EnableIPv4); intf = java.net.NetworkInterface.getByInetAddress(addr.getAddress()); } } diff --git a/java/src/IceInternal/UnknownEndpointI.java b/java/src/IceInternal/UnknownEndpointI.java index 638a81b52e9..9b91786e0c1 100644 --- a/java/src/IceInternal/UnknownEndpointI.java +++ b/java/src/IceInternal/UnknownEndpointI.java @@ -266,7 +266,8 @@ final class UnknownEndpointI extends EndpointI // // Expand endpoint out in to separate endpoints for each local - // host if listening on INADDR_ANY. + // host if listening on INADDR_ANY on server side or if no host + // was specified on client side. // public java.util.List expand() diff --git a/java/src/IceSSL/AcceptorI.java b/java/src/IceSSL/AcceptorI.java index 3d1ea382f35..05e1e7d50cb 100644 --- a/java/src/IceSSL/AcceptorI.java +++ b/java/src/IceSSL/AcceptorI.java @@ -233,7 +233,7 @@ final class AcceptorI implements IceInternal.Acceptor // IceInternal.Network.setReuseAddress(_fd, true); } - _addr = new java.net.InetSocketAddress(host, port); + _addr = IceInternal.Network.getAddressForServer(host, port, _instance.protocolSupport()); if(_instance.networkTraceLevel() >= 2) { String s = "attempting to bind to ssl socket " + toString(); diff --git a/java/src/IceSSL/EndpointFactoryI.java b/java/src/IceSSL/EndpointFactoryI.java index 41f1d1eb12c..9b8cc99309e 100644 --- a/java/src/IceSSL/EndpointFactoryI.java +++ b/java/src/IceSSL/EndpointFactoryI.java @@ -29,9 +29,9 @@ final class EndpointFactoryI implements IceInternal.EndpointFactory } public IceInternal.EndpointI - create(String str, boolean server) + create(String str, boolean oaEndpoint) { - return new EndpointI(_instance, str, server); + return new EndpointI(_instance, str, oaEndpoint); } public IceInternal.EndpointI diff --git a/java/src/IceSSL/EndpointI.java b/java/src/IceSSL/EndpointI.java index 84a94885599..76381474dfa 100644 --- a/java/src/IceSSL/EndpointI.java +++ b/java/src/IceSSL/EndpointI.java @@ -26,7 +26,7 @@ final class EndpointI extends IceInternal.EndpointI } public - EndpointI(Instance instance, String str, boolean server) + EndpointI(Instance instance, String str, boolean oaEndpoint) { _instance = instance; _host = null; @@ -55,6 +55,10 @@ final class EndpointI extends IceInternal.EndpointI if(i < arr.length && arr[i].charAt(0) != '-') { argument = arr[i++]; + if(argument.charAt(0) == '\"' && argument.charAt(argument.length() - 1) == '\"') + { + argument = argument.substring(1, argument.length() - 1); + } } switch(option.charAt(1)) @@ -134,22 +138,24 @@ final class EndpointI extends IceInternal.EndpointI if(_host == null) { _host = _instance.defaultHost(); - if(_host == null) + } + else if(_host.equals("*")) + { + if(oaEndpoint) { - if(server) - { - _host = "0.0.0.0"; - } - else - { - _host = "127.0.0.1"; - } + _host = null; + } + else + { + throw new Ice.EndpointParseException("ssl " + str); } } - else if(_host.equals("*")) + + if(_host == null) { - _host = "0.0.0.0"; + _host = ""; } + calcHashValue(); } @@ -194,7 +200,25 @@ final class EndpointI extends IceInternal.EndpointI // these features. Please review for all features that depend on the // format of proxyToString() before changing this and related code. // - String s = "ssl -h " + _host + " -p " + _port; + String s = "ssl"; + + if(_host != null && _host.length() > 0) + { + s += " -h "; + boolean addQuote = _host.indexOf(':') != -1; + if(addQuote) + { + s += "\""; + } + s += _host; + if(addQuote) + { + s += "\""; + } + } + + s += " -p " + _port; + if(_timeout != -1) { s += " -t " + _timeout; @@ -335,7 +359,7 @@ final class EndpointI extends IceInternal.EndpointI public java.util.List connectors() { - return connectors(IceInternal.Network.getAddresses(_host, _port)); + return connectors(IceInternal.Network.getAddresses(_host, _port, _instance.protocolSupport())); } public void @@ -355,7 +379,8 @@ final class EndpointI extends IceInternal.EndpointI acceptor(IceInternal.EndpointIHolder endpoint, String adapterName) { AcceptorI p = new AcceptorI(_instance, adapterName, _host, _port); - endpoint.value = new EndpointI(_instance, _host, p.effectivePort(), _timeout, _connectionId, _compress); + endpoint.value = + new EndpointI(_instance, _host, p.effectivePort(), _timeout, _connectionId, _compress); return p; } @@ -367,23 +392,18 @@ final class EndpointI extends IceInternal.EndpointI expand() { java.util.ArrayList endps = new java.util.ArrayList(); - if(_host.equals("0.0.0.0")) + java.util.ArrayList hosts = IceInternal.Network.getHostsForEndpointExpand(_host, _instance.protocolSupport()); + if(hosts == null || hosts.isEmpty()) { - java.util.ArrayList hosts = IceInternal.Network.getLocalHosts(); - java.util.Iterator iter = hosts.iterator(); - while(iter.hasNext()) - { - String host = (String)iter.next(); - if(hosts.size() == 1 || !host.equals("127.0.0.1")) - { - endps.add(new EndpointI(_instance, host, _port, _timeout, _connectionId, _compress)); - - } - } + endps.add(this); } else { - endps.add(this); + java.util.Iterator p = hosts.iterator(); + while(p.hasNext()) + { + endps.add(new EndpointI(_instance, (String)p.next(), _port, _timeout, _connectionId, _compress)); + } } return endps; } @@ -498,15 +518,7 @@ final class EndpointI extends IceInternal.EndpointI private void calcHashValue() { - try - { - java.net.InetSocketAddress addr = IceInternal.Network.getAddress(_host, _port); - _hashCode = addr.getAddress().getHostAddress().hashCode(); - } - catch(Ice.DNSException ex) - { - _hashCode = _host.hashCode(); - } + _hashCode = _host.hashCode(); _hashCode = 5 * _hashCode + _port; _hashCode = 5 * _hashCode + _timeout; _hashCode = 5 * _hashCode + _connectionId.hashCode(); diff --git a/java/src/IceSSL/Instance.java b/java/src/IceSSL/Instance.java index 9d0251c5c13..861ed1f7c70 100644 --- a/java/src/IceSSL/Instance.java +++ b/java/src/IceSSL/Instance.java @@ -513,6 +513,12 @@ class Instance return _facade.getEndpointHostResolver(); } + int + protocolSupport() + { + return _facade.getProtocolSupport(); + } + String defaultHost() { |