diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 6263ab1ec8..cf4204b4e1 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -192,7 +192,11 @@ void application_impl::reset_websocket_server() if( !_options->count("rpc-endpoint") ) return; - _websocket_server = std::make_shared(); + string proxy_forward_header; + if( _options->count("proxy-forwarded-for-header") ) + proxy_forward_header = _options->at("proxy-forwarded-for-header").as(); + + _websocket_server = std::make_shared( proxy_forward_header ); _websocket_server->on_connection( std::bind(&application_impl::new_connection, this, std::placeholders::_1) ); ilog("Configured websocket rpc to listen on ${ip}", ("ip",_options->at("rpc-endpoint").as())); @@ -210,8 +214,13 @@ void application_impl::reset_websocket_tls_server() return; } + string proxy_forward_header; + if( _options->count("proxy-forwarded-for-header") ) + proxy_forward_header = _options->at("proxy-forwarded-for-header").as(); + string password = _options->count("server-pem-password") ? _options->at("server-pem-password").as() : ""; - _websocket_tls_server = std::make_shared( _options->at("server-pem").as(), password ); + _websocket_tls_server = std::make_shared( + _options->at("server-pem").as(), password, proxy_forward_header ); _websocket_tls_server->on_connection( std::bind(&application_impl::new_connection, this, std::placeholders::_1) ); ilog("Configured websocket TLS rpc to listen on ${ip}", ("ip",_options->at("rpc-tls-endpoint").as())); @@ -974,6 +983,9 @@ void application::set_program_options(boost::program_options::options_descriptio "Endpoint for TLS websocket RPC to listen on") ("server-pem,p", bpo::value()->implicit_value("server.pem"), "The TLS certificate file for this server") ("server-pem-password,P", bpo::value()->implicit_value(""), "Password for this certificate") + ("proxy-forwarded-for-header", bpo::value()->implicit_value("X-Forwarded-For-Client"), + "A HTTP header similar to X-Forwarded-For (XFF), used by the RPC server to extract clients' address info, " + "usually added by a trusted reverse proxy") ("genesis-json", bpo::value(), "File to read Genesis State from") ("dbg-init-key", bpo::value(), "Block signing key to use for init witnesses, overrides genesis file") ("api-access", bpo::value(), "JSON file specifying API permissions") diff --git a/libraries/fc b/libraries/fc index 73a7f08f00..c00824a137 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit 73a7f08f00456b0984cd431dd8f55bd901282e15 +Subproject commit c00824a1374eeb75dba23d9ab2e7830b195b63d4 diff --git a/programs/build_helpers/run-node-test b/programs/build_helpers/run-node-test index e7362c4cb1..1f80ffc7d0 100755 --- a/programs/build_helpers/run-node-test +++ b/programs/build_helpers/run-node-test @@ -22,12 +22,12 @@ NODE_PID=$! echo "Waiting for cli_wallet start..." 1>&2 & CLI_PID=$! -sleep 1 +sleep 5 _START="`date +%s`" -while ! ps -p "$CLI_PID" >/dev/null && [ $((`date +%s` - _START)) -lt 120 ]; do +while ! ps -p "$CLI_PID" >/dev/null && [ $((`date +%s` - $_START)) -lt 120 ]; do programs/cli_wallet/cli_wallet -sws://127.0.0.1:8090 -d -H127.0.0.1:8091 >cli.log 2>&1 & CLI_PID=$! - sleep 2 + sleep 10 done if ! ps -p "$CLI_PID" >/dev/null; then diff --git a/programs/cli_wallet/main.cpp b/programs/cli_wallet/main.cpp index abe317cd31..dc6249d596 100644 --- a/programs/cli_wallet/main.cpp +++ b/programs/cli_wallet/main.cpp @@ -245,7 +245,7 @@ int main( int argc, char** argv ) std::shared_ptr _websocket_server; if( options.count("rpc-endpoint") ) { - _websocket_server = std::make_shared(); + _websocket_server = std::make_shared(""); _websocket_server->on_connection([&wapi]( const fc::http::websocket_connection_ptr& c ){ auto wsc = std::make_shared(c, GRAPHENE_MAX_NESTED_OBJECTS); wsc->register_api(wapi); @@ -263,7 +263,7 @@ int main( int argc, char** argv ) std::shared_ptr _websocket_tls_server; if( options.count("rpc-tls-endpoint") ) { - _websocket_tls_server = std::make_shared(cert_pem); + _websocket_tls_server = std::make_shared(cert_pem, "", ""); _websocket_tls_server->on_connection([&wapi]( const fc::http::websocket_connection_ptr& c ){ auto wsc = std::make_shared(c, GRAPHENE_MAX_NESTED_OBJECTS); wsc->register_api(wapi); @@ -278,7 +278,7 @@ int main( int argc, char** argv ) std::shared_ptr _http_ws_server; if( options.count("rpc-http-endpoint" ) ) { - _http_ws_server = std::make_shared(); + _http_ws_server = std::make_shared(""); ilog( "Listening for incoming HTTP and WS RPC requests on ${p}", ("p", options.at("rpc-http-endpoint").as()) ); _http_ws_server->on_connection([&wapi]( const fc::http::websocket_connection_ptr& c ){ diff --git a/tests/app/main.cpp b/tests/app/main.cpp index f8515a2d77..14c1d3c4fd 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -245,7 +245,12 @@ BOOST_AUTO_TEST_CASE( two_node_network ) app1.initialize(app_dir.path(), cfg); BOOST_TEST_MESSAGE( "Starting app1 and waiting 500 ms" ); app1.startup(); - fc::wait_for( fc::seconds(10), [&app1] () { + #ifdef NDEBUG + #define LISTEN_WAIT_TIME (fc::milliseconds(10000)) + #else + #define LISTEN_WAIT_TIME (fc::milliseconds(30000)) + #endif + fc::wait_for( LISTEN_WAIT_TIME, [&app1] () { const auto status = app1.p2p_node()->network_get_info(); return status["listening_on"].as( 5 ).port() == 3939; }); @@ -268,7 +273,12 @@ BOOST_AUTO_TEST_CASE( two_node_network ) BOOST_TEST_MESSAGE( "Starting app2 and waiting for connection" ); app2.startup(); - fc::wait_for( fc::seconds(10), [&app1] () { return app1.p2p_node()->get_connection_count() > 0; } ); + #ifdef NDEBUG + #define CONNECT_WAIT_TIME (fc::milliseconds(10000)) + #else + #define CONNECT_WAIT_TIME (fc::milliseconds(30000)) + #endif + fc::wait_for( CONNECT_WAIT_TIME, [&app1] () { return app1.p2p_node()->get_connection_count() > 0; } ); BOOST_REQUIRE_EQUAL(app1.p2p_node()->get_connection_count(), 1u); BOOST_CHECK_EQUAL(std::string(app1.p2p_node()->get_connected_peers().front().host.get_address()), "127.0.0.1"); @@ -316,7 +326,12 @@ BOOST_AUTO_TEST_CASE( two_node_network ) BOOST_TEST_MESSAGE( "Broadcasting tx" ); app1.p2p_node()->broadcast(graphene::net::trx_message(trx)); - fc::usleep(fc::milliseconds(3000)); + #ifdef NDEBUG + #define BROADCAST_WAIT_TIME (fc::milliseconds(5000)) + #else + #define BROADCAST_WAIT_TIME (fc::milliseconds(15000)) + #endif + fc::usleep( BROADCAST_WAIT_TIME ); BOOST_CHECK_EQUAL( db1->get_balance( GRAPHENE_NULL_ACCOUNT, asset_id_type() ).amount.value, 1000000 ); BOOST_CHECK_EQUAL( db2->get_balance( GRAPHENE_NULL_ACCOUNT, asset_id_type() ).amount.value, 1000000 ); @@ -333,7 +348,8 @@ BOOST_AUTO_TEST_CASE( two_node_network ) BOOST_TEST_MESSAGE( "Broadcasting block" ); app2.p2p_node()->broadcast(graphene::net::block_message( block_1 )); - fc::usleep(fc::milliseconds(3000)); + fc::usleep( BROADCAST_WAIT_TIME ); + BOOST_TEST_MESSAGE( "Verifying nodes are still connected" ); BOOST_CHECK_EQUAL(app1.p2p_node()->get_connection_count(), 1u); BOOST_CHECK_EQUAL(app1.chain_database()->head_block_num(), 1u); diff --git a/tests/tests/main.cpp b/tests/tests/main.cpp index 405e7c1059..0c3e9f7644 100644 --- a/tests/tests/main.cpp +++ b/tests/tests/main.cpp @@ -24,12 +24,14 @@ #include #include #include +#include extern uint32_t GRAPHENE_TESTING_GENESIS_TIMESTAMP; boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { - std::srand(time(NULL)); - std::cout << "Random number generator seeded to " << time(NULL) << std::endl; + const auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count(); + std::srand( seed ); + std::cout << "Random number generator seeded to " << seed << std::endl; const char* genesis_timestamp_str = getenv("GRAPHENE_TESTING_GENESIS_TIMESTAMP"); if( genesis_timestamp_str != nullptr ) {