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

IPv6 support #3773

Merged
merged 27 commits into from
Nov 5, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
938b8f4
IPv6 support
KeRan213539 Sep 7, 2020
dd7aeb6
AddressServerParamCheckUtil 合并到 IpUtil 及一些修改
KeRan213539 Sep 7, 2020
b4f234d
解决魔法值
KeRan213539 Sep 7, 2020
bb4e177
修改隐患
KeRan213539 Sep 8, 2020
601f0b4
调整使用了类似 ip.indexOf(":") 查找是否有端口的地方的逻辑, 一些 ":" 替换为常量
KeRan213539 Sep 8, 2020
87ab5f1
删除无用测试
KeRan213539 Sep 8, 2020
1858bc0
IpUtil 改名 为 IPUtil, 涉及IP的相关方法名修改,涉及到的调用修改,检测IP的地方调用的isIPv4改为isIP. 修改涉…
KeRan213539 Sep 8, 2020
a0a6320
no message
KeRan213539 Sep 8, 2020
dbe8934
no message
KeRan213539 Sep 8, 2020
37620a4
no message
KeRan213539 Sep 8, 2020
55c3845
no message
KeRan213539 Sep 8, 2020
44c7ff8
获取本机IP时,如果本机IP是IPv6并且包含网卡信息(V6地址中最后面的百分号和百分号后面的内容)则去除网卡信息
KeRan213539 Sep 9, 2020
167d479
Merge pull request #1 from alibaba/develop
KeRan213539 Sep 21, 2020
7ba3152
Merge branch 'develop' into support_ipv6
KeRan213539 Sep 21, 2020
5fe766a
Merge pull request #2 from alibaba/develop
KeRan213539 Oct 12, 2020
9ef561b
Merge pull request #3 from alibaba/develop
KeRan213539 Oct 13, 2020
34b53fc
Merge pull request #4 from alibaba/develop
KeRan213539 Oct 17, 2020
5a3b893
Merge branch 'develop' into support_ipv6
KeRan213539 Oct 17, 2020
877ebab
解决 AvoidComplexConditionRule(请不要在条件中使用复杂的表达式)
KeRan213539 Oct 17, 2020
ce51939
移除无用代码
KeRan213539 Oct 19, 2020
1deee2a
Merge pull request #5 from alibaba/develop
KeRan213539 Oct 20, 2020
6db4d53
Merge pull request #6 from alibaba/develop
KeRan213539 Oct 22, 2020
a34904b
Merge branch 'develop' into support_ipv6
KeRan213539 Oct 22, 2020
29e7546
Merge pull request #7 from alibaba/develop
KeRan213539 Oct 26, 2020
e9eae1c
Merge branch 'develop' into support_ipv6
KeRan213539 Oct 26, 2020
99cbf16
添加注释
KeRan213539 Nov 3, 2020
bceff65
调整code style, 调整获取本机IP的逻辑
KeRan213539 Nov 4, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.alibaba.nacos.address.constant.AddressServerConstants;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.common.utils.IpUtil;
import com.alibaba.nacos.naming.core.Instance;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
Expand Down Expand Up @@ -85,14 +86,11 @@ public List<Instance> generateInstancesByIps(String serviceName, String rawProdu
}

private String[] generateIpAndPort(String ip) {

int index = ip.indexOf(AddressServerConstants.IP_PORT_SEPARATOR);
if (index != -1) {

return new String[] {ip.substring(0, index), ip.substring(index + 1)};
String[] result = IpUtil.splitIpPortStr(ip);
if (result.length != IpUtil.SPLIT_IP_PORT_RESULT_LENGTH) {
return new String[] {result[0], String.valueOf(AddressServerConstants.DEFAULT_SERVER_PORT)};
}

return new String[] {ip, String.valueOf(AddressServerConstants.DEFAULT_SERVER_PORT)};
return result;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ public interface AddressServerConstants {
*/
String DEFAULT_PRODUCT = "nacos";

/**
* the separator between ip and port.
*/
String IP_PORT_SEPARATOR = ":";

/**
* the separator for service name between raw service name and group.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import com.alibaba.nacos.address.component.AddressServerManager;
import com.alibaba.nacos.address.constant.AddressServerConstants;
import com.alibaba.nacos.address.misc.Loggers;
import com.alibaba.nacos.address.util.AddressServerParamCheckUtil;
import com.alibaba.nacos.api.common.Constants;
import com.alibaba.nacos.api.naming.pojo.healthcheck.AbstractHealthChecker;
import com.alibaba.nacos.common.utils.IpUtil;
import com.alibaba.nacos.naming.core.Cluster;
import com.alibaba.nacos.naming.core.Instance;
import com.alibaba.nacos.naming.core.Service;
Expand Down Expand Up @@ -87,8 +87,8 @@ public ResponseEntity postCluster(@RequestParam(required = false) String product
clusterObj.setHealthChecker(new AbstractHealthChecker.None());
serviceManager.createServiceIfAbsent(Constants.DEFAULT_NAMESPACE_ID, serviceName, false, clusterObj);
String[] ipArray = addressServerManager.splitIps(ips);
String checkResult = AddressServerParamCheckUtil.checkIps(ipArray);
if (AddressServerParamCheckUtil.CHECK_OK.equals(checkResult)) {
String checkResult = IpUtil.checkIps(ipArray);
if (IpUtil.CHECK_OK.equals(checkResult)) {
KeRan213539 marked this conversation as resolved.
Show resolved Hide resolved
List<Instance> instanceList = addressServerGeneratorManager
.generateInstancesByIps(serviceName, rawProductName, clusterName, ipArray);
for (Instance instance : instanceList) {
Expand Down Expand Up @@ -143,8 +143,8 @@ public ResponseEntity deleteCluster(@RequestParam(required = false) String produ
} else {
// delete specified ip list
String[] ipArray = addressServerManager.splitIps(ips);
String checkResult = AddressServerParamCheckUtil.checkIps(ipArray);
if (AddressServerParamCheckUtil.CHECK_OK.equals(checkResult)) {
String checkResult = IpUtil.checkIps(ipArray);
if (IpUtil.CHECK_OK.equals(checkResult)) {
List<Instance> instanceList = addressServerGeneratorManager
.generateInstancesByIps(serviceName, rawProductName, clusterName, ipArray);
serviceManager.removeInstance(Constants.DEFAULT_NAMESPACE_ID, serviceName, false,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

package com.alibaba.nacos.address;

import com.alibaba.nacos.address.util.AddressServerParamCheckUtil;
import com.alibaba.nacos.common.utils.IpUtil;
import org.junit.Test;

public class ParamCheckUtilTests {

@Test
public void checkIps() {
String[] ips = {"127.0.0.1"};
System.out.println(AddressServerParamCheckUtil.checkIps(ips));
System.out.println(IpUtil.checkIps(ips));

String[] illlegalIps = {"127.100.19", "127.0.0.1"};
System.err.println(AddressServerParamCheckUtil.checkIps(illlegalIps));
System.err.println(IpUtil.checkIps(illlegalIps));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.alibaba.nacos.common.lifecycle.Closeable;
import com.alibaba.nacos.common.notify.NotifyCenter;
import com.alibaba.nacos.common.utils.IoUtils;
import com.alibaba.nacos.common.utils.IpUtil;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.common.utils.ThreadUtils;
import org.slf4j.Logger;
Expand Down Expand Up @@ -87,9 +88,9 @@ public ServerListManager(List<String> fixed, String namespace) {
this.isStarted = true;
List<String> serverAddrs = new ArrayList<String>();
for (String serverAddr : fixed) {
String[] serverAddrArr = serverAddr.split(":");
String[] serverAddrArr = IpUtil.splitIpPortStr(serverAddr);
if (serverAddrArr.length == 1) {
serverAddrs.add(serverAddrArr[0] + ":" + ParamUtil.getDefaultServerPort());
serverAddrs.add(serverAddrArr[0] + IpUtil.IP_PORT_SPLITER + ParamUtil.getDefaultServerPort());
} else {
serverAddrs.add(serverAddr);
}
Expand Down Expand Up @@ -156,9 +157,10 @@ public ServerListManager(Properties properties) throws NacosException {
if (serverAddr.startsWith(HTTPS) || serverAddr.startsWith(HTTP)) {
serverAddrs.add(serverAddr);
} else {
String[] serverAddrArr = serverAddr.split(":");
String[] serverAddrArr = IpUtil.splitIpPortStr(serverAddr);
if (serverAddrArr.length == 1) {
serverAddrs.add(HTTP + serverAddrArr[0] + ":" + ParamUtil.getDefaultServerPort());
serverAddrs.add(HTTP + serverAddrArr[0] + IpUtil.IP_PORT_SPLITER + ParamUtil
.getDefaultServerPort());
} else {
serverAddrs.add(HTTP + serverAddr);
}
Expand Down Expand Up @@ -355,10 +357,10 @@ private List<String> getApacheServerList(String url, String name) {
List<String> result = new ArrayList<String>(lines.size());
for (String serverAddr : lines) {
if (StringUtils.isNotBlank(serverAddr)) {
String[] ipPort = serverAddr.trim().split(":");
String[] ipPort = IpUtil.splitIpPortStr(serverAddr.trim());
String ip = ipPort[0].trim();
if (ipPort.length == 1) {
result.add(ip + ":" + ParamUtil.getDefaultServerPort());
result.add(ip + IpUtil.IP_PORT_SPLITER + ParamUtil.getDefaultServerPort());
} else {
result.add(serverAddr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package com.alibaba.nacos.client.config.utils;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.common.utils.IpUtils;
import com.alibaba.nacos.common.utils.IpUtil;
import com.alibaba.nacos.common.utils.StringUtils;

import java.util.List;
Expand Down Expand Up @@ -190,7 +190,7 @@ public static void checkBetaIps(String betaIps) throws NacosException {
}
String[] ipsArr = betaIps.split(",");
for (String ip : ipsArr) {
if (!IpUtils.isIpv4(ip)) {
if (!IpUtil.isIpv4(ip)) {
KeRan213539 marked this conversation as resolved.
Show resolved Hide resolved
throw new NacosException(NacosException.CLIENT_INVALID_PARAM, "betaIps invalid");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.alibaba.nacos.common.lifecycle.Closeable;
import com.alibaba.nacos.common.utils.HttpMethod;
import com.alibaba.nacos.common.utils.IoUtils;
import com.alibaba.nacos.common.utils.IpUtil;
import com.alibaba.nacos.common.utils.JacksonUtils;
import com.alibaba.nacos.common.utils.StringUtils;
import com.alibaba.nacos.common.utils.ThreadUtils;
Expand Down Expand Up @@ -588,8 +589,8 @@ public String callServer(String api, Map<String, String> params, Map<String, Str
if (curServer.startsWith(UtilAndComs.HTTPS) || curServer.startsWith(UtilAndComs.HTTP)) {
url = curServer + api;
} else {
if (!curServer.contains(UtilAndComs.SERVER_ADDR_IP_SPLITER)) {
curServer = curServer + UtilAndComs.SERVER_ADDR_IP_SPLITER + serverPort;
if (!IpUtil.containsPort(curServer)) {
curServer = curServer + IpUtil.IP_PORT_SPLITER + serverPort;
}
url = NamingHttpClientManager.getInstance().getPrefix() + curServer + api;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public class UtilAndComs {

public static final String NACOS_NAMING_LOG_LEVEL = "com.alibaba.nacos.naming.log.level";

public static final String SERVER_ADDR_IP_SPLITER = ":";

public static final int DEFAULT_CLIENT_BEAT_THREAD_COUNT =
Runtime.getRuntime().availableProcessors() > 1 ? Runtime.getRuntime().availableProcessors() / 2 : 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.alibaba.nacos.common.tls;

import com.alibaba.nacos.common.utils.IpUtils;
import com.alibaba.nacos.common.utils.IpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -38,7 +38,7 @@ public final class SelfHostnameVerifier implements HostnameVerifier {

private static ConcurrentHashMap<String, Boolean> hosts = new ConcurrentHashMap<String, Boolean>();

private static final String[] LOCALHOST_HOSTNAME = new String[] {"localhost", "127.0.0.1"};
private static final String[] LOCALHOST_HOSTNAME = new String[] {"localhost", IpUtil.localHostIp()};
KeRan213539 marked this conversation as resolved.
Show resolved Hide resolved

public SelfHostnameVerifier(HostnameVerifier hv) {
this.hv = hv;
Expand All @@ -64,7 +64,7 @@ private static boolean isIpv4(String host) {
if (cacheHostVerify != null) {
return cacheHostVerify;
}
boolean isIp = IpUtils.isIpv4(host);
boolean isIp = IpUtil.isIpv4(host);
hosts.putIfAbsent(host, isIp);
return isIp;
}
Expand Down
Loading