Files
p2pool-salvium/src/zmq_reader.h

75 lines
2.1 KiB
C
Raw Normal View History

2021-08-22 12:20:59 +02:00
/*
* This file is part of the Monero P2Pool <https://github.com/SChernykh/p2pool>
2025-07-14 20:30:33 +02:00
* Copyright (c) 2021-2025 SChernykh <https://github.com/SChernykh>
2021-08-22 12:20:59 +02:00
*
* 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 "uv_util.h"
#include <zmq.hpp>
namespace p2pool {
2025-07-31 21:09:54 +02:00
class ZMQReader : public nocopy_nomove {
2021-08-22 12:20:59 +02:00
public:
2022-08-31 16:37:33 +02:00
ZMQReader(const std::string& address, uint32_t zmq_port, const std::string& proxy, MinerCallbackHandler* handler);
2021-08-22 12:20:59 +02:00
~ZMQReader();
bool is_running() const { return m_workerThreadRunning.load(); }
2021-08-22 12:20:59 +02:00
private:
struct Monitor : public zmq::monitor_t {
Monitor() : m_connected(false) {}
Monitor(const Monitor&) = delete;
void on_event_connected(const zmq_event_t&, const char* address) ZMQ_OVERRIDE;
void on_event_disconnected(const zmq_event_t&, const char* address) ZMQ_OVERRIDE;
std::atomic<bool> m_connected;
} *m_monitor;
static void monitor_thread(void* arg);
uv_thread_t m_monitorThread{};
private:
void stop();
static void run_wrapper(void* arg);
2021-08-22 12:20:59 +02:00
void run();
bool connect(const std::string& address, bool keep_monitor);
2021-08-22 12:20:59 +02:00
void parse(char* data, size_t size);
2022-08-31 16:37:33 +02:00
std::string m_address;
2021-08-22 12:20:59 +02:00
uint32_t m_zmqPort;
2022-08-31 16:37:33 +02:00
std::string m_proxy;
2021-08-22 12:20:59 +02:00
MinerCallbackHandler* m_handler;
uv_thread_t m_worker{};
zmq::context_t m_context{ 1 };
zmq::socket_t m_publisher{ m_context, ZMQ_PUB };
zmq::socket_t m_subscriber{ m_context, ZMQ_SUB };
2023-05-29 14:37:20 +02:00
uint16_t m_publisherPort = 0;
std::atomic<bool> m_stopped{ false };
std::atomic<bool> m_workerThreadRunning{ false };
2021-08-22 12:20:59 +02:00
TxMempoolData m_tx;
MinerData m_minerData;
ChainMain m_chainmainData;
};
} // namespace p2pool