Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 32 additions & 33 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void application_impl::reset_p2p_node(const fc::path& data_dir)
for( const string& endpoint_string : seeds )
{
try {
std::vector<fc::ip::endpoint> endpoints = resolve_string_to_ip_endpoints(endpoint_string);
std::vector<fc::ip::endpoint> endpoints = application::resolve_string_to_ip_endpoints(endpoint_string);
for (const fc::ip::endpoint& endpoint : endpoints)
{
ilog("Adding seed node ${endpoint}", ("endpoint", endpoint));
Expand All @@ -149,7 +149,7 @@ void application_impl::reset_p2p_node(const fc::path& data_dir)
for( const string& endpoint_string : seeds )
{
try {
std::vector<fc::ip::endpoint> endpoints = resolve_string_to_ip_endpoints(endpoint_string);
std::vector<fc::ip::endpoint> endpoints = application::resolve_string_to_ip_endpoints(endpoint_string);
for (const fc::ip::endpoint& endpoint : endpoints)
{
ilog("Adding seed node ${endpoint}", ("endpoint", endpoint));
Expand All @@ -170,7 +170,7 @@ void application_impl::reset_p2p_node(const fc::path& data_dir)
for( const string& endpoint_string : seeds )
{
try {
std::vector<fc::ip::endpoint> endpoints = resolve_string_to_ip_endpoints(endpoint_string);
std::vector<fc::ip::endpoint> endpoints = application::resolve_string_to_ip_endpoints(endpoint_string);
for (const fc::ip::endpoint& endpoint : endpoints)
{
ilog("Adding seed node ${endpoint}", ("endpoint", endpoint));
Expand All @@ -196,36 +196,6 @@ void application_impl::reset_p2p_node(const fc::path& data_dir)
std::vector<uint32_t>());
} FC_CAPTURE_AND_RETHROW() }

std::vector<fc::ip::endpoint> application_impl::resolve_string_to_ip_endpoints(const std::string& endpoint_string)
{
try
{
string::size_type colon_pos = endpoint_string.find(':');
if (colon_pos == std::string::npos)
FC_THROW("Missing required port number in endpoint string \"${endpoint_string}\"",
("endpoint_string", endpoint_string));
std::string port_string = endpoint_string.substr(colon_pos + 1);
try
{
uint16_t port = boost::lexical_cast<uint16_t>(port_string);

std::string hostname = endpoint_string.substr(0, colon_pos);
std::vector<fc::ip::endpoint> endpoints = fc::resolve(hostname, port);
if (endpoints.empty())
FC_THROW_EXCEPTION( fc::unknown_host_exception,
"The host name can not be resolved: ${hostname}",
("hostname", hostname) );
return endpoints;
}
catch (const boost::bad_lexical_cast&)
{
FC_THROW("Bad port: ${port}", ("port", port_string));
}
}
FC_CAPTURE_AND_RETHROW((endpoint_string))
}


void application_impl::new_connection( const fc::http::websocket_connection_ptr& c )
{
auto wsc = std::make_shared<fc::rpc::websocket_api_connection>(c, GRAPHENE_NET_MAX_NESTED_OBJECTS);
Expand Down Expand Up @@ -988,6 +958,35 @@ application::~application()
}
}

std::vector<fc::ip::endpoint> application::resolve_string_to_ip_endpoints(const std::string& endpoint_string)
{
try
{
string::size_type colon_pos = endpoint_string.find(':');
if (colon_pos == std::string::npos)
FC_THROW("Missing required port number in endpoint string \"${endpoint_string}\"",
("endpoint_string", endpoint_string));
std::string port_string = endpoint_string.substr(colon_pos + 1);
try
{
uint16_t port = boost::lexical_cast<uint16_t>(port_string);

std::string hostname = endpoint_string.substr(0, colon_pos);
std::vector<fc::ip::endpoint> endpoints = fc::resolve(hostname, port);
if (endpoints.empty())
FC_THROW_EXCEPTION( fc::unknown_host_exception,
"The host name can not be resolved: ${hostname}",
("hostname", hostname) );
return endpoints;
}
catch (const boost::bad_lexical_cast&)
{
FC_THROW("Bad port: ${port}", ("port", port_string));
}
}
FC_CAPTURE_AND_RETHROW((endpoint_string))
}

void application::set_program_options(boost::program_options::options_description& command_line_options,
boost::program_options::options_description& configuration_file_options) const
{
Expand Down
2 changes: 0 additions & 2 deletions libraries/app/application_impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class application_impl : public net::node_delegate

void reset_p2p_node(const fc::path& data_dir);

std::vector<fc::ip::endpoint> resolve_string_to_ip_endpoints(const std::string& endpoint_string);

void new_connection( const fc::http::websocket_connection_ptr& c );

void reset_websocket_server();
Expand Down
2 changes: 2 additions & 0 deletions libraries/app/include/graphene/app/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ namespace graphene { namespace app {

bool is_plugin_enabled(const string& name) const;

static std::vector<fc::ip::endpoint> resolve_string_to_ip_endpoints(const std::string& endpoint_string);

std::shared_ptr<fc::thread> elasticsearch_thread;

private:
Expand Down
9 changes: 6 additions & 3 deletions libraries/net/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ namespace graphene { namespace net { namespace detail {
item_hash_t head_block_id = _delegate->get_head_block_id();
user_data["last_known_block_hash"] = fc::variant( head_block_id, 1 );
user_data["last_known_block_number"] = _delegate->get_block_number(head_block_id);
user_data["last_known_block_time"] = _delegate->get_block_time(head_block_id);
user_data["last_known_block_time"] = _delegate->get_block_time(head_block_id);

if (!_hard_fork_block_numbers.empty())
user_data["last_known_fork_block_number"] = _hard_fork_block_numbers.back();
Expand Down Expand Up @@ -4184,6 +4184,7 @@ namespace graphene { namespace net { namespace detail {

void node_impl::add_node(const fc::ip::endpoint& ep)
{
dlog("Attempting to add node ${ip}", ("ip", ep));
VERIFY_CORRECT_THREAD();
// if we're connecting to them, we believe they're not firewalled
potential_peer_record updated_peer_record = _potential_peer_db.lookup_or_create_entry_for_endpoint(ep);
Expand Down Expand Up @@ -5076,12 +5077,14 @@ namespace graphene { namespace net { namespace detail {

fc::time_point_sec statistics_gathering_node_delegate_wrapper::get_block_time(const item_hash_t& block_id)
{
INVOKE_AND_COLLECT_STATISTICS(get_block_time, block_id);
//INVOKE_AND_COLLECT_STATISTICS(get_block_time, block_id);
return _node_delegate->get_block_time(block_id);
}

item_hash_t statistics_gathering_node_delegate_wrapper::get_head_block_id() const
{
INVOKE_AND_COLLECT_STATISTICS(get_head_block_id);
//INVOKE_AND_COLLECT_STATISTICS(get_head_block_id);
_node_delegate->get_head_block_id();
}

uint32_t statistics_gathering_node_delegate_wrapper::estimate_last_known_fork_from_git_revision_timestamp(uint32_t unix_timestamp) const
Expand Down
9 changes: 7 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
file(GLOB COMMON_SOURCES "common/*.cpp")
file(GLOB COMMON_SOURCES "common/database_fixture.cpp")

find_package( Gperftools QUIET )
if( GPERFTOOLS_FOUND )
Expand Down Expand Up @@ -31,10 +31,15 @@ target_link_libraries( chain_bench
graphene_es_objects graphene_egenesis_none graphene_api_helper_indexes
fc ${PLATFORM_SPECIFIC_LIBS} )

file(GLOB APP_SOURCES "app/*.cpp")
file(GLOB APP_SOURCES "app/main.cpp")
add_executable( app_test ${APP_SOURCES} )
target_link_libraries( app_test graphene_app graphene_account_history graphene_net graphene_witness graphene_chain graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} )

file(GLOB GOOD_NODE_SOURCES "common/application_helper.cpp" "app/good_node.cpp")
add_executable( good_node ${GOOD_NODE_SOURCES} )
target_include_directories( good_node PRIVATE "../libraries/plugins/witness/include" )
target_link_libraries( good_node graphene_app graphene_account_history graphene_net graphene_witness graphene_chain graphene_egenesis_none fc ${PLATFORM_SPECIFIC_LIBS} )

file(GLOB CLI_SOURCES "cli/*.cpp")
add_executable( cli_test ${CLI_SOURCES} )
if(WIN32)
Expand Down
69 changes: 69 additions & 0 deletions tests/app/good_node.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "../common/application_helper.hpp"
#include <fc/log/logger.hpp>
#include <fc/log/logger_config.hpp>
#include <thread>
#include <memory>
#include <csignal>

namespace fc {
extern std::unordered_map<std::string,logger>& get_logger_map();
extern std::unordered_map<std::string,appender::ptr>& get_appender_map();
}

int main(int argc, char** argv)
{
fc::temp_directory td;
std::shared_ptr<fc::path> temp_dir = nullptr;
std::string remote_node_ip;
std::string my_port = "0";
int timeout = -1;
for (int i = 1; i < argc; i++)
{
if (std::string(argv[i]) == "-d")
temp_dir = std::make_shared<fc::path>( fc::path(argv[i+1]));
if (std::string(argv[i]) == "-s")
remote_node_ip = argv[i+1];
if (std::string(argv[i]) == "-p")
my_port = argv[i+1];
if (std::string(argv[i]) == "-t")
timeout = std::stoi(argv[i+1]);
}
// we were not passed a temp directory, create one
if (!temp_dir)
temp_dir = std::make_shared<fc::path>( td.path() );
// start node
graphene::test::application_runner app(temp_dir, std::stoi(my_port));
app.start();
std::string p2p_address = "127.0.0.1:" + std::to_string( app.p2p_port_number );

// adjust logging
auto log_map = fc::get_logger_map();
auto appenders = fc::get_appender_map();
auto p2p_logger = log_map["p2p"];
p2p_logger.add_appender( appenders["stdout"] );
p2p_logger.set_log_level(fc::log_level::debug);
auto default_logger = log_map["default"];
default_logger.set_log_level(fc::log_level::debug);
std::cout << "Running on " << p2p_address << std::endl;

// add node if passed in
if (!remote_node_ip.empty())
{
std::this_thread::sleep_for(std::chrono::seconds(5));
std::cout << "attempting to add node " << remote_node_ip << "\n";
app.add_node(remote_node_ip);
}

if (timeout == -1)
{
std::cout << "Press e [enter] to exit" << std::endl;
char c = 0;
while( c != 'e' )
std::cin >> c;
}
else
{
std::this_thread::sleep_for(std::chrono::seconds(timeout));
::raise(SIGINT);
}
}
4 changes: 2 additions & 2 deletions tests/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ BOOST_AUTO_TEST_CASE( two_node_network )
app1.startup_plugins();
boost::program_options::variables_map cfg;
cfg.emplace("p2p-endpoint", boost::program_options::variable_value(string("127.0.0.1:3939"), false));
cfg.emplace("genesis-json", boost::program_options::variable_value(create_genesis_file(app_dir), false));
cfg.emplace("genesis-json", boost::program_options::variable_value(create_genesis_file(app_dir.path()), false));
cfg.emplace("seed-nodes", boost::program_options::variable_value(string("[]"), false));
app1.initialize(app_dir.path(), cfg);
BOOST_TEST_MESSAGE( "Starting app1 and waiting 500 ms" );
Expand All @@ -246,7 +246,7 @@ BOOST_AUTO_TEST_CASE( two_node_network )
auto cfg2 = cfg;
cfg2.erase("p2p-endpoint");
cfg2.emplace("p2p-endpoint", boost::program_options::variable_value(string("127.0.0.1:4040"), false));
cfg2.emplace("genesis-json", boost::program_options::variable_value(create_genesis_file(app_dir), false));
cfg2.emplace("genesis-json", boost::program_options::variable_value(create_genesis_file(app_dir.path()), false));
cfg2.emplace("seed-node", boost::program_options::variable_value(vector<string>{"127.0.0.1:3939"}, false));
cfg2.emplace("seed-nodes", boost::program_options::variable_value(string("[]"), false));
app2.initialize(app2_dir.path(), cfg2);
Expand Down
2 changes: 1 addition & 1 deletion tests/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ std::shared_ptr<graphene::app::application> start_application(fc::temp_directory
"rpc-endpoint",
boost::program_options::variable_value(string("127.0.0.1:" + std::to_string(server_port_number)), false)
);
cfg.emplace("genesis-json", boost::program_options::variable_value(create_genesis_file(app_dir), false));
cfg.emplace("genesis-json", boost::program_options::variable_value(create_genesis_file(app_dir.path()), false));
cfg.emplace("seed-nodes", boost::program_options::variable_value(string("[]"), false));
app1->initialize(app_dir.path(), cfg);

Expand Down
Loading