mirror of
https://github.com/monero-project/monero.git
synced 2025-01-28 18:56:31 +02:00
RPC print_pl
This commit is contained in:
parent
976db0e898
commit
51e03fad1d
@ -4,9 +4,28 @@
|
||||
#include "daemon/http_connection.h"
|
||||
#include "daemon/rpc_command_executor.h"
|
||||
#include "rpc/core_rpc_server_commands_defs.h"
|
||||
#include <boost/format.hpp>
|
||||
#include <ctime>
|
||||
|
||||
namespace daemonize {
|
||||
|
||||
namespace {
|
||||
void print_peer(std::string const & prefix, cryptonote::peer const & peer)
|
||||
{
|
||||
time_t now;
|
||||
time(&now);
|
||||
|
||||
std::string id_str;
|
||||
std::string port_str;
|
||||
std::string elapsed = epee::misc_utils::get_time_interval_string(now - peer.last_seen);
|
||||
std::string ip_str = epee::string_tools::get_ip_string_from_int32(peer.ip);
|
||||
epee::string_tools::xtype_to_string(peer.id, id_str);
|
||||
epee::string_tools::xtype_to_string(peer.port, port_str);
|
||||
std::string addr_str = ip_str + ":" + port_str;
|
||||
tools::msg_writer() << boost::format("%-10s %-25s %-25s %s") % prefix % id_str % addr_str % elapsed;
|
||||
}
|
||||
}
|
||||
|
||||
t_rpc_command_executor::t_host_result t_rpc_command_executor::parse_host(
|
||||
std::string const & rpc_host_ip_str, std::string const & rpc_host_port_str)
|
||||
{
|
||||
@ -28,7 +47,23 @@ t_rpc_command_executor::t_rpc_command_executor(std::string && rpc_host_ip_str, s
|
||||
t_rpc_command_executor::t_rpc_command_executor(t_rpc_command_executor && other) = default;
|
||||
|
||||
bool t_rpc_command_executor::print_peer_list() {
|
||||
std::cout << "print peer list" << std::endl;
|
||||
cryptonote::COMMAND_RPC_GET_PEER_LIST::request req;
|
||||
cryptonote::COMMAND_RPC_GET_PEER_LIST::response res;
|
||||
|
||||
bool ok = rpc_request(req, res, "/get_peer_list", "Couldn't retrieve peer list");
|
||||
|
||||
if (!ok) return false;
|
||||
|
||||
for (auto & peer : res.white_list)
|
||||
{
|
||||
print_peer("white", peer);
|
||||
}
|
||||
|
||||
for (auto & peer : res.gray_list)
|
||||
{
|
||||
print_peer("gray", peer);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -123,8 +158,8 @@ bool t_rpc_command_executor::stop_mining() {
|
||||
|
||||
template <typename T_req, typename T_res>
|
||||
bool t_rpc_command_executor::rpc_request(
|
||||
T_req & request
|
||||
, T_res & response
|
||||
T_req & req
|
||||
, T_res & res
|
||||
, std::string const & relative_url
|
||||
, std::string const & fail_msg
|
||||
)
|
||||
@ -133,15 +168,15 @@ bool t_rpc_command_executor::rpc_request(
|
||||
t_http_connection connection(mp_http_client.get(), m_rpc_host_ip_str, m_rpc_host_port_str);
|
||||
|
||||
bool ok = connection.is_open();
|
||||
ok = ok && epee::net_utils::invoke_http_json_remote_command2(rpc_url, request, response, *mp_http_client);
|
||||
ok = ok && epee::net_utils::invoke_http_json_remote_command2(rpc_url, req, res, *mp_http_client);
|
||||
if (!ok)
|
||||
{
|
||||
tools::fail_msg_writer() << "Couldn't connect to daemon";
|
||||
return false;
|
||||
}
|
||||
else if (response.status != CORE_RPC_STATUS_OK)
|
||||
else if (res.status != CORE_RPC_STATUS_OK) // TODO - handle CORE_RPC_STATUS_BUSY ?
|
||||
{
|
||||
tools::fail_msg_writer() << fail_msg << " -- " << response.status;
|
||||
tools::fail_msg_writer() << fail_msg << " -- " << res.status;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
|
@ -60,8 +60,8 @@ public:
|
||||
private:
|
||||
template <typename T_req, typename T_res>
|
||||
bool rpc_request(
|
||||
T_req & request
|
||||
, T_res & response
|
||||
T_req & req
|
||||
, T_res & res
|
||||
, std::string const & relative_url
|
||||
, std::string const & fail_msg
|
||||
);
|
||||
|
@ -72,6 +72,10 @@ namespace nodetool
|
||||
a & m_config.m_peer_id;
|
||||
}
|
||||
// debug functions
|
||||
void get_peerlist(
|
||||
std::list<peerlist_entry> & white_list
|
||||
, std::list<peerlist_entry> & gray_list
|
||||
);
|
||||
bool log_peerlist();
|
||||
bool log_connections();
|
||||
virtual uint64_t get_connections_count();
|
||||
|
@ -1072,6 +1072,15 @@ namespace nodetool
|
||||
}
|
||||
//-----------------------------------------------------------------------------------
|
||||
template<class t_payload_net_handler>
|
||||
void node_server<t_payload_net_handler>::get_peerlist(
|
||||
std::list<peerlist_entry> & white_list
|
||||
, std::list<peerlist_entry> & gray_list
|
||||
)
|
||||
{
|
||||
m_peerlist.get_peerlist_full(gray_list, white_list);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------
|
||||
template<class t_payload_net_handler>
|
||||
bool node_server<t_payload_net_handler>::log_peerlist()
|
||||
{
|
||||
std::list<peerlist_entry> pl_wite;
|
||||
|
@ -11,6 +11,7 @@ using namespace epee;
|
||||
#include "cryptonote_core/cryptonote_format_utils.h"
|
||||
#include "cryptonote_core/account.h"
|
||||
#include "cryptonote_core/cryptonote_basic_impl.h"
|
||||
#include "p2p/p2p_protocol_defs.h"
|
||||
#include "misc_language.h"
|
||||
#include "crypto/hash.h"
|
||||
#include "core_rpc_server_error_codes.h"
|
||||
@ -311,6 +312,27 @@ namespace cryptonote
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::on_get_peer_list(const COMMAND_RPC_GET_PEER_LIST::request& req, COMMAND_RPC_GET_PEER_LIST::response& res, connection_context& cntx)
|
||||
{
|
||||
// No need to worry about the core here
|
||||
std::list<nodetool::peerlist_entry> white_list;
|
||||
std::list<nodetool::peerlist_entry> gray_list;
|
||||
m_p2p.get_peerlist(white_list, gray_list);
|
||||
|
||||
for (auto & entry : white_list)
|
||||
{
|
||||
res.white_list.emplace_back(entry.id, entry.adr.ip, entry.adr.port, entry.last_seen);
|
||||
}
|
||||
|
||||
for (auto & entry : gray_list)
|
||||
{
|
||||
res.gray_list.emplace_back(entry.id, entry.adr.ip, entry.adr.port, entry.last_seen);
|
||||
}
|
||||
|
||||
res.status = CORE_RPC_STATUS_OK;
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool core_rpc_server::on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, connection_context& cntx)
|
||||
{
|
||||
CHECK_CORE_BUSY();
|
||||
|
@ -46,6 +46,7 @@ namespace cryptonote
|
||||
MAP_URI_AUTO_JON2("/mining_status", on_mining_status, COMMAND_RPC_MINING_STATUS)
|
||||
MAP_URI_AUTO_JON2("/save_bc", on_save_bc, COMMAND_RPC_SAVE_BC)
|
||||
MAP_URI_AUTO_JON2("/getinfo", on_get_info, COMMAND_RPC_GET_INFO)
|
||||
MAP_URI_AUTO_JON2("/get_peer_list", on_get_peer_list, COMMAND_RPC_GET_PEER_LIST)
|
||||
BEGIN_JSON_RPC_MAP("/json_rpc")
|
||||
MAP_JON_RPC("getblockcount", on_getblockcount, COMMAND_RPC_GETBLOCKCOUNT)
|
||||
MAP_JON_RPC_WE("on_getblockhash", on_getblockhash, COMMAND_RPC_GETBLOCKHASH)
|
||||
@ -68,6 +69,7 @@ namespace cryptonote
|
||||
bool on_get_random_outs(const COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request& req, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response& res, connection_context& cntx);
|
||||
bool on_get_info(const COMMAND_RPC_GET_INFO::request& req, COMMAND_RPC_GET_INFO::response& res, connection_context& cntx);
|
||||
bool on_save_bc(const COMMAND_RPC_SAVE_BC::request& req, COMMAND_RPC_SAVE_BC::response& res, connection_context& cntx);
|
||||
bool on_get_peer_list(const COMMAND_RPC_GET_PEER_LIST::request& req, COMMAND_RPC_GET_PEER_LIST::response& res, connection_context& cntx);
|
||||
|
||||
//json_rpc
|
||||
bool on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res, connection_context& cntx);
|
||||
|
@ -477,5 +477,47 @@ namespace cryptonote
|
||||
|
||||
};
|
||||
|
||||
struct peer {
|
||||
uint64_t id;
|
||||
uint32_t ip;
|
||||
uint16_t port;
|
||||
time_t last_seen;
|
||||
|
||||
peer() = default;
|
||||
|
||||
peer(uint64_t id, uint32_t ip, uint16_t port, time_t last_seen)
|
||||
: id(id), ip(ip), port(port), last_seen(last_seen)
|
||||
{}
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(id)
|
||||
KV_SERIALIZE(ip)
|
||||
KV_SERIALIZE(port)
|
||||
KV_SERIALIZE(last_seen)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct COMMAND_RPC_GET_PEER_LIST
|
||||
{
|
||||
struct request
|
||||
{
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
struct response
|
||||
{
|
||||
std::string status;
|
||||
std::vector<peer> white_list;
|
||||
std::vector<peer> gray_list;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(status)
|
||||
KV_SERIALIZE(white_list)
|
||||
KV_SERIALIZE(gray_list)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user