Search in sources :

Example 1 with ServiceEndpoint

use of com.hederahashgraph.api.proto.java.ServiceEndpoint 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 2 with ServiceEndpoint

use of com.hederahashgraph.api.proto.java.ServiceEndpoint 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 3 with ServiceEndpoint

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

the class AddressBookServiceImplTest method assertAddressBookEndPoints.

private void assertAddressBookEndPoints(Set<AddressBookServiceEndpoint> actual, List<ServiceEndpoint> expected) {
    if (expected.isEmpty()) {
        return;
    }
    var listAssert = assertThat(actual).hasSize(expected.size());
    for (ServiceEndpoint serviceEndpoint : expected) {
        listAssert.anySatisfy(abe -> {
            AtomicReference<String> ip = new AtomicReference<>("");
            assertDoesNotThrow(() -> {
                ip.set(InetAddress.getByAddress(serviceEndpoint.getIpAddressV4().toByteArray()).getHostAddress());
            });
            assertThat(abe.getId().getPort()).isEqualTo(serviceEndpoint.getPort());
            assertThat(abe.getId().getIpAddressV4()).isEqualTo(ip.get());
        });
    }
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) ByteString(com.google.protobuf.ByteString) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)

Example 4 with ServiceEndpoint

use of com.hederahashgraph.api.proto.java.ServiceEndpoint 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)

Example 5 with ServiceEndpoint

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

the class AddressBookServiceImpl method getAddressBookServiceEndpoints.

private static Set<AddressBookServiceEndpoint> getAddressBookServiceEndpoints(NodeAddress nodeAddressProto, long consensusTimestamp) throws UnknownHostException {
    var nodeId = nodeAddressProto.getNodeId();
    Set<AddressBookServiceEndpoint> serviceEndpoints = new HashSet<>();
    // create an AddressBookServiceEndpoint for deprecated port and IP if populated
    AddressBookServiceEndpoint deprecatedServiceEndpoint = getAddressBookServiceEndpoint(nodeAddressProto, consensusTimestamp, nodeId);
    if (deprecatedServiceEndpoint != null) {
        serviceEndpoints.add(deprecatedServiceEndpoint);
    }
    // create an AddressBookServiceEndpoint for every ServiceEndpoint found
    for (ServiceEndpoint serviceEndpoint : nodeAddressProto.getServiceEndpointList()) {
        serviceEndpoints.add(getAddressBookServiceEndpoint(serviceEndpoint, consensusTimestamp, nodeId));
    }
    return serviceEndpoints;
}
Also used : AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) ServiceEndpoint(com.hederahashgraph.api.proto.java.ServiceEndpoint) AddressBookServiceEndpoint(com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint) HashSet(java.util.HashSet)

Aggregations

ServiceEndpoint (com.hederahashgraph.api.proto.java.ServiceEndpoint)6 AddressBookServiceEndpoint (com.hedera.mirror.common.domain.addressbook.AddressBookServiceEndpoint)4 NodeAddress (com.hederahashgraph.api.proto.java.NodeAddress)3 ByteString (com.google.protobuf.ByteString)2 NodeAddressBook (com.hederahashgraph.api.proto.java.NodeAddressBook)2 ArrayList (java.util.ArrayList)2 StatusRuntimeException (io.grpc.StatusRuntimeException)1 HashSet (java.util.HashSet)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1