diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index bd72c802..1d78bb3f 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -57,6 +57,7 @@ namespace const command_line::arg_descriptor arg_scan_for_wallet ( "scan-for-wallet", ""); const command_line::arg_descriptor arg_addr_to_compare ( "addr-to-compare", ""); const command_line::arg_descriptor arg_disable_tor_relay ( "disable-tor-relay", "Disable TOR relay", false); + const command_line::arg_descriptor arg_set_timeout("set-timeout", "Set timeout for the wallet"); const command_line::arg_descriptor< std::vector > arg_command ("command", ""); @@ -261,6 +262,29 @@ bool simple_wallet::set_log(const std::vector &args) return true; } //---------------------------------------------------------------------------------------------------- +void process_wallet_command_line_params(const po::variables_map& vm, tools::wallet2& wal, bool is_server_mode = true) +{ + if (command_line::has_arg(vm, arg_disable_tor_relay)) + { + wal.set_disable_tor_relay(command_line::get_arg(vm, arg_disable_tor_relay)); + message_writer(epee::log_space::console_color_default, true, std::string(), LOG_LEVEL_0) << "Notice: Relaying transactions over TOR disabled with command line parameter"; + } + else + { + if (is_server_mode) + { + //disable TOR by default for server-mode, to avoid potential sporadic errors due to TOR connectivity fails + wal.set_disable_tor_relay(true); + } + } + + if (command_line::has_arg(vm, arg_set_timeout)) + { + wal.set_connectivity_options(command_line::get_arg(vm, arg_set_timeout)); + } + +} +//---------------------------------------------------------------------------------------------------- bool simple_wallet::init(const boost::program_options::variables_map& vm) { handle_command_line(vm); @@ -305,7 +329,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) m_do_refresh_after_load = false; } - + bool was_open = false; if (!m_generate_new.empty()) { bool r = new_wallet(m_generate_new, pwd_container.password(), false); @@ -356,12 +380,14 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) { bool r = open_wallet(m_wallet_file, pwd_container.password()); CHECK_AND_ASSERT_MES(r, false, "could not open account"); + was_open = true; } - if (m_disable_tor) - { - m_wallet->set_disable_tor_relay(true); - message_writer(epee::log_space::console_color_default, true, std::string(), LOG_LEVEL_0) << "Notice: Relaying transactions over TOR disabled with command line parameter"; - } + process_wallet_command_line_params(vm, *m_wallet, false); + + m_wallet->init(m_daemon_address); + + if (was_open && (m_do_refresh_after_load && !m_offline_mode)) + refresh(std::vector()); return true; } @@ -425,9 +451,6 @@ bool simple_wallet::new_wallet(const string &wallet_file, const std::string& pas return false; } - m_wallet->init(m_daemon_address); - - success_msg_writer() << "**********************************************************************\n" << "Your wallet has been generated.\n" << @@ -472,7 +495,6 @@ bool simple_wallet::restore_wallet(const std::string& wallet_file, const std::st fail_msg_writer() << "failed to restore wallet, check your " << (tracking_wallet ? "tracking seed!" : "seed phrase!") << ENDL; return false; } - m_wallet->init(m_daemon_address); success_msg_writer() << "**********************************************************************\n" << @@ -514,12 +536,6 @@ bool simple_wallet::open_wallet(const string &wallet_file, const std::string& pa } } - - m_wallet->init(m_daemon_address); - - if (m_do_refresh_after_load && !m_offline_mode) - refresh(std::vector()); - success_msg_writer() << "**********************************************************************\n" << "Use \"help\" command to see the list of available commands.\n" << @@ -1946,6 +1962,7 @@ bool search_for_wallet_file(const std::wstring &search_here/*, const std::string } return false; } + //---------------------------------------------------------------------------------------------------- #ifdef WIN32 int wmain( int argc, wchar_t* argv_w[ ], wchar_t* envp[ ] ) @@ -2006,6 +2023,8 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_params, arg_scan_for_wallet); command_line::add_arg(desc_params, arg_addr_to_compare); command_line::add_arg(desc_params, arg_disable_tor_relay); + command_line::add_arg(desc_params, arg_set_timeout); + tools::wallet_rpc_server::init_options(desc_params); @@ -2148,6 +2167,7 @@ int main(int argc, char* argv[]) try { LOG_PRINT_L0("Initializing wallet..."); + process_wallet_command_line_params(vm, wal); wal.init(daemon_address); if (command_line::get_arg(vm, arg_generate_new_wallet).size() || command_line::get_arg(vm, arg_generate_new_auditable_wallet).size()) return EXIT_FAILURE; @@ -2178,15 +2198,6 @@ int main(int argc, char* argv[]) } } - if (command_line::has_arg(vm, arg_disable_tor_relay)) - { - wal.set_disable_tor_relay(command_line::get_arg(vm, arg_disable_tor_relay)); - } - else - { - //disable TOR by default for server-mode, to avoid potential sporadic errors due to TOR connectivity fails - wal.set_disable_tor_relay(true); - } tools::wallet_rpc_server wrpc(wal); diff --git a/src/wallet/core_default_rpc_proxy.cpp b/src/wallet/core_default_rpc_proxy.cpp index 9de9f344..6fdbd693 100644 --- a/src/wallet/core_default_rpc_proxy.cpp +++ b/src/wallet/core_default_rpc_proxy.cpp @@ -184,11 +184,10 @@ namespace tools // m_plast_daemon_is_disconnected = plast_daemon_is_disconnected ? plast_daemon_is_disconnected : &m_last_daemon_is_disconnected_stub; // } //------------------------------------------------------------------------------------------------------------------------------ - bool default_http_core_proxy::set_connectivity(unsigned int connection_timeout, size_t repeats_count) + void default_http_core_proxy::set_connectivity(unsigned int connection_timeout, size_t repeats_count) { m_connection_timeout = connection_timeout; m_attempts_count = repeats_count; - return true; } //------------------------------------------------------------------------------------------------------------------------------ default_http_core_proxy::default_http_core_proxy(): //:m_plast_daemon_is_disconnected(&m_last_daemon_is_disconnected_stub), diff --git a/src/wallet/core_default_rpc_proxy.h b/src/wallet/core_default_rpc_proxy.h index 77d3a4f3..d5773c4e 100644 --- a/src/wallet/core_default_rpc_proxy.h +++ b/src/wallet/core_default_rpc_proxy.h @@ -28,7 +28,7 @@ namespace tools bool set_connection_addr(const std::string& url) override; - bool set_connectivity(unsigned int connection_timeout, size_t repeats_count); + void set_connectivity(unsigned int connection_timeout, size_t repeats_count); bool call_COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES(const currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::request& rqt, currency::COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES::response& rsp) override; bool call_COMMAND_RPC_GET_BLOCKS_FAST(const currency::COMMAND_RPC_GET_BLOCKS_FAST::request& rqt, currency::COMMAND_RPC_GET_BLOCKS_FAST::response& rsp) override; bool call_COMMAND_RPC_GET_BLOCKS_DIRECT(const currency::COMMAND_RPC_GET_BLOCKS_DIRECT::request& rqt, currency::COMMAND_RPC_GET_BLOCKS_DIRECT::response& rsp) override; @@ -56,7 +56,7 @@ namespace tools bool check_connection() override; bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr, std::string& payment_id) override; - void set_plast_daemon_is_disconnected(std::atomic *plast_daemon_is_disconnected); + void set_plast_daemon_is_disconnected(std::atomic *plast_daemon_is_disconnected); default_http_core_proxy(); private: diff --git a/src/wallet/core_rpc_proxy.h b/src/wallet/core_rpc_proxy.h index b8d2e303..68ff46b5 100644 --- a/src/wallet/core_rpc_proxy.h +++ b/src/wallet/core_rpc_proxy.h @@ -63,6 +63,7 @@ namespace tools std::shared_ptr get_proxy_diagnostic_info() const { return m_pdiganostic_info; } std::shared_ptr get_editable_proxy_diagnostic_info() { return m_pdiganostic_info; } virtual bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr, std::string& payment_id){ return false; } + virtual void set_connectivity(unsigned int connection_timeout, size_t repeats_count) {} protected: std::shared_ptr m_pdiganostic_info; }; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index c1f4f3fb..c73678a6 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -3323,7 +3323,11 @@ void wallet2::wti_to_json_line(std::ostream& ss, const wallet_public::wallet_tra ss << epee::serialization::store_t_to_json(wti, 4) << ","; }; - +//---------------------------------------------------------------------------------------------------- +void wallet2::set_connectivity_options(unsigned int timeout) +{ + m_core_proxy->set_connectivity(timeout, WALLET_RCP_COUNT_ATTEMNTS); +} //---------------------------------------------------------------------------------------------------- void wallet2::export_transaction_history(std::ostream& ss, const std::string& format, bool include_pos_transactions) { diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index d0c80a00..b8ecac13 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -867,6 +867,7 @@ namespace tools void set_disable_tor_relay(bool disable); uint64_t get_default_fee() {return TX_DEFAULT_FEE;} void export_transaction_history(std::ostream& ss, const std::string& format, bool include_pos_transactions = true); + void set_connectivity_options(unsigned int timeout); /* create_htlc_proposal: if htlc_hash == null_hash, then this wallet is originator of the atomic process, and diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5e6a9006..40c89aee 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -32,7 +32,7 @@ target_link_libraries(coretests rpc wallet currency_core common crypto zlibstati target_link_libraries(functional_tests rpc wallet currency_core crypto common zlibstatic ethash libminiupnpc-static ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) target_link_libraries(hash-tests crypto ethash) target_link_libraries(hash-target-tests crypto currency_core ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) -target_link_libraries(performance_tests currency_core common crypto zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +target_link_libraries(performance_tests wallet currency_core common crypto zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) target_link_libraries(unit_tests wallet currency_core common crypto gtest_main zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) target_link_libraries(net_load_tests_clt currency_core common crypto gtest_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) target_link_libraries(net_load_tests_srv currency_core common crypto gtest_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) diff --git a/tests/performance_tests/api_test.cpp b/tests/performance_tests/api_test.cpp new file mode 100644 index 00000000..6a492c28 --- /dev/null +++ b/tests/performance_tests/api_test.cpp @@ -0,0 +1,25 @@ +// Copyright (c) 2012-2013 The Cryptonote developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + + +#include "wallet/core_rpc_proxy.h" +#include "wallet/core_default_rpc_proxy.h" + +int test_get_rand_outs() +{ + currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::request req = AUTO_VAL_INIT(req); + currency::COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS::response rsp = AUTO_VAL_INIT(rsp); + req.use_forced_mix_outs = false; + req.outs_count = 10 + 1; + for (size_t i = 0; i != 50; i++) + req.amounts.push_back(COIN); + + std::shared_ptr m_core_proxy(new tools::default_http_core_proxy()); + m_core_proxy->set_connection_addr("127.0.0.1:11211"); + m_core_proxy->check_connection(); + + bool r = m_core_proxy->call_COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS(req, rsp); + + return 0; +} diff --git a/tests/performance_tests/main.cpp b/tests/performance_tests/main.cpp index e8d7a2ed..5472f68b 100644 --- a/tests/performance_tests/main.cpp +++ b/tests/performance_tests/main.cpp @@ -25,6 +25,7 @@ #include "htlc_hash_tests.h" #include "threads_pool_tests.h" +int test_get_rand_outs(); int main(int argc, char** argv) { @@ -36,7 +37,8 @@ int main(int argc, char** argv) epee::log_space::log_singletone::get_default_log_folder().c_str()); - thread_pool_tests(); + test_get_rand_outs(); + //thread_pool_tests(); // std::string buf1 = tools::get_varint_data(CURRENCY_PUBLIC_ADDRESS_BASE58_PREFIX); // std::string buf2 = tools::get_varint_data(CURRENCY_PUBLIC_INTEG_ADDRESS_BASE58_PREFIX);