103 lines
3.2 KiB
C++
103 lines
3.2 KiB
C++
/*
|
|
* This file is part of the Monero P2Pool <https://github.com/SChernykh/p2pool>
|
|
* Copyright (c) 2021-2026 SChernykh <https://github.com/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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "tcp_server.h"
|
|
#include "merge_mining_client.h"
|
|
|
|
namespace p2pool {
|
|
|
|
class p2pool;
|
|
|
|
class NodejsPoolRpc : public TCPServer
|
|
{
|
|
public:
|
|
NodejsPoolRpc(p2pool* pool, const std::string& listen_addresses);
|
|
~NodejsPoolRpc() override;
|
|
|
|
void on_shutdown() override;
|
|
|
|
private:
|
|
struct WorkSnapshot
|
|
{
|
|
bool ready = false;
|
|
uint64_t mainchain_height = 0;
|
|
uint64_t mining_height = 0;
|
|
uint64_t sidechain_height = 0;
|
|
hash parent_prev_id;
|
|
hash seed_hash;
|
|
hash work_hash;
|
|
uint32_t template_id = 0;
|
|
size_t nonce_offset = 0;
|
|
size_t hashing_nonce_offset = 0;
|
|
size_t extra_nonce_offset = 0;
|
|
size_t extra_nonce_size = 4;
|
|
uint32_t hashing_blob_extra_nonce_start = 0;
|
|
uint32_t hashing_blob_count = 0;
|
|
uint32_t hashing_blob_size = 0;
|
|
difficulty_type mainchain_difficulty;
|
|
difficulty_type sidechain_difficulty;
|
|
difficulty_type aux_difficulty;
|
|
difficulty_type submit_difficulty;
|
|
std::vector<uint8_t> block_template_blob;
|
|
std::vector<uint8_t> hashing_blob;
|
|
std::vector<uint8_t> hashing_blobs;
|
|
std::vector<AuxChainData> aux_chains;
|
|
std::vector<IMergeMiningClient::ChainParameters> aux_chain_params;
|
|
};
|
|
|
|
struct RpcClient : public Client
|
|
{
|
|
RpcClient() : Client(m_readBuf, sizeof(m_readBuf)) {}
|
|
|
|
static Client* allocate() { return new RpcClient(); }
|
|
|
|
size_t size() const override { return sizeof(RpcClient); }
|
|
void reset() override
|
|
{
|
|
Client::reset();
|
|
m_request.clear();
|
|
m_request.shrink_to_fit();
|
|
}
|
|
|
|
bool on_connect() override { return true; }
|
|
bool on_read(const char* data, uint32_t size) override;
|
|
|
|
alignas(8) char m_readBuf[16384] = {};
|
|
std::string m_request;
|
|
};
|
|
|
|
p2pool* m_pool;
|
|
mutable uv_mutex_t m_recentWorkLock;
|
|
mutable std::vector<WorkSnapshot> m_recentWork;
|
|
|
|
const char* get_log_category() const override;
|
|
|
|
bool make_work_snapshot(WorkSnapshot& out, uint32_t hashing_blob_batch_count) const;
|
|
void remember_work_snapshot(const WorkSnapshot& work) const;
|
|
bool find_cached_work_by_template_id(uint32_t template_id, WorkSnapshot& out) const;
|
|
bool find_cached_work_by_block_blob(const std::vector<uint8_t>& blob, WorkSnapshot& out) const;
|
|
uint32_t copy_cached_hashing_blob(const WorkSnapshot& work, uint32_t extra_nonce, uint8_t (&blob)[128], size_t& nonce_offset) const;
|
|
bool handle_http_request(RpcClient* client);
|
|
std::string build_get_height_response() const;
|
|
std::string build_json_rpc_response(const std::string& body) const;
|
|
std::string json_error_response(const char* id, int code, const std::string& message) const;
|
|
};
|
|
|
|
} // namespace p2pool
|