This repository has been archived by the owner on Sep 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added --nodes-whitelist param to CLI and NodeWhitelistController (#346)
* added --nodes-whitelist param to CLI and NodeWhitelistController
- Loading branch information
Showing
9 changed files
with
232 additions
and
6 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...rc/main/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright 2018 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. | ||
*/ | ||
package tech.pegasys.pantheon.ethereum.permissioning; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public class PermissioningConfiguration { | ||
private List<String> nodeWhitelist; | ||
private boolean nodeWhitelistSet; | ||
|
||
public List<String> getNodeWhitelist() { | ||
return nodeWhitelist; | ||
} | ||
|
||
public static PermissioningConfiguration createDefault() { | ||
final PermissioningConfiguration config = new PermissioningConfiguration(); | ||
config.nodeWhitelist = new ArrayList<>(); | ||
return config; | ||
} | ||
|
||
public void setNodeWhitelist(final Collection<String> nodeWhitelist) { | ||
if (nodeWhitelist != null) { | ||
this.nodeWhitelist.addAll(nodeWhitelist); | ||
this.nodeWhitelistSet = true; | ||
} | ||
} | ||
|
||
public boolean isNodeWhitelistSet() { | ||
return nodeWhitelistSet; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...est/java/tech/pegasys/pantheon/ethereum/permissioning/PermissioningConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright 2018 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. | ||
*/ | ||
package tech.pegasys.pantheon.ethereum.permissioning; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.junit.Test; | ||
|
||
public class PermissioningConfigurationTest { | ||
|
||
@Test | ||
public void defaultConfiguration() { | ||
final PermissioningConfiguration configuration = PermissioningConfiguration.createDefault(); | ||
assertThat(configuration.getNodeWhitelist()).isEmpty(); | ||
assertThat(configuration.isNodeWhitelistSet()).isFalse(); | ||
} | ||
|
||
@Test | ||
public void setNodeWhitelist() { | ||
final String[] nodes = {"enode://001@123:4567", "enode://002@123:4567", "enode://003@123:4567"}; | ||
final PermissioningConfiguration configuration = PermissioningConfiguration.createDefault(); | ||
configuration.setNodeWhitelist(Arrays.asList(nodes)); | ||
assertThat(configuration.getNodeWhitelist()).containsExactlyInAnyOrder(nodes); | ||
assertThat(configuration.isNodeWhitelistSet()).isTrue(); | ||
} | ||
|
||
@Test | ||
public void setNodeWhiteListPassingNull() { | ||
final PermissioningConfiguration configuration = PermissioningConfiguration.createDefault(); | ||
configuration.setNodeWhitelist(null); | ||
assertThat(configuration.getNodeWhitelist()).isEmpty(); | ||
assertThat(configuration.isNodeWhitelistSet()).isFalse(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
pantheon/src/main/java/tech/pegasys/pantheon/controller/NodeWhitelistController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2018 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. | ||
*/ | ||
package tech.pegasys.pantheon.controller; | ||
|
||
import tech.pegasys.pantheon.ethereum.permissioning.PermissioningConfiguration; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class NodeWhitelistController { | ||
|
||
private static final Logger LOG = LogManager.getLogger(); | ||
|
||
private static List<String> nodeWhitelist; | ||
private static boolean nodeWhitelistSet = false; | ||
|
||
public NodeWhitelistController(final PermissioningConfiguration configuration) { | ||
nodeWhitelist = new ArrayList<>(); | ||
if (configuration != null && configuration.getNodeWhitelist() != null) { | ||
nodeWhitelist.addAll(configuration.getNodeWhitelist()); | ||
nodeWhitelistSet = true; | ||
} | ||
} | ||
|
||
public boolean addNode(final String nodeId) { | ||
return nodeWhitelist.add(nodeId); | ||
} | ||
|
||
public boolean removeNode(final String nodeId) { | ||
return nodeWhitelist.remove(nodeId); | ||
} | ||
|
||
public static boolean isNodeWhitelistSet() { | ||
return nodeWhitelistSet; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.