use of com.hederahashgraph.api.proto.java.NodeAddress in project hedera-services by hashgraph.
the class NodeSignatureVerifier method initKeysFrom.
private void initKeysFrom(NodeAddressBook addressBook) {
for (NodeAddress nodeAddress : addressBook.getNodeAddressList()) {
String account = new String(nodeAddress.getMemo().toByteArray());
try {
accountKeys.put(account, loadPublicKey(nodeAddress.getRSAPubKey()));
log.info("Discovered node " + account);
} catch (IllegalArgumentException ex) {
log.warn("Malformed address key {} for node {}", nodeAddress.getRSAPubKey(), account);
throw new IllegalArgumentException("Malformed public key!");
}
}
}
use of com.hederahashgraph.api.proto.java.NodeAddress in project hedera-mirror-node by hashgraph.
the class NetworkControllerTest method assertEntry.
@SuppressWarnings("deprecation")
private void assertEntry(AddressBookEntry addressBookEntry, NodeAddress nodeAddress) {
assertThat(nodeAddress).isNotNull().returns(addressBookEntry.getDescription(), NodeAddress::getDescription).returns(ByteString.copyFromUtf8(addressBookEntry.getMemo()), NodeAddress::getMemo).returns(addressBookEntry.getNodeAccountId(), n -> EntityId.of(n.getNodeAccountId())).returns(ProtoUtil.toByteString(addressBookEntry.getNodeCertHash()), NodeAddress::getNodeCertHash).returns(addressBookEntry.getNodeId(), NodeAddress::getNodeId).returns(addressBookEntry.getPublicKey(), NodeAddress::getRSAPubKey).returns(addressBookEntry.getStake(), NodeAddress::getStake);
var serviceEndpoint = addressBookEntry.getServiceEndpoints().iterator().next();
ByteString ipAddress = null;
try {
ipAddress = ProtoUtil.toByteString(InetAddress.getByName(serviceEndpoint.getIpAddressV4()).getAddress());
} catch (Exception e) {
// Ignore
}
assertThat(nodeAddress.getServiceEndpointList()).hasSize(1).first().returns(ipAddress, ServiceEndpoint::getIpAddressV4).returns(serviceEndpoint.getPort(), ServiceEndpoint::getPort);
}
use of com.hederahashgraph.api.proto.java.NodeAddress in project hedera-mirror-node by hashgraph.
the class AddressBookServiceImplTest method verifyAddressBookWithDeprecatedIpOnly.
@Test
void verifyAddressBookWithDeprecatedIpOnly() throws UnknownHostException {
List<NodeAddress> nodeAddressList = new ArrayList<>();
int nodeAccountStart = 3;
int addressBookEntries = 5;
int numEndpointsPerNode = 1;
for (int i = nodeAccountStart; i < addressBookEntries + nodeAccountStart; i++) {
nodeAddressList.add(getNodeAddress(i, baseAccountId + i, String.format("127.0.%d.0", i), List.of()));
}
NodeAddressBook.Builder nodeAddressBookBuilder = NodeAddressBook.newBuilder().addAllNodeAddress(nodeAddressList);
byte[] addressBookBytes = nodeAddressBookBuilder.build().toByteArray();
update(addressBookBytes, 2L, false);
assertArrayEquals(initialAddressBookBytes, addressBookService.getCurrent().getFileData());
// bootstrap and new address book with service endpoints
assertEquals(2, addressBookRepository.count());
assertEquals(TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT + addressBookEntries, addressBookEntryRepository.count());
assertEquals(addressBookEntries * numEndpointsPerNode, addressBookServiceEndpointRepository.count());
}
use of com.hederahashgraph.api.proto.java.NodeAddress in project hedera-mirror-node by hashgraph.
the class AddressBookServiceImplTest method verifyDuplicateNodeAddressPerNodeIdAreCollapsed.
@Test
void verifyDuplicateNodeAddressPerNodeIdAreCollapsed() throws UnknownHostException {
List<NodeAddress> nodeAddressList = new ArrayList<>();
int nodeAccountStart = 3;
int addressBookEntries = 5;
// deprecated ip, service endpoints, deprecated ip + service endpoints
int numEndpointsPerNode = 6;
for (int i = nodeAccountStart; i < addressBookEntries + nodeAccountStart; i++) {
// deprecated ip
nodeAddressList.add(getNodeAddress(i, baseAccountId + i, String.format("127.0.%d.0", i), List.of()));
// subset of only service endpoints
nodeAddressList.add(getNodeAddress(i, baseAccountId + i, null, List.of(String.format("127.0.%d.1", i), String.format("127.0.%d.2", i))));
// another deprecated ip and more service endpoints
nodeAddressList.add(getNodeAddress(i, baseAccountId + i, String.format("128.0.%d.0", i), List.of(String.format("127.0.%d.3", i), String.format("127.0.%d.4", i))));
}
NodeAddressBook.Builder nodeAddressBookBuilder = NodeAddressBook.newBuilder().addAllNodeAddress(nodeAddressList);
byte[] addressBookBytes = nodeAddressBookBuilder.build().toByteArray();
update(addressBookBytes, 2L, true);
assertArrayEquals(addressBookBytes, addressBookService.getCurrent().getFileData());
// bootstrap and new address book with service endpoints
assertEquals(2, addressBookRepository.count());
assertEquals(TEST_INITIAL_ADDRESS_BOOK_NODE_COUNT + addressBookEntries, addressBookEntryRepository.count());
assertEquals(addressBookEntries * numEndpointsPerNode, addressBookServiceEndpointRepository.count());
}
use of com.hederahashgraph.api.proto.java.NodeAddress in project hedera-mirror-node by hashgraph.
the class AddressBookServiceImplTest method assertAddressBook.
private void assertAddressBook(AddressBook actual, NodeAddressBook expected) {
ListAssert<AddressBookEntry> listAssert = assertThat(actual.getEntries()).hasSize(expected.getNodeAddressCount());
for (NodeAddress nodeAddress : expected.getNodeAddressList()) {
listAssert.anySatisfy(abe -> {
assertThat(abe.getMemo()).isEqualTo(nodeAddress.getMemo().toStringUtf8());
assertThat(abe.getNodeAccountId()).isEqualTo(EntityId.of(nodeAddress.getNodeAccountId()));
assertThat(abe.getNodeCertHash()).isEqualTo(nodeAddress.getNodeCertHash().toByteArray());
assertThat(abe.getPublicKey()).isEqualTo(nodeAddress.getRSAPubKey());
assertThat(abe.getNodeId()).isEqualTo(nodeAddress.getNodeId());
assertAddressBookEndPoints(abe.getServiceEndpoints(), nodeAddress.getServiceEndpointList());
});
}
}
Aggregations