diff options
author | Riccardo Spagni <ric@spagni.net> | 2015-11-30 00:16:32 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2015-11-30 00:16:34 +0200 |
commit | a2d1e5a82cdc67f3b84ef476a08fb0f4da047ab1 (patch) | |
tree | ed35b91ab9e9b6a90e612cfe1ad42d54ce1d5321 /src/rpc/core_rpc_server.cpp | |
parent | Merge pull request #501 (diff) | |
parent | add RPC calls and commands to get/set bans (diff) | |
download | monero-a2d1e5a82cdc67f3b84ef476a08fb0f4da047ab1.tar.xz |
Merge pull request #502
38ceb73 add RPC calls and commands to get/set bans (moneromooo-monero)
7bc4dce net_node: allow bans for custom amounts of time (moneromooo-monero)
Diffstat (limited to 'src/rpc/core_rpc_server.cpp')
-rw-r--r-- | src/rpc/core_rpc_server.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index f5e700033..e2b30b6e0 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -899,6 +899,49 @@ namespace cryptonote #endif } //------------------------------------------------------------------------------------------------------------------------------ + bool core_rpc_server::on_get_bans(const COMMAND_RPC_GETBANS::request& req, COMMAND_RPC_GETBANS::response& res, epee::json_rpc::error& error_resp) + { + if(!check_core_busy()) + { + error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; + error_resp.message = "Core is busy."; + return false; + } + + std::map<uint32_t, time_t> blocked_ips = m_p2p.get_blocked_ips(); + for (std::map<uint32_t, time_t>::const_iterator i = blocked_ips.begin(); i != blocked_ips.end(); ++i) + { + COMMAND_RPC_GETBANS::ban b; + b.ip = i->first; + b.seconds = i->second; + res.bans.push_back(b); + } + + res.status = CORE_RPC_STATUS_OK; + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ + bool core_rpc_server::on_set_bans(const COMMAND_RPC_SETBANS::request& req, COMMAND_RPC_SETBANS::response& res, epee::json_rpc::error& error_resp) + { + if(!check_core_busy()) + { + error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY; + error_resp.message = "Core is busy."; + return false; + } + + for (auto i = req.bans.begin(); i != req.bans.end(); ++i) + { + if (i->ban) + m_p2p.block_ip(i->ip, i->seconds); + else + m_p2p.unblock_ip(i->ip); + } + + res.status = CORE_RPC_STATUS_OK; + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::on_fast_exit(const COMMAND_RPC_FAST_EXIT::request& req, COMMAND_RPC_FAST_EXIT::response& res) { cryptonote::core::set_fast_exit(); |