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 /csharp/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 'csharp/src')
-rw-r--r-- | csharp/src/Ice/ConnectionFactory.cs | 27 | ||||
-rw-r--r-- | csharp/src/Ice/EndpointI.cs | 13 | ||||
-rw-r--r-- | csharp/src/Ice/IPEndpointI.cs | 46 | ||||
-rw-r--r-- | csharp/src/Ice/ObjectAdapterI.cs | 26 | ||||
-rw-r--r-- | csharp/src/Ice/OpaqueEndpointI.cs | 12 | ||||
-rw-r--r-- | csharp/src/Ice/WSEndpoint.cs | 21 | ||||
-rw-r--r-- | csharp/src/IceSSL/EndpointI.cs | 18 |
7 files changed, 146 insertions, 17 deletions
diff --git a/csharp/src/Ice/ConnectionFactory.cs b/csharp/src/Ice/ConnectionFactory.cs index 8f695852f23..308be80e6c0 100644 --- a/csharp/src/Ice/ConnectionFactory.cs +++ b/csharp/src/Ice/ConnectionFactory.cs @@ -1265,10 +1265,28 @@ namespace IceInternal } } + public bool isLocal(EndpointI endpoint) + { + if(_publishedEndpoint != null && endpoint.equivalent(_publishedEndpoint)) + { + return true; + } + lock(this) + { + return endpoint.equivalent(_endpoint); + } + } + public EndpointI endpoint() { - // No mutex protection necessary, _endpoint is immutable. - return _endpoint; + if(_publishedEndpoint != null) + { + return _publishedEndpoint; + } + lock(this) + { + return _endpoint; + } } public ICollection<Ice.ConnectionI> connections() @@ -1528,10 +1546,12 @@ namespace IceInternal } } - public IncomingConnectionFactory(Instance instance, EndpointI endpoint, Ice.ObjectAdapterI adapter) + public 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; _connections = new HashSet<Ice.ConnectionI>(); @@ -1788,6 +1808,7 @@ namespace IceInternal private Acceptor _acceptor; private readonly Transceiver _transceiver; private EndpointI _endpoint; + private readonly EndpointI _publishedEndpoint; private Ice.ObjectAdapterI _adapter; diff --git a/csharp/src/Ice/EndpointI.cs b/csharp/src/Ice/EndpointI.cs index 8d1e8aeb60a..6ba4b8e6621 100644 --- a/csharp/src/Ice/EndpointI.cs +++ b/csharp/src/Ice/EndpointI.cs @@ -146,7 +146,18 @@ namespace IceInternal // host if listening on INADDR_ANY on server side or if no host // was specified on client side. // - public abstract List<EndpointI> expand(); + public abstract 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 List<EndpointI> expandHost(out EndpointI publishedEndpoint); // // Check whether the endpoint is equivalent to another one. diff --git a/csharp/src/Ice/IPEndpointI.cs b/csharp/src/Ice/IPEndpointI.cs index 16fa7944a27..b7a7186a35f 100644 --- a/csharp/src/Ice/IPEndpointI.cs +++ b/csharp/src/Ice/IPEndpointI.cs @@ -116,7 +116,7 @@ namespace IceInternal instance_.resolve(host_, port_, selType, this, callback); } - public override List<EndpointI> expand() + public override List<EndpointI> expandIfWildcard() { List<EndpointI> endps = new List<EndpointI>(); List<string> hosts = Network.getHostsForEndpointExpand(host_, instance_.protocolSupport(), false); @@ -134,6 +134,50 @@ namespace IceInternal return endps; } + public override List<EndpointI> expandHost(out EndpointI publish) + { + // + // If this endpoint has an empty host (wildcard address), don't expand, just return + // this endpoint. + // + var endpoints = new List<EndpointI>(); + if(host_.Length == 0) + { + publish = null; + 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. + // + publish = port_ > 0 ? this : null; + + List<EndPoint> addresses = Network.getAddresses(host_, + port_, + instance_.protocolSupport(), + Ice.EndpointSelectionType.Ordered, + instance_.preferIPv6(), + true); + + if(addresses.Count == 1) + { + endpoints.Add(this); + } + else + { + foreach(EndPoint addr in addresses) + { + endpoints.Add(createEndpoint(Network.endpointAddressToString(addr), + Network.endpointPort(addr), + connectionId_)); + } + } + return endpoints; + } + public override bool equivalent(EndpointI endpoint) { if(!(endpoint is IPEndpointI)) diff --git a/csharp/src/Ice/ObjectAdapterI.cs b/csharp/src/Ice/ObjectAdapterI.cs index a0f75b109ab..38891e49bf8 100644 --- a/csharp/src/Ice/ObjectAdapterI.cs +++ b/csharp/src/Ice/ObjectAdapterI.cs @@ -698,7 +698,7 @@ namespace Ice } foreach(IncomingConnectionFactory factory in _incomingConnectionFactories) { - if(endpoints[i].equivalent(factory.endpoint())) + if(factory.isLocal(endpoints[i])) { return true; } @@ -1022,8 +1022,15 @@ namespace Ice List<EndpointI> endpoints = parseEndpoints(properties.getProperty(_name + ".Endpoints"), true); foreach(EndpointI endp in endpoints) { - IncomingConnectionFactory factory = new IncomingConnectionFactory(instance, endp, this); - _incomingConnectionFactories.Add(factory); + EndpointI publishedEndpoint; + foreach(IceInternal.EndpointI expanded in endp.expandHost(out publishedEndpoint)) + { + IncomingConnectionFactory factory = new IncomingConnectionFactory(instance, + expanded, + publishedEndpoint, + this); + _incomingConnectionFactories.Add(factory); + } } if(endpoints.Count == 0) { @@ -1245,7 +1252,18 @@ namespace Ice // foreach(IncomingConnectionFactory factory in _incomingConnectionFactories) { - endpoints.AddRange(factory.endpoint().expand()); + foreach(EndpointI endpt in 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/csharp/src/Ice/OpaqueEndpointI.cs b/csharp/src/Ice/OpaqueEndpointI.cs index 2421d75c68c..c52cc9c0185 100644 --- a/csharp/src/Ice/OpaqueEndpointI.cs +++ b/csharp/src/Ice/OpaqueEndpointI.cs @@ -227,13 +227,21 @@ namespace IceInternal // host if listening on INADDR_ANY on server side or if no host // was specified on client side. // - public override List<EndpointI> expand() + public override List<EndpointI> expandIfWildcard() { List<EndpointI> endps = new List<EndpointI>(); endps.Add(this); return endps; } + public override List<EndpointI> expandHost(out EndpointI publishedEndpoint) + { + publishedEndpoint = null; + List<EndpointI> endps = new List<EndpointI>(); + endps.Add(this); + return endps; + } + // // Check whether the endpoint is equivalent to another one. // @@ -384,7 +392,7 @@ namespace IceInternal { throw new Ice.EndpointParseException("Invalid Base64 input in endpoint " + endpoint, ex); } - + return true; } diff --git a/csharp/src/Ice/WSEndpoint.cs b/csharp/src/Ice/WSEndpoint.cs index d4e1e044732..7990f7ca224 100644 --- a/csharp/src/Ice/WSEndpoint.cs +++ b/csharp/src/Ice/WSEndpoint.cs @@ -215,17 +215,30 @@ namespace IceInternal return new WSEndpoint(_instance, delEndp, _resource); } - public override List<EndpointI> expand() + public override List<EndpointI> expandIfWildcard() { - List<EndpointI> endps = _delegate.expand(); List<EndpointI> l = new List<EndpointI>(); - foreach(EndpointI e in endps) + foreach(EndpointI e in _delegate.expandIfWildcard()) { l.Add(e == _delegate ? this : new WSEndpoint(_instance, e, _resource)); } return l; } + public override List<EndpointI> expandHost(out EndpointI publish) + { + List<EndpointI> l = new List<EndpointI>(); + foreach(EndpointI e in _delegate.expandHost(out publish)) + { + l.Add(e == _delegate ? this : new WSEndpoint(_instance, e, _resource)); + } + if(publish != null) + { + publish = publish == _delegate ? this : new WSEndpoint(_instance, publish, _resource); + } + return l; + } + public override bool equivalent(EndpointI endpoint) { if(!(endpoint is WSEndpoint)) @@ -274,7 +287,7 @@ namespace IceInternal public override int CompareTo(EndpointI obj) { - if(!(obj is EndpointI)) + if(!(obj is WSEndpoint)) { return type() < obj.type() ? -1 : 1; } diff --git a/csharp/src/IceSSL/EndpointI.cs b/csharp/src/IceSSL/EndpointI.cs index 52bf89e712f..f9b83efc211 100644 --- a/csharp/src/IceSSL/EndpointI.cs +++ b/csharp/src/IceSSL/EndpointI.cs @@ -188,16 +188,30 @@ namespace IceSSL return new EndpointI(_instance, del); } - public override List<IceInternal.EndpointI> expand() + public override List<IceInternal.EndpointI> expandIfWildcard() { List<IceInternal.EndpointI> l = new List<IceInternal.EndpointI>(); - foreach(IceInternal.EndpointI e in _delegate.expand()) + foreach(IceInternal.EndpointI e in _delegate.expandIfWildcard()) { l.Add(e == _delegate ? this : new EndpointI(_instance, e)); } return l; } + public override List<IceInternal.EndpointI> expandHost(out IceInternal.EndpointI publish) + { + List<IceInternal.EndpointI> l = new List<IceInternal.EndpointI>(); + foreach(IceInternal.EndpointI e in _delegate.expandHost(out publish)) + { + l.Add(e == _delegate ? this : new EndpointI(_instance, e)); + } + if(publish != null) + { + publish = publish == _delegate ? this : new EndpointI(_instance, publish); + } + return l; + } + public override bool equivalent(IceInternal.EndpointI endpoint) { if(!(endpoint is EndpointI)) |