Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ on: [push]
jobs:
build:
runs-on: ubuntu-latest
env:
BUILD_WRAPPER_OUT_DIR: /srv/build

strategy:
fail-fast: false
Expand All @@ -33,37 +31,11 @@ jobs:
container:
image: ghcr.io/anexperimentwithtime/compiler:${{ matrix.version }}-${{ matrix.type }}-${{ matrix.link }}

services:
mysql:
image: mysql:8.4
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
MYSQL_ROOT_PASSWORD: state_password
MYSQL_USER: user
MYSQL_PASSWORD: state_password
MYSQL_DATABASE: state
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Prepares databases
env:
DB_HOST: mysql
DB_PORT: 3306
run: |
bash scripts/prepare-database.sh

- name: Run build and test
env:
DB_HOST: mysql
DB_USER: user
DB_PASSWORD: state_password
DB_NAME: state
DB_PORT: 3306
run: |
bash scripts/build-and-test.sh ${{ matrix.type }} ${{ matrix.link }}
94 changes: 7 additions & 87 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,6 @@ if (ENABLE_STATIC_LINKING)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_STATIC_RUNTIME ON)
set(BOOST_ALL_NO_LIB ON)
set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries" FORCE)
set(ZLIB_USE_STATIC_LIBS ON)
set(OPENSSL_USE_STATIC_LIBS TRUE)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")

if (ENABLE_CI)
set(OPENSSL_CRYPTO_LIBRARY "/usr/lib/libcrypto.a")
set(OPENSSL_SSL_LIBRARY "/usr/lib/libssl.a")
set(CURL_LIBRARY "/usr/lib/libcurl.a")
set(ZLIB_LIBRARY "/usr/lib/libz.a")
set(NGHTTP2_LIBRARY "/usr/lib/libnghttp2.a")
else ()
if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
set(ARCH_LIB_DIR "/usr/lib/aarch64-linux-gnu")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
set(ARCH_LIB_DIR "/usr/lib/x86_64-linux-gnu")
else()
message(FATAL_ERROR "Arquitectura no soportada: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
set(OPENSSL_CRYPTO_LIBRARY "${ARCH_LIB_DIR}/libcrypto.a")
set(OPENSSL_SSL_LIBRARY "${ARCH_LIB_DIR}/libssl.a")
set(CURL_LIBRARY "${ARCH_LIB_DIR}/libcurl.a")
set(ZLIB_LIBRARY "${ARCH_LIB_DIR}/libz.a")
set(NGHTTP2_LIBRARY "${ARCH_LIB_DIR}/libnghttp2.a")
endif ()

set(OpenSSL_USE_STATIC_LIBS TRUE)

if (ENABLE_NATIVE_OPTIMIZATION)
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -flto -march=native -mtune=native -g0 -static -static-libgcc")
Expand All @@ -84,89 +57,38 @@ if (ENABLE_DEBUG)
add_definitions(-DDEBUG_ENABLED)
endif ()


find_package(Boost REQUIRED COMPONENTS program_options json charconv)

find_package(
Boost
REQUIRED
COMPONENTS
program_options
json
)

find_package(OpenSSL REQUIRED)
find_package(spdlog REQUIRED)
find_package(fmt REQUIRED)

if (NOT ENABLE_STATIC_LINKING)
find_package(CURL REQUIRED)
find_package(sentry REQUIRED)
find_library(NGHTTP2_LIBRARY nghttp2 REQUIRED)
endif ()

file(GLOB_RECURSE STATE_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/src/objects/*.cpp")

include_directories(src/include)

add_library(objects OBJECT ${STATE_SOURCES})

if (NOT ENABLE_STATIC_LINKING)
target_link_libraries(objects PRIVATE
${Boost_LIBRARIES}
${OPENSSL_SSL_LIBRARY}
${OPENSSL_CRYPTO_LIBRARY}
spdlog::spdlog
sentry::sentry
fmt::fmt
)
else ()
target_link_libraries(objects PRIVATE
${Boost_LIBRARIES}
${OPENSSL_SSL_LIBRARY}
${OPENSSL_CRYPTO_LIBRARY}
spdlog::spdlog
fmt::fmt
)
endif ()

add_library(netdeps OBJECT
deps/asio.cxx
deps/beast.cxx
)

target_link_libraries(netdeps PRIVATE
target_link_libraries(objects PRIVATE
${Boost_LIBRARIES}
${OPENSSL_SSL_LIBRARY}
${OPENSSL_CRYPTO_LIBRARY}
spdlog::spdlog
fmt::fmt
)

add_library(netdeps OBJECT deps/asio.cxx deps/beast.cxx)

target_link_libraries(netdeps PRIVATE ${Boost_LIBRARIES})

add_executable(state main.cpp)
if (ENABLE_STATIC_LINKING)
target_compile_options(state PRIVATE -static -static-libgcc -static-libstdc++)
target_link_options(state PRIVATE -static -static-libgcc -static-libstdc++)
endif()

if (NOT ENABLE_STATIC_LINKING)
target_link_libraries(state PRIVATE objects
netdeps
${Boost_LIBRARIES}
${OPENSSL_SSL_LIBRARY}
${OPENSSL_CRYPTO_LIBRARY}
spdlog::spdlog
sentry::sentry
fmt::fmt
)
else ()
target_link_libraries(state PRIVATE objects
netdeps
${Boost_LIBRARIES}
${OPENSSL_SSL_LIBRARY}
${OPENSSL_CRYPTO_LIBRARY}
spdlog::spdlog
fmt::fmt
)
endif ()

if (ENABLE_TESTS)
include(FetchContent)
Expand All @@ -189,8 +111,6 @@ if (ENABLE_TESTS)
netdeps
GTest::gtest_main
${Boost_LIBRARIES}
${OPENSSL_SSL_LIBRARY}
${OPENSSL_CRYPTO_LIBRARY}
spdlog::spdlog
fmt::fmt
)
Expand Down
60 changes: 0 additions & 60 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,65 +15,21 @@

#include <fmt/base.h>

#ifdef STATIC_ENABLED
#else
#include <sentry.h>
#endif

#include <aewt/logger.hpp>
#include <aewt/state.hpp>
#include <aewt/config.hpp>
#include <aewt/server.hpp>
#include <aewt/session.hpp>
#include <aewt/session_listener.hpp>
#include <aewt/client_listener.hpp>
#include <aewt/repl.hpp>

#include <aewt/version.hpp>

#include <boost/version.hpp>
#include <boost/asio/io_context.hpp>
#include <boost/uuid/uuid_io.hpp>

#include <boost/program_options/options_description.hpp>
#include <boost/program_options/parsers.hpp>
#include <boost/program_options/variables_map.hpp>


std::string DEFAULT_SENTRY_DSN =
"https://{username}@{token}.ingest.{zone}.sentry.io/{app_id}";
std::string DEFAULT_SENTRY_DEBUG = "OFF";

void sentry_start(const std::string &dsn, const bool debug) {
#ifdef STATIC_ENABLED
LOG_INFO("sentry start isn't available on static");
#else
LOG_INFO("sentry starting");
sentry_options_t *_options = sentry_options_new();
sentry_options_set_dsn(_options, dsn.data());
sentry_options_set_database_path(_options, ".sentry-native");

const std::string _release_name =
fmt::format("state@{}.{}.{}", aewt::version::get_major(),
aewt::version::get_minor(), aewt::version::get_patch());

sentry_options_set_release(_options, _release_name.data());
sentry_options_set_debug(_options, debug);
sentry_init(_options);
LOG_INFO("sentry started");
#endif
}

void sentry_stop() {
#ifdef STATIC_ENABLED
LOG_INFO("sentry close isn't available on static");
#else
LOG_INFO("sentry closing");
sentry_close();
LOG_INFO("sentry closed");
#endif
}

int main(const int argc, const char *argv[]) {
boost::program_options::options_description _options("Options");
auto _push_option = _options.add_options();
Expand All @@ -86,19 +42,10 @@ int main(const int argc, const char *argv[]) {
_push_option("remote_address", boost::program_options::value<std::string>()->default_value("localhost"));
_push_option("remote_sessions_port", boost::program_options::value<unsigned short>()->default_value(9000));
_push_option("remote_clients_port", boost::program_options::value<unsigned short>()->default_value(10000));
_push_option("sentry_enabled", boost::program_options::value<bool>()->default_value(false));
_push_option("sentry_dsn",
boost::program_options::value<std::string>()->default_value(
"https://{username}@{token}.ingest.{zone}.sentry.io/{app_id}"));
_push_option("sentry_debug", boost::program_options::value<bool>()->default_value(false));

boost::program_options::variables_map _vm;
store(parse_command_line(argc, argv, _options), _vm);

if (_vm["sentry_enabled"].as<bool>()) {
sentry_start(_vm["sentry_dsn"].as<std::string>(), _vm["sentry_debug"].as<bool>());
}

const auto _server = std::make_shared<aewt::server>();

_server->get_config()->address_ = _vm["address"].as<std::string>();
Expand All @@ -122,15 +69,8 @@ int main(const int argc, const char *argv[]) {
LOG_INFO("- remote_address: {}", _vm["remote_address"].as<std::string>());
LOG_INFO("- remote_sessions_port: {}", _vm["remote_sessions_port"].as<unsigned short>());
LOG_INFO("- remote_clients_port: {}", _vm["remote_clients_port"].as<unsigned short>());
LOG_INFO("- sentry_enabled: {}", _vm["sentry_enabled"].as<bool>());
LOG_INFO("- sentry_debug: {}", _vm["sentry_debug"].as<bool>());
LOG_INFO("- sentry_dsn: {}", _vm["sentry_dsn"].as<std::string>());

_server->start();

if (_vm["sentry_enabled"].as<bool>()) {
sentry_stop();
}

return 0;
}
17 changes: 0 additions & 17 deletions scripts/prepare-database.sh

This file was deleted.

6 changes: 4 additions & 2 deletions src/objects/session_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

namespace aewt {
session_listener::session_listener(boost::asio::io_context &ioc, const boost::asio::ip::tcp::endpoint &endpoint,
const std::shared_ptr<state> &state) : ioc_(ioc), acceptor_(make_strand(ioc)), state_(state) {
const std::shared_ptr<state> &state) : ioc_(ioc), acceptor_(make_strand(ioc)),
state_(state) {
boost::beast::error_code ec;

acceptor_.open(endpoint.protocol(), ec);
Expand Down Expand Up @@ -52,7 +53,8 @@ namespace aewt {
}

state_->get_config()->sessions_port_.store(acceptor_.local_endpoint().port(), std::memory_order_release);
LOG_INFO("state_id=[{}] sessions is listening on [{}]", to_string(state_->get_id()), state_->get_config()->sessions_port_.load(std::memory_order_acquire));
LOG_INFO("state_id=[{}] sessions is listening on [{}]", to_string(state_->get_id()),
state_->get_config()->sessions_port_.load(std::memory_order_acquire));
}

void session_listener::on_accept(const boost::beast::error_code &ec, boost::asio::ip::tcp::socket socket) {
Expand Down
Loading