-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Rationale
In the configuration file config.conf, you can configure the local IP address through configuration items, including LAN IP and WAN IP. The main role of IP is to be used in the node discovery phase to construct UDP messages that are sent to peers. Generally, the LAN address is configured through node.discovery.bind.ip, and the WAN address is configured through node.discovery.external.ip.
Setting the IP of P2pConfig in java-tron is divided into as following priorities:
- The external network IP / WAN IP obtained from the query URL through the libp2p module;
- The value obtained by reading the configuration item node.discovery.external.ip;
- The value obtained by reading the configuration item node.bind.bind.ip;
This IP is used to fill in the address or addressIpv6 field of the Endpoint from in the following 5 messages:
- HelloMessage
- PingMessage
- PongMessage
- FindNeighbors
- Neighbors
For Ethernet networking (main chain), an external network connection must be ensured, so that priority 1 is met. For local area networking (private chain), assume that it cannot obtain the external network IP. During the actual connection, the node obtains peer's IP through the data packet socket , and then encapsulates the IP into a Node and adds it to the peer's k bucket.
See the method org.tron.p2p.discover.socket.P2pPacketDecoder#decode:
@Override
public void decode(ChannelHandlerContext ctx, DatagramPacket packet, List<Object> out)
throws Exception {
ByteBuf buf = packet.content();
int length = buf.readableBytes();
...
byte[] encoded = new byte[length];
buf.readBytes(encoded);
try {
UdpEvent event = new UdpEvent(Message.parse(encoded), packet.sender());
out.add(event);
} catch (P2pException pe) {
...
}
}
Local node doesn’t get peer’s ip from above messages. Therefore, it is actually not necessary to configure the LAN IP.
Implementation
Delete the configuration item node.discovery.bind.ip in the configuration file to reduce redundant items. For nodes without ethernet access, the local ip is 127.0.0.1.