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