aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/rpc_command_executor.cpp
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2015-11-26 00:04:22 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2015-11-26 00:04:22 +0000
commit38ceb73848a3c37df60bce637d855b7564b09730 (patch)
treeed35b91ab9e9b6a90e612cfe1ad42d54ce1d5321 /src/daemon/rpc_command_executor.cpp
parentnet_node: allow bans for custom amounts of time (diff)
downloadmonero-38ceb73848a3c37df60bce637d855b7564b09730.tar.xz
add RPC calls and commands to get/set bans
Diffstat (limited to 'src/daemon/rpc_command_executor.cpp')
-rw-r--r--src/daemon/rpc_command_executor.cpp106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index 176df81fc..547db1672 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -1036,4 +1036,110 @@ bool t_rpc_command_executor::hard_fork_info(uint8_t version)
return true;
}
+bool t_rpc_command_executor::print_bans()
+{
+ cryptonote::COMMAND_RPC_GETBANS::request req;
+ cryptonote::COMMAND_RPC_GETBANS::response res;
+ std::string fail_message = "Unsuccessful";
+ epee::json_rpc::error error_resp;
+
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->json_rpc_request(req, res, "get_bans", fail_message.c_str()))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (!m_rpc_server->on_get_bans(req, res, error_resp))
+ {
+ tools::fail_msg_writer() << fail_message.c_str();
+ return true;
+ }
+ }
+
+ time_t now = time(nullptr);
+ for (auto i = res.bans.begin(); i != res.bans.end(); ++i)
+ {
+ time_t seconds = i->seconds - now;
+ tools::msg_writer() << epee::string_tools::get_ip_string_from_int32(i->ip) << " banned for " << seconds << " seconds";
+ }
+
+ return true;
+}
+
+
+bool t_rpc_command_executor::ban(const std::string &ip, time_t seconds)
+{
+ cryptonote::COMMAND_RPC_SETBANS::request req;
+ cryptonote::COMMAND_RPC_SETBANS::response res;
+ std::string fail_message = "Unsuccessful";
+ epee::json_rpc::error error_resp;
+
+ cryptonote::COMMAND_RPC_SETBANS::ban ban;
+ if (!epee::string_tools::get_ip_int32_from_string(ban.ip, ip))
+ {
+ tools::fail_msg_writer() << "Invalid IP";
+ return true;
+ }
+ ban.ban = true;
+ ban.seconds = seconds;
+ req.bans.push_back(ban);
+
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->json_rpc_request(req, res, "set_bans", fail_message.c_str()))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (!m_rpc_server->on_set_bans(req, res, error_resp))
+ {
+ tools::fail_msg_writer() << fail_message.c_str();
+ return true;
+ }
+ }
+
+ return true;
+}
+
+bool t_rpc_command_executor::unban(const std::string &ip)
+{
+ cryptonote::COMMAND_RPC_SETBANS::request req;
+ cryptonote::COMMAND_RPC_SETBANS::response res;
+ std::string fail_message = "Unsuccessful";
+ epee::json_rpc::error error_resp;
+
+ cryptonote::COMMAND_RPC_SETBANS::ban ban;
+ if (!epee::string_tools::get_ip_int32_from_string(ban.ip, ip))
+ {
+ tools::fail_msg_writer() << "Invalid IP";
+ return true;
+ }
+ ban.ban = false;
+ ban.seconds = 0;
+ req.bans.push_back(ban);
+
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->json_rpc_request(req, res, "set_bans", fail_message.c_str()))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (!m_rpc_server->on_set_bans(req, res, error_resp))
+ {
+ tools::fail_msg_writer() << fail_message.c_str();
+ return true;
+ }
+ }
+
+ return true;
+}
+
}// namespace daemonize