diff options
author | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-03-29 22:03:52 +0000 |
---|---|---|
committer | moneromooo-monero <moneromooo-monero@users.noreply.github.com> | 2019-04-11 10:46:41 +0000 |
commit | 9f8dc4ce515f52ebb2a434ba6d1d9f47bfeac612 (patch) | |
tree | 7c73227be570f59685f1c3efb4d313c0831aa9f6 | |
parent | Merge pull request #5367 (diff) | |
download | monero-9f8dc4ce515f52ebb2a434ba6d1d9f47bfeac612.tar.xz |
simplewallet: new net_stats command
displays total sent and received bytes
-rw-r--r-- | contrib/epee/include/net/http_client.h | 10 | ||||
-rw-r--r-- | contrib/epee/include/net/net_helper.h | 22 | ||||
-rw-r--r-- | src/simplewallet/simplewallet.cpp | 12 | ||||
-rw-r--r-- | src/simplewallet/simplewallet.h | 1 | ||||
-rw-r--r-- | src/wallet/wallet2.cpp | 10 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 3 |
6 files changed, 56 insertions, 2 deletions
diff --git a/contrib/epee/include/net/http_client.h b/contrib/epee/include/net/http_client.h index a18a1d30a..bb10c8efc 100644 --- a/contrib/epee/include/net/http_client.h +++ b/contrib/epee/include/net/http_client.h @@ -444,6 +444,16 @@ namespace net_utils return handle_reciev(timeout); } //--------------------------------------------------------------------------- + uint64_t get_bytes_sent() const + { + return m_net_client.get_bytes_sent(); + } + //--------------------------------------------------------------------------- + uint64_t get_bytes_received() const + { + return m_net_client.get_bytes_received(); + } + //--------------------------------------------------------------------------- private: //--------------------------------------------------------------------------- inline bool handle_reciev(std::chrono::milliseconds timeout) diff --git a/contrib/epee/include/net/net_helper.h b/contrib/epee/include/net/net_helper.h index 66a307c97..e8fb40a0a 100644 --- a/contrib/epee/include/net/net_helper.h +++ b/contrib/epee/include/net/net_helper.h @@ -108,7 +108,9 @@ namespace net_utils m_initialized(true), m_connected(false), m_deadline(m_io_service), - m_shutdowned(0) + m_shutdowned(0), + m_bytes_sent(0), + m_bytes_received(0) { } @@ -313,6 +315,7 @@ namespace net_utils }else { m_deadline.expires_at(std::chrono::steady_clock::time_point::max()); + m_bytes_sent += buff.size(); } } @@ -369,6 +372,7 @@ namespace net_utils }else { m_deadline.expires_at(std::chrono::steady_clock::time_point::max()); + m_bytes_sent += sz; } } @@ -458,6 +462,7 @@ namespace net_utils /*if(!bytes_transfered) return false;*/ + m_bytes_received += bytes_transfered; buff.assign(local_buff, bytes_transfered); return true; } @@ -526,6 +531,7 @@ namespace net_utils m_deadline.expires_at(std::chrono::steady_clock::time_point::max()); } + m_bytes_received += bytes_transfered; if(bytes_transfered != buff.size()) { LOG_ERROR("Transferred mismatch with transfer_at_least value: m_bytes_transferred=" << bytes_transfered << " at_least value=" << buff.size()); @@ -581,7 +587,17 @@ namespace net_utils { return m_ssl_socket->next_layer(); } - + + uint64_t get_bytes_sent() const + { + return m_bytes_sent; + } + + uint64_t get_bytes_received() const + { + return m_bytes_received; + } + private: void check_deadline() @@ -667,6 +683,8 @@ namespace net_utils bool m_connected; boost::asio::steady_timer m_deadline; volatile uint32_t m_shutdowned; + std::atomic<uint64_t> m_bytes_sent; + std::atomic<uint64_t> m_bytes_received; }; diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 9f7cc9c3b..736d5391e 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -242,6 +242,7 @@ namespace const char* USAGE_FREEZE("freeze <key_image>"); const char* USAGE_THAW("thaw <key_image>"); const char* USAGE_FROZEN("frozen <key_image>"); + const char* USAGE_NET_STATS("net_stats"); const char* USAGE_VERSION("version"); const char* USAGE_HELP("help [<command>]"); @@ -2098,6 +2099,13 @@ bool simple_wallet::frozen(const std::vector<std::string> &args) return true; } +bool simple_wallet::net_stats(const std::vector<std::string> &args) +{ + message_writer() << std::to_string(m_wallet->get_bytes_sent()) + tr(" bytes sent"); + message_writer() << std::to_string(m_wallet->get_bytes_received()) + tr(" bytes received"); + return true; +} + bool simple_wallet::version(const std::vector<std::string> &args) { message_writer() << "Monero '" << MONERO_RELEASE_NAME << "' (v" << MONERO_VERSION_FULL << ")"; @@ -3097,6 +3105,10 @@ simple_wallet::simple_wallet() boost::bind(&simple_wallet::frozen, this, _1), tr(USAGE_FROZEN), tr("Checks whether a given output is currently frozen by key image")); + m_cmd_binder.set_handler("net_stats", + boost::bind(&simple_wallet::net_stats, this, _1), + tr(USAGE_NET_STATS), + tr("Prints simple network stats")); m_cmd_binder.set_handler("version", boost::bind(&simple_wallet::version, this, _1), tr(USAGE_VERSION), diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index c9a5c55e8..b2dcebb18 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -241,6 +241,7 @@ namespace cryptonote bool freeze(const std::vector<std::string>& args); bool thaw(const std::vector<std::string>& args); bool frozen(const std::vector<std::string>& args); + bool net_stats(const std::vector<std::string>& args); bool version(const std::vector<std::string>& args); bool cold_sign_tx(const std::vector<tools::wallet2::pending_tx>& ptx_vector, tools::wallet2::signed_tx_set &exported_txs, std::vector<cryptonote::address_parse_info> &dsts_info, std::function<bool(const tools::wallet2::signed_tx_set &)> accept_func); diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 1d3ba900d..338feb016 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -12969,4 +12969,14 @@ void wallet2::finish_rescan_bc_keep_key_images(uint64_t transfer_height, const c m_transfers[it->second].m_key_image_known = true; } } +//---------------------------------------------------------------------------------------------------- +uint64_t wallet2::get_bytes_sent() const +{ + return m_http_client.get_bytes_sent(); +} +//---------------------------------------------------------------------------------------------------- +uint64_t wallet2::get_bytes_received() const +{ + return m_http_client.get_bytes_received(); +} } diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 38cd68784..8e652d0ec 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1258,6 +1258,9 @@ namespace tools bool frozen(const crypto::key_image &ki) const; bool frozen(const transfer_details &td) const; + uint64_t get_bytes_sent() const; + uint64_t get_bytes_received() const; + // MMS ------------------------------------------------------------------------------------------------- mms::message_store& get_message_store() { return m_message_store; }; const mms::message_store& get_message_store() const { return m_message_store; }; |