Skip to content

Commit 7308e1b

Browse files
feat: address book serializes text hostnames (#12515)
Signed-off-by: Edward Wertz <[email protected]>
1 parent 488d80c commit 7308e1b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

platform-sdk/swirlds-platform-core/src/main/java/com/swirlds/platform/system/address/AddressBookUtils.java

+10-6
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,11 @@ public static Address parseAddressText(@NonNull final String addressText) throws
208208
} catch (NumberFormatException e) {
209209
throw new ParseException("Cannot parse value of weight from '" + parts[4] + "'", 4);
210210
}
211-
final InetAddress internalIp;
211+
// FQDN Support: The original string value is preserved, whether it is an IP Address or a FQDN.
212+
final String internalHostname = parts[5];
212213
try {
213-
internalIp = InetAddress.getByName(parts[5]);
214+
// validate that an InetAddress can be created from the internal hostname.
215+
InetAddress.getByName(internalHostname);
214216
} catch (UnknownHostException e) {
215217
throw new ParseException("Cannot parse ip address from '" + parts[5] + ",", 5);
216218
}
@@ -220,9 +222,11 @@ public static Address parseAddressText(@NonNull final String addressText) throws
220222
} catch (NumberFormatException e) {
221223
throw new ParseException("Cannot parse ip port from '" + parts[6] + "'", 6);
222224
}
223-
final InetAddress externalIp;
225+
// FQDN Support: The original string value is preserved, whether it is an IP Address or a FQDN.
226+
final String externalHostname = parts[7];
224227
try {
225-
externalIp = InetAddress.getByName(parts[7]);
228+
// validate that an InetAddress can be created from the external hostname.
229+
InetAddress.getByName(externalHostname);
226230
} catch (UnknownHostException e) {
227231
throw new ParseException("Cannot parse ip address from '" + parts[7] + ",", 7);
228232
}
@@ -239,9 +243,9 @@ public static Address parseAddressText(@NonNull final String addressText) throws
239243
nickname,
240244
selfname,
241245
weight,
242-
internalIp.getHostAddress(),
246+
internalHostname,
243247
internalPort,
244-
externalIp.getHostAddress(),
248+
externalHostname,
245249
externalPort,
246250
memoToUse);
247251
}

platform-sdk/swirlds-platform-core/src/test/java/com/swirlds/platform/system/address/AddressBookTests.java

+6
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,12 @@ void setNextNodeIdTest() {
463463
void roundTripSerializeAndDeserializeCompatibleWithConfigTxt() throws ParseException {
464464
final RandomAddressBookGenerator generator = new RandomAddressBookGenerator(getRandomPrintSeed());
465465
final AddressBook addressBook = generator.build();
466+
// FQDN Support: modify address in address book to have a text based host name.
467+
addressBook.add(addressBook
468+
.getAddress(addressBook.getNodeId(0))
469+
.copySetHostnameInternal("localhost")
470+
.copySetHostnameExternal("localhost"));
471+
466472
// make one of the memo fields an empty string
467473
final NodeId firstNode = addressBook.getNodeId(0);
468474
addressBook.add(addressBook.getAddress(firstNode).copySetMemo(""));

0 commit comments

Comments
 (0)