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