/* * Copyright (c) 2026, The PurpleI2P Project * * This file is part of Purple i2pd project and licensed under BSD3 * * See full license text in LICENSE file at top of project tree */ #ifndef TORRENTS_RPC_H__ #define TORRENTS_RPC_H__ #include #include #include #include #include #include #include #include "util.h" namespace i2p { namespace torrents { class TorrentsRPCServer; class TorrentsTunnel; class TorrentsRPCSession: public std::enable_shared_from_this { public: TorrentsRPCSession (TorrentsRPCServer& server, boost::asio::ip::tcp::socket&& s); void ReceiveRequest (); private: void HandleRequest (const boost::system::error_code& ecode, size_t bytes_transferred); void SendResponse (boost::beast::http::status result, std::string_view data = ""); private: TorrentsRPCServer& m_Server; boost::asio::ip::tcp::socket m_Socket; boost::beast::flat_buffer m_ReceiveBuffer; boost::beast::http::request m_Request; boost::beast::http::response m_Response; }; class TorrentsRPCServer final: private i2p::util::RunnableServiceWithWork { public: TorrentsRPCServer (std::string_view address, uint16_t port); auto& GetService () { return GetIOService (); } void Start (); void Stop (); void AddTunnel (std::string_view path, std::shared_ptr tunnel); std::shared_ptr GetTunnel (std::string_view path) const; private: void Accept (); private: boost::asio::ip::tcp::acceptor m_Acceptor; std::map, std::less<> > m_Tunnels; // path->tunnel }; } } #endif