Skip to content

Commit

Permalink
Node host can be specified via host name as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Nashatyrev committed Oct 10, 2016
1 parent 670e96b commit 8307602
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions ethereumj-core/src/main/java/org/ethereum/net/rlpx/Node.java
Expand Up @@ -9,8 +9,10 @@
import org.spongycastle.util.encoders.Hex;

import java.io.*;
import java.net.InetAddress;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;

Expand Down Expand Up @@ -135,13 +137,14 @@ public void setPort(int port) {
}

public byte[] getRLP() {
String[] ipArray = host.split("\\.");
byte[] host = new byte[4];
for (int i = 0; i < ipArray.length; i++) {
host[i] = (byte) (Integer.parseInt(ipArray[i]) | 0x00);
byte[] ip;
try {
ip = InetAddress.getByName(host).getAddress();
} catch (UnknownHostException e) {
ip = new byte[4]; // fall back to invalid 0.0.0.0 address
}

byte[] rlphost = RLP.encodeElement(host);
byte[] rlphost = RLP.encodeElement(ip);
byte[] rlpTCPPort = RLP.encodeInt(port);
byte[] rlpUDPPort = RLP.encodeInt(port);
byte[] rlpId = RLP.encodeElement(id);
Expand Down

0 comments on commit 8307602

Please sign in to comment.