Initial Commit

This commit is contained in:
2025-11-06 15:51:56 +01:00
commit 0f7191ad54
648 changed files with 170981 additions and 0 deletions

39
src/server/main.cpp Normal file
View File

@@ -0,0 +1,39 @@
// main.cpp - Server entry point for ColumnLynx
// Copyright (C) 2025 DcruBro
// Distributed under the GPLv3 license. See LICENSE for details.
#include <asio/asio.hpp>
#include <iostream>
#include <columnlynx/common/utils.hpp>
#include <columnlynx/common/panic_handler.hpp>
#include <columnlynx/server/net/tcp/tcp_server.hpp>
#include <columnlynx/common/libsodium_wrapper.hpp>
using asio::ip::tcp;
using namespace ColumnLynx::Utils;
using namespace ColumnLynx::Net::TCP;
int main(int argc, char** argv) {
PanicHandler::init();
try {
// TODO: Catch SIGINT and SIGTERM for graceful shutdown
// Generate a temporary keypair, replace with actual CA signed keys later (Note, these are stored in memory)
LibSodiumWrapper sodiumWrapper = LibSodiumWrapper();
asio::io_context io;
auto server = std::make_shared<TCPServer>(io, serverPort());
// Run the IO context in a separate thread
std::thread ioThread([&io]() {
io.run();
});
ioThread.join();
log("Server started on port " + std::to_string(serverPort()));
} catch (const std::exception& e) {
error("Server error: " + std::string(e.what()));
}
}

View File

@@ -0,0 +1,45 @@
// tcp_server.cpp - TCP Server for ColumnLynx
// Copyright (C) 2025 DcruBro
// Distributed under the GPLv3 license. See LICENSE for details.
#pragma once
#include <columnlynx/server/net/tcp/tcp_server.hpp>
#include <cstdint>
#include <string>
#include <unordered_map>
#include <vector>
#include <memory>
#include <unordered_set>
#include <asio/asio.hpp>
#include <columnlynx/common/net/tcp/tcp_message_type.hpp>
#include <columnlynx/common/net/tcp/net_helper.hpp>
#include <columnlynx/common/utils.hpp>
namespace ColumnLynx::Net::TCP {
void TCPServer::mStartAccept() {
mAcceptor.async_accept(
[this](asio::error_code ec, asio::ip::tcp::socket socket) {
if (!NetHelper::isExpectedDisconnect(ec)) {
auto client = TCPConnection::create(std::move(socket), mSodiumWrapper,
[this](std::shared_ptr<TCPConnection> c) {
mClients.erase(c);
Utils::log("Client removed.");
});
mClients.insert(client);
client->start();
Utils::log("Accepted new client connection.");
} else {
Utils::error("Accept failed: " + ec.message());
}
TCPServer::mStartAccept(); // Accept next
}
);
}
}