Search in sources :

Example 11 with AddressBookServiceEndpoint

use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.

the class AddressBookServiceImpl method retrieveNodeAddressesFromAddressBook.

/**
 * Extracts a collection of AddressBookEntry domain objects from NodeAddressBook proto. Sets provided
 * consensusTimestamp as the consensusTimestamp of each address book entry to ensure mapping to a single
 * AddressBook
 *
 * @param nodeAddressBook    node address book proto
 * @param consensusTimestamp transaction consensusTimestamp
 * @return
 */
private static Collection<AddressBookEntry> retrieveNodeAddressesFromAddressBook(NodeAddressBook nodeAddressBook, long consensusTimestamp) throws UnknownHostException {
    // node id to entry
    Map<Long, AddressBookEntry> addressBookEntries = new LinkedHashMap<>();
    for (NodeAddress nodeAddressProto : nodeAddressBook.getNodeAddressList()) {
        Pair<Long, EntityId> nodeIds = getNodeIds(nodeAddressProto);
        AddressBookEntry addressBookEntry = addressBookEntries.computeIfAbsent(nodeIds.getLeft(), k -> getAddressBookEntry(nodeAddressProto, consensusTimestamp, nodeIds));
        Set<AddressBookServiceEndpoint> updatedList = new HashSet<>(addressBookEntry.getServiceEndpoints());
        updatedList.addAll(getAddressBookServiceEndpoints(nodeAddressProto, consensusTimestamp));
        addressBookEntry.setServiceEndpoints(updatedList);
    }
    return addressBookEntries.values();
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet)

Example 12 with AddressBookServiceEndpoint

use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.

the class AddressBookServiceEndpointRepositoryTest method addressBookServiceEndpoint.

private AddressBookServiceEndpoint addressBookServiceEndpoint(long consensusTimestamp, String ip, int port, long nodeId) {
    AddressBookServiceEndpoint addressBookServiceEndpoint = new AddressBookServiceEndpoint();
    addressBookServiceEndpoint.setConsensusTimestamp(consensusTimestamp);
    addressBookServiceEndpoint.setIpAddressV4(ip);
    addressBookServiceEndpoint.setPort(port);
    addressBookServiceEndpoint.setNodeId(nodeId);
    return addressBookServiceEndpoint;
}
Also used : AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)

Example 13 with AddressBookServiceEndpoint

use of com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint in project hedera-mirror-node by hashgraph.

the class AddressBookServiceEndpointRepositoryTest method addressBookEntry.

private AddressBookEntry addressBookEntry(long consensusTimestamp, long nodeAccountId, List<Integer> portNums) throws UnknownHostException {
    long nodeId = nodeAccountId - 3;
    String nodeAccountIdString = String.format("0.0.%s", nodeAccountId);
    EntityId nodeAccountEntityId = EntityId.of(nodeAccountIdString, EntityType.ACCOUNT);
    AddressBookEntry.AddressBookEntryBuilder builder = AddressBookEntry.builder().consensusTimestamp(consensusTimestamp).memo(nodeAccountIdString).nodeAccountId(nodeAccountEntityId).nodeCertHash("nodeCertHash".getBytes()).nodeId(nodeId).publicKey("rsa+public/key");
    if (!CollectionUtils.isEmpty(portNums)) {
        Set<AddressBookServiceEndpoint> serviceEndpoints = new HashSet<>();
        for (int i = 0; i < portNums.size(); i++) {
            serviceEndpoints.add(addressBookServiceEndpoint(consensusTimestamp, InetAddress.getByName("127.0.0." + i).getHostAddress(), portNums.get(i), nodeId));
        }
        builder.serviceEndpoints(serviceEndpoints);
    }
    return builder.build();
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) HashSet(java.util.HashSet)

Aggregations

AddressBookServiceEndpoint (com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)13 AddressBookEntry (com.hedera.mirror.common.domain.addressbook.AddressBookEntry)7 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)4 Test (org.junit.jupiter.api.Test)4 EntityId (com.hedera.mirror.common.domain.entity.EntityId)3 HashSet (java.util.HashSet)3 ByteString (com.google.protobuf.ByteString)2 AddressBook (com.hedera.mirror.common.domain.addressbook.AddressBook)2 ServiceEndpoint (com.hederahashgraph.api.proto.java.ServiceEndpoint)2 Range (com.google.common.collect.Range)1 NodeStake (com.hedera.mirror.common.domain.addressbook.NodeStake)1 AccountBalance (com.hedera.mirror.common.domain.balance.AccountBalance)1 AccountBalanceFile (com.hedera.mirror.common.domain.balance.AccountBalanceFile)1 TokenBalance (com.hedera.mirror.common.domain.balance.TokenBalance)1 Contract (com.hedera.mirror.common.domain.contract.Contract)1 ContractLog (com.hedera.mirror.common.domain.contract.ContractLog)1 ContractResult (com.hedera.mirror.common.domain.contract.ContractResult)1 ContractStateChange (com.hedera.mirror.common.domain.contract.ContractStateChange)1 CryptoAllowance (com.hedera.mirror.common.domain.entity.CryptoAllowance)1 Entity (com.hedera.mirror.common.domain.entity.Entity)1