aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-08-07 15:24:58 +0200
committerRiccardo Spagni <ric@spagni.net>2017-08-07 15:24:58 +0200
commit6db8a60a18c3678824016234b2153b4b0f0dbbdd (patch)
tree7a36b079ad838f6d8046844e3a7596027f12bfdf /src/rpc
parentMerge pull request #2138 (diff)
parentcore: thread most of handle_incoming_tx (diff)
downloadmonero-6db8a60a18c3678824016234b2153b4b0f0dbbdd.tar.xz
Merge pull request #2149
158c3ecf core: thread most of handle_incoming_tx (moneromooo-monero) f57ee382 cryptonote_protocol: retry stale spans early (moneromooo-monero) 90df52e1 cryptonote_protocol: light cleanup (moneromooo-monero) 84e23156 cryptonote_protocol: avoid spurious SYNCHRONIZED OK messages (moneromooo-monero) 5be43fcd cryptonote_protocol_handler: sync speedup (moneromooo-monero)
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/core_rpc_server.cpp35
-rw-r--r--src/rpc/core_rpc_server.h2
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h56
3 files changed, 93 insertions, 0 deletions
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index 097958d24..877256d16 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -1690,6 +1690,41 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool core_rpc_server::on_sync_info(const COMMAND_RPC_SYNC_INFO::request& req, COMMAND_RPC_SYNC_INFO::response& res, epee::json_rpc::error& error_resp)
+ {
+ if(!check_core_busy())
+ {
+ error_resp.code = CORE_RPC_ERROR_CODE_CORE_BUSY;
+ error_resp.message = "Core is busy.";
+ return false;
+ }
+
+ crypto::hash top_hash;
+ if (!m_core.get_blockchain_top(res.height, top_hash))
+ {
+ res.status = "Failed";
+ return false;
+ }
+ ++res.height; // turn top block height into blockchain height
+ res.target_height = m_core.get_target_blockchain_height();
+
+ for (const auto &c: m_p2p.get_payload_object().get_connections())
+ res.peers.push_back({c});
+ const cryptonote::block_queue &block_queue = m_p2p.get_payload_object().get_block_queue();
+ block_queue.foreach([&](const cryptonote::block_queue::span &span) {
+ uint32_t speed = (uint32_t)(100.0f * block_queue.get_speed(span.connection_id) + 0.5f);
+ std::string address = "";
+ for (const auto &c: m_p2p.get_payload_object().get_connections())
+ if (c.connection_id == span.connection_id)
+ address = c.address;
+ res.spans.push_back({span.start_block_height, span.nblocks, span.connection_id, (uint32_t)(span.rate + 0.5f), speed, span.size, address});
+ return true;
+ });
+
+ res.status = CORE_RPC_STATUS_OK;
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
const command_line::arg_descriptor<std::string> core_rpc_server::arg_rpc_bind_port = {
"rpc-bind-port"
diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h
index cf95b0edf..1d1d9da66 100644
--- a/src/rpc/core_rpc_server.h
+++ b/src/rpc/core_rpc_server.h
@@ -124,6 +124,7 @@ namespace cryptonote
MAP_JON_RPC_WE("get_fee_estimate", on_get_per_kb_fee_estimate, COMMAND_RPC_GET_PER_KB_FEE_ESTIMATE)
MAP_JON_RPC_WE_IF("get_alternate_chains",on_get_alternate_chains, COMMAND_RPC_GET_ALTERNATE_CHAINS, !m_restricted)
MAP_JON_RPC_WE_IF("relay_tx", on_relay_tx, COMMAND_RPC_RELAY_TX, !m_restricted)
+ MAP_JON_RPC_WE_IF("sync_info", on_sync_info, COMMAND_RPC_SYNC_INFO, !m_restricted)
END_JSON_RPC_MAP()
END_URI_MAP2()
@@ -180,6 +181,7 @@ namespace cryptonote
bool on_get_per_kb_fee_estimate(const COMMAND_RPC_GET_PER_KB_FEE_ESTIMATE::request& req, COMMAND_RPC_GET_PER_KB_FEE_ESTIMATE::response& res, epee::json_rpc::error& error_resp);
bool on_get_alternate_chains(const COMMAND_RPC_GET_ALTERNATE_CHAINS::request& req, COMMAND_RPC_GET_ALTERNATE_CHAINS::response& res, epee::json_rpc::error& error_resp);
bool on_relay_tx(const COMMAND_RPC_RELAY_TX::request& req, COMMAND_RPC_RELAY_TX::response& res, epee::json_rpc::error& error_resp);
+ bool on_sync_info(const COMMAND_RPC_SYNC_INFO::request& req, COMMAND_RPC_SYNC_INFO::response& res, epee::json_rpc::error& error_resp);
//-----------------------
private:
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index a38952bff..c413f9af8 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -1606,4 +1606,60 @@ namespace cryptonote
END_KV_SERIALIZE_MAP()
};
};
+
+ struct COMMAND_RPC_SYNC_INFO
+ {
+ struct request
+ {
+ BEGIN_KV_SERIALIZE_MAP()
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct peer
+ {
+ connection_info info;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(info)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct span
+ {
+ uint64_t start_block_height;
+ uint64_t nblocks;
+ boost::uuids::uuid connection_id;
+ uint32_t rate;
+ uint32_t speed;
+ uint64_t size;
+ std::string remote_address;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(start_block_height)
+ KV_SERIALIZE(nblocks)
+ KV_SERIALIZE_VAL_POD_AS_BLOB(connection_id)
+ KV_SERIALIZE(rate)
+ KV_SERIALIZE(speed)
+ KV_SERIALIZE(size)
+ KV_SERIALIZE(remote_address)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ std::string status;
+ uint64_t height;
+ uint64_t target_height;
+ std::list<peer> peers;
+ std::list<span> spans;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(status)
+ KV_SERIALIZE(height)
+ KV_SERIALIZE(target_height)
+ KV_SERIALIZE(peers)
+ KV_SERIALIZE(spans)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
}