Search in sources :

Example 11 with EnodeURL

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

the class NodeLocalConfigPermissioningController method createNodeAllowlistModifiedEventAfterReload.

private void createNodeAllowlistModifiedEventAfterReload(final List<EnodeURL> previousNodeAllowlist, final List<EnodeURL> currentNodesList) {
    final List<EnodeURL> removedNodes = previousNodeAllowlist.stream().filter(n -> !currentNodesList.contains(n)).collect(Collectors.toList());
    final List<EnodeURL> addedNodes = currentNodesList.stream().filter(n -> !previousNodeAllowlist.contains(n)).collect(Collectors.toList());
    if (!removedNodes.isEmpty() || !addedNodes.isEmpty()) {
        notifyListUpdatedSubscribers(new NodeAllowlistUpdatedEvent(addedNodes, removedNodes));
    }
}
Also used : EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) EnodeURLImpl(org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl) Logger(org.slf4j.Logger) BesuMetricCategory(org.hyperledger.besu.metrics.BesuMetricCategory) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Bytes(org.apache.tuweni.bytes.Bytes) Subscribers(org.hyperledger.besu.util.Subscribers) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) HashSet(java.util.HashSet) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) NodeAllowlistUpdatedEvent(org.hyperledger.besu.ethereum.permissioning.node.NodeAllowlistUpdatedEvent) NodeConnectionPermissioningProvider(org.hyperledger.besu.plugin.services.permissioning.NodeConnectionPermissioningProvider) Optional(java.util.Optional) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ALLOWLIST_TYPE(org.hyperledger.besu.ethereum.permissioning.AllowlistPersistor.ALLOWLIST_TYPE) Collections(java.util.Collections) Counter(org.hyperledger.besu.plugin.services.metrics.Counter) NodeAllowlistUpdatedEvent(org.hyperledger.besu.ethereum.permissioning.node.NodeAllowlistUpdatedEvent)

Example 12 with EnodeURL

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

the class NodeLocalConfigPermissioningController method removeNodes.

public NodesAllowlistResult removeNodes(final List<String> enodeURLs) {
    final NodesAllowlistResult inputValidationResult = validInput(enodeURLs);
    if (inputValidationResult.result() != AllowlistOperationResult.SUCCESS) {
        return inputValidationResult;
    }
    final List<EnodeURL> peers = enodeURLs.stream().map(url -> EnodeURLImpl.fromString(url, configuration.getEnodeDnsConfiguration())).collect(Collectors.toList());
    boolean anyBootnode = peers.stream().anyMatch(fixedNodes::contains);
    if (anyBootnode) {
        return new NodesAllowlistResult(AllowlistOperationResult.ERROR_FIXED_NODE_CANNOT_BE_REMOVED);
    }
    for (EnodeURL peer : peers) {
        if (!(nodesAllowlist.contains(peer))) {
            return new NodesAllowlistResult(AllowlistOperationResult.ERROR_ABSENT_ENTRY, String.format("Specified peer: %s does not exist in allowlist.", peer.getNodeId()));
        }
    }
    final List<EnodeURL> oldAllowlist = new ArrayList<>(this.nodesAllowlist);
    peers.forEach(this::removeNode);
    notifyListUpdatedSubscribers(new NodeAllowlistUpdatedEvent(Collections.emptyList(), peers));
    final NodesAllowlistResult updateConfigFileResult = updateAllowlistInConfigFile(oldAllowlist);
    if (updateConfigFileResult.result() != AllowlistOperationResult.SUCCESS) {
        return updateConfigFileResult;
    }
    return new NodesAllowlistResult(AllowlistOperationResult.SUCCESS);
}
Also used : EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) EnodeURLImpl(org.hyperledger.besu.ethereum.p2p.peers.EnodeURLImpl) Logger(org.slf4j.Logger) BesuMetricCategory(org.hyperledger.besu.metrics.BesuMetricCategory) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Bytes(org.apache.tuweni.bytes.Bytes) Subscribers(org.hyperledger.besu.util.Subscribers) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) HashSet(java.util.HashSet) Objects(java.util.Objects) Consumer(java.util.function.Consumer) List(java.util.List) NodeAllowlistUpdatedEvent(org.hyperledger.besu.ethereum.permissioning.node.NodeAllowlistUpdatedEvent) NodeConnectionPermissioningProvider(org.hyperledger.besu.plugin.services.permissioning.NodeConnectionPermissioningProvider) Optional(java.util.Optional) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) VisibleForTesting(com.google.common.annotations.VisibleForTesting) ALLOWLIST_TYPE(org.hyperledger.besu.ethereum.permissioning.AllowlistPersistor.ALLOWLIST_TYPE) Collections(java.util.Collections) Counter(org.hyperledger.besu.plugin.services.metrics.Counter) NodeAllowlistUpdatedEvent(org.hyperledger.besu.ethereum.permissioning.node.NodeAllowlistUpdatedEvent) ArrayList(java.util.ArrayList)

Example 13 with EnodeURL

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

the class NodeSmartContractPermissioningAllowNodeV2Transaction method signedTransactionData.

private String signedTransactionData() {
    final EnodeURL enodeURL = EnodeURLImpl.fromURI(((RunnableNode) node).enodeUrl());
    final Bytes payload = createPayload(enodeURL);
    RawTransaction transaction = RawTransaction.createTransaction(sender.getNextNonce(), BigInteger.valueOf(1_000L), BigInteger.valueOf(3_000_000L), contractAddress.toString(), payload.toString());
    return toHexString(TransactionEncoder.signMessage(transaction, sender.web3jCredentialsOrThrow()));
}
Also used : EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) Bytes(org.apache.tuweni.bytes.Bytes) RawTransaction(org.web3j.crypto.RawTransaction)

Example 14 with EnodeURL

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

the class AdminAddPeer method performOperation.

@Override
protected JsonRpcResponse performOperation(final Object id, final String enode) {
    LOG.debug("Adding ({}) to peers", enode);
    final EnodeURL enodeURL = EnodeURLImpl.fromString(enode);
    final Peer peer = DefaultPeer.fromEnodeURL(enodeURL);
    final boolean addedToNetwork = peerNetwork.addMaintainedConnectionPeer(peer);
    return new JsonRpcSuccessResponse(id, addedToNetwork);
}
Also used : EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) DefaultPeer(org.hyperledger.besu.ethereum.p2p.peers.DefaultPeer) Peer(org.hyperledger.besu.ethereum.p2p.peers.Peer) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse)

Example 15 with EnodeURL

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

the class AdminNodeInfo method response.

@Override
public JsonRpcResponse response(final JsonRpcRequestContext requestContext) {
    final Map<String, Object> response = new HashMap<>();
    final Map<String, Integer> ports = new HashMap<>();
    if (!peerNetwork.isP2pEnabled()) {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.P2P_DISABLED);
    }
    final Optional<EnodeURL> maybeEnode = peerNetwork.getLocalEnode();
    if (maybeEnode.isEmpty()) {
        return new JsonRpcErrorResponse(requestContext.getRequest().getId(), JsonRpcError.P2P_NETWORK_NOT_RUNNING);
    }
    final EnodeURL enode = maybeEnode.get();
    response.put("enode", enode.toString());
    response.put("ip", enode.getIpAsString());
    final Bytes nodeId = enode.getNodeId();
    final String ip = getIp(enode);
    final int listeningPort = getListeningPort(enode);
    final int discoveryPort = getDiscoveryPort(enode);
    response.put("enode", getNodeAsString(enode, ip, listeningPort, discoveryPort));
    response.put("ip", ip);
    if (enode.isListening()) {
        response.put("listenAddr", String.format("%s:%d", ip, listeningPort));
    }
    response.put("id", nodeId.toUnprefixedHexString());
    response.put("name", clientVersion);
    if (enode.isRunningDiscovery()) {
        ports.put("discovery", discoveryPort);
    }
    if (enode.isListening()) {
        ports.put("listener", listeningPort);
    }
    response.put("ports", ports);
    final ChainHead chainHead = blockchainQueries.getBlockchain().getChainHead();
    response.put("protocols", ImmutableMap.of("eth", ImmutableMap.of("config", genesisConfigOptions.asMap(), "difficulty", chainHead.getTotalDifficulty().toBigInteger(), "genesis", blockchainQueries.getBlockHashByNumber(0).get().toString(), "head", chainHead.getHash().toString(), "network", networkId)));
    return new JsonRpcSuccessResponse(requestContext.getRequest().getId(), response);
}
Also used : HashMap(java.util.HashMap) BigInteger(java.math.BigInteger) EnodeURL(org.hyperledger.besu.plugin.data.EnodeURL) Bytes(org.apache.tuweni.bytes.Bytes) JsonRpcSuccessResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcSuccessResponse) ChainHead(org.hyperledger.besu.ethereum.chain.ChainHead) JsonRpcErrorResponse(org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.JsonRpcErrorResponse)

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