From 8a1794f3052a743290755e711c6866f6fcecca03 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Sun, 17 Nov 2024 17:20:42 -0500 Subject: [PATCH 1/2] Fix colloc and IPv6 --- .../main/java/com/zeroc/Ice/IPEndpointI.java | 38 +++++++++++-------- scripts/Util.py | 4 +- 2 files changed, 23 insertions(+), 19 deletions(-) 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 ab55f4358be..50f12073548 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 @@ -4,6 +4,7 @@ package com.zeroc.Ice; +import java.net.InetAddress; import java.util.Collections; abstract class IPEndpointI extends EndpointI { @@ -14,26 +15,18 @@ protected IPEndpointI( java.net.InetSocketAddress sourceAddr, String connectionId) { _instance = instance; - _host = host; + _host = 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 @@ -113,9 +106,8 @@ public java.util.List expandHost() { var result = new java.util.ArrayList(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; @@ -140,6 +132,7 @@ public boolean equivalent(EndpointI endpoint) { if (!(endpoint instanceof IPEndpointI)) { return false; } + IPEndpointI ipEndpointI = (IPEndpointI) endpoint; return ipEndpointI.type() == type() && ipEndpointI._host.equals(_host) @@ -258,7 +251,7 @@ public void initWithOptions(java.util.ArrayList args, boolean oaEndpoint super.initWithOptions(args); if (_host == null || _host.isEmpty()) { - _host = _instance.defaultHost(); + _host = normalizeHost(_instance.defaultHost()); } else if (_host.equals("*")) { if (oaEndpoint) { _host = ""; @@ -289,7 +282,7 @@ protected boolean checkOption(String option, String argument, String endpoint) { throw new ParseException( "no argument provided for -h option in endpoint '" + endpoint + "'"); } - _host = argument; + _host = normalizeHost(argument); } else if (option.equals("-p")) { if (argument == null) { throw new ParseException( @@ -331,6 +324,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); diff --git a/scripts/Util.py b/scripts/Util.py index cd9abc87fe9..48f6266a857 100644 --- a/scripts/Util.py +++ b/scripts/Util.py @@ -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 From 2c491b508f0a6dcc3d55c0d3e0a33a3db2a63380 Mon Sep 17 00:00:00 2001 From: Bernard Normier Date: Sun, 17 Nov 2024 18:50:12 -0500 Subject: [PATCH 2/2] Fix cross-test failure --- .../main/java/com/zeroc/Ice/IPEndpointI.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) 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 50f12073548..f83fd495882 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 @@ -15,7 +15,8 @@ protected IPEndpointI( java.net.InetSocketAddress sourceAddr, String connectionId) { _instance = instance; - _host = normalizeHost(host); + _host = host; + _normalizedHost = normalizeHost(host); _port = port; _sourceAddr = sourceAddr; _connectionId = connectionId; @@ -135,7 +136,7 @@ public boolean equivalent(EndpointI endpoint) { 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); } @@ -247,14 +248,16 @@ public void fillEndpointInfo(IPEndpointInfo info) { info.sourceAddress = _sourceAddr == null ? "" : _sourceAddr.getAddress().getHostAddress(); } - public void initWithOptions(java.util.ArrayList args, boolean oaEndpoint) { + void initWithOptions(java.util.ArrayList args, boolean oaEndpoint) { super.initWithOptions(args); if (_host == null || _host.isEmpty()) { - _host = normalizeHost(_instance.defaultHost()); + _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() + "'"); @@ -263,6 +266,7 @@ public void initWithOptions(java.util.ArrayList args, boolean oaEndpoint if (_host == null) { _host = ""; + _normalizedHost = ""; } if (_sourceAddr == null) { @@ -282,7 +286,8 @@ protected boolean checkOption(String option, String argument, String endpoint) { throw new ParseException( "no argument provided for -h option in endpoint '" + endpoint + "'"); } - _host = normalizeHost(argument); + _host = argument; + _normalizedHost = normalizeHost(argument); } else if (option.equals("-p")) { if (argument == null) { throw new ParseException( @@ -347,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; }