Merge commit '52cd2fa0aff4d6393e91ebb400c33c2449dd1301' into MergeUpstream2

This commit is contained in:
Doyle 2020-04-20 16:55:01 +10:00
commit edc1a13601
4 changed files with 97 additions and 15 deletions

View file

@ -2231,10 +2231,10 @@ bool t_rpc_command_executor::alt_chain_info(const std::string &tip, size_t above
}
const uint64_t dt = t1 - t0;
const uint64_t age = std::max(dt, t0 < now ? now - t0 : 0);
tools::msg_writer() << "Age: " << tools::get_human_readable_timespan(age);
tools::msg_writer() << "Age: " << tools::get_human_readable_timespan(std::chrono::seconds(age));
if (chain.length > 1)
{
tools::msg_writer() << "Time span: " << tools::get_human_readable_timespan(dt);
tools::msg_writer() << "Time span: " << tools::get_human_readable_timespan(std::chrono::seconds(dt));
cryptonote::difficulty_type start_difficulty = bhres.block_headers.back().difficulty;
if (start_difficulty > 0)
tools::msg_writer() << "Approximated " << 100.f * DIFFICULTY_TARGET_V2 * chain.length / dt << "% of network hash rate";

View file

@ -1097,6 +1097,45 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_public_nodes(const COMMAND_RPC_GET_PUBLIC_NODES::request& req, COMMAND_RPC_GET_PUBLIC_NODES::response& res, const connection_context *ctx)
{
PERF_TIMER(on_get_public_nodes);
COMMAND_RPC_GET_PEER_LIST::response peer_list_res;
const bool success = on_get_peer_list(COMMAND_RPC_GET_PEER_LIST::request(), peer_list_res, ctx);
res.status = peer_list_res.status;
if (!success)
{
return false;
}
if (res.status != CORE_RPC_STATUS_OK)
{
return true;
}
const auto collect = [](const std::vector<peer> &peer_list, std::vector<public_node> &public_nodes)
{
for (const auto &entry : peer_list)
{
if (entry.rpc_port != 0)
{
public_nodes.emplace_back(entry);
}
}
};
if (req.white)
{
collect(peer_list_res.white_list, res.white);
}
if (req.gray)
{
collect(peer_list_res.gray_list, res.gray);
}
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_set_log_hash_rate(const COMMAND_RPC_SET_LOG_HASH_RATE::request& req, COMMAND_RPC_SET_LOG_HASH_RATE::response& res, const connection_context *ctx)
{
PERF_TIMER(on_set_log_hash_rate);

View file

@ -116,6 +116,7 @@ namespace cryptonote
MAP_URI_AUTO_JON2_IF("/mining_status", on_mining_status, COMMAND_RPC_MINING_STATUS, !m_restricted)
MAP_URI_AUTO_JON2_IF("/save_bc", on_save_bc, COMMAND_RPC_SAVE_BC, !m_restricted)
MAP_URI_AUTO_JON2_IF("/get_peer_list", on_get_peer_list, COMMAND_RPC_GET_PEER_LIST, !m_restricted)
MAP_URI_AUTO_JON2_IF("/get_public_nodes", on_get_public_nodes, COMMAND_RPC_GET_PUBLIC_NODES, !m_restricted)
MAP_URI_AUTO_JON2_IF("/set_log_hash_rate", on_set_log_hash_rate, COMMAND_RPC_SET_LOG_HASH_RATE, !m_restricted)
MAP_URI_AUTO_JON2_IF("/set_log_level", on_set_log_level, COMMAND_RPC_SET_LOG_LEVEL, !m_restricted)
MAP_URI_AUTO_JON2_IF("/set_log_categories", on_set_log_categories, COMMAND_RPC_SET_LOG_CATEGORIES, !m_restricted)
@ -219,6 +220,7 @@ namespace cryptonote
bool on_get_net_stats(const COMMAND_RPC_GET_NET_STATS::request& req, COMMAND_RPC_GET_NET_STATS::response& res, const connection_context *ctx = NULL);
bool on_save_bc(const COMMAND_RPC_SAVE_BC::request& req, COMMAND_RPC_SAVE_BC::response& res, const connection_context *ctx = NULL);
bool on_get_peer_list(const COMMAND_RPC_GET_PEER_LIST::request& req, COMMAND_RPC_GET_PEER_LIST::response& res, const connection_context *ctx = NULL);
bool on_get_public_nodes(const COMMAND_RPC_GET_PUBLIC_NODES::request& req, COMMAND_RPC_GET_PUBLIC_NODES::response& res, const connection_context *ctx = NULL);
bool on_set_log_hash_rate(const COMMAND_RPC_SET_LOG_HASH_RATE::request& req, COMMAND_RPC_SET_LOG_HASH_RATE::response& res, const connection_context *ctx = NULL);
bool on_set_log_level(const COMMAND_RPC_SET_LOG_LEVEL::request& req, COMMAND_RPC_SET_LOG_LEVEL::response& res, const connection_context *ctx = NULL);
bool on_set_log_categories(const COMMAND_RPC_SET_LOG_CATEGORIES::request& req, COMMAND_RPC_SET_LOG_CATEGORIES::response& res, const connection_context *ctx = NULL);

View file

@ -96,13 +96,8 @@ constexpr char const CORE_RPC_STATUS_TX_LONG_POLL_MAX_CONNECTIONS[] = "Daemon ma
// whether they can talk to a given daemon without having to know in
// advance which version they will stop working with
// Don't go over 32767 for any of these
<<<<<<< HEAD
#define CORE_RPC_VERSION_MAJOR 3
#define CORE_RPC_VERSION_MINOR 4
=======
#define CORE_RPC_VERSION_MAJOR 2
#define CORE_RPC_VERSION_MINOR 7
>>>>>>> 880ebfdeeaceab5e1ca40b748516987e9c6cecb7
#define CORE_RPC_VERSION_MINOR 5
#define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor))
#define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR)
@ -1378,6 +1373,57 @@ constexpr char const CORE_RPC_STATUS_TX_LONG_POLL_MAX_CONNECTIONS[] = "Daemon ma
typedef epee::misc_utils::struct_init<response_t> response;
};
LOKI_RPC_DOC_INTROSPECT
struct public_node
{
std::string host;
uint64_t last_seen;
uint16_t rpc_port;
public_node() = delete;
public_node(const peer &peer)
: host(peer.host), last_seen(peer.last_seen), rpc_port(peer.rpc_port)
{}
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(host)
KV_SERIALIZE(last_seen)
KV_SERIALIZE(rpc_port)
END_KV_SERIALIZE_MAP()
};
LOKI_RPC_DOC_INTROSPECT
// Query the daemon's peerlist and retrieve peers who have set their public rpc port.
struct COMMAND_RPC_GET_PUBLIC_NODES
{
struct request_t
{
bool gray; // Get peers that have recently gone offline.
bool white; // Get peers that are online
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE_OPT(gray, false)
KV_SERIALIZE_OPT(white, true)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<request_t> request;
struct response_t
{
std::string status; // General RPC error code. "OK" means everything looks good. Any other value means that something went wrong.
std::vector<public_node> gray; // Graylist peers
std::vector<public_node> white; // Whitelist peers
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(status)
KV_SERIALIZE(gray)
KV_SERIALIZE(white)
END_KV_SERIALIZE_MAP()
};
typedef epee::misc_utils::struct_init<response_t> response;
};
LOKI_RPC_DOC_INTROSPECT
// Set the log hash rate display mode.
struct COMMAND_RPC_SET_LOG_HASH_RATE
@ -2287,13 +2333,8 @@ constexpr char const CORE_RPC_STATUS_TX_LONG_POLL_MAX_CONNECTIONS[] = "Daemon ma
struct response_t
{
<<<<<<< HEAD
std::string status; // General RPC error code. "OK" means everything looks good.
std::list<chain_info> chains; // Array of Chains.
=======
std::string status;
std::vector<chain_info> chains;
>>>>>>> 880ebfdeeaceab5e1ca40b748516987e9c6cecb7
std::vector<chain_info> chains; // Array of Chains.
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(status)