From 5326521c0c7d27d44b854fa08147ef24f7048fd7 Mon Sep 17 00:00:00 2001 From: Matt Hess Date: Sun, 16 Nov 2025 17:04:46 +0000 Subject: [PATCH] added unban function, fixed up blck template structure to make salviumd happy, fixed protocol communication bug --- src/console_commands.cpp | 14 +++++++++++++- src/p2p_server.cpp | 4 +++- src/tcp_server.cpp | 8 ++++++++ src/tcp_server.h | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/console_commands.cpp b/src/console_commands.cpp index db5ebb2..1e24550 100644 --- a/src/console_commands.cpp +++ b/src/console_commands.cpp @@ -165,7 +165,7 @@ typedef struct cmd { cmdfunc *func; } cmd; -static cmdfunc do_help, do_status, do_loglevel, do_addpeers, do_droppeers, do_showpeers, do_showworkers, do_showbans, do_showhosts, do_nexthost, do_outpeers, do_inpeers, do_donatetime, do_exit, do_version; +static cmdfunc do_help, do_status, do_loglevel, do_addpeers, do_droppeers, do_showpeers, do_showworkers, do_showbans, do_unban, do_showhosts, do_nexthost, do_outpeers, do_inpeers, do_donatetime, do_exit, do_version; #ifdef WITH_RANDOMX static cmdfunc do_start_mining, do_stop_mining; @@ -180,6 +180,7 @@ static cmd cmds[] = { { STRCONST("peers"), "", "show all peers", do_showpeers }, { STRCONST("workers"), "", "show all connected workers", do_showworkers }, { STRCONST("bans"), "", "show all banned IPs", do_showbans }, + { STRCONST("unban"), "[IP]", "unban peer (or all if no IP given)", do_unban }, { STRCONST("hosts"), "", "show Monero hosts", do_showhosts }, { STRCONST("next_host"), "", "switch to the next Monero host", do_nexthost }, { STRCONST("outpeers"), "", "set maximum number of outgoing connections", do_outpeers }, @@ -349,6 +350,16 @@ static void do_showbans(p2pool* m_pool, const char* /* args */) } } +static void do_unban(p2pool* m_pool, const char* /* args */) +{ + if (m_pool->stratum_server()) { + m_pool->stratum_server()->clear_bans(); + } + if (m_pool->p2p_server()) { + m_pool->p2p_server()->clear_bans(); + } +} + // cppcheck-suppress constParameterCallback static void do_showhosts(p2pool* m_pool, const char* /* args */) { @@ -516,3 +527,4 @@ ConsoleCommands::~ConsoleCommands() } } // namespace p2pool + diff --git a/src/p2p_server.cpp b/src/p2p_server.cpp index 057d0c8..ae19940 100644 --- a/src/p2p_server.cpp +++ b/src/p2p_server.cpp @@ -55,6 +55,7 @@ static const char* seed_nodes_nano[] = { "seed01.whiskymine.io", "seed02.whiskym static constexpr int DEFAULT_BACKLOG = 16; static constexpr uint64_t DEFAULT_BAN_TIME = 600; static constexpr uint64_t PEER_REQUEST_DELAY = 60; +static constexpr uint8_t TX_VERSION = 60; namespace p2pool { @@ -3179,7 +3180,8 @@ bool P2PServer::P2PClient::on_monero_block_broadcast(const uint8_t* buf, uint32_ return false; } - if (buf[data.header_size] != TX_VERSION) { + uint8_t tx_ver = buf[data.header_size]; + if (tx_ver != 4 && tx_ver != TX_VERSION) { LOGWARN(3, "Invalid MONERO_BLOCK_BROADCAST: TX_VERSION byte not found"); return false; } diff --git a/src/tcp_server.cpp b/src/tcp_server.cpp index 5f2826a..23fe58f 100644 --- a/src/tcp_server.cpp +++ b/src/tcp_server.cpp @@ -571,6 +571,14 @@ void TCPServer::print_bans() } } +void TCPServer::clear_bans() +{ + MutexLock lock(m_bansLock); + size_t count = m_bans.size(); + m_bans.clear(); + LOGINFO(0, "cleared " << count << " banned IPs"); +} + bool TCPServer::send_internal(Client* client, const Callback::Base& callback, bool raw) { check_event_loop_thread(__func__); diff --git a/src/tcp_server.h b/src/tcp_server.h index 4499485..f221ce4 100644 --- a/src/tcp_server.h +++ b/src/tcp_server.h @@ -41,6 +41,7 @@ public: void drop_connections_async() { if (m_finished.load() == 0) { uv_async_send(&m_dropConnectionsAsync); } } void shutdown_tcp(); virtual void print_status(); + virtual void clear_bans(); [[nodiscard]] uv_loop_t* get_loop() { return &m_loop; }