simplewallet: new net_stats command

displays total sent and received bytes
release-v0.6.1.2
moneromooo-monero 5 years ago
parent 19e37c05d6
commit 9f8dc4ce51
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3

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

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

@ -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),

@ -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);

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

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

Loading…
Cancel
Save