service: address_map: add lookup function that expects address to exist

We will add code that expects id to ip mapping to exist. If it does not
it is better to fail earlier during testing, so add a function that
calls internal error in case there is no mapping.
This commit is contained in:
Gleb Natapov
2025-01-12 11:09:02 +02:00
parent 2eac7a2d61
commit 50ee962033

View File

@@ -298,6 +298,15 @@ public:
return entry._addr;
}
// Same as find() above but expects mapping to exist
gms::inet_address get(locator::host_id id) const {
try {
return find(id).value();
} catch (std::bad_optional_access& err) {
on_internal_error(rslog, fmt::format("No ip address for {} when one is expected", id));
}
}
// Find an id with a given mapping.
//
// If a mapping is expiring, the last access timestamp is updated automatically.