|
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; |
@@ -637,7 +636,7 @@ public static void setParam(final String[] args, final String confFileName) { |
637 | 636 | config.hasPath(Constant.NODE_LISTEN_PORT) |
638 | 637 | ? config.getInt(Constant.NODE_LISTEN_PORT) : 0; |
639 | 638 |
|
640 | | - bindIp(config); |
| 639 | + PARAMETER.nodeLanIp = PARAMETER.p2pConfig.getLanIp(); |
641 | 640 | externalIp(config); |
642 | 641 |
|
643 | 642 | PARAMETER.nodeP2pVersion = |
@@ -1257,7 +1256,7 @@ public static List<InetSocketAddress> getInetSocketAddress( |
1257 | 1256 | if (filter) { |
1258 | 1257 | String ip = inetSocketAddress.getAddress().getHostAddress(); |
1259 | 1258 | int port = inetSocketAddress.getPort(); |
1260 | | - if (!(PARAMETER.nodeDiscoveryBindIp.equals(ip) |
| 1259 | + if (!(PARAMETER.nodeLanIp.equals(ip) |
1261 | 1260 | || PARAMETER.nodeExternalIp.equals(ip) |
1262 | 1261 | || Constant.LOCAL_HOST.equals(ip)) |
1263 | 1262 | || PARAMETER.nodeListenPort != port) { |
@@ -1535,33 +1534,14 @@ private static FilterQuery getEventFilter(final com.typesafe.config.Config confi |
1535 | 1534 | return filter; |
1536 | 1535 | } |
1537 | 1536 |
|
1538 | | - private static void bindIp(final com.typesafe.config.Config config) { |
1539 | | - if (!config.hasPath(Constant.NODE_DISCOVERY_BIND_IP) |
1540 | | - || config.getString(Constant.NODE_DISCOVERY_BIND_IP) |
1541 | | - .trim().isEmpty()) { |
1542 | | - if (PARAMETER.nodeDiscoveryBindIp == null) { |
1543 | | - logger.info("Bind address wasn't set, Punching to identify it..."); |
1544 | | - try (Socket s = new Socket("www.baidu.com", 80)) { |
1545 | | - PARAMETER.nodeDiscoveryBindIp = s.getLocalAddress().getHostAddress(); |
1546 | | - logger.info("UDP local bound to: {}", PARAMETER.nodeDiscoveryBindIp); |
1547 | | - } catch (IOException e) { |
1548 | | - logger.warn("Can't get bind IP. Fall back to 127.0.0.1: " + e); |
1549 | | - PARAMETER.nodeDiscoveryBindIp = "127.0.0.1"; |
1550 | | - } |
1551 | | - } |
1552 | | - } else { |
1553 | | - PARAMETER.nodeDiscoveryBindIp = config.getString(Constant.NODE_DISCOVERY_BIND_IP).trim(); |
1554 | | - } |
1555 | | - } |
1556 | | - |
1557 | 1537 | private static void externalIp(final com.typesafe.config.Config config) { |
1558 | 1538 | if (!config.hasPath(Constant.NODE_DISCOVERY_EXTERNAL_IP) || config |
1559 | 1539 | .getString(Constant.NODE_DISCOVERY_EXTERNAL_IP).trim().isEmpty()) { |
1560 | 1540 | if (PARAMETER.nodeExternalIp == null) { |
1561 | 1541 | logger.info("External IP wasn't set, using ipv4 from libp2p"); |
1562 | 1542 | PARAMETER.nodeExternalIp = PARAMETER.p2pConfig.getIp(); |
1563 | 1543 | if (StringUtils.isEmpty(PARAMETER.nodeExternalIp)) { |
1564 | | - PARAMETER.nodeExternalIp = PARAMETER.nodeDiscoveryBindIp; |
| 1544 | + PARAMETER.nodeExternalIp = PARAMETER.nodeLanIp; |
1565 | 1545 | } |
1566 | 1546 | } |
1567 | 1547 | } else { |
@@ -1632,7 +1612,7 @@ public static void logConfig() { |
1632 | 1612 | logger.info("\n"); |
1633 | 1613 | logger.info("************************ Net config ************************"); |
1634 | 1614 | logger.info("P2P version: {}", parameter.getNodeP2pVersion()); |
1635 | | - logger.info("Bind IP: {}", parameter.getNodeDiscoveryBindIp()); |
| 1615 | + logger.info("LAN IP: {}", parameter.getNodeLanIp()); |
1636 | 1616 | logger.info("External IP: {}", parameter.getNodeExternalIp()); |
1637 | 1617 | logger.info("Listen port: {}", parameter.getNodeListenPort()); |
1638 | 1618 | logger.info("Node ipv6 enable: {}", parameter.isNodeEnableIpv6()); |
|
0 commit comments