diff --git a/include/network.hpp b/include/network.hpp index 962fda2..c6a06bf 100644 --- a/include/network.hpp +++ b/include/network.hpp @@ -1,13 +1,56 @@ #ifndef GEMINISERVER_NETWORK_HPP #define GEMINISERVER_NETWORK_HPP +#include +#include +#include +#include "information.hpp" namespace gemini { + namespace asio = boost::asio; + namespace ssl = asio::ssl; + + using asio::ip::tcp; + using ssl_socket = ssl::stream; + /** * \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) {} }; } diff --git a/main.cpp b/main.cpp index 436699c..cf47251 100644 --- a/main.cpp +++ b/main.cpp @@ -1,8 +1,11 @@ #include +#include #include #include #include #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()); return gemini::Configuration{ vm["config"].as() }; } return gemini::Configuration{}; - }(); + }().create_infos(); + + boost::asio::io_context io_context; + gemini::Network network(io_context, infos); return EXIT_SUCCESS; }