Version 1.0.0
This commit is contained in:
@@ -28,9 +28,10 @@ namespace ColumnLynx::Net::TCP {
|
||||
asio::ip::tcp::socket socket,
|
||||
std::shared_ptr<Utils::LibSodiumWrapper> sodiumWrapper,
|
||||
std::unordered_map<std::string, std::string>* serverConfig,
|
||||
std::string configDirPath,
|
||||
std::function<void(pointer)> onDisconnect)
|
||||
{
|
||||
auto conn = pointer(new TCPConnection(std::move(socket), sodiumWrapper, serverConfig));
|
||||
auto conn = pointer(new TCPConnection(std::move(socket), sodiumWrapper, serverConfig, configDirPath));
|
||||
conn->mOnDisconnect = std::move(onDisconnect);
|
||||
return conn;
|
||||
}
|
||||
@@ -50,14 +51,15 @@ namespace ColumnLynx::Net::TCP {
|
||||
std::array<uint8_t, 32> getAESKey() const;
|
||||
|
||||
private:
|
||||
TCPConnection(asio::ip::tcp::socket socket, std::shared_ptr<Utils::LibSodiumWrapper> sodiumWrapper, std::unordered_map<std::string, std::string>* serverConfig)
|
||||
TCPConnection(asio::ip::tcp::socket socket, std::shared_ptr<Utils::LibSodiumWrapper> sodiumWrapper, std::unordered_map<std::string, std::string>* serverConfig, std::string configDirPath)
|
||||
:
|
||||
mHandler(std::make_shared<MessageHandler>(std::move(socket))),
|
||||
mLibSodiumWrapper(sodiumWrapper),
|
||||
mRawServerConfig(serverConfig),
|
||||
mHeartbeatTimer(mHandler->socket().get_executor()),
|
||||
mLastHeartbeatReceived(std::chrono::steady_clock::now()),
|
||||
mLastHeartbeatSent(std::chrono::steady_clock::now())
|
||||
mLastHeartbeatSent(std::chrono::steady_clock::now()),
|
||||
mConfigDirPath(configDirPath)
|
||||
{}
|
||||
|
||||
// Start the heartbeat routine
|
||||
@@ -77,5 +79,6 @@ namespace ColumnLynx::Net::TCP {
|
||||
std::chrono::steady_clock::time_point mLastHeartbeatSent;
|
||||
int mMissedHeartbeats = 0;
|
||||
std::string mRemoteIP; // Cached remote IP to avoid calling remote_endpoint() on closed sockets
|
||||
std::string mConfigDirPath;
|
||||
};
|
||||
}
|
||||
@@ -25,14 +25,17 @@ namespace ColumnLynx::Net::TCP {
|
||||
TCPServer(asio::io_context& ioContext,
|
||||
uint16_t port,
|
||||
std::shared_ptr<Utils::LibSodiumWrapper> sodiumWrapper,
|
||||
std::shared_ptr<bool> hostRunning, bool ipv4Only = false)
|
||||
std::shared_ptr<bool> hostRunning,
|
||||
std::string& configPath,
|
||||
bool ipv4Only = false)
|
||||
: mIoContext(ioContext),
|
||||
mAcceptor(ioContext),
|
||||
mSodiumWrapper(sodiumWrapper),
|
||||
mHostRunning(hostRunning)
|
||||
mHostRunning(hostRunning),
|
||||
mConfigDirPath(configPath)
|
||||
{
|
||||
// Preload the config map
|
||||
mRawServerConfig = Utils::getConfigMap("server_config", {"NETWORK", "SUBNET_MASK"});
|
||||
mRawServerConfig = Utils::getConfigMap(configPath + "server_config", {"NETWORK", "SUBNET_MASK"});
|
||||
|
||||
asio::error_code ec_open, ec_v6only, ec_bind;
|
||||
|
||||
@@ -84,6 +87,7 @@ namespace ColumnLynx::Net::TCP {
|
||||
std::shared_ptr<Utils::LibSodiumWrapper> mSodiumWrapper;
|
||||
std::shared_ptr<bool> mHostRunning;
|
||||
std::unordered_map<std::string, std::string> mRawServerConfig;
|
||||
std::string mConfigDirPath;
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user