Beginning of implementation of the network part
This commit is contained in:
parent
27b6a75c7d
commit
bd43e7d9fd
@ -1,13 +1,56 @@
|
||||
#ifndef 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 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.
|
||||
*/
|
||||
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) {}
|
||||
};
|
||||
}
|
||||
|
||||
|
10
main.cpp
10
main.cpp
@ -1,8 +1,11 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <boost/program_options.hpp>
|
||||
#include <spdlog/sinks/stdout_color_sinks.h>
|
||||
#include <spdlog/spdlog.h>
|
||||
#include "include/configuration.hpp"
|
||||
#include "include/cache_files.hpp"
|
||||
#include "include/network.hpp"
|
||||
|
||||
namespace po = boost::program_options;
|
||||
|
||||
@ -28,13 +31,16 @@ int main(int argc, char *argv[]) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
const gemini::Configuration configuration = [&]() -> gemini::Configuration {
|
||||
const auto[infos, caches] = [&]() -> gemini::Configuration {
|
||||
if (vm.count("config")) {
|
||||
spdlog::debug("config file was set to {}", vm["config"].as<std::string>());
|
||||
return gemini::Configuration{ vm["config"].as<std::string>() };
|
||||
}
|
||||
return gemini::Configuration{};
|
||||
}();
|
||||
}().create_infos();
|
||||
|
||||
boost::asio::io_context io_context;
|
||||
gemini::Network network(io_context, infos);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user