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

feat(net): delete config item node.discovery.bind.ip #5597

Merged
merged 4 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
2 changes: 0 additions & 2 deletions common/src/main/java/org/tron/core/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,6 @@ public class Constant {
public static final String EVENT_SUBSCRIBE_CONTRACT_ADDRESS = "event.subscribe.filter.contractAddress";
public static final String EVENT_SUBSCRIBE_CONTRACT_TOPIC = "event.subscribe.filter.contractTopic";

public static final String NODE_DISCOVERY_BIND_IP = "node.discovery.bind.ip";

public static final String NODE_DISCOVERY_EXTERNAL_IP = "node.discovery.external.ip";

public static final String NODE_BACKUP_PRIORITY = "node.backup.priority";
Expand Down
24 changes: 7 additions & 17 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,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(config);
bindIp();
externalIp(config);

PARAMETER.nodeP2pVersion =
Expand Down Expand Up @@ -1521,22 +1521,12 @@ private static FilterQuery getEventFilter(final com.typesafe.config.Config confi
return filter;
}

private static void bindIp(final com.typesafe.config.Config config) {
if (!config.hasPath(Constant.NODE_DISCOVERY_BIND_IP)
|| config.getString(Constant.NODE_DISCOVERY_BIND_IP)
.trim().isEmpty()) {
if (PARAMETER.nodeDiscoveryBindIp == null) {
logger.info("Bind address wasn't set, Punching to identify it...");
try (Socket s = new Socket("www.baidu.com", 80)) {
PARAMETER.nodeDiscoveryBindIp = s.getLocalAddress().getHostAddress();
logger.info("UDP local bound to: {}", PARAMETER.nodeDiscoveryBindIp);
} catch (IOException e) {
logger.warn("Can't get bind IP. Fall back to 127.0.0.1: " + e);
PARAMETER.nodeDiscoveryBindIp = "127.0.0.1";
}
}
} else {
PARAMETER.nodeDiscoveryBindIp = config.getString(Constant.NODE_DISCOVERY_BIND_IP).trim();
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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should this logic be retained?

Copy link
Contributor Author

@317787106 317787106 Nov 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the external ip is not exist, use LAN IP.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why hardcoded into www.baidu.com?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@halibobo1205 It has been moved to libp2p module. This url is not necessary and we can use alternative way.

}
}

Expand Down
19 changes: 1 addition & 18 deletions framework/src/test/java/org/tron/core/config/args/ArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@

import com.google.common.collect.Lists;
import com.typesafe.config.Config;
import com.typesafe.config.ConfigMergeable;
import com.typesafe.config.ConfigOrigin;
import com.typesafe.config.ConfigRenderOptions;
import com.typesafe.config.ConfigValue;
import com.typesafe.config.ConfigValueType;
import io.grpc.internal.GrpcUtil;
import io.grpc.netty.NettyServerBuilder;
import java.lang.reflect.InvocationTargetException;
Expand All @@ -36,10 +31,8 @@
import org.tron.common.utils.ByteArray;
import org.tron.common.utils.LocalWitnesses;
import org.tron.common.utils.PublicMethod;
import org.tron.common.utils.ReflectUtils;
import org.tron.core.Constant;
import org.tron.core.config.Configuration;
import org.tron.core.net.peer.PeerManager;

@Slf4j
public class ArgsTest {
Expand Down Expand Up @@ -95,7 +88,6 @@ public void get() {

Assert.assertTrue(parameter.isNodeDiscoveryEnable());
Assert.assertTrue(parameter.isNodeDiscoveryPersist());
Assert.assertEquals("127.0.0.1", parameter.getNodeDiscoveryBindIp());
Assert.assertEquals("46.168.1.1", parameter.getNodeExternalIp());
Assert.assertEquals(18888, parameter.getNodeListenPort());
Assert.assertEquals(2000, parameter.getNodeConnectionTimeout());
Expand Down Expand Up @@ -130,27 +122,18 @@ public void testIpFromLibP2p()
Args.setParam(new String[] {"-w"}, Constant.TEST_CONF);
CommonParameter parameter = Args.getInstance();

String configuredBindIp = parameter.getNodeDiscoveryBindIp();
String configuredExternalIp = parameter.getNodeExternalIp();
Assert.assertEquals("127.0.0.1", configuredBindIp);
Assert.assertEquals("46.168.1.1", configuredExternalIp);

Config config = Configuration.getByFileName(null, Constant.TEST_CONF);
Config config2 = config.withoutPath(Constant.NODE_DISCOVERY_BIND_IP);
Config config3 = config2.withoutPath(Constant.NODE_DISCOVERY_EXTERNAL_IP);
Config config3 = config.withoutPath(Constant.NODE_DISCOVERY_EXTERNAL_IP);

CommonParameter.getInstance().setNodeDiscoveryBindIp(null);
CommonParameter.getInstance().setNodeExternalIp(null);

Method method1 = Args.class.getDeclaredMethod("bindIp", Config.class);
method1.setAccessible(true);
method1.invoke(Args.class, config3);

Method method2 = Args.class.getDeclaredMethod("externalIp", Config.class);
method2.setAccessible(true);
method2.invoke(Args.class, config3);

Assert.assertNotEquals(configuredBindIp, parameter.getNodeDiscoveryBindIp());
Assert.assertNotEquals(configuredExternalIp, parameter.getNodeExternalIp());
}
}
Expand Down
1 change: 0 additions & 1 deletion framework/src/test/resources/config-test-mainnet.conf
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ storage {
node.discovery = {
enable = true
persist = true
bind.ip = "127.0.0.1"
external.ip = "46.168.1.1"
}

Expand Down
1 change: 0 additions & 1 deletion framework/src/test/resources/config-test-storagetest.conf
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ storage {
node.discovery = {
enable = true
persist = true
bind.ip = "127.0.0.1"
external.ip = "46.168.1.1"
}

Expand Down
1 change: 0 additions & 1 deletion framework/src/test/resources/config-test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ storage {
node.discovery = {
enable = true
persist = true
bind.ip = "127.0.0.1"
external.ip = "46.168.1.1"
}

Expand Down