mirror of https://github.com/hyperledger/besu
[NC-2005] Implemented --p2p-enabled configuration item (#619)
Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>pull/2/head
parent
a0ce15568e
commit
a1ef038865
@ -0,0 +1,57 @@ |
||||
/* |
||||
* Copyright 2019 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.tests.acceptance; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.AcceptanceTestBase; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster.Cluster; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster.ClusterConfiguration; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.cluster.ClusterConfigurationBuilder; |
||||
|
||||
import org.junit.Before; |
||||
import org.junit.Test; |
||||
|
||||
public class P2pDisabledAcceptanceTest extends AcceptanceTestBase { |
||||
private Node node; |
||||
private Cluster p2pDisabledCluster; |
||||
|
||||
@Before |
||||
public void setUp() throws Exception { |
||||
final ClusterConfiguration clusterConfiguration = |
||||
new ClusterConfigurationBuilder().setAwaitPeerDiscovery(false).build(); |
||||
|
||||
p2pDisabledCluster = new Cluster(clusterConfiguration, net); |
||||
node = pantheon.createArchiveNodeWithP2pDisabled("node1"); |
||||
p2pDisabledCluster.start(node); |
||||
} |
||||
|
||||
@Override |
||||
public void tearDownAcceptanceTestBase() { |
||||
p2pDisabledCluster.stop(); |
||||
super.tearDownAcceptanceTestBase(); |
||||
} |
||||
|
||||
@Test |
||||
public void shouldSucceedExecutingUnaffectedJsonRpcCall() { |
||||
final String input = "0x68656c6c6f20776f726c64"; |
||||
final String expectedHash = |
||||
"0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad"; |
||||
|
||||
node.verify(web3.sha3(input, expectedHash)); |
||||
} |
||||
|
||||
@Test |
||||
public void shouldFailExecutingAffectedJsonRpcCall() { |
||||
node.verify(net.awaitPeerCountExceptional()); |
||||
} |
||||
} |
@ -0,0 +1,36 @@ |
||||
/* |
||||
* 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.tests.acceptance.dsl.condition.net; |
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat; |
||||
import static org.assertj.core.api.Assertions.catchThrowable; |
||||
|
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.condition.Condition; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.node.Node; |
||||
import tech.pegasys.pantheon.tests.acceptance.dsl.transaction.net.NetPeerCountTransaction; |
||||
|
||||
public class AwaitNetPeerCountException implements Condition { |
||||
|
||||
private final NetPeerCountTransaction transaction; |
||||
|
||||
public AwaitNetPeerCountException(final NetPeerCountTransaction transaction) { |
||||
this.transaction = transaction; |
||||
} |
||||
|
||||
@Override |
||||
public void verify(final Node node) { |
||||
final Throwable thrown = catchThrowable(() -> node.execute(transaction)); |
||||
assertThat(thrown).isInstanceOf(RuntimeException.class); |
||||
assertThat(thrown).hasMessageContaining("P2P has been disabled."); |
||||
} |
||||
} |
@ -0,0 +1,90 @@ |
||||
/* |
||||
* Copyright 2019 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.p2p; |
||||
|
||||
import tech.pegasys.pantheon.ethereum.p2p.api.DisconnectCallback; |
||||
import tech.pegasys.pantheon.ethereum.p2p.api.Message; |
||||
import tech.pegasys.pantheon.ethereum.p2p.api.P2PNetwork; |
||||
import tech.pegasys.pantheon.ethereum.p2p.api.PeerConnection; |
||||
import tech.pegasys.pantheon.ethereum.p2p.peers.Peer; |
||||
import tech.pegasys.pantheon.ethereum.p2p.permissioning.NodeWhitelistController; |
||||
import tech.pegasys.pantheon.ethereum.p2p.wire.Capability; |
||||
import tech.pegasys.pantheon.ethereum.p2p.wire.PeerInfo; |
||||
|
||||
import java.io.IOException; |
||||
import java.net.InetSocketAddress; |
||||
import java.util.Collection; |
||||
import java.util.concurrent.CompletableFuture; |
||||
import java.util.function.Consumer; |
||||
|
||||
public class NoopP2PNetwork implements P2PNetwork { |
||||
@Override |
||||
public Collection<PeerConnection> getPeers() { |
||||
throw new P2pDisabledException("P2P networking disabled. Peers list unavailable."); |
||||
} |
||||
|
||||
@Override |
||||
public CompletableFuture<PeerConnection> connect(final Peer peer) { |
||||
throw new P2pDisabledException("P2P networking disabled. Unable to connect to network."); |
||||
} |
||||
|
||||
@Override |
||||
public void subscribe(final Capability capability, final Consumer<Message> consumer) {} |
||||
|
||||
@Override |
||||
public void subscribeConnect(final Consumer<PeerConnection> consumer) {} |
||||
|
||||
@Override |
||||
public void subscribeDisconnect(final DisconnectCallback consumer) {} |
||||
|
||||
@Override |
||||
public boolean addMaintainConnectionPeer(final Peer peer) { |
||||
throw new P2pDisabledException("P2P networking disabled. Unable to connect to add peer."); |
||||
} |
||||
|
||||
@Override |
||||
public void checkMaintainedConnectionPeers() {} |
||||
|
||||
@Override |
||||
public void stop() {} |
||||
|
||||
@Override |
||||
public void awaitStop() {} |
||||
|
||||
@Override |
||||
public InetSocketAddress getDiscoverySocketAddress() { |
||||
throw new P2pDisabledException( |
||||
"P2P networking disabled. Discovery socket address unavailable."); |
||||
} |
||||
|
||||
@Override |
||||
public PeerInfo getLocalPeerInfo() { |
||||
throw new P2pDisabledException("P2P networking disabled. Local peer info unavailable."); |
||||
} |
||||
|
||||
@Override |
||||
public boolean isListening() { |
||||
return false; |
||||
} |
||||
|
||||
@Override |
||||
public NodeWhitelistController getNodeWhitelistController() { |
||||
throw new P2pDisabledException("P2P networking disabled. Node whitelist unavailable."); |
||||
} |
||||
|
||||
@Override |
||||
public void close() throws IOException {} |
||||
|
||||
@Override |
||||
public void run() {} |
||||
} |
@ -0,0 +1,19 @@ |
||||
/* |
||||
* Copyright 2019 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.p2p; |
||||
|
||||
public class P2pDisabledException extends RuntimeException { |
||||
public P2pDisabledException(final String message) { |
||||
super(message); |
||||
} |
||||
} |
Loading…
Reference in new issue