aboutsummaryrefslogtreecommitdiff
path: root/zenserver
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-06-21 11:07:55 +0200
committerStefan Boberg <[email protected]>2021-06-21 11:07:55 +0200
commitdd00d3dbd4b53d23cee616dd3b8771d38d403cbd (patch)
tree6ba8313d867efd278d0dc786d6af5567ba39fb71 /zenserver
parentclang-format only (diff)
downloadzen-dd00d3dbd4b53d23cee616dd3b8771d38d403cbd.tar.xz
zen-dd00d3dbd4b53d23cee616dd3b8771d38d403cbd.zip
Made some changes to how mesh config works
Diffstat (limited to 'zenserver')
-rw-r--r--zenserver/config.cpp10
-rw-r--r--zenserver/config.h21
-rw-r--r--zenserver/upstream/zen.cpp14
-rw-r--r--zenserver/zenserver.cpp26
4 files changed, 39 insertions, 32 deletions
diff --git a/zenserver/config.cpp b/zenserver/config.cpp
index 027427528..588f3ddd1 100644
--- a/zenserver/config.cpp
+++ b/zenserver/config.cpp
@@ -56,7 +56,7 @@ PickDefaultStateDirectory()
#endif
void
-ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions)
+ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, ZenServiceConfig& ServiceConfig)
{
cxxopts::Options options("zenserver", "Zen Server");
options.add_options()("d, debug", "Enable debugging", cxxopts::value<bool>(GlobalOptions.IsDebug)->default_value("false"));
@@ -81,6 +81,13 @@ ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions)
cxxopts::value<int>(GlobalOptions.BasePort)->default_value("1337"),
"<port number>");
+ options.add_option("network",
+ "m",
+ "mesh",
+ "Enable mesh network",
+ cxxopts::value<bool>(ServiceConfig.MeshEnabled)->default_value("true"),
+ "");
+
try
{
auto result = options.parse(argc, argv);
@@ -153,5 +160,6 @@ ParseServiceConfig(const std::filesystem::path& DataRoot, ZenServiceConfig& Serv
ServiceConfig.LegacyCacheEnabled = lua["legacycache"]["enable"];
const std::string path = lua["legacycache"]["readpath"];
ServiceConfig.StructuredCacheEnabled = lua["structuredcache"]["enable"];
+ ServiceConfig.MeshEnabled = lua["mesh"]["enable"];
}
}
diff --git a/zenserver/config.h b/zenserver/config.h
index fb866f134..e33b27962 100644
--- a/zenserver/config.h
+++ b/zenserver/config.h
@@ -9,21 +9,20 @@ struct ZenServerOptions
{
bool IsDebug = false;
bool IsTest = false;
- 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)
- std::string LogId; // Id for tagging log output
- std::filesystem::path DataDir; // Root directory for state (used for testing)
- std::string FlockId; // Id for grouping test instances into sets
- bool EnableMesh = false; // Experimental p2p mesh discovery
+ 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)
+ std::string LogId; // Id for tagging log output
+ std::filesystem::path DataDir; // Root directory for state (used for testing)
};
-void ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions);
-
struct ZenServiceConfig
{
- bool LegacyCacheEnabled = false;
- bool StructuredCacheEnabled = true;
+ bool LegacyCacheEnabled = false;
+ bool StructuredCacheEnabled = true;
+ bool MeshEnabled = false; // Experimental p2p mesh discovery
+ std::string FlockId; // Id for grouping test instances into sets
};
+void ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, ZenServiceConfig& ServiceConfig);
void ParseServiceConfig(const std::filesystem::path& DataRoot, ZenServiceConfig& ServiceConfig);
diff --git a/zenserver/upstream/zen.cpp b/zenserver/upstream/zen.cpp
index 7148715f2..7904f9b28 100644
--- a/zenserver/upstream/zen.cpp
+++ b/zenserver/upstream/zen.cpp
@@ -208,7 +208,7 @@ Mesh::IssueReceive()
if (!ec && BytesReceived)
{
std::error_code ErrorCode;
- std::string Sender = m_SenderEndpoint.address().to_string(ErrorCode);
+ std::string SenderIp = m_SenderEndpoint.address().to_string(ErrorCode);
// Process message
@@ -238,7 +238,7 @@ Mesh::IssueReceive()
const uint16_t Port = (++It)->AsUInt16(m_SenderEndpoint.port());
const uint32_t Lsn = (++It)->AsUInt32();
- spdlog::info("received hey from {} ({})", Sender, SessionId);
+ spdlog::info("received hey from {} ({})", SenderIp, SessionId);
RwLock::ExclusiveLockScope _(m_SessionsLock);
@@ -257,7 +257,7 @@ Mesh::IssueReceive()
{
Oid SessionId = Field.AsObjectId();
- spdlog::info("received bye from {} ({})", Sender, SessionId);
+ spdlog::info("received bye from {} ({})", SenderIp, SessionId);
// We could verify that it's sent from a known IP before erasing the
// session, if we want to be paranoid
@@ -273,18 +273,18 @@ Mesh::IssueReceive()
}
else
{
- spdlog::warn("received malformed message from {}", Sender);
+ spdlog::warn("received malformed message from {}", SenderIp);
}
}
break;
default:
- spdlog::warn("received malformed data from {}", Sender);
+ spdlog::warn("received malformed data from {}", SenderIp);
break;
}
-
- IssueReceive();
}
+
+ IssueReceive();
});
}
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp
index f1db8676b..c55d3497e 100644
--- a/zenserver/zenserver.cpp
+++ b/zenserver/zenserver.cpp
@@ -59,7 +59,7 @@
class ZenServer
{
public:
- void Initialize(int BasePort, int ParentPid)
+ void Initialize(ZenServiceConfig& ServiceConfig, int BasePort, int ParentPid)
{
using namespace fmt::literals;
spdlog::info(ZEN_APP_NAME " initializing");
@@ -78,11 +78,6 @@ public:
}
}
- // Prototype config system, let's see how this pans out
-
- ZenServiceConfig ServiceConfig;
- ParseServiceConfig(m_DataRoot, /* out */ ServiceConfig);
-
// Ok so now we're configured, let's kick things off
zen::CasStoreConfiguration Config;
@@ -122,6 +117,11 @@ public:
spdlog::info("NOT instantiating structured cache service");
}
+ if (ServiceConfig.MeshEnabled)
+ {
+ StartMesh(BasePort);
+ }
+
m_Http.Initialize(BasePort);
m_Http.AddEndpoint(m_HealthService);
m_Http.AddEndpoint(m_TestService);
@@ -256,10 +256,15 @@ main(int argc, char* argv[])
mi_version();
ZenServerOptions GlobalOptions;
- ParseGlobalCliOptions(argc, argv, GlobalOptions);
+ ZenServiceConfig ServiceConfig;
+ ParseGlobalCliOptions(argc, argv, GlobalOptions, ServiceConfig);
InitializeCrashReporting(GlobalOptions.DataDir / "crashdumps");
InitializeLogging(GlobalOptions);
+ // Prototype config system, let's see how this pans out
+
+ ParseServiceConfig(GlobalOptions.DataDir, /* out */ ServiceConfig);
+
spdlog::info("zen cache server starting on port {}", GlobalOptions.BasePort);
try
@@ -270,12 +275,7 @@ main(int argc, char* argv[])
ZenServer Server;
Server.SetDataRoot(GlobalOptions.DataDir);
Server.SetTestMode(GlobalOptions.IsTest);
- Server.Initialize(GlobalOptions.BasePort, GlobalOptions.OwnerPid);
-
- if (GlobalOptions.EnableMesh)
- {
- Server.StartMesh(GlobalOptions.BasePort);
- }
+ Server.Initialize(ServiceConfig, GlobalOptions.BasePort, GlobalOptions.OwnerPid);
if (!GlobalOptions.ChildId.empty())
{