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

Fix colloc and IPv6 #3161

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
44 changes: 29 additions & 15 deletions java/src/com.zeroc.ice/src/main/java/com/zeroc/Ice/IPEndpointI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package com.zeroc.Ice;

import java.net.InetAddress;
import java.util.Collections;

abstract class IPEndpointI extends EndpointI {
Expand All @@ -15,25 +16,18 @@ protected IPEndpointI(
String connectionId) {
_instance = instance;
_host = host;
_normalizedHost = normalizeHost(host);
_port = port;
_sourceAddr = sourceAddr;
_connectionId = connectionId;
}

protected IPEndpointI(ProtocolInstance instance) {
_instance = instance;
_host = null;
_port = 0;
_sourceAddr = null;
_connectionId = "";
this(instance, null, 0, null, "");
}

protected IPEndpointI(ProtocolInstance instance, InputStream s) {
_instance = instance;
_host = s.readString();
_port = s.readInt();
_sourceAddr = null;
_connectionId = "";
this(instance, s.readString(), s.readInt(), null, "");
}

@Override
Expand Down Expand Up @@ -113,9 +107,8 @@ public java.util.List<EndpointI> expandHost() {

var result = new java.util.ArrayList<EndpointI>(addresses.size());
for (java.net.InetSocketAddress addr : addresses) {
result.add(
createEndpoint(
addr.getAddress().getHostAddress(), addr.getPort(), _connectionId));
String host = addr.getAddress().getHostAddress();
result.add(createEndpoint(host, addr.getPort(), _connectionId));
}

return result;
Expand All @@ -140,9 +133,10 @@ public boolean equivalent(EndpointI endpoint) {
if (!(endpoint instanceof IPEndpointI)) {
return false;
}

IPEndpointI ipEndpointI = (IPEndpointI) endpoint;
return ipEndpointI.type() == type()
&& ipEndpointI._host.equals(_host)
&& ipEndpointI._normalizedHost.equals(_normalizedHost)
&& ipEndpointI._port == _port
&& java.util.Objects.equals(ipEndpointI._sourceAddr, _sourceAddr);
}
Expand Down Expand Up @@ -254,14 +248,16 @@ public void fillEndpointInfo(IPEndpointInfo info) {
info.sourceAddress = _sourceAddr == null ? "" : _sourceAddr.getAddress().getHostAddress();
}

public void initWithOptions(java.util.ArrayList<String> args, boolean oaEndpoint) {
void initWithOptions(java.util.ArrayList<String> args, boolean oaEndpoint) {
super.initWithOptions(args);

if (_host == null || _host.isEmpty()) {
_host = _instance.defaultHost();
_normalizedHost = normalizeHost(_host);
} else if (_host.equals("*")) {
if (oaEndpoint) {
_host = "";
_normalizedHost = "";
} else {
throw new ParseException(
"'-h *' not valid for proxy endpoint '" + toString() + "'");
Expand All @@ -270,6 +266,7 @@ public void initWithOptions(java.util.ArrayList<String> args, boolean oaEndpoint

if (_host == null) {
_host = "";
_normalizedHost = "";
}

if (_sourceAddr == null) {
Expand All @@ -290,6 +287,7 @@ protected boolean checkOption(String option, String argument, String endpoint) {
"no argument provided for -h option in endpoint '" + endpoint + "'");
}
_host = argument;
_normalizedHost = normalizeHost(argument);
} else if (option.equals("-p")) {
if (argument == null) {
throw new ParseException(
Expand Down Expand Up @@ -331,6 +329,19 @@ protected boolean checkOption(String option, String argument, String endpoint) {
return true;
}

private String normalizeHost(String host) {
if (host != null && host.contains(":")) {
// Could be an IPv6 address that we need to normalize.
try {
var address = InetAddress.getByName(host);
host = address.getHostAddress(); // normalized host
} catch (java.net.UnknownHostException ex) {
// Ignore - don't normalize host.
}
}
return host;
}

protected abstract Connector createConnector(
java.net.InetSocketAddress addr, NetworkProxy proxy);

Expand All @@ -341,4 +352,7 @@ protected abstract Connector createConnector(
protected int _port;
protected java.net.InetSocketAddress _sourceAddr;
protected final String _connectionId;

// Set when we set _host; used by the implementation of equivalent.
private String _normalizedHost;
}
4 changes: 1 addition & 3 deletions scripts/Util.py
Original file line number Diff line number Diff line change
Expand Up @@ -3437,9 +3437,7 @@ def getProps(self, process, current):
props = {}
if isinstance(process, IceProcess):
if not self.host:
props["Ice.Default.Host"] = (
"0:0:0:0:0:0:0:1" if current.config.ipv6 else "127.0.0.1"
)
props["Ice.Default.Host"] = ("::1" if current.config.ipv6 else "127.0.0.1")
else:
props["Ice.Default.Host"] = self.host
return props
Expand Down