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