Skip to content

Commit

Permalink
Merge pull request steemit#1690 from steemit/2017-10-23-runtime-p2p-c…
Browse files Browse the repository at this point in the history
…onfig

Expose more p2p configuration to config file
  • Loading branch information
theoreticalbts authored Oct 25, 2017
2 parents 8bd4f5b + 85a455c commit e4a8324
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 125 deletions.
2 changes: 1 addition & 1 deletion libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
33 changes: 27 additions & 6 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<fc::temp_file> _lock_file;
bool _is_block_producer = false;
Expand Down Expand Up @@ -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<string>(), 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()));

Expand Down Expand Up @@ -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) );
}
}
}
Expand Down Expand Up @@ -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") )
{
Expand Down Expand Up @@ -997,6 +1016,7 @@ void application::set_program_options(boost::program_options::options_descriptio
configuration_file_options.add_options()
("p2p-endpoint", bpo::value<string>(), "Endpoint for P2P node to listen on")
("p2p-max-connections", bpo::value<uint32_t>(), "Maxmimum number of incoming connections on P2P endpoint")
("p2p-parameters", bpo::value<string>()->default_value(fc::json::to_string(graphene::net::node_configuration())), "P2P network parameters")
("seed-node,s", bpo::value<vector<string>>()->composing(), "P2P nodes to connect to on startup (may specify multiple times)")
("checkpoint,c", bpo::value<vector<string>>()->composing(), "Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints.")
("shared-file-dir", bpo::value<string>(), "Location of the shared memory file. Defaults to data_dir/blockchain")
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion libraries/app/include/steemit/app/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions libraries/net/include/graphene/net/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions libraries/net/include/graphene/net/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <graphene/net/core_messages.hpp>
#include <graphene/net/message.hpp>
#include <graphene/net/node_configuration.hpp>
#include <graphene/net/peer_database.hpp>

#include <steemit/protocol/types.hpp>
Expand Down Expand Up @@ -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;
Expand All @@ -290,7 +291,6 @@ namespace graphene { namespace net {

std::vector<potential_peer_record> get_potential_peers() const;

void disable_peer_advertising();
fc::variant_object get_call_statistics() const;
private:
std::unique_ptr<detail::node_impl, detail::node_impl_deleter> my;
Expand Down
59 changes: 59 additions & 0 deletions libraries/net/include/graphene/net/node_configuration.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma once

#include <graphene/net/config.hpp>

#include <fc/crypto/elliptic.hpp>
#include <fc/network/ip.hpp>

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

0 comments on commit e4a8324

Please sign in to comment.