Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear local options from computed published endpoints #3178

Merged
merged 5 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions cpp/src/Ice/EndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<EndpointI> 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<EndpointI> toPublishedEndpoint(std::string publishedHost) const = 0;

//
// Check whether the endpoint is equivalent to another one.
//
Expand Down
6 changes: 0 additions & 6 deletions cpp/src/Ice/IPEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,6 @@ IceInternal::IPEndpointI::isLoopbackOrMulticast() const
return _host.empty() ? false : isLoopbackOrMulticastAddress(_host);
}

shared_ptr<EndpointI>
IceInternal::IPEndpointI::withPublishedHost(string host) const
{
return createEndpoint(host, _port, _connectionId);
}

bool
IceInternal::IPEndpointI::equivalent(const EndpointIPtr& endpoint) const
{
Expand Down
1 change: 0 additions & 1 deletion cpp/src/Ice/IPEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ namespace IceInternal
std::function<void(std::exception_ptr)>) const override;
std::vector<EndpointIPtr> expandHost() const override;
bool isLoopbackOrMulticast() const override;
std::shared_ptr<EndpointI> withPublishedHost(std::string host) const override;
bool equivalent(const EndpointIPtr&) const override;
std::size_t hash() const noexcept override;
std::string options() const override;
Expand Down
27 changes: 12 additions & 15 deletions cpp/src/Ice/ObjectAdapterI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1214,25 +1214,22 @@ ObjectAdapterI::computePublishedEndpoints()
}
// else keep endpoints as-is; they are all loopback or multicast

if (!publishedHost.empty())
{
vector<EndpointIPtr> newEndpoints;
vector<EndpointIPtr> 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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/OpaqueEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ IceInternal::OpaqueEndpointI::isLoopbackOrMulticast() const
}

shared_ptr<EndpointI>
IceInternal::OpaqueEndpointI::withPublishedHost(string) const
IceInternal::OpaqueEndpointI::toPublishedEndpoint(string) const
{
return const_cast<OpaqueEndpointI*>(this)->shared_from_this();
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/OpaqueEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ namespace IceInternal
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<EndpointIPtr> expandHost() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<EndpointI> withPublishedHost(std::string host) const final;
std::shared_ptr<EndpointI> toPublishedEndpoint(std::string publishedHost) const final;
bool equivalent(const EndpointIPtr&) const final;
std::size_t hash() const noexcept final;
std::string options() const final;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/Ice/SSL/SSLEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,9 @@ Ice::SSL::EndpointI::isLoopbackOrMulticast() const
}

shared_ptr<IceInternal::EndpointI>
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
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/SSL/SSLEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace Ice::SSL
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<IceInternal::EndpointIPtr> expandHost() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<IceInternal::EndpointI> withPublishedHost(std::string host) const final;
std::shared_ptr<IceInternal::EndpointI> 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;
Expand Down
16 changes: 16 additions & 0 deletions cpp/src/Ice/TcpEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ IceInternal::TcpEndpointI::datagram() const
return false;
}

shared_ptr<EndpointI>
IceInternal::TcpEndpointI::toPublishedEndpoint(string publishedHost) const
{
// A server endpoint can't have a source address or connection ID.
assert(!isAddressValid(_sourceAddr) && _connectionId.empty());

if (publishedHost.empty())
{
return const_cast<TcpEndpointI*>(this)->shared_from_this();
}
else
{
return make_shared<TcpEndpointI>(_instance, publishedHost, _port, Address{}, _timeout, "", _compress);
}
}

TransceiverPtr
IceInternal::TcpEndpointI::transceiver() const
{
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/Ice/TcpEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ namespace IceInternal
EndpointIPtr compress(bool) const final;
bool datagram() const final;

std::shared_ptr<EndpointI> toPublishedEndpoint(std::string publishedHost) const final;

TransceiverPtr transceiver() const final;
AcceptorPtr
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
Expand Down
15 changes: 15 additions & 0 deletions cpp/src/Ice/UdpEndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ IceInternal::UdpEndpointI::datagram() const
return true;
}

shared_ptr<EndpointI>
IceInternal::UdpEndpointI::toPublishedEndpoint(string publishedHost) const
{
return make_shared<UdpEndpointI>(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not reuse current endpoint like in tcp, is it never possible?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible, but requires more code/complexity, and there is no benefit since we don't compute these published endpoints often.

_instance,
publishedHost.empty() ? _host : publishedHost,
_port,
Address{},
"",
-1,
false, // for "connect"
"",
_compress);
}

TransceiverPtr
IceInternal::UdpEndpointI::transceiver() const
{
Expand Down
2 changes: 2 additions & 0 deletions cpp/src/Ice/UdpEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ namespace IceInternal
EndpointIPtr compress(bool) const final;
bool datagram() const final;

std::shared_ptr<EndpointI> toPublishedEndpoint(std::string publishedHost) const final;

TransceiverPtr transceiver() const final;
AcceptorPtr
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/Ice/WSEndpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ IceInternal::WSEndpoint::isLoopbackOrMulticast() const
}

shared_ptr<EndpointI>
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
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/WSEndpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace IceInternal
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<EndpointIPtr> expandHost() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<EndpointI> withPublishedHost(std::string host) const final;
std::shared_ptr<EndpointI> toPublishedEndpoint(std::string publishedHost) const final;
bool equivalent(const EndpointIPtr&) const final;
std::size_t hash() const noexcept final;
std::string options() const final;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/ios/iAPEndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace IceObjC
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<IceInternal::EndpointIPtr> expandHost() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<EndpointI> withPublishedHost(std::string host) const final;
std::shared_ptr<EndpointI> toPublishedEndpoint(std::string publishedHost) const final;
bool equivalent(const IceInternal::EndpointIPtr&) const final;

bool operator==(const Ice::Endpoint&) const final;
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/Ice/ios/iAPEndpointI.mm
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ ICEIAP_API void registerIceIAP(bool loadOnInitialize)
}

shared_ptr<EndpointI>
IceObjC::iAPEndpointI::withPublishedHost(string) const
IceObjC::iAPEndpointI::toPublishedEndpoint(string) const
{
return const_cast<iAPEndpointI*>(this)->shared_from_this();
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/IceBT/EndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ IceBT::EndpointI::isLoopbackOrMulticast() const
}

shared_ptr<IceInternal::EndpointI>
IceBT::EndpointI::withPublishedHost(string) const
IceBT::EndpointI::toPublishedEndpoint(string) const
{
return const_cast<EndpointI*>(this)->shared_from_this();
}
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/IceBT/EndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace IceBT
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<IceInternal::EndpointIPtr> expandHost() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<IceInternal::EndpointI> withPublishedHost(std::string host) const final;
std::shared_ptr<IceInternal::EndpointI> toPublishedEndpoint(std::string publishedHost) const final;
bool equivalent(const IceInternal::EndpointIPtr&) const final;

bool operator==(const Ice::Endpoint&) const final;
Expand Down
4 changes: 2 additions & 2 deletions cpp/test/Ice/background/EndpointI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,9 @@ EndpointI::isLoopbackOrMulticast() const
}

shared_ptr<IceInternal::EndpointI>
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
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/Ice/background/EndpointI.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class EndpointI final : public IceInternal::EndpointI, public std::enable_shared
acceptor(const std::string&, const std::optional<Ice::SSL::ServerAuthenticationOptions>&) const final;
std::vector<IceInternal::EndpointIPtr> expandHost() const final;
bool isLoopbackOrMulticast() const final;
std::shared_ptr<IceInternal::EndpointI> withPublishedHost(std::string host) const final;
std::shared_ptr<IceInternal::EndpointI> toPublishedEndpoint(std::string publishedHost) const final;
bool equivalent(const IceInternal::EndpointIPtr&) const final;

// From TestEndpoint
Expand Down
7 changes: 5 additions & 2 deletions cpp/test/Ice/info/AllTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions csharp/src/Ice/Internal/EndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 1 addition & 4 deletions csharp/src/Ice/Internal/IPEndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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_;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed sourceAddr from this equivalent comparison in C# and Java; in C++, we didn't check sourceAddr.

}

public virtual List<Connector> connectors(List<EndPoint> addresses, NetworkProxy proxy)
Expand Down
2 changes: 1 addition & 1 deletion csharp/src/Ice/Internal/OpaqueEndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions csharp/src/Ice/Internal/TcpEndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,21 @@ public override void fillEndpointInfo(Ice.IPEndpointInfo info)
info.compress = _compress;
}

public override EndpointI toPublishedEndpoint(string publishedHost)
{
// 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, port_, sourceAddr: null, _timeout, conId: "", _compress);
}
}

protected override bool checkOption(string option, string argument, string endpoint)
{
if (base.checkOption(option, argument, endpoint))
Expand Down
12 changes: 12 additions & 0 deletions csharp/src/Ice/Internal/UdpEndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion csharp/src/Ice/Internal/WSEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,8 @@ public override List<EndpointI> 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)
{
Expand Down
8 changes: 2 additions & 6 deletions csharp/src/Ice/ObjectAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
3 changes: 2 additions & 1 deletion csharp/src/Ice/SSL/EndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
3 changes: 2 additions & 1 deletion csharp/test/Ice/background/EndpointI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Loading
Loading