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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations