diff options
author | Benoit Foucher <benoit@zeroc.com> | 2017-04-10 19:33:17 +0200 |
---|---|---|
committer | Benoit Foucher <benoit@zeroc.com> | 2017-04-10 19:33:17 +0200 |
commit | 1fa97b799b91fa6b0842e3267fec3d6e3a240df5 (patch) | |
tree | 1bc3abfddbcb66b51c776da15e2d88586ca2bbf4 /java-compat/src | |
parent | Fix (ICE-7771) - UWP build fails, missing targets file (diff) | |
download | ice-1fa97b799b91fa6b0842e3267fec3d6e3a240df5.tar.bz2 ice-1fa97b799b91fa6b0842e3267fec3d6e3a240df5.tar.xz ice-1fa97b799b91fa6b0842e3267fec3d6e3a240df5.zip |
Fixed ICE-7755 - listen on all IPs associated with a DNS name
Diffstat (limited to 'java-compat/src')
8 files changed, 158 insertions, 18 deletions
diff --git a/java-compat/src/Ice/src/main/java/Ice/ObjectAdapterI.java b/java-compat/src/Ice/src/main/java/Ice/ObjectAdapterI.java index 4b677da2c96..2e817cf9bff 100644 --- a/java-compat/src/Ice/src/main/java/Ice/ObjectAdapterI.java +++ b/java-compat/src/Ice/src/main/java/Ice/ObjectAdapterI.java @@ -755,7 +755,7 @@ public final class ObjectAdapterI implements ObjectAdapter } for(IncomingConnectionFactory p : _incomingConnectionFactories) { - if(endpoint.equivalent(p.endpoint())) + if(p.isLocal(endpoint)) { return true; } @@ -1079,8 +1079,15 @@ public final class ObjectAdapterI implements ObjectAdapter parseEndpoints(properties.getProperty(_name + ".Endpoints"), true); for(IceInternal.EndpointI endp : endpoints) { - IncomingConnectionFactory factory = new IncomingConnectionFactory(instance, endp, this); - _incomingConnectionFactories.add(factory); + Ice.Holder<IceInternal.EndpointI> publishedEndpoint = new Ice.Holder<>(); + for(IceInternal.EndpointI expanded : endp.expandHost(publishedEndpoint)) + { + IncomingConnectionFactory factory = new IncomingConnectionFactory(instance, + expanded, + publishedEndpoint.value, + this); + _incomingConnectionFactories.add(factory); + } } if(endpoints.size() == 0) { @@ -1339,7 +1346,18 @@ public final class ObjectAdapterI implements ObjectAdapter // for(IncomingConnectionFactory factory : _incomingConnectionFactories) { - endpoints.addAll(factory.endpoint().expand()); + for(IceInternal.EndpointI endpt : factory.endpoint().expandIfWildcard()) + { + // + // Check for duplicate endpoints, this might occur if an endpoint with a DNS name + // expands to multiple addresses. In this case, multiple incoming connection + // factories can point to the same published endpoint. + // + if(!endpoints.contains(endpt)) + { + endpoints.add(endpt); + } + } } } diff --git a/java-compat/src/Ice/src/main/java/IceInternal/EndpointI.java b/java-compat/src/Ice/src/main/java/IceInternal/EndpointI.java index b6ce248e5d4..700d4f8b71d 100644 --- a/java-compat/src/Ice/src/main/java/IceInternal/EndpointI.java +++ b/java-compat/src/Ice/src/main/java/IceInternal/EndpointI.java @@ -120,7 +120,18 @@ abstract public class EndpointI implements Ice.Endpoint, java.lang.Comparable<En // Expand endpoint out in to separate endpoints for each local // host if listening on INADDR_ANY. // - public abstract java.util.List<EndpointI> expand(); + public abstract java.util.List<EndpointI> expandIfWildcard(); + + // + // Expand endpoint out into separate endpoints for each IP + // address returned by the DNS resolver. Also returns the + // endpoint which can be used to connect to the returned + // endpoints or null if no specific endpoint can be used to + // connect to these endpoints (e.g.: with the IP endpoint, + // it returns this endpoint if it uses a fixed port, null + // otherwise). + // + public abstract java.util.List<EndpointI> expandHost(Ice.Holder<EndpointI> publishedEndpoint); // // Check whether the endpoint is equivalent to another one. diff --git a/java-compat/src/Ice/src/main/java/IceInternal/IPEndpointI.java b/java-compat/src/Ice/src/main/java/IceInternal/IPEndpointI.java index cbdeebe8a66..e67a02ff611 100644 --- a/java-compat/src/Ice/src/main/java/IceInternal/IPEndpointI.java +++ b/java-compat/src/Ice/src/main/java/IceInternal/IPEndpointI.java @@ -113,7 +113,7 @@ public abstract class IPEndpointI extends EndpointI } @Override - public java.util.List<EndpointI> expand() + public java.util.List<EndpointI> expandIfWildcard() { java.util.List<EndpointI> endps = new java.util.ArrayList<EndpointI>(); java.util.List<String> hosts = Network.getHostsForEndpointExpand(_host, _instance.protocolSupport(), false); @@ -132,6 +132,50 @@ public abstract class IPEndpointI extends EndpointI } @Override + public java.util.List<EndpointI> expandHost(Ice.Holder<EndpointI> publishedEndpoint) + { + // + // If this endpoint has an empty host (wildcard address), don't expand, just return + // this endpoint. + // + if(_host.isEmpty()) + { + java.util.ArrayList<EndpointI> endpoints = new java.util.ArrayList<>(); + endpoints.add(this); + return endpoints; + } + + // + // If using a fixed port, this endpoint can be used as the published endpoint to + // access the returned endpoints. Otherwise, we'll publish each individual expanded + // endpoint. + // + publishedEndpoint.value = _port > 0 ? this : null; + + java.util.List<java.net.InetSocketAddress> addresses = Network.getAddresses(_host, + _port, + _instance.protocolSupport(), + Ice.EndpointSelectionType.Ordered, + _instance.preferIPv6(), + true); + + + java.util.ArrayList<EndpointI> endpoints = new java.util.ArrayList<>(); + if(addresses.size() == 1) + { + endpoints.add(this); + } + else + { + for(java.net.InetSocketAddress addr : addresses) + { + endpoints.add(createEndpoint(addr.getAddress().getHostAddress(), addr.getPort(), _connectionId)); + } + } + return endpoints; + } + + @Override public boolean equivalent(EndpointI endpoint) { if(!(endpoint instanceof IPEndpointI)) diff --git a/java-compat/src/Ice/src/main/java/IceInternal/IncomingConnectionFactory.java b/java-compat/src/Ice/src/main/java/IceInternal/IncomingConnectionFactory.java index 1e031a86cde..9d830960d75 100644 --- a/java-compat/src/Ice/src/main/java/IceInternal/IncomingConnectionFactory.java +++ b/java-compat/src/Ice/src/main/java/IceInternal/IncomingConnectionFactory.java @@ -169,11 +169,30 @@ public final class IncomingConnectionFactory extends EventHandler implements Ice } } + public boolean + isLocal(EndpointI endpoint) + { + if(_publishedEndpoint != null && endpoint.equivalent(_publishedEndpoint)) + { + return true; + } + synchronized(this) + { + return endpoint.equivalent(_endpoint); + } + } + public EndpointI endpoint() { - // No mutex protection necessary, _endpoint is immutable. - return _endpoint; + if(_publishedEndpoint != null) + { + return _publishedEndpoint; + } + synchronized(this) + { + return _endpoint; + } } public synchronized java.util.LinkedList<Ice.ConnectionI> @@ -420,10 +439,11 @@ public final class IncomingConnectionFactory extends EventHandler implements Ice } public - IncomingConnectionFactory(Instance instance, EndpointI endpoint, Ice.ObjectAdapterI adapter) + IncomingConnectionFactory(Instance instance, EndpointI endpoint, EndpointI publish, Ice.ObjectAdapterI adapter) { _instance = instance; _endpoint = endpoint; + _publishedEndpoint = publish; _adapter = adapter; _warn = _instance.initializationData().properties.getPropertyAsInt("Ice.Warn.Connections") > 0 ? true : false; _state = StateHolding; @@ -718,6 +738,7 @@ public final class IncomingConnectionFactory extends EventHandler implements Ice private Acceptor _acceptor; private Transceiver _transceiver; private EndpointI _endpoint; + private final EndpointI _publishedEndpoint; private Ice.ObjectAdapterI _adapter; diff --git a/java-compat/src/Ice/src/main/java/IceInternal/OpaqueEndpointI.java b/java-compat/src/Ice/src/main/java/IceInternal/OpaqueEndpointI.java index aea8308a636..85bf2473ee7 100644 --- a/java-compat/src/Ice/src/main/java/IceInternal/OpaqueEndpointI.java +++ b/java-compat/src/Ice/src/main/java/IceInternal/OpaqueEndpointI.java @@ -215,9 +215,18 @@ final class OpaqueEndpointI extends EndpointI // was specified on client side. // @Override - public java.util.List<EndpointI> expand() + public java.util.List<EndpointI> expandIfWildcard() { - java.util.List<EndpointI> endps = new java.util.ArrayList<EndpointI>(); + java.util.List<EndpointI> endps = new java.util.ArrayList<>(); + endps.add(this); + return endps; + } + + @Override + public java.util.List<EndpointI> expandHost(Ice.Holder<EndpointI> publish) + { + publish.value = null; + java.util.List<EndpointI> endps = new java.util.ArrayList<>(); endps.add(this); return endps; } diff --git a/java-compat/src/Ice/src/main/java/IceInternal/WSEndpoint.java b/java-compat/src/Ice/src/main/java/IceInternal/WSEndpoint.java index 2cba87138b9..ad4c70cd973 100644 --- a/java-compat/src/Ice/src/main/java/IceInternal/WSEndpoint.java +++ b/java-compat/src/Ice/src/main/java/IceInternal/WSEndpoint.java @@ -207,11 +207,10 @@ final class WSEndpoint extends IceInternal.EndpointI } @Override - public java.util.List<EndpointI> expand() + public java.util.List<EndpointI> expandIfWildcard() { - java.util.List<EndpointI> endps = _delegate.expand(); java.util.List<EndpointI> l = new java.util.ArrayList<EndpointI>(); - for(EndpointI e : endps) + for(EndpointI e : _delegate.expandIfWildcard()) { l.add(e == _delegate ? this : new WSEndpoint(_instance, e, _resource)); } @@ -219,6 +218,21 @@ final class WSEndpoint extends IceInternal.EndpointI } @Override + public java.util.List<EndpointI> expandHost(Ice.Holder<EndpointI> publish) + { + java.util.List<EndpointI> l = new java.util.ArrayList<EndpointI>(); + for(EndpointI e : _delegate.expandHost(publish)) + { + l.add(e == _delegate ? this : new WSEndpoint(_instance, e, _resource)); + } + if(publish.value != null) + { + publish.value = publish.value == _delegate ? this : new WSEndpoint(_instance, publish.value, _resource); + } + return l; + } + + @Override public boolean equivalent(EndpointI endpoint) { if(!(endpoint instanceof WSEndpoint)) diff --git a/java-compat/src/Ice/src/main/java/IceSSL/EndpointI.java b/java-compat/src/Ice/src/main/java/IceSSL/EndpointI.java index cda60997e7b..e5f9854bb76 100644 --- a/java-compat/src/Ice/src/main/java/IceSSL/EndpointI.java +++ b/java-compat/src/Ice/src/main/java/IceSSL/EndpointI.java @@ -195,11 +195,10 @@ final class EndpointI extends IceInternal.EndpointI } @Override - public java.util.List<IceInternal.EndpointI> expand() + public java.util.List<IceInternal.EndpointI> expandIfWildcard() { - java.util.List<IceInternal.EndpointI> endps = _delegate.expand(); java.util.List<IceInternal.EndpointI> l = new java.util.ArrayList<IceInternal.EndpointI>(); - for(IceInternal.EndpointI e : endps) + for(IceInternal.EndpointI e : _delegate.expandIfWildcard()) { l.add(e == _delegate ? this : new EndpointI(_instance, e)); } @@ -207,6 +206,21 @@ final class EndpointI extends IceInternal.EndpointI } @Override + public java.util.List<IceInternal.EndpointI> expandHost(Ice.Holder<IceInternal.EndpointI> publish) + { + java.util.List<IceInternal.EndpointI> l = new java.util.ArrayList<IceInternal.EndpointI>(); + for(IceInternal.EndpointI e : _delegate.expandHost(publish)) + { + l.add(e == _delegate ? this : new EndpointI(_instance, e)); + } + if(publish.value != null) + { + publish.value = publish.value == _delegate ? this : new EndpointI(_instance, publish.value); + } + return l; + } + + @Override public boolean equivalent(IceInternal.EndpointI endpoint) { if(!(endpoint instanceof EndpointI)) diff --git a/java-compat/src/IceBT/src/main/java/IceBT/EndpointI.java b/java-compat/src/IceBT/src/main/java/IceBT/EndpointI.java index cbb3cf4c6dc..28df16fdf46 100644 --- a/java-compat/src/IceBT/src/main/java/IceBT/EndpointI.java +++ b/java-compat/src/IceBT/src/main/java/IceBT/EndpointI.java @@ -184,7 +184,7 @@ final class EndpointI extends IceInternal.EndpointI } @Override - public java.util.List<IceInternal.EndpointI> expand() + public java.util.List<IceInternal.EndpointI> expandIfWildcard() { java.util.List<IceInternal.EndpointI> endps = new java.util.ArrayList<IceInternal.EndpointI>(); endps.add(this); @@ -192,6 +192,15 @@ final class EndpointI extends IceInternal.EndpointI } @Override + public java.util.List<IceInternal.EndpointI> expandHost(Ice.Holder<IceInternal.EndpointI> publish) + { + publish.value = null; + java.util.List<IceInternal.EndpointI> endps = new java.util.ArrayList<IceInternal.EndpointI>(); + endps.add(this); + return endps; + } + + @Override public boolean equivalent(IceInternal.EndpointI endpoint) { if(!(endpoint instanceof EndpointI)) |