Compare commits
10
Commits
dfbbdaaf01
...
v2.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2ec314eb9 | ||
|
|
16d9a667eb | ||
|
|
d456257d0c | ||
|
|
cbb178d83d | ||
|
|
29c7e60733 | ||
|
|
4b6f3165b2 | ||
|
|
b08f8ad29b | ||
|
|
915e2ab981 | ||
|
|
9637f1eef7 | ||
|
|
a277f2102b |
No files matched your search
@@ -0,0 +1,55 @@
|
|||||||
|
name: Independent component release
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: [v*]
|
||||||
|
schedule:
|
||||||
|
- cron: '17 2 * * *'
|
||||||
|
workflow_dispatch:
|
||||||
|
jobs:
|
||||||
|
publish:
|
||||||
|
runs-on: echoion-release-serial
|
||||||
|
steps:
|
||||||
|
- name: Check out component
|
||||||
|
uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Check out pinned public release tools
|
||||||
|
uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262
|
||||||
|
with:
|
||||||
|
repository: Void/Echoion
|
||||||
|
ref: ${{ vars.ECHOION_RELEASE_TOOLS_REF }}
|
||||||
|
path: .echoion-release-tools
|
||||||
|
fetch-depth: 0
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Build, publish, and merge feed transaction
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
AWS_ACCESS_KEY_ID: ${{ secrets.COMPONENT_OBJECT_STORAGE_ACCESS_KEY }}
|
||||||
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.COMPONENT_OBJECT_STORAGE_SECRET_KEY }}
|
||||||
|
AWS_DEFAULT_REGION: ${{ vars.COMPONENT_OBJECT_STORAGE_REGION }}
|
||||||
|
ECHOION_COMPONENT_SSH_KEY: ${{ secrets.RELEASE_CHECKOUT_SSH_KEY }}
|
||||||
|
ECHOION_DISTRIBUTION_BACKEND: ${{ vars.ECHOION_DISTRIBUTION_BACKEND }}
|
||||||
|
ECHOION_DISTRIBUTION_BASE_URL: ${{ vars.ECHOION_DISTRIBUTION_BASE_URL }}
|
||||||
|
ECHOION_FEED_BASE_URL: ${{ vars.ECHOION_FEED_BASE_URL }}
|
||||||
|
ECHOION_FEED_COMMIT_SIGNING_KEY: ${{ secrets.RELEASE_FEED_GIT_SIGNING_KEY }}
|
||||||
|
ECHOION_FEED_PRIVATE_KEY: ${{ secrets.RELEASE_FEED_ED25519_PRIVATE_KEY }}
|
||||||
|
ECHOION_FEED_REPOSITORY: ssh://gitea@git.faumaray.ru/Void/Echoion.git
|
||||||
|
ECHOION_FEED_SIGNING_KEY_ID: ${{ vars.ECHOION_FEED_SIGNING_KEY_ID }}
|
||||||
|
ECHOION_OBJECT_STORAGE_BUCKET: ${{ vars.COMPONENT_OBJECT_STORAGE_BUCKET }}
|
||||||
|
ECHOION_OBJECT_STORAGE_ENDPOINT: ${{ vars.COMPONENT_OBJECT_STORAGE_ENDPOINT }}
|
||||||
|
ECHOION_OBJECT_STORAGE_PREFIX: ${{ vars.COMPONENT_OBJECT_STORAGE_PREFIX }}
|
||||||
|
ECHOION_RELEASE_TAG_ALLOWED_SIGNERS: ${{ secrets.RELEASE_TAG_ALLOWED_SIGNERS }}
|
||||||
|
GITEA_API_URL: ${{ gitea.api_url }}
|
||||||
|
GITEA_EVENT_NAME: ${{ gitea.event_name }}
|
||||||
|
GITEA_REF_NAME: ${{ gitea.ref_name }}
|
||||||
|
GITEA_RUN_NUMBER: ${{ gitea.run_number }}
|
||||||
|
GITEA_SHA: ${{ gitea.sha }}
|
||||||
|
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||||
|
GITEA_RELEASE_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }}
|
||||||
|
RELEASE_TOOLS_REF: ${{ vars.ECHOION_RELEASE_TOOLS_REF }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
[[ "$RELEASE_TOOLS_REF" =~ ^[0-9a-f]{40}$ ]]
|
||||||
|
test "$(git -C .echoion-release-tools rev-parse HEAD)" = "$RELEASE_TOOLS_REF"
|
||||||
|
.echoion-release-tools/scripts/release-component.sh component.release.json
|
||||||
+73
-2
@@ -1,5 +1,36 @@
|
|||||||
cmake_minimum_required(VERSION 4.0.0)
|
cmake_minimum_required(VERSION 4.0.0)
|
||||||
project(EchoionCore VERSION 1.0.0 LANGUAGES CXX)
|
if(NOT DEFINED ECHOION_PRODUCT_VERSION)
|
||||||
|
set(ECHOION_PRODUCT_VERSION 0.0.0)
|
||||||
|
endif()
|
||||||
|
if(NOT DEFINED ECHOION_COMPONENT_VERSION)
|
||||||
|
set(ECHOION_COMPONENT_VERSION "${ECHOION_PRODUCT_VERSION}")
|
||||||
|
endif()
|
||||||
|
project(EchoionCore VERSION "${ECHOION_COMPONENT_VERSION}" LANGUAGES CXX)
|
||||||
|
|
||||||
|
if(PROJECT_IS_TOP_LEVEL)
|
||||||
|
set(BUILD_SHARED_LIBS ON CACHE BOOL
|
||||||
|
"Build shared component dependencies" FORCE)
|
||||||
|
file(DOWNLOAD
|
||||||
|
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.8/CPM.cmake
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake"
|
||||||
|
EXPECTED_HASH
|
||||||
|
SHA256=78ba32abdf798bc616bab7c73aac32a17bbd7b06ad9e26a6add69de8f3ae4791)
|
||||||
|
include("${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake")
|
||||||
|
CPMAddPackage(
|
||||||
|
NAME Void
|
||||||
|
GIT_REPOSITORY ssh://gitea@git.faumaray.ru/void/voidlibrary.git
|
||||||
|
GIT_TAG main
|
||||||
|
OPTIONS "VOID_ENABLE_TESTING OFF")
|
||||||
|
CPMAddPackage(
|
||||||
|
NAME EchoionApi
|
||||||
|
GIT_REPOSITORY ssh://gitea@git.faumaray.ru/void/echoionapi.git
|
||||||
|
GIT_TAG main)
|
||||||
|
option(BUILD_TESTS "Build component tests" ON)
|
||||||
|
if(BUILD_TESTS)
|
||||||
|
enable_testing()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
||||||
set(CMAKE_CXX_STANDARD 26)
|
set(CMAKE_CXX_STANDARD 26)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
@@ -11,6 +42,12 @@ file(GLOB_RECURSE CORE_SOURCES
|
|||||||
"src/**.cpp"
|
"src/**.cpp"
|
||||||
)
|
)
|
||||||
add_library(EchoionCore SHARED ${CORE_SOURCES})
|
add_library(EchoionCore SHARED ${CORE_SOURCES})
|
||||||
|
target_compile_definitions(EchoionCore PRIVATE
|
||||||
|
ECHOION_CORE_VERSION="${ECHOION_COMPONENT_VERSION}"
|
||||||
|
ECHOION_MODULE_BUILD
|
||||||
|
ECHOION_COMPONENT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
|
||||||
|
ECHOION_COMPONENT_VERSION_MINOR=${PROJECT_VERSION_MINOR}
|
||||||
|
ECHOION_COMPONENT_VERSION_PATCH=${PROJECT_VERSION_PATCH})
|
||||||
|
|
||||||
add_library(Echoion::Core ALIAS EchoionCore)
|
add_library(Echoion::Core ALIAS EchoionCore)
|
||||||
|
|
||||||
@@ -37,6 +74,7 @@ target_link_libraries(EchoionCore PUBLIC
|
|||||||
Echoion::ApiPluginInterface
|
Echoion::ApiPluginInterface
|
||||||
Echoion::ApiCoreInterface
|
Echoion::ApiCoreInterface
|
||||||
Echoion::ApiUtils
|
Echoion::ApiUtils
|
||||||
|
Echoion::ApiModuleAbi
|
||||||
)
|
)
|
||||||
|
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
@@ -110,13 +148,19 @@ endif()
|
|||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
find_package(OpenSSL REQUIRED)
|
find_package(OpenSSL REQUIRED)
|
||||||
find_package(SQLite3 REQUIRED)
|
find_package(SQLite3 REQUIRED)
|
||||||
|
# FindSQLite3 exposed only SQLite::SQLite3 before CMake 4.3. Keep the
|
||||||
|
# component's preferred target name available across the supported CMake 4.x
|
||||||
|
# range; an alias created inside sibling VoidLibrary is not visible here.
|
||||||
|
if(NOT TARGET SQLite3::SQLite3 AND TARGET SQLite::SQLite3)
|
||||||
|
add_library(SQLite3::SQLite3 ALIAS SQLite::SQLite3)
|
||||||
|
endif()
|
||||||
find_package(TBB REQUIRED)
|
find_package(TBB REQUIRED)
|
||||||
|
|
||||||
target_link_libraries(EchoionCore
|
target_link_libraries(EchoionCore
|
||||||
PUBLIC
|
PUBLIC
|
||||||
PkgConfig::LIBAV
|
PkgConfig::LIBAV
|
||||||
TBB::tbb
|
TBB::tbb
|
||||||
SQLite::SQLite3
|
SQLite3::SQLite3
|
||||||
# VoidLibrary modules (migration target — replacing in-house infra)
|
# VoidLibrary modules (migration target — replacing in-house infra)
|
||||||
Void::Data
|
Void::Data
|
||||||
Void::Functional
|
Void::Functional
|
||||||
@@ -150,6 +194,21 @@ else()
|
|||||||
target_compile_options(EchoionCore PRIVATE -Wall -Wextra -Wpedantic)
|
target_compile_options(EchoionCore PRIVATE -Wall -Wextra -Wpedantic)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(BUILD_TESTS)
|
||||||
|
include("${Void_SOURCE_DIR}/cmake/VoidTesting.cmake")
|
||||||
|
|
||||||
|
add_executable(echoion_log_rotation_tests
|
||||||
|
tests/test_log_rotation.cpp
|
||||||
|
src/LogRotation.cpp
|
||||||
|
)
|
||||||
|
target_include_directories(echoion_log_rotation_tests PRIVATE
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||||
|
)
|
||||||
|
target_compile_features(echoion_log_rotation_tests PRIVATE cxx_std_26)
|
||||||
|
add_test(NAME echoion_log_rotation_tests
|
||||||
|
COMMAND echoion_log_rotation_tests)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Precompiled headers for the heavy translation units (MusicManager.cpp ~2.4k
|
# Precompiled headers for the heavy translation units (MusicManager.cpp ~2.4k
|
||||||
# lines, Core.cpp, YouTubeClient.cpp). These pull in the same expensive standard
|
# lines, Core.cpp, YouTubeClient.cpp). These pull in the same expensive standard
|
||||||
# and Void headers, so compiling them once cuts a large slice off build time.
|
# and Void headers, so compiling them once cuts a large slice off build time.
|
||||||
@@ -200,6 +259,9 @@ install(EXPORT EchoionCoreTargets
|
|||||||
DESTINATION lib/cmake/EchoionCore
|
DESTINATION lib/cmake/EchoionCore
|
||||||
)
|
)
|
||||||
|
|
||||||
|
install(FILES abi/module.json
|
||||||
|
DESTINATION share/echoion/components/EchoionCore/${PROJECT_VERSION}/abi)
|
||||||
|
|
||||||
# Package config files
|
# Package config files
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
write_basic_package_version_file(
|
write_basic_package_version_file(
|
||||||
@@ -253,6 +315,15 @@ if(BUILD_TESTS)
|
|||||||
target_link_libraries(echoion_core_url_shortener_tests PRIVATE EchoionCore)
|
target_link_libraries(echoion_core_url_shortener_tests PRIVATE EchoionCore)
|
||||||
add_test(NAME echoion_core_url_shortener_tests
|
add_test(NAME echoion_core_url_shortener_tests
|
||||||
COMMAND echoion_core_url_shortener_tests)
|
COMMAND echoion_core_url_shortener_tests)
|
||||||
|
|
||||||
|
add_executable(echoion_core_plugin_compatibility_tests
|
||||||
|
tests/test_plugin_compatibility.cpp)
|
||||||
|
target_include_directories(echoion_core_plugin_compatibility_tests PRIVATE
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||||
|
target_link_libraries(echoion_core_plugin_compatibility_tests PRIVATE
|
||||||
|
EchoionCore)
|
||||||
|
void_add_tests(echoion_core_plugin_compatibility_tests)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
option(BUNDLE_FFMPEG "Bundle FFmpeg libraries with installation" OFF)
|
option(BUNDLE_FFMPEG "Bundle FFmpeg libraries with installation" OFF)
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"contractId": "echoion.module.core",
|
||||||
|
"descriptor": "echoion_module_descriptor_v1",
|
||||||
|
"querySymbol": "echoion_module_abi_query",
|
||||||
|
"moduleId": "EchoionCore",
|
||||||
|
"activation": "reloadable",
|
||||||
|
"dependencies": [
|
||||||
|
{
|
||||||
|
"moduleId": "EchoionApi",
|
||||||
|
"versionRange": "^2.0.0",
|
||||||
|
"abiHash": "sha256:d50293d345a97e52f9844088bdd42277f566bc815a21b7636d3e053f06c6c113"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"componentId": "EchoionCore",
|
||||||
|
"productCompatibility": ">=2.0.0 <3.0.0",
|
||||||
|
"publishNightly": true,
|
||||||
|
"cmakeOptions": {}
|
||||||
|
}
|
||||||
@@ -187,7 +187,8 @@ namespace Echoion::Core
|
|||||||
|
|
||||||
// Build the console + split-file logging stack and install it as
|
// Build the console + split-file logging stack and install it as
|
||||||
// the global Void::Log sink (logSink_ must outlive logging).
|
// the global Void::Log sink (logSink_ must outlive logging).
|
||||||
void installLogging(const std::filesystem::path& logDirectory);
|
void installLogging(const std::filesystem::path& logDirectory,
|
||||||
|
const Api::LoggingConfig& config);
|
||||||
|
|
||||||
// Guard helper: ok if initialized, else a ServiceUnavailable error.
|
// Guard helper: ok if initialized, else a ServiceUnavailable error.
|
||||||
[[nodiscard]] Api::Result<void> requireInitialized() const noexcept;
|
[[nodiscard]] Api::Result<void> requireInitialized() const noexcept;
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <system_error>
|
||||||
|
|
||||||
|
namespace Echoion::Core
|
||||||
|
{
|
||||||
|
// Archive a non-empty active log into <directory>/history and prune the
|
||||||
|
// oldest archives. This is intentionally performed before opening the
|
||||||
|
// logger so every process start gets a fresh active file.
|
||||||
|
[[nodiscard]] std::error_code
|
||||||
|
rotateLogOnStartup(const std::filesystem::path& activeLog,
|
||||||
|
std::size_t maxFiles) noexcept;
|
||||||
|
} // namespace Echoion::Core
|
||||||
@@ -47,6 +47,9 @@ namespace Echoion::Core
|
|||||||
|
|
||||||
void loadDirectory(const std::filesystem::path& directory);
|
void loadDirectory(const std::filesystem::path& directory);
|
||||||
void loadManagedDirectory(const std::filesystem::path& directory);
|
void loadManagedDirectory(const std::filesystem::path& directory);
|
||||||
|
// Bind and validate cross-plugin services after every startup
|
||||||
|
// directory has been loaded.
|
||||||
|
[[nodiscard]] bool finalizeLoading();
|
||||||
[[nodiscard]] Api::Result<std::string>
|
[[nodiscard]] Api::Result<std::string>
|
||||||
manage(const std::string& requestJson);
|
manage(const std::string& requestJson);
|
||||||
void setChangeCallback(std::function<void()> callback);
|
void setChangeCallback(std::function<void()> callback);
|
||||||
@@ -71,8 +74,8 @@ namespace Echoion::Core
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void publish(std::string_view name);
|
void publish(std::string name);
|
||||||
void unpublish(std::string_view name);
|
void unpublish(std::string name);
|
||||||
void notifyChanged() const;
|
void notifyChanged() const;
|
||||||
[[nodiscard]] std::string
|
[[nodiscard]] std::string
|
||||||
pluginConfiguration(std::string_view name) const;
|
pluginConfiguration(std::string_view name) const;
|
||||||
|
|||||||
@@ -28,6 +28,24 @@ namespace Echoion::Core
|
|||||||
config.bot.language = "en";
|
config.bot.language = "en";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::filesystem::path logFile{config.logging.fileName};
|
||||||
|
if (config.logging.fileName.empty() || logFile.is_absolute() ||
|
||||||
|
logFile.has_parent_path() || logFile.filename() != logFile ||
|
||||||
|
logFile == "." || logFile == "..") {
|
||||||
|
config.logging.fileName = "echoion.log";
|
||||||
|
}
|
||||||
|
config.logging.maxFileSizeBytes = std::clamp<uint64_t>(
|
||||||
|
config.logging.maxFileSizeBytes, 64 * 1024, 1024ULL * 1024 * 1024);
|
||||||
|
config.logging.maxFiles =
|
||||||
|
std::clamp<uint32_t>(config.logging.maxFiles, 1, 1000);
|
||||||
|
static constexpr std::array<std::string_view, 8> kLogLevels = {
|
||||||
|
"trace", "debug", "info", "warning",
|
||||||
|
"warn", "error", "critical", "fatal"};
|
||||||
|
if (std::ranges::find(kLogLevels, config.logging.level) ==
|
||||||
|
kLogLevels.end()) {
|
||||||
|
config.logging.level = "debug";
|
||||||
|
}
|
||||||
|
|
||||||
// Keep partially specified updater sections usable. Security-sensitive
|
// Keep partially specified updater sections usable. Security-sensitive
|
||||||
// URL/key validation happens in the host updater before the policy is
|
// URL/key validation happens in the host updater before the policy is
|
||||||
// persisted or used; normalization here only supplies structural
|
// persisted or used; normalization here only supplies structural
|
||||||
|
|||||||
+53
-24
@@ -1,6 +1,7 @@
|
|||||||
#include "PluginTypes.hpp"
|
#include "PluginTypes.hpp"
|
||||||
#include "echoion/core/ConfigLoader.hpp"
|
#include "echoion/core/ConfigLoader.hpp"
|
||||||
#include "echoion/core/Core.hpp"
|
#include "echoion/core/Core.hpp"
|
||||||
|
#include "echoion/core/LogRotation.hpp"
|
||||||
#include "echoion/core/PluginHost.hpp"
|
#include "echoion/core/PluginHost.hpp"
|
||||||
#include "echoion/core/RpcDtos.hpp"
|
#include "echoion/core/RpcDtos.hpp"
|
||||||
#include "echoion/core/TeamSpeakDirectoryService.hpp"
|
#include "echoion/core/TeamSpeakDirectoryService.hpp"
|
||||||
@@ -16,8 +17,8 @@
|
|||||||
#include <Void/Log/Formatter.hpp>
|
#include <Void/Log/Formatter.hpp>
|
||||||
#include <Void/Log/Log.hpp>
|
#include <Void/Log/Log.hpp>
|
||||||
#include <Void/Log/LoggingAdapter.hpp>
|
#include <Void/Log/LoggingAdapter.hpp>
|
||||||
|
#include <Void/Log/RotatingFileLogger.hpp>
|
||||||
#include <Void/Log/Sinks.hpp>
|
#include <Void/Log/Sinks.hpp>
|
||||||
#include <Void/Log/SplitFileLogger.hpp>
|
|
||||||
#include <Void/Text/Base64.hpp>
|
#include <Void/Text/Base64.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@@ -91,31 +92,57 @@ namespace Echoion::Core
|
|||||||
return "application/octet-stream";
|
return "application/octet-stream";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the console + split-file logging stack and install it as the
|
// Build the configurable console + rolling-file logging stack.
|
||||||
// process-wide Void::Log sink. Replaces the old ILogger/LoggerRegistry
|
|
||||||
// indirection; every ECHOION_LOG_* macro is now a Void::Log:: call.
|
|
||||||
[[nodiscard]] std::shared_ptr<Void::Logging::MultiLogger>
|
[[nodiscard]] std::shared_ptr<Void::Logging::MultiLogger>
|
||||||
buildLogSink(const std::filesystem::path& logDirectory)
|
buildLogSink(const std::filesystem::path& logDirectory,
|
||||||
|
const Api::LoggingConfig& config)
|
||||||
{
|
{
|
||||||
namespace VL = Void::Logging;
|
namespace VL = Void::Logging;
|
||||||
auto multi = std::make_shared<VL::MultiLogger>();
|
auto multi = std::make_shared<VL::MultiLogger>();
|
||||||
auto formatter = std::make_shared<const VL::PatternFormatter>(
|
auto formatter = std::make_shared<const VL::PatternFormatter>(
|
||||||
"[{time}] [{level}] [{thread}] {file} - {message}");
|
"[{time}] [{level}] [{thread}] {file} - {message}");
|
||||||
|
|
||||||
auto console = std::make_shared<VL::ConsoleLogger>(std::cout);
|
if (config.console) {
|
||||||
console->set_formatter(formatter);
|
auto console = std::make_shared<VL::ConsoleLogger>(std::cout);
|
||||||
multi->add(std::move(console));
|
console->set_formatter(formatter);
|
||||||
|
multi->add(std::move(console));
|
||||||
|
}
|
||||||
|
|
||||||
VL::SplitFileOptions opts;
|
VL::RotatingFileOptions opts;
|
||||||
opts.combined = true;
|
opts.max_bytes = static_cast<std::size_t>(config.maxFileSizeBytes);
|
||||||
opts.max_bytes = 10 * 1024 * 1024;
|
opts.max_files = config.maxFiles;
|
||||||
opts.max_files = 5;
|
const auto logPath = logDirectory / config.fileName;
|
||||||
if (auto fileSink = VL::SplitFileLogger::open(logDirectory, opts)) {
|
if (auto rotationError =
|
||||||
|
rotateLogOnStartup(logPath, config.maxFiles)) {
|
||||||
|
std::cerr << "Echoion: cannot rotate startup log '" << logPath
|
||||||
|
<< "': " << rotationError.message() << '\n';
|
||||||
|
} else if (auto fileSink =
|
||||||
|
VL::RotatingFileLogger::open(logPath, opts)) {
|
||||||
(*fileSink)->set_formatter(formatter);
|
(*fileSink)->set_formatter(formatter);
|
||||||
multi->add(std::shared_ptr<VL::Logger>(std::move(*fileSink)));
|
multi->add(std::shared_ptr<VL::Logger>(std::move(*fileSink)));
|
||||||
}
|
}
|
||||||
return multi;
|
return multi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] Void::Log::Level logLevel(std::string_view level)
|
||||||
|
{
|
||||||
|
if (level == "trace") {
|
||||||
|
return Void::Log::Level::Trace;
|
||||||
|
}
|
||||||
|
if (level == "info") {
|
||||||
|
return Void::Log::Level::Info;
|
||||||
|
}
|
||||||
|
if (level == "warning" || level == "warn") {
|
||||||
|
return Void::Log::Level::Warning;
|
||||||
|
}
|
||||||
|
if (level == "error") {
|
||||||
|
return Void::Log::Level::Error;
|
||||||
|
}
|
||||||
|
if (level == "critical" || level == "fatal") {
|
||||||
|
return Void::Log::Level::Fatal;
|
||||||
|
}
|
||||||
|
return Void::Log::Level::Debug;
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace Echoion::Core
|
} // namespace Echoion::Core
|
||||||
|
|
||||||
@@ -134,11 +161,12 @@ namespace Echoion::Core
|
|||||||
|
|
||||||
Core::Core() = default;
|
Core::Core() = default;
|
||||||
|
|
||||||
void Core::installLogging(const std::filesystem::path& logDirectory)
|
void Core::installLogging(const std::filesystem::path& logDirectory,
|
||||||
|
const Api::LoggingConfig& config)
|
||||||
{
|
{
|
||||||
logSink_ = buildLogSink(logDirectory);
|
logSink_ = buildLogSink(logDirectory, config);
|
||||||
Void::Log::set_sink(Void::Log::make_sink(logSink_));
|
Void::Log::set_sink(Void::Log::make_sink(logSink_));
|
||||||
Void::Log::set_min_level(Void::Log::Level::Debug);
|
Void::Log::set_min_level(logLevel(config.level));
|
||||||
}
|
}
|
||||||
|
|
||||||
Api::Result<void> Core::requireInitialized() const noexcept
|
Api::Result<void> Core::requireInitialized() const noexcept
|
||||||
@@ -173,13 +201,6 @@ namespace Echoion::Core
|
|||||||
const auto stateDir = stateDirectory(configPath);
|
const auto stateDir = stateDirectory(configPath);
|
||||||
std::error_code stateDirectoryError;
|
std::error_code stateDirectoryError;
|
||||||
std::filesystem::create_directories(stateDir, stateDirectoryError);
|
std::filesystem::create_directories(stateDir, stateDirectoryError);
|
||||||
installLogging(stateDir / "logs");
|
|
||||||
if (stateDirectoryError) {
|
|
||||||
Void::Log::warn(
|
|
||||||
"Core", "{}",
|
|
||||||
std::format("Failed to create state directory '{}': {}",
|
|
||||||
stateDir.string(), stateDirectoryError.message()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load config from file (Core-internal, Plugin doesn't need to know
|
// Load config from file (Core-internal, Plugin doesn't need to know
|
||||||
// about AppConfig structure)
|
// about AppConfig structure)
|
||||||
@@ -201,6 +222,13 @@ namespace Echoion::Core
|
|||||||
} else {
|
} else {
|
||||||
config_ = *configResult;
|
config_ = *configResult;
|
||||||
}
|
}
|
||||||
|
installLogging(stateDir / "logs", config_.logging);
|
||||||
|
if (stateDirectoryError) {
|
||||||
|
Void::Log::warn(
|
||||||
|
"Core", "{}",
|
||||||
|
std::format("Failed to create state directory '{}': {}",
|
||||||
|
stateDir.string(), stateDirectoryError.message()));
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize global ConfigManager with loaded config
|
// Initialize global ConfigManager with loaded config
|
||||||
configManager_.updateConfig(config_, false);
|
configManager_.updateConfig(config_, false);
|
||||||
@@ -469,6 +497,7 @@ namespace Echoion::Core
|
|||||||
extensionPlugins_->loadDirectory(stateDir / "plugins");
|
extensionPlugins_->loadDirectory(stateDir / "plugins");
|
||||||
extensionPlugins_->loadManagedDirectory(stateDir / "plugins" /
|
extensionPlugins_->loadManagedDirectory(stateDir / "plugins" /
|
||||||
".managed");
|
".managed");
|
||||||
|
(void)extensionPlugins_->finalizeLoading();
|
||||||
applyUrlShorteningConfig();
|
applyUrlShorteningConfig();
|
||||||
|
|
||||||
#ifdef ECHOION_WITH_WEB
|
#ifdef ECHOION_WITH_WEB
|
||||||
@@ -1855,7 +1884,7 @@ namespace Echoion::Core
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Core::getVersion() const { return Api::VERSION_STRING; }
|
std::string Core::getVersion() const { return ECHOION_CORE_VERSION; }
|
||||||
|
|
||||||
std::chrono::system_clock::time_point Core::getUptime() const
|
std::chrono::system_clock::time_point Core::getUptime() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -159,6 +159,14 @@ namespace Echoion::Core
|
|||||||
"updates.rollback");
|
"updates.rollback");
|
||||||
registerUpdateHandler(Api::RpcMethod::ConfirmUnsignedUpdate,
|
registerUpdateHandler(Api::RpcMethod::ConfirmUnsignedUpdate,
|
||||||
"updates.confirmUnsigned");
|
"updates.confirmUnsigned");
|
||||||
|
registerUpdateHandler(Api::RpcMethod::PreviewUpdateTransaction,
|
||||||
|
"updates.preview");
|
||||||
|
registerUpdateHandler(Api::RpcMethod::ApplyUpdateTransaction,
|
||||||
|
"updates.applyTransaction");
|
||||||
|
registerUpdateHandler(Api::RpcMethod::RollbackUpdateGeneration,
|
||||||
|
"updates.rollbackGeneration");
|
||||||
|
registerUpdateHandler(Api::RpcMethod::GetUpdateHistory,
|
||||||
|
"updates.history");
|
||||||
// Authentication - expects JSON with either "nickname" (for initial
|
// Authentication - expects JSON with either "nickname" (for initial
|
||||||
// request) or "token" (for validation). The same handler backs
|
// request) or "token" (for validation). The same handler backs
|
||||||
// Authenticate, RequestLoginToken and ValidateLoginToken.
|
// Authenticate, RequestLoginToken and ValidateLoginToken.
|
||||||
|
|||||||
+1
-1
@@ -115,7 +115,7 @@ extern "C"
|
|||||||
return Void::Plugin::PluginInfo{
|
return Void::Plugin::PluginInfo{
|
||||||
.abi_version = Void::Plugin::ABI_VERSION,
|
.abi_version = Void::Plugin::ABI_VERSION,
|
||||||
.name = "Echoion",
|
.name = "Echoion",
|
||||||
.plugin_version = Echoion::Api::VERSION_STRING,
|
.plugin_version = ECHOION_CORE_VERSION,
|
||||||
.description = "Echoion TeamSpeak music bot core"};
|
.description = "Echoion TeamSpeak music bot core"};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,142 @@
|
|||||||
|
#include "echoion/core/LogRotation.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <chrono>
|
||||||
|
#include <ctime>
|
||||||
|
#include <format>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Echoion::Core
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
[[nodiscard]] std::string archiveTimestamp()
|
||||||
|
{
|
||||||
|
using namespace std::chrono;
|
||||||
|
const auto now = system_clock::now();
|
||||||
|
const auto secondsPart = floor<seconds>(now);
|
||||||
|
const auto micros = duration_cast<microseconds>(now - secondsPart);
|
||||||
|
const std::time_t raw = system_clock::to_time_t(now);
|
||||||
|
std::tm utc{};
|
||||||
|
#ifdef _WIN32
|
||||||
|
gmtime_s(&utc, &raw);
|
||||||
|
#else
|
||||||
|
gmtime_r(&raw, &utc);
|
||||||
|
#endif
|
||||||
|
return std::format("{:04}{:02}{:02}-{:02}{:02}{:02}-{:06}",
|
||||||
|
utc.tm_year + 1900, utc.tm_mon + 1, utc.tm_mday,
|
||||||
|
utc.tm_hour, utc.tm_min, utc.tm_sec,
|
||||||
|
micros.count());
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool isArchiveFor(const std::filesystem::path& path,
|
||||||
|
const std::filesystem::path& active)
|
||||||
|
{
|
||||||
|
const auto name = path.filename().string();
|
||||||
|
const auto prefix = active.stem().string() + "-";
|
||||||
|
return name.starts_with(prefix) &&
|
||||||
|
path.extension() == active.extension();
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
std::error_code rotateLogOnStartup(const std::filesystem::path& activeLog,
|
||||||
|
std::size_t maxFiles) noexcept
|
||||||
|
{
|
||||||
|
std::error_code error;
|
||||||
|
const auto status = std::filesystem::symlink_status(activeLog, error);
|
||||||
|
if (error && error != std::errc::no_such_file_or_directory) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
error.clear();
|
||||||
|
|
||||||
|
const bool exists = std::filesystem::exists(status);
|
||||||
|
if (exists && std::filesystem::is_symlink(status)) {
|
||||||
|
return std::make_error_code(
|
||||||
|
std::errc::too_many_symbolic_link_levels);
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto history = activeLog.parent_path() / "history";
|
||||||
|
std::filesystem::create_directories(activeLog.parent_path(), error);
|
||||||
|
if (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exists) {
|
||||||
|
if (!std::filesystem::is_regular_file(status)) {
|
||||||
|
return std::make_error_code(std::errc::invalid_argument);
|
||||||
|
}
|
||||||
|
const auto size = std::filesystem::file_size(activeLog, error);
|
||||||
|
if (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
if (size == 0 || maxFiles == 0) {
|
||||||
|
std::filesystem::remove(activeLog, error);
|
||||||
|
if (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::filesystem::create_directories(history, error);
|
||||||
|
if (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
const auto timestamp = archiveTimestamp();
|
||||||
|
auto archived = history / (activeLog.stem().string() + "-" +
|
||||||
|
timestamp +
|
||||||
|
activeLog.extension().string());
|
||||||
|
for (std::size_t suffix = 1;
|
||||||
|
std::filesystem::exists(archived, error) && !error;
|
||||||
|
++suffix) {
|
||||||
|
archived = history / (activeLog.stem().string() + "-" +
|
||||||
|
timestamp + "-" +
|
||||||
|
std::to_string(suffix) +
|
||||||
|
activeLog.extension().string());
|
||||||
|
}
|
||||||
|
if (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
std::filesystem::rename(activeLog, archived, error);
|
||||||
|
if (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto historyStatus =
|
||||||
|
std::filesystem::symlink_status(history, error);
|
||||||
|
if (error == std::errc::no_such_file_or_directory ||
|
||||||
|
historyStatus.type() == std::filesystem::file_type::not_found) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
if (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
if (!std::filesystem::is_directory(historyStatus) ||
|
||||||
|
std::filesystem::is_symlink(historyStatus)) {
|
||||||
|
return std::make_error_code(std::errc::invalid_argument);
|
||||||
|
}
|
||||||
|
std::vector<std::filesystem::path> archives;
|
||||||
|
for (std::filesystem::directory_iterator iterator(history, error), end;
|
||||||
|
!error && iterator != end; iterator.increment(error)) {
|
||||||
|
const auto entryStatus = iterator->symlink_status(error);
|
||||||
|
if (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
if (std::filesystem::is_regular_file(entryStatus) &&
|
||||||
|
isArchiveFor(iterator->path(), activeLog)) {
|
||||||
|
archives.push_back(iterator->path());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
std::ranges::sort(archives);
|
||||||
|
while (archives.size() > maxFiles) {
|
||||||
|
std::filesystem::remove(archives.front(), error);
|
||||||
|
if (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
archives.erase(archives.begin());
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
} // namespace Echoion::Core
|
||||||
+104
@@ -0,0 +1,104 @@
|
|||||||
|
#include <echoion/api/module/LegacyModuleAbi.hpp>
|
||||||
|
|
||||||
|
#include "ModuleContracts.hpp"
|
||||||
|
|
||||||
|
#include <iterator>
|
||||||
|
#include <memory>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
namespace Echoion::CoreModule
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
class LifecycleModule final : public Void::Plugin::IModule
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
[[nodiscard]] std::string_view name() const noexcept override
|
||||||
|
{
|
||||||
|
return "EchoionCore";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
std::unique_ptr<Void::Plugin::IModule> createCoreModule()
|
||||||
|
{
|
||||||
|
return std::make_unique<LifecycleModule>();
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
const Void::Plugin::ModuleDescriptor& coreModuleDescriptor()
|
||||||
|
{
|
||||||
|
static const Void::Plugin::ModuleDescriptor descriptor{
|
||||||
|
.module_id = "EchoionCore",
|
||||||
|
.component_version =
|
||||||
|
{
|
||||||
|
.major = ECHOION_COMPONENT_VERSION_MAJOR,
|
||||||
|
.minor = ECHOION_COMPONENT_VERSION_MINOR,
|
||||||
|
.patch = ECHOION_COMPONENT_VERSION_PATCH,
|
||||||
|
.pre_release = {},
|
||||||
|
.build = {},
|
||||||
|
},
|
||||||
|
.abi_hash = coreAbiHash,
|
||||||
|
.abi_contract = Void::Json::object({
|
||||||
|
{"schemaVersion", 1},
|
||||||
|
{"contractId", "echoion.module.core"},
|
||||||
|
{"descriptor", "echoion_module_descriptor_v1"},
|
||||||
|
}),
|
||||||
|
.dependencies =
|
||||||
|
{
|
||||||
|
{
|
||||||
|
.module_id = "EchoionApi",
|
||||||
|
.version_range = "^2.0.0",
|
||||||
|
.abi_hash = apiAbiHash,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
.activation_policy = Void::Plugin::ActivationPolicy::Reloadable,
|
||||||
|
.create = createCoreModule,
|
||||||
|
};
|
||||||
|
return descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
const echoion_module_descriptor_v1& coreModuleAbiDescriptor()
|
||||||
|
{
|
||||||
|
using Bridge = Api::Module::LegacyModuleAbi<createCoreModule>;
|
||||||
|
static const echoion_module_dependency_v1 dependencies[]{
|
||||||
|
{
|
||||||
|
.struct_size = sizeof(echoion_module_dependency_v1),
|
||||||
|
.component_id = Api::Module::Detail::stringView("EchoionApi"),
|
||||||
|
.version_range =
|
||||||
|
Api::Module::Detail::stringView(">=2.0.0 <3.0.0"),
|
||||||
|
.abi_hash = Api::Module::Detail::stringView(apiAbiHash),
|
||||||
|
.optional = 0,
|
||||||
|
.reserved_bytes = {},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
static const echoion_module_descriptor_v1 descriptor{
|
||||||
|
.struct_size = sizeof(echoion_module_descriptor_v1),
|
||||||
|
.abi_version = ECHOION_MODULE_ABI_VERSION,
|
||||||
|
.component_id = Api::Module::Detail::stringView("EchoionCore"),
|
||||||
|
.version_major = ECHOION_COMPONENT_VERSION_MAJOR,
|
||||||
|
.version_minor = ECHOION_COMPONENT_VERSION_MINOR,
|
||||||
|
.version_patch = ECHOION_COMPONENT_VERSION_PATCH,
|
||||||
|
.version_prerelease = {},
|
||||||
|
.abi_hash = Api::Module::Detail::stringView(coreAbiHash),
|
||||||
|
.dependencies = dependencies,
|
||||||
|
.dependency_count = std::size(dependencies),
|
||||||
|
.activation_policy = ECHOION_ACTIVATION_RELOADABLE_V1,
|
||||||
|
.api = &Bridge::api,
|
||||||
|
.reserved = {},
|
||||||
|
};
|
||||||
|
return descriptor;
|
||||||
|
}
|
||||||
|
} // namespace Echoion::CoreModule
|
||||||
|
|
||||||
|
extern "C" ECHOION_MODULE_EXPORT const Void::Plugin::ModuleDescriptor*
|
||||||
|
echoion_module_query()
|
||||||
|
{
|
||||||
|
return &Echoion::CoreModule::coreModuleDescriptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
extern "C" ECHOION_MODULE_ABI_EXPORT const echoion_module_descriptor_v1*
|
||||||
|
echoion_module_abi_query()
|
||||||
|
{
|
||||||
|
return &Echoion::CoreModule::coreModuleAbiDescriptor();
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace Echoion::CoreModule
|
||||||
|
{
|
||||||
|
inline constexpr auto apiAbiHash =
|
||||||
|
"sha256:"
|
||||||
|
"d50293d345a97e52f9844088bdd42277f566bc815a21b7636d3e053f06c6c113";
|
||||||
|
inline constexpr auto coreAbiHash =
|
||||||
|
"sha256:"
|
||||||
|
"9cb668e2a502dcfe02d145ed63635d63619732d77ff5749685834382705e8d21";
|
||||||
|
} // namespace Echoion::CoreModule
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
#include "PluginCompatibility.hpp"
|
||||||
|
|
||||||
|
#include "ModuleContracts.hpp"
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <exception>
|
||||||
|
#include <string_view>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
namespace Echoion::Core::Detail
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
constexpr std::size_t maximumDescriptorText = 1024;
|
||||||
|
constexpr std::size_t maximumDependencies = 64;
|
||||||
|
|
||||||
|
[[nodiscard]] PluginCompatibility reject(std::string reason)
|
||||||
|
{
|
||||||
|
return {.compatible = false, .reason = std::move(reason)};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool valid(const echoion_string_view_v1 value) noexcept
|
||||||
|
{
|
||||||
|
return value.size <= maximumDescriptorText &&
|
||||||
|
(value.size == 0U || value.data != nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] std::string_view
|
||||||
|
view(const echoion_string_view_v1 value) noexcept
|
||||||
|
{
|
||||||
|
return value.data == nullptr
|
||||||
|
? std::string_view{}
|
||||||
|
: std::string_view{value.data, value.size};
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
PluginCompatibility
|
||||||
|
checkExtensionDescriptor(const echoion_module_descriptor_v1* descriptor)
|
||||||
|
{
|
||||||
|
if (descriptor == nullptr) {
|
||||||
|
return reject("stable module descriptor is null");
|
||||||
|
}
|
||||||
|
if (descriptor->struct_size < sizeof(echoion_module_descriptor_v1) ||
|
||||||
|
descriptor->abi_version != ECHOION_MODULE_ABI_VERSION) {
|
||||||
|
return reject("stable module descriptor version is incompatible");
|
||||||
|
}
|
||||||
|
if (!valid(descriptor->component_id) ||
|
||||||
|
view(descriptor->component_id).empty() ||
|
||||||
|
descriptor->version_major != ECHOION_COMPONENT_VERSION_MAJOR) {
|
||||||
|
return reject(
|
||||||
|
"component identity or major version is incompatible");
|
||||||
|
}
|
||||||
|
if (descriptor->api == nullptr ||
|
||||||
|
descriptor->api->struct_size < sizeof(echoion_module_api_v1) ||
|
||||||
|
descriptor->api->abi_version != ECHOION_MODULE_ABI_VERSION ||
|
||||||
|
descriptor->api->create == nullptr ||
|
||||||
|
descriptor->api->destroy == nullptr ||
|
||||||
|
descriptor->api->activate == nullptr ||
|
||||||
|
descriptor->api->quiesce == nullptr ||
|
||||||
|
descriptor->api->checkpoint == nullptr ||
|
||||||
|
descriptor->api->restore == nullptr ||
|
||||||
|
descriptor->api->readiness == nullptr ||
|
||||||
|
descriptor->api->deactivate == nullptr) {
|
||||||
|
return reject("stable module function table is incomplete");
|
||||||
|
}
|
||||||
|
if (descriptor->dependency_count > maximumDependencies ||
|
||||||
|
(descriptor->dependency_count != 0U &&
|
||||||
|
descriptor->dependencies == nullptr)) {
|
||||||
|
return reject("stable module dependency table is invalid");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool apiCompatible = false;
|
||||||
|
bool coreCompatible = false;
|
||||||
|
for (std::size_t index = 0; index < descriptor->dependency_count;
|
||||||
|
++index) {
|
||||||
|
const auto& dependency = descriptor->dependencies[index];
|
||||||
|
if (dependency.struct_size < sizeof(echoion_module_dependency_v1) ||
|
||||||
|
!valid(dependency.component_id) ||
|
||||||
|
!valid(dependency.abi_hash)) {
|
||||||
|
return reject("stable module dependency entry is invalid");
|
||||||
|
}
|
||||||
|
const auto component = view(dependency.component_id);
|
||||||
|
const auto abiHash = view(dependency.abi_hash);
|
||||||
|
if (component == "EchoionApi" && dependency.optional == 0U) {
|
||||||
|
apiCompatible = abiHash == CoreModule::apiAbiHash;
|
||||||
|
}
|
||||||
|
if (component == "EchoionCore" && dependency.optional == 0U) {
|
||||||
|
coreCompatible = abiHash == CoreModule::coreAbiHash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!apiCompatible || !coreCompatible) {
|
||||||
|
return reject("plugin was built for incompatible Echoion APIs");
|
||||||
|
}
|
||||||
|
return {.compatible = true, .reason = {}};
|
||||||
|
}
|
||||||
|
|
||||||
|
PluginCompatibility
|
||||||
|
checkExtensionCandidate(const Void::Plugin::PluginHandle& candidate)
|
||||||
|
{
|
||||||
|
const auto symbol =
|
||||||
|
candidate.raw_symbol(ECHOION_MODULE_ABI_QUERY_SYMBOL);
|
||||||
|
if (symbol == nullptr) {
|
||||||
|
return reject("stable module query symbol is missing");
|
||||||
|
}
|
||||||
|
const auto query =
|
||||||
|
reinterpret_cast<echoion_module_abi_query_fn_v1>(symbol);
|
||||||
|
try {
|
||||||
|
return checkExtensionDescriptor(query());
|
||||||
|
} catch (const std::exception& error) {
|
||||||
|
return reject(std::string{"stable module query threw: "} +
|
||||||
|
error.what());
|
||||||
|
} catch (...) {
|
||||||
|
return reject("stable module query threw");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace Echoion::Core::Detail
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <echoion/api/module/ModuleAbi.h>
|
||||||
|
|
||||||
|
#include <Void/Plugin/Manager.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Echoion::Core::Detail
|
||||||
|
{
|
||||||
|
struct PluginCompatibility {
|
||||||
|
bool compatible{};
|
||||||
|
std::string reason;
|
||||||
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] PluginCompatibility checkExtensionDescriptor(
|
||||||
|
const echoion_module_descriptor_v1* descriptor);
|
||||||
|
[[nodiscard]] PluginCompatibility
|
||||||
|
checkExtensionCandidate(const Void::Plugin::PluginHandle& candidate);
|
||||||
|
} // namespace Echoion::Core::Detail
|
||||||
+28
-12
@@ -4,6 +4,8 @@
|
|||||||
#include "echoion/core/MusicManager.hpp"
|
#include "echoion/core/MusicManager.hpp"
|
||||||
#include "echoion/core/sources/TrackSource.hpp"
|
#include "echoion/core/sources/TrackSource.hpp"
|
||||||
|
|
||||||
|
#include "PluginCompatibility.hpp"
|
||||||
|
|
||||||
#include <Void/Data/Json.hpp>
|
#include <Void/Data/Json.hpp>
|
||||||
#include <Void/Log/Log.hpp>
|
#include <Void/Log/Log.hpp>
|
||||||
#include <Void/Plugin/Loader.hpp>
|
#include <Void/Plugin/Loader.hpp>
|
||||||
@@ -282,11 +284,22 @@ namespace Echoion::Core
|
|||||||
const Void::Plugin::PluginInfo&) {
|
const Void::Plugin::PluginInfo&) {
|
||||||
return dynamic_cast<Api::IExtensionPlugin*>(&plugin) !=
|
return dynamic_cast<Api::IExtensionPlugin*>(&plugin) !=
|
||||||
nullptr;
|
nullptr;
|
||||||
|
},
|
||||||
|
.candidate_validator =
|
||||||
|
[](const Void::Plugin::PluginHandle& candidate) {
|
||||||
|
const auto compatibility =
|
||||||
|
Detail::checkExtensionCandidate(candidate);
|
||||||
|
if (!compatibility.compatible) {
|
||||||
|
Void::Log::warn(
|
||||||
|
"PluginHost", "Plugin '{}' rejected: {}",
|
||||||
|
candidate.info().name, compatibility.reason);
|
||||||
|
}
|
||||||
|
return compatibility.compatible;
|
||||||
}}),
|
}}),
|
||||||
configuration_(std::move(configuration))
|
configuration_(std::move(configuration))
|
||||||
{
|
{
|
||||||
reloadCallback_ = plugins_.on_reloaded(
|
reloadCallback_ = plugins_.on_reloaded(
|
||||||
[this](std::string_view name) { publish(name); });
|
[this](std::string_view name) { publish(std::string{name}); });
|
||||||
}
|
}
|
||||||
|
|
||||||
PluginHost::~PluginHost()
|
PluginHost::~PluginHost()
|
||||||
@@ -317,11 +330,6 @@ namespace Echoion::Core
|
|||||||
publish(*result);
|
publish(*result);
|
||||||
plugins_.watch(*result);
|
plugins_.watch(*result);
|
||||||
}
|
}
|
||||||
if (!bindShortenerServices()) {
|
|
||||||
Void::Log::warn("PluginHost",
|
|
||||||
"Loaded plugins do not provide the configured "
|
|
||||||
"short URL service");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -378,11 +386,18 @@ namespace Echoion::Core
|
|||||||
publish(id);
|
publish(id);
|
||||||
plugins_.watch(id);
|
plugins_.watch(id);
|
||||||
}
|
}
|
||||||
if (!bindShortenerServices()) {
|
}
|
||||||
Void::Log::warn("PluginHost",
|
|
||||||
"Managed plugins do not provide the configured "
|
bool PluginHost::finalizeLoading()
|
||||||
"short URL service");
|
{
|
||||||
|
std::scoped_lock operationLock{reconfigureMutex_};
|
||||||
|
if (bindShortenerServices()) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
Void::Log::warn("PluginHost",
|
||||||
|
"Loaded plugins do not provide the configured short "
|
||||||
|
"URL service");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string PluginHost::pluginConfiguration(std::string_view name) const
|
std::string PluginHost::pluginConfiguration(std::string_view name) const
|
||||||
@@ -948,8 +963,9 @@ namespace Echoion::Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginHost::publish(std::string_view name)
|
void PluginHost::publish(std::string name)
|
||||||
{
|
{
|
||||||
|
Void::Log::info("PluginHost", "Publishing Echoion plugin '{}'", name);
|
||||||
unpublish(name);
|
unpublish(name);
|
||||||
auto pin = plugins_.acquire(name);
|
auto pin = plugins_.acquire(name);
|
||||||
auto* extension =
|
auto* extension =
|
||||||
@@ -1004,7 +1020,7 @@ namespace Echoion::Core
|
|||||||
notifyChanged();
|
notifyChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PluginHost::unpublish(std::string_view name)
|
void PluginHost::unpublish(std::string name)
|
||||||
{
|
{
|
||||||
commands_.unregisterExternalCommands(name);
|
commands_.unregisterExternalCommands(name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,33 @@ int main()
|
|||||||
const auto defaults = ConfigLoader::createDefaultConfig();
|
const auto defaults = ConfigLoader::createDefaultConfig();
|
||||||
expect(!defaults.urlShortening.enabled,
|
expect(!defaults.urlShortening.enabled,
|
||||||
"generated defaults keep URL shortening disabled");
|
"generated defaults keep URL shortening disabled");
|
||||||
|
expect(defaults.logging.fileName == "echoion.log" &&
|
||||||
|
defaults.logging.maxFiles == 10,
|
||||||
|
"generated defaults configure bounded rolling logs");
|
||||||
|
|
||||||
|
const auto logging = ConfigLoader::loadFromJson(R"({
|
||||||
|
"logging": {
|
||||||
|
"level": "verbose",
|
||||||
|
"fileName": "../outside.log",
|
||||||
|
"maxFileSizeBytes": 1,
|
||||||
|
"maxFiles": 0
|
||||||
|
}
|
||||||
|
})");
|
||||||
|
expect(logging.has_value(), "logging configuration parses");
|
||||||
|
if (logging) {
|
||||||
|
expect(logging->logging.level == "debug",
|
||||||
|
"invalid log level is normalized");
|
||||||
|
expect(logging->logging.fileName == "echoion.log",
|
||||||
|
"log file cannot escape the state log directory");
|
||||||
|
expect(logging->logging.maxFileSizeBytes == 64 * 1024,
|
||||||
|
"log size is clamped to a safe minimum");
|
||||||
|
expect(logging->logging.maxFiles == 1,
|
||||||
|
"at least one rolled log is retained");
|
||||||
|
}
|
||||||
|
const auto parentLog =
|
||||||
|
ConfigLoader::loadFromJson(R"({"logging":{"fileName":".."}})");
|
||||||
|
expect(parentLog && parentLog->logging.fileName == "echoion.log",
|
||||||
|
"parent-directory logging filename is normalized");
|
||||||
|
|
||||||
expectShortening("legacy disabled",
|
expectShortening("legacy disabled",
|
||||||
R"({
|
R"({
|
||||||
|
|||||||
@@ -0,0 +1,82 @@
|
|||||||
|
#include "echoion/core/LogRotation.hpp"
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
int failures = 0;
|
||||||
|
|
||||||
|
void expect(bool condition, std::string_view message)
|
||||||
|
{
|
||||||
|
if (!condition) {
|
||||||
|
std::cerr << "FAILED: " << message << '\n';
|
||||||
|
++failures;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t archiveCount(const std::filesystem::path& history)
|
||||||
|
{
|
||||||
|
std::size_t count = 0;
|
||||||
|
std::error_code error;
|
||||||
|
for (std::filesystem::directory_iterator iterator(history, error), end;
|
||||||
|
!error && iterator != end; iterator.increment(error)) {
|
||||||
|
if (iterator->is_regular_file()) {
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
const auto root =
|
||||||
|
std::filesystem::temp_directory_path() / "echoion-log-rotation-test";
|
||||||
|
std::error_code error;
|
||||||
|
std::filesystem::remove_all(root, error);
|
||||||
|
std::filesystem::create_directories(root, error);
|
||||||
|
const auto active = root / "echoion.log";
|
||||||
|
|
||||||
|
{
|
||||||
|
std::ofstream file(active);
|
||||||
|
file << "first run\n";
|
||||||
|
}
|
||||||
|
error = Echoion::Core::rotateLogOnStartup(active, 2);
|
||||||
|
expect(!error, "first startup rotation succeeds");
|
||||||
|
expect(!std::filesystem::exists(active),
|
||||||
|
"startup rotation leaves no old active file");
|
||||||
|
expect(archiveCount(root / "history") == 1, "first run is archived");
|
||||||
|
|
||||||
|
for (int run = 0; run < 3; ++run) {
|
||||||
|
{
|
||||||
|
std::ofstream file(active);
|
||||||
|
file << "run " << run << '\n';
|
||||||
|
}
|
||||||
|
error = Echoion::Core::rotateLogOnStartup(active, 2);
|
||||||
|
expect(!error, "subsequent startup rotation succeeds");
|
||||||
|
}
|
||||||
|
expect(archiveCount(root / "history") == 2,
|
||||||
|
"startup rotation prunes to configured history count");
|
||||||
|
|
||||||
|
{
|
||||||
|
std::ofstream file(active);
|
||||||
|
}
|
||||||
|
error = Echoion::Core::rotateLogOnStartup(active, 2);
|
||||||
|
expect(!error && !std::filesystem::exists(active),
|
||||||
|
"empty active file is removed instead of archived");
|
||||||
|
|
||||||
|
std::filesystem::remove_all(root / "history", error);
|
||||||
|
{
|
||||||
|
std::ofstream invalidHistory(root / "history");
|
||||||
|
invalidHistory << "not a directory\n";
|
||||||
|
}
|
||||||
|
error = Echoion::Core::rotateLogOnStartup(active, 2);
|
||||||
|
expect(error == std::errc::invalid_argument,
|
||||||
|
"non-directory history path was accepted");
|
||||||
|
|
||||||
|
std::filesystem::remove_all(root, error);
|
||||||
|
return failures == 0 ? 0 : 1;
|
||||||
|
}
|
||||||
@@ -0,0 +1,141 @@
|
|||||||
|
#include "PluginCompatibility.hpp"
|
||||||
|
|
||||||
|
#include <Void/Testing/Assert.hpp>
|
||||||
|
#include <Void/Testing/Runner.hpp>
|
||||||
|
#include <Void/Testing/Test.hpp>
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
echoion_string_view_v1 view(const std::string_view value)
|
||||||
|
{
|
||||||
|
return {.data = value.data(), .size = value.size()};
|
||||||
|
}
|
||||||
|
|
||||||
|
echoion_status_v1 create(const echoion_module_host_v1*,
|
||||||
|
echoion_module_instance_v1*)
|
||||||
|
{
|
||||||
|
return ECHOION_STATUS_OK_V1;
|
||||||
|
}
|
||||||
|
void destroy(echoion_module_instance_v1) {}
|
||||||
|
echoion_status_v1 activate(echoion_module_instance_v1)
|
||||||
|
{
|
||||||
|
return ECHOION_STATUS_OK_V1;
|
||||||
|
}
|
||||||
|
echoion_status_v1 quiesce(echoion_module_instance_v1, std::int64_t)
|
||||||
|
{
|
||||||
|
return ECHOION_STATUS_OK_V1;
|
||||||
|
}
|
||||||
|
echoion_status_v1 checkpoint(echoion_module_instance_v1,
|
||||||
|
echoion_write_bytes_fn_v1, void*)
|
||||||
|
{
|
||||||
|
return ECHOION_STATUS_OK_V1;
|
||||||
|
}
|
||||||
|
echoion_status_v1 restore(echoion_module_instance_v1, echoion_bytes_view_v1)
|
||||||
|
{
|
||||||
|
return ECHOION_STATUS_OK_V1;
|
||||||
|
}
|
||||||
|
echoion_status_v1 readiness(echoion_module_instance_v1,
|
||||||
|
echoion_module_readiness_v1*)
|
||||||
|
{
|
||||||
|
return ECHOION_STATUS_OK_V1;
|
||||||
|
}
|
||||||
|
echoion_status_v1 deactivate(echoion_module_instance_v1)
|
||||||
|
{
|
||||||
|
return ECHOION_STATUS_OK_V1;
|
||||||
|
}
|
||||||
|
|
||||||
|
const echoion_module_api_v1 api{
|
||||||
|
.struct_size = sizeof(echoion_module_api_v1),
|
||||||
|
.abi_version = ECHOION_MODULE_ABI_VERSION,
|
||||||
|
.create = create,
|
||||||
|
.destroy = destroy,
|
||||||
|
.activate = activate,
|
||||||
|
.quiesce = quiesce,
|
||||||
|
.checkpoint = checkpoint,
|
||||||
|
.restore = restore,
|
||||||
|
.readiness = readiness,
|
||||||
|
.deactivate = deactivate,
|
||||||
|
.reserved = {},
|
||||||
|
};
|
||||||
|
|
||||||
|
std::array<echoion_module_dependency_v1, 2>
|
||||||
|
dependencies(const std::string_view apiHash,
|
||||||
|
const std::string_view coreHash)
|
||||||
|
{
|
||||||
|
return {{
|
||||||
|
{
|
||||||
|
.struct_size = sizeof(echoion_module_dependency_v1),
|
||||||
|
.component_id = view("EchoionApi"),
|
||||||
|
.version_range = view(">=2.0.0 <3.0.0"),
|
||||||
|
.abi_hash = view(apiHash),
|
||||||
|
.optional = 0,
|
||||||
|
.reserved_bytes = {},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
.struct_size = sizeof(echoion_module_dependency_v1),
|
||||||
|
.component_id = view("EchoionCore"),
|
||||||
|
.version_range = view(">=2.0.0 <3.0.0"),
|
||||||
|
.abi_hash = view(coreHash),
|
||||||
|
.optional = 0,
|
||||||
|
.reserved_bytes = {},
|
||||||
|
},
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
echoion_module_descriptor_v1
|
||||||
|
descriptor(const std::array<echoion_module_dependency_v1, 2>& values)
|
||||||
|
{
|
||||||
|
return {
|
||||||
|
.struct_size = sizeof(echoion_module_descriptor_v1),
|
||||||
|
.abi_version = ECHOION_MODULE_ABI_VERSION,
|
||||||
|
.component_id = view("EchoionPluginExample"),
|
||||||
|
.version_major = 2,
|
||||||
|
.version_minor = 0,
|
||||||
|
.version_patch = 0,
|
||||||
|
.version_prerelease = {},
|
||||||
|
.abi_hash = view("sha256:example"),
|
||||||
|
.dependencies = values.data(),
|
||||||
|
.dependency_count = values.size(),
|
||||||
|
.activation_policy = ECHOION_ACTIVATION_RELOADABLE_V1,
|
||||||
|
.api = &api,
|
||||||
|
.reserved = {},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
Void::Testing::Test compatible_v2_extension_descriptor_is_accepted()
|
||||||
|
{
|
||||||
|
const auto values = dependencies(
|
||||||
|
"sha256:"
|
||||||
|
"d50293d345a97e52f9844088bdd42277f566bc815a21b7636d3e053f06c6c113",
|
||||||
|
"sha256:"
|
||||||
|
"9cb668e2a502dcfe02d145ed63635d63619732d77ff5749685834382705e8d21");
|
||||||
|
const auto candidate = descriptor(values);
|
||||||
|
const auto result =
|
||||||
|
Echoion::Core::Detail::checkExtensionDescriptor(&candidate);
|
||||||
|
Void::Testing::expect(result.compatible);
|
||||||
|
}
|
||||||
|
|
||||||
|
Void::Testing::Test legacy_or_mismatched_extension_descriptor_is_rejected()
|
||||||
|
{
|
||||||
|
const auto values = dependencies("sha256:old-api", "sha256:old-core");
|
||||||
|
auto candidate = descriptor(values);
|
||||||
|
auto result = Echoion::Core::Detail::checkExtensionDescriptor(&candidate);
|
||||||
|
Void::Testing::expect(!result.compatible);
|
||||||
|
|
||||||
|
candidate.version_major = 1;
|
||||||
|
result = Echoion::Core::Detail::checkExtensionDescriptor(&candidate);
|
||||||
|
Void::Testing::expect(!result.compatible);
|
||||||
|
|
||||||
|
Void::Testing::expect(
|
||||||
|
!Echoion::Core::Detail::checkExtensionDescriptor(nullptr).compatible);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
return Void::Testing::Runner::instance().main(argc, argv);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user