You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2020/12/18 07:14:21 UTC

[GitHub] [ignite] vkozhukhova opened a new pull request #8591: IGNITE-13555 Added support for IPv6 addresses in Java thin

vkozhukhova opened a new pull request #8591:
URL: https://github.com/apache/ignite/pull/8591


   - changed HostAndPortRange.parse method to support addresses like [IPv6_host]:port1..port2, because previous implementation didn't recognized IPv6;
   - implemented unit tests for HostAndPortRange.parse method for both IPv4 and IPv6 hosts.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vkozhukhova commented on a change in pull request #8591: IGNITE-13555 Added support for IPv6 addresses in Java thin

Posted by GitBox <gi...@apache.org>.
vkozhukhova commented on a change in pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#discussion_r547763530



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +53,89 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
+        if (addrStr.contains("[")) { // IPv6
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 host is incorrect");
+            }
+            host = addrStr.substring(1, hostEndIdx);

Review comment:
       Now it checks for `addrStr.charAt(0) == '['`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vkozhukhova commented on a change in pull request #8591: IGNITE-13555 Added support for IPv6 addresses in Java thin

Posted by GitBox <gi...@apache.org>.
vkozhukhova commented on a change in pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#discussion_r547765496



##########
File path: modules/core/src/test/java/org/apache/ignite/internal/util/HostAndPortRangeTest.java
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.util;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class HostAndPortRangeTest {

Review comment:
       Fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vkozhukhova commented on a change in pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
vkozhukhova commented on a change in pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#discussion_r548440559



##########
File path: modules/core/src/test/java/org/apache/ignite/internal/util/HostAndPortRangeTest.java
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.util;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+/**
+ * Tests HostAndPortRange parse method.
+ */
+@GridCommonTest(group = "Utils")
+public class HostAndPortRangeTest extends GridCommonAbstractTest {
+

Review comment:
       Removed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vkozhukhova commented on pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
vkozhukhova commented on pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#issuecomment-751233634


   @ptupitsyn It fails on TC with `java.net.SocketException: Protocol family unavailable`


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vkozhukhova commented on a change in pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
vkozhukhova commented on a change in pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#discussion_r548440670



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");

Review comment:
       Corrected.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {

Review comment:
       Fixed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vkozhukhova commented on pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
vkozhukhova commented on pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#issuecomment-751273570


   Ok, I'll mark it with `@Ignore` for now.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vkozhukhova commented on a change in pull request #8591: IGNITE-13555 Added support for IPv6 addresses in Java thin

Posted by GitBox <gi...@apache.org>.
vkozhukhova commented on a change in pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#discussion_r547762709



##########
File path: modules/core/src/test/java/org/apache/ignite/internal/util/HostAndPortRangeTest.java
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.util;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class HostAndPortRangeTest {
+
+    /**
+     * tests correct input address with IPv4 host and port range.
+     * @throws IgniteCheckedException on incorrect host/port
+     */
+    @Test
+    public void testParseIPv4WithPortRange() throws IgniteCheckedException {
+        String addrStr = "127.0.0.1:8080..8090";
+        String errMsgPrefix = "";
+        int dfltPortFrom = 18360;
+        int dfltPortTo = 18362;
+        HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix);
+        HostAndPortRange expected = new HostAndPortRange("127.0.0.1", 8080, 8090);
+        assertEquals(expected, actual);
+    }
+
+    /**
+     * tests correct input address with IPv4 host and single port.
+     * @throws IgniteCheckedException on incorrect host/port
+     */
+    @Test
+    public void testParseIPv4WithSinglePort() throws IgniteCheckedException {
+        String addrStr = "127.0.0.1:8080";
+        String errMsgPrefix = "";
+        int dfltPortFrom = 18360;
+        int dfltPortTo = 18362;
+        HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix);
+        HostAndPortRange expected = new HostAndPortRange("127.0.0.1", 8080, 8080);
+        assertEquals(expected, actual);
+    }
+
+    /**
+     * ests correct input address with IPv4 host and no port.
+     * @throws IgniteCheckedException on incorrect host/port
+     */
+    @Test
+    public void testParseIPv4NoPort() throws IgniteCheckedException {
+        String addrStr = "127.0.0.1";
+        String errMsgPrefix = "";
+        int dfltPortFrom = 18360;
+        int dfltPortTo = 18362;
+        HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix);
+        HostAndPortRange expected = new HostAndPortRange("127.0.0.1", 18360, 18362);
+        assertEquals(expected, actual);
+    }
+
+    /**
+     * tests correct input address with IPv6 host and port range.
+     * @throws IgniteCheckedException on incorrect host/port
+     */
+    @Test
+    public void testParseIPv6WithPortRange() throws IgniteCheckedException {
+        String addrStr = "[::1]:8080..8090";
+        String errMsgPrefix = "";
+        int dfltPortFrom = 18360;
+        int dfltPortTo = 18362;
+        HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix);
+        HostAndPortRange expected = new HostAndPortRange("::1", 8080, 8090);
+        assertEquals(expected, actual);
+    }
+
+    /**
+     * tests correct input address with IPv6 host and single port.
+     * @throws IgniteCheckedException on incorrect host/port
+     */
+    @Test
+    public void testParseIPv6WithSinglePort() throws IgniteCheckedException {
+        String addrStr = "[3ffe:2a00:100:7031::]:8080";
+        String errMsgPrefix = "";
+        int dfltPortFrom = 18360;
+        int dfltPortTo = 18362;
+        HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix);
+        HostAndPortRange expected = new HostAndPortRange("3ffe:2a00:100:7031::", 8080, 8080);
+        assertEquals(expected, actual);
+    }
+
+    /**
+     * tests correct input address with IPv6 host and no port.
+     * @throws IgniteCheckedException on incorrect host/port
+     */
+    @Test
+    public void testParseIPv6NoPort() throws IgniteCheckedException {
+        String addrStr = "[::FFFF:129.144.52.38]";
+        String errMsgPrefix = "";
+        int dfltPortFrom = 18360;
+        int dfltPortTo = 18362;
+        HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix);
+        HostAndPortRange expected = new HostAndPortRange("::FFFF:129.144.52.38", 18360, 18362);
+        assertEquals(expected, actual);
+    }
+
+    /**
+     * tests incorrect input address with IPv6 host (no brackets) and port.
+     * @throws IgniteCheckedException on incorrect host/port
+     */
+    @Test(expected = IgniteCheckedException.class)

Review comment:
       Done




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vkozhukhova commented on a change in pull request #8591: IGNITE-13555 Added support for IPv6 addresses in Java thin

Posted by GitBox <gi...@apache.org>.
vkozhukhova commented on a change in pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#discussion_r547765317



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +53,89 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
+        if (addrStr.contains("[")) { // IPv6

Review comment:
       Added the case where there is IPv6 without `[` and `]` and port(s)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vkozhukhova commented on pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
vkozhukhova commented on pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#issuecomment-750874924


   @ptupitsyn What should I do right now? I can add this test, it passes if I change host in LocalIgniteCluster to Ipv6 localhost))) but can you explain my further actions? P.S. I'm quite confused because I thought that this issue was only about parsing logic for client and now you talk about changes for server.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vkozhukhova commented on a change in pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
vkozhukhova commented on a change in pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#discussion_r548441662



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+            }
+            host = addrStr.substring(1, hostEndIdx);
+            if (hostEndIdx == addrStr.length() - 1) { // no port specified, using default
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            } else { // port specified
+                portStr = addrStr.substring(hostEndIdx + 2);
+
+                int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr);
+                portFrom = ports[0];
+                portTo = ports[1];
+            }
+        } else { //IPv4 || IPv6 without port || empty host
+            final int colIdx = addrStr.lastIndexOf(':');
+            if (colIdx > 0) {

Review comment:
       Added.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vkozhukhova commented on a change in pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
vkozhukhova commented on a change in pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#discussion_r548440866



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+            }
+            host = addrStr.substring(1, hostEndIdx);
+            if (hostEndIdx == addrStr.length() - 1) { // no port specified, using default
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            } else { // port specified
+                portStr = addrStr.substring(hostEndIdx + 2);
+
+                int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr);
+                portFrom = ports[0];
+                portTo = ports[1];
+            }
+        } else { //IPv4 || IPv6 without port || empty host
+            final int colIdx = addrStr.lastIndexOf(':');
+            if (colIdx > 0) {
+                if (addrStr.substring(0, colIdx).contains(":")) { // IPv6 without [] and port
+                    try {
+                        Inet6Address.getByName(addrStr);
+                        host = addrStr;
+                        portFrom = dfltPortFrom;
+                        portTo = dfltPortTo;
+                    }
+                    catch (UnknownHostException e) {
+                        throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+                    }
+                }
+                else {
+                    host = addrStr.substring(0, colIdx);
+                    portStr = addrStr.substring(colIdx + 1);
+                    int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr);
+                    portFrom = ports[0];
+                    portTo = ports[1];
+                }
+            } else if (colIdx == 0) {
+                throw createParseError(addrStr, errMsgPrefix, "Host name is empty");
+            } else { // Port is not specified, use defaults.
+                host = addrStr;
 
-            host = addrStr.substring(0, colIdx);
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            }
+        }
 
-            String portStr = addrStr.substring(colIdx + 1, addrStr.length());
+        return new HostAndPortRange(host, portFrom, portTo);
+    }
 
-            if (F.isEmpty(portStr))
-                throw createParseError(addrStr, errMsgPrefix, "port range is not specified");
+    /**
+     *

Review comment:
       Added javadoc.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+            }
+            host = addrStr.substring(1, hostEndIdx);
+            if (hostEndIdx == addrStr.length() - 1) { // no port specified, using default
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            } else { // port specified
+                portStr = addrStr.substring(hostEndIdx + 2);
+
+                int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr);
+                portFrom = ports[0];
+                portTo = ports[1];
+            }
+        } else { //IPv4 || IPv6 without port || empty host
+            final int colIdx = addrStr.lastIndexOf(':');
+            if (colIdx > 0) {
+                if (addrStr.substring(0, colIdx).contains(":")) { // IPv6 without [] and port
+                    try {
+                        Inet6Address.getByName(addrStr);
+                        host = addrStr;
+                        portFrom = dfltPortFrom;
+                        portTo = dfltPortTo;
+                    }
+                    catch (UnknownHostException e) {
+                        throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+                    }
+                }
+                else {
+                    host = addrStr.substring(0, colIdx);
+                    portStr = addrStr.substring(colIdx + 1);
+                    int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr);
+                    portFrom = ports[0];
+                    portTo = ports[1];
+                }
+            } else if (colIdx == 0) {
+                throw createParseError(addrStr, errMsgPrefix, "Host name is empty");
+            } else { // Port is not specified, use defaults.
+                host = addrStr;
 
-            host = addrStr.substring(0, colIdx);
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            }
+        }
 
-            String portStr = addrStr.substring(colIdx + 1, addrStr.length());
+        return new HostAndPortRange(host, portFrom, portTo);
+    }
 
-            if (F.isEmpty(portStr))
-                throw createParseError(addrStr, errMsgPrefix, "port range is not specified");
+    /**
+     *
+     * @param addrStr Address String.
+     * @param errMsgPrefix Error message prefix.
+     * @param portStr Port or port range string.
+     * @return Array of int[portFrom, portTo].
+     * @throws IgniteCheckedException If failed.
+     */
 
-            int portRangeIdx = portStr.indexOf("..");
+    private static int[] verifyPortStr(String addrStr, String errMsgPrefix, String portStr) throws IgniteCheckedException {
+        String portFromStr;
+        String portToStr;
 
-            if (portRangeIdx >= 0) {
-                // Port range is specified.
-                portFromStr = portStr.substring(0, portRangeIdx);
-                portToStr = portStr.substring(portRangeIdx + 2, portStr.length());
-            }
-            else {
-                // Single port is specified.
-                portFromStr = portStr;
-                portToStr = portStr;
-            }
+        if (F.isEmpty(portStr))
+            throw createParseError(addrStr, errMsgPrefix, "port range is not specified");
 
-            portFrom = parsePort(portFromStr, addrStr, errMsgPrefix);
-            portTo = parsePort(portToStr, addrStr, errMsgPrefix);
+        int portRangeIdx = portStr.indexOf("..");
 
-            if (portFrom > portTo)
-                throw createParseError(addrStr, errMsgPrefix, "start port cannot be less than end port");
+        if (portRangeIdx >= 0) {
+            // Port range is specified.
+            portFromStr = portStr.substring(0, portRangeIdx);
+            portToStr = portStr.substring(portRangeIdx + 2);
         }
         else {
-            // Host name not specified.
-            if (colIdx == 0)
-                throw createParseError(addrStr, errMsgPrefix, "Host name is empty");
-
-            // Port is not specified, use defaults.
-            host = addrStr;
-
-            portFrom = dfltPortFrom;
-            portTo = dfltPortTo;
+            // Single port is specified.
+            portFromStr = portStr;
+            portToStr = portStr;
         }
 
-        if (F.isEmpty(host))
-            throw createParseError(addrStr, errMsgPrefix, "Host name is empty");
+        int portFrom = parsePort(portFromStr, addrStr, errMsgPrefix);
+        int portTo = parsePort(portToStr, addrStr, errMsgPrefix);
 
-        return new HostAndPortRange(host, portFrom, portTo);
+        if (portFrom > portTo)
+            throw createParseError(addrStr, errMsgPrefix, "start port cannot be less than end port");
+
+        return new int[]{portFrom, portTo};

Review comment:
       Added.

##########
File path: modules/core/src/test/java/org/apache/ignite/internal/util/HostAndPortRangeTest.java
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.util;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+/**
+ * Tests HostAndPortRange parse method.
+ */
+@GridCommonTest(group = "Utils")
+public class HostAndPortRangeTest extends GridCommonAbstractTest {
+
+    /**
+     * tests correct input address with IPv4 host and port range.

Review comment:
       Corrected.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ptupitsyn edited a comment on pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
ptupitsyn edited a comment on pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#issuecomment-751258763


   @vkozhukhova I see; actually, I had to enable IPv6 on my machine (Ubuntu 20) explicitly to make this test pass.
   So I propose to keep this test, but mark it with `@Ignore("IPv6 is not enabled by default on some systems.")`, so it can be executed manually.
   
   Alternatively, we can ask on the dev list whether TeamCity agents can be fixed.
   
   What do you think?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ptupitsyn commented on a change in pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on a change in pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#discussion_r548241712



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+            }
+            host = addrStr.substring(1, hostEndIdx);
+            if (hostEndIdx == addrStr.length() - 1) { // no port specified, using default
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            } else { // port specified

Review comment:
       Code style: `else` should start on a new line

##########
File path: modules/core/src/test/java/org/apache/ignite/internal/util/HostAndPortRangeTest.java
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.util;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+/**
+ * Tests HostAndPortRange parse method.
+ */
+@GridCommonTest(group = "Utils")
+public class HostAndPortRangeTest extends GridCommonAbstractTest {
+

Review comment:
       Redundant blank line

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+            }
+            host = addrStr.substring(1, hostEndIdx);
+            if (hostEndIdx == addrStr.length() - 1) { // no port specified, using default
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            } else { // port specified
+                portStr = addrStr.substring(hostEndIdx + 2);
+
+                int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr);
+                portFrom = ports[0];
+                portTo = ports[1];
+            }
+        } else { //IPv4 || IPv6 without port || empty host

Review comment:
       Code style: add space after `//`

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+            }
+            host = addrStr.substring(1, hostEndIdx);
+            if (hostEndIdx == addrStr.length() - 1) { // no port specified, using default
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            } else { // port specified
+                portStr = addrStr.substring(hostEndIdx + 2);
+
+                int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr);
+                portFrom = ports[0];
+                portTo = ports[1];
+            }
+        } else { //IPv4 || IPv6 without port || empty host
+            final int colIdx = addrStr.lastIndexOf(':');
+            if (colIdx > 0) {
+                if (addrStr.substring(0, colIdx).contains(":")) { // IPv6 without [] and port
+                    try {
+                        Inet6Address.getByName(addrStr);
+                        host = addrStr;
+                        portFrom = dfltPortFrom;
+                        portTo = dfltPortTo;
+                    }
+                    catch (UnknownHostException e) {
+                        throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+                    }
+                }
+                else {
+                    host = addrStr.substring(0, colIdx);
+                    portStr = addrStr.substring(colIdx + 1);
+                    int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr);
+                    portFrom = ports[0];
+                    portTo = ports[1];
+                }
+            } else if (colIdx == 0) {
+                throw createParseError(addrStr, errMsgPrefix, "Host name is empty");
+            } else { // Port is not specified, use defaults.
+                host = addrStr;
 
-            host = addrStr.substring(0, colIdx);
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            }
+        }
 
-            String portStr = addrStr.substring(colIdx + 1, addrStr.length());
+        return new HostAndPortRange(host, portFrom, portTo);
+    }
 
-            if (F.isEmpty(portStr))
-                throw createParseError(addrStr, errMsgPrefix, "port range is not specified");
+    /**
+     *

Review comment:
       Missing javadoc

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+            }
+            host = addrStr.substring(1, hostEndIdx);
+            if (hostEndIdx == addrStr.length() - 1) { // no port specified, using default
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            } else { // port specified
+                portStr = addrStr.substring(hostEndIdx + 2);
+
+                int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr);
+                portFrom = ports[0];
+                portTo = ports[1];
+            }
+        } else { //IPv4 || IPv6 without port || empty host
+            final int colIdx = addrStr.lastIndexOf(':');
+            if (colIdx > 0) {
+                if (addrStr.substring(0, colIdx).contains(":")) { // IPv6 without [] and port
+                    try {
+                        Inet6Address.getByName(addrStr);
+                        host = addrStr;
+                        portFrom = dfltPortFrom;
+                        portTo = dfltPortTo;
+                    }
+                    catch (UnknownHostException e) {
+                        throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");

Review comment:
       Pass `e` as `cause`.

##########
File path: modules/core/src/test/java/org/apache/ignite/internal/util/HostAndPortRangeTest.java
##########
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.util;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.testframework.junits.common.GridCommonTest;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+/**
+ * Tests HostAndPortRange parse method.
+ */
+@GridCommonTest(group = "Utils")
+public class HostAndPortRangeTest extends GridCommonAbstractTest {
+
+    /**
+     * tests correct input address with IPv4 host and port range.

Review comment:
       Comments should start with a capital letter

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+            }
+            host = addrStr.substring(1, hostEndIdx);
+            if (hostEndIdx == addrStr.length() - 1) { // no port specified, using default
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            } else { // port specified
+                portStr = addrStr.substring(hostEndIdx + 2);
+
+                int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr);
+                portFrom = ports[0];
+                portTo = ports[1];
+            }
+        } else { //IPv4 || IPv6 without port || empty host
+            final int colIdx = addrStr.lastIndexOf(':');
+            if (colIdx > 0) {

Review comment:
       Code style: add blank line between semantic units

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");

Review comment:
       Let's make the error message more helpful, something along the lines of `Failed to parse IPv6 address, missing ']'`

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+            }

Review comment:
       Code style: add blank line after closing curly brace

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {

Review comment:
       Code style: remove curly braces for single-line statement
   https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+            }
+            host = addrStr.substring(1, hostEndIdx);
+            if (hostEndIdx == addrStr.length() - 1) { // no port specified, using default
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            } else { // port specified
+                portStr = addrStr.substring(hostEndIdx + 2);
+
+                int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr);
+                portFrom = ports[0];
+                portTo = ports[1];
+            }
+        } else { //IPv4 || IPv6 without port || empty host
+            final int colIdx = addrStr.lastIndexOf(':');
+            if (colIdx > 0) {
+                if (addrStr.substring(0, colIdx).contains(":")) { // IPv6 without [] and port

Review comment:
       Can be shorter and avoid extra allocation: `addrStr.lastIndexOf(":", colIdx)`

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+            }
+            host = addrStr.substring(1, hostEndIdx);
+            if (hostEndIdx == addrStr.length() - 1) { // no port specified, using default
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            } else { // port specified
+                portStr = addrStr.substring(hostEndIdx + 2);
+
+                int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr);
+                portFrom = ports[0];
+                portTo = ports[1];
+            }
+        } else { //IPv4 || IPv6 without port || empty host
+            final int colIdx = addrStr.lastIndexOf(':');
+            if (colIdx > 0) {
+                if (addrStr.substring(0, colIdx).contains(":")) { // IPv6 without [] and port
+                    try {
+                        Inet6Address.getByName(addrStr);
+                        host = addrStr;
+                        portFrom = dfltPortFrom;
+                        portTo = dfltPortTo;
+                    }
+                    catch (UnknownHostException e) {
+                        throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+                    }
+                }
+                else {
+                    host = addrStr.substring(0, colIdx);
+                    portStr = addrStr.substring(colIdx + 1);
+                    int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr);
+                    portFrom = ports[0];
+                    portTo = ports[1];
+                }
+            } else if (colIdx == 0) {
+                throw createParseError(addrStr, errMsgPrefix, "Host name is empty");
+            } else { // Port is not specified, use defaults.
+                host = addrStr;
 
-            host = addrStr.substring(0, colIdx);
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            }
+        }
 
-            String portStr = addrStr.substring(colIdx + 1, addrStr.length());
+        return new HostAndPortRange(host, portFrom, portTo);
+    }
 
-            if (F.isEmpty(portStr))
-                throw createParseError(addrStr, errMsgPrefix, "port range is not specified");
+    /**
+     *
+     * @param addrStr Address String.
+     * @param errMsgPrefix Error message prefix.
+     * @param portStr Port or port range string.
+     * @return Array of int[portFrom, portTo].
+     * @throws IgniteCheckedException If failed.
+     */
 
-            int portRangeIdx = portStr.indexOf("..");
+    private static int[] verifyPortStr(String addrStr, String errMsgPrefix, String portStr) throws IgniteCheckedException {
+        String portFromStr;
+        String portToStr;
 
-            if (portRangeIdx >= 0) {
-                // Port range is specified.
-                portFromStr = portStr.substring(0, portRangeIdx);
-                portToStr = portStr.substring(portRangeIdx + 2, portStr.length());
-            }
-            else {
-                // Single port is specified.
-                portFromStr = portStr;
-                portToStr = portStr;
-            }
+        if (F.isEmpty(portStr))
+            throw createParseError(addrStr, errMsgPrefix, "port range is not specified");
 
-            portFrom = parsePort(portFromStr, addrStr, errMsgPrefix);
-            portTo = parsePort(portToStr, addrStr, errMsgPrefix);
+        int portRangeIdx = portStr.indexOf("..");
 
-            if (portFrom > portTo)
-                throw createParseError(addrStr, errMsgPrefix, "start port cannot be less than end port");
+        if (portRangeIdx >= 0) {
+            // Port range is specified.
+            portFromStr = portStr.substring(0, portRangeIdx);
+            portToStr = portStr.substring(portRangeIdx + 2);
         }
         else {
-            // Host name not specified.
-            if (colIdx == 0)
-                throw createParseError(addrStr, errMsgPrefix, "Host name is empty");
-
-            // Port is not specified, use defaults.
-            host = addrStr;
-
-            portFrom = dfltPortFrom;
-            portTo = dfltPortTo;
+            // Single port is specified.
+            portFromStr = portStr;
+            portToStr = portStr;
         }
 
-        if (F.isEmpty(host))
-            throw createParseError(addrStr, errMsgPrefix, "Host name is empty");
+        int portFrom = parsePort(portFromStr, addrStr, errMsgPrefix);
+        int portTo = parsePort(portToStr, addrStr, errMsgPrefix);
 
-        return new HostAndPortRange(host, portFrom, portTo);
+        if (portFrom > portTo)
+            throw createParseError(addrStr, errMsgPrefix, "start port cannot be less than end port");
+
+        return new int[]{portFrom, portTo};

Review comment:
       Code style: add space after `[]`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ptupitsyn commented on pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#issuecomment-751209568


   Looks good to me :+1: 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ptupitsyn merged pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
ptupitsyn merged pull request #8591:
URL: https://github.com/apache/ignite/pull/8591


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ptupitsyn commented on pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#issuecomment-750925555


   
   @vkozhukhova 
   
   > it passes if I change host in LocalIgniteCluster to Ipv6 localhost
   
   That is what I had in mind, but if you do this, other tests will fail, right? So we can add an overload: `LocalIgniteCluster start(int initSize, String host)`, and so on.
   
   > I'm quite confused because I thought that this issue was only about parsing logic for client and now you talk about changes for server.
   
   Sorry for the confusion, I don't mean we should do any server-side changes. I was talking about `LocalIgniteCluster` changes so that the server optionally listens on IPv6 loopback.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vkozhukhova commented on a change in pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
vkozhukhova commented on a change in pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#discussion_r548441231



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+            }
+            host = addrStr.substring(1, hostEndIdx);
+            if (hostEndIdx == addrStr.length() - 1) { // no port specified, using default
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            } else { // port specified
+                portStr = addrStr.substring(hostEndIdx + 2);
+
+                int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr);
+                portFrom = ports[0];
+                portTo = ports[1];
+            }
+        } else { //IPv4 || IPv6 without port || empty host
+            final int colIdx = addrStr.lastIndexOf(':');
+            if (colIdx > 0) {
+                if (addrStr.substring(0, colIdx).contains(":")) { // IPv6 without [] and port

Review comment:
       Now it checks for previous colon as `addrStr.lastIndexOf(':', colIdx-1) != -1`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vkozhukhova commented on pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
vkozhukhova commented on pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#issuecomment-751201048


   @ptupitsyn Thank you very much for the explanation. Added overloaded `start` for LocalIgniteCluster and added test


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ptupitsyn commented on pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#issuecomment-751258763


   @vkozhukhova I see; actually, I had to enable IPv6 on my machine (Ubuntu 20) explicitly to make this test pass.
   So I propose to keep this test, but mark it with `@Ignore("IPv6 is not enabled by default on some systems.")`, so it can be executed manually. What do you think?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vkozhukhova commented on a change in pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
vkozhukhova commented on a change in pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#discussion_r548440602



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+            }
+            host = addrStr.substring(1, hostEndIdx);
+            if (hostEndIdx == addrStr.length() - 1) { // no port specified, using default
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            } else { // port specified

Review comment:
       Fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] ptupitsyn commented on a change in pull request #8591: IGNITE-13555 Added support for IPv6 addresses in Java thin

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on a change in pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#discussion_r545881507



##########
File path: modules/core/src/test/java/org/apache/ignite/internal/util/HostAndPortRangeTest.java
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.util;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class HostAndPortRangeTest {

Review comment:
       Javadoc is required for all classes.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +53,89 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
+        if (addrStr.contains("[")) { // IPv6

Review comment:
       `[` and `]` are only needed when there is a port, otherwise IPv6 address does not have those.

##########
File path: modules/core/src/test/java/org/apache/ignite/internal/util/HostAndPortRangeTest.java
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.util;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class HostAndPortRangeTest {

Review comment:
       Looks like this test is not added to any suite, and thus won't run on CI.

##########
File path: modules/core/src/test/java/org/apache/ignite/internal/util/HostAndPortRangeTest.java
##########
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.util;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class HostAndPortRangeTest {
+
+    /**
+     * tests correct input address with IPv4 host and port range.
+     * @throws IgniteCheckedException on incorrect host/port
+     */
+    @Test
+    public void testParseIPv4WithPortRange() throws IgniteCheckedException {
+        String addrStr = "127.0.0.1:8080..8090";
+        String errMsgPrefix = "";
+        int dfltPortFrom = 18360;
+        int dfltPortTo = 18362;
+        HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix);
+        HostAndPortRange expected = new HostAndPortRange("127.0.0.1", 8080, 8090);
+        assertEquals(expected, actual);
+    }
+
+    /**
+     * tests correct input address with IPv4 host and single port.
+     * @throws IgniteCheckedException on incorrect host/port
+     */
+    @Test
+    public void testParseIPv4WithSinglePort() throws IgniteCheckedException {
+        String addrStr = "127.0.0.1:8080";
+        String errMsgPrefix = "";
+        int dfltPortFrom = 18360;
+        int dfltPortTo = 18362;
+        HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix);
+        HostAndPortRange expected = new HostAndPortRange("127.0.0.1", 8080, 8080);
+        assertEquals(expected, actual);
+    }
+
+    /**
+     * ests correct input address with IPv4 host and no port.
+     * @throws IgniteCheckedException on incorrect host/port
+     */
+    @Test
+    public void testParseIPv4NoPort() throws IgniteCheckedException {
+        String addrStr = "127.0.0.1";
+        String errMsgPrefix = "";
+        int dfltPortFrom = 18360;
+        int dfltPortTo = 18362;
+        HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix);
+        HostAndPortRange expected = new HostAndPortRange("127.0.0.1", 18360, 18362);
+        assertEquals(expected, actual);
+    }
+
+    /**
+     * tests correct input address with IPv6 host and port range.
+     * @throws IgniteCheckedException on incorrect host/port
+     */
+    @Test
+    public void testParseIPv6WithPortRange() throws IgniteCheckedException {
+        String addrStr = "[::1]:8080..8090";
+        String errMsgPrefix = "";
+        int dfltPortFrom = 18360;
+        int dfltPortTo = 18362;
+        HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix);
+        HostAndPortRange expected = new HostAndPortRange("::1", 8080, 8090);
+        assertEquals(expected, actual);
+    }
+
+    /**
+     * tests correct input address with IPv6 host and single port.
+     * @throws IgniteCheckedException on incorrect host/port
+     */
+    @Test
+    public void testParseIPv6WithSinglePort() throws IgniteCheckedException {
+        String addrStr = "[3ffe:2a00:100:7031::]:8080";
+        String errMsgPrefix = "";
+        int dfltPortFrom = 18360;
+        int dfltPortTo = 18362;
+        HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix);
+        HostAndPortRange expected = new HostAndPortRange("3ffe:2a00:100:7031::", 8080, 8080);
+        assertEquals(expected, actual);
+    }
+
+    /**
+     * tests correct input address with IPv6 host and no port.
+     * @throws IgniteCheckedException on incorrect host/port
+     */
+    @Test
+    public void testParseIPv6NoPort() throws IgniteCheckedException {
+        String addrStr = "[::FFFF:129.144.52.38]";
+        String errMsgPrefix = "";
+        int dfltPortFrom = 18360;
+        int dfltPortTo = 18362;
+        HostAndPortRange actual = HostAndPortRange.parse(addrStr, dfltPortFrom, dfltPortTo, errMsgPrefix);
+        HostAndPortRange expected = new HostAndPortRange("::FFFF:129.144.52.38", 18360, 18362);
+        assertEquals(expected, actual);
+    }
+
+    /**
+     * tests incorrect input address with IPv6 host (no brackets) and port.
+     * @throws IgniteCheckedException on incorrect host/port
+     */
+    @Test(expected = IgniteCheckedException.class)

Review comment:
       Please add a check for the exception message too, not only the class.

##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +53,89 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
+        if (addrStr.contains("[")) { // IPv6
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 host is incorrect");
+            }
+            host = addrStr.substring(1, hostEndIdx);

Review comment:
       `substring(1` assumes that `[` is at index `0`, however, the line above `addrStr.contains("[")` allows `[` at any index.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vkozhukhova commented on a change in pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
vkozhukhova commented on a change in pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#discussion_r548441385



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+            }
+            host = addrStr.substring(1, hostEndIdx);
+            if (hostEndIdx == addrStr.length() - 1) { // no port specified, using default
+                portFrom = dfltPortFrom;
+                portTo = dfltPortTo;
+            } else { // port specified
+                portStr = addrStr.substring(hostEndIdx + 2);
+
+                int[] ports = verifyPortStr(addrStr, errMsgPrefix, portStr);
+                portFrom = ports[0];
+                portTo = ports[1];
+            }
+        } else { //IPv4 || IPv6 without port || empty host
+            final int colIdx = addrStr.lastIndexOf(':');
+            if (colIdx > 0) {
+                if (addrStr.substring(0, colIdx).contains(":")) { // IPv6 without [] and port
+                    try {
+                        Inet6Address.getByName(addrStr);
+                        host = addrStr;
+                        portFrom = dfltPortFrom;
+                        portTo = dfltPortTo;
+                    }
+                    catch (UnknownHostException e) {
+                        throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");

Review comment:
       Overloaded `createParseError` method to pass cause.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite] vkozhukhova commented on a change in pull request #8591: IGNITE-13555 Java thin: add IPv6 address support

Posted by GitBox <gi...@apache.org>.
vkozhukhova commented on a change in pull request #8591:
URL: https://github.com/apache/ignite/pull/8591#discussion_r548440807



##########
File path: modules/core/src/main/java/org/apache/ignite/internal/util/HostAndPortRange.java
##########
@@ -53,60 +55,99 @@ public static HostAndPortRange parse(String addrStr, int dfltPortFrom, int dfltP
 
         String host;
 
+        String portStr;
         int portFrom;
         int portTo;
 
         if (F.isEmpty(addrStr))
             throw createParseError(addrStr, errMsgPrefix, "Address is empty");
 
-        final int colIdx = addrStr.indexOf(':');
-
-        if (colIdx > 0) {
-            String portFromStr;
-            String portToStr;
+        if (addrStr.charAt(0) == '[') { // IPv6 with port(s)
+            int hostEndIdx = addrStr.indexOf(']');
+            if (hostEndIdx == -1) {
+                throw createParseError(addrStr, errMsgPrefix, "IPv6 is incorrect");
+            }

Review comment:
       Done.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org