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