Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add dns support #1247

Merged
merged 17 commits into from
Aug 25, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Additions and Improvements

* The EvmTool now processes State Tests from the Ethereum Reference Tests. [\#1311](https://github.com/hyperledger/besu/pull/1311)
* Experimental dns support added via the `Xdns-enabled` and `Xdns-update-enabled` CLI commands. [\#1247](https://github.com/hyperledger/besu/pull/1247)

### Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public class BesuNode implements NodeConfiguration, RunnableNode, AutoCloseable
private final List<String> plugins = new ArrayList<>();
private final List<String> extraCLIOptions;
private final List<String> staticNodes;
private boolean isDnsEnabled = false;
private Optional<Integer> exitCode = Optional.empty();

public BesuNode(
Expand All @@ -132,6 +133,7 @@ public BesuNode(
final List<String> plugins,
final List<String> extraCLIOptions,
final List<String> staticNodes,
final boolean isDnsEnabled,
final Optional<PrivacyParameters> privacyParameters,
final List<String> runCommand)
throws IOException {
Expand Down Expand Up @@ -174,6 +176,7 @@ public BesuNode(
});
this.extraCLIOptions = extraCLIOptions;
this.staticNodes = staticNodes;
this.isDnsEnabled = isDnsEnabled;
privacyParameters.ifPresent(this::setPrivacyParameters);
LOG.info("Created BesuNode {}", this.toString());
}
Expand Down Expand Up @@ -609,6 +612,10 @@ public List<String> getStaticNodes() {
return staticNodes;
}

public boolean isDnsEnabled() {
return isDnsEnabled;
}

public boolean hasStaticNodes() {
return staticNodes != null && !staticNodes.isEmpty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ public void startNode(final BesuNode node) {
createStaticNodes(node);
}

if (node.isDnsEnabled()) {
params.add("--Xdns-enabled");
params.add("true");
params.add("--Xdns-update-enabled");
params.add("true");
}

if (node.isJsonRpcEnabled()) {
params.add("--rpc-http-enabled");
params.add("--rpc-http-host");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class BesuNodeConfiguration {
private final List<String> plugins;
private final List<String> extraCLIOptions;
private final List<String> staticNodes;
private final boolean isDnsEnabled;
private final Optional<PrivacyParameters> privacyParameters;
private final List<String> runCommand;

Expand All @@ -73,6 +74,7 @@ public class BesuNodeConfiguration {
final List<String> plugins,
final List<String> extraCLIOptions,
final List<String> staticNodes,
final boolean isDnsEnabled,
final Optional<PrivacyParameters> privacyParameters,
final List<String> runCommand) {
this.name = name;
Expand All @@ -95,6 +97,7 @@ public class BesuNodeConfiguration {
this.plugins = plugins;
this.extraCLIOptions = extraCLIOptions;
this.staticNodes = staticNodes;
this.isDnsEnabled = isDnsEnabled;
this.privacyParameters = privacyParameters;
this.runCommand = runCommand;
}
Expand Down Expand Up @@ -179,6 +182,10 @@ public List<String> getStaticNodes() {
return staticNodes;
}

public boolean isDnsEnabled() {
return isDnsEnabled;
}

public Optional<PrivacyParameters> getPrivacyParameters() {
return privacyParameters;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class BesuNodeConfigurationBuilder {
private final List<String> plugins = new ArrayList<>();
private final List<String> extraCLIOptions = new ArrayList<>();
private List<String> staticNodes = new ArrayList<>();
private boolean isDnsEnabled = false;
private Optional<PrivacyParameters> privacyParameters = Optional.empty();
private List<String> runCommand = new ArrayList<>();

Expand Down Expand Up @@ -268,6 +269,11 @@ public BesuNodeConfigurationBuilder staticNodes(final List<String> staticNodes)
return this;
}

public BesuNodeConfigurationBuilder dnsEnabled(final boolean isDnsEnabled) {
this.isDnsEnabled = isDnsEnabled;
return this;
}

public BesuNodeConfigurationBuilder privacyParameters(final PrivacyParameters privacyParameters) {
this.privacyParameters = Optional.ofNullable(privacyParameters);
return this;
Expand Down Expand Up @@ -300,6 +306,7 @@ public BesuNodeConfiguration build() {
plugins,
extraCLIOptions,
staticNodes,
isDnsEnabled,
privacyParameters,
runCommand);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public BesuNode create(final BesuNodeConfiguration config) throws IOException {
config.getPlugins(),
config.getExtraCLIOptions(),
config.getStaticNodes(),
config.isDnsEnabled(),
config.getPrivacyParameters(),
config.getRunCommand());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApi;
import org.hyperledger.besu.ethereum.api.jsonrpc.RpcApis;
import org.hyperledger.besu.ethereum.core.Address;
import org.hyperledger.besu.ethereum.p2p.peers.EnodeURL;
import org.hyperledger.besu.ethereum.permissioning.AllowlistPersistor;
import org.hyperledger.besu.ethereum.permissioning.AllowlistPersistor.ALLOWLIST_TYPE;
import org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration;
Expand Down Expand Up @@ -71,6 +72,7 @@ public class PermissionedNodeBuilder {
private String accountPermissioningSmartContractAddress = null;

private List<String> staticNodes = new ArrayList<>();
private boolean isDnsEnabled = false;
private boolean mining = true;

public PermissionedNodeBuilder name(final String name) {
Expand Down Expand Up @@ -139,6 +141,11 @@ public PermissionedNodeBuilder staticNodes(final List<String> staticNodes) {
return this;
}

public PermissionedNodeBuilder dnsEnabled(final boolean isDnsEnabled) {
this.isDnsEnabled = isDnsEnabled;
return this;
}

public PermissionedNodeBuilder disableMining() {
this.mining = false;
return this;
Expand Down Expand Up @@ -188,6 +195,8 @@ public BesuNode build() {
builder.staticNodes(staticNodes);
}

builder.dnsEnabled(isDnsEnabled);

if (genesisFile != null) {
builder.genesisConfigProvider((a) -> Optional.of(genesisFile));
builder.devMode(false);
Expand All @@ -209,12 +218,15 @@ private LocalPermissioningConfiguration localConfigPermissioningConfiguration()
localConfigNodesPermissioningFile = createTemporaryPermissionsFile();
}

List<String> nodesAsListOfStrings =
localConfigPermittedNodes.stream().map(URI::toASCIIString).collect(Collectors.toList());
final List<EnodeURL> nodeAllowList =
localConfigPermittedNodes.stream().map(EnodeURL::fromURI).collect(Collectors.toList());

initPermissioningConfigurationFile(
ALLOWLIST_TYPE.NODES, nodesAsListOfStrings, localConfigNodesPermissioningFile);
ALLOWLIST_TYPE.NODES,
nodeAllowList.stream().map(EnodeURL::toString).collect(Collectors.toList()),
localConfigNodesPermissioningFile);

localPermissioningConfiguration.setNodeAllowlist(localConfigPermittedNodes);
localPermissioningConfiguration.setNodeAllowlist(nodeAllowList);
localPermissioningConfiguration.setNodePermissioningConfigFilePath(
localConfigNodesPermissioningFile.toAbsolutePath().toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public PrivacyNode(final PrivacyNodeConfiguration privacyConfiguration, final Ve
besuConfig.getPlugins(),
besuConfig.getExtraCLIOptions(),
Collections.emptyList(),
besuConfig.isDnsEnabled(),
besuConfig.getPrivacyParameters(),
List.of());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import java.util.ArrayList;
import java.util.Collections;

import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import org.web3j.protocol.exceptions.ClientConnectionException;

public class AllowlistPersistorAcceptanceTest extends AcceptanceTestBase {

Expand All @@ -36,6 +38,8 @@ public class AllowlistPersistorAcceptanceTest extends AcceptanceTestBase {
"enode://5f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.10:4567";
private static final String ENODE_THREE =
"enode://4f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.10:4567";
private static final String ENODE_FOURTH =
"enode://4f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@localhost:4567";

private Node node;
private Account senderA;
Expand Down Expand Up @@ -99,4 +103,11 @@ public void manipulatedNodesWhitelistIsPersisted() {
perm.expectPermissioningAllowlistFileKeyValue(
ALLOWLIST_TYPE.NODES, tempFile, ENODE_TWO, ENODE_ONE, ENODE_THREE));
}

@Test
public void manipulatedNodesWhitelistWithHostnameShouldNotWorkWhenDnsDisabled() {
Assertions.assertThatThrownBy(() -> node.verify(perm.addNodesToAllowlist(ENODE_FOURTH)))
.isInstanceOf(ClientConnectionException.class)
.hasMessageContaining("Request contains an invalid node");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright ConsenSys AG.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.tests.acceptance.permissioning;

import static org.hyperledger.besu.ethereum.permissioning.AllowlistPersistor.ALLOWLIST_TYPE;

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.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;

import org.junit.Before;
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 Node node;
private Account senderA;
private Path tempFile;

@Before
public void setUp() throws Exception {
senderA = accounts.getPrimaryBenefactor();
tempFile = Files.createTempFile("test", "test");

this.node =
permissionedNodeBuilder
.name("node")
.nodesConfigFile(tempFile)
.nodesPermittedInConfig(new ArrayList<>())
.accountsConfigFile(tempFile)
.accountsPermittedInConfig(Collections.singletonList(senderA.getAddress()))
.dnsEnabled(true)
.build();

cluster.start(this.node);
}

@Test
public void manipulatedNodesWhitelistWithHostnameShouldWorkWhenDnsEnabled() {

node.verify(perm.addNodesToAllowlist(ENODE_ONE, ENODE_TWO));
node.verify(
perm.expectPermissioningAllowlistFileKeyValue(
ALLOWLIST_TYPE.NODES, tempFile, ENODE_ONE, ENODE_TWO));

node.verify(perm.removeNodesFromAllowlist(ENODE_ONE));
node.verify(
perm.expectPermissioningAllowlistFileKeyValue(ALLOWLIST_TYPE.NODES, tempFile, ENODE_TWO));

node.verify(perm.addNodesToAllowlist(ENODE_ONE, ENODE_THREE));
node.verify(
perm.expectPermissioningAllowlistFileKeyValue(
ALLOWLIST_TYPE.NODES, tempFile, ENODE_TWO, ENODE_ONE, ENODE_THREE));
}
}
Loading