|
|
|
@ -15,6 +15,7 @@ package tech.pegasys.pantheon.util.enode; |
|
|
|
|
import static com.google.common.base.Preconditions.checkArgument; |
|
|
|
|
|
|
|
|
|
import tech.pegasys.pantheon.util.NetworkUtility; |
|
|
|
|
import tech.pegasys.pantheon.util.bytes.BytesValue; |
|
|
|
|
|
|
|
|
|
import java.net.InetAddress; |
|
|
|
|
import java.net.URI; |
|
|
|
@ -38,7 +39,7 @@ public class EnodeURL { |
|
|
|
|
+ "(?<listening>\\d+)" |
|
|
|
|
+ "(\\?discport=(?<discovery>\\d+))?$"; |
|
|
|
|
|
|
|
|
|
private final String nodeId; |
|
|
|
|
private final BytesValue nodeId; |
|
|
|
|
private final InetAddress ip; |
|
|
|
|
private final Integer listeningPort; |
|
|
|
|
// DiscoveryPort will only be present if it differs from listening port, otherwise
|
|
|
|
@ -66,11 +67,7 @@ public class EnodeURL { |
|
|
|
|
final InetAddress address, |
|
|
|
|
final Integer listeningPort, |
|
|
|
|
final OptionalInt discoveryPort) { |
|
|
|
|
if (nodeId.startsWith("0x")) { |
|
|
|
|
this.nodeId = nodeId.substring(2); |
|
|
|
|
} else { |
|
|
|
|
this.nodeId = nodeId; |
|
|
|
|
} |
|
|
|
|
this.nodeId = BytesValue.fromHexString(nodeId); |
|
|
|
|
this.ip = address; |
|
|
|
|
this.listeningPort = listeningPort; |
|
|
|
|
// Only explicitly define a discovery port if it differs from the listening port
|
|
|
|
@ -99,7 +96,9 @@ public class EnodeURL { |
|
|
|
|
|
|
|
|
|
public URI toURI() { |
|
|
|
|
final String uri = |
|
|
|
|
String.format("enode://%s@%s:%d", nodeId, InetAddresses.toUriString(ip), listeningPort); |
|
|
|
|
String.format( |
|
|
|
|
"enode://%s@%s:%d", |
|
|
|
|
nodeId.toUnprefixedString(), InetAddresses.toUriString(ip), listeningPort); |
|
|
|
|
if (discoveryPort.isPresent()) { |
|
|
|
|
return URI.create(uri + String.format("?discport=%d", discoveryPort.getAsInt())); |
|
|
|
|
} else { |
|
|
|
@ -152,7 +151,7 @@ public class EnodeURL { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String getNodeId() { |
|
|
|
|
public BytesValue getNodeId() { |
|
|
|
|
return nodeId; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|