/* * This file is part of the Monero P2Pool * Copyright (c) 2021-2024 SChernykh * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #pragma once #include #if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-qual" #endif #include #if defined(__GNUC__) && !defined(__clang__) #pragma GCC diagnostic pop #endif namespace p2pool { class ServerTls { public: FORCEINLINE ServerTls() { reset(); } [[nodiscard]] static bool load_from_files(const char* cert, const char* cert_key); void reset(); [[nodiscard]] bool init(); template [[nodiscard]] FORCEINLINE bool on_read(const char* data, uint32_t size, T&& read_callback, U&& write_callback) { return on_read_internal(data, size, ReadCallback::Derived(std::move(read_callback)), WriteCallback::Derived(std::move(write_callback))); } template [[nodiscard]] FORCEINLINE bool on_write(const uint8_t* data, size_t size, T&& write_callback) { return on_write_internal(data, size, WriteCallback::Derived(std::move(write_callback))); } [[nodiscard]] FORCEINLINE bool is_empty() const { return m_ssl.get() == nullptr; } private: typedef Callback ReadCallback; typedef Callback WriteCallback; [[nodiscard]] bool on_read_internal(const char* data, uint32_t size, ReadCallback::Base&& read_callback, WriteCallback::Base&& write_callback); [[nodiscard]] bool on_write_internal(const uint8_t* data, size_t size, WriteCallback::Base&& write_callback); private: bssl::UniquePtr m_ssl; }; } // namespace p2pool