Загрузка данных


struct Live { std::string ip; uint16_t port; };

std::optional<Live> ParseUnitName(std::string_view unit) {
    // osmo-gbproxy@23142_192.168.250.31.service
    auto at = unit.find('@');
    auto dot = unit.rfind(".service");
    if (at == npos || dot == npos) return std::nullopt;
    auto inst = unit.substr(at + 1, dot - at - 1);
    auto us = inst.find('_');
    if (us == npos) return std::nullopt;
    Live l;
    if (!ParsePort(std::string(inst.substr(0, us)), &l.port)) return std::nullopt;
    l.ip = inst.substr(us + 1);
    if (!IsValidIp(l.ip)) return std::nullopt;
    return l;
}