Beginning of implementation of the network part

This commit is contained in:
Pcornat 2021-03-23 21:51:21 +01:00
parent 27b6a75c7d
commit bd43e7d9fd
No known key found for this signature in database
GPG Key ID: 873C3ACCF970C74E
2 changed files with 51 additions and 2 deletions

View File

@ -1,13 +1,56 @@
#ifndef GEMINISERVER_NETWORK_HPP #ifndef GEMINISERVER_NETWORK_HPP
#define GEMINISERVER_NETWORK_HPP #define GEMINISERVER_NETWORK_HPP
#include <boost/asio/io_context.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/asio/ip/tcp.hpp>
#include "information.hpp"
namespace gemini { namespace gemini {
namespace asio = boost::asio;
namespace ssl = asio::ssl;
using asio::ip::tcp;
using ssl_socket = ssl::stream<tcp::socket>;
/** /**
* \brief This class is used for all the network things for the server. * \brief This class is used for all the network things for the server.
*/ */
class Network { class Network {
private:
asio::io_context &io_context;
ssl::context ctx;
ssl_socket socket;
tcp::endpoint endpoint;
tcp::acceptor acceptor;
static ssl::context helper_context(const Information &infos) {
const auto options = ssl::context::no_tlsv1_2 |
ssl::context::no_tlsv1 |
ssl::context::no_sslv2 |
ssl::context::no_sslv3 |
ssl::context::no_tlsv1_1;
ssl::context ctx(ssl::context::tlsv13_server);
ctx.set_options(options);
ctx.set_default_verify_paths();
ctx.use_certificate_chain_file(infos.ssl_pem_path);
ctx.use_private_key_file(infos.ssl_pem_path, ssl::context::pem);
return ctx;
}
public:
const Information &information;
static constexpr std::uint32_t port{ 1965 };
Network() = delete;
Network(asio::io_context &ioContext, const Information &information) :
io_context(ioContext),
ctx(helper_context(information)),
socket(io_context, ctx),
endpoint(tcp::v4(), port),
acceptor(io_context, endpoint),
information(information) {}
}; };
} }

View File

@ -1,8 +1,11 @@
#include <iostream> #include <iostream>
#include <string>
#include <boost/program_options.hpp> #include <boost/program_options.hpp>
#include <spdlog/sinks/stdout_color_sinks.h> #include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include "include/configuration.hpp" #include "include/configuration.hpp"
#include "include/cache_files.hpp"
#include "include/network.hpp"
namespace po = boost::program_options; namespace po = boost::program_options;
@ -28,13 +31,16 @@ int main(int argc, char *argv[]) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
const gemini::Configuration configuration = [&]() -> gemini::Configuration { const auto[infos, caches] = [&]() -> gemini::Configuration {
if (vm.count("config")) { if (vm.count("config")) {
spdlog::debug("config file was set to {}", vm["config"].as<std::string>()); spdlog::debug("config file was set to {}", vm["config"].as<std::string>());
return gemini::Configuration{ vm["config"].as<std::string>() }; return gemini::Configuration{ vm["config"].as<std::string>() };
} }
return gemini::Configuration{}; return gemini::Configuration{};
}(); }().create_infos();
boost::asio::io_context io_context;
gemini::Network network(io_context, infos);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }