aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ridgers <[email protected]>2021-11-29 09:18:03 +0100
committerMartin Ridgers <[email protected]>2021-11-29 09:18:03 +0100
commit91aa9708bd42960405019148d39b57dda0155367 (patch)
treeb4ed6d1273e53cbe95e2ec20c37373f629947592
parentAdded a simple NamedMutex test (diff)
parentMerge pull request #28 from EpicGames/non-elevated-asio (diff)
downloadzen-91aa9708bd42960405019148d39b57dda0155367.tar.xz
zen-91aa9708bd42960405019148d39b57dda0155367.zip
Merged main
-rw-r--r--zenhttp/httpasio.cpp51
-rw-r--r--zenhttp/httpserver.cpp81
-rw-r--r--zenhttp/httpsys.cpp79
-rw-r--r--zenhttp/include/zenhttp/httpserver.h2
-rw-r--r--zenserver/config.cpp184
-rw-r--r--zenserver/config.h52
-rw-r--r--zenserver/zenserver.cpp97
7 files changed, 315 insertions, 231 deletions
diff --git a/zenhttp/httpasio.cpp b/zenhttp/httpasio.cpp
index 0ed5e78cf..e2b9262ff 100644
--- a/zenhttp/httpasio.cpp
+++ b/zenhttp/httpasio.cpp
@@ -17,6 +17,14 @@ ZEN_THIRD_PARTY_INCLUDES_START
#include <asio.hpp>
ZEN_THIRD_PARTY_INCLUDES_END
+#define ASIO_VERBOSE_TRACE 0
+
+#if ASIO_VERBOSE_TRACE
+#define ZEN_TRACE_VERBOSE ZEN_TRACE
+#else
+#define ZEN_TRACE_VERBOSE(fmtstr, ...)
+#endif
+
namespace zen::asio_http {
using namespace std::literals;
@@ -320,6 +328,7 @@ private:
std::unique_ptr<asio::ip::tcp::socket> m_Socket;
std::atomic<uint32_t> m_RequestCounter{0};
uint32_t m_ConnectionId = 0;
+ Ref<IHttpPackageHandler> m_PackageHandler;
RwLock m_ResponsesLock;
std::deque<std::unique_ptr<HttpResponse>> m_Responses;
@@ -332,12 +341,12 @@ HttpServerConnection::HttpServerConnection(HttpAsioServerImpl& Server, std::uniq
, m_Socket(std::move(Socket))
, m_ConnectionId(g_ConnectionIdCounter.fetch_add(1))
{
- ZEN_TRACE("new connection #{}", m_ConnectionId);
+ ZEN_TRACE_VERBOSE("new connection #{}", m_ConnectionId);
}
HttpServerConnection::~HttpServerConnection()
{
- ZEN_TRACE("destroying connection #{}", m_ConnectionId);
+ ZEN_TRACE_VERBOSE("destroying connection #{}", m_ConnectionId);
}
void
@@ -373,18 +382,18 @@ HttpServerConnection::EnqueueRead()
asio::async_read(*m_Socket.get(),
m_RequestBuffer,
- asio::transfer_at_least(16),
+ asio::transfer_at_least(1),
[Conn = AsSharedPtr()](const asio::error_code& Ec, std::size_t ByteCount) { Conn->OnDataReceived(Ec, ByteCount); });
}
void
-HttpServerConnection::OnDataReceived(const asio::error_code& Ec, std::size_t ByteCount)
+HttpServerConnection::OnDataReceived(const asio::error_code& Ec, [[maybe_unused]] std::size_t ByteCount)
{
if (Ec)
{
if (m_RequestState == RequestState::kDone || m_RequestState == RequestState::kInitialRead)
{
- ZEN_TRACE("on data received ERROR (EXPECTED), connection '{}' reason '{}'", m_ConnectionId, Ec.message());
+ ZEN_TRACE_VERBOSE("on data received ERROR (EXPECTED), connection '{}' reason '{}'", m_ConnectionId, Ec.message());
return;
}
else
@@ -394,7 +403,7 @@ HttpServerConnection::OnDataReceived(const asio::error_code& Ec, std::size_t Byt
}
}
- ZEN_TRACE("on data received, connection '{}', request '{}', thread '{}', bytes '{}'",
+ ZEN_TRACE_VERBOSE("on data received, connection '{}', request '{}', thread '{}', bytes '{}'",
m_ConnectionId,
m_RequestCounter.load(std::memory_order_relaxed),
zen::GetCurrentThreadId(),
@@ -423,7 +432,7 @@ HttpServerConnection::OnDataReceived(const asio::error_code& Ec, std::size_t Byt
}
void
-HttpServerConnection::OnResponseDataSent(const asio::error_code& Ec, std::size_t ByteCount, bool Pop)
+HttpServerConnection::OnResponseDataSent(const asio::error_code& Ec, [[maybe_unused]] std::size_t ByteCount, bool Pop)
{
if (Ec)
{
@@ -432,7 +441,7 @@ HttpServerConnection::OnResponseDataSent(const asio::error_code& Ec, std::size_t
}
else
{
- ZEN_TRACE("on data sent, connection '{}', request '{}', thread '{}', bytes '{}'",
+ ZEN_TRACE_VERBOSE("on data sent, connection '{}', request '{}', thread '{}', bytes '{}'",
m_ConnectionId,
m_RequestCounter.load(std::memory_order_relaxed),
zen::GetCurrentThreadId(),
@@ -487,9 +496,13 @@ HttpServerConnection::HandleRequest()
{
HttpAsioServerRequest Request(m_RequestData, *Service, m_RequestData.Body());
- ZEN_TRACE("handle request, connection '{}' request '{}'", m_ConnectionId, m_RequestCounter.load(std::memory_order_relaxed));
- Service->HandleRequest(Request);
+ ZEN_TRACE_VERBOSE("handle request, connection '{}' request '{}'", m_ConnectionId, m_RequestCounter.load(std::memory_order_relaxed));
+
+ if (!HandlePackageOffers(*Service, Request, m_PackageHandler))
+ {
+ Service->HandleRequest(Request);
+ }
if (std::unique_ptr<HttpResponse> Response = std::move(Request.m_Response))
{
@@ -937,7 +950,7 @@ HttpAsioServerRequest::HttpAsioServerRequest(asio_http::HttpRequest& Request, Ht
const int PrefixLength = Service.UriPrefixLength();
std::string_view Uri = Request.Url();
- Uri.remove_prefix(PrefixLength);
+ Uri.remove_prefix(std::min(PrefixLength, static_cast<int>(Uri.size())));
m_Uri = Uri;
m_QueryString = Request.QueryString();
@@ -1101,6 +1114,10 @@ HttpAsioServerImpl::RegisterService(const char* InUrlPath, HttpService& Service)
{
std::string_view UrlPath(InUrlPath);
Service.SetUriPrefixLength(UrlPath.size());
+ if (!UrlPath.empty() && UrlPath.back() == '/')
+ {
+ UrlPath.remove_suffix(1);
+ }
RwLock::ExclusiveLockScope _(m_Lock);
m_UriHandlers.push_back({std::string(UrlPath), &Service});
@@ -1111,16 +1128,22 @@ HttpAsioServerImpl::RouteRequest(std::string_view Url)
{
RwLock::SharedLockScope _(m_Lock);
+ HttpService* CandidateService = nullptr;
+ std::string::size_type CandidateMatchSize = 0;
for (const ServiceEntry& SvcEntry : m_UriHandlers)
{
const std::string& SvcUrl = SvcEntry.ServiceUrlPath;
- if (Url.compare(0, SvcUrl.size(), SvcUrl) == 0)
+ const std::string::size_type SvcUrlSize = SvcUrl.size();
+ if ((SvcUrlSize >= CandidateMatchSize) &&
+ Url.compare(0, SvcUrlSize, SvcUrl) == 0 &&
+ ((SvcUrlSize == Url.size()) || (Url[SvcUrlSize] == '/')))
{
- return SvcEntry.Service;
+ CandidateMatchSize = SvcUrl.size();
+ CandidateService = SvcEntry.Service;
}
}
- return nullptr;
+ return CandidateService;
}
} // namespace zen::asio_http
diff --git a/zenhttp/httpserver.cpp b/zenhttp/httpserver.cpp
index 7b729cf0e..9f4978e7a 100644
--- a/zenhttp/httpserver.cpp
+++ b/zenhttp/httpserver.cpp
@@ -7,6 +7,7 @@
#include "httpsys.h"
#include <zencore/compactbinary.h>
+#include <zencore/compactbinarybuilder.h>
#include <zencore/compactbinarypackage.h>
#include <zencore/iobuffer.h>
#include <zencore/logging.h>
@@ -617,6 +618,86 @@ CreateHttpServer(std::string_view ServerClass)
//////////////////////////////////////////////////////////////////////////
+bool
+HandlePackageOffers(HttpService& Service, HttpServerRequest& Request, Ref<IHttpPackageHandler>& PackageHandlerRef)
+{
+ if (Request.RequestVerb() == HttpVerb::kPost)
+ {
+ if (Request.RequestContentType() == HttpContentType::kCbPackageOffer)
+ {
+ // The client is presenting us with a package attachments offer, we need
+ // to filter it down to the list of attachments we need them to send in
+ // the follow-up request
+
+ PackageHandlerRef = Service.HandlePackageRequest(Request);
+
+ if (PackageHandlerRef)
+ {
+ CbObject OfferMessage = LoadCompactBinaryObject(Request.ReadPayload());
+
+ std::vector<IoHash> OfferCids;
+
+ for (auto& CidEntry : OfferMessage["offer"])
+ {
+ if (!CidEntry.IsHash())
+ {
+ // Should yield bad request response?
+
+ ZEN_WARN("found invalid entry in offer");
+
+ continue;
+ }
+
+ OfferCids.push_back(CidEntry.AsHash());
+ }
+
+ ZEN_TRACE("request #{} -> filtering offer of {} entries", Request.RequestId(), OfferCids.size());
+
+ PackageHandlerRef->FilterOffer(OfferCids);
+
+ ZEN_TRACE("request #{} -> filtered to {} entries", Request.RequestId(), OfferCids.size());
+
+ CbObjectWriter ResponseWriter;
+ ResponseWriter.BeginArray("need");
+
+ for (const IoHash& Cid : OfferCids)
+ {
+ ResponseWriter.AddHash(Cid);
+ }
+
+ ResponseWriter.EndArray();
+
+ // Emit filter response
+ Request.WriteResponse(HttpResponseCode::OK, ResponseWriter.Save());
+ return true;
+ }
+ }
+ else if (Request.RequestContentType() == HttpContentType::kCbPackage)
+ {
+ // Process chunks in package request
+
+ PackageHandlerRef = Service.HandlePackageRequest(Request);
+
+ // TODO: this should really be done in a streaming fashion, currently this emulates
+ // the intended flow from an API perspective
+
+ if (PackageHandlerRef)
+ {
+ PackageHandlerRef->OnRequestBegin();
+
+ auto CreateBuffer = [&](const IoHash& Cid, uint64_t Size) -> IoBuffer { return PackageHandlerRef->CreateTarget(Cid, Size); };
+
+ CbPackage Package = ParsePackageMessage(Request.ReadPayload(), CreateBuffer);
+
+ PackageHandlerRef->OnRequestComplete();
+ }
+ }
+ }
+ return false;
+}
+
+//////////////////////////////////////////////////////////////////////////
+
#if ZEN_WITH_TESTS
TEST_CASE("http.common")
diff --git a/zenhttp/httpsys.cpp b/zenhttp/httpsys.cpp
index 242954912..fb1c43537 100644
--- a/zenhttp/httpsys.cpp
+++ b/zenhttp/httpsys.cpp
@@ -1131,83 +1131,12 @@ HttpSysTransaction::InvokeRequestHandler(HttpService& Service, IoBuffer Payload)
{
HttpSysServerRequest& ThisRequest = m_HandlerRequest.emplace(*this, Service, Payload);
- if (ThisRequest.RequestVerb() == HttpVerb::kPost)
- {
- if (ThisRequest.RequestContentType() == HttpContentType::kCbPackageOffer)
- {
- // The client is presenting us with a package attachments offer, we need
- // to filter it down to the list of attachments we need them to send in
- // the follow-up request
-
- m_PackageHandler = Service.HandlePackageRequest(ThisRequest);
-
- if (m_PackageHandler)
- {
- CbObject OfferMessage = LoadCompactBinaryObject(Payload);
-
- std::vector<IoHash> OfferCids;
-
- for (auto& CidEntry : OfferMessage["offer"])
- {
- if (!CidEntry.IsHash())
- {
- // Should yield bad request response?
-
- ZEN_WARN("found invalid entry in offer");
-
- continue;
- }
-
- OfferCids.push_back(CidEntry.AsHash());
- }
-
- ZEN_TRACE("request #{} -> filtering offer of {} entries", ThisRequest.RequestId(), OfferCids.size());
-
- m_PackageHandler->FilterOffer(OfferCids);
-
- ZEN_TRACE("request #{} -> filtered to {} entries", ThisRequest.RequestId(), OfferCids.size());
-
- CbObjectWriter ResponseWriter;
- ResponseWriter.BeginArray("need");
-
- for (const IoHash& Cid : OfferCids)
- {
- ResponseWriter.AddHash(Cid);
- }
-
- ResponseWriter.EndArray();
-
- // Emit filter response
- ThisRequest.WriteResponse(HttpResponseCode::OK, ResponseWriter.Save());
-
- return ThisRequest;
- }
- }
- else if (ThisRequest.RequestContentType() == HttpContentType::kCbPackage)
- {
- // Process chunks in package request
-
- m_PackageHandler = Service.HandlePackageRequest(ThisRequest);
-
- // TODO: this should really be done in a streaming fashion, currently this emulates
- // the intended flow from an API perspective
-
- if (m_PackageHandler)
- {
- m_PackageHandler->OnRequestBegin();
-
- auto CreateBuffer = [&](const IoHash& Cid, uint64_t Size) -> IoBuffer { return m_PackageHandler->CreateTarget(Cid, Size); };
-
- CbPackage Package = ParsePackageMessage(ThisRequest.ReadPayload(), CreateBuffer);
-
- m_PackageHandler->OnRequestComplete();
- }
- }
- }
-
// Default request handling
- Service.HandleRequest(ThisRequest);
+ if (!HandlePackageOffers(Service, ThisRequest, m_PackageHandler))
+ {
+ Service.HandleRequest(ThisRequest);
+ }
return ThisRequest;
}
diff --git a/zenhttp/include/zenhttp/httpserver.h b/zenhttp/include/zenhttp/httpserver.h
index 614cdc2ac..644350372 100644
--- a/zenhttp/include/zenhttp/httpserver.h
+++ b/zenhttp/include/zenhttp/httpserver.h
@@ -269,6 +269,8 @@ private:
std::unordered_map<std::string, std::string> m_PatternMap;
};
+bool HandlePackageOffers(HttpService& Service, HttpServerRequest& Request, Ref<IHttpPackageHandler>& PackageHandlerRef);
+
void http_forcelink(); // internal
} // namespace zen
diff --git a/zenserver/config.cpp b/zenserver/config.cpp
index 44297c58e..a5a747150 100644
--- a/zenserver/config.cpp
+++ b/zenserver/config.cpp
@@ -83,8 +83,10 @@ ParseUpstreamCachePolicy(std::string_view Options)
}
}
+void ParseConfigFile(const std::filesystem::path& Path, ZenServerOptions& ServerOptions);
+
void
-ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, ZenServiceConfig& ServiceConfig)
+ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions)
{
#if ZEN_WITH_HTTPSYS
const char* DefaultHttp = "httpsys";
@@ -95,22 +97,23 @@ ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, Z
cxxopts::Options options("zenserver", "Zen Server");
options.add_options()("dedicated",
"Enable dedicated server mode",
- cxxopts::value<bool>(GlobalOptions.IsDedicated)->default_value("false"));
- options.add_options()("d, debug", "Enable debugging", cxxopts::value<bool>(GlobalOptions.IsDebug)->default_value("false"));
+ cxxopts::value<bool>(ServerOptions.IsDedicated)->default_value("false"));
+ options.add_options()("d, debug", "Enable debugging", cxxopts::value<bool>(ServerOptions.IsDebug)->default_value("false"));
options.add_options()("help", "Show command line help");
- options.add_options()("t, test", "Enable test mode", cxxopts::value<bool>(GlobalOptions.IsTest)->default_value("false"));
- options.add_options()("log-id", "Specify id for adding context to log output", cxxopts::value<std::string>(GlobalOptions.LogId));
- options.add_options()("data-dir", "Specify persistence root", cxxopts::value<std::filesystem::path>(GlobalOptions.DataDir));
- options.add_options()("content-dir", "Frontend content directory", cxxopts::value<std::filesystem::path>(GlobalOptions.ContentDir));
- options.add_options()("abslog", "Path to log file", cxxopts::value<std::filesystem::path>(GlobalOptions.AbsLogFile));
+ options.add_options()("t, test", "Enable test mode", cxxopts::value<bool>(ServerOptions.IsTest)->default_value("false"));
+ options.add_options()("log-id", "Specify id for adding context to log output", cxxopts::value<std::string>(ServerOptions.LogId));
+ options.add_options()("data-dir", "Specify persistence root", cxxopts::value<std::filesystem::path>(ServerOptions.DataDir));
+ options.add_options()("content-dir", "Frontend content directory", cxxopts::value<std::filesystem::path>(ServerOptions.ContentDir));
+ options.add_options()("abslog", "Path to log file", cxxopts::value<std::filesystem::path>(ServerOptions.AbsLogFile));
+ options.add_options()("config", "Path to Lua config file", cxxopts::value<std::filesystem::path>(ServerOptions.ConfigFile));
options
- .add_option("lifetime", "", "owner-pid", "Specify owning process id", cxxopts::value<int>(GlobalOptions.OwnerPid), "<identifier>");
+ .add_option("lifetime", "", "owner-pid", "Specify owning process id", cxxopts::value<int>(ServerOptions.OwnerPid), "<identifier>");
options.add_option("lifetime",
"",
"child-id",
"Specify id which can be used to signal parent",
- cxxopts::value<std::string>(GlobalOptions.ChildId),
+ cxxopts::value<std::string>(ServerOptions.ChildId),
"<identifier>");
#if ZEN_PLATFORM_WINDOWS
@@ -118,13 +121,13 @@ ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, Z
"",
"install",
"Install zenserver as a Windows service",
- cxxopts::value<bool>(GlobalOptions.InstallService),
+ cxxopts::value<bool>(ServerOptions.InstallService),
"");
options.add_option("lifetime",
"",
"uninstall",
"Uninstall zenserver as a Windows service",
- cxxopts::value<bool>(GlobalOptions.UninstallService),
+ cxxopts::value<bool>(ServerOptions.UninstallService),
"");
#endif
@@ -132,14 +135,14 @@ ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, Z
"",
"http",
"Select HTTP server implementation (asio|httpsys|null)",
- cxxopts::value<std::string>(GlobalOptions.HttpServerClass)->default_value(DefaultHttp),
+ cxxopts::value<std::string>(ServerOptions.HttpServerClass)->default_value(DefaultHttp),
"<http class>");
options.add_option("network",
"p",
"port",
"Select HTTP port",
- cxxopts::value<int>(GlobalOptions.BasePort)->default_value("1337"),
+ cxxopts::value<int>(ServerOptions.BasePort)->default_value("1337"),
"<port number>");
#if ZEN_ENABLE_MESH
@@ -147,7 +150,7 @@ ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, Z
"m",
"mesh",
"Enable mesh network",
- cxxopts::value<bool>(ServiceConfig.MeshEnabled)->default_value("false"),
+ cxxopts::value<bool>(ServerOptions.MeshEnabled)->default_value("false"),
"");
#endif
@@ -171,7 +174,7 @@ ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, Z
"",
"crash",
"Simulate a crash",
- cxxopts::value<bool>(ServiceConfig.ShouldCrash)->default_value("false"),
+ cxxopts::value<bool>(ServerOptions.ShouldCrash)->default_value("false"),
"");
std::string UpstreamCachePolicyOptions;
@@ -186,105 +189,105 @@ ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, Z
"",
"upstream-jupiter-url",
"URL to a Jupiter instance",
- cxxopts::value<std::string>(ServiceConfig.UpstreamCacheConfig.JupiterConfig.Url)->default_value(""),
+ cxxopts::value<std::string>(ServerOptions.UpstreamCacheConfig.JupiterConfig.Url)->default_value(""),
"");
options.add_option("cache",
"",
"upstream-jupiter-oauth-url",
"URL to the OAuth provier",
- cxxopts::value<std::string>(ServiceConfig.UpstreamCacheConfig.JupiterConfig.OAuthProvider)->default_value(""),
+ cxxopts::value<std::string>(ServerOptions.UpstreamCacheConfig.JupiterConfig.OAuthProvider)->default_value(""),
"");
options.add_option("cache",
"",
"upstream-jupiter-oauth-clientid",
"The OAuth client ID",
- cxxopts::value<std::string>(ServiceConfig.UpstreamCacheConfig.JupiterConfig.OAuthClientId)->default_value(""),
+ cxxopts::value<std::string>(ServerOptions.UpstreamCacheConfig.JupiterConfig.OAuthClientId)->default_value(""),
"");
options.add_option("cache",
"",
"upstream-jupiter-oauth-clientsecret",
"The OAuth client secret",
- cxxopts::value<std::string>(ServiceConfig.UpstreamCacheConfig.JupiterConfig.OAuthClientSecret)->default_value(""),
+ cxxopts::value<std::string>(ServerOptions.UpstreamCacheConfig.JupiterConfig.OAuthClientSecret)->default_value(""),
"");
options.add_option("cache",
"",
"upstream-jupiter-namespace",
"The Common Blob Store API namespace",
- cxxopts::value<std::string>(ServiceConfig.UpstreamCacheConfig.JupiterConfig.Namespace)->default_value(""),
+ cxxopts::value<std::string>(ServerOptions.UpstreamCacheConfig.JupiterConfig.Namespace)->default_value(""),
"");
options.add_option("cache",
"",
"upstream-jupiter-namespace-ddc",
"The lecacy DDC namespace",
- cxxopts::value<std::string>(ServiceConfig.UpstreamCacheConfig.JupiterConfig.DdcNamespace)->default_value(""),
+ cxxopts::value<std::string>(ServerOptions.UpstreamCacheConfig.JupiterConfig.DdcNamespace)->default_value(""),
"");
options.add_option("cache",
"",
"upstream-jupiter-prod",
"Enable Jupiter upstream caching using production settings",
- cxxopts::value<bool>(ServiceConfig.UpstreamCacheConfig.JupiterConfig.UseProductionSettings)->default_value("false"),
+ cxxopts::value<bool>(ServerOptions.UpstreamCacheConfig.JupiterConfig.UseProductionSettings)->default_value("false"),
"");
options.add_option("cache",
"",
"upstream-jupiter-dev",
"Enable Jupiter upstream caching using development settings",
- cxxopts::value<bool>(ServiceConfig.UpstreamCacheConfig.JupiterConfig.UseDevelopmentSettings)->default_value("false"),
+ cxxopts::value<bool>(ServerOptions.UpstreamCacheConfig.JupiterConfig.UseDevelopmentSettings)->default_value("false"),
"");
options.add_option("cache",
"",
"upstream-jupiter-use-legacy-ddc",
"Whether to store derived data using the legacy endpoint",
- cxxopts::value<bool>(ServiceConfig.UpstreamCacheConfig.JupiterConfig.UseLegacyDdc)->default_value("false"),
+ cxxopts::value<bool>(ServerOptions.UpstreamCacheConfig.JupiterConfig.UseLegacyDdc)->default_value("false"),
"");
options.add_option("cache",
"",
"upstream-zen-url",
"URL to remote Zen server. Use a comma separated list to choose the one with the best latency.",
- cxxopts::value<std::vector<std::string>>(ServiceConfig.UpstreamCacheConfig.ZenConfig.Urls)->default_value(""),
+ cxxopts::value<std::vector<std::string>>(ServerOptions.UpstreamCacheConfig.ZenConfig.Urls)->default_value(""),
"");
options.add_option("cache",
"",
"upstream-zen-dns",
"DNS that resolves to one or more Zen server instance(s)",
- cxxopts::value<std::vector<std::string>>(ServiceConfig.UpstreamCacheConfig.ZenConfig.Dns)->default_value(""),
+ cxxopts::value<std::vector<std::string>>(ServerOptions.UpstreamCacheConfig.ZenConfig.Dns)->default_value(""),
"");
options.add_option("cache",
"",
"upstream-thread-count",
"Number of threads used for upstream procsssing",
- cxxopts::value<int32_t>(ServiceConfig.UpstreamCacheConfig.UpstreamThreadCount)->default_value("4"),
+ cxxopts::value<int32_t>(ServerOptions.UpstreamCacheConfig.UpstreamThreadCount)->default_value("4"),
"");
options.add_option("cache",
"",
"upstream-stats",
"Collect performance metrics for upstream endpoints",
- cxxopts::value<bool>(ServiceConfig.UpstreamCacheConfig.StatsEnabled)->default_value("false"),
+ cxxopts::value<bool>(ServerOptions.UpstreamCacheConfig.StatsEnabled)->default_value("false"),
"");
options.add_option("cache",
"",
"upstream-connect-timeout-ms",
"Connect timeout in millisecond(s). Default 5000 ms.",
- cxxopts::value<int32_t>(ServiceConfig.UpstreamCacheConfig.ConnectTimeoutMilliseconds)->default_value("5000"),
+ cxxopts::value<int32_t>(ServerOptions.UpstreamCacheConfig.ConnectTimeoutMilliseconds)->default_value("5000"),
"");
options.add_option("cache",
"",
"upstream-timeout-ms",
"Timeout in millisecond(s). Default 0 ms",
- cxxopts::value<int32_t>(ServiceConfig.UpstreamCacheConfig.TimeoutMilliseconds)->default_value("0"),
+ cxxopts::value<int32_t>(ServerOptions.UpstreamCacheConfig.TimeoutMilliseconds)->default_value("0"),
"");
try
@@ -304,7 +307,16 @@ ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, Z
exit(0);
}
- ServiceConfig.UpstreamCacheConfig.CachePolicy = ParseUpstreamCachePolicy(UpstreamCachePolicyOptions);
+ ServerOptions.UpstreamCacheConfig.CachePolicy = ParseUpstreamCachePolicy(UpstreamCachePolicyOptions);
+
+ if (!ServerOptions.ConfigFile.empty())
+ {
+ ParseConfigFile(ServerOptions.ConfigFile, ServerOptions);
+ }
+ else
+ {
+ ParseConfigFile(ServerOptions.DataDir / "zen_cfg.lua", ServerOptions);
+ }
}
catch (cxxopts::OptionParseException& e)
{
@@ -313,32 +325,33 @@ ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, Z
throw;
}
- if (GlobalOptions.DataDir.empty())
+ if (ServerOptions.DataDir.empty())
{
- GlobalOptions.DataDir = PickDefaultStateDirectory();
+ ServerOptions.DataDir = PickDefaultStateDirectory();
}
}
void
-ParseServiceConfig(const std::filesystem::path& DataRoot, ZenServiceConfig& ServiceConfig)
+ParseConfigFile(const std::filesystem::path& Path, ZenServerOptions& ServerOptions)
{
using namespace fmt::literals;
+<<<<<<< HEAD
std::filesystem::path ConfigScript = DataRoot / "zen_cfg.lua";
zen::IoBuffer LuaScript = zen::IoBufferBuilder::MakeFromFile(ConfigScript);
+||||||| b2cc49b
+ std::filesystem::path ConfigScript = DataRoot / "zen_cfg.lua";
+ zen::IoBuffer LuaScript = zen::IoBufferBuilder::MakeFromFile(ConfigScript.native().c_str());
+=======
+ zen::IoBuffer LuaScript = zen::IoBufferBuilder::MakeFromFile(Path.native().c_str());
+>>>>>>> origin/main
if (LuaScript)
{
sol::state lua;
- // Provide some context to help derive defaults
- lua.set("dataroot", DataRoot.native());
-
lua.open_libraries(sol::lib::base);
- // We probably want to limit the scope of this so the script won't see
- // any more than it needs to
-
lua.set_function("getenv", [&](const std::string env) -> sol::object {
#if ZEN_PLATFORM_WINDOWS
std::wstring EnvVarValue;
@@ -375,14 +388,50 @@ ParseServiceConfig(const std::filesystem::path& DataRoot, ZenServiceConfig& Serv
}
catch (std::exception& e)
{
- ZEN_ERROR("config failure: {}", e.what());
+ throw std::runtime_error("failed to load config script ('{}'): {}"_format(Path, e.what()).c_str());
+ }
+
+ if (sol::optional<sol::table> ServerConfig = lua["server"])
+ {
+ if (ServerOptions.DataDir.empty())
+ {
+ if (sol::optional<std::string> Opt = ServerConfig.value()["datadir"])
+ {
+ ServerOptions.DataDir = Opt.value();
+ }
+ }
+
+ if (ServerOptions.ContentDir.empty())
+ {
+ if (sol::optional<std::string> Opt = ServerConfig.value()["contentdir"])
+ {
+ ServerOptions.ContentDir = Opt.value();
+ }
+ }
+
+ if (ServerOptions.AbsLogFile.empty())
+ {
+ if (sol::optional<std::string> Opt = ServerConfig.value()["abslog"])
+ {
+ ServerOptions.AbsLogFile = Opt.value();
+ }
+ }
- throw std::runtime_error("failed to run global config script ('{}'): {}"_format(ConfigScript, e.what()).c_str());
+ ServerOptions.IsDebug = ServerConfig->get_or("debug", ServerOptions.IsDebug);
}
+ if (sol::optional<sol::table> NetworkConfig = lua["network"])
+ {
+ if (sol::optional<std::string> Opt = NetworkConfig.value()["httpserverclass"])
+ {
+ ServerOptions.HttpServerClass = Opt.value();
+ }
+
+ ServerOptions.BasePort = NetworkConfig->get_or<int>("port", ServerOptions.BasePort);
#if ZEN_ENABLE_MESH
- ServiceConfig.MeshEnabled = lua["mesh"]["enable"].get_or(ServiceConfig.MeshEnabled);
+ ServerOptions.MeshEnabled = NetworkConfig->get_or<bool>("meshenabled", ServerOptions.MeshEnabled);
#endif
+ }
auto UpdateStringValueFromConfig = [](const sol::table& Table, std::string_view Key, std::string& OutValue) {
// Update the specified config value unless it has been set, i.e. from command line
@@ -392,56 +441,69 @@ ParseServiceConfig(const std::filesystem::path& DataRoot, ZenServiceConfig& Serv
}
};
- if (sol::optional<sol::table> StructuredCacheConfig = lua["structuredcache"])
+ if (sol::optional<sol::table> StructuredCacheConfig = lua["cache"])
{
- ServiceConfig.StructuredCacheEnabled = StructuredCacheConfig->get_or("enable", ServiceConfig.StructuredCacheEnabled);
+ ServerOptions.StructuredCacheEnabled = StructuredCacheConfig->get_or("enable", ServerOptions.StructuredCacheEnabled);
if (auto UpstreamConfig = StructuredCacheConfig->get<sol::optional<sol::table>>("upstream"))
{
- std::string Policy = UpstreamConfig->get_or("policy", std::string());
- ServiceConfig.UpstreamCacheConfig.CachePolicy = ParseUpstreamCachePolicy(Policy);
- ServiceConfig.UpstreamCacheConfig.UpstreamThreadCount = UpstreamConfig->get_or("upstreamthreadcount", 4);
+ std::string Policy = UpstreamConfig->get_or("policy", std::string());
+ ServerOptions.UpstreamCacheConfig.CachePolicy = ParseUpstreamCachePolicy(Policy);
+ ServerOptions.UpstreamCacheConfig.UpstreamThreadCount =
+ UpstreamConfig->get_or("upstreamthreadcount", ServerOptions.UpstreamCacheConfig.UpstreamThreadCount);
if (auto JupiterConfig = UpstreamConfig->get<sol::optional<sol::table>>("jupiter"))
{
UpdateStringValueFromConfig(JupiterConfig.value(),
std::string_view("url"),
- ServiceConfig.UpstreamCacheConfig.JupiterConfig.Url);
+ ServerOptions.UpstreamCacheConfig.JupiterConfig.Url);
UpdateStringValueFromConfig(JupiterConfig.value(),
std::string_view("oauthprovider"),
- ServiceConfig.UpstreamCacheConfig.JupiterConfig.OAuthProvider);
+ ServerOptions.UpstreamCacheConfig.JupiterConfig.OAuthProvider);
UpdateStringValueFromConfig(JupiterConfig.value(),
std::string_view("oauthclientid"),
- ServiceConfig.UpstreamCacheConfig.JupiterConfig.OAuthClientId);
+ ServerOptions.UpstreamCacheConfig.JupiterConfig.OAuthClientId);
UpdateStringValueFromConfig(JupiterConfig.value(),
std::string_view("oauthclientsecret"),
- ServiceConfig.UpstreamCacheConfig.JupiterConfig.OAuthClientSecret);
+ ServerOptions.UpstreamCacheConfig.JupiterConfig.OAuthClientSecret);
UpdateStringValueFromConfig(JupiterConfig.value(),
std::string_view("namespace"),
- ServiceConfig.UpstreamCacheConfig.JupiterConfig.Namespace);
+ ServerOptions.UpstreamCacheConfig.JupiterConfig.Namespace);
UpdateStringValueFromConfig(JupiterConfig.value(),
std::string_view("ddcnamespace"),
- ServiceConfig.UpstreamCacheConfig.JupiterConfig.DdcNamespace);
+ ServerOptions.UpstreamCacheConfig.JupiterConfig.DdcNamespace);
- ServiceConfig.UpstreamCacheConfig.JupiterConfig.UseDevelopmentSettings =
+ ServerOptions.UpstreamCacheConfig.JupiterConfig.UseDevelopmentSettings =
JupiterConfig->get_or("usedevelopmentsettings",
- ServiceConfig.UpstreamCacheConfig.JupiterConfig.UseDevelopmentSettings);
+ ServerOptions.UpstreamCacheConfig.JupiterConfig.UseDevelopmentSettings);
- ServiceConfig.UpstreamCacheConfig.JupiterConfig.UseLegacyDdc =
- JupiterConfig->get_or("uselegacyddc", ServiceConfig.UpstreamCacheConfig.JupiterConfig.UseLegacyDdc);
+ ServerOptions.UpstreamCacheConfig.JupiterConfig.UseLegacyDdc =
+ JupiterConfig->get_or("uselegacyddc", ServerOptions.UpstreamCacheConfig.JupiterConfig.UseLegacyDdc);
};
if (auto ZenConfig = UpstreamConfig->get<sol::optional<sol::table>>("zen"))
{
if (auto Url = ZenConfig.value().get<sol::optional<std::string>>("url"))
{
- ServiceConfig.UpstreamCacheConfig.ZenConfig.Urls.push_back(Url.value());
+ ServerOptions.UpstreamCacheConfig.ZenConfig.Urls.push_back(Url.value());
}
else if (auto Urls = ZenConfig.value().get<sol::optional<sol::table>>("url"))
{
for (const auto& Kv : Urls.value())
{
- ServiceConfig.UpstreamCacheConfig.ZenConfig.Urls.push_back(Kv.second.as<std::string>());
+ ServerOptions.UpstreamCacheConfig.ZenConfig.Urls.push_back(Kv.second.as<std::string>());
+ }
+ }
+
+ if (auto Dns = ZenConfig.value().get<sol::optional<std::string>>("dns"))
+ {
+ ServerOptions.UpstreamCacheConfig.ZenConfig.Dns.push_back(Dns.value());
+ }
+ else if (auto DnsArray = ZenConfig.value().get<sol::optional<sol::table>>("dns"))
+ {
+ for (const auto& Kv : DnsArray.value())
+ {
+ ServerOptions.UpstreamCacheConfig.ZenConfig.Dns.push_back(Kv.second.as<std::string>());
}
}
}
diff --git a/zenserver/config.h b/zenserver/config.h
index 0f3994893..74e444339 100644
--- a/zenserver/config.h
+++ b/zenserver/config.h
@@ -10,27 +10,6 @@
# define ZEN_ENABLE_MESH 0
#endif
-struct ZenServerOptions
-{
- bool IsDebug = false;
- bool IsTest = false;
- bool IsDedicated = false; // Indicates a dedicated/shared instance, with larger resource requirements
- int BasePort = 1337; // Service listen port (used for both UDP and TCP)
- int OwnerPid = 0; // Parent process id (zero for standalone)
- std::string ChildId; // Id assigned by parent process (used for lifetime management)
- bool InstallService = false; // Flag used to initiate service install (temporary)
- bool UninstallService = false; // Flag used to initiate service uninstall (temporary)
- std::string LogId; // Id for tagging log output
- std::filesystem::path DataDir; // Root directory for state (used for testing)
- std::filesystem::path ContentDir; // Root directory for serving frontend content (experimental)
- std::string HttpServerClass; // Choice of HTTP server implementation
- std::filesystem::path AbsLogFile; // Absolute path to main log file
-#if ZEN_WITH_TRACE
- std::string TraceHost; // Host name or IP address to send trace data to
- std::string TraceFile; // Path of a file to write a trace
-#endif
-};
-
struct ZenUpstreamJupiterConfig
{
std::string Url;
@@ -69,16 +48,33 @@ struct ZenUpstreamCacheConfig
bool StatsEnabled = false;
};
-struct ZenServiceConfig
+struct ZenServerOptions
{
- bool StructuredCacheEnabled = true;
- bool ShouldCrash = false; // Option for testing crash handling
- bool IsFirstRun = false;
+ ZenUpstreamCacheConfig UpstreamCacheConfig;
+ std::filesystem::path DataDir; // Root directory for state (used for testing)
+ std::filesystem::path ContentDir; // Root directory for serving frontend content (experimental)
+ std::filesystem::path AbsLogFile; // Absolute path to main log file
+ std::filesystem::path ConfigFile; // Path to Lua config file
+ std::string ChildId; // Id assigned by parent process (used for lifetime management)
+ std::string LogId; // Id for tagging log output
+ std::string HttpServerClass; // Choice of HTTP server implementation
+ int BasePort = 1337; // Service listen port (used for both UDP and TCP)
+ int OwnerPid = 0; // Parent process id (zero for standalone)
+ bool InstallService = false; // Flag used to initiate service install (temporary)
+ bool UninstallService = false; // Flag used to initiate service uninstall (temporary)
+ bool IsDebug = false;
+ bool IsTest = false;
+ bool IsDedicated = false; // Indicates a dedicated/shared instance, with larger resource requirements
+ bool StructuredCacheEnabled = true;
+ bool ShouldCrash = false; // Option for testing crash handling
+ bool IsFirstRun = false;
+#if ZEN_WITH_TRACE
+ std::string TraceHost; // Host name or IP address to send trace data to
+ std::string TraceFile; // Path of a file to write a trace
+#endif
#if ZEN_ENABLE_MESH
bool MeshEnabled = false; // Experimental p2p mesh discovery
#endif
- ZenUpstreamCacheConfig UpstreamCacheConfig;
};
-void ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, ZenServiceConfig& ServiceConfig);
-void ParseServiceConfig(const std::filesystem::path& DataRoot, ZenServiceConfig& ServiceConfig);
+void ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions);
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp
index 3caf37084..ff0c01f4f 100644
--- a/zenserver/zenserver.cpp
+++ b/zenserver/zenserver.cpp
@@ -155,12 +155,12 @@ namespace utils {
class ZenServer : public IHttpStatusProvider
{
public:
- void Initialize(ZenServiceConfig& ServiceConfig, const ZenServerOptions& ServerOptions, ZenServerState::ZenServerEntry* ServerEntry)
+ void Initialize(const ZenServerOptions& ServerOptions, ZenServerState::ZenServerEntry* ServerEntry)
{
using namespace fmt::literals;
m_ServerEntry = ServerEntry;
- m_DebugOptionForcedCrash = ServiceConfig.ShouldCrash;
+ m_DebugOptionForcedCrash = ServerOptions.ShouldCrash;
const int ParentPid = ServerOptions.OwnerPid;
if (ParentPid)
@@ -192,7 +192,7 @@ public:
throw std::runtime_error("Failed to create mutex '{}' - is another instance already running?"_format(MutexName).c_str());
}
- InitializeState(ServiceConfig);
+ InitializeState(ServerOptions);
m_HealthService.SetHealthInfo({.DataRoot = m_DataRoot,
.AbsLogPath = ServerOptions.AbsLogFile,
@@ -237,9 +237,9 @@ public:
m_HttpFunctionService = std::make_unique<zen::HttpFunctionService>(*m_CasStore, *m_CidStore, ApplySandboxDir);
#endif // ZEN_WITH_COMPUTE_SERVICES
- if (ServiceConfig.StructuredCacheEnabled)
+ if (ServerOptions.StructuredCacheEnabled)
{
- InitializeStructuredCache(ServiceConfig);
+ InitializeStructuredCache(ServerOptions);
}
else
{
@@ -247,7 +247,7 @@ public:
}
#if ZEN_ENABLE_MESH
- if (ServiceConfig.MeshEnabled)
+ if (ServerOptions.MeshEnabled)
{
StartMesh(BasePort);
}
@@ -293,8 +293,8 @@ public:
}
}
- void InitializeState(ZenServiceConfig& ServiceConfig);
- void InitializeStructuredCache(ZenServiceConfig& ServiceConfig);
+ void InitializeState(const ZenServerOptions& ServerOptions);
+ void InitializeStructuredCache(const ZenServerOptions& ServerOptions);
#if ZEN_ENABLE_MESH
void StartMesh(int BasePort)
@@ -539,7 +539,7 @@ ZenServer::OnReady()
}
void
-ZenServer::InitializeState(ZenServiceConfig& ServiceConfig)
+ZenServer::InitializeState(const ZenServerOptions& ServerOptions)
{
// Check root manifest to deal with schema versioning
@@ -552,7 +552,7 @@ ZenServer::InitializeState(ZenServiceConfig& ServiceConfig)
if (ManifestData.ErrorCode)
{
- if (ServiceConfig.IsFirstRun)
+ if (ServerOptions.IsFirstRun)
{
ZEN_INFO("Initializing state at '{}'", m_DataRoot);
@@ -633,7 +633,7 @@ ZenServer::InitializeState(ZenServiceConfig& ServiceConfig)
}
void
-ZenServer::InitializeStructuredCache(ZenServiceConfig& ServiceConfig)
+ZenServer::InitializeStructuredCache(const ZenServerOptions& ServerOptions)
{
using namespace std::literals;
auto ValueOrDefault = [](std::string_view Value, std::string_view Default) { return Value.empty() ? Default : Value; };
@@ -642,13 +642,13 @@ ZenServer::InitializeStructuredCache(ZenServiceConfig& ServiceConfig)
m_CacheStore = std::make_unique<ZenCacheStore>(m_DataRoot / "cache");
std::unique_ptr<zen::UpstreamCache> UpstreamCache;
- if (ServiceConfig.UpstreamCacheConfig.CachePolicy != UpstreamCachePolicy::Disabled)
+ if (ServerOptions.UpstreamCacheConfig.CachePolicy != UpstreamCachePolicy::Disabled)
{
- const ZenUpstreamCacheConfig& UpstreamConfig = ServiceConfig.UpstreamCacheConfig;
+ const ZenUpstreamCacheConfig& UpstreamConfig = ServerOptions.UpstreamCacheConfig;
zen::UpstreamCacheOptions UpstreamOptions;
- UpstreamOptions.ReadUpstream = (uint8_t(ServiceConfig.UpstreamCacheConfig.CachePolicy) & uint8_t(UpstreamCachePolicy::Read)) != 0;
- UpstreamOptions.WriteUpstream = (uint8_t(ServiceConfig.UpstreamCacheConfig.CachePolicy) & uint8_t(UpstreamCachePolicy::Write)) != 0;
+ UpstreamOptions.ReadUpstream = (uint8_t(ServerOptions.UpstreamCacheConfig.CachePolicy) & uint8_t(UpstreamCachePolicy::Read)) != 0;
+ UpstreamOptions.WriteUpstream = (uint8_t(ServerOptions.UpstreamCacheConfig.CachePolicy) & uint8_t(UpstreamCachePolicy::Write)) != 0;
if (UpstreamConfig.UpstreamThreadCount < 32)
{
@@ -757,14 +757,13 @@ ZenServer::InitializeStructuredCache(ZenServiceConfig& ServiceConfig)
class ZenEntryPoint
{
public:
- ZenEntryPoint(ZenServerOptions& GlobalOptions, ZenServiceConfig& ServiceConfig);
+ ZenEntryPoint(ZenServerOptions& ServerOptions);
ZenEntryPoint(const ZenEntryPoint&) = delete;
ZenEntryPoint& operator = (const ZenEntryPoint&) = delete;
int Run();
private:
- ZenServerOptions& m_GlobalOptions;
- ZenServiceConfig& m_ServiceConfig;
+ ZenServerOptions& m_ServerOptions;
zen::LockFile m_LockFile;
};
@@ -788,8 +787,7 @@ ZenEntryPoint::Run()
auto _ = zen::MakeGuard([] { sentry_close(); });
#endif
- auto& GlobalOptions = m_GlobalOptions;
- auto& ServiceConfig = m_ServiceConfig;
+ auto& ServerOptions = m_ServerOptions;
try
{
@@ -797,13 +795,13 @@ ZenEntryPoint::Run()
std::error_code Ec;
- std::filesystem::path LockFilePath = GlobalOptions.DataDir / ".lock";
+ std::filesystem::path LockFilePath = ServerOptions.DataDir / ".lock";
bool IsReady = false;
auto MakeLockData = [&] {
CbObjectWriter Cbo;
- Cbo << "pid" << zen::GetCurrentProcessId() << "data" << PathToUtf8(GlobalOptions.DataDir) << "port" << GlobalOptions.BasePort << "session_id"
+ Cbo << "pid" << zen::GetCurrentProcessId() << "data" << PathToUtf8(ServerOptions.DataDir) << "port" << ServerOptions.BasePort << "session_id"
<< GetSessionId() << "ready" << IsReady;
return Cbo.Save();
};
@@ -817,21 +815,15 @@ ZenEntryPoint::Run()
std::exit(99);
}
- InitializeLogging(GlobalOptions);
+ InitializeLogging(ServerOptions);
- // Prototype config system, we'll see how this pans out
- //
- // TODO: we need to report any parse errors here
-
- ParseServiceConfig(GlobalOptions.DataDir, /* out */ ServiceConfig);
-
- ZEN_INFO(ZEN_APP_NAME " - starting on port {}, build '{}'", GlobalOptions.BasePort, BUILD_VERSION);
+ ZEN_INFO(ZEN_APP_NAME " - starting on port {}, build '{}'", ServerOptions.BasePort, BUILD_VERSION);
ZenServerState ServerState;
ServerState.Initialize();
ServerState.Sweep();
- ZenServerState::ZenServerEntry* Entry = ServerState.Lookup(GlobalOptions.BasePort);
+ ZenServerState::ZenServerEntry* Entry = ServerState.Lookup(ServerOptions.BasePort);
if (Entry)
{
@@ -839,34 +831,34 @@ ZenEntryPoint::Run()
ZEN_WARN("Looks like there is already a process listening to this port (pid: {})", Entry->Pid);
- if (GlobalOptions.OwnerPid)
+ if (ServerOptions.OwnerPid)
{
- Entry->AddSponsorProcess(GlobalOptions.OwnerPid);
+ Entry->AddSponsorProcess(ServerOptions.OwnerPid);
std::exit(0);
}
}
- Entry = ServerState.Register(GlobalOptions.BasePort);
+ Entry = ServerState.Register(ServerOptions.BasePort);
- if (GlobalOptions.OwnerPid)
+ if (ServerOptions.OwnerPid)
{
- Entry->AddSponsorProcess(GlobalOptions.OwnerPid);
+ Entry->AddSponsorProcess(ServerOptions.OwnerPid);
}
std::unique_ptr<std::thread> ShutdownThread;
std::unique_ptr<zen::NamedEvent> ShutdownEvent;
zen::ExtendableStringBuilder<64> ShutdownEventName;
- ShutdownEventName << "Zen_" << GlobalOptions.BasePort << "_Shutdown";
+ ShutdownEventName << "Zen_" << ServerOptions.BasePort << "_Shutdown";
ShutdownEvent.reset(new zen::NamedEvent{ShutdownEventName});
ZenServer Server;
- Server.SetDataRoot(GlobalOptions.DataDir);
- Server.SetContentRoot(GlobalOptions.ContentDir);
- Server.SetTestMode(GlobalOptions.IsTest);
- Server.SetDedicatedMode(GlobalOptions.IsDedicated);
- Server.Initialize(ServiceConfig, GlobalOptions, Entry);
+ Server.SetDataRoot(ServerOptions.DataDir);
+ Server.SetContentRoot(ServerOptions.ContentDir);
+ Server.SetTestMode(ServerOptions.IsTest);
+ Server.SetDedicatedMode(ServerOptions.IsDedicated);
+ Server.Initialize(ServerOptions, Entry);
// Monitor shutdown signals
@@ -891,9 +883,9 @@ ZenEntryPoint::Run()
m_LockFile.Update(MakeLockData(), Ec);
- if (!GlobalOptions.ChildId.empty())
+ if (!ServerOptions.ChildId.empty())
{
- zen::NamedEvent ParentEvent{GlobalOptions.ChildId};
+ zen::NamedEvent ParentEvent{ServerOptions.ChildId};
ParentEvent.Set();
}
});
@@ -984,14 +976,13 @@ main(int argc, char* argv[])
try
{
- ZenServerOptions GlobalOptions;
- ZenServiceConfig ServiceConfig;
- ParseGlobalCliOptions(argc, argv, GlobalOptions, ServiceConfig);
+ ZenServerOptions ServerOptions;
+ ParseCliOptions(argc, argv, ServerOptions);
- if (!std::filesystem::exists(GlobalOptions.DataDir))
+ if (!std::filesystem::exists(ServerOptions.DataDir))
{
- ServiceConfig.IsFirstRun = true;
- std::filesystem::create_directories(GlobalOptions.DataDir);
+ ServerOptions.IsFirstRun = true;
+ std::filesystem::create_directories(ServerOptions.DataDir);
}
#if ZEN_WITH_TRACE
@@ -1006,21 +997,21 @@ main(int argc, char* argv[])
#endif // ZEN_WITH_TRACE
#if ZEN_PLATFORM_WINDOWS
- if (GlobalOptions.InstallService)
+ if (ServerOptions.InstallService)
{
WindowsService::Install();
std::exit(0);
}
- if (GlobalOptions.UninstallService)
+ if (ServerOptions.UninstallService)
{
WindowsService::Delete();
std::exit(0);
}
- ZenWindowsService App(GlobalOptions, ServiceConfig);
+ ZenWindowsService App(ServerOptions);
return App.ServiceMain();
#else
if (GlobalOptions.InstallService || GlobalOptions.UninstallService)