Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: implement get_public_nodes command #5607

Open
wants to merge 1 commit into
base: master
from
Open
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

rpc: implement get_public_nodes command

  • Loading branch information...
xiphon committed Jun 4, 2019
commit 6dbf97d2d0548a52ea73fdd0e075c11a6a980e70
@@ -1069,6 +1069,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)

This comment has been minimized.

Copy link
@vtnerd

vtnerd Jun 4, 2019

Contributor

public_nodes.reserve(peer_list.size())

This comment has been minimized.

Copy link
@xiphon

xiphon Jun 4, 2019

Author Contributor

Not the case, peer_list.size() ≫ public_nodes.size()

This comment has been minimized.

Copy link
@vtnerd

vtnerd Jun 4, 2019

Contributor

I don't see why that matters. The reserve call will remove allocations in this loop (to one before the loop) and a decent (but admittedly indeterminate) chunk of of the list is going to be copied anyway. And the std::vector is nearly immediately deallocated - once the message is serialized and transmitted.

This comment has been minimized.

Copy link
@xiphon

xiphon Jun 5, 2019

Author Contributor

I prefer doing a few re-allocations here over allocating almost completely unused big chunk of memory.

{
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);
@@ -108,6 +108,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)
@@ -186,6 +187,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);
@@ -84,7 +84,7 @@ namespace cryptonote
// advance which version they will stop working with
// Don't go over 32767 for any of these
#define CORE_RPC_VERSION_MAJOR 2
#define CORE_RPC_VERSION_MINOR 6
#define CORE_RPC_VERSION_MINOR 8

This comment has been minimized.

Copy link
@moneromooo-monero

moneromooo-monero Jun 4, 2019

Contributor

Any reason for skipping 7 ? Another PR somewhere ?

This comment has been minimized.

Copy link
@hyc

hyc Jun 4, 2019

Contributor

As a matter of fact, #5549 uses 7. Not sure it's relevant, we'll rebase to whatever's the current version at the time anyway.

This comment has been minimized.

Copy link
@xiphon

xiphon Jun 4, 2019

Author Contributor

Due to the #5582 PR. I guess it will be merged before this one

#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)

@@ -1236,6 +1236,54 @@ namespace cryptonote
typedef epee::misc_utils::struct_init<response_t> response;
};

struct public_node
{
std::string host;
uint64_t last_seen;

This comment has been minimized.

Copy link
@moneromooo-monero

moneromooo-monero Jun 4, 2019

Contributor

You might want to zero this is restricted RPC.

This comment has been minimized.

Copy link
@xiphon

xiphon Jun 4, 2019

Author Contributor

Have some concerns about it being used for fingerprinting.
Currently get_public_nodes works only in non-restricted mode only (https://github.com/monero-project/monero/pull/5607/files#diff-8238353d591b683ea88296ba92b7ee25R111)
For example, get_peer_list acts the same as well.

Any thoughts?

This comment has been minimized.

Copy link
@moneromooo-monero

moneromooo-monero Jun 4, 2019

Contributor

Oh good, it's fine then.

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()
};

struct COMMAND_RPC_GET_PUBLIC_NODES
{
struct request_t
{
bool gray;
bool white;

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;
std::vector<public_node> gray;
std::vector<public_node> white;

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;
};

struct COMMAND_RPC_SET_LOG_HASH_RATE
{
struct request_t
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.