aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/rpc_command_executor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/daemon/rpc_command_executor.cpp')
-rw-r--r--src/daemon/rpc_command_executor.cpp112
1 files changed, 109 insertions, 3 deletions
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index a28b4290d..74dbc0012 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -242,7 +242,7 @@ bool t_rpc_command_executor::show_difficulty() {
tools::success_msg_writer() << "BH: " << res.height
<< ", DIFF: " << res.difficulty
- << ", HR: " << (int) res.difficulty / 60L << " H/s";
+ << ", HR: " << (int) res.difficulty / res.target << " H/s";
return true;
}
@@ -283,11 +283,11 @@ bool t_rpc_command_executor::show_status() {
tools::success_msg_writer() << boost::format("Height: %llu/%llu (%.1f%%) on %s, net hash %s, v%u, %s, %u+%u connections")
% (unsigned long long)ires.height
- % (unsigned long long)(ires.target_height ? ires.target_height : ires.height)
+ % (unsigned long long)(ires.target_height >= ires.height ? ires.target_height : ires.height)
% (100.0f * ires.height / (ires.target_height ? ires.target_height < ires.height ? ires.height : ires.target_height : ires.height))
% (ires.testnet ? "testnet" : "mainnet")
% [&ires]()->std::string {
- float hr = ires.difficulty / 60.0f;
+ float hr = ires.difficulty / ires.target;
if (hr>1e9) return (boost::format("%.2f GH/s") % (hr/1e9)).str();
if (hr>1e6) return (boost::format("%.2f MH/s") % (hr/1e6)).str();
if (hr>1e3) return (boost::format("%.2f kH/s") % (hr/1e3)).str();
@@ -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