Skip to content

Commit

Permalink
remove bindIp method from Args
Browse files Browse the repository at this point in the history
  • Loading branch information
317787106 committed Dec 27, 2023
1 parent 920e45f commit 4fc1538
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 26 deletions.
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies {
compile 'org.aspectj:aspectjrt:1.8.13'
compile 'org.aspectj:aspectjweaver:1.8.13'
compile 'org.aspectj:aspectjtools:1.8.13'
compile group: 'io.github.tronprotocol', name: 'libp2p', version: '2.1.0',{
compile group: 'com.github.tronprotocol', name: 'libp2p', version: 'test-v2.2.1',{
exclude group: 'io.grpc', module: 'grpc-context'
exclude group: 'io.grpc', module: 'grpc-core'
exclude group: 'io.grpc', module: 'grpc-netty'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public class CommonParameter {
public int nodeListenPort;
@Getter
@Setter
public String nodeDiscoveryBindIp;
public String nodeLanIp;
@Getter
@Setter
public String nodeExternalIp;
Expand Down
20 changes: 5 additions & 15 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.InputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -136,7 +135,7 @@ public static void clearParam() {
PARAMETER.maxTps = 1000;
PARAMETER.minParticipationRate = 0;
PARAMETER.nodeListenPort = 0;
PARAMETER.nodeDiscoveryBindIp = "";
PARAMETER.nodeLanIp = "";
PARAMETER.nodeExternalIp = "";
PARAMETER.nodeP2pVersion = 0;
PARAMETER.nodeEnableIpv6 = false;
Expand Down Expand Up @@ -635,7 +634,7 @@ public static void setParam(final String[] args, final String confFileName) {
config.hasPath(Constant.NODE_LISTEN_PORT)
? config.getInt(Constant.NODE_LISTEN_PORT) : 0;

bindIp();
PARAMETER.nodeLanIp = PARAMETER.p2pConfig.getLanIp();
externalIp(config);

PARAMETER.nodeP2pVersion =
Expand Down Expand Up @@ -1247,7 +1246,7 @@ public static List<InetSocketAddress> getInetSocketAddress(
if (filter) {
String ip = inetSocketAddress.getAddress().getHostAddress();
int port = inetSocketAddress.getPort();
if (!(PARAMETER.nodeDiscoveryBindIp.equals(ip)
if (!(PARAMETER.nodeLanIp.equals(ip)
|| PARAMETER.nodeExternalIp.equals(ip)
|| Constant.LOCAL_HOST.equals(ip))
|| PARAMETER.nodeListenPort != port) {
Expand Down Expand Up @@ -1525,23 +1524,14 @@ private static FilterQuery getEventFilter(final com.typesafe.config.Config confi
return filter;
}

private static void bindIp() {
try (Socket s = new Socket("www.baidu.com", 80)) {
PARAMETER.nodeDiscoveryBindIp = s.getLocalAddress().getHostAddress();
} catch (IOException e) {
logger.warn("Can't get bind IP. Fall back to 127.0.0.1: " + e);
PARAMETER.nodeDiscoveryBindIp = "127.0.0.1";
}
}

private static void externalIp(final com.typesafe.config.Config config) {
if (!config.hasPath(Constant.NODE_DISCOVERY_EXTERNAL_IP) || config
.getString(Constant.NODE_DISCOVERY_EXTERNAL_IP).trim().isEmpty()) {
if (PARAMETER.nodeExternalIp == null) {
logger.info("External IP wasn't set, using ipv4 from libp2p");
PARAMETER.nodeExternalIp = PARAMETER.p2pConfig.getIp();
if (StringUtils.isEmpty(PARAMETER.nodeExternalIp)) {
PARAMETER.nodeExternalIp = PARAMETER.nodeDiscoveryBindIp;
PARAMETER.nodeExternalIp = PARAMETER.nodeLanIp;
}
}
} else {
Expand Down Expand Up @@ -1612,7 +1602,7 @@ public static void logConfig() {
logger.info("\n");
logger.info("************************ Net config ************************");
logger.info("P2P version: {}", parameter.getNodeP2pVersion());
logger.info("Bind IP: {}", parameter.getNodeDiscoveryBindIp());
logger.info("LAN IP: {}", parameter.getNodeLanIp());
logger.info("External IP: {}", parameter.getNodeExternalIp());
logger.info("Listen port: {}", parameter.getNodeListenPort());
logger.info("Node ipv6 enable: {}", parameter.isNodeEnableIpv6());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ public static void init() throws IOException {
getInstance().setRpcPort(PublicMethod.chooseRandomPort());
getInstance().setRpcOnSolidityPort(PublicMethod.chooseRandomPort());
getInstance().setRpcOnPBFTPort(PublicMethod.chooseRandomPort());
String fullNode = String.format("%s:%d", getInstance().getNodeDiscoveryBindIp(),
String fullNode = String.format("%s:%d", getInstance().getNodeLanIp(),
getInstance().getRpcPort());
String solidityNode = String.format("%s:%d", getInstance().getNodeDiscoveryBindIp(),
String solidityNode = String.format("%s:%d", getInstance().getNodeLanIp(),
getInstance().getRpcOnSolidityPort());
String pBFTNode = String.format("%s:%d", getInstance().getNodeDiscoveryBindIp(),
String pBFTNode = String.format("%s:%d", getInstance().getNodeLanIp(),
getInstance().getRpcOnPBFTPort());

ManagedChannel channelFull = ManagedChannelBuilder.forTarget(fullNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ public static void init() throws IOException {
Args.getInstance().setRpcPort(PublicMethod.chooseRandomPort());
Args.getInstance().setRpcOnSolidityPort(PublicMethod.chooseRandomPort());
Args.getInstance().setRpcOnPBFTPort(PublicMethod.chooseRandomPort());
String fullnode = String.format("%s:%d", Args.getInstance().getNodeDiscoveryBindIp(),
String fullnode = String.format("%s:%d", Args.getInstance().getNodeLanIp(),
Args.getInstance().getRpcPort());
String solidityNode = String.format("%s:%d", Args.getInstance().getNodeDiscoveryBindIp(),
String solidityNode = String.format("%s:%d", Args.getInstance().getNodeLanIp(),
Args.getInstance().getRpcOnSolidityPort());
String pBFTNode = String.format("%s:%d", Args.getInstance().getNodeDiscoveryBindIp(),
String pBFTNode = String.format("%s:%d", Args.getInstance().getNodeLanIp(),
Args.getInstance().getRpcOnPBFTPort());
channelFull = ManagedChannelBuilder.forTarget(fullnode)
.usePlaintext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public static void init() throws IOException {
Args.getInstance().setRpcPort(PublicMethod.chooseRandomPort());
Args.getInstance().setRpcOnSolidityPort(PublicMethod.chooseRandomPort());
Args.getInstance().setRpcOnPBFTPort(PublicMethod.chooseRandomPort());
String fullNode = String.format("%s:%d", Args.getInstance().getNodeDiscoveryBindIp(),
String fullNode = String.format("%s:%d", Args.getInstance().getNodeLanIp(),
Args.getInstance().getRpcPort());
String solidityNode = String.format("%s:%d", Args.getInstance().getNodeDiscoveryBindIp(),
String solidityNode = String.format("%s:%d", Args.getInstance().getNodeLanIp(),
Args.getInstance().getRpcOnSolidityPort());
String pBFTNode = String.format("%s:%d", Args.getInstance().getNodeDiscoveryBindIp(),
String pBFTNode = String.format("%s:%d", Args.getInstance().getNodeLanIp(),
Args.getInstance().getRpcOnPBFTPort());

ManagedChannel channelFull = ManagedChannelBuilder.forTarget(fullNode)
Expand Down

0 comments on commit 4fc1538

Please sign in to comment.