2021-08-22 10:20:59 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Monero P2Pool <https://github.com/SChernykh/p2pool>
|
2024-01-02 13:06:19 +00:00
|
|
|
* Copyright (c) 2021-2024 SChernykh <https://github.com/SChernykh>
|
2021-08-22 10:20:59 +00: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
|
|
|
|
|
2022-07-05 20:08:18 +00:00
|
|
|
#include "uv_util.h"
|
2023-04-18 13:38:24 +00:00
|
|
|
#include "tcp_server.h"
|
2021-08-22 10:20:59 +00:00
|
|
|
|
|
|
|
namespace p2pool {
|
|
|
|
|
|
|
|
class p2pool;
|
|
|
|
|
2023-04-19 09:36:12 +00:00
|
|
|
class ConsoleCommands : public TCPServer
|
2021-08-22 10:20:59 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit ConsoleCommands(p2pool* pool);
|
|
|
|
~ConsoleCommands();
|
|
|
|
|
2023-04-18 13:38:24 +00:00
|
|
|
struct ConsoleClient : public Client
|
|
|
|
{
|
2023-04-19 09:36:12 +00:00
|
|
|
ConsoleClient() : Client(m_consoleReadBuf, sizeof(m_consoleReadBuf)) {}
|
2023-04-18 13:38:24 +00:00
|
|
|
~ConsoleClient() {}
|
|
|
|
|
|
|
|
static Client* allocate() { return new ConsoleClient(); }
|
|
|
|
|
|
|
|
size_t size() const override { return sizeof(ConsoleClient); }
|
|
|
|
|
|
|
|
bool on_connect() override { return true; };
|
|
|
|
bool on_read(char* data, uint32_t size) override { static_cast<ConsoleCommands*>(m_owner)->process_input(m_command, data, size); return true; };
|
|
|
|
|
2023-04-19 09:36:12 +00:00
|
|
|
char m_consoleReadBuf[1024] = {};
|
|
|
|
|
2023-04-18 13:38:24 +00:00
|
|
|
std::string m_command;
|
|
|
|
};
|
|
|
|
|
|
|
|
void on_shutdown() override;
|
|
|
|
|
2021-08-22 10:20:59 +00:00
|
|
|
private:
|
2023-08-16 11:00:11 +00:00
|
|
|
const char* get_log_category() const override;
|
2023-04-19 09:36:12 +00:00
|
|
|
|
2021-08-22 10:20:59 +00:00
|
|
|
p2pool* m_pool;
|
|
|
|
|
2022-07-05 20:08:18 +00:00
|
|
|
uv_tty_t m_tty;
|
2023-03-07 13:35:49 +00:00
|
|
|
uv_pipe_t m_stdin_pipe;
|
2023-03-09 01:36:33 +00:00
|
|
|
uv_stream_t* m_stdin_handle;
|
2022-07-05 20:08:18 +00:00
|
|
|
|
2023-04-19 09:36:12 +00:00
|
|
|
char m_readBuf[1024];
|
2022-07-05 20:08:18 +00:00
|
|
|
bool m_readBufInUse;
|
|
|
|
|
2022-08-05 07:04:16 +00:00
|
|
|
std::string m_command;
|
|
|
|
|
2022-07-05 20:08:18 +00:00
|
|
|
static void allocCallback(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf);
|
|
|
|
static void stdinReadCallback(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf);
|
2023-04-18 13:38:24 +00:00
|
|
|
|
|
|
|
void process_input(std::string& command, char* data, uint32_t size);
|
2021-08-22 10:20:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace p2pool
|