diff options
author | Riccardo Spagni <ric@spagni.net> | 2015-05-20 14:36:04 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2015-05-20 14:36:07 +0200 |
commit | 38068d07ca8ac5e00afb72b4dce2294742ef680f (patch) | |
tree | 5fe223ef0927566948cefa06ac67b9c09839deb1 /src | |
parent | Merge pull request #287 (diff) | |
parent | s/terget/target/ (diff) | |
download | monero-38068d07ca8ac5e00afb72b4dce2294742ef680f.tar.xz |
Merge pull request #288
f278fe3 s/terget/target/ (moneromooo-monero)
d8ee0a9 print limits when running limit commands with no arguments (moneromooo-monero)
Diffstat (limited to 'src')
-rw-r--r-- | src/daemon/command_parser_executor.cpp | 15 | ||||
-rw-r--r-- | src/daemon/rpc_command_executor.cpp | 23 | ||||
-rw-r--r-- | src/daemon/rpc_command_executor.h | 6 | ||||
-rw-r--r-- | src/p2p/connection_basic.cpp | 21 | ||||
-rw-r--r-- | src/p2p/connection_basic.hpp | 2 | ||||
-rw-r--r-- | src/p2p/network_throttle-detail.cpp | 2 | ||||
-rw-r--r-- | src/p2p/network_throttle-detail.hpp | 2 | ||||
-rw-r--r-- | src/p2p/network_throttle.hpp | 2 |
8 files changed, 65 insertions, 8 deletions
diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp index fd7b40be2..1b86ff269 100644 --- a/src/daemon/command_parser_executor.cpp +++ b/src/daemon/command_parser_executor.cpp @@ -251,7 +251,10 @@ bool t_command_parser_executor::print_status(const std::vector<std::string>& arg bool t_command_parser_executor::set_limit(const std::vector<std::string>& args) { - if(args.size()!=1) return false; + if(args.size()>1) return false; + if(args.size()==0) { + return m_executor.get_limit(); + } int limit; try { limit = std::stoi(args[0]); @@ -267,7 +270,10 @@ bool t_command_parser_executor::set_limit(const std::vector<std::string>& args) bool t_command_parser_executor::set_limit_up(const std::vector<std::string>& args) { - if(args.size()!=1) return false; + if(args.size()>1) return false; + if(args.size()==0) { + return m_executor.get_limit_up(); + } int limit; try { limit = std::stoi(args[0]); @@ -283,7 +289,10 @@ bool t_command_parser_executor::set_limit_up(const std::vector<std::string>& arg bool t_command_parser_executor::set_limit_down(const std::vector<std::string>& args) { - if(args.size()!=1) return false; + if(args.size()>1) return false; + if(args.size()==0) { + return m_executor.get_limit_down(); + } int limit; try { limit = std::stoi(args[0]); diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index 8ef91600c..79b52711a 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -737,6 +737,15 @@ bool t_rpc_command_executor::print_status() return true; } +bool t_rpc_command_executor::get_limit() +{ + int limit_down = epee::net_utils::connection_basic::get_rate_down_limit( ); + int limit_up = epee::net_utils::connection_basic::get_rate_up_limit( ); + std::cout << "limit-down is " << limit_down/1024 << " kB/s" << std::endl; + std::cout << "limit-up is " << limit_up/1024 << " kB/s" << std::endl; + return true; +} + bool t_rpc_command_executor::set_limit(int limit) { epee::net_utils::connection_basic::set_rate_down_limit( limit ); @@ -746,6 +755,13 @@ bool t_rpc_command_executor::set_limit(int limit) return true; } +bool t_rpc_command_executor::get_limit_up() +{ + int limit_up = epee::net_utils::connection_basic::get_rate_up_limit( ); + std::cout << "limit-up is " << limit_up/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 ); @@ -753,6 +769,13 @@ bool t_rpc_command_executor::set_limit_up(int limit) return true; } +bool t_rpc_command_executor::get_limit_down() +{ + int limit_down = epee::net_utils::connection_basic::get_rate_down_limit( ); + std::cout << "limit-down is " << limit_down/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 ); diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h index 43b8a9fe0..21229c577 100644 --- a/src/daemon/rpc_command_executor.h +++ b/src/daemon/rpc_command_executor.h @@ -99,6 +99,12 @@ public: bool print_status(); + bool get_limit(); + + bool get_limit_up(); + + bool get_limit_down(); + bool set_limit(int limit); bool set_limit_up(int limit); diff --git a/src/p2p/connection_basic.cpp b/src/p2p/connection_basic.cpp index 0454f30e3..d3f6415c5 100644 --- a/src/p2p/connection_basic.cpp +++ b/src/p2p/connection_basic.cpp @@ -199,6 +199,23 @@ void connection_basic::set_rate_down_limit(uint64_t limit) { save_limit_to_file(limit); } +uint64_t connection_basic::get_rate_up_limit() { + uint64_t limit; + { + CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_out ); + limit = network_throttle_manager::get_global_throttle_out().get_target_speed(); + } + return limit; +} + +uint64_t connection_basic::get_rate_down_limit() { + uint64_t limit; + { + CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_in ); + limit = network_throttle_manager::get_global_throttle_in().get_target_speed(); + } + return limit; +} void connection_basic::save_limit_to_file(int limit) { // saving limit to file @@ -207,12 +224,12 @@ void connection_basic::save_limit_to_file(int limit) { { CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_out ); - epee::net_utils::data_logger::get_instance().add_data("upload_limit", network_throttle_manager::get_global_throttle_out().get_terget_speed() / 1024); + epee::net_utils::data_logger::get_instance().add_data("upload_limit", network_throttle_manager::get_global_throttle_out().get_target_speed() / 1024); } { CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_in ); - epee::net_utils::data_logger::get_instance().add_data("download_limit", network_throttle_manager::get_global_throttle_in().get_terget_speed() / 1024); + epee::net_utils::data_logger::get_instance().add_data("download_limit", network_throttle_manager::get_global_throttle_in().get_target_speed() / 1024); } } diff --git a/src/p2p/connection_basic.hpp b/src/p2p/connection_basic.hpp index d8101afe4..945cd982c 100644 --- a/src/p2p/connection_basic.hpp +++ b/src/p2p/connection_basic.hpp @@ -119,6 +119,8 @@ class connection_basic { // not-templated base class for rapid developmet of som static void set_rate_up_limit(uint64_t limit); static void set_rate_down_limit(uint64_t limit); + static uint64_t get_rate_up_limit(); + static uint64_t get_rate_down_limit(); // config misc static void set_tos_flag(int tos); // ToS / QoS flag diff --git a/src/p2p/network_throttle-detail.cpp b/src/p2p/network_throttle-detail.cpp index 6fa27b62a..6e6989d44 100644 --- a/src/p2p/network_throttle-detail.cpp +++ b/src/p2p/network_throttle-detail.cpp @@ -172,7 +172,7 @@ void network_throttle::set_real_target_speed( network_speed_kbps real_target ) m_real_target_speed = real_target * 1024; } -network_speed_kbps network_throttle::get_terget_speed() +network_speed_kbps network_throttle::get_target_speed() { return m_real_target_speed / 1024; } diff --git a/src/p2p/network_throttle-detail.hpp b/src/p2p/network_throttle-detail.hpp index 063dac850..9f0003332 100644 --- a/src/p2p/network_throttle-detail.hpp +++ b/src/p2p/network_throttle-detail.hpp @@ -81,7 +81,7 @@ class network_throttle : public i_network_throttle { virtual void set_name(const std::string &name); virtual void set_target_speed( network_speed_kbps target ); virtual void set_real_target_speed( network_speed_kbps real_target ); // only for throttle_out - virtual network_speed_kbps get_terget_speed(); + virtual network_speed_kbps get_target_speed(); // add information about events: virtual void handle_trafic_exact(size_t packet_size); ///< count the new traffic/packet; the size is exact considering all network costs diff --git a/src/p2p/network_throttle.hpp b/src/p2p/network_throttle.hpp index add4daa86..b93cfc563 100644 --- a/src/p2p/network_throttle.hpp +++ b/src/p2p/network_throttle.hpp @@ -147,7 +147,7 @@ class i_network_throttle { virtual void set_name(const std::string &name)=0; virtual void set_target_speed( network_speed_kbps target )=0; virtual void set_real_target_speed(network_speed_kbps real_target)=0; - virtual network_speed_kbps get_terget_speed()=0; + virtual network_speed_kbps get_target_speed()=0; virtual void handle_trafic_exact(size_t packet_size) =0; // count the new traffic/packet; the size is exact considering all network costs virtual void handle_trafic_tcp(size_t packet_size) =0; // count the new traffic/packet; the size is as TCP, we will consider MTU etc |