mirror of
https://github.com/vacp2p/linea-besu.git
synced 2026-01-09 21:17:54 -05:00
Keep enode nodeId stored as a BytesValue (#1274)
Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>
This commit is contained in:
@@ -102,7 +102,7 @@ public interface PeerConnection {
|
||||
}
|
||||
|
||||
default boolean isRemoteEnode(final EnodeURL remoteEnodeUrl) {
|
||||
return ((remoteEnodeUrl.getNodeId().equals(this.getPeer().getAddress().toString()))
|
||||
return ((remoteEnodeUrl.getNodeId().equals(this.getPeer().getAddress()))
|
||||
&& (remoteEnodeUrl.getListeningPort() == this.getPeer().getPort())
|
||||
&& (remoteEnodeUrl
|
||||
.getInetAddress()
|
||||
|
||||
@@ -52,7 +52,7 @@ public class DefaultPeer extends DefaultPeerId implements Peer {
|
||||
udpPort,
|
||||
OptionalInt.of(enodeURL.getListeningPort()));
|
||||
|
||||
return new DefaultPeer(BytesValue.fromHexString(enodeURL.getNodeId()), endpoint);
|
||||
return new DefaultPeer(enodeURL.getNodeId(), endpoint);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -67,7 +67,8 @@ public class StaticNodesParserTest {
|
||||
final File validFile = new File(resource.getFile());
|
||||
final Set<EnodeURL> enodes = StaticNodesParser.fromPath(validFile.toPath());
|
||||
|
||||
assertThat(enodes).containsExactly(validFileItems.toArray(new EnodeURL[validFileItems.size()]));
|
||||
assertThat(enodes)
|
||||
.containsExactlyInAnyOrder(validFileItems.toArray(new EnodeURL[validFileItems.size()]));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -125,9 +125,7 @@ public class SmartContractPermissioningController implements NodePermissioningPr
|
||||
|
||||
private static BytesValue encodeEnodeUrl(final EnodeURL enode) {
|
||||
return BytesValues.concatenate(
|
||||
encodeEnodeId(enode.getNodeId()),
|
||||
encodeIp(enode.getInetAddress()),
|
||||
encodePort(enode.getListeningPort()));
|
||||
enode.getNodeId(), encodeIp(enode.getInetAddress()), encodePort(enode.getListeningPort()));
|
||||
}
|
||||
|
||||
// As a function parameter an ip needs to be the appropriate number of bytes, big endian, and
|
||||
@@ -156,10 +154,4 @@ public class SmartContractPermissioningController implements NodePermissioningPr
|
||||
res[30] = (byte) ((port >> 8) & 0xFF);
|
||||
return BytesValue.wrap(res);
|
||||
}
|
||||
|
||||
// The enode high and low need to be 32 bytes each. They then get concatenated as they are
|
||||
// adjacent parameters
|
||||
private static BytesValue encodeEnodeId(final String id) {
|
||||
return BytesValue.fromHexString(id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user