From f60efc72931546ef41eadc1f1f7f49019041fb60 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Fri, 22 Nov 2024 10:49:13 -0500 Subject: [PATCH 1/5] Remove local from computed published endpoints in C# --- csharp/src/Ice/Internal/EndpointI.cs | 4 ++-- csharp/src/Ice/Internal/IPEndpointI.cs | 5 +---- csharp/src/Ice/Internal/OpaqueEndpointI.cs | 2 +- csharp/src/Ice/Internal/TcpEndpointI.cs | 19 +++++++++++++++++++ csharp/src/Ice/Internal/UdpEndpointI.cs | 12 ++++++++++++ csharp/src/Ice/Internal/WSEndpoint.cs | 3 ++- csharp/src/Ice/ObjectAdapter.cs | 8 ++------ csharp/src/Ice/SSL/EndpointI.cs | 3 ++- csharp/test/Ice/background/EndpointI.cs | 3 ++- 9 files changed, 43 insertions(+), 16 deletions(-) diff --git a/csharp/src/Ice/Internal/EndpointI.cs b/csharp/src/Ice/Internal/EndpointI.cs index b33b1e88c24..6ffa5cac0f0 100644 --- a/csharp/src/Ice/Internal/EndpointI.cs +++ b/csharp/src/Ice/Internal/EndpointI.cs @@ -136,8 +136,8 @@ public virtual void streamWrite(Ice.OutputStream s) // Returns true when the most underlying endpoint is an IP endpoint with a loopback or multicast address. public abstract bool isLoopbackOrMulticast(); - // Returns a new endpoint with the specified host; returns this when this operation is not applicable. - public abstract EndpointI withPublishedHost(string host); + // Returns a new endpoint with the specified host (if not empty) and all local options cleared. May return this. + public abstract EndpointI toPublishedEndpoint(string publishedHost); // // Check whether the endpoint is equivalent to another one. diff --git a/csharp/src/Ice/Internal/IPEndpointI.cs b/csharp/src/Ice/Internal/IPEndpointI.cs index 27fa0622bba..c16d316a62d 100644 --- a/csharp/src/Ice/Internal/IPEndpointI.cs +++ b/csharp/src/Ice/Internal/IPEndpointI.cs @@ -141,8 +141,6 @@ public override bool isLoopbackOrMulticast() } } - public override EndpointI withPublishedHost(string host) => createEndpoint(host, port_, connectionId_); - public override bool equivalent(EndpointI endpoint) { if (!(endpoint is IPEndpointI)) @@ -152,8 +150,7 @@ public override bool equivalent(EndpointI endpoint) IPEndpointI ipEndpointI = (IPEndpointI)endpoint; return ipEndpointI.type() == type() && ipEndpointI.host_.Equals(host_, StringComparison.Ordinal) && - ipEndpointI.port_ == port_ && - Network.addressEquals(ipEndpointI.sourceAddr_, sourceAddr_); + ipEndpointI.port_ == port_; } public virtual List connectors(List addresses, NetworkProxy proxy) diff --git a/csharp/src/Ice/Internal/OpaqueEndpointI.cs b/csharp/src/Ice/Internal/OpaqueEndpointI.cs index e4a3e71fc73..afbe4dad13c 100644 --- a/csharp/src/Ice/Internal/OpaqueEndpointI.cs +++ b/csharp/src/Ice/Internal/OpaqueEndpointI.cs @@ -215,7 +215,7 @@ public override Acceptor acceptor(string adapterName, SslServerAuthenticationOpt public override bool isLoopbackOrMulticast() => false; - public override EndpointI withPublishedHost(string host) => this; + public override EndpointI toPublishedEndpoint(string host) => this; // // Check whether the endpoint is equivalent to another one. diff --git a/csharp/src/Ice/Internal/TcpEndpointI.cs b/csharp/src/Ice/Internal/TcpEndpointI.cs index 8114db0d626..415f831e5e2 100644 --- a/csharp/src/Ice/Internal/TcpEndpointI.cs +++ b/csharp/src/Ice/Internal/TcpEndpointI.cs @@ -212,6 +212,25 @@ public override void fillEndpointInfo(Ice.IPEndpointInfo info) info.compress = _compress; } + public override EndpointI toPublishedEndpoint(string publishedHost) + { + if (publishedHost.Length == 0 && sourceAddr_ is null && connectionId_.Length == 0) + { + return this; + } + else + { + return new TcpEndpointI( + instance_, + publishedHost.Length > 0 ? publishedHost : host_, + port_, + sourceAddr: null, + _timeout, + conId: "", + _compress); + } + } + protected override bool checkOption(string option, string argument, string endpoint) { if (base.checkOption(option, argument, endpoint)) diff --git a/csharp/src/Ice/Internal/UdpEndpointI.cs b/csharp/src/Ice/Internal/UdpEndpointI.cs index 6fe5be0b450..f12d39b00f9 100644 --- a/csharp/src/Ice/Internal/UdpEndpointI.cs +++ b/csharp/src/Ice/Internal/UdpEndpointI.cs @@ -332,6 +332,18 @@ public override void fillEndpointInfo(Ice.IPEndpointInfo info) } } + public override EndpointI toPublishedEndpoint(string publishedHost) => + new UdpEndpointI( + instance_, + publishedHost.Length > 0 ? publishedHost : host_, + port_, + sourceAddr: null, + mcastInterface: "", + mttl: -1, + conn: false, // for "connect" + conId: "", + _compress); + protected override bool checkOption(string option, string argument, string endpoint) { if (base.checkOption(option, argument, endpoint)) diff --git a/csharp/src/Ice/Internal/WSEndpoint.cs b/csharp/src/Ice/Internal/WSEndpoint.cs index f63a48e1089..47b22b2b048 100644 --- a/csharp/src/Ice/Internal/WSEndpoint.cs +++ b/csharp/src/Ice/Internal/WSEndpoint.cs @@ -219,7 +219,8 @@ public override List expandHost() => public override bool isLoopbackOrMulticast() => _delegate.isLoopbackOrMulticast(); - public override EndpointI withPublishedHost(string host) => endpoint(_delegate.withPublishedHost(host)); + public override EndpointI toPublishedEndpoint(string publishedHost) => + endpoint(_delegate.toPublishedEndpoint(publishedHost)); public override bool equivalent(EndpointI endpoint) { diff --git a/csharp/src/Ice/ObjectAdapter.cs b/csharp/src/Ice/ObjectAdapter.cs index dfa8683447a..7fa969709cf 100644 --- a/csharp/src/Ice/ObjectAdapter.cs +++ b/csharp/src/Ice/ObjectAdapter.cs @@ -1344,12 +1344,8 @@ private EndpointI[] computePublishedEndpoints() } } - if (publishedHost.Length > 0) - { - // Replace the host in all endpoints by publishedHost (when applicable). - endpoints = endpoints.Select(e => e.withPublishedHost(publishedHost)).Distinct(); - } - // else keep the loopback-only/multicast endpoints as-is (with IP addresses) + // Replace the host in all endpoints by publishedHost (when applicable) and clear all local options. + endpoints = endpoints.Select(e => e.toPublishedEndpoint(publishedHost)).Distinct(); } } diff --git a/csharp/src/Ice/SSL/EndpointI.cs b/csharp/src/Ice/SSL/EndpointI.cs index e728b65e7c2..18a20827a87 100644 --- a/csharp/src/Ice/SSL/EndpointI.cs +++ b/csharp/src/Ice/SSL/EndpointI.cs @@ -157,7 +157,8 @@ public EndpointI endpoint(Ice.Internal.EndpointI del) public override bool isLoopbackOrMulticast() => _delegate.isLoopbackOrMulticast(); - public override EndpointI withPublishedHost(string host) => endpoint(_delegate.withPublishedHost(host)); + public override EndpointI toPublishedEndpoint(string publishedHost) => + endpoint(_delegate.toPublishedEndpoint(publishedHost)); public override bool equivalent(Ice.Internal.EndpointI endpoint) { diff --git a/csharp/test/Ice/background/EndpointI.cs b/csharp/test/Ice/background/EndpointI.cs index f515d4892af..a598c632bed 100644 --- a/csharp/test/Ice/background/EndpointI.cs +++ b/csharp/test/Ice/background/EndpointI.cs @@ -178,7 +178,8 @@ public EndpointI endpoint(Ice.Internal.EndpointI delEndp) public override bool isLoopbackOrMulticast() => _endpoint.isLoopbackOrMulticast(); - public override EndpointI withPublishedHost(string host) => endpoint(_endpoint.withPublishedHost(host)); + public override EndpointI toPublishedEndpoint(string publishedHost) => + endpoint(_endpoint.toPublishedEndpoint(publishedHost)); public override bool equivalent(Ice.Internal.EndpointI endpoint) { From 3513e475766ddf5d3f5741f9adea48783ea18694 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Fri, 22 Nov 2024 11:10:58 -0500 Subject: [PATCH 2/5] Fix Java --- .../src/main/java/com/zeroc/Ice/EndpointI.java | 6 +++--- .../src/main/java/com/zeroc/Ice/IPEndpointI.java | 8 +------- .../main/java/com/zeroc/Ice/ObjectAdapter.java | 14 ++++++-------- .../main/java/com/zeroc/Ice/OpaqueEndpointI.java | 2 +- .../main/java/com/zeroc/Ice/SSL/EndpointI.java | 4 ++-- .../main/java/com/zeroc/Ice/TcpEndpointI.java | 16 ++++++++++++++++ .../main/java/com/zeroc/Ice/UdpEndpointI.java | 14 ++++++++++++++ .../src/main/java/com/zeroc/Ice/WSEndpoint.java | 4 ++-- .../src/main/java/com/zeroc/IceBT/EndpointI.java | 2 +- .../main/java/test/Ice/background/EndpointI.java | 4 ++-- 10 files changed, 48 insertions(+), 26 deletions(-) diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/EndpointI.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/EndpointI.java index d7ed37361c4..ce50e8f0412 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/EndpointI.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/EndpointI.java @@ -120,9 +120,9 @@ public abstract Acceptor acceptor( // address. public abstract boolean isLoopbackOrMulticast(); - // Returns a new endpoint with the specified host; returns this when this operation is not - // applicable. - public abstract EndpointI withPublishedHost(String host); + // Returns a new endpoint with the specified host (if not empty) and all local options cleared. + // May return this. + public abstract EndpointI toPublishedEndpoint(String publishedHost); // // Check whether the endpoint is equivalent to another one. diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/IPEndpointI.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/IPEndpointI.java index 6802d758efe..ea4dfc3124a 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/IPEndpointI.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/IPEndpointI.java @@ -128,11 +128,6 @@ public boolean isLoopbackOrMulticast() { } } - @Override - public EndpointI withPublishedHost(String host) { - return createEndpoint(host, _port, _connectionId); - } - @Override public boolean equivalent(EndpointI endpoint) { if (!(endpoint instanceof IPEndpointI)) { @@ -142,8 +137,7 @@ public boolean equivalent(EndpointI endpoint) { IPEndpointI ipEndpointI = (IPEndpointI) endpoint; return ipEndpointI.type() == type() && ipEndpointI._normalizedHost.equals(_normalizedHost) - && ipEndpointI._port == _port - && java.util.Objects.equals(ipEndpointI._sourceAddr, _sourceAddr); + && ipEndpointI._port == _port; } public java.util.List connectors( diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/ObjectAdapter.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/ObjectAdapter.java index cf7a720ed4d..f8ac6195807 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/ObjectAdapter.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/ObjectAdapter.java @@ -1428,14 +1428,12 @@ private EndpointI[] computePublishedEndpoints() { } } - if (!publishedHost.isEmpty()) { - // Replace the host in all endpoints by publishedHost (when applicable). - final String publishedHostCapture = publishedHost; - endpoints = - endpoints - .map(e -> e.withPublishedHost(publishedHostCapture)) - .distinct(); - } + // Replace the host in all endpoints by publishedHost (when applicable) and clear + // local options. + final String publishedHostCapture = publishedHost; + endpoints = + endpoints.map(e -> e.toPublishedEndpoint(publishedHostCapture)).distinct(); + endpointsArray = endpoints.toArray(EndpointI[]::new); } else { endpointsArray = endpointsList.toArray(EndpointI[]::new); diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/OpaqueEndpointI.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/OpaqueEndpointI.java index 5451aa1a514..572afff8595 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/OpaqueEndpointI.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/OpaqueEndpointI.java @@ -191,7 +191,7 @@ public boolean isLoopbackOrMulticast() { } @Override - public EndpointI withPublishedHost(String host) { + public EndpointI toPublishedEndpoint(String publishedHost) { return this; } diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/SSL/EndpointI.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/SSL/EndpointI.java index c9b32f02347..44bad80262a 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/SSL/EndpointI.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/SSL/EndpointI.java @@ -174,8 +174,8 @@ public boolean isLoopbackOrMulticast() { } @Override - public com.zeroc.Ice.EndpointI withPublishedHost(String host) { - return endpoint(_delegate.withPublishedHost(host)); + public com.zeroc.Ice.EndpointI toPublishedEndpoint(String publishedHost) { + return endpoint(_delegate.toPublishedEndpoint(publishedHost)); } @Override diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/TcpEndpointI.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/TcpEndpointI.java index fa28e53e54b..eb2671983bf 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/TcpEndpointI.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/TcpEndpointI.java @@ -213,6 +213,22 @@ public int hashCode() { return h; } + @Override + public EndpointI toPublishedEndpoint(String publishedHost) { + if (publishedHost.isEmpty() && _sourceAddr == null && _connectionId.isEmpty()) { + return this; + } else { + return new TcpEndpointI( + _instance, + publishedHost.isEmpty() ? _host : publishedHost, + _port, + null, + _timeout, + "", + _compress); + } + } + @Override protected boolean checkOption(String option, String argument, String endpoint) { if (super.checkOption(option, argument, endpoint)) { diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/UdpEndpointI.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/UdpEndpointI.java index a80c4f35184..843f19763e3 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/UdpEndpointI.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/UdpEndpointI.java @@ -317,6 +317,20 @@ public void fillEndpointInfo(IPEndpointInfo info) { } } + @Override + public EndpointI toPublishedEndpoint(String publishedHost) { + return new UdpEndpointI( + _instance, + publishedHost.isEmpty() ? _host : publishedHost, + _port, + null, + "", + -1, + false, // for "connect" + "", + _compress); + } + @Override protected boolean checkOption(String option, String argument, String endpoint) { if (super.checkOption(option, argument, endpoint)) { diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/WSEndpoint.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/WSEndpoint.java index 07756599c49..5cddd5db2d2 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/WSEndpoint.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/WSEndpoint.java @@ -184,8 +184,8 @@ public boolean isLoopbackOrMulticast() { } @Override - public EndpointI withPublishedHost(String host) { - return endpoint(_delegate.withPublishedHost(host)); + public EndpointI toPublishedEndpoint(String publishedHost) { + return endpoint(_delegate.toPublishedEndpoint(publishedHost)); } @Override diff --git a/java/src/com.zeroc.icebt/src/main/java/com/zeroc/IceBT/EndpointI.java b/java/src/com.zeroc.icebt/src/main/java/com/zeroc/IceBT/EndpointI.java index 9d6099b6753..a1631a46a45 100644 --- a/java/src/com.zeroc.icebt/src/main/java/com/zeroc/IceBT/EndpointI.java +++ b/java/src/com.zeroc.icebt/src/main/java/com/zeroc/IceBT/EndpointI.java @@ -166,7 +166,7 @@ public boolean isLoopbackOrMulticast() { } @Override - public com.zeroc.Ice.EndpointI withPublishedHost(String host) { + public com.zeroc.Ice.EndpointI toPublishedEndpoint(String publishedHost) { return this; } diff --git a/java/test/src/main/java/test/Ice/background/EndpointI.java b/java/test/src/main/java/test/Ice/background/EndpointI.java index 0ec32379616..5bcc90556b7 100644 --- a/java/test/src/main/java/test/Ice/background/EndpointI.java +++ b/java/test/src/main/java/test/Ice/background/EndpointI.java @@ -159,8 +159,8 @@ public boolean isLoopbackOrMulticast() { } @Override - public com.zeroc.Ice.EndpointI withPublishedHost(String host) { - return endpoint(_endpoint.withPublishedHost(host)); + public com.zeroc.Ice.EndpointI toPublishedEndpoint(String publishedHost) { + return endpoint(_endpoint.toPublishedEndpoint(publishedHost)); } @Override From 9dfebb94bb9bbc1446bdb93019d84cab2deeed67 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Fri, 22 Nov 2024 11:53:15 -0500 Subject: [PATCH 3/5] Fix C++ --- cpp/src/Ice/EndpointI.h | 6 ++++-- cpp/src/Ice/IPEndpointI.cpp | 6 ------ cpp/src/Ice/IPEndpointI.h | 1 - cpp/src/Ice/ObjectAdapterI.cpp | 27 ++++++++++++--------------- cpp/src/Ice/OpaqueEndpointI.cpp | 2 +- cpp/src/Ice/OpaqueEndpointI.h | 2 +- cpp/src/Ice/SSL/SSLEndpointI.cpp | 4 ++-- cpp/src/Ice/SSL/SSLEndpointI.h | 2 +- cpp/src/Ice/TcpEndpointI.cpp | 20 ++++++++++++++++++++ cpp/src/Ice/TcpEndpointI.h | 2 ++ cpp/src/Ice/UdpEndpointI.cpp | 15 +++++++++++++++ cpp/src/Ice/UdpEndpointI.h | 2 ++ cpp/src/Ice/WSEndpoint.cpp | 4 ++-- cpp/src/Ice/WSEndpoint.h | 2 +- cpp/src/Ice/ios/iAPEndpointI.h | 2 +- cpp/src/Ice/ios/iAPEndpointI.mm | 2 +- cpp/src/IceBT/EndpointI.cpp | 2 +- cpp/src/IceBT/EndpointI.h | 2 +- cpp/test/Ice/background/EndpointI.cpp | 4 ++-- cpp/test/Ice/background/EndpointI.h | 2 +- cpp/test/Ice/info/AllTests.cpp | 7 +++++-- 21 files changed, 75 insertions(+), 41 deletions(-) diff --git a/cpp/src/Ice/EndpointI.h b/cpp/src/Ice/EndpointI.h index b36a2550c2c..1ca08ca2cb1 100644 --- a/cpp/src/Ice/EndpointI.h +++ b/cpp/src/Ice/EndpointI.h @@ -119,8 +119,10 @@ namespace IceInternal // Returns true when the most underlying endpoint is an IP endpoint with a loopback or multicast address. virtual bool isLoopbackOrMulticast() const = 0; - // Returns a new endpoint with the specified host; returns this when this operation is not applicable. - virtual std::shared_ptr withPublishedHost(std::string host) const = 0; + // Returns a new endpoint with the specified host (if not empty) and all local options cleared. May return + // shared_from_this(). + virtual std::shared_ptr toPublishedEndpoint(std::string publishedHost) const = 0; + // // Check whether the endpoint is equivalent to another one. // diff --git a/cpp/src/Ice/IPEndpointI.cpp b/cpp/src/Ice/IPEndpointI.cpp index 69ec95d7881..29333d5e4ab 100644 --- a/cpp/src/Ice/IPEndpointI.cpp +++ b/cpp/src/Ice/IPEndpointI.cpp @@ -142,12 +142,6 @@ IceInternal::IPEndpointI::isLoopbackOrMulticast() const return _host.empty() ? false : isLoopbackOrMulticastAddress(_host); } -shared_ptr -IceInternal::IPEndpointI::withPublishedHost(string host) const -{ - return createEndpoint(host, _port, _connectionId); -} - bool IceInternal::IPEndpointI::equivalent(const EndpointIPtr& endpoint) const { diff --git a/cpp/src/Ice/IPEndpointI.h b/cpp/src/Ice/IPEndpointI.h index 84ccc0c44d0..5522884e861 100644 --- a/cpp/src/Ice/IPEndpointI.h +++ b/cpp/src/Ice/IPEndpointI.h @@ -50,7 +50,6 @@ namespace IceInternal std::function) const override; std::vector expandHost() const override; bool isLoopbackOrMulticast() const override; - std::shared_ptr withPublishedHost(std::string host) const override; bool equivalent(const EndpointIPtr&) const override; std::size_t hash() const noexcept override; std::string options() const override; diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index e8805a4c2e1..740cd0f064f 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -1214,25 +1214,22 @@ ObjectAdapterI::computePublishedEndpoints() } // else keep endpoints as-is; they are all loopback or multicast - if (!publishedHost.empty()) - { - vector newEndpoints; + vector newEndpoints; - // Replace the host in all endpoints by publishedHost (when applicable), and remove duplicates. - for (const auto& endpoint : endpoints) + // Replace the host in all endpoints by publishedHost (when applicable), clear local options and remove + // duplicates. + for (const auto& endpoint : endpoints) + { + EndpointIPtr newEndpoint = endpoint->toPublishedEndpoint(publishedHost); + if (find_if( + newEndpoints.begin(), + newEndpoints.end(), + [&newEndpoint](const EndpointIPtr& p) { return *newEndpoint == *p; }) == newEndpoints.end()) { - EndpointIPtr newEndpoint = endpoint->withPublishedHost(publishedHost); - if (find_if( - newEndpoints.begin(), - newEndpoints.end(), - [&newEndpoint](const EndpointIPtr& p) { return *newEndpoint == *p; }) == newEndpoints.end()) - { - newEndpoints.push_back(newEndpoint); - } + newEndpoints.push_back(newEndpoint); } - endpoints = std::move(newEndpoints); } - // else keep the loopback/multicast endpoints as-is (with IP addresses) + endpoints = std::move(newEndpoints); } } diff --git a/cpp/src/Ice/OpaqueEndpointI.cpp b/cpp/src/Ice/OpaqueEndpointI.cpp index cfa14ad543a..1dab41dc724 100644 --- a/cpp/src/Ice/OpaqueEndpointI.cpp +++ b/cpp/src/Ice/OpaqueEndpointI.cpp @@ -175,7 +175,7 @@ IceInternal::OpaqueEndpointI::isLoopbackOrMulticast() const } shared_ptr -IceInternal::OpaqueEndpointI::withPublishedHost(string) const +IceInternal::OpaqueEndpointI::toPublishedEndpoint(string) const { return const_cast(this)->shared_from_this(); } diff --git a/cpp/src/Ice/OpaqueEndpointI.h b/cpp/src/Ice/OpaqueEndpointI.h index 46c008ee9aa..bfdea04dd96 100644 --- a/cpp/src/Ice/OpaqueEndpointI.h +++ b/cpp/src/Ice/OpaqueEndpointI.h @@ -42,7 +42,7 @@ namespace IceInternal acceptor(const std::string&, const std::optional&) const final; std::vector expandHost() const final; bool isLoopbackOrMulticast() const final; - std::shared_ptr withPublishedHost(std::string host) const final; + std::shared_ptr toPublishedEndpoint(std::string publishedHost) const final; bool equivalent(const EndpointIPtr&) const final; std::size_t hash() const noexcept final; std::string options() const final; diff --git a/cpp/src/Ice/SSL/SSLEndpointI.cpp b/cpp/src/Ice/SSL/SSLEndpointI.cpp index fe121054edd..1ecdce33030 100644 --- a/cpp/src/Ice/SSL/SSLEndpointI.cpp +++ b/cpp/src/Ice/SSL/SSLEndpointI.cpp @@ -260,9 +260,9 @@ Ice::SSL::EndpointI::isLoopbackOrMulticast() const } shared_ptr -Ice::SSL::EndpointI::withPublishedHost(string host) const +Ice::SSL::EndpointI::toPublishedEndpoint(string publishedHost) const { - return endpoint(_delegate->withPublishedHost(std::move(host))); + return endpoint(_delegate->toPublishedEndpoint(std::move(publishedHost))); } bool diff --git a/cpp/src/Ice/SSL/SSLEndpointI.h b/cpp/src/Ice/SSL/SSLEndpointI.h index eb03ae7c920..f954d966a38 100644 --- a/cpp/src/Ice/SSL/SSLEndpointI.h +++ b/cpp/src/Ice/SSL/SSLEndpointI.h @@ -44,7 +44,7 @@ namespace Ice::SSL acceptor(const std::string&, const std::optional&) const final; std::vector expandHost() const final; bool isLoopbackOrMulticast() const final; - std::shared_ptr withPublishedHost(std::string host) const final; + std::shared_ptr toPublishedEndpoint(std::string publishedHost) const final; bool equivalent(const IceInternal::EndpointIPtr&) const final; std::size_t hash() const noexcept final; std::string options() const final; diff --git a/cpp/src/Ice/TcpEndpointI.cpp b/cpp/src/Ice/TcpEndpointI.cpp index dceeade014c..bf7897f9f8b 100644 --- a/cpp/src/Ice/TcpEndpointI.cpp +++ b/cpp/src/Ice/TcpEndpointI.cpp @@ -122,6 +122,26 @@ IceInternal::TcpEndpointI::datagram() const return false; } +shared_ptr +IceInternal::TcpEndpointI::toPublishedEndpoint(string publishedHost) const +{ + if (publishedHost.empty() && !isAddressValid(_sourceAddr) && _connectionId.empty()) + { + return const_cast(this)->shared_from_this(); + } + else + { + return make_shared( + _instance, + publishedHost.empty() ? _host : publishedHost, + _port, + Address{}, + _timeout, + "", + _compress); + } +} + TransceiverPtr IceInternal::TcpEndpointI::transceiver() const { diff --git a/cpp/src/Ice/TcpEndpointI.h b/cpp/src/Ice/TcpEndpointI.h index 705dc27bc33..ee65991d143 100644 --- a/cpp/src/Ice/TcpEndpointI.h +++ b/cpp/src/Ice/TcpEndpointI.h @@ -37,6 +37,8 @@ namespace IceInternal EndpointIPtr compress(bool) const final; bool datagram() const final; + std::shared_ptr toPublishedEndpoint(std::string publishedHost) const final; + TransceiverPtr transceiver() const final; AcceptorPtr acceptor(const std::string&, const std::optional&) const final; diff --git a/cpp/src/Ice/UdpEndpointI.cpp b/cpp/src/Ice/UdpEndpointI.cpp index 325d30c67a8..f7e6db54524 100644 --- a/cpp/src/Ice/UdpEndpointI.cpp +++ b/cpp/src/Ice/UdpEndpointI.cpp @@ -149,6 +149,21 @@ IceInternal::UdpEndpointI::datagram() const return true; } +shared_ptr +IceInternal::UdpEndpointI::toPublishedEndpoint(string publishedHost) const +{ + return make_shared( + _instance, + publishedHost.empty() ? _host : publishedHost, + _port, + Address{}, + "", + -1, + false, // for "connect" + "", + _compress); +} + TransceiverPtr IceInternal::UdpEndpointI::transceiver() const { diff --git a/cpp/src/Ice/UdpEndpointI.h b/cpp/src/Ice/UdpEndpointI.h index 6ed878787bf..ac5454719f3 100644 --- a/cpp/src/Ice/UdpEndpointI.h +++ b/cpp/src/Ice/UdpEndpointI.h @@ -41,6 +41,8 @@ namespace IceInternal EndpointIPtr compress(bool) const final; bool datagram() const final; + std::shared_ptr toPublishedEndpoint(std::string publishedHost) const final; + TransceiverPtr transceiver() const final; AcceptorPtr acceptor(const std::string&, const std::optional&) const final; diff --git a/cpp/src/Ice/WSEndpoint.cpp b/cpp/src/Ice/WSEndpoint.cpp index 24fd77a7b7e..af7e0e85276 100644 --- a/cpp/src/Ice/WSEndpoint.cpp +++ b/cpp/src/Ice/WSEndpoint.cpp @@ -281,9 +281,9 @@ IceInternal::WSEndpoint::isLoopbackOrMulticast() const } shared_ptr -IceInternal::WSEndpoint::withPublishedHost(string host) const +IceInternal::WSEndpoint::toPublishedEndpoint(string publishedHost) const { - return endpoint(_delegate->withPublishedHost(std::move(host))); + return endpoint(_delegate->toPublishedEndpoint(std::move(publishedHost))); } bool diff --git a/cpp/src/Ice/WSEndpoint.h b/cpp/src/Ice/WSEndpoint.h index 2dd0d055bb9..69485e656cf 100644 --- a/cpp/src/Ice/WSEndpoint.h +++ b/cpp/src/Ice/WSEndpoint.h @@ -48,7 +48,7 @@ namespace IceInternal acceptor(const std::string&, const std::optional&) const final; std::vector expandHost() const final; bool isLoopbackOrMulticast() const final; - std::shared_ptr withPublishedHost(std::string host) const final; + std::shared_ptr toPublishedEndpoint(std::string publishedHost) const final; bool equivalent(const EndpointIPtr&) const final; std::size_t hash() const noexcept final; std::string options() const final; diff --git a/cpp/src/Ice/ios/iAPEndpointI.h b/cpp/src/Ice/ios/iAPEndpointI.h index 1443a3bd4ef..b417c05c149 100644 --- a/cpp/src/Ice/ios/iAPEndpointI.h +++ b/cpp/src/Ice/ios/iAPEndpointI.h @@ -56,7 +56,7 @@ namespace IceObjC acceptor(const std::string&, const std::optional&) const final; std::vector expandHost() const final; bool isLoopbackOrMulticast() const final; - std::shared_ptr withPublishedHost(std::string host) const final; + std::shared_ptr toPublishedEndpoint(std::string publishedHost) const final; bool equivalent(const IceInternal::EndpointIPtr&) const final; bool operator==(const Ice::Endpoint&) const final; diff --git a/cpp/src/Ice/ios/iAPEndpointI.mm b/cpp/src/Ice/ios/iAPEndpointI.mm index 15c9acd61af..41eb028ec99 100644 --- a/cpp/src/Ice/ios/iAPEndpointI.mm +++ b/cpp/src/Ice/ios/iAPEndpointI.mm @@ -315,7 +315,7 @@ ICEIAP_API void registerIceIAP(bool loadOnInitialize) } shared_ptr -IceObjC::iAPEndpointI::withPublishedHost(string) const +IceObjC::iAPEndpointI::toPublishedEndpoint(string) const { return const_cast(this)->shared_from_this(); } diff --git a/cpp/src/IceBT/EndpointI.cpp b/cpp/src/IceBT/EndpointI.cpp index 31a51ba1336..4dafb2640a3 100644 --- a/cpp/src/IceBT/EndpointI.cpp +++ b/cpp/src/IceBT/EndpointI.cpp @@ -204,7 +204,7 @@ IceBT::EndpointI::isLoopbackOrMulticast() const } shared_ptr -IceBT::EndpointI::withPublishedHost(string) const +IceBT::EndpointI::toPublishedEndpoint(string) const { return const_cast(this)->shared_from_this(); } diff --git a/cpp/src/IceBT/EndpointI.h b/cpp/src/IceBT/EndpointI.h index be8f5c9f64d..5a94aa11f63 100644 --- a/cpp/src/IceBT/EndpointI.h +++ b/cpp/src/IceBT/EndpointI.h @@ -49,7 +49,7 @@ namespace IceBT acceptor(const std::string&, const std::optional&) const final; std::vector expandHost() const final; bool isLoopbackOrMulticast() const final; - std::shared_ptr withPublishedHost(std::string host) const final; + std::shared_ptr toPublishedEndpoint(std::string publishedHost) const final; bool equivalent(const IceInternal::EndpointIPtr&) const final; bool operator==(const Ice::Endpoint&) const final; diff --git a/cpp/test/Ice/background/EndpointI.cpp b/cpp/test/Ice/background/EndpointI.cpp index b7ed2a78a70..f339589f25d 100644 --- a/cpp/test/Ice/background/EndpointI.cpp +++ b/cpp/test/Ice/background/EndpointI.cpp @@ -206,9 +206,9 @@ EndpointI::isLoopbackOrMulticast() const } shared_ptr -EndpointI::withPublishedHost(string host) const +EndpointI::toPublishedEndpoint(string publishedHost) const { - return endpoint(_endpoint->withPublishedHost(std::move(host))); + return endpoint(_endpoint->toPublishedEndpoint(std::move(publishedHost))); } bool diff --git a/cpp/test/Ice/background/EndpointI.h b/cpp/test/Ice/background/EndpointI.h index 300f025c1c8..41bd61b0c13 100644 --- a/cpp/test/Ice/background/EndpointI.h +++ b/cpp/test/Ice/background/EndpointI.h @@ -36,7 +36,7 @@ class EndpointI final : public IceInternal::EndpointI, public std::enable_shared acceptor(const std::string&, const std::optional&) const final; std::vector expandHost() const final; bool isLoopbackOrMulticast() const final; - std::shared_ptr withPublishedHost(std::string host) const final; + std::shared_ptr toPublishedEndpoint(std::string publishedHost) const final; bool equivalent(const IceInternal::EndpointIPtr&) const final; // From TestEndpoint diff --git a/cpp/test/Ice/info/AllTests.cpp b/cpp/test/Ice/info/AllTests.cpp index dcc61f52245..87cd0e2997b 100644 --- a/cpp/test/Ice/info/AllTests.cpp +++ b/cpp/test/Ice/info/AllTests.cpp @@ -109,7 +109,9 @@ allTests(Test::TestHelper* helper) Ice::EndpointSeq endpoints = adapter->getEndpoints(); test(endpoints.size() == 2); Ice::EndpointSeq publishedEndpoints = adapter->getPublishedEndpoints(); - test(endpoints == publishedEndpoints); + test(publishedEndpoints.size() == 2); + test(*endpoints[0] == *publishedEndpoints[0]); + test(*endpoints[1] == *publishedEndpoints[1]); Ice::TCPEndpointInfoPtr ipEndpoint = getTCPEndpointInfo(endpoints[0]->getInfo()); test(ipEndpoint); @@ -130,7 +132,8 @@ allTests(Test::TestHelper* helper) test(endpoints.size() == 1); adapter->setPublishedEndpoints(endpoints); publishedEndpoints = adapter->getPublishedEndpoints(); - test(endpoints == publishedEndpoints); + test(publishedEndpoints.size() == 1); + test(*endpoints[0] == *publishedEndpoints[0]); adapter->destroy(); From fd4e6952900b04585d51ddfdda03509c3e8f92ad Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Fri, 22 Nov 2024 12:08:56 -0500 Subject: [PATCH 4/5] Simplify TcpEndpointI --- cpp/src/Ice/TcpEndpointI.cpp | 14 +++++--------- csharp/src/Ice/Internal/TcpEndpointI.cs | 14 +++++--------- .../src/main/java/com/zeroc/Ice/TcpEndpointI.java | 13 ++++--------- 3 files changed, 14 insertions(+), 27 deletions(-) diff --git a/cpp/src/Ice/TcpEndpointI.cpp b/cpp/src/Ice/TcpEndpointI.cpp index bf7897f9f8b..aa8a29cb082 100644 --- a/cpp/src/Ice/TcpEndpointI.cpp +++ b/cpp/src/Ice/TcpEndpointI.cpp @@ -125,20 +125,16 @@ IceInternal::TcpEndpointI::datagram() const shared_ptr IceInternal::TcpEndpointI::toPublishedEndpoint(string publishedHost) const { - if (publishedHost.empty() && !isAddressValid(_sourceAddr) && _connectionId.empty()) + // A server endpoint can't have a source address or connection ID. + assert(!isAddressValid(_sourceAddr) && _connectionId.empty()); + + if (publishedHost.empty()) { return const_cast(this)->shared_from_this(); } else { - return make_shared( - _instance, - publishedHost.empty() ? _host : publishedHost, - _port, - Address{}, - _timeout, - "", - _compress); + return make_shared(_instance, publishedHost, _port, Address{}, _timeout, "", _compress); } } diff --git a/csharp/src/Ice/Internal/TcpEndpointI.cs b/csharp/src/Ice/Internal/TcpEndpointI.cs index 415f831e5e2..e79578fad93 100644 --- a/csharp/src/Ice/Internal/TcpEndpointI.cs +++ b/csharp/src/Ice/Internal/TcpEndpointI.cs @@ -214,20 +214,16 @@ public override void fillEndpointInfo(Ice.IPEndpointInfo info) public override EndpointI toPublishedEndpoint(string publishedHost) { - if (publishedHost.Length == 0 && sourceAddr_ is null && connectionId_.Length == 0) + // A server endpoint can't have a source address or connection ID. + Debug.Assert(sourceAddr_ is null && connectionId_.Length == 0); + + if (publishedHost.Length == 0) { return this; } else { - return new TcpEndpointI( - instance_, - publishedHost.Length > 0 ? publishedHost : host_, - port_, - sourceAddr: null, - _timeout, - conId: "", - _compress); + return new TcpEndpointI(instance_, publishedHost, port_, sourceAddr: null, _timeout, conId: "", _compress); } } diff --git a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/TcpEndpointI.java b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/TcpEndpointI.java index eb2671983bf..d5d29ca3c51 100644 --- a/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/TcpEndpointI.java +++ b/java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/TcpEndpointI.java @@ -215,17 +215,12 @@ public int hashCode() { @Override public EndpointI toPublishedEndpoint(String publishedHost) { - if (publishedHost.isEmpty() && _sourceAddr == null && _connectionId.isEmpty()) { + // A server endpoint can't have a source address or connection ID. + assert (_sourceAddr == null && _connectionId.isEmpty()); + if (publishedHost.isEmpty()) { return this; } else { - return new TcpEndpointI( - _instance, - publishedHost.isEmpty() ? _host : publishedHost, - _port, - null, - _timeout, - "", - _compress); + return new TcpEndpointI(_instance, publishedHost, _port, null, _timeout, "", _compress); } } From fc12695727c184ec7ca8da6e25340aa2456d4ad1 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Fri, 22 Nov 2024 14:19:24 -0500 Subject: [PATCH 5/5] Reformat --- csharp/src/Ice/Internal/TcpEndpointI.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csharp/src/Ice/Internal/TcpEndpointI.cs b/csharp/src/Ice/Internal/TcpEndpointI.cs index e79578fad93..2163e103193 100644 --- a/csharp/src/Ice/Internal/TcpEndpointI.cs +++ b/csharp/src/Ice/Internal/TcpEndpointI.cs @@ -223,7 +223,7 @@ public override EndpointI toPublishedEndpoint(string publishedHost) } else { - return new TcpEndpointI(instance_, publishedHost, port_, sourceAddr: null, _timeout, conId: "", _compress); + return new TcpEndpointI(instance_, publishedHost, port_, sourceAddr: null, _timeout, conId: "", _compress); } }