Search in sources :

Example 1 with NodeAddressBook

use of com.hederahashgraph.api.proto.java.NodeAddressBook in project hedera-mirror-node by hashgraph.

the class AddressBookServiceImplTest method addressBook.

private static NodeAddressBook addressBook(int size, int endPointSize) {
    NodeAddressBook.Builder builder = NodeAddressBook.newBuilder();
    for (int i = 0; i < size; ++i) {
        long nodeId = 3 + i;
        NodeAddress.Builder nodeAddressBuilder = NodeAddress.newBuilder().setIpAddress(ByteString.copyFromUtf8("127.0.0." + nodeId)).setPortno((int) nodeId).setNodeId(nodeId).setMemo(ByteString.copyFromUtf8("0.0." + nodeId)).setNodeAccountId(AccountID.newBuilder().setAccountNum(nodeId)).setNodeCertHash(ByteString.copyFromUtf8("nodeCertHash")).setRSAPubKey("rsa+public/key");
        // add service endpoints
        if (endPointSize > 0) {
            List<ServiceEndpoint> serviceEndpoints = new ArrayList<>();
            for (int j = 1; j <= size; ++j) {
                serviceEndpoints.add(ServiceEndpoint.newBuilder().setIpAddressV4(ByteString.copyFrom(new byte[] { 127, 0, 0, (byte) j })).setPort(443 + j).build());
            }
        }
        builder.addNodeAddress(nodeAddressBuilder.build());
    }
    return builder.build();
}
Also used : NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) ArrayList(java.util.ArrayList) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)

Example 2 with NodeAddressBook

use of com.hederahashgraph.api.proto.java.NodeAddressBook in project hedera-mirror-node by hashgraph.

the class AddressBookServiceImplTest method verifyAddressBookEntriesWithNodeIdAndPortNotSet.

@Test
void verifyAddressBookEntriesWithNodeIdAndPortNotSet() {
    Map<String, Integer> memoToNodeIdMap = Map.of("0.0.3", 0, "0.0.4", 1);
    String[] accountIds = memoToNodeIdMap.keySet().stream().sorted().toArray(String[]::new);
    // nodeId 0, port 0
    NodeAddress nodeAddress1 = NodeAddress.newBuilder().setIpAddress(ByteString.copyFromUtf8("127.0.0.1")).setMemo(ByteString.copyFromUtf8(accountIds[0])).setNodeAccountId(AccountID.newBuilder().setAccountNum(3)).setNodeCertHash(ByteString.copyFromUtf8("nodeCertHash")).setRSAPubKey("rsa+public/key").build();
    // nodeId 0, port 50211
    NodeAddress nodeAddress2 = NodeAddress.newBuilder(nodeAddress1).setIpAddress(ByteString.copyFromUtf8("127.0.0.2")).setMemo(ByteString.copyFromUtf8(accountIds[1])).setNodeAccountId(AccountID.newBuilder().setAccountNum(4)).setPortno(50211).build();
    NodeAddressBook nodeAddressBook = NodeAddressBook.newBuilder().addAllNodeAddress(List.of(nodeAddress1, nodeAddress2)).build();
    byte[] addressBookBytes = nodeAddressBook.toByteArray();
    long addressBookConsensusTimeStamp = 5L;
    update(addressBookBytes, addressBookConsensusTimeStamp, true);
    assertAddressBookData(addressBookBytes, addressBookConsensusTimeStamp + 1);
    AddressBook addressBook = addressBookService.getCurrent();
    ListAssert<AddressBookEntry> listAssert = assertThat(addressBook.getEntries()).hasSize(nodeAddressBook.getNodeAddressCount());
    for (NodeAddress nodeAddress : nodeAddressBook.getNodeAddressList()) {
        int expectedNodeId = memoToNodeIdMap.get(nodeAddress.getMemo().toStringUtf8());
        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());
            // both entries have null node id
            assertThat(abe.getNodeId()).isEqualTo(expectedNodeId);
            assertAddressBookEndPoints(abe.getServiceEndpoints(), nodeAddress.getServiceEndpointList());
        });
    }
}
Also used : AddressBook(com.hedera.mirror.common.domain.addressbook.AddressBook) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) AddressBookEntry(com.hedera.mirror.common.domain.addressbook.AddressBookEntry) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) ByteString(com.google.protobuf.ByteString) 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 3 with NodeAddressBook

use of com.hederahashgraph.api.proto.java.NodeAddressBook in project hedera-mirror-node by hashgraph.

the class MissingAddressBooksMigrationTest method addressBook.

@SuppressWarnings("deprecation")
private static NodeAddressBook addressBook(int size, int endPointSize) {
    NodeAddressBook.Builder builder = NodeAddressBook.newBuilder();
    for (int i = 0; i < size; ++i) {
        long nodeId = 3 + i;
        NodeAddress.Builder nodeAddressBuilder = NodeAddress.newBuilder().setIpAddress(ByteString.copyFromUtf8("127.0.0." + nodeId)).setPortno((int) nodeId).setNodeId(nodeId).setMemo(ByteString.copyFromUtf8("0.0." + nodeId)).setNodeAccountId(AccountID.newBuilder().setAccountNum(nodeId)).setNodeCertHash(ByteString.copyFromUtf8("nodeCertHash")).setRSAPubKey("rsa+public/key");
        // add service endpoints
        if (endPointSize > 0) {
            List<ServiceEndpoint> serviceEndpoints = new ArrayList<>();
            for (int j = 1; j <= size; ++j) {
                serviceEndpoints.add(ServiceEndpoint.newBuilder().setIpAddressV4(ByteString.copyFrom(new byte[] { 127, 0, 0, (byte) j })).setPort(443 + j).build());
            }
        }
        builder.addNodeAddress(nodeAddressBuilder.build());
    }
    return builder.build();
}
Also used : NodeAddressBook(com.hederahashgraph.api.proto.java.NodeAddressBook) ArrayList(java.util.ArrayList) NodeAddress(com.hederahashgraph.api.proto.java.NodeAddress) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)

Aggregations

AddressBookServiceEndpoint (com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)3 NodeAddress (com.hederahashgraph.api.proto.java.NodeAddress)3 NodeAddressBook (com.hederahashgraph.api.proto.java.NodeAddressBook)3 ServiceEndpoint (com.hederahashgraph.api.proto.java.ServiceEndpoint)3 ArrayList (java.util.ArrayList)2 ByteString (com.google.protobuf.ByteString)1 AddressBook (com.hedera.mirror.common.domain.addressbook.AddressBook)1 AddressBookEntry (com.hedera.mirror.common.domain.addressbook.AddressBookEntry)1 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)1 Test (org.junit.jupiter.api.Test)1