Upgrade EnodeURL builder strategy (#3483)

* Upgrade EnodeURLImpl builder strategy
* Lookup the local hostname if specifying localhost/loopback
* Add test for valid domain that can be found and can not be found

Signed-off-by: Antony Denyer <git@antonydenyer.co.uk>
Co-authored-by: Alberto Hernandez <albherna@gmail.com>
pull/3647/head
Alberto Hernandez 3 years ago committed by GitHub
parent 7e0d06ac61
commit aad52d1ae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/AllowlistWithDnsPersistorAcceptanceTest.java
  2. 13
      acceptance-tests/tests/src/test/java/org/hyperledger/besu/tests/acceptance/permissioning/NodeSmartContractPermissioningV2DNSAcceptanceTest.java
  3. 17
      ethereum/p2p/src/main/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImpl.java
  4. 58
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/peers/EnodeURLImplTest.java
  5. 2
      ethereum/p2p/src/test/java/org/hyperledger/besu/ethereum/p2p/peers/StaticNodesParserTest.java
  6. 8
      ethereum/p2p/src/test/resources/org/hyperledger/besu/ethereum/p2p/peers/unknown_hostname_static_nodes.json
  7. 2
      ethereum/p2p/src/test/resources/org/hyperledger/besu/ethereum/p2p/peers/valid_hostname_static_nodes.json
  8. 2
      ethereum/p2p/src/test/resources/org/hyperledger/besu/ethereum/p2p/peers/valid_static_nodes.json
  9. 16
      ethereum/permissioning/src/test/java/org/hyperledger/besu/ethereum/permissioning/NodeLocalConfigPermissioningControllerTest.java
  10. 37
      ethereum/permissioning/src/test/java/org/hyperledger/besu/ethereum/permissioning/NodeSmartContractV2PermissioningControllerTest.java
  11. 45
      ethereum/permissioning/src/test/java/org/hyperledger/besu/ethereum/permissioning/node/provider/SyncStatusNodePermissioningProviderTest.java

@ -20,6 +20,7 @@ import org.hyperledger.besu.tests.acceptance.dsl.AcceptanceTestBase;
import org.hyperledger.besu.tests.acceptance.dsl.account.Account;
import org.hyperledger.besu.tests.acceptance.dsl.node.Node;
import java.net.InetAddress;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@ -30,12 +31,9 @@ import org.junit.Test;
public class AllowlistWithDnsPersistorAcceptanceTest extends AcceptanceTestBase {
private static final String ENODE_ONE =
"enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@localhost:4567";
private static final String ENODE_TWO =
"enode://5f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.10:4567";
private static final String ENODE_THREE =
"enode://4f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.11:4567";
private String ENODE_ONE;
private String ENODE_TWO;
private String ENODE_THREE;
private Node node;
private Account senderA;
@ -43,6 +41,15 @@ public class AllowlistWithDnsPersistorAcceptanceTest extends AcceptanceTestBase
@Before
public void setUp() throws Exception {
ENODE_ONE =
"enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@"
+ InetAddress.getLocalHost().getHostName()
+ ":4567";
ENODE_TWO =
"enode://5f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.10:4567";
ENODE_THREE =
"enode://4f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.11:4567";
senderA = accounts.getPrimaryBenefactor();
tempFile = Files.createTempFile("test", "test");

@ -20,6 +20,9 @@ import org.hyperledger.besu.plugin.data.EnodeURL;
import org.hyperledger.besu.tests.acceptance.dsl.node.Node;
import org.hyperledger.besu.tests.acceptance.dsl.node.RunnableNode;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
@ -63,11 +66,12 @@ public class NodeSmartContractPermissioningV2DNSAcceptanceTest
}
@Test
public void permissionedNodeShouldAddDnsRuleAndAllowNode() {
public void permissionedNodeShouldAddDnsRuleAndAllowNode() throws UnknownHostException {
final EnodeURL forbiddenEnodeURL = getForbiddenEnodeURL();
Assertions.assertThat(forbiddenEnodeURL.toURI().getHost()).isEqualTo("127.0.0.1");
final EnodeURL forbiddenDnsEnodeURL = buildDnsEnodeUrl(forbiddenEnodeURL);
Assertions.assertThat(forbiddenDnsEnodeURL.toURI().getHost()).isEqualTo("localhost");
Assertions.assertThat(forbiddenDnsEnodeURL.toURI().getHost())
.isEqualTo(InetAddress.getLocalHost().getHostName());
permissionedNode.verify(connectionIsForbidden(forbiddenNode));
permissionedNode.verify(connectionIsForbidden(forbiddenDnsEnodeURL));
@ -77,11 +81,12 @@ public class NodeSmartContractPermissioningV2DNSAcceptanceTest
}
@Test
public void permissionedNodeShouldAddDNSRuleAndConnectToNewPeer() {
public void permissionedNodeShouldAddDNSRuleAndConnectToNewPeer() throws UnknownHostException {
final EnodeURL forbiddenEnodeURL = getForbiddenEnodeURL();
Assertions.assertThat(forbiddenEnodeURL.toURI().getHost()).isEqualTo("127.0.0.1");
final EnodeURL forbiddenDnsEnodeURL = buildDnsEnodeUrl(forbiddenEnodeURL);
Assertions.assertThat(forbiddenDnsEnodeURL.toURI().getHost()).isEqualTo("localhost");
Assertions.assertThat(forbiddenDnsEnodeURL.toURI().getHost())
.isEqualTo(InetAddress.getLocalHost().getHostName());
permissionedNode.verify(net.awaitPeerCount(2));
permissionedNode.verify(connectionIsForbidden(forbiddenNode));

@ -354,16 +354,15 @@ public class EnodeURLImpl implements EnodeURL {
}
public Builder ipAddress(final String ip, final EnodeDnsConfiguration enodeDnsConfiguration) {
if (InetAddresses.isUriInetAddress(ip)) {
this.ip = InetAddresses.forUriString(ip);
} else if (InetAddresses.isInetAddress(ip)) {
this.ip = InetAddresses.forString(ip);
} else if (enodeDnsConfiguration.dnsEnabled()) {
if (enodeDnsConfiguration.dnsEnabled()) {
try {
this.ip = InetAddress.getByName(ip);
if (enodeDnsConfiguration.updateEnabled()) {
this.maybeHostname = Optional.of(ip);
if (this.ip.isLoopbackAddress()) {
this.ip = InetAddress.getLocalHost();
}
this.maybeHostname = Optional.of(this.ip.getHostName());
}
this.ip = InetAddress.getByName(ip);
} catch (final UnknownHostException e) {
if (!enodeDnsConfiguration.updateEnabled()) {
throw new IllegalArgumentException("Invalid ip address or hostname.");
@ -371,6 +370,10 @@ public class EnodeURLImpl implements EnodeURL {
this.ip = InetAddresses.forString("127.0.0.1");
}
}
} else if (InetAddresses.isUriInetAddress(ip)) {
this.ip = InetAddresses.forUriString(ip);
} else if (InetAddresses.isInetAddress(ip)) {
this.ip = InetAddresses.forString(ip);
} else {
throw new IllegalArgumentException("Invalid ip address.");
}

@ -22,7 +22,9 @@ import static org.assertj.core.api.Assertions.catchThrowable;
import org.hyperledger.besu.plugin.data.EnodeURL;
import org.hyperledger.besu.util.IllegalPortException;
import java.net.InetAddress;
import java.net.URI;
import java.net.UnknownHostException;
import java.util.Optional;
import java.util.stream.Stream;
@ -490,8 +492,15 @@ public class EnodeURLImplTest {
}
@Test
public void toURI_WithHostnameShouldWorkWhenDnsEnabledAndUpdateEnabled() {
final String enodeURLString = "enode://" + VALID_NODE_ID + "@" + "localhost" + ":" + P2P_PORT;
public void toURI_WithHostnameShouldWorkWhenDnsEnabledAndUpdateEnabled()
throws UnknownHostException {
final String enodeURLString =
"enode://"
+ VALID_NODE_ID
+ "@"
+ InetAddress.getLocalHost().getHostName()
+ ":"
+ P2P_PORT;
final URI expectedURI = URI.create(enodeURLString);
final URI createdURI =
EnodeURLImpl.fromString(
@ -913,4 +922,49 @@ public class EnodeURLImplTest {
assertThat(nodeId.size()).isEqualTo(EnodeURLImpl.NODE_ID_SIZE);
assertThat(nodeId.toUnprefixedHexString()).isEqualTo(validId);
}
@Test
public void toURIWithoutDiscoveryPortShouldProduceEntryWithHostnameWhenUsingLoopbackAddress()
throws UnknownHostException {
String enodeString = String.format("enode://%s@%s:%d", VALID_NODE_ID, "127.0.0.1", 9999);
final EnodeURL enodeA =
EnodeURLImpl.fromString(
enodeString,
ImmutableEnodeDnsConfiguration.builder().dnsEnabled(true).updateEnabled(true).build());
URI expected =
URI.create(
String.format(
"enode://%s@%s:%d", VALID_NODE_ID, InetAddress.getLocalHost().getHostName(), 9999));
assertThat(enodeA.toURIWithoutDiscoveryPort()).isEqualTo(expected);
}
@Test
public void toURIWithoutDiscoveryPortShouldUseLoopbackWhenDomainNotFound() {
String enodeString =
String.format("enode://%s@%s:%d", VALID_NODE_ID, "besu-is-awesome.example.com", 9999);
final EnodeURL enodeA =
EnodeURLImpl.fromString(
enodeString,
ImmutableEnodeDnsConfiguration.builder().dnsEnabled(true).updateEnabled(true).build());
URI expected = URI.create(String.format("enode://%s@%s:%d", VALID_NODE_ID, "127.0.0.1", 9999));
assertThat(enodeA.toURIWithoutDiscoveryPort()).isEqualTo(expected);
}
@Test
public void toURIWithoutDiscoveryPortShouldKeepDomainWhenFound() {
String enodeString = String.format("enode://%s@%s:%d", VALID_NODE_ID, "hyperledger.org", 9999);
final EnodeURL enodeA =
EnodeURLImpl.fromString(
enodeString,
ImmutableEnodeDnsConfiguration.builder().dnsEnabled(true).updateEnabled(true).build());
URI expected =
URI.create(String.format("enode://%s@%s:%d", VALID_NODE_ID, "hyperledger.org", 9999));
assertThat(enodeA.toURIWithoutDiscoveryPort()).isEqualTo(expected);
}
}

@ -59,7 +59,7 @@ public class StaticNodesParserTest {
EnodeURLImpl.builder()
.nodeId(
"819e5cbd81f123516b10f04bf620daa2b385efef06d77253148b814bf1bb6197ff58ebd1fd7bf5dc765b49a4440c733bf941e479c800173f2bfeb887e4fbcbc2")
.ipAddress("127.0.0.1")
.ipAddress("10.0.0.1")
.discoveryAndListeningPorts(30305)
.build(),
EnodeURLImpl.builder()

@ -1,4 +1,4 @@
["enode://50203c6bfca6874370e71aecc8958529fd723feb05013dc1abca8fc1fff845c5259faba05852e9dfe5ce172a7d6e7c2a3a5eaa8b541c8af15ea5518bbff5f2fa@localhost:30303",
"enode://02beb46bc17227616be44234071dfa18516684e45eed88049190b6cb56b0bae218f045fd0450f123b8f55c60b96b78c45e8e478004293a8de6818aa4e02eff97@nodfound:30304",
"enode://819e5cbd81f123516b10f04bf620daa2b385efef06d77253148b814bf1bb6197ff58ebd1fd7bf5dc765b49a4440c733bf941e479c800173f2bfeb887e4fbcbc2@127.0.0.1:30305",
"enode://6cf53e25d2a98a22e7e205a86bda7077e3c8a7bc99e5ff88ddfd2037a550969ab566f069ffa455df0cfae0c21f7aec3447e414eccc473a3e8b20984b90f164ac@127.0.0.1:30306"]
["enode://50203c6bfca6874370e71aecc8958529fd723feb05013dc1abca8fc1fff845c5259faba05852e9dfe5ce172a7d6e7c2a3a5eaa8b541c8af15ea5518bbff5f2fa@not-found:30303",
"enode://02beb46bc17227616be44234071dfa18516684e45eed88049190b6cb56b0bae218f045fd0450f123b8f55c60b96b78c45e8e478004293a8de6818aa4e02eff97@not-found:30304",
"enode://819e5cbd81f123516b10f04bf620daa2b385efef06d77253148b814bf1bb6197ff58ebd1fd7bf5dc765b49a4440c733bf941e479c800173f2bfeb887e4fbcbc2@10.0.0.1:30305",
"enode://6cf53e25d2a98a22e7e205a86bda7077e3c8a7bc99e5ff88ddfd2037a550969ab566f069ffa455df0cfae0c21f7aec3447e414eccc473a3e8b20984b90f164ac@not-found:30306"]

@ -1,4 +1,4 @@
["enode://50203c6bfca6874370e71aecc8958529fd723feb05013dc1abca8fc1fff845c5259faba05852e9dfe5ce172a7d6e7c2a3a5eaa8b541c8af15ea5518bbff5f2fa@localhost:30303",
"enode://02beb46bc17227616be44234071dfa18516684e45eed88049190b6cb56b0bae218f045fd0450f123b8f55c60b96b78c45e8e478004293a8de6818aa4e02eff97@localhost:30304",
"enode://819e5cbd81f123516b10f04bf620daa2b385efef06d77253148b814bf1bb6197ff58ebd1fd7bf5dc765b49a4440c733bf941e479c800173f2bfeb887e4fbcbc2@127.0.0.1:30305",
"enode://819e5cbd81f123516b10f04bf620daa2b385efef06d77253148b814bf1bb6197ff58ebd1fd7bf5dc765b49a4440c733bf941e479c800173f2bfeb887e4fbcbc2@10.0.0.1:30305",
"enode://6cf53e25d2a98a22e7e205a86bda7077e3c8a7bc99e5ff88ddfd2037a550969ab566f069ffa455df0cfae0c21f7aec3447e414eccc473a3e8b20984b90f164ac@127.0.0.1:30306"]

@ -1,4 +1,4 @@
["enode://50203c6bfca6874370e71aecc8958529fd723feb05013dc1abca8fc1fff845c5259faba05852e9dfe5ce172a7d6e7c2a3a5eaa8b541c8af15ea5518bbff5f2fa@127.0.0.1:30303",
"enode://02beb46bc17227616be44234071dfa18516684e45eed88049190b6cb56b0bae218f045fd0450f123b8f55c60b96b78c45e8e478004293a8de6818aa4e02eff97@127.0.0.1:30304",
"enode://819e5cbd81f123516b10f04bf620daa2b385efef06d77253148b814bf1bb6197ff58ebd1fd7bf5dc765b49a4440c733bf941e479c800173f2bfeb887e4fbcbc2@127.0.0.1:30305",
"enode://819e5cbd81f123516b10f04bf620daa2b385efef06d77253148b814bf1bb6197ff58ebd1fd7bf5dc765b49a4440c733bf941e479c800173f2bfeb887e4fbcbc2@10.0.0.1:30305",
"enode://6cf53e25d2a98a22e7e205a86bda7077e3c8a7bc99e5ff88ddfd2037a550969ab566f069ffa455df0cfae0c21f7aec3447e414eccc473a3e8b20984b90f164ac@127.0.0.1:30306"]

@ -38,6 +38,7 @@ import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.Counter;
import java.io.IOException;
import java.net.InetAddress;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@ -350,6 +351,9 @@ public class NodeLocalConfigPermissioningControllerTest {
when(permissioningConfig.isNodeAllowlistEnabled()).thenReturn(true);
when(permissioningConfig.getNodeAllowlist())
.thenReturn(Arrays.asList(EnodeURLImpl.fromString(expectedEnodeURL)));
when(permissioningConfig.getEnodeDnsConfiguration())
.thenReturn(EnodeDnsConfiguration.dnsDisabled());
controller =
new NodeLocalConfigPermissioningController(
permissioningConfig, bootnodesList, selfEnode.getNodeId(), metricsSystem);
@ -471,6 +475,9 @@ public class NodeLocalConfigPermissioningControllerTest {
when(permissioningConfig.isNodeAllowlistEnabled()).thenReturn(true);
when(permissioningConfig.getNodeAllowlist())
.thenReturn(Arrays.asList(EnodeURLImpl.fromString(enode1)));
when(permissioningConfig.getEnodeDnsConfiguration())
.thenReturn(EnodeDnsConfiguration.dnsDisabled());
controller =
new NodeLocalConfigPermissioningController(
permissioningConfig, bootnodesList, selfEnode.getNodeId(), metricsSystem);
@ -495,6 +502,9 @@ public class NodeLocalConfigPermissioningControllerTest {
when(permissioningConfig.isNodeAllowlistEnabled()).thenReturn(true);
when(permissioningConfig.getNodeAllowlist())
.thenReturn(Arrays.asList(EnodeURLImpl.fromString(enode1)));
when(permissioningConfig.getEnodeDnsConfiguration())
.thenReturn(EnodeDnsConfiguration.dnsDisabled());
controller =
new NodeLocalConfigPermissioningController(
permissioningConfig, bootnodesList, selfEnode.getNodeId(), metricsSystem);
@ -548,7 +558,11 @@ public class NodeLocalConfigPermissioningControllerTest {
new NodeLocalConfigPermissioningController(
permissioningConfig, bootnodesList, selfEnode.getNodeId(), metricsSystem);
assertThat(controller.getNodesAllowlist()).hasSize(1);
assertThat(controller.getNodesAllowlist()).contains(enodeDns);
assertThat(controller.getNodesAllowlist())
.contains(
"enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@"
+ InetAddress.getLocalHost().getHostName()
+ ":4567");
}
private Path createPermissionsFileWithNode(final String node) throws IOException {

@ -14,6 +14,7 @@
*/
package org.hyperledger.besu.ethereum.permissioning;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.mockito.ArgumentMatchers.any;
@ -36,6 +37,8 @@ import org.hyperledger.besu.metrics.noop.NoOpMetricsSystem;
import org.hyperledger.besu.plugin.data.EnodeURL;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Optional;
import org.apache.tuweni.bytes.Bytes;
@ -54,13 +57,6 @@ public class NodeSmartContractV2PermissioningControllerTest {
Bytes.fromHexString(
"0x45a59e5b000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000009dd40000000000000000000000000000000000000000000000000000000000000080333534386338376239393230666631366161346264636630316338356632353131376132396165313537346437353962616434386363393436336438653966376333633164316539666230643238653733383938393531663930653032373134616262373730666436643232653930333731383832613435363538383030653900000000000000000000000000000000000000000000000000000000000000093132372e302e302e310000000000000000000000000000000000000000000000");
private static final Bytes SOURCE_ENODE_EXPECTED_PAYLOAD_DNS =
Bytes.fromHexString(
"0x45a59e5b00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000765f0000000000000000000000000000000000000000000000000000000000000080666362653966383332313834383762336330623530383738313933383830653663323563666438363730386330613062663063613931663063653633333734366138393266653234306166613562396138383062386263613438653861323237303465663933376664646132643763633633653464343165643162343137616500000000000000000000000000000000000000000000000000000000000000096c6f63616c686f73740000000000000000000000000000000000000000000000");
private static final Bytes DESTINATION_ENODE_EXPECTED_PAYLOAD_DNS =
Bytes.fromHexString(
"0x45a59e5b000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000009dd40000000000000000000000000000000000000000000000000000000000000080333534386338376239393230666631366161346264636630316338356632353131376132396165313537346437353962616434386363393436336438653966376333633164316539666230643238653733383938393531663930653032373134616262373730666436643232653930333731383832613435363538383030653900000000000000000000000000000000000000000000000000000000000000096c6f63616c686f73740000000000000000000000000000000000000000000000");
private static final EnodeURL SOURCE_ENODE_IPV4 =
EnodeURLImpl.fromString(
"enode://fcbe9f83218487b3c0b50878193880e6c25cfd86708c0a0bf0ca91f0ce633746a892fe240afa5b9a880b8bca48e8a22704ef937fdda2d7cc63e4d41ed1b417ae@127.0.0.1:30303");
@ -169,7 +165,8 @@ public class NodeSmartContractV2PermissioningControllerTest {
}
@Test
public void expectedPayloadWhenCheckingPermissioningWithAlternateDNS() {
public void expectedPayloadWhenCheckingPermissioningWithAlternateDNS()
throws UnknownHostException {
final TransactionSimulatorResult txSimulatorResultFalse =
transactionSimulatorResult(
NodeSmartContractV2PermissioningController.FALSE_RESPONSE, ValidationResult.valid());
@ -183,9 +180,12 @@ public class NodeSmartContractV2PermissioningControllerTest {
when(transactionSimulator.processAtHead(eq(callParams(DESTINATION_ENODE_EXPECTED_PAYLOAD_IP))))
.thenReturn(Optional.of(txSimulatorResultFalse));
when(transactionSimulator.processAtHead(eq(callParams(SOURCE_ENODE_EXPECTED_PAYLOAD_DNS))))
var sourcePayload = sourceEnodeExpectedPayloadDns();
when(transactionSimulator.processAtHead(eq(callParams(Bytes.fromHexString(sourcePayload)))))
.thenReturn(Optional.of(txSimulatorResultTrue));
when(transactionSimulator.processAtHead(eq(callParams(DESTINATION_ENODE_EXPECTED_PAYLOAD_DNS))))
var destinationPayload = destinationEnodeExpectedPayloadDns();
when(transactionSimulator.processAtHead(
eq(callParams(Bytes.fromHexString(destinationPayload)))))
.thenReturn(Optional.of(txSimulatorResultTrue));
boolean isPermitted =
@ -206,4 +206,21 @@ public class NodeSmartContractV2PermissioningControllerTest {
TransactionProcessingResult.successful(
blockDataGenerator.logs(1, 1), 0L, 0L, output, validationResult));
}
// Note - don't use FunctionEncoder.makeFunction here otherwise we're not really testing anything!
private String sourceEnodeExpectedPayloadDns() throws UnknownHostException {
var hostname = InetAddress.getLocalHost().getHostName();
return "0x45a59e5b00000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000765f0000000000000000000000000000000000000000000000000000000000000080666362653966383332313834383762336330623530383738313933383830653663323563666438363730386330613062663063613931663063653633333734366138393266653234306166613562396138383062386263613438653861323237303465663933376664646132643763633633653464343165643162343137616500000000000000000000000000000000000000000000000000000000000000"
+ Bytes.of(hostname.length()).toUnprefixedHexString()
+ Bytes.of(hostname.getBytes(UTF_8)).toUnprefixedHexString()
+ "00".repeat(32 - hostname.length());
}
private String destinationEnodeExpectedPayloadDns() throws UnknownHostException {
var hostname = InetAddress.getLocalHost().getHostName();
return "0x45a59e5b000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000009dd40000000000000000000000000000000000000000000000000000000000000080333534386338376239393230666631366161346264636630316338356632353131376132396165313537346437353962616434386363393436336438653966376333633164316539666230643238653733383938393531663930653032373134616262373730666436643232653930333731383832613435363538383030653900000000000000000000000000000000000000000000000000000000000000"
+ Bytes.of(hostname.length()).toUnprefixedHexString()
+ Bytes.of(hostname.getBytes(UTF_8)).toUnprefixedHexString()
+ "00".repeat(32 - hostname.length());
}
}

@ -24,11 +24,14 @@ import static org.mockito.Mockito.when;
import org.hyperledger.besu.ethereum.core.Synchronizer;
import org.hyperledger.besu.ethereum.core.Synchronizer.InSyncListener;
import org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl;
import org.hyperledger.besu.ethereum.p2p.peers.ImmutableEnodeDnsConfiguration;
import org.hyperledger.besu.metrics.BesuMetricCategory;
import org.hyperledger.besu.plugin.data.EnodeURL;
import org.hyperledger.besu.plugin.services.MetricsSystem;
import org.hyperledger.besu.plugin.services.metrics.Counter;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.function.IntSupplier;
@ -253,4 +256,46 @@ public class SyncStatusNodePermissioningProviderTest {
assertThat(isPermitted).isTrue();
}
@Test
public void syncStatusPermissioningCheckShouldAllowDNS() throws UnknownHostException {
inSyncListener.onInSyncStatusChange(false);
assertThat(provider.hasReachedSync()).isFalse();
EnodeURL bootnode =
EnodeURLImpl.builder()
.nodeId(
"6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0")
.listeningPort(9999)
.disableDiscovery()
.ipAddress(
InetAddress.getLocalHost().getHostName(),
ImmutableEnodeDnsConfiguration.builder()
.dnsEnabled(true)
.updateEnabled(true)
.build())
.build();
EnodeURL enodeWithIP =
EnodeURLImpl.builder()
.nodeId(
"6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0")
.listeningPort(9999)
.disableDiscovery()
.ipAddress(
"127.0.0.1",
ImmutableEnodeDnsConfiguration.builder()
.dnsEnabled(true)
.updateEnabled(true)
.build())
.build();
final SyncStatusNodePermissioningProvider provider =
new SyncStatusNodePermissioningProvider(
synchronizer, Lists.newArrayList(bootnode), metricsSystem);
boolean isPermitted = provider.isConnectionPermitted(enode1, enodeWithIP);
assertThat(isPermitted).isTrue();
}
}

Loading…
Cancel
Save