aboutsummaryrefslogtreecommitdiff
path: root/src/daemon/rpc_command_executor.cpp
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2015-04-02 17:43:38 +0200
committerRiccardo Spagni <ric@spagni.net>2015-04-02 17:43:43 +0200
commit6f0d93097e3fbe9b1101e90ad1adc718a18263aa (patch)
treeb5a2189ee6cbdd6f8ba57cd1d46edac7ac599ee3 /src/daemon/rpc_command_executor.cpp
parentMerge pull request #251 (diff)
parentNetwork 1.7; Quieted the debug a bit. (diff)
downloadmonero-6f0d93097e3fbe9b1101e90ad1adc718a18263aa.tar.xz
Merge pull request #252
618f20c Network 1.7; Quieted the debug a bit. (rfree2monero) 391c7f9 Utils: use const, document dbg. Less default debug (rfree2monero) 44f4234 [fix] mac os x includes std::random... (rfree2monero) 162c993 Network 1.6: network limits, logging, +doxy (rfree2monero) a3b2226 my changelog (rfree2monero) 2900b1e doxygen files (rfree2monero) 1489310 doxygen related tool (rfree2monero) f9dba47 added windows_stream.* console colors (rfree2monero) c511abf remerged; commands JSON. logging upgrade. doxygen (rfree2monero) f79821a fix locking in count-peers thread (2) (rfree2monero) 0198ffb 2014 network limit 1.3 fix log/path/data +utils (rfree2monero) ae2a506 2014 network limit 1.2 +utils +toc -doc -drmonero (rfree2monero) 0f06dca fixed size_t on windows (rfree2monero) 39fc63f removed not needed <netinet/in.h> (rfree2monero) 5ce4256 2014 network limit 1.1 +utils +toc -doc -drmonero (rfree2monero) eabb519 2014 network limit 1.0a +utils +toc -doc -drmonero (rfree2monero)
Diffstat (limited to 'src/daemon/rpc_command_executor.cpp')
-rw-r--r--src/daemon/rpc_command_executor.cpp152
1 files changed, 140 insertions, 12 deletions
diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp
index f06f48544..46900b071 100644
--- a/src/daemon/rpc_command_executor.cpp
+++ b/src/daemon/rpc_command_executor.cpp
@@ -32,6 +32,7 @@
#include "common/scoped_message_writer.h"
#include "daemon/rpc_command_executor.h"
#include "rpc/core_rpc_server_commands_defs.h"
+#include "cryptonote_core/cryptonote_core.h"
#include <boost/format.hpp>
#include <ctime>
@@ -267,11 +268,38 @@ bool t_rpc_command_executor::print_connections() {
}
}
+ tools::msg_writer() << std::setw(30) << std::left << "Remote Host"
+ << std::setw(20) << "Peer id"
+ << std::setw(30) << "Recv/Sent (inactive,sec)"
+ << std::setw(25) << "State"
+ << std::setw(20) << "Livetime(sec)"
+ << std::setw(12) << "Down (kB/s)"
+ << std::setw(14) << "Down(now)"
+ << std::setw(10) << "Up (kB/s)"
+ << std::setw(13) << "Up(now)"
+ << std::endl;
+
for (auto & info : res.connections)
{
- std::string address = info.ip + ":" + info.port;
- std::string in_out = info.incoming ? "INC" : "OUT";
- tools::msg_writer() << boost::format("%-25s peer_id: %-25s %s") % address % info.peer_id % in_out;
+ std::string address = info.incoming ? "INC " : "OUT ";
+ address += info.ip + ":" + info.port;
+ //std::string in_out = info.incoming ? "INC " : "OUT ";
+ tools::msg_writer()
+ //<< std::setw(30) << std::left << in_out
+ << std::setw(30) << std::left << address
+ << std::setw(20) << info.peer_id
+ << std::setw(30) << std::to_string(info.recv_count) + "(" + std::to_string(info.recv_idle_time) + ")/" + std::to_string(info.send_count) + "(" + std::to_string(info.send_idle_time) + ")"
+ << std::setw(25) << info.state
+ << std::setw(20) << info.live_time
+ << std::setw(12) << info.avg_download
+ << std::setw(14) << info.current_download
+ << std::setw(10) << info.avg_upload
+ << std::setw(13) << info.current_upload
+
+ << std::left << (info.localhost ? "[LOCALHOST]" : "")
+ << std::left << (info.local_ip ? "[LAN]" : "");
+ //tools::msg_writer() << boost::format("%-25s peer_id: %-25s %s") % address % info.peer_id % in_out;
+
}
return true;
@@ -659,34 +687,134 @@ bool t_rpc_command_executor::print_status()
bool t_rpc_command_executor::set_limit(int limit)
{
-/*
epee::net_utils::connection_basic::set_rate_down_limit( limit );
epee::net_utils::connection_basic::set_rate_up_limit( limit );
std::cout << "Set limit-down to " << limit/1024 << " kB/s" << std::endl;
std::cout << "Set limit-up to " << limit/1024 << " kB/s" << std::endl;
-*/
-
return true;
}
bool t_rpc_command_executor::set_limit_up(int limit)
{
-/*
epee::net_utils::connection_basic::set_rate_up_limit( limit );
std::cout << "Set limit-up to " << limit/1024 << " kB/s" << std::endl;
-*/
-
return true;
}
bool t_rpc_command_executor::set_limit_down(int limit)
{
-/*
epee::net_utils::connection_basic::set_rate_down_limit( limit );
std::cout << "Set limit-down to " << limit/1024 << " kB/s" << std::endl;
-*/
-
return true;
}
+bool t_rpc_command_executor::fast_exit()
+{
+ cryptonote::COMMAND_RPC_FAST_EXIT::request req;
+ cryptonote::COMMAND_RPC_FAST_EXIT::response res;
+
+ std::string fail_message = "Daemon did not stop";
+
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->rpc_request(req, res, "/fast_exit", fail_message.c_str()))
+ {
+ return true;
+ }
+ }
+
+ else
+ {
+ if (!m_rpc_server->on_fast_exit(req, res))
+ {
+ tools::fail_msg_writer() << fail_message.c_str();
+ return true;
+ }
+ }
+
+ tools::success_msg_writer() << "Daemon stopped";
+ return true;
+}
+
+bool t_rpc_command_executor::out_peers(uint64_t limit)
+{
+ cryptonote::COMMAND_RPC_OUT_PEERS::request req;
+ cryptonote::COMMAND_RPC_OUT_PEERS::response res;
+
+ epee::json_rpc::error error_resp;
+
+ req.out_peers = limit;
+
+ std::string fail_message = "Unsuccessful";
+
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->json_rpc_request(req, res, "/out_peers", fail_message.c_str()))
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (!m_rpc_server->on_out_peers(req, res))
+ {
+ tools::fail_msg_writer() << fail_message.c_str();
+ return true;
+ }
+ }
+
+ return true;
+}
+
+bool t_rpc_command_executor::start_save_graph()
+{
+ cryptonote::COMMAND_RPC_START_SAVE_GRAPH::request req;
+ cryptonote::COMMAND_RPC_START_SAVE_GRAPH::response res;
+ std::string fail_message = "Unsuccessful";
+
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->rpc_request(req, res, "/start_save_graph", fail_message.c_str()))
+ {
+ return true;
+ }
+ }
+
+ else
+ {
+ if (!m_rpc_server->on_start_save_graph(req, res))
+ {
+ tools::fail_msg_writer() << fail_message.c_str();
+ return true;
+ }
+ }
+
+ return true;
+}
+
+bool t_rpc_command_executor::stop_save_graph()
+{
+ cryptonote::COMMAND_RPC_STOP_SAVE_GRAPH::request req;
+ cryptonote::COMMAND_RPC_STOP_SAVE_GRAPH::response res;
+ std::string fail_message = "Unsuccessful";
+
+ if (m_is_rpc)
+ {
+ if (!m_rpc_client->rpc_request(req, res, "/stop_save_graph", fail_message.c_str()))
+ {
+ return true;
+ }
+ }
+
+ else
+ {
+ if (!m_rpc_server->on_stop_save_graph(req, res))
+ {
+ tools::fail_msg_writer() << fail_message.c_str();
+ return true;
+ }
+ }
+ return true;
+}
+
}// namespace daemonize