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