Search in sources :

Example 1 with NodeAddress

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!");
        }
    }
}
Also used : NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress)

Example 2 with NodeAddress

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);
}
Also used : ByteString(com.google.protobuf.ByteString) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) StatusRuntimeException(io.grpc.StatusRuntimeException) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint)

Example 3 with NodeAddress

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());
}
Also used : ArrayList(java.util.ArrayList) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 4 with NodeAddress

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());
}
Also used : ArrayList(java.util.ArrayList) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

Example 5 with NodeAddress

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());
        });
    }
}
Also used : AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress)

Aggregations

NodeAddress (com.hederahashgraph.api.proto.java.NodeAddress)13 ServiceEndpoint (com.hederahashgraph.api.proto.java.ServiceEndpoint)9 AddressBookServiceEndpoint (com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)8 Test (org.junit.jupiter.api.Test)8 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)7 NodeAddressBook (com.hederahashgraph.api.proto.java.NodeAddressBook)7 ArrayList (java.util.ArrayList)6 AddressBookEntry (com.hedera.mirror.common.domain.addressbook.AddressBookEntry)5 ByteString (com.google.protobuf.ByteString)3 AddressBook (com.hedera.mirror.common.domain.addressbook.AddressBook)2 EntityId (com.hedera.mirror.common.domain.entity.EntityId)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 AddressBookQuery (com.hedera.mirror.api.proto.AddressBookQuery)1 ReactorNetworkServiceGrpc (com.hedera.mirror.api.proto.ReactorNetworkServiceGrpc)1 DomainBuilder (com.hedera.mirror.common.domain.DomainBuilder)1 GrpcIntegrationTest (com.hedera.mirror.grpc.GrpcIntegrationTest)1 ProtoUtil (com.hedera.mirror.grpc.util.ProtoUtil)1 FileID (com.hederahashgraph.api.proto.java.FileID)1 Status (io.grpc.Status)1 InetAddress (java.net.InetAddress)1