From 4abf25f3c901016803515771cc19997d9a95bacb Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 29 Nov 2017 22:53:58 +0000 Subject: cryptonote_core does not depend on p2p anymore As a followon side effect, this makes a lot of inline code included only in particular cpp files (and instanciated when necessary. --- src/cryptonote_core/cryptonote_core.cpp | 16 ++---- src/cryptonote_core/cryptonote_core.h | 3 +- .../cryptonote_protocol_handler.h | 6 -- .../cryptonote_protocol_handler.inl | 4 +- src/daemon/CMakeLists.txt | 1 - src/daemon/core.h | 15 ++++- src/daemon/main.cpp | 1 + src/p2p/net_node.cpp | 65 ++++++++++++++++++++++ src/p2p/net_node.h | 33 ++++++++--- src/p2p/net_node.inl | 37 +----------- src/p2p/net_peerlist.h | 2 - src/rpc/CMakeLists.txt | 3 +- src/rpc/core_rpc_server.cpp | 2 + src/rpc/instanciations.cpp | 37 ++++++++++++ 14 files changed, 154 insertions(+), 71 deletions(-) create mode 100644 src/p2p/net_node.cpp create mode 100644 src/rpc/instanciations.cpp (limited to 'src') diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 04f1e46a7..1976ee0bc 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -45,11 +45,11 @@ using namespace epee; #include "cryptonote_tx_utils.h" #include "misc_language.h" #include -#include #include "checkpoints/checkpoints.h" #include "ringct/rctTypes.h" #include "blockchain_db/blockchain_db.h" #include "ringct/rctSigs.h" +#include "version.h" #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "cn" @@ -233,10 +233,6 @@ namespace cryptonote command_line::add_arg(desc, arg_test_dbg_lock_sleep); command_line::add_arg(desc, arg_offline); - // we now also need some of net_node's options (p2p bind arg, for separate data dir) - command_line::add_arg(desc, nodetool::arg_testnet_p2p_bind_port, false); - command_line::add_arg(desc, nodetool::arg_p2p_bind_port, false); - miner::init_options(desc); BlockchainDB::init_options(desc); } @@ -335,21 +331,17 @@ namespace cryptonote return m_blockchain_storage.get_alternative_blocks_count(); } //----------------------------------------------------------------------------------------------- - bool core::init(const boost::program_options::variables_map& vm, const cryptonote::test_options *test_options) + bool core::init(const boost::program_options::variables_map& vm, const char *config_subdir, const cryptonote::test_options *test_options) { start_time = std::time(nullptr); m_fakechain = test_options != NULL; bool r = handle_command_line(vm); bool testnet = command_line::get_arg(vm, arg_testnet_on); - auto p2p_bind_arg = testnet ? nodetool::arg_testnet_p2p_bind_port : nodetool::arg_p2p_bind_port; - std::string m_port = command_line::get_arg(vm, p2p_bind_arg); std::string m_config_folder_mempool = m_config_folder; - if ((!testnet && m_port != std::to_string(::config::P2P_DEFAULT_PORT)) - || (testnet && m_port != std::to_string(::config::testnet::P2P_DEFAULT_PORT))) { - m_config_folder_mempool = m_config_folder_mempool + "/" + m_port; - } + if (config_subdir) + m_config_folder_mempool = m_config_folder_mempool + "/" + config_subdir; std::string db_type = command_line::get_arg(vm, cryptonote::arg_db_type); std::string db_sync_mode = command_line::get_arg(vm, cryptonote::arg_db_sync_mode); diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index 6cb4fc938..c8cd671c4 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -242,11 +242,12 @@ namespace cryptonote * a miner instance with parameters given on the command line (or defaults) * * @param vm command line parameters + * @param config_subdir subdirectory for config storage * @param test_options configuration options for testing * * @return false if one of the init steps fails, otherwise true */ - bool init(const boost::program_options::variables_map& vm, const test_options *test_options = NULL); + bool init(const boost::program_options::variables_map& vm, const char *config_subdir = NULL, const test_options *test_options = NULL); /** * @copydoc Blockchain::reset_and_set_genesis_block diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.h b/src/cryptonote_protocol/cryptonote_protocol_handler.h index d54687e6a..f61caf69b 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.h +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.h @@ -36,7 +36,6 @@ #include #include -#include #include "math_helper.h" #include "storages/levin_abstract_invoke2.h" @@ -46,8 +45,6 @@ #include "block_queue.h" #include "cryptonote_basic/connection_context.h" #include "cryptonote_basic/cryptonote_stat_info.h" -#include "cryptonote_basic/verification_context.h" -// #include #include PUSH_WARNINGS @@ -173,7 +170,4 @@ namespace cryptonote } // namespace - -#include "cryptonote_protocol_handler.inl" - POP_WARNINGS diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index 48ab1eadf..4ba406ffc 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -37,7 +37,7 @@ #include #include -#include +#include #include "cryptonote_basic/cryptonote_format_utils.h" #include "profile_tools.h" @@ -1561,7 +1561,7 @@ skip: size_t t_cryptonote_protocol_handler::get_synchronizing_connections_count() { size_t count = 0; - m_p2p->for_each_connection([&](cryptonote_connection_context& context, nodetool::peerid_type peer_id)->bool{ + m_p2p->for_each_connection([&](cryptonote_connection_context& context, nodetool::peerid_type peer_id, uint32_t support_flags)->bool{ if(context.m_state == cryptonote_connection_context::state_synchronizing) ++count; return true; diff --git a/src/daemon/CMakeLists.txt b/src/daemon/CMakeLists.txt index 2f9c2b2f9..298965e10 100644 --- a/src/daemon/CMakeLists.txt +++ b/src/daemon/CMakeLists.txt @@ -67,7 +67,6 @@ set(daemon_private_headers # p2p ../p2p/net_node.h - ../p2p/net_node.inl ../p2p/net_node_common.h ../p2p/net_peerlist.h ../p2p/net_peerlist_boost_serialization.h diff --git a/src/daemon/core.h b/src/daemon/core.h index 9e6ff5e29..97f1cb8c1 100644 --- a/src/daemon/core.h +++ b/src/daemon/core.h @@ -67,11 +67,24 @@ public: m_core.set_cryptonote_protocol(&protocol); } + std::string get_config_subdir() const + { + bool testnet = command_line::get_arg(m_vm_HACK, cryptonote::arg_testnet_on); + auto p2p_bind_arg = testnet ? nodetool::arg_testnet_p2p_bind_port : nodetool::arg_p2p_bind_port; + std::string port = command_line::get_arg(m_vm_HACK, p2p_bind_arg); + if ((!testnet && port != std::to_string(::config::P2P_DEFAULT_PORT)) + || (testnet && port != std::to_string(::config::testnet::P2P_DEFAULT_PORT))) { + return port; + } + return std::string(); + } + bool run() { //initialize core here MGINFO("Initializing core..."); - if (!m_core.init(m_vm_HACK)) + std::string config_subdir = get_config_subdir(); + if (!m_core.init(m_vm_HACK, config_subdir.empty() ? NULL : config_subdir.c_str())) { return false; } diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp index d038cc825..6ac47fcb2 100644 --- a/src/daemon/main.cpp +++ b/src/daemon/main.cpp @@ -44,6 +44,7 @@ #include "rpc/rpc_args.h" #include "daemon/command_line_args.h" #include "blockchain_db/db_types.h" +#include "version.h" #ifdef STACK_TRACE #include "common/stack_trace.h" diff --git a/src/p2p/net_node.cpp b/src/p2p/net_node.cpp new file mode 100644 index 000000000..4ea08a1f8 --- /dev/null +++ b/src/p2p/net_node.cpp @@ -0,0 +1,65 @@ +// Copyright (c) 2014-2017, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + +#include "common/command_line.h" +#include "net_node.h" + +namespace nodetool +{ + const command_line::arg_descriptor arg_p2p_bind_ip = {"p2p-bind-ip", "Interface for p2p network protocol", "0.0.0.0"}; + const command_line::arg_descriptor arg_p2p_bind_port = { + "p2p-bind-port" + , "Port for p2p network protocol" + , std::to_string(config::P2P_DEFAULT_PORT) + }; + const command_line::arg_descriptor arg_testnet_p2p_bind_port = { + "testnet-p2p-bind-port" + , "Port for testnet p2p network protocol" + , std::to_string(config::testnet::P2P_DEFAULT_PORT) + }; + const command_line::arg_descriptor arg_p2p_external_port = {"p2p-external-port", "External port for p2p network protocol (if port forwarding used with NAT)", 0}; + const command_line::arg_descriptor arg_p2p_allow_local_ip = {"allow-local-ip", "Allow local ip add to peer list, mostly in debug purposes"}; + const command_line::arg_descriptor > arg_p2p_add_peer = {"add-peer", "Manually add peer to local peerlist"}; + const command_line::arg_descriptor > arg_p2p_add_priority_node = {"add-priority-node", "Specify list of peers to connect to and attempt to keep the connection open"}; + const command_line::arg_descriptor > arg_p2p_add_exclusive_node = {"add-exclusive-node", "Specify list of peers to connect to only." + " If this option is given the options add-priority-node and seed-node are ignored"}; + const command_line::arg_descriptor > arg_p2p_seed_node = {"seed-node", "Connect to a node to retrieve peer addresses, and disconnect"}; + const command_line::arg_descriptor arg_p2p_hide_my_port = {"hide-my-port", "Do not announce yourself as peerlist candidate", false, true}; + + const command_line::arg_descriptor arg_no_igd = {"no-igd", "Disable UPnP port mapping"}; + const command_line::arg_descriptor arg_out_peers = {"out-peers", "set max number of out peers", -1}; + const command_line::arg_descriptor arg_tos_flag = {"tos-flag", "set TOS flag", -1}; + + const command_line::arg_descriptor arg_limit_rate_up = {"limit-rate-up", "set limit-rate-up [kB/s]", -1}; + const command_line::arg_descriptor arg_limit_rate_down = {"limit-rate-down", "set limit-rate-down [kB/s]", -1}; + const command_line::arg_descriptor arg_limit_rate = {"limit-rate", "set limit-rate [kB/s]", -1}; + + const command_line::arg_descriptor arg_save_graph = {"save-graph", "Save data for dr monero", false}; +} diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index 8bbaa9138..294ccde9e 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -30,13 +30,6 @@ #pragma once #include -#include -#include -#include -#include -#include -#include -#include #include #include #include @@ -335,8 +328,30 @@ namespace nodetool bool m_testnet; }; -} -#include "net_node.inl" + const int64_t default_limit_up = 2048; + const int64_t default_limit_down = 8192; + extern const command_line::arg_descriptor arg_p2p_bind_ip; + extern const command_line::arg_descriptor arg_p2p_bind_port; + extern const command_line::arg_descriptor arg_testnet_p2p_bind_port; + extern const command_line::arg_descriptor arg_p2p_external_port; + extern const command_line::arg_descriptor arg_p2p_allow_local_ip; + extern const command_line::arg_descriptor > arg_p2p_add_peer; + extern const command_line::arg_descriptor > arg_p2p_add_priority_node; + extern const command_line::arg_descriptor > arg_p2p_add_exclusive_node; + extern const command_line::arg_descriptor > arg_p2p_seed_node; + extern const command_line::arg_descriptor arg_p2p_hide_my_port; + + extern const command_line::arg_descriptor arg_no_igd; + extern const command_line::arg_descriptor arg_offline; + extern const command_line::arg_descriptor arg_out_peers; + extern const command_line::arg_descriptor arg_tos_flag; + + extern const command_line::arg_descriptor arg_limit_rate_up; + extern const command_line::arg_descriptor arg_limit_rate_down; + extern const command_line::arg_descriptor arg_limit_rate; + + extern const command_line::arg_descriptor arg_save_graph; +} POP_WARNINGS diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index c6792f138..55be7c2cb 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -30,11 +30,10 @@ // IP blocking adapted from Boolberry -#pragma once - #include #include #include +#include #include #include "version.h" @@ -70,40 +69,6 @@ namespace nodetool { - namespace - { - const int64_t default_limit_up = 2048; // kB/s - const int64_t default_limit_down = 8192; // kB/s - const command_line::arg_descriptor arg_p2p_bind_ip = {"p2p-bind-ip", "Interface for p2p network protocol", "0.0.0.0"}; - const command_line::arg_descriptor arg_p2p_bind_port = { - "p2p-bind-port" - , "Port for p2p network protocol" - , std::to_string(config::P2P_DEFAULT_PORT) - }; - const command_line::arg_descriptor arg_testnet_p2p_bind_port = { - "testnet-p2p-bind-port" - , "Port for testnet p2p network protocol" - , std::to_string(config::testnet::P2P_DEFAULT_PORT) - }; - const command_line::arg_descriptor arg_p2p_external_port = {"p2p-external-port", "External port for p2p network protocol (if port forwarding used with NAT)", 0}; - const command_line::arg_descriptor arg_p2p_allow_local_ip = {"allow-local-ip", "Allow local ip add to peer list, mostly in debug purposes"}; - const command_line::arg_descriptor > arg_p2p_add_peer = {"add-peer", "Manually add peer to local peerlist"}; - const command_line::arg_descriptor > arg_p2p_add_priority_node = {"add-priority-node", "Specify list of peers to connect to and attempt to keep the connection open"}; - const command_line::arg_descriptor > arg_p2p_add_exclusive_node = {"add-exclusive-node", "Specify list of peers to connect to only." - " If this option is given the options add-priority-node and seed-node are ignored"}; - const command_line::arg_descriptor > arg_p2p_seed_node = {"seed-node", "Connect to a node to retrieve peer addresses, and disconnect"}; - const command_line::arg_descriptor arg_p2p_hide_my_port = {"hide-my-port", "Do not announce yourself as peerlist candidate", false, true}; - - const command_line::arg_descriptor arg_no_igd = {"no-igd", "Disable UPnP port mapping"}; - const command_line::arg_descriptor arg_out_peers = {"out-peers", "set max number of out peers", -1}; - const command_line::arg_descriptor arg_tos_flag = {"tos-flag", "set TOS flag", -1}; - - const command_line::arg_descriptor arg_limit_rate_up = {"limit-rate-up", "set limit-rate-up [kB/s]", -1}; - const command_line::arg_descriptor arg_limit_rate_down = {"limit-rate-down", "set limit-rate-down [kB/s]", -1}; - const command_line::arg_descriptor arg_limit_rate = {"limit-rate", "set limit-rate [kB/s]", -1}; - - const command_line::arg_descriptor arg_save_graph = {"save-graph", "Save data for dr monero", false}; - } //----------------------------------------------------------------------------------- template void node_server::init_options(boost::program_options::options_description& desc) diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h index 8372445aa..8216e9be6 100644 --- a/src/p2p/net_peerlist.h +++ b/src/p2p/net_peerlist.h @@ -33,8 +33,6 @@ #include #include #include -//#include -//#include #include #include #include diff --git a/src/rpc/CMakeLists.txt b/src/rpc/CMakeLists.txt index 23bb6aaae..652a03f44 100644 --- a/src/rpc/CMakeLists.txt +++ b/src/rpc/CMakeLists.txt @@ -28,7 +28,8 @@ set(rpc_sources core_rpc_server.cpp - rpc_args.cpp) + rpc_args.cpp + instanciations) set(daemon_messages_sources message.cpp diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index c2206c89a..f054b3ce0 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -44,6 +44,8 @@ using namespace epee; #include "crypto/hash.h" #include "rpc/rpc_args.h" #include "core_rpc_server_error_codes.h" +#include "p2p/net_node.h" +#include "version.h" #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "daemon.rpc" diff --git a/src/rpc/instanciations.cpp b/src/rpc/instanciations.cpp new file mode 100644 index 000000000..ac521247e --- /dev/null +++ b/src/rpc/instanciations.cpp @@ -0,0 +1,37 @@ +// Copyright (c) 2017, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + +#include "p2p/net_node.h" +#include "p2p/net_node.inl" +#include "cryptonote_protocol/cryptonote_protocol_handler.h" +#include "cryptonote_protocol/cryptonote_protocol_handler.inl" + +namespace nodetool { template class node_server>; } +namespace cryptonote { template class t_cryptonote_protocol_handler; } -- cgit v1.2.3 From bb89ae8b2058d98a764f24e17e6c58089dd548f0 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 29 Nov 2017 19:30:06 +0000 Subject: move connection_basic and network_throttle from src/p2p to epee These even had the epee namespace. This fixes some ugly circular dependencies. --- contrib/epee/include/net/abstract_tcp_server2.h | 4 +- contrib/epee/include/net/connection_basic.hpp | 141 ++++++++ .../epee/include/net/network_throttle-detail.hpp | 125 +++++++ contrib/epee/include/net/network_throttle.hpp | 176 ++++++++++ contrib/epee/src/CMakeLists.txt | 3 +- contrib/epee/src/connection_basic.cpp | 290 ++++++++++++++++ contrib/epee/src/network_throttle-detail.cpp | 369 +++++++++++++++++++++ contrib/epee/src/network_throttle.cpp | 113 +++++++ .../cryptonote_protocol_handler-base.cpp | 2 +- .../cryptonote_protocol_handler.inl | 2 +- src/debug_utilities/object_sizes.cpp | 2 +- src/p2p/connection_basic.cpp | 290 ---------------- src/p2p/connection_basic.hpp | 141 -------- src/p2p/network_throttle-detail.cpp | 369 --------------------- src/p2p/network_throttle-detail.hpp | 125 ------- src/p2p/network_throttle.cpp | 113 ------- src/p2p/network_throttle.hpp | 176 ---------- 17 files changed, 1221 insertions(+), 1220 deletions(-) create mode 100644 contrib/epee/include/net/connection_basic.hpp create mode 100644 contrib/epee/include/net/network_throttle-detail.hpp create mode 100644 contrib/epee/include/net/network_throttle.hpp create mode 100644 contrib/epee/src/connection_basic.cpp create mode 100644 contrib/epee/src/network_throttle-detail.cpp create mode 100644 contrib/epee/src/network_throttle.cpp delete mode 100644 src/p2p/connection_basic.cpp delete mode 100644 src/p2p/connection_basic.hpp delete mode 100644 src/p2p/network_throttle-detail.cpp delete mode 100644 src/p2p/network_throttle-detail.hpp delete mode 100644 src/p2p/network_throttle.cpp delete mode 100644 src/p2p/network_throttle.hpp (limited to 'src') diff --git a/contrib/epee/include/net/abstract_tcp_server2.h b/contrib/epee/include/net/abstract_tcp_server2.h index 33fec8ec5..c0401c8b0 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.h +++ b/contrib/epee/include/net/abstract_tcp_server2.h @@ -54,8 +54,8 @@ #include #include "net_utils_base.h" #include "syncobj.h" -#include "../../../../src/p2p/connection_basic.hpp" -#include "../../../../src/p2p/network_throttle-detail.hpp" +#include "connection_basic.hpp" +#include "network_throttle-detail.hpp" #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "net" diff --git a/contrib/epee/include/net/connection_basic.hpp b/contrib/epee/include/net/connection_basic.hpp new file mode 100644 index 000000000..16de469a7 --- /dev/null +++ b/contrib/epee/include/net/connection_basic.hpp @@ -0,0 +1,141 @@ +/// @file +/// @author rfree (current maintainer in monero.cc project) +/// @brief base for connection, contains e.g. the ratelimit hooks + +// ! This file might contain variable names same as in template class connection<> +// ! from files contrib/epee/include/net/abstract_tcp_server2.* +// ! I am not a lawyer; afaik APIs, var names etc are not copyrightable ;) +// ! (how ever if in some wonderful juristdictions that is not the case, then why not make another sub-class withat that members and licence it as epee part) +// ! Working on above premise, IF this is valid in your juristdictions, then consider this code as released as: + +// Copyright (c) 2014-2017, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/* rfree: place for hanlers for the non-template base, can be used by connection<> template class in abstract_tcp_server2 file */ + +#ifndef INCLUDED_p2p_connection_basic_hpp +#define INCLUDED_p2p_connection_basic_hpp + + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "net/net_utils_base.h" +#include "syncobj.h" + +namespace epee +{ +namespace net_utils +{ + + /************************************************************************/ + /* */ + /************************************************************************/ + /// Represents a single connection from a client. + +class connection_basic_pimpl; // PIMPL for this class + + enum t_connection_type { // type of the connection (of this server), e.g. so that we will know how to limit it + e_connection_type_NET = 0, // default (not used?) + e_connection_type_RPC = 1, // the rpc commands (probably not rate limited, not chunked, etc) + e_connection_type_P2P = 2 // to other p2p node (probably limited) + }; + + std::string to_string(t_connection_type type); + +class connection_basic { // not-templated base class for rapid developmet of some code parts + public: + std::unique_ptr< connection_basic_pimpl > mI; // my Implementation + + // moved here from orginal connecton<> - common member variables that do not depend on template in connection<> + volatile uint32_t m_want_close_connection; + std::atomic m_was_shutdown; + critical_section m_send_que_lock; + std::list m_send_que; + volatile bool m_is_multithreaded; + double m_start_time; + /// Strand to ensure the connection's handlers are not called concurrently. + boost::asio::io_service::strand strand_; + /// Socket for the connection. + boost::asio::ip::tcp::socket socket_; + + std::atomic &m_ref_sock_count; // reference to external counter of existing sockets that we will ++/-- + public: + // first counter is the ++/-- count of current sockets, the other socket_number is only-increasing ++ number generator + connection_basic(boost::asio::io_service& io_service, std::atomic &ref_sock_count, std::atomic &sock_number); + + virtual ~connection_basic() noexcept(false); + + // various handlers to be called from connection class: + void do_send_handler_write(const void * ptr , size_t cb); + void do_send_handler_write_from_queue(const boost::system::error_code& e, size_t cb , int q_len); // from handle_write, sending next part + + void logger_handle_net_write(size_t size); // network data written + void logger_handle_net_read(size_t size); // network data read + + void set_start_time(); + + // config for rate limit + + 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 + static int get_tos_flag(); + + // handlers and sleep + void sleep_before_packet(size_t packet_size, int phase, int q_len); // execute a sleep ; phase is not really used now(?) + static void save_limit_to_file(int limit); ///< for dr-monero + static double get_sleep_time(size_t cb); + + static void set_save_graph(bool save_graph); +}; + +} // nameserver +} // nameserver + +#endif + + diff --git a/contrib/epee/include/net/network_throttle-detail.hpp b/contrib/epee/include/net/network_throttle-detail.hpp new file mode 100644 index 000000000..dba15a5ed --- /dev/null +++ b/contrib/epee/include/net/network_throttle-detail.hpp @@ -0,0 +1,125 @@ +/// @file +/// @author rfree (current maintainer in monero.cc project) +/// @brief implementaion for throttling of connection (count and rate-limit speed etc) + +// Copyright (c) 2014-2017, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/* rfree: throttle details, implementing rate limiting */ + + +#ifndef INCLUDED_throttle_detail_hpp +#define INCLUDED_throttle_detail_hpp + +#include "network_throttle.hpp" + +namespace epee +{ +namespace net_utils +{ + + +class network_throttle : public i_network_throttle { + private: + struct packet_info { + size_t m_size; // octets sent. Summary for given small-window (e.g. for all packaged in 1 second) + packet_info(); + }; + + + network_speed_bps m_target_speed; + size_t m_network_add_cost; // estimated add cost of headers + size_t m_network_minimal_segment; // estimated minimal cost of sending 1 byte to round up to + size_t m_network_max_segment; // recommended max size of 1 TCP transmission + + const size_t m_window_size; // the number of samples to average over + network_time_seconds m_slot_size; // the size of one slot. TODO: now hardcoded for 1 second e.g. in time_to_slot() + // TODO for big window size, for performance better the substract on change of m_last_sample_time instead of recalculating average of eg >100 elements + + std::vector< packet_info > m_history; // the history of bw usage + network_time_seconds m_last_sample_time; // time of last history[0] - so we know when to rotate the buffer + network_time_seconds m_start_time; // when we were created + bool m_any_packet_yet; // did we yet got any packet to count + + std::string m_name; // my name for debug and logs + std::string m_nameshort; // my name for debug and logs (used in log file name) + + // each sample is now 1 second + public: + network_throttle(const std::string &nameshort, const std::string &name, int window_size=-1); + virtual ~network_throttle(); + virtual void set_name(const std::string &name); + virtual void set_target_speed( network_speed_kbps target ); + 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 + virtual void handle_trafic_tcp(size_t packet_size); ///< count the new traffic/packet; the size is as TCP, we will consider MTU etc + + virtual void tick(); ///< poke and update timers/history (recalculates, moves the history if needed, checks the real clock etc) + + virtual double get_time_seconds() const ; ///< timer that we use, time in seconds, monotionic + + // time calculations: + virtual void calculate_times(size_t packet_size, calculate_times_struct &cts, bool dbg, double force_window) const; ///< MAIN LOGIC (see base class for info) + + virtual network_time_seconds get_sleep_time_after_tick(size_t packet_size); ///< increase the timer if needed, and get the package size + virtual network_time_seconds get_sleep_time(size_t packet_size) const; ///< gets the Delay (recommended Delay time) from calc. (not safe: only if time didnt change?) TODO + + virtual size_t get_recommended_size_of_planned_transport() const; ///< what should be the size (bytes) of next data block to be transported + virtual size_t get_recommended_size_of_planned_transport_window(double force_window) const; ///< ditto, but for given windows time frame + virtual double get_current_speed() const; + + private: + virtual network_time_seconds time_to_slot(network_time_seconds t) const { return std::floor( t ); } // convert exact time eg 13.7 to rounded time for slot number in history 13 + virtual void _handle_trafic_exact(size_t packet_size, size_t orginal_size); + virtual void logger_handle_net(const std::string &filename, double time, size_t size); +}; + +/*** + * The complete set of traffic throttle for one typical connection +*/ +struct network_throttle_bw { + public: + network_throttle m_in; ///< for incomming traffic (this we can not controll directly as it depends of what others send to us - usually) + network_throttle m_inreq; ///< for requesting incomming traffic (this is exact usually) + network_throttle m_out; ///< for outgoing traffic that we just sent (this is exact usually) + + public: + network_throttle_bw(const std::string &name1); +}; + + + +} // namespace net_utils +} // namespace epee + + +#endif + + diff --git a/contrib/epee/include/net/network_throttle.hpp b/contrib/epee/include/net/network_throttle.hpp new file mode 100644 index 000000000..464b34726 --- /dev/null +++ b/contrib/epee/include/net/network_throttle.hpp @@ -0,0 +1,176 @@ +/// @file +/// @author rfree (current maintainer in monero.cc project) +/// @brief interface for throttling of connection (count and rate-limit speed etc) + +// Copyright (c) 2014-2017, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/* rfree: throttle basic interface */ +/* rfree: also includes the manager for singeton/global such objects */ + + +#ifndef INCLUDED_network_throttle_hpp +#define INCLUDED_network_throttle_hpp + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "syncobj.h" + +#include "net/net_utils_base.h" +#include "misc_log_ex.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "misc_language.h" +#include "pragma_comp_defs.h" +#include +#include +#include + +#include +#include +#include + +namespace epee +{ +namespace net_utils +{ + +// just typedefs to in code define the units used. TODO later it will be enforced that casts to other numericals are only explicit to avoid mistakes? use boost::chrono? +typedef double network_speed_kbps; // externally, for parameters and return values, all defined in kilobytes per second +typedef double network_speed_bps; // throttle-internally, bytes per second +typedef double network_time_seconds; +typedef double network_MB; + +class i_network_throttle; + +/*** +@brief All information about given throttle - speed calculations +*/ +struct calculate_times_struct { + double average; + double window; + double delay; + double recomendetDataSize; +}; +typedef calculate_times_struct calculate_times_struct; + + +namespace cryptonote { class cryptonote_protocol_handler_base; } // a friend class // TODO friend not working + +/*** +@brief Access to simple throttles, with singlton to access global network limits +*/ +class network_throttle_manager { + // provides global (singleton) in/inreq/out throttle access + + // [[note1]] see also http://www.nuonsoft.com/blog/2012/10/21/implementing-a-thread-safe-singleton-with-c11/ + // [[note2]] _inreq is the requested in traffic - we anticipate we will get in-bound traffic soon as result of what we do (e.g. that we sent network downloads requests) + + //protected: + public: // XXX + + static boost::mutex m_lock_get_global_throttle_in; + static boost::mutex m_lock_get_global_throttle_inreq; + static boost::mutex m_lock_get_global_throttle_out; + + friend class cryptonote::cryptonote_protocol_handler_base; // FRIEND - to directly access global throttle-s. !! REMEMBER TO USE LOCKS! + friend class connection_basic; // FRIEND - to directly access global throttle-s. !! REMEMBER TO USE LOCKS! + friend class connection_basic_pimpl; // ditto + + static int xxx; + + public: + static i_network_throttle & get_global_throttle_in(); ///< singleton ; for friend class ; caller MUST use proper locks! like m_lock_get_global_throttle_in + static i_network_throttle & get_global_throttle_inreq(); ///< ditto ; use lock ... use m_lock_get_global_throttle_inreq obviously + static i_network_throttle & get_global_throttle_out(); ///< ditto ; use lock ... use m_lock_get_global_throttle_out obviously +}; + + + +/*** +@brief interface for the throttle, see the derivated class +*/ +class i_network_throttle { + public: + virtual void set_name(const std::string &name)=0; + virtual void set_target_speed( network_speed_kbps target )=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 + virtual void tick() =0; // poke and update timers/history + + // time calculations: + + virtual void calculate_times(size_t packet_size, calculate_times_struct &cts, bool dbg, double force_window) const =0; // assuming sending new package (or 0), calculate: + // Average, Window, Delay, Recommended data size ; also gets dbg=debug flag, and forced widnow size if >0 or -1 for not forcing window size + + // Average speed, Window size, recommended Delay to sleep now, Recommended size of data to send now + + virtual network_time_seconds get_sleep_time(size_t packet_size) const =0; // gets the D (recommended Delay time) from calc + virtual network_time_seconds get_sleep_time_after_tick(size_t packet_size) =0; // ditto, but first tick the timer + + virtual size_t get_recommended_size_of_planned_transport() const =0; // what should be the recommended limit of data size that we can transport over current network_throttle in near future + + virtual double get_time_seconds() const =0; // a timer + virtual void logger_handle_net(const std::string &filename, double time, size_t size)=0; + + +}; + + +// ... more in the -advanced.h file + + +} // namespace net_utils +} // namespace epee + + +#endif + + + diff --git a/contrib/epee/src/CMakeLists.txt b/contrib/epee/src/CMakeLists.txt index 5cd6d7813..b6967e8fc 100644 --- a/contrib/epee/src/CMakeLists.txt +++ b/contrib/epee/src/CMakeLists.txt @@ -26,7 +26,8 @@ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -add_library(epee STATIC hex.cpp http_auth.cpp mlog.cpp net_utils_base.cpp string_tools.cpp wipeable_string.cpp) +add_library(epee STATIC hex.cpp http_auth.cpp mlog.cpp net_utils_base.cpp string_tools.cpp wipeable_string.cpp + connection_basic.cpp network_throttle.cpp network_throttle-detail.cpp) if (USE_READLINE AND GNU_READLINE_FOUND) add_library(epee_readline STATIC readline_buffer.cpp) endif() diff --git a/contrib/epee/src/connection_basic.cpp b/contrib/epee/src/connection_basic.cpp new file mode 100644 index 000000000..534044a79 --- /dev/null +++ b/contrib/epee/src/connection_basic.cpp @@ -0,0 +1,290 @@ +/// @file +/// @author rfree (current maintainer in monero.cc project) +/// @brief base for connection, contains e.g. the ratelimit hooks + +// Copyright (c) 2014-2017, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +/* rfree: implementation for the non-template base, can be used by connection<> template class in abstract_tcp_server2 file */ + +#include "net/connection_basic.hpp" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "syncobj.h" + +#include "net/net_utils_base.h" +#include "misc_log_ex.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "misc_language.h" +#include "pragma_comp_defs.h" +#include +#include +#include +#include +#include + +#include +#include +#include "net/abstract_tcp_server2.h" + +// TODO: +#include "net/network_throttle-detail.hpp" +#include "cryptonote_core/cryptonote_core.h" + +#undef MONERO_DEFAULT_LOG_CATEGORY +#define MONERO_DEFAULT_LOG_CATEGORY "net.p2p" + +// ################################################################################################ +// local (TU local) headers +// ################################################################################################ + +namespace epee +{ +namespace net_utils +{ + + std::string to_string(t_connection_type type) + { + if (type == e_connection_type_NET) + return std::string("NET"); + else if (type == e_connection_type_RPC) + return std::string("RPC"); + else if (type == e_connection_type_P2P) + return std::string("P2P"); + + return std::string("UNKNOWN"); + } + + +/* ============================================================================ */ + +class connection_basic_pimpl { + public: + connection_basic_pimpl(const std::string &name); + + static int m_default_tos; + + network_throttle_bw m_throttle; // per-perr + critical_section m_throttle_lock; + + int m_peer_number; // e.g. for debug/stats +}; + + +} // namespace +} // namespace + +// ################################################################################################ +// The implementation part +// ################################################################################################ + +namespace epee +{ +namespace net_utils +{ + +// ================================================================================================ +// connection_basic_pimpl +// ================================================================================================ + +connection_basic_pimpl::connection_basic_pimpl(const std::string &name) : m_throttle(name) { } + +// ================================================================================================ +// connection_basic +// ================================================================================================ + +// static variables: +int connection_basic_pimpl::m_default_tos; + +// methods: +connection_basic::connection_basic(boost::asio::io_service& io_service, std::atomic &ref_sock_count, std::atomic &sock_number) + : + mI( new connection_basic_pimpl("peer") ), + strand_(io_service), + socket_(io_service), + m_want_close_connection(false), + m_was_shutdown(false), + m_ref_sock_count(ref_sock_count) +{ + ++ref_sock_count; // increase the global counter + mI->m_peer_number = sock_number.fetch_add(1); // use, and increase the generated number + + std::string remote_addr_str = "?"; + try { boost::system::error_code e; remote_addr_str = socket_.remote_endpoint(e).address().to_string(); } catch(...){} ; + + _note("Spawned connection p2p#"<m_peer_number<<" to " << remote_addr_str << " currently we have sockets count:" << m_ref_sock_count); + //boost::filesystem::create_directories("log/dr-monero/net/"); +} + +connection_basic::~connection_basic() noexcept(false) { + std::string remote_addr_str = "?"; + m_ref_sock_count--; + try { boost::system::error_code e; remote_addr_str = socket_.remote_endpoint(e).address().to_string(); } catch(...){} ; + _note("Destructing connection p2p#"<m_peer_number << " to " << remote_addr_str); +} + +void connection_basic::set_rate_up_limit(uint64_t limit) { + { + CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_out ); + network_throttle_manager::get_global_throttle_out().set_target_speed(limit); + } + save_limit_to_file(limit); +} + +void connection_basic::set_rate_down_limit(uint64_t limit) { + { + CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_in ); + network_throttle_manager::get_global_throttle_in().set_target_speed(limit); + } + + { + CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_inreq ); + network_throttle_manager::get_global_throttle_inreq().set_target_speed(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) { +} + +void connection_basic::set_tos_flag(int tos) { + connection_basic_pimpl::m_default_tos = tos; +} + +int connection_basic::get_tos_flag() { + return connection_basic_pimpl::m_default_tos; +} + +void connection_basic::sleep_before_packet(size_t packet_size, int phase, int q_len) { + double delay=0; // will be calculated + do + { // rate limiting + if (m_was_shutdown) { + _dbg2("m_was_shutdown - so abort sleep"); + return; + } + + { + CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_out ); + delay = network_throttle_manager::get_global_throttle_out().get_sleep_time_after_tick( packet_size ); + } + + delay *= 0.50; + if (delay > 0) { + long int ms = (long int)(delay * 1000); + MTRACE("Sleeping in " << __FUNCTION__ << " for " << ms << " ms before packet_size="< 0); + +// XXX LATER XXX + { + CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_out ); + network_throttle_manager::get_global_throttle_out().handle_trafic_exact( packet_size ); // increase counter - global + } + +} +void connection_basic::set_start_time() { + CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_out ); + m_start_time = network_throttle_manager::get_global_throttle_out().get_time_seconds(); +} + +void connection_basic::do_send_handler_write(const void* ptr , size_t cb ) { + // No sleeping here; sleeping is done once and for all in connection::handle_write + MTRACE("handler_write (direct) - before ASIO write, for packet="<::handle_write + MTRACE("handler_write (after write, from queue="< +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "syncobj.h" + +#include "net/net_utils_base.h" +#include "misc_log_ex.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "misc_language.h" +#include "pragma_comp_defs.h" +#include +#include +#include + + + +#include +#include +#include "net/abstract_tcp_server2.h" + +// TODO: +#include "net/network_throttle-detail.hpp" + +#undef MONERO_DEFAULT_LOG_CATEGORY +#define MONERO_DEFAULT_LOG_CATEGORY "net.throttle" + +// ################################################################################################ +// ################################################################################################ +// the "header part". Not separeted out for .hpp because point of this modification is +// to rebuild just 1 translation unit while working on this code. +// (But maybe common parts will be separated out later though - if needed) +// ################################################################################################ +// ################################################################################################ + +namespace epee +{ +namespace net_utils +{ + + +/* ============================================================================ */ + +class connection_basic_pimpl { + public: + connection_basic_pimpl(const std::string &name); + + static int m_default_tos; + + network_throttle_bw m_throttle; // per-perr + critical_section m_throttle_lock; + + void _packet(size_t packet_size, int phase, int q_len); // execute a sleep ; phase is not really used now(?) could be used for different kinds of sleep e.g. direct/queue write +}; + + +} // namespace +} // namespace + + + + + + +// ################################################################################################ +// ################################################################################################ +// The implementation part +// ################################################################################################ +// ################################################################################################ + +namespace epee +{ +namespace net_utils +{ + +// ================================================================================================ +// network_throttle +// ================================================================================================ + +network_throttle::~network_throttle() { } + +network_throttle::packet_info::packet_info() + : m_size(0) +{ +} + +network_throttle::network_throttle(const std::string &nameshort, const std::string &name, int window_size) + : m_window_size( (window_size==-1) ? 10 : window_size ), + m_history( m_window_size ), m_nameshort(nameshort) +{ + set_name(name); + m_network_add_cost = 128; + m_network_minimal_segment = 256; + m_network_max_segment = 1024*1024; + m_any_packet_yet = false; + m_slot_size = 1.0; // hard coded in few places + m_target_speed = 16 * 1024; // other defaults are probably defined in the command-line parsing code when this class is used e.g. as main global throttle +} + +void network_throttle::set_name(const std::string &name) +{ + m_name = name; +} + +void network_throttle::set_target_speed( network_speed_kbps target ) +{ + m_target_speed = target * 1024; + MINFO("Setting LIMIT: " << target << " kbps"); +} + +network_speed_kbps network_throttle::get_target_speed() +{ + return m_target_speed / 1024; +} + +void network_throttle::tick() +{ + double time_now = get_time_seconds(); + if (!m_any_packet_yet) m_start_time = time_now; // starting now + + network_time_seconds current_sample_time_slot = time_to_slot( time_now ); // T=13.7 --> 13 (for 1-second smallwindow) + network_time_seconds last_sample_time_slot = time_to_slot( m_last_sample_time ); + + // moving to next position, and filling gaps + // !! during this loop the m_last_sample_time and last_sample_time_slot mean the variable moved in +1 + // TODO optimize when moving few slots at once + while ( (!m_any_packet_yet) || (last_sample_time_slot < current_sample_time_slot)) + { + _dbg3("Moving counter buffer by 1 second " << last_sample_time_slot << " < " << current_sample_time_slot << " (last time " << m_last_sample_time<<")"); + // rotate buffer + for (size_t i=m_history.size()-1; i>=1; --i) m_history[i] = m_history[i-1]; + m_history[0] = packet_info(); + if (! m_any_packet_yet) + { + m_last_sample_time = time_now; + } + m_last_sample_time += 1; last_sample_time_slot = time_to_slot( m_last_sample_time ); // increase and recalculate time, time slot + m_any_packet_yet=true; + } + m_last_sample_time = time_now; // the real exact last time +} + +void network_throttle::handle_trafic_exact(size_t packet_size) +{ + _handle_trafic_exact(packet_size, packet_size); +} + +void network_throttle::_handle_trafic_exact(size_t packet_size, size_t orginal_size) +{ + tick(); + + calculate_times_struct cts ; calculate_times(packet_size, cts , false, -1); + calculate_times_struct cts2; calculate_times(packet_size, cts2, false, 5); + m_history[0].m_size += packet_size; + + std::ostringstream oss; oss << "["; for (auto sample: m_history) oss << sample.m_size << " "; oss << "]" << std::ends; + std::string history_str = oss.str(); + + MTRACE("Throttle " << m_name << ": packet of ~"<(time) << " " << static_cast(size/1024) << "\n"; + file.close(); + } mutex.unlock(); +} + +// fine tune this to decide about sending speed: +network_time_seconds network_throttle::get_sleep_time(size_t packet_size) const +{ + double D2=0; + calculate_times_struct cts = { 0, 0, 0, 0}; + calculate_times(packet_size, cts, true, m_window_size); D2=cts.delay; + return D2; +} + +// MAIN LOGIC: +void network_throttle::calculate_times(size_t packet_size, calculate_times_struct &cts, bool dbg, double force_window) const +{ + const double the_window_size = std::max( (double)m_window_size , + ((force_window>0) ? force_window : m_window_size) + ); + + if (!m_any_packet_yet) { + cts.window=0; cts.average=0; cts.delay=0; + cts.recomendetDataSize = m_network_minimal_segment; // should be overrided by caller anyway + return ; // no packet yet, I can not decide about sleep time + } + + network_time_seconds window_len = (the_window_size-1) * m_slot_size ; // -1 since current slot is not finished + window_len += (m_last_sample_time - time_to_slot(m_last_sample_time)); // add the time for current slot e.g. 13.7-13 = 0.7 + + auto time_passed = get_time_seconds() - m_start_time; + cts.window = std::max( std::min( window_len , time_passed ) , m_slot_size ) ; // window length resulting from size of history but limited by how long ago history was started, + // also at least slot size (e.g. 1 second) to not be ridiculous + // window_len e.g. 5.7 because takes into account current slot time + + size_t Epast = 0; // summ of traffic till now + for (auto sample : m_history) Epast += sample.m_size; + + const size_t E = Epast; + const size_t Enow = Epast + packet_size ; // including the data we're about to send now + + const double M = m_target_speed; // max + const double D1 = (Epast - M*cts.window) / M; // delay - how long to sleep to get back to target speed + const double D2 = (Enow - M*cts.window) / M; // delay - how long to sleep to get back to target speed (including current packet) + + cts.delay = (D1*0.80 + D2*0.20); // finall sleep depends on both with/without current packet + // update_overheat(); + cts.average = Epast/cts.window; // current avg. speed (for info) + + if (Epast <= 0) { + if (cts.delay>=0) cts.delay = 0; // no traffic in history so we will not wait + } + + double Wgood=-1; + { // how much data we recommend now to download + Wgood = the_window_size + 1; + cts.recomendetDataSize = M*cts.window - E; + } + + if (dbg) { + std::ostringstream oss; oss << "["; for (auto sample: m_history) oss << sample.m_size << " "; oss << "]" << std::ends; + std::string history_str = oss.str(); + MTRACE((cts.delay > 0 ? "SLEEP" : "") + << "dbg " << m_name << ": " + << "speed is A=" << std::setw(8) <>> global-OUT",10); + return obj_get_global_throttle_out; +} + + + + +network_throttle_bw::network_throttle_bw(const std::string &name1) + : m_in("in/"+name1, name1+"-DOWNLOAD"), m_inreq("inreq/"+name1, name1+"-DOWNLOAD-REQUESTS"), m_out("out/"+name1, name1+"-UPLOAD") +{ } + + + + +} // namespace +} // namespace + + + + + diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp b/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp index 094e4fc95..578abd20c 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp +++ b/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp @@ -70,7 +70,7 @@ #include #include "cryptonote_protocol_handler.h" -#include "p2p/network_throttle.hpp" +#include "net/network_throttle.hpp" #include "cryptonote_core/cryptonote_core.h" // e.g. for the send_stop_signal() diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl index 4ba406ffc..389e8ba84 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl +++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl @@ -41,7 +41,7 @@ #include "cryptonote_basic/cryptonote_format_utils.h" #include "profile_tools.h" -#include "p2p/network_throttle-detail.hpp" +#include "net/network_throttle-detail.hpp" #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "net.cn" diff --git a/src/debug_utilities/object_sizes.cpp b/src/debug_utilities/object_sizes.cpp index e58da7395..82d8a4add 100644 --- a/src/debug_utilities/object_sizes.cpp +++ b/src/debug_utilities/object_sizes.cpp @@ -31,7 +31,7 @@ #include "cryptonote_basic/tx_extra.h" #include "cryptonote_core/blockchain.h" #include "p2p/p2p_protocol_defs.h" -#include "p2p/connection_basic.hpp" +#include "net/connection_basic.hpp" #include "p2p/net_peerlist.h" #include "p2p/net_node.h" #include "cryptonote_protocol/cryptonote_protocol_handler.h" diff --git a/src/p2p/connection_basic.cpp b/src/p2p/connection_basic.cpp deleted file mode 100644 index 06baa7893..000000000 --- a/src/p2p/connection_basic.cpp +++ /dev/null @@ -1,290 +0,0 @@ -/// @file -/// @author rfree (current maintainer in monero.cc project) -/// @brief base for connection, contains e.g. the ratelimit hooks - -// Copyright (c) 2014-2017, The Monero Project -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, are -// permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of -// conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, this list -// of conditions and the following disclaimer in the documentation and/or other -// materials provided with the distribution. -// -// 3. Neither the name of the copyright holder nor the names of its contributors may be -// used to endorse or promote products derived from this software without specific -// prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -/* rfree: implementation for the non-template base, can be used by connection<> template class in abstract_tcp_server2 file */ - -#include "connection_basic.hpp" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "syncobj.h" - -#include "net/net_utils_base.h" -#include "misc_log_ex.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "misc_language.h" -#include "pragma_comp_defs.h" -#include -#include -#include -#include -#include - -#include -#include -#include "net/abstract_tcp_server2.h" - -// TODO: -#include "network_throttle-detail.hpp" -#include "cryptonote_core/cryptonote_core.h" - -#undef MONERO_DEFAULT_LOG_CATEGORY -#define MONERO_DEFAULT_LOG_CATEGORY "net.p2p" - -// ################################################################################################ -// local (TU local) headers -// ################################################################################################ - -namespace epee -{ -namespace net_utils -{ - - std::string to_string(t_connection_type type) - { - if (type == e_connection_type_NET) - return std::string("NET"); - else if (type == e_connection_type_RPC) - return std::string("RPC"); - else if (type == e_connection_type_P2P) - return std::string("P2P"); - - return std::string("UNKNOWN"); - } - - -/* ============================================================================ */ - -class connection_basic_pimpl { - public: - connection_basic_pimpl(const std::string &name); - - static int m_default_tos; - - network_throttle_bw m_throttle; // per-perr - critical_section m_throttle_lock; - - int m_peer_number; // e.g. for debug/stats -}; - - -} // namespace -} // namespace - -// ################################################################################################ -// The implementation part -// ################################################################################################ - -namespace epee -{ -namespace net_utils -{ - -// ================================================================================================ -// connection_basic_pimpl -// ================================================================================================ - -connection_basic_pimpl::connection_basic_pimpl(const std::string &name) : m_throttle(name) { } - -// ================================================================================================ -// connection_basic -// ================================================================================================ - -// static variables: -int connection_basic_pimpl::m_default_tos; - -// methods: -connection_basic::connection_basic(boost::asio::io_service& io_service, std::atomic &ref_sock_count, std::atomic &sock_number) - : - mI( new connection_basic_pimpl("peer") ), - strand_(io_service), - socket_(io_service), - m_want_close_connection(false), - m_was_shutdown(false), - m_ref_sock_count(ref_sock_count) -{ - ++ref_sock_count; // increase the global counter - mI->m_peer_number = sock_number.fetch_add(1); // use, and increase the generated number - - std::string remote_addr_str = "?"; - try { boost::system::error_code e; remote_addr_str = socket_.remote_endpoint(e).address().to_string(); } catch(...){} ; - - _note("Spawned connection p2p#"<m_peer_number<<" to " << remote_addr_str << " currently we have sockets count:" << m_ref_sock_count); - //boost::filesystem::create_directories("log/dr-monero/net/"); -} - -connection_basic::~connection_basic() noexcept(false) { - std::string remote_addr_str = "?"; - m_ref_sock_count--; - try { boost::system::error_code e; remote_addr_str = socket_.remote_endpoint(e).address().to_string(); } catch(...){} ; - _note("Destructing connection p2p#"<m_peer_number << " to " << remote_addr_str); -} - -void connection_basic::set_rate_up_limit(uint64_t limit) { - { - CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_out ); - network_throttle_manager::get_global_throttle_out().set_target_speed(limit); - } - save_limit_to_file(limit); -} - -void connection_basic::set_rate_down_limit(uint64_t limit) { - { - CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_in ); - network_throttle_manager::get_global_throttle_in().set_target_speed(limit); - } - - { - CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_inreq ); - network_throttle_manager::get_global_throttle_inreq().set_target_speed(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) { -} - -void connection_basic::set_tos_flag(int tos) { - connection_basic_pimpl::m_default_tos = tos; -} - -int connection_basic::get_tos_flag() { - return connection_basic_pimpl::m_default_tos; -} - -void connection_basic::sleep_before_packet(size_t packet_size, int phase, int q_len) { - double delay=0; // will be calculated - do - { // rate limiting - if (m_was_shutdown) { - _dbg2("m_was_shutdown - so abort sleep"); - return; - } - - { - CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_out ); - delay = network_throttle_manager::get_global_throttle_out().get_sleep_time_after_tick( packet_size ); - } - - delay *= 0.50; - if (delay > 0) { - long int ms = (long int)(delay * 1000); - MTRACE("Sleeping in " << __FUNCTION__ << " for " << ms << " ms before packet_size="< 0); - -// XXX LATER XXX - { - CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_out ); - network_throttle_manager::get_global_throttle_out().handle_trafic_exact( packet_size ); // increase counter - global - } - -} -void connection_basic::set_start_time() { - CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_out ); - m_start_time = network_throttle_manager::get_global_throttle_out().get_time_seconds(); -} - -void connection_basic::do_send_handler_write(const void* ptr , size_t cb ) { - // No sleeping here; sleeping is done once and for all in connection::handle_write - MTRACE("handler_write (direct) - before ASIO write, for packet="<::handle_write - MTRACE("handler_write (after write, from queue="< -// ! from files contrib/epee/include/net/abstract_tcp_server2.* -// ! I am not a lawyer; afaik APIs, var names etc are not copyrightable ;) -// ! (how ever if in some wonderful juristdictions that is not the case, then why not make another sub-class withat that members and licence it as epee part) -// ! Working on above premise, IF this is valid in your juristdictions, then consider this code as released as: - -// Copyright (c) 2014-2017, The Monero Project -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, are -// permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of -// conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, this list -// of conditions and the following disclaimer in the documentation and/or other -// materials provided with the distribution. -// -// 3. Neither the name of the copyright holder nor the names of its contributors may be -// used to endorse or promote products derived from this software without specific -// prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -/* rfree: place for hanlers for the non-template base, can be used by connection<> template class in abstract_tcp_server2 file */ - -#ifndef INCLUDED_p2p_connection_basic_hpp -#define INCLUDED_p2p_connection_basic_hpp - - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "net/net_utils_base.h" -#include "syncobj.h" - -namespace epee -{ -namespace net_utils -{ - - /************************************************************************/ - /* */ - /************************************************************************/ - /// Represents a single connection from a client. - -class connection_basic_pimpl; // PIMPL for this class - - enum t_connection_type { // type of the connection (of this server), e.g. so that we will know how to limit it - e_connection_type_NET = 0, // default (not used?) - e_connection_type_RPC = 1, // the rpc commands (probably not rate limited, not chunked, etc) - e_connection_type_P2P = 2 // to other p2p node (probably limited) - }; - - std::string to_string(t_connection_type type); - -class connection_basic { // not-templated base class for rapid developmet of some code parts - public: - std::unique_ptr< connection_basic_pimpl > mI; // my Implementation - - // moved here from orginal connecton<> - common member variables that do not depend on template in connection<> - volatile uint32_t m_want_close_connection; - std::atomic m_was_shutdown; - critical_section m_send_que_lock; - std::list m_send_que; - volatile bool m_is_multithreaded; - double m_start_time; - /// Strand to ensure the connection's handlers are not called concurrently. - boost::asio::io_service::strand strand_; - /// Socket for the connection. - boost::asio::ip::tcp::socket socket_; - - std::atomic &m_ref_sock_count; // reference to external counter of existing sockets that we will ++/-- - public: - // first counter is the ++/-- count of current sockets, the other socket_number is only-increasing ++ number generator - connection_basic(boost::asio::io_service& io_service, std::atomic &ref_sock_count, std::atomic &sock_number); - - virtual ~connection_basic() noexcept(false); - - // various handlers to be called from connection class: - void do_send_handler_write(const void * ptr , size_t cb); - void do_send_handler_write_from_queue(const boost::system::error_code& e, size_t cb , int q_len); // from handle_write, sending next part - - void logger_handle_net_write(size_t size); // network data written - void logger_handle_net_read(size_t size); // network data read - - void set_start_time(); - - // config for rate limit - - 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 - static int get_tos_flag(); - - // handlers and sleep - void sleep_before_packet(size_t packet_size, int phase, int q_len); // execute a sleep ; phase is not really used now(?) - static void save_limit_to_file(int limit); ///< for dr-monero - static double get_sleep_time(size_t cb); - - static void set_save_graph(bool save_graph); -}; - -} // nameserver -} // nameserver - -#endif - - diff --git a/src/p2p/network_throttle-detail.cpp b/src/p2p/network_throttle-detail.cpp deleted file mode 100644 index 651e01e6b..000000000 --- a/src/p2p/network_throttle-detail.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/// @file -/// @author rfree (current maintainer in monero.cc project) -/// @brief implementaion for throttling of connection (count and rate-limit speed etc) - -// Copyright (c) 2014-2017, The Monero Project -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, are -// permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of -// conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, this list -// of conditions and the following disclaimer in the documentation and/or other -// materials provided with the distribution. -// -// 3. Neither the name of the copyright holder nor the names of its contributors may be -// used to endorse or promote products derived from this software without specific -// prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -/* rfree: implementation for throttle details */ - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include "syncobj.h" - -#include "net/net_utils_base.h" -#include "misc_log_ex.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include "misc_language.h" -#include "pragma_comp_defs.h" -#include -#include -#include - - - -#include -#include -#include "net/abstract_tcp_server2.h" - -// TODO: -#include "network_throttle-detail.hpp" - -#undef MONERO_DEFAULT_LOG_CATEGORY -#define MONERO_DEFAULT_LOG_CATEGORY "net.throttle" - -// ################################################################################################ -// ################################################################################################ -// the "header part". Not separeted out for .hpp because point of this modification is -// to rebuild just 1 translation unit while working on this code. -// (But maybe common parts will be separated out later though - if needed) -// ################################################################################################ -// ################################################################################################ - -namespace epee -{ -namespace net_utils -{ - - -/* ============================================================================ */ - -class connection_basic_pimpl { - public: - connection_basic_pimpl(const std::string &name); - - static int m_default_tos; - - network_throttle_bw m_throttle; // per-perr - critical_section m_throttle_lock; - - void _packet(size_t packet_size, int phase, int q_len); // execute a sleep ; phase is not really used now(?) could be used for different kinds of sleep e.g. direct/queue write -}; - - -} // namespace -} // namespace - - - - - - -// ################################################################################################ -// ################################################################################################ -// The implementation part -// ################################################################################################ -// ################################################################################################ - -namespace epee -{ -namespace net_utils -{ - -// ================================================================================================ -// network_throttle -// ================================================================================================ - -network_throttle::~network_throttle() { } - -network_throttle::packet_info::packet_info() - : m_size(0) -{ -} - -network_throttle::network_throttle(const std::string &nameshort, const std::string &name, int window_size) - : m_window_size( (window_size==-1) ? 10 : window_size ), - m_history( m_window_size ), m_nameshort(nameshort) -{ - set_name(name); - m_network_add_cost = 128; - m_network_minimal_segment = 256; - m_network_max_segment = 1024*1024; - m_any_packet_yet = false; - m_slot_size = 1.0; // hard coded in few places - m_target_speed = 16 * 1024; // other defaults are probably defined in the command-line parsing code when this class is used e.g. as main global throttle -} - -void network_throttle::set_name(const std::string &name) -{ - m_name = name; -} - -void network_throttle::set_target_speed( network_speed_kbps target ) -{ - m_target_speed = target * 1024; - MINFO("Setting LIMIT: " << target << " kbps"); -} - -network_speed_kbps network_throttle::get_target_speed() -{ - return m_target_speed / 1024; -} - -void network_throttle::tick() -{ - double time_now = get_time_seconds(); - if (!m_any_packet_yet) m_start_time = time_now; // starting now - - network_time_seconds current_sample_time_slot = time_to_slot( time_now ); // T=13.7 --> 13 (for 1-second smallwindow) - network_time_seconds last_sample_time_slot = time_to_slot( m_last_sample_time ); - - // moving to next position, and filling gaps - // !! during this loop the m_last_sample_time and last_sample_time_slot mean the variable moved in +1 - // TODO optimize when moving few slots at once - while ( (!m_any_packet_yet) || (last_sample_time_slot < current_sample_time_slot)) - { - _dbg3("Moving counter buffer by 1 second " << last_sample_time_slot << " < " << current_sample_time_slot << " (last time " << m_last_sample_time<<")"); - // rotate buffer - for (size_t i=m_history.size()-1; i>=1; --i) m_history[i] = m_history[i-1]; - m_history[0] = packet_info(); - if (! m_any_packet_yet) - { - m_last_sample_time = time_now; - } - m_last_sample_time += 1; last_sample_time_slot = time_to_slot( m_last_sample_time ); // increase and recalculate time, time slot - m_any_packet_yet=true; - } - m_last_sample_time = time_now; // the real exact last time -} - -void network_throttle::handle_trafic_exact(size_t packet_size) -{ - _handle_trafic_exact(packet_size, packet_size); -} - -void network_throttle::_handle_trafic_exact(size_t packet_size, size_t orginal_size) -{ - tick(); - - calculate_times_struct cts ; calculate_times(packet_size, cts , false, -1); - calculate_times_struct cts2; calculate_times(packet_size, cts2, false, 5); - m_history[0].m_size += packet_size; - - std::ostringstream oss; oss << "["; for (auto sample: m_history) oss << sample.m_size << " "; oss << "]" << std::ends; - std::string history_str = oss.str(); - - MTRACE("Throttle " << m_name << ": packet of ~"<(time) << " " << static_cast(size/1024) << "\n"; - file.close(); - } mutex.unlock(); -} - -// fine tune this to decide about sending speed: -network_time_seconds network_throttle::get_sleep_time(size_t packet_size) const -{ - double D2=0; - calculate_times_struct cts = { 0, 0, 0, 0}; - calculate_times(packet_size, cts, true, m_window_size); D2=cts.delay; - return D2; -} - -// MAIN LOGIC: -void network_throttle::calculate_times(size_t packet_size, calculate_times_struct &cts, bool dbg, double force_window) const -{ - const double the_window_size = std::max( (double)m_window_size , - ((force_window>0) ? force_window : m_window_size) - ); - - if (!m_any_packet_yet) { - cts.window=0; cts.average=0; cts.delay=0; - cts.recomendetDataSize = m_network_minimal_segment; // should be overrided by caller anyway - return ; // no packet yet, I can not decide about sleep time - } - - network_time_seconds window_len = (the_window_size-1) * m_slot_size ; // -1 since current slot is not finished - window_len += (m_last_sample_time - time_to_slot(m_last_sample_time)); // add the time for current slot e.g. 13.7-13 = 0.7 - - auto time_passed = get_time_seconds() - m_start_time; - cts.window = std::max( std::min( window_len , time_passed ) , m_slot_size ) ; // window length resulting from size of history but limited by how long ago history was started, - // also at least slot size (e.g. 1 second) to not be ridiculous - // window_len e.g. 5.7 because takes into account current slot time - - size_t Epast = 0; // summ of traffic till now - for (auto sample : m_history) Epast += sample.m_size; - - const size_t E = Epast; - const size_t Enow = Epast + packet_size ; // including the data we're about to send now - - const double M = m_target_speed; // max - const double D1 = (Epast - M*cts.window) / M; // delay - how long to sleep to get back to target speed - const double D2 = (Enow - M*cts.window) / M; // delay - how long to sleep to get back to target speed (including current packet) - - cts.delay = (D1*0.80 + D2*0.20); // finall sleep depends on both with/without current packet - // update_overheat(); - cts.average = Epast/cts.window; // current avg. speed (for info) - - if (Epast <= 0) { - if (cts.delay>=0) cts.delay = 0; // no traffic in history so we will not wait - } - - double Wgood=-1; - { // how much data we recommend now to download - Wgood = the_window_size + 1; - cts.recomendetDataSize = M*cts.window - E; - } - - if (dbg) { - std::ostringstream oss; oss << "["; for (auto sample: m_history) oss << sample.m_size << " "; oss << "]" << std::ends; - std::string history_str = oss.str(); - MTRACE((cts.delay > 0 ? "SLEEP" : "") - << "dbg " << m_name << ": " - << "speed is A=" << std::setw(8) <100 elements - - std::vector< packet_info > m_history; // the history of bw usage - network_time_seconds m_last_sample_time; // time of last history[0] - so we know when to rotate the buffer - network_time_seconds m_start_time; // when we were created - bool m_any_packet_yet; // did we yet got any packet to count - - std::string m_name; // my name for debug and logs - std::string m_nameshort; // my name for debug and logs (used in log file name) - - // each sample is now 1 second - public: - network_throttle(const std::string &nameshort, const std::string &name, int window_size=-1); - virtual ~network_throttle(); - virtual void set_name(const std::string &name); - virtual void set_target_speed( network_speed_kbps target ); - 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 - virtual void handle_trafic_tcp(size_t packet_size); ///< count the new traffic/packet; the size is as TCP, we will consider MTU etc - - virtual void tick(); ///< poke and update timers/history (recalculates, moves the history if needed, checks the real clock etc) - - virtual double get_time_seconds() const ; ///< timer that we use, time in seconds, monotionic - - // time calculations: - virtual void calculate_times(size_t packet_size, calculate_times_struct &cts, bool dbg, double force_window) const; ///< MAIN LOGIC (see base class for info) - - virtual network_time_seconds get_sleep_time_after_tick(size_t packet_size); ///< increase the timer if needed, and get the package size - virtual network_time_seconds get_sleep_time(size_t packet_size) const; ///< gets the Delay (recommended Delay time) from calc. (not safe: only if time didnt change?) TODO - - virtual size_t get_recommended_size_of_planned_transport() const; ///< what should be the size (bytes) of next data block to be transported - virtual size_t get_recommended_size_of_planned_transport_window(double force_window) const; ///< ditto, but for given windows time frame - virtual double get_current_speed() const; - - private: - virtual network_time_seconds time_to_slot(network_time_seconds t) const { return std::floor( t ); } // convert exact time eg 13.7 to rounded time for slot number in history 13 - virtual void _handle_trafic_exact(size_t packet_size, size_t orginal_size); - virtual void logger_handle_net(const std::string &filename, double time, size_t size); -}; - -/*** - * The complete set of traffic throttle for one typical connection -*/ -struct network_throttle_bw { - public: - network_throttle m_in; ///< for incomming traffic (this we can not controll directly as it depends of what others send to us - usually) - network_throttle m_inreq; ///< for requesting incomming traffic (this is exact usually) - network_throttle m_out; ///< for outgoing traffic that we just sent (this is exact usually) - - public: - network_throttle_bw(const std::string &name1); -}; - - - -} // namespace net_utils -} // namespace epee - - -#endif - - diff --git a/src/p2p/network_throttle.cpp b/src/p2p/network_throttle.cpp deleted file mode 100644 index 74b20376d..000000000 --- a/src/p2p/network_throttle.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/** -@file -@author rfree (current maintainer in monero.cc project) -@brief interface for throttling of connection (count and rate-limit speed etc) -@details
-
-Throttling work by:
-1) taking note of all traffic (hooks added e.g. to connection class) and measuring speed
-2) depending on that information we sleep before sending out data (or send smaller portions of data)
-3) depending on the information we can also sleep before sending requests or ask for smaller sets of data to download
-
-
- -@image html images/net/rate1-down-1k.png -@image html images/net/rate1-down-full.png -@image html images/net/rate1-up-10k.png -@image html images/net/rate1-up-full.png -@image html images/net/rate2-down-100k.png -@image html images/net/rate2-down-10k.png -@image html images/net/rate2-down-50k.png -@image html images/net/rate2-down-full.png -@image html images/net/rate2-up-100k.png -@image html images/net/rate2-up-10k.png -@image html images/net/rate3-up-10k.png - - -*/ - -// Copyright (c) 2014-2017, The Monero Project -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, are -// permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of -// conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, this list -// of conditions and the following disclaimer in the documentation and/or other -// materials provided with the distribution. -// -// 3. Neither the name of the copyright holder nor the names of its contributors may be -// used to endorse or promote products derived from this software without specific -// prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -#include "network_throttle-detail.hpp" - -namespace epee -{ -namespace net_utils -{ - -// ================================================================================================ -// network_throttle_manager -// ================================================================================================ - -// ================================================================================================ -// static: -boost::mutex network_throttle_manager::m_lock_get_global_throttle_in; -boost::mutex network_throttle_manager::m_lock_get_global_throttle_inreq; -boost::mutex network_throttle_manager::m_lock_get_global_throttle_out; - -int network_throttle_manager::xxx; - - -// ================================================================================================ -// methods: -i_network_throttle & network_throttle_manager::get_global_throttle_in() { - static network_throttle obj_get_global_throttle_in("in/all","<<< global-IN",10); - return obj_get_global_throttle_in; -} - - - -i_network_throttle & network_throttle_manager::get_global_throttle_inreq() { - static network_throttle obj_get_global_throttle_inreq("inreq/all", "<== global-IN-REQ",10); - return obj_get_global_throttle_inreq; -} - - -i_network_throttle & network_throttle_manager::get_global_throttle_out() { - static network_throttle obj_get_global_throttle_out("out/all", ">>> global-OUT",10); - return obj_get_global_throttle_out; -} - - - - -network_throttle_bw::network_throttle_bw(const std::string &name1) - : m_in("in/"+name1, name1+"-DOWNLOAD"), m_inreq("inreq/"+name1, name1+"-DOWNLOAD-REQUESTS"), m_out("out/"+name1, name1+"-UPLOAD") -{ } - - - - -} // namespace -} // namespace - - - - - diff --git a/src/p2p/network_throttle.hpp b/src/p2p/network_throttle.hpp deleted file mode 100644 index bf1f93859..000000000 --- a/src/p2p/network_throttle.hpp +++ /dev/null @@ -1,176 +0,0 @@ -/// @file -/// @author rfree (current maintainer in monero.cc project) -/// @brief interface for throttling of connection (count and rate-limit speed etc) - -// Copyright (c) 2014-2017, The Monero Project -// -// All rights reserved. -// -// Redistribution and use in source and binary forms, with or without modification, are -// permitted provided that the following conditions are met: -// -// 1. Redistributions of source code must retain the above copyright notice, this list of -// conditions and the following disclaimer. -// -// 2. Redistributions in binary form must reproduce the above copyright notice, this list -// of conditions and the following disclaimer in the documentation and/or other -// materials provided with the distribution. -// -// 3. Neither the name of the copyright holder nor the names of its contributors may be -// used to endorse or promote products derived from this software without specific -// prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY -// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL -// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, -// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF -// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -/* rfree: throttle basic interface */ -/* rfree: also includes the manager for singeton/global such objects */ - - -#ifndef INCLUDED_p2p_network_throttle_hpp -#define INCLUDED_p2p_network_throttle_hpp - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "syncobj.h" - -#include "net/net_utils_base.h" -#include "misc_log_ex.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include "misc_language.h" -#include "pragma_comp_defs.h" -#include -#include -#include - -#include -#include -#include - -namespace epee -{ -namespace net_utils -{ - -// just typedefs to in code define the units used. TODO later it will be enforced that casts to other numericals are only explicit to avoid mistakes? use boost::chrono? -typedef double network_speed_kbps; // externally, for parameters and return values, all defined in kilobytes per second -typedef double network_speed_bps; // throttle-internally, bytes per second -typedef double network_time_seconds; -typedef double network_MB; - -class i_network_throttle; - -/*** -@brief All information about given throttle - speed calculations -*/ -struct calculate_times_struct { - double average; - double window; - double delay; - double recomendetDataSize; -}; -typedef calculate_times_struct calculate_times_struct; - - -namespace cryptonote { class cryptonote_protocol_handler_base; } // a friend class // TODO friend not working - -/*** -@brief Access to simple throttles, with singlton to access global network limits -*/ -class network_throttle_manager { - // provides global (singleton) in/inreq/out throttle access - - // [[note1]] see also http://www.nuonsoft.com/blog/2012/10/21/implementing-a-thread-safe-singleton-with-c11/ - // [[note2]] _inreq is the requested in traffic - we anticipate we will get in-bound traffic soon as result of what we do (e.g. that we sent network downloads requests) - - //protected: - public: // XXX - - static boost::mutex m_lock_get_global_throttle_in; - static boost::mutex m_lock_get_global_throttle_inreq; - static boost::mutex m_lock_get_global_throttle_out; - - friend class cryptonote::cryptonote_protocol_handler_base; // FRIEND - to directly access global throttle-s. !! REMEMBER TO USE LOCKS! - friend class connection_basic; // FRIEND - to directly access global throttle-s. !! REMEMBER TO USE LOCKS! - friend class connection_basic_pimpl; // ditto - - static int xxx; - - public: - static i_network_throttle & get_global_throttle_in(); ///< singleton ; for friend class ; caller MUST use proper locks! like m_lock_get_global_throttle_in - static i_network_throttle & get_global_throttle_inreq(); ///< ditto ; use lock ... use m_lock_get_global_throttle_inreq obviously - static i_network_throttle & get_global_throttle_out(); ///< ditto ; use lock ... use m_lock_get_global_throttle_out obviously -}; - - - -/*** -@brief interface for the throttle, see the derivated class -*/ -class i_network_throttle { - public: - virtual void set_name(const std::string &name)=0; - virtual void set_target_speed( network_speed_kbps target )=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 - virtual void tick() =0; // poke and update timers/history - - // time calculations: - - virtual void calculate_times(size_t packet_size, calculate_times_struct &cts, bool dbg, double force_window) const =0; // assuming sending new package (or 0), calculate: - // Average, Window, Delay, Recommended data size ; also gets dbg=debug flag, and forced widnow size if >0 or -1 for not forcing window size - - // Average speed, Window size, recommended Delay to sleep now, Recommended size of data to send now - - virtual network_time_seconds get_sleep_time(size_t packet_size) const =0; // gets the D (recommended Delay time) from calc - virtual network_time_seconds get_sleep_time_after_tick(size_t packet_size) =0; // ditto, but first tick the timer - - virtual size_t get_recommended_size_of_planned_transport() const =0; // what should be the recommended limit of data size that we can transport over current network_throttle in near future - - virtual double get_time_seconds() const =0; // a timer - virtual void logger_handle_net(const std::string &filename, double time, size_t size)=0; - - -}; - - -// ... more in the -advanced.h file - - -} // namespace net_utils -} // namespace epee - - -#endif - - - -- cgit v1.2.3 From 43f5269f842cbdc585226eea20e48d19253f61e7 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 29 Nov 2017 19:31:38 +0000 Subject: Wallets now do not depend on the daemon rpc lib The shared RPC code is now moved off into a separate lib --- src/rpc/CMakeLists.txt | 23 +++++++++++++++++++++-- src/simplewallet/CMakeLists.txt | 2 +- src/wallet/CMakeLists.txt | 2 +- 3 files changed, 23 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/rpc/CMakeLists.txt b/src/rpc/CMakeLists.txt index 652a03f44..748c6b8c1 100644 --- a/src/rpc/CMakeLists.txt +++ b/src/rpc/CMakeLists.txt @@ -26,9 +26,11 @@ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +set(rpc_base_sources + rpc_args.cpp) + set(rpc_sources core_rpc_server.cpp - rpc_args.cpp instanciations) set(daemon_messages_sources @@ -40,9 +42,11 @@ set(daemon_rpc_server_sources zmq_server.cpp) -set(rpc_headers +set(rpc_base_headers rpc_args.h) +set(rpc_headers) + set(daemon_rpc_server_headers) @@ -70,6 +74,11 @@ monero_private_headers(daemon_rpc_server ${daemon_rpc_server_private_headers}) +monero_add_library(rpc_base + ${rpc_base_sources} + ${rpc_base_headers} + ${rpc_base_private_headers}) + monero_add_library(rpc ${rpc_sources} ${rpc_headers} @@ -86,8 +95,18 @@ monero_add_library(daemon_rpc_server ${daemon_rpc_server_private_headers}) +target_link_libraries(rpc_base + PUBLIC + common + epee + ${Boost_REGEX_LIBRARY} + ${Boost_THREAD_LIBRARY} + PRIVATE + ${EXTRA_LIBRARIES}) + target_link_libraries(rpc PUBLIC + rpc_base common cryptonote_core cryptonote_protocol diff --git a/src/simplewallet/CMakeLists.txt b/src/simplewallet/CMakeLists.txt index 3ff4466fc..beaacf0e9 100644 --- a/src/simplewallet/CMakeLists.txt +++ b/src/simplewallet/CMakeLists.txt @@ -43,7 +43,7 @@ monero_add_executable(simplewallet target_link_libraries(simplewallet PRIVATE wallet - rpc + rpc_base cryptonote_core cncrypto common diff --git a/src/wallet/CMakeLists.txt b/src/wallet/CMakeLists.txt index 74992139d..ab48bd7a2 100644 --- a/src/wallet/CMakeLists.txt +++ b/src/wallet/CMakeLists.txt @@ -82,7 +82,7 @@ target_link_libraries(wallet_rpc_server PRIVATE wallet epee - rpc + rpc_base cryptonote_core cncrypto common -- cgit v1.2.3