diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 8a234617ee..5e631bf274 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -323,7 +323,7 @@ namespace steemit { namespace app { return _app.p2p_node()->get_potential_peers(); } - fc::variant_object network_node_api::get_advanced_node_parameters() const + graphene::net::node_configuration network_node_api::get_advanced_node_parameters() const { return _app.p2p_node()->get_advanced_node_parameters(); } diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 24c04b281a..ebfbbf5329 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -86,7 +86,7 @@ namespace detail { class application_impl : public graphene::net::node_delegate { public: - uint32_t _next_rebroadcast = -1; + uint32_t _next_rebroadcast = 0; boost::signals2::connection _rebroadcast_con; fc::optional _lock_file; bool _is_block_producer = false; @@ -138,6 +138,14 @@ namespace detail { ilog("Setting p2p max connections to ${n}", ("n", node_param["maximum_number_of_connections"])); } + if( _options->count("p2p-parameters") ) + { + fc::variant var = fc::json::from_string( _options->at("p2p-parameters").as(), fc::json::strict_parser ); + const fc::variant_object& vo = var.get_object(); + ilog( "Setting p2p advanced node parameters: ${vo}", ("vo", vo) ); + _p2p_network->set_advanced_node_parameters( vo ); + } + _p2p_network->listen_to_p2p_network(); ilog("Configured p2p node to listen on ${ip}", ("ip", _p2p_network->get_actual_listening_endpoint())); @@ -241,12 +249,19 @@ namespace detail { void rebroadcast_pending_tx() { - if( _chain_db->head_block_num() >= _next_rebroadcast ) + uint32_t hbn = _chain_db->head_block_num(); + if( (_next_rebroadcast > 0) && (hbn >= _next_rebroadcast) ) { - _next_rebroadcast += REBROADCAST_RAND_INTERVAL(); + _next_rebroadcast = hbn + REBROADCAST_RAND_INTERVAL(); + uint32_t n = 0; for( const auto& trx : _chain_db->_pending_tx ) { - _p2p_network->broadcast( graphene::net::trx_message( trx ) ); + _p2p_network->broadcast( graphene::net::trx_message( trx ) ); + ++n; + } + if( n > 0 ) + { + ilog( "Force rebroadcast ${n} transactions", ("n", n) ); } } } @@ -368,8 +383,12 @@ namespace detail { } _chain_db->show_free_memory( true ); - _next_rebroadcast = _chain_db->head_block_num() + REBROADCAST_RAND_INTERVAL(); - _rebroadcast_con = _chain_db->applied_block.connect( [this]( const signed_block& b ){ rebroadcast_pending_tx(); } ); + if( _options->count( "force-tx-rebroadcast" ) ) + { + ilog( "Force transaction rebroadcast" ); + _next_rebroadcast = 1; + _rebroadcast_con = _chain_db->applied_block.connect( [this]( const signed_block& b ){ rebroadcast_pending_tx(); } ); + } if( _options->count("api-user") ) { @@ -997,6 +1016,7 @@ void application::set_program_options(boost::program_options::options_descriptio configuration_file_options.add_options() ("p2p-endpoint", bpo::value(), "Endpoint for P2P node to listen on") ("p2p-max-connections", bpo::value(), "Maxmimum number of incoming connections on P2P endpoint") + ("p2p-parameters", bpo::value()->default_value(fc::json::to_string(graphene::net::node_configuration())), "P2P network parameters") ("seed-node,s", bpo::value>()->composing(), "P2P nodes to connect to on startup (may specify multiple times)") ("checkpoint,c", bpo::value>()->composing(), "Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints.") ("shared-file-dir", bpo::value(), "Location of the shared memory file. Defaults to data_dir/blockchain") @@ -1021,6 +1041,7 @@ void application::set_program_options(boost::program_options::options_descriptio ("read-only", "Node will not connect to p2p network and can only read from the chain state" ) ("check-locks", "Check correctness of chainbase locking") ("disable-get-block", "Disable get_block API call" ) + ("force-tx-rebroadcast", "Rebroadcast transactions every few seconds") ; command_line_options.add(_cli_options); configuration_file_options.add(_cfg_options); diff --git a/libraries/app/include/steemit/app/api.hpp b/libraries/app/include/steemit/app/api.hpp index 7e1312fded..6b7ba2014d 100644 --- a/libraries/app/include/steemit/app/api.hpp +++ b/libraries/app/include/steemit/app/api.hpp @@ -149,7 +149,7 @@ namespace steemit { namespace app { * @brief Get advanced node parameters, such as desired and max * number of connections */ - fc::variant_object get_advanced_node_parameters() const; + graphene::net::node_configuration get_advanced_node_parameters() const; /** * @brief Set advanced node parameters, such as desired and max diff --git a/libraries/net/include/graphene/net/config.hpp b/libraries/net/include/graphene/net/config.hpp index 8847cd87c7..928b745aac 100644 --- a/libraries/net/include/graphene/net/config.hpp +++ b/libraries/net/include/graphene/net/config.hpp @@ -103,3 +103,6 @@ #define GRAPHENE_NET_MIN_BLOCK_IDS_TO_PREFETCH 10000 #define GRAPHENE_NET_MAX_TRX_PER_SECOND 1000 + +#define GRAPHENE_NET_MAX_NUMBER_OF_BLOCKS_TO_HANDLE_AT_ONE_TIME 200 +#define GRAPHENE_NET_MAX_NUMBER_OF_BLOCKS_TO_PREFETCH (10 * GRAPHENE_NET_MAX_NUMBER_OF_BLOCKS_TO_HANDLE_AT_ONE_TIME) diff --git a/libraries/net/include/graphene/net/node.hpp b/libraries/net/include/graphene/net/node.hpp index 0d590bd876..5c719afe81 100644 --- a/libraries/net/include/graphene/net/node.hpp +++ b/libraries/net/include/graphene/net/node.hpp @@ -25,6 +25,7 @@ #include #include +#include #include #include @@ -271,7 +272,7 @@ namespace graphene { namespace net { bool is_connected() const; void set_advanced_node_parameters(const fc::variant_object& params); - fc::variant_object get_advanced_node_parameters(); + node_configuration get_advanced_node_parameters()const; message_propagation_data get_transaction_propagation_data(const steemit::protocol::transaction_id_type& transaction_id); message_propagation_data get_block_propagation_data(const steemit::protocol::block_id_type& block_id); node_id_t get_node_id() const; @@ -290,7 +291,6 @@ namespace graphene { namespace net { std::vector get_potential_peers() const; - void disable_peer_advertising(); fc::variant_object get_call_statistics() const; private: std::unique_ptr my; diff --git a/libraries/net/include/graphene/net/node_configuration.hpp b/libraries/net/include/graphene/net/node_configuration.hpp new file mode 100644 index 0000000000..6e562a5118 --- /dev/null +++ b/libraries/net/include/graphene/net/node_configuration.hpp @@ -0,0 +1,59 @@ +#pragma once + +#include + +#include +#include + +namespace graphene { namespace net { + +struct node_configuration +{ + node_configuration() {} + + fc::ip::endpoint listen_endpoint; + bool accept_incoming_connections = true; + bool wait_if_endpoint_is_busy = true; + + /** + * Originally, our p2p code just had a 'node-id' that was a random number identifying this node + * on the network. This is now a private key/public key pair, where the public key is used + * in place of the old random node-id. The private part is unused, but might be used in + * the future to support some notion of trusted peers. + */ + fc::ecc::private_key private_key; + + /** if we have less than `desired_number_of_connections`, we will try to connect with more nodes */ + uint32_t desired_number_of_connections = GRAPHENE_NET_DEFAULT_DESIRED_CONNECTIONS; + /** if we have _maximum_number_of_connections or more, we will refuse any inbound connections */ + uint32_t maximum_number_of_connections = GRAPHENE_NET_DEFAULT_MAX_CONNECTIONS; + /** retry connections to peers that have failed or rejected us this often, in seconds */ + uint32_t peer_connection_retry_timeout = GRAPHENE_NET_DEFAULT_PEER_CONNECTION_RETRY_TIME; + /** how many seconds of inactivity are permitted before disconnecting a peer */ + uint32_t peer_inactivity_timeout = GRAPHENE_NET_PEER_HANDSHAKE_INACTIVITY_TIMEOUT; + + bool peer_advertising_disabled = false; + + uint32_t maximum_number_of_blocks_to_handle_at_one_time = GRAPHENE_NET_MAX_NUMBER_OF_BLOCKS_TO_HANDLE_AT_ONE_TIME; + uint32_t maximum_number_of_sync_blocks_to_prefetch = GRAPHENE_NET_MAX_NUMBER_OF_BLOCKS_TO_PREFETCH; + uint32_t maximum_blocks_per_peer_during_syncing = GRAPHENE_NET_MAX_BLOCKS_PER_PEER_DURING_SYNCING; + int64_t active_ignored_request_timeout_microseconds = 6000000; +}; + +} } + +FC_REFLECT(graphene::net::node_configuration, + (listen_endpoint) + (accept_incoming_connections) + (wait_if_endpoint_is_busy) + (private_key) + (desired_number_of_connections) + (maximum_number_of_connections) + (peer_connection_retry_timeout) + (peer_inactivity_timeout) + (peer_advertising_disabled) + (maximum_number_of_blocks_to_handle_at_one_time) + (maximum_number_of_sync_blocks_to_prefetch) + (maximum_blocks_per_peer_during_syncing) + (active_ignored_request_timeout_microseconds) +) diff --git a/libraries/net/node.cpp b/libraries/net/node.cpp index 19ed390fa8..3e1b31f5f5 100644 --- a/libraries/net/node.cpp +++ b/libraries/net/node.cpp @@ -71,6 +71,7 @@ #include #include +#include #include #include #include @@ -220,35 +221,6 @@ namespace graphene { namespace net { FC_THROW_EXCEPTION( fc::key_not_found_exception, "Requested message not in cache" ); } -///////////////////////////////////////////////////////////////////////////////////////////////////////// - - // This specifies configuration info for the local node. It's stored as JSON - // in the configuration directory (application data directory) - struct node_configuration - { - node_configuration() : accept_incoming_connections(true), wait_if_endpoint_is_busy(true) {} - - fc::ip::endpoint listen_endpoint; - bool accept_incoming_connections; - bool wait_if_endpoint_is_busy; - /** - * Originally, our p2p code just had a 'node-id' that was a random number identifying this node - * on the network. This is now a private key/public key pair, where the public key is used - * in place of the old random node-id. The private part is unused, but might be used in - * the future to support some notion of trusted peers. - */ - fc::ecc::private_key private_key; - }; - - -} } } // end namespace graphene::net::detail -FC_REFLECT(graphene::net::detail::node_configuration, (listen_endpoint) - (accept_incoming_connections) - (wait_if_endpoint_is_busy) - (private_key)); - -namespace graphene { namespace net { namespace detail { - // when requesting items from peers, we want to prioritize any blocks before // transactions, but otherwise request items in the order we heard about them struct prioritized_item_id @@ -494,15 +466,6 @@ namespace graphene { namespace net { namespace detail { */ node_id_t _node_id; - /** if we have less than `_desired_number_of_connections`, we will try to connect with more nodes */ - uint32_t _desired_number_of_connections; - /** if we have _maximum_number_of_connections or more, we will refuse any inbound connections */ - uint32_t _maximum_number_of_connections; - /** retry connections to peers that have failed or rejected us this often, in seconds */ - uint32_t _peer_connection_retry_timeout; - /** how many seconds of inactivity are permitted before disconnecting a peer */ - uint32_t _peer_inactivity_timeout; - fc::tcp_server _tcp_server; fc::future _accept_loop_complete; @@ -528,8 +491,6 @@ namespace graphene { namespace net { namespace detail { uint32_t _last_reported_number_of_connections; // number of connections last reported to the client (to avoid sending duplicate messages) - bool _peer_advertising_disabled; - fc::future _fetch_updated_peer_lists_loop_done; boost::circular_buffer _average_network_read_speed_seconds; @@ -567,10 +528,6 @@ namespace graphene { namespace net { namespace detail { bool _node_is_shutting_down; // set to true when we begin our destructor, used to prevent us from starting new tasks while we're shutting down - unsigned _maximum_number_of_blocks_to_handle_at_one_time; - unsigned _maximum_number_of_sync_blocks_to_prefetch; - unsigned _maximum_blocks_per_peer_during_syncing; - std::list > _handle_message_calls_in_progress; std::set _message_ids_currently_being_processed; @@ -736,7 +693,7 @@ namespace graphene { namespace net { namespace detail { std::vector get_potential_peers() const; void set_advanced_node_parameters( const fc::variant_object& params ); - fc::variant_object get_advanced_node_parameters(); + node_configuration get_advanced_node_parameters()const; message_propagation_data get_transaction_propagation_data( const graphene::net::transaction_id_type& transaction_id ); message_propagation_data get_block_propagation_data( const graphene::net::block_id_type& block_id ); @@ -744,7 +701,6 @@ namespace graphene { namespace net { namespace detail { void set_allowed_peers( const std::vector& allowed_peers ); void clear_peer_database(); void set_total_bandwidth_limit( uint32_t upload_bytes_per_second, uint32_t download_bytes_per_second ); - void disable_peer_advertising(); fc::variant_object get_call_statistics() const; message get_message_for_item(const item_id& item) override; @@ -784,9 +740,6 @@ namespace graphene { namespace net { namespace detail { # define VERIFY_CORRECT_THREAD() do {} while (0) #endif -#define MAXIMUM_NUMBER_OF_BLOCKS_TO_HANDLE_AT_ONE_TIME 200 -#define MAXIMUM_NUMBER_OF_BLOCKS_TO_PREFETCH (10 * MAXIMUM_NUMBER_OF_BLOCKS_TO_HANDLE_AT_ONE_TIME) - node_impl::node_impl(const std::string& user_agent) : #ifdef P2P_IN_DEDICATED_THREAD _thread(std::make_shared("p2p")), @@ -800,15 +753,10 @@ namespace graphene { namespace net { namespace detail { _items_to_fetch_sequence_counter(0), _recent_block_interval_in_seconds(STEEMIT_BLOCK_INTERVAL), _user_agent_string(user_agent), - _desired_number_of_connections(GRAPHENE_NET_DEFAULT_DESIRED_CONNECTIONS), - _maximum_number_of_connections(GRAPHENE_NET_DEFAULT_MAX_CONNECTIONS), - _peer_connection_retry_timeout(GRAPHENE_NET_DEFAULT_PEER_CONNECTION_RETRY_TIME), - _peer_inactivity_timeout(GRAPHENE_NET_PEER_HANDSHAKE_INACTIVITY_TIMEOUT), - _most_recent_blocks_accepted(_maximum_number_of_connections), + _most_recent_blocks_accepted(GRAPHENE_NET_DEFAULT_MAX_CONNECTIONS), _total_number_of_unfetched_items(0), _rate_limiter(0, 0), _last_reported_number_of_connections(0), - _peer_advertising_disabled(false), _average_network_read_speed_seconds(60), _average_network_write_speed_seconds(60), _average_network_read_speed_minutes(60), @@ -817,10 +765,7 @@ namespace graphene { namespace net { namespace detail { _average_network_write_speed_hours(72), _average_network_usage_second_counter(0), _average_network_usage_minute_counter(0), - _node_is_shutting_down(false), - _maximum_number_of_blocks_to_handle_at_one_time(MAXIMUM_NUMBER_OF_BLOCKS_TO_HANDLE_AT_ONE_TIME), - _maximum_number_of_sync_blocks_to_prefetch(MAXIMUM_NUMBER_OF_BLOCKS_TO_PREFETCH), - _maximum_blocks_per_peer_during_syncing(GRAPHENE_NET_MAX_BLOCKS_PER_PEER_DURING_SYNCING) + _node_is_shutting_down(false) { _rate_limiter.set_actual_rate_time_constant(fc::seconds(2)); fc::rand_pseudo_bytes(&_node_id.data[0], (int)_node_id.size()); @@ -920,7 +865,7 @@ namespace graphene { namespace net { namespace detail { iter != _potential_peer_db.end() && is_wanting_new_connections(); ++iter) { - fc::microseconds delay_until_retry = fc::seconds((iter->number_of_failed_connection_attempts + 1) * _peer_connection_retry_timeout); + fc::microseconds delay_until_retry = fc::seconds((iter->number_of_failed_connection_attempts + 1) * _node_configuration.peer_connection_retry_timeout); if (!is_connection_to_endpoint_in_progress(iter->endpoint) && ((iter->last_connection_disposition != last_connection_failed && @@ -1057,7 +1002,7 @@ namespace graphene { namespace net { namespace detail { // then schedule a request from this peer sync_item_requests_to_send[peer].push_back(item_to_potentially_request); sync_items_to_request.insert( item_to_potentially_request ); - if (sync_item_requests_to_send[peer].size() >= _maximum_blocks_per_peer_during_syncing) + if (sync_item_requests_to_send[peer].size() >= _node_configuration.maximum_blocks_per_peer_during_syncing) break; } } @@ -1335,7 +1280,7 @@ namespace graphene { namespace net { namespace detail { // those lists yielding at our leisure later. ASSERT_TASK_NOT_PREEMPTED(); - uint32_t handshaking_timeout = _peer_inactivity_timeout; + uint32_t handshaking_timeout = _node_configuration.peer_inactivity_timeout; fc::time_point handshaking_disconnect_threshold = fc::time_point::now() - fc::seconds(handshaking_timeout); for( const peer_connection_ptr handshaking_peer : _handshaking_connections ) if( handshaking_peer->connection_initiation_time < handshaking_disconnect_threshold && @@ -1366,9 +1311,9 @@ namespace graphene { namespace net { namespace detail { // to reply before we give up and ask another peer for the item. // Ideally this should be significantly shorter than the block interval, because // we'd like to realize the block isn't coming and fetch it from a different - // peer before the next block comes in. + // peer before the next block comes in. // Increased to 6 from 1 in #1660 due to heavy load. May need to adjust further - fc::microseconds active_ignored_request_timeout = fc::seconds(6); + fc::microseconds active_ignored_request_timeout = fc::microseconds( _node_configuration.active_ignored_request_timeout_microseconds ); fc::time_point active_disconnect_threshold = fc::time_point::now() - fc::seconds(active_disconnect_timeout); fc::time_point active_send_keepalive_threshold = fc::time_point::now() - fc::seconds(active_send_keepalive_timeout); @@ -1502,7 +1447,7 @@ namespace graphene { namespace net { namespace detail { fc::exception detailed_error( FC_LOG_MESSAGE(warn, "Disconnecting due to inactivity", ( "last_message_received_seconds_ago", (peer->get_last_message_received_time() - fc::time_point::now() ).count() / fc::seconds(1 ).count() ) ( "last_message_sent_seconds_ago", (peer->get_last_message_sent_time() - fc::time_point::now() ).count() / fc::seconds(1 ).count() ) - ( "inactivity_timeout", _active_connections.find(peer ) != _active_connections.end() ? _peer_inactivity_timeout * 10 : _peer_inactivity_timeout ) ) ); + ( "inactivity_timeout", _active_connections.find(peer ) != _active_connections.end() ? _node_configuration.peer_inactivity_timeout * 10 : _node_configuration.peer_inactivity_timeout ) ) ); disconnect_from_peer( peer.get(), "Disconnecting due to inactivity", false, detailed_error ); } peers_to_disconnect_gently.clear(); @@ -1674,13 +1619,13 @@ namespace graphene { namespace net { namespace detail { bool node_impl::is_accepting_new_connections() { VERIFY_CORRECT_THREAD(); - return !_p2p_network_connect_loop_done.canceled() && get_number_of_connections() <= _maximum_number_of_connections; + return !_p2p_network_connect_loop_done.canceled() && get_number_of_connections() <= _node_configuration.maximum_number_of_connections; } bool node_impl::is_wanting_new_connections() { VERIFY_CORRECT_THREAD(); - return !_p2p_network_connect_loop_done.canceled() && get_number_of_connections() < _desired_number_of_connections; + return !_p2p_network_connect_loop_done.canceled() && get_number_of_connections() < _node_configuration.desired_number_of_connections; } uint32_t node_impl::get_number_of_connections() @@ -1747,8 +1692,8 @@ namespace graphene { namespace net { namespace detail { VERIFY_CORRECT_THREAD(); dlog("Currently have ${current} of [${desired}/${max}] connections", ("current", get_number_of_connections()) - ("desired", _desired_number_of_connections) - ("max", _maximum_number_of_connections)); + ("desired", _node_configuration.desired_number_of_connections) + ("max", _node_configuration.maximum_number_of_connections)); dlog(" my id is ${id}", ("id", _node_id)); for (const peer_connection_ptr& active_connection : _active_connections) @@ -2180,7 +2125,7 @@ namespace graphene { namespace net { namespace detail { dlog("Received an address request message"); address_message reply; - if (!_peer_advertising_disabled) + if (!_node_configuration.peer_advertising_disabled) { reply.addresses.reserve(_active_connections.size()); for (const peer_connection_ptr& active_peer : _active_connections) @@ -3262,7 +3207,7 @@ namespace graphene { namespace net { namespace detail { } dlog("in process_backlog_of_sync_blocks"); - if (_handle_message_calls_in_progress.size() >= _maximum_number_of_blocks_to_handle_at_one_time) + if (_handle_message_calls_in_progress.size() >= _node_configuration.maximum_number_of_blocks_to_handle_at_one_time) { dlog("leaving process_backlog_of_sync_blocks because we're already processing too many blocks"); return; // we will be rescheduled when the next block finishes its processing @@ -3372,13 +3317,13 @@ namespace graphene { namespace net { namespace detail { } // end if potential_first_block } // end for each block in _received_sync_items - if (_handle_message_calls_in_progress.size() >= _maximum_number_of_blocks_to_handle_at_one_time) + if (_handle_message_calls_in_progress.size() >= _node_configuration.maximum_number_of_blocks_to_handle_at_one_time) { dlog("stopping processing sync block backlog because we have ${count} blocks in progress", ("count", _handle_message_calls_in_progress.size())); //ulog("stopping processing sync block backlog because we have ${count} blocks in progress, total on hand: ${received}", // ("count", _handle_message_calls_in_progress.size())("received", _received_sync_items.size())); - if (_received_sync_items.size() >= _maximum_number_of_sync_blocks_to_prefetch) + if (_received_sync_items.size() >= _node_configuration.maximum_number_of_sync_blocks_to_prefetch) _suspend_fetching_sync_blocks = true; break; } @@ -4499,7 +4444,7 @@ namespace graphene { namespace net { namespace detail { { try { - _node_configuration = fc::json::from_file( configuration_file_name ).as(); + _node_configuration = fc::json::from_file( configuration_file_name ).as(); ilog( "Loaded configuration from file ${filename}", ("filename", configuration_file_name ) ); if( _node_configuration.private_key == fc::ecc::private_key() ) @@ -4521,7 +4466,7 @@ namespace graphene { namespace net { namespace detail { if( !node_configuration_loaded ) { - _node_configuration = detail::node_configuration(); + _node_configuration = node_configuration(); #ifdef GRAPHENE_TEST_NETWORK uint32_t port = GRAPHENE_NET_TEST_P2P_PORT + GRAPHENE_TEST_NETWORK_VERSION; @@ -4548,7 +4493,7 @@ namespace graphene { namespace net { namespace detail { { potential_peer_record updated_peer_record = *itr; updated_peer_record.last_connection_attempt_time = std::min(updated_peer_record.last_connection_attempt_time, - fc::time_point::now() - fc::seconds(_peer_connection_retry_timeout)); + fc::time_point::now() - fc::seconds(_node_configuration.peer_connection_retry_timeout)); _potential_peer_db.update_entry(updated_peer_record); } @@ -4691,7 +4636,7 @@ namespace graphene { namespace net { namespace detail { // if we've recently connected to this peer, reset the last_connection_attempt_time to allow // us to immediately retry this peer updated_peer_record.last_connection_attempt_time = std::min(updated_peer_record.last_connection_attempt_time, - fc::time_point::now() - fc::seconds(_peer_connection_retry_timeout)); + fc::time_point::now() - fc::seconds(_node_configuration.peer_connection_retry_timeout)); _add_once_node_list.push_back(updated_peer_record); _potential_peer_db.update_entry(updated_peer_record); trigger_p2p_network_connect_loop(); @@ -4797,7 +4742,7 @@ namespace graphene { namespace net { namespace detail { ilog( "----------------- PEER STATUS UPDATE --------------------" ); ilog( " number of peers: ${active} active, ${handshaking}, ${closing} closing. attempting to maintain ${desired} - ${maximum} peers", ( "active", _active_connections.size() )("handshaking", _handshaking_connections.size() )("closing",_closing_connections.size() ) - ( "desired", _desired_number_of_connections )("maximum", _maximum_number_of_connections ) ); + ( "desired", _node_configuration.desired_number_of_connections )("maximum", _node_configuration.maximum_number_of_connections ) ); for( const peer_connection_ptr& peer : _active_connections ) { ilog( " active peer ${endpoint} peer_is_in_sync_with_us:${in_sync_with_us} we_are_in_sync_with_peer:${in_sync_with_them}", @@ -5052,38 +4997,27 @@ namespace graphene { namespace net { namespace detail { void node_impl::set_advanced_node_parameters(const fc::variant_object& params) { VERIFY_CORRECT_THREAD(); - if (params.contains("peer_connection_retry_timeout")) - _peer_connection_retry_timeout = params["peer_connection_retry_timeout"].as(); - if (params.contains("desired_number_of_connections")) - _desired_number_of_connections = params["desired_number_of_connections"].as(); - if (params.contains("maximum_number_of_connections")) - _maximum_number_of_connections = params["maximum_number_of_connections"].as(); - if (params.contains("maximum_number_of_blocks_to_handle_at_one_time")) - _maximum_number_of_blocks_to_handle_at_one_time = params["maximum_number_of_blocks_to_handle_at_one_time"].as(); - if (params.contains("maximum_number_of_sync_blocks_to_prefetch")) - _maximum_number_of_sync_blocks_to_prefetch = params["maximum_number_of_sync_blocks_to_prefetch"].as(); - if (params.contains("maximum_blocks_per_peer_during_syncing")) - _maximum_blocks_per_peer_during_syncing = params["maximum_blocks_per_peer_during_syncing"].as(); - - _desired_number_of_connections = std::min(_desired_number_of_connections, _maximum_number_of_connections); - - while (_active_connections.size() > _maximum_number_of_connections) + + fc::from_variant( params, _node_configuration ); + + if( _node_configuration.desired_number_of_connections > _node_configuration.maximum_number_of_connections ) + { + wlog( "Reducing desired_number_of_connections from ${x0} to maximum_number_of_connections=${x1}", + ("x0", _node_configuration.desired_number_of_connections) + ("x1", _node_configuration.maximum_number_of_connections) + ); + } + + while (_active_connections.size() > _node_configuration.maximum_number_of_connections) disconnect_from_peer(_active_connections.begin()->get(), "I have too many connections open"); trigger_p2p_network_connect_loop(); } - fc::variant_object node_impl::get_advanced_node_parameters() + node_configuration node_impl::get_advanced_node_parameters()const { VERIFY_CORRECT_THREAD(); - fc::mutable_variant_object result; - result["peer_connection_retry_timeout"] = _peer_connection_retry_timeout; - result["desired_number_of_connections"] = _desired_number_of_connections; - result["maximum_number_of_connections"] = _maximum_number_of_connections; - result["maximum_number_of_blocks_to_handle_at_one_time"] = _maximum_number_of_blocks_to_handle_at_one_time; - result["maximum_number_of_sync_blocks_to_prefetch"] = _maximum_number_of_sync_blocks_to_prefetch; - result["maximum_blocks_per_peer_during_syncing"] = _maximum_blocks_per_peer_during_syncing; - return result; + return _node_configuration; } message_propagation_data node_impl::get_transaction_propagation_data( const graphene::net::transaction_id_type& transaction_id ) @@ -5131,12 +5065,6 @@ namespace graphene { namespace net { namespace detail { _rate_limiter.set_download_limit( download_bytes_per_second ); } - void node_impl::disable_peer_advertising() - { - VERIFY_CORRECT_THREAD(); - _peer_advertising_disabled = true; - } - fc::variant_object node_impl::get_call_statistics() const { VERIFY_CORRECT_THREAD(); @@ -5305,7 +5233,7 @@ namespace graphene { namespace net { namespace detail { INVOKE_IN_IMPL(set_advanced_node_parameters, params); } - fc::variant_object node::get_advanced_node_parameters() + node_configuration node::get_advanced_node_parameters()const { INVOKE_IN_IMPL(get_advanced_node_parameters); } @@ -5341,11 +5269,6 @@ namespace graphene { namespace net { namespace detail { INVOKE_IN_IMPL(set_total_bandwidth_limit, upload_bytes_per_second, download_bytes_per_second); } - void node::disable_peer_advertising() - { - INVOKE_IN_IMPL(disable_peer_advertising); - } - fc::variant_object node::get_call_statistics() const { INVOKE_IN_IMPL(get_call_statistics);