|
20 | 20 | import java.io.InputStream; |
21 | 21 | import java.net.InetAddress; |
22 | 22 | import java.net.InetSocketAddress; |
23 | | -import java.net.Socket; |
24 | 23 | import java.text.ParseException; |
25 | 24 | import java.util.ArrayList; |
26 | 25 | import java.util.Arrays; |
@@ -136,7 +135,7 @@ public static void clearParam() { |
136 | 135 | PARAMETER.maxTps = 1000; |
137 | 136 | PARAMETER.minParticipationRate = 0; |
138 | 137 | PARAMETER.nodeListenPort = 0; |
139 | | - PARAMETER.nodeDiscoveryBindIp = ""; |
| 138 | + PARAMETER.nodeLanIp = ""; |
140 | 139 | PARAMETER.nodeExternalIp = ""; |
141 | 140 | PARAMETER.nodeP2pVersion = 0; |
142 | 141 | PARAMETER.nodeEnableIpv6 = false; |
@@ -635,7 +634,7 @@ public static void setParam(final String[] args, final String confFileName) { |
635 | 634 | config.hasPath(Constant.NODE_LISTEN_PORT) |
636 | 635 | ? config.getInt(Constant.NODE_LISTEN_PORT) : 0; |
637 | 636 |
|
638 | | - bindIp(config); |
| 637 | + PARAMETER.nodeLanIp = PARAMETER.p2pConfig.getLanIp(); |
639 | 638 | externalIp(config); |
640 | 639 |
|
641 | 640 | PARAMETER.nodeP2pVersion = |
@@ -1247,7 +1246,7 @@ public static List<InetSocketAddress> getInetSocketAddress( |
1247 | 1246 | if (filter) { |
1248 | 1247 | String ip = inetSocketAddress.getAddress().getHostAddress(); |
1249 | 1248 | int port = inetSocketAddress.getPort(); |
1250 | | - if (!(PARAMETER.nodeDiscoveryBindIp.equals(ip) |
| 1249 | + if (!(PARAMETER.nodeLanIp.equals(ip) |
1251 | 1250 | || PARAMETER.nodeExternalIp.equals(ip) |
1252 | 1251 | || Constant.LOCAL_HOST.equals(ip)) |
1253 | 1252 | || PARAMETER.nodeListenPort != port) { |
@@ -1525,33 +1524,14 @@ private static FilterQuery getEventFilter(final com.typesafe.config.Config confi |
1525 | 1524 | return filter; |
1526 | 1525 | } |
1527 | 1526 |
|
1528 | | - private static void bindIp(final com.typesafe.config.Config config) { |
1529 | | - if (!config.hasPath(Constant.NODE_DISCOVERY_BIND_IP) |
1530 | | - || config.getString(Constant.NODE_DISCOVERY_BIND_IP) |
1531 | | - .trim().isEmpty()) { |
1532 | | - if (PARAMETER.nodeDiscoveryBindIp == null) { |
1533 | | - logger.info("Bind address wasn't set, Punching to identify it..."); |
1534 | | - try (Socket s = new Socket("www.baidu.com", 80)) { |
1535 | | - PARAMETER.nodeDiscoveryBindIp = s.getLocalAddress().getHostAddress(); |
1536 | | - logger.info("UDP local bound to: {}", PARAMETER.nodeDiscoveryBindIp); |
1537 | | - } catch (IOException e) { |
1538 | | - logger.warn("Can't get bind IP. Fall back to 127.0.0.1: " + e); |
1539 | | - PARAMETER.nodeDiscoveryBindIp = "127.0.0.1"; |
1540 | | - } |
1541 | | - } |
1542 | | - } else { |
1543 | | - PARAMETER.nodeDiscoveryBindIp = config.getString(Constant.NODE_DISCOVERY_BIND_IP).trim(); |
1544 | | - } |
1545 | | - } |
1546 | | - |
1547 | 1527 | private static void externalIp(final com.typesafe.config.Config config) { |
1548 | 1528 | if (!config.hasPath(Constant.NODE_DISCOVERY_EXTERNAL_IP) || config |
1549 | 1529 | .getString(Constant.NODE_DISCOVERY_EXTERNAL_IP).trim().isEmpty()) { |
1550 | 1530 | if (PARAMETER.nodeExternalIp == null) { |
1551 | 1531 | logger.info("External IP wasn't set, using ipv4 from libp2p"); |
1552 | 1532 | PARAMETER.nodeExternalIp = PARAMETER.p2pConfig.getIp(); |
1553 | 1533 | if (StringUtils.isEmpty(PARAMETER.nodeExternalIp)) { |
1554 | | - PARAMETER.nodeExternalIp = PARAMETER.nodeDiscoveryBindIp; |
| 1534 | + PARAMETER.nodeExternalIp = PARAMETER.nodeLanIp; |
1555 | 1535 | } |
1556 | 1536 | } |
1557 | 1537 | } else { |
@@ -1622,7 +1602,7 @@ public static void logConfig() { |
1622 | 1602 | logger.info("\n"); |
1623 | 1603 | logger.info("************************ Net config ************************"); |
1624 | 1604 | logger.info("P2P version: {}", parameter.getNodeP2pVersion()); |
1625 | | - logger.info("Bind IP: {}", parameter.getNodeDiscoveryBindIp()); |
| 1605 | + logger.info("LAN IP: {}", parameter.getNodeLanIp()); |
1626 | 1606 | logger.info("External IP: {}", parameter.getNodeExternalIp()); |
1627 | 1607 | logger.info("Listen port: {}", parameter.getNodeListenPort()); |
1628 | 1608 | logger.info("Node ipv6 enable: {}", parameter.isNodeEnableIpv6()); |
|
0 commit comments