2021-08-22 04:20:59 -06:00
|
|
|
/*
|
|
|
|
* This file is part of the Monero P2Pool <https://github.com/SChernykh/p2pool>
|
2023-01-04 05:07:55 -07:00
|
|
|
* Copyright (c) 2021-2023 SChernykh <https://github.com/SChernykh>
|
2021-08-22 04:20:59 -06: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 14:08:18 -06:00
|
|
|
#include "uv_util.h"
|
2023-04-18 07:38:24 -06:00
|
|
|
#include "tcp_server.h"
|
2021-08-22 04:20:59 -06:00
|
|
|
|
|
|
|
namespace p2pool {
|
|
|
|
|
|
|
|
class p2pool;
|
|
|
|
|
2023-04-18 07:38:24 -06:00
|
|
|
class ConsoleCommands : public TCPServer<256, 256>
|
2021-08-22 04:20:59 -06:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit ConsoleCommands(p2pool* pool);
|
|
|
|
~ConsoleCommands();
|
|
|
|
|
2023-04-18 07:38:24 -06:00
|
|
|
struct ConsoleClient : public Client
|
|
|
|
{
|
|
|
|
~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; };
|
|
|
|
|
|
|
|
std::string m_command;
|
|
|
|
};
|
|
|
|
|
|
|
|
void on_shutdown() override;
|
|
|
|
|
2021-08-22 04:20:59 -06:00
|
|
|
private:
|
|
|
|
p2pool* m_pool;
|
|
|
|
|
2022-07-05 14:08:18 -06:00
|
|
|
uv_tty_t m_tty;
|
2023-03-07 06:35:49 -07:00
|
|
|
uv_pipe_t m_stdin_pipe;
|
2023-03-08 18:36:33 -07:00
|
|
|
uv_stream_t* m_stdin_handle;
|
2022-07-05 14:08:18 -06:00
|
|
|
|
|
|
|
char m_readBuf[64];
|
|
|
|
bool m_readBufInUse;
|
|
|
|
|
2022-08-05 01:04:16 -06:00
|
|
|
std::string m_command;
|
|
|
|
|
2022-07-05 14:08:18 -06: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 07:38:24 -06:00
|
|
|
|
|
|
|
void process_input(std::string& command, char* data, uint32_t size);
|
2021-08-22 04:20:59 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace p2pool
|