allow blocking whole subnets

This commit is contained in:
moneromooo-monero
2019-03-29 10:47:53 +00:00
parent 515ac2951d
commit 65c4004963
19 changed files with 413 additions and 34 deletions

View File

@@ -1641,14 +1641,14 @@ bool t_rpc_command_executor::print_bans()
for (auto i = res.bans.begin(); i != res.bans.end(); ++i)
{
tools::msg_writer() << epee::string_tools::get_ip_string_from_int32(i->ip) << " banned for " << i->seconds << " seconds";
tools::msg_writer() << i->host << " banned for " << i->seconds << " seconds";
}
return true;
}
bool t_rpc_command_executor::ban(const std::string &ip, time_t seconds)
bool t_rpc_command_executor::ban(const std::string &address, time_t seconds)
{
cryptonote::COMMAND_RPC_SETBANS::request req;
cryptonote::COMMAND_RPC_SETBANS::response res;
@@ -1656,11 +1656,8 @@ bool t_rpc_command_executor::ban(const std::string &ip, time_t seconds)
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.host = address;
ban.ip = 0;
ban.ban = true;
ban.seconds = seconds;
req.bans.push_back(ban);
@@ -1684,7 +1681,7 @@ bool t_rpc_command_executor::ban(const std::string &ip, time_t seconds)
return true;
}
bool t_rpc_command_executor::unban(const std::string &ip)
bool t_rpc_command_executor::unban(const std::string &address)
{
cryptonote::COMMAND_RPC_SETBANS::request req;
cryptonote::COMMAND_RPC_SETBANS::response res;
@@ -1692,11 +1689,8 @@ bool t_rpc_command_executor::unban(const std::string &ip)
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.host = address;
ban.ip = 0;
ban.ban = false;
ban.seconds = 0;
req.bans.push_back(ban);
@@ -1720,6 +1714,39 @@ bool t_rpc_command_executor::unban(const std::string &ip)
return true;
}
bool t_rpc_command_executor::banned(const std::string &address)
{
cryptonote::COMMAND_RPC_BANNED::request req;
cryptonote::COMMAND_RPC_BANNED::response res;
std::string fail_message = "Unsuccessful";
epee::json_rpc::error error_resp;
req.address = address;
if (m_is_rpc)
{
if (!m_rpc_client->json_rpc_request(req, res, "banned", fail_message.c_str()))
{
return true;
}
}
else
{
if (!m_rpc_server->on_banned(req, res, error_resp) || res.status != CORE_RPC_STATUS_OK)
{
tools::fail_msg_writer() << make_error(fail_message, res.status);
return true;
}
}
if (res.banned)
tools::msg_writer() << address << " is banned for " << res.seconds << " seconds";
else
tools::msg_writer() << address << " is not banned";
return true;
}
bool t_rpc_command_executor::flush_txpool(const std::string &txid)
{
cryptonote::COMMAND_RPC_FLUSH_TRANSACTION_POOL::request req;