Files
stvpn/helmetsrv.cpp
T
Олег Бородин 3f261b0922 working commit
2026-05-20 17:15:26 +02:00

46 lines
1.4 KiB
C++

#include <expected>
#include <string>
#include <cstring>
#include <defines.hpp>
#include <tservice.hpp>
#include <uxlogger.hpp>
#include <srvconfig.hpp>
std::expected<void, std::string> Run() {
ServConfig config;
std::string confdir(SRV_CONFDIR);
auto readRes = config.Read(confdir + "/" + "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.Error(runRes.error());
return 1;
}
return 0;
}