Search in sources :

Example 6 with EnodeURL

use of org.hyperledger.besu.plugin.data.EnodeURL in project besu by hyperledger.

the class InsufficientPeersPermissioningProviderTest method firesUpdateWhenDisconnectLastNonBootnode.

@Test
public void firesUpdateWhenDisconnectLastNonBootnode() {
    final Collection<EnodeURL> bootnodes = Collections.singletonList(ENODE_2);
    final Collection<PeerConnection> pcs = Arrays.asList(peerConnectionMatching(ENODE_2), peerConnectionMatching(ENODE_3), peerConnectionMatching(ENODE_4));
    when(p2pNetwork.getPeers()).thenReturn(pcs);
    final InsufficientPeersPermissioningProvider provider = new InsufficientPeersPermissioningProvider(p2pNetwork, bootnodes);
    final ArgumentCaptor<DisconnectCallback> callbackCaptor = ArgumentCaptor.forClass(DisconnectCallback.class);
    verify(p2pNetwork).subscribeDisconnect(callbackCaptor.capture());
    final DisconnectCallback disconnectCallback = callbackCaptor.getValue();
    final Runnable updatePermsCallback = mock(Runnable.class);
    provider.subscribeToUpdates(updatePermsCallback);
    disconnectCallback.onDisconnect(peerConnectionMatching(ENODE_3), null, true);
    verify(updatePermsCallback, times(0)).run();
    disconnectCallback.onDisconnect(peerConnectionMatching(ENODE_4), null, true);
    verify(updatePermsCallback, times(1)).run();
    disconnectCallback.onDisconnect(peerConnectionMatching(ENODE_2), null, true);
    verify(updatePermsCallback, times(1)).run();
}
Also used : EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) DisconnectCallback(org.hyperledger.besu.ethereum.p2p.rlpx.DisconnectCallback) PeerConnection(org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection) Test(org.junit.Test)

Example 7 with EnodeURL

use of org.hyperledger.besu.plugin.data.EnodeURL in project besu by hyperledger.

the class InsufficientPeersPermissioningProviderTest method allowsConnectionIfBootnodeAndOnlyBootnodesConnected.

@Test
public void allowsConnectionIfBootnodeAndOnlyBootnodesConnected() {
    final Collection<EnodeURL> bootnodes = Collections.singletonList(ENODE_2);
    final PeerConnection bootnodeMatchPeerConnection = mock(PeerConnection.class);
    when(bootnodeMatchPeerConnection.getRemoteEnode()).thenReturn(ENODE_2);
    when(p2pNetwork.getPeers()).thenReturn(Collections.singletonList(bootnodeMatchPeerConnection));
    final InsufficientPeersPermissioningProvider provider = new InsufficientPeersPermissioningProvider(p2pNetwork, bootnodes);
    assertThat(provider.isPermitted(SELF_ENODE, ENODE_2)).contains(true);
    assertThat(provider.isPermitted(SELF_ENODE, ENODE_3)).isEmpty();
}
Also used : EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) PeerConnection(org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection) Test(org.junit.Test)

Example 8 with EnodeURL

use of org.hyperledger.besu.plugin.data.EnodeURL in project besu by hyperledger.

the class NodePermissioningControllerFactoryTest method testCreateWithSmartContractNodePermissioningEnabledOnlyAndBootnode.

@Test
public void testCreateWithSmartContractNodePermissioningEnabledOnlyAndBootnode() {
    final Collection<EnodeURL> fixedNodes = Collections.singleton(selfEnode);
    smartContractPermissioningConfiguration = new SmartContractPermissioningConfiguration();
    smartContractPermissioningConfiguration.setNodeSmartContractAddress(Address.fromHexString("0x0000000000000000000000000000000000001234"));
    smartContractPermissioningConfiguration.setSmartContractNodeAllowlistEnabled(true);
    config = new PermissioningConfiguration(Optional.empty(), Optional.of(smartContractPermissioningConfiguration), Optional.empty());
    NodePermissioningControllerFactory factory = new NodePermissioningControllerFactory();
    NodePermissioningController controller = factory.create(config, synchronizer, fixedNodes, selfEnode.getNodeId(), transactionSimulator, new NoOpMetricsSystem(), blockchain, Collections.emptyList());
    assertThat(controller.getSyncStatusNodePermissioningProvider()).isPresent();
}
Also used : EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) PermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.PermissioningConfiguration) SmartContractPermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.SmartContractPermissioningConfiguration) LocalPermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration) NoOpMetricsSystem(org.hyperledger.besu.metrics.noop.NoOpMetricsSystem) SmartContractPermissioningConfiguration(org.hyperledger.besu.ethereum.permissioning.SmartContractPermissioningConfiguration) NodePermissioningControllerFactory(org.hyperledger.besu.ethereum.permissioning.NodePermissioningControllerFactory) Test(org.junit.Test)

Example 9 with EnodeURL

use of org.hyperledger.besu.plugin.data.EnodeURL in project besu by hyperledger.

the class SyncStatusNodePermissioningProviderTest method syncStatusPermissioningCheckShouldIgnoreEnodeURLDiscoveryPort.

@Test
public void syncStatusPermissioningCheckShouldIgnoreEnodeURLDiscoveryPort() {
    inSyncListener.onInSyncStatusChange(false);
    assertThat(provider.hasReachedSync()).isFalse();
    final EnodeURL bootnode = EnodeURLImpl.fromString("enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.3:5678");
    final EnodeURL enodeWithDiscoveryPort = EnodeURLImpl.fromString("enode://6f8a80d14311c39f35f516fa664deaaaa13e85b2f7493f37f6144d86991ec012937307647bd3b9a82abe2974e1407241d54947bbb39763a4cac9f77166ad92a0@192.168.0.3:5678?discport=30303");
    final SyncStatusNodePermissioningProvider provider = new SyncStatusNodePermissioningProvider(synchronizer, Lists.newArrayList(bootnode), metricsSystem);
    boolean isPermitted = provider.isConnectionPermitted(enode1, enodeWithDiscoveryPort);
    assertThat(isPermitted).isTrue();
}
Also used : EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) Test(org.junit.Test)

Example 10 with EnodeURL

use of org.hyperledger.besu.plugin.data.EnodeURL in project besu by hyperledger.

the class SyncStatusNodePermissioningProviderTest method syncStatusPermissioningCheckShouldAllowDNS.

@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();
}
Also used : EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) Test(org.junit.Test)

Aggregations

EnodeURL (org.hyperledger.besu.plugin.data.EnodeURL)109 Test (org.junit.Test)83 Bytes (org.apache.tuweni.bytes.Bytes)26 PeerConnection (org.hyperledger.besu.ethereum.p2p.rlpx.connections.PeerConnection)22 DefaultPeer (org.hyperledger.besu.ethereum.p2p.peers.DefaultPeer)17 Peer (org.hyperledger.besu.ethereum.p2p.peers.Peer)17 NodeKey (org.hyperledger.besu.crypto.NodeKey)14 Path (java.nio.file.Path)12 CompletableFuture (java.util.concurrent.CompletableFuture)12 Optional (java.util.Optional)11 List (java.util.List)10 Collectors (java.util.stream.Collectors)10 URL (java.net.URL)9 EnodeURLImpl (org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl)9 DisconnectReason (org.hyperledger.besu.ethereum.p2p.rlpx.wire.messages.DisconnectMessage.DisconnectReason)9 File (java.io.File)8 Collections (java.util.Collections)8 LocalPermissioningConfiguration (org.hyperledger.besu.ethereum.permissioning.LocalPermissioningConfiguration)8 ArrayList (java.util.ArrayList)7 EthNetworkConfig (org.hyperledger.besu.cli.config.EthNetworkConfig)7