Files
stvpn/helmetsrv.cpp
T
2026-05-15 15:30:29 +02:00

45 lines
1.3 KiB
C++

#include <expected>
#include <string>
#include <cstring>
#include <tservice.hpp>
#include <uxlogger.hpp>
#include <srvconfig.hpp>
std::expected<void, std::string> Run() {
ServConfig config;
auto readRes = config.Read("helmetsrv.conf");
if (!readRes) {
return std::unexpected("Read config error: " + readRes.error());
}
auto validateRes = config.Validate();
if (!validateRes) {
return std::unexpected("Validate config error: " + validateRes.error());
}
auto listport = config.Listenport();
auto localnets = config.Localnets();
auto tunnelnet = config.Tunnelnet();
TunService service(listport, tunnelnet, localnets);
auto bindRes = service.Bind();
if (!bindRes) {
return std::unexpected("Bind error: " + bindRes.error());
}
uxlogger.Info(std::format("Listening on port {}", listport));
auto listenRes = service.Listen();
if (!listenRes) {
return std::unexpected("Listen error: " + listenRes.error());
}
return {};
}
int main(int argc, char** argv) {
auto runRes = Run();
if (!runRes) {
uxlogger.Log(runRes.error());
return 1;
}
return 0;
}