aboutsummaryrefslogtreecommitdiff
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
parentclang-format only (diff)
downloadzen-dd00d3dbd4b53d23cee616dd3b8771d38d403cbd.tar.xz
zen-dd00d3dbd4b53d23cee616dd3b8771d38d403cbd.zip
Made some changes to how mesh config works
-rw-r--r--zenserver-test/zenserver-test.cpp28
-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
-rw-r--r--zentestutil/include/zenserverprocess.h2
-rw-r--r--zentestutil/zenserverprocess.cpp5
7 files changed, 74 insertions, 32 deletions
diff --git a/zenserver-test/zenserver-test.cpp b/zenserver-test/zenserver-test.cpp
index bd348ae14..a59807ebe 100644
--- a/zenserver-test/zenserver-test.cpp
+++ b/zenserver-test/zenserver-test.cpp
@@ -1346,4 +1346,32 @@ TEST_CASE("exec.basic")
}
}
+TEST_CASE("mesh.basic")
+{
+ using namespace std::literals;
+
+ const int kInstanceCount = 4;
+
+ spdlog::info("spawning {} instances", kInstanceCount);
+
+ std::unique_ptr<ZenServerInstance> Instances[kInstanceCount];
+
+ for (int i = 0; i < kInstanceCount; ++i)
+ {
+ auto& Instance = Instances[i];
+
+ Instance = std::make_unique<ZenServerInstance>(TestEnv);
+ Instance->SetTestDir(TestEnv.CreateNewTestDir());
+ Instance->EnableMesh();
+ Instance->SpawnServer(13337 + i);
+ }
+
+ for (int i = 0; i < kInstanceCount; ++i)
+ {
+ auto& Instance = Instances[i];
+
+ Instance->WaitUntilReady();
+ }
+}
+
#endif
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())
{
diff --git a/zentestutil/include/zenserverprocess.h b/zentestutil/include/zenserverprocess.h
index ecbe39f90..4990230d3 100644
--- a/zentestutil/include/zenserverprocess.h
+++ b/zentestutil/include/zenserverprocess.h
@@ -35,6 +35,7 @@ struct ZenServerInstance
void SignalShutdown() { m_ShutdownEvent.Set(); }
void WaitUntilReady() { m_ReadyEvent.Wait(); }
void EnableTermination() { m_Terminate = true; }
+ void EnableMesh() { m_MeshEnabled = true; }
void SetTestDir(std::filesystem::path TestDir)
{
@@ -51,4 +52,5 @@ private:
zen::Event m_ShutdownEvent;
bool m_Terminate = false;
std::filesystem::path m_TestDir;
+ bool m_MeshEnabled = false;
};
diff --git a/zentestutil/zenserverprocess.cpp b/zentestutil/zenserverprocess.cpp
index ba28a43d6..9961c6151 100644
--- a/zentestutil/zenserverprocess.cpp
+++ b/zentestutil/zenserverprocess.cpp
@@ -125,6 +125,11 @@ ZenServerInstance::SpawnServer(int BasePort)
CommandLine << m_TestDir.c_str();
}
+ if (m_MeshEnabled)
+ {
+ CommandLine << " --mesh";
+ }
+
std::filesystem::path CurrentDirectory = std::filesystem::current_path();
spdlog::debug("Spawning server");