Configuration is partially made.
Compilation and linker flags for spdlog are changed to be usable with clang and the project. Another default logger is made in the main.cpp Correction in README.md and format.
This commit is contained in:
parent
d113932c8f
commit
23246d0d9d
@ -6,17 +6,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
set(CMAKE_CXX_COMPILER_LAUNCHER ccache)
|
set(CMAKE_CXX_COMPILER_LAUNCHER ccache)
|
||||||
|
|
||||||
# options for spdlog
|
|
||||||
set(SPDLOG_ENABLE_PCH ON CACHE BOOL "Build static or shared library using precompiled header to speed up compilation time")
|
|
||||||
set(SPDLOG_BUILD_WARNINGS ON CACHE BOOL "Enable compiler warnings")
|
|
||||||
set(SPDLOG_FMT_EXTERNAL ON CACHE BOOL "Use external fmt library instead of bundled")
|
|
||||||
set(SPDLOG_PREVENT_CHILD_FD ON CACHE BOOL "Prevent from child processes to inherit log file descriptors")
|
|
||||||
set(SPDLOG_NO_THREAD_ID ON CACHE BOOL "prevent spdlog from querying the thread id on each log call if thread id is not needed")
|
|
||||||
set(SPDLOG_NO_TLS ON CACHE BOOL "prevent spdlog from using thread local storage")
|
|
||||||
|
|
||||||
add_subdirectory(external/spdlog)
|
|
||||||
# end
|
|
||||||
|
|
||||||
find_package(Boost REQUIRED COMPONENTS system)
|
find_package(Boost REQUIRED COMPONENTS system)
|
||||||
find_package(OpenSSL REQUIRED)
|
find_package(OpenSSL REQUIRED)
|
||||||
find_package(OpenMP REQUIRED)
|
find_package(OpenMP REQUIRED)
|
||||||
@ -42,11 +31,12 @@ set(COMPILE_FLAGS
|
|||||||
-Wmove
|
-Wmove
|
||||||
-Wopenmp
|
-Wopenmp
|
||||||
-funroll-loops
|
-funroll-loops
|
||||||
-flto=thin -fwhole-program-vtables
|
-flto=thin
|
||||||
|
-fwhole-program-vtables
|
||||||
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
|
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free
|
||||||
)
|
)
|
||||||
set(LINKER_OPTIONS
|
set(LINKER_OPTIONS
|
||||||
PRIVATE -Wl,--sort-common,--as-needed
|
-Wl,--sort-common,--as-needed
|
||||||
-stdlib=libc++
|
-stdlib=libc++
|
||||||
-flto=thin
|
-flto=thin
|
||||||
-fwhole-program-vtables
|
-fwhole-program-vtables
|
||||||
@ -70,11 +60,26 @@ set(FILES
|
|||||||
include/cache_files.hpp
|
include/cache_files.hpp
|
||||||
src/simdjson.cpp
|
src/simdjson.cpp
|
||||||
include/simdjson.h
|
include/simdjson.h
|
||||||
)
|
include/configuration.hpp src/configuration.cpp)
|
||||||
|
|
||||||
|
# options for spdlog
|
||||||
|
set(SPDLOG_ENABLE_PCH ON CACHE BOOL "Build static or shared library using precompiled header to speed up compilation time")
|
||||||
|
set(SPDLOG_BUILD_WARNINGS ON CACHE BOOL "Enable compiler warnings")
|
||||||
|
set(SPDLOG_FMT_EXTERNAL ON CACHE BOOL "Use external fmt library instead of bundled")
|
||||||
|
set(SPDLOG_PREVENT_CHILD_FD ON CACHE BOOL "Prevent from child processes to inherit log file descriptors")
|
||||||
|
set(SPDLOG_NO_THREAD_ID ON CACHE BOOL "prevent spdlog from querying the thread id on each log call if thread id is not needed")
|
||||||
|
set(SPDLOG_NO_TLS ON CACHE BOOL "prevent spdlog from using thread local storage")
|
||||||
|
set(SPDLOG_NO_ATOMIC_LEVELS ON CACHE BOOL "prevent spdlog from using of std::atomic log levels (use only if your code never modifies log levels concurrently")
|
||||||
|
|
||||||
|
add_subdirectory(external/spdlog EXCLUDE_FROM_ALL)
|
||||||
|
target_compile_definitions(spdlog PRIVATE ${COMPILE_DEFINITIONS})
|
||||||
|
target_compile_options(spdlog PRIVATE ${COMPILE_FLAGS})
|
||||||
|
target_link_options(spdlog PRIVATE ${LINKER_OPTIONS})
|
||||||
|
# end
|
||||||
|
|
||||||
add_executable(GeminiServer ${FILES})
|
add_executable(GeminiServer ${FILES})
|
||||||
target_precompile_headers(GeminiServer PRIVATE ${HEADERS})
|
target_precompile_headers(GeminiServer PRIVATE ${HEADERS})
|
||||||
target_compile_definitions(GeminiServer PRIVATE ${COMPILE_DEFINITIONS})
|
target_compile_definitions(GeminiServer PRIVATE ${COMPILE_DEFINITIONS})
|
||||||
target_compile_options(GeminiServer PRIVATE ${COMPILE_FLAGS})
|
target_compile_options(GeminiServer PRIVATE ${COMPILE_FLAGS})
|
||||||
target_link_options(GeminiServer ${LINKER_OPTIONS})
|
target_link_options(GeminiServer PRIVATE ${LINKER_OPTIONS})
|
||||||
target_link_libraries(GeminiServer ${LINKER_FLAGS} spdlog::spdlog)
|
target_link_libraries(GeminiServer ${LINKER_FLAGS} spdlog)
|
30
README.md
30
README.md
@ -1,36 +1,46 @@
|
|||||||
# A C++ Gemini server
|
# A C++ Gemini server
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
As I saw other implementations in Rust but no C++ to compete, I felt that I had to do something ;-).
|
|
||||||
It is also a chance for me and a friend (Brumaire) to practice C++ and to try to get as much performance as possible (my speciality is HPC so… Yeah).
|
As I saw other implementations in Rust but no C++ to compete, I felt that I had to do something ;-). It is also a chance for me and a friend (
|
||||||
|
Brumaire) to practice C++ and to try to get as much performance as possible (my speciality is HPC so… Yeah).
|
||||||
|
|
||||||
## Design
|
## Design
|
||||||
|
|
||||||
I use PlantUML to do the class diagram for the design. It's a work in progress.
|
I use PlantUML to do the class diagram for the design. It's a work in progress.
|
||||||
|
|
||||||
## Goal
|
## Goal
|
||||||
|
|
||||||
What we want is a high performance server using asynchrony at first, and then maybe multi-threading to have the maximum possible performance.
|
What we want is a high performance server using asynchrony at first, and then maybe multi-threading to have the maximum possible performance.
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
**WIP**
|
**WIP**
|
||||||
The configuration of the server is made through a JSON file `config.json`. The JSON parser is [simdjson](https://github.com/simdjson/simdjson) directly integrated
|
The configuration of the server is made through a JSON file `config.json`. The JSON parser is [simdjson](https://github.com/simdjson/simdjson)
|
||||||
in our source code.
|
directly integrated in our source code.
|
||||||
|
|
||||||
### Structure of the file
|
### Structure of the file
|
||||||
|
|
||||||
- content
|
- content
|
||||||
- path : string, folder to the content of your site.
|
- path : string, folder to the content of your site.
|
||||||
- cache
|
- cache
|
||||||
- enable_cache: bool, to enable cache of files or not
|
- enable_cache: bool, to enable cache of files or not
|
||||||
- cache_size : unsigned int, the maximum size in bytes to put in cache
|
- cache_size : unsigned int, the maximum size in bytes to put in cache
|
||||||
- ssl
|
- ssl
|
||||||
- pem_path : string
|
- pem_path : string
|
||||||
- cert_path : string
|
- cert_path : string
|
||||||
|
|
||||||
## Dependencies
|
## Dependencies
|
||||||
It uses a bundled version of `spdlog` as a git submodule, but it does not use the `fmt` lib that is inside `spdlog`.
|
|
||||||
|
It uses a bundled version of `spdlog` as a git submodule, but it does not use the `fmt` lib that is inside `spdlog` (you can still change it in the
|
||||||
|
CMakeLists).
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
The doc of the code is made with [doxygen](https://www.doxygen.nl/), the `Doxyfile` is at the root of the repo.
|
The doc of the code is made with [doxygen](https://www.doxygen.nl/), the `Doxyfile` is at the root of the repo.
|
||||||
|
|
||||||
## TODO/features
|
## TODO/features
|
||||||
|
|
||||||
* Possibility of an applicative gateway (like CGI for example)
|
* Possibility of an applicative gateway (like CGI for example)
|
||||||
* Content in RAM cache
|
* Content in RAM cache
|
||||||
* Asynchronous (boost ASIO deals with it)
|
* Asynchronous (boost ASIO deals with it)
|
47
include/configuration.hpp
Normal file
47
include/configuration.hpp
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#ifndef GEMINISERVER_CONFIGURATION_HPP
|
||||||
|
#define GEMINISERVER_CONFIGURATION_HPP
|
||||||
|
|
||||||
|
#include "simdjson.h"
|
||||||
|
#include <string>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
|
||||||
|
namespace gemini {
|
||||||
|
struct Information;
|
||||||
|
|
||||||
|
class CacheFiles;
|
||||||
|
|
||||||
|
using namespace std::literals::string_literals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \class Configuration
|
||||||
|
* \brief This class is used to configurate the whole server and different classes.
|
||||||
|
*
|
||||||
|
* The configuration is made through a JSON file structured like this :
|
||||||
|
*
|
||||||
|
* {
|
||||||
|
* "content" : folder_to_content,
|
||||||
|
* "cache" : {
|
||||||
|
* "enable_cache" : bool,
|
||||||
|
* "cache_size" : int
|
||||||
|
* },
|
||||||
|
* "ssl" : {
|
||||||
|
* "pem_path" : string,
|
||||||
|
* "cert_path" : string
|
||||||
|
* }
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
class Configuration {
|
||||||
|
private:
|
||||||
|
const std::string filename{ "config.json"s };
|
||||||
|
|
||||||
|
public:
|
||||||
|
Configuration() = default;
|
||||||
|
|
||||||
|
explicit Configuration(const std::string &filename) : filename(filename) {}
|
||||||
|
|
||||||
|
std::pair<Information, std::optional<CacheFiles>> create_infos() const;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif //GEMINISERVER_CONFIGURATION_HPP
|
@ -6,7 +6,15 @@ namespace gemini {
|
|||||||
* \brief This struct is used to store information inside, used by any other class/struct.
|
* \brief This struct is used to store information inside, used by any other class/struct.
|
||||||
*/
|
*/
|
||||||
struct Information {
|
struct Information {
|
||||||
|
const bool enable_cache{ false };
|
||||||
|
const std::size_t cache_size{ 0 };
|
||||||
|
const std::string ssl_pem_path{};
|
||||||
|
const std::string ssl_cert_path{};
|
||||||
|
|
||||||
|
Information() = default;
|
||||||
|
|
||||||
|
Information(const bool enableCache, const size_t cacheSize, std::string sslPemPath, std::string sslCertPath) :
|
||||||
|
enable_cache(enableCache), cache_size(cacheSize), ssl_pem_path(std::move(sslPemPath)), ssl_cert_path(std::move(sslCertPath)) {}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
5
main.cpp
5
main.cpp
@ -1,6 +1,11 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||||
|
#include <spdlog/spdlog.h>
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
// Create logger
|
||||||
|
auto logger = spdlog::stdout_color_st("single_log");
|
||||||
|
spdlog::set_default_logger(logger);
|
||||||
std::cout << "Hello, World!" << std::endl;
|
std::cout << "Hello, World!" << std::endl;
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
15
src/configuration.cpp
Normal file
15
src/configuration.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include "../include/configuration.hpp"
|
||||||
|
#include "../include/information.hpp"
|
||||||
|
#include "../include/cache_files.hpp"
|
||||||
|
|
||||||
|
std::pair<gemini::Information, std::optional<gemini::CacheFiles>> gemini::Configuration::create_infos() const {
|
||||||
|
simdjson::dom::parser parser;
|
||||||
|
const auto config = parser.load(filename);
|
||||||
|
const Information infos{
|
||||||
|
config["cache"]["enable_cache"].get_bool(),
|
||||||
|
config["cache"]["cache_size"].get_uint64(),
|
||||||
|
config["ssl"]["pem_path"].get_c_str().value(),
|
||||||
|
config["ssl"]["cert_path"].get_c_str().value() };
|
||||||
|
return std::make_pair(infos,
|
||||||
|
infos.enable_cache ? std::optional(CacheFiles(config["content"]["path"].get_c_str().value(), infos)) : std::nullopt);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user