Skip to content

Commit

Permalink
Expose node configuration via config file
Browse files Browse the repository at this point in the history
  • Loading branch information
theoreticalbts committed Oct 24, 2017
1 parent 953d04d commit 6bb865b
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 119 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
9 changes: 9 additions & 0 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
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 @@ -1008,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("{}"), "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 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 6bb865b

Please sign in to comment.