1
0
Fork 0
forked from lthn/blockchain

Added timeout to wallet rpc transport

This commit is contained in:
cryptozoidberg 2022-07-12 23:05:36 +02:00
parent 5b80a22157
commit 788c5be092
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
9 changed files with 75 additions and 32 deletions

View file

@ -57,6 +57,7 @@ namespace
const command_line::arg_descriptor<std::string> arg_scan_for_wallet ( "scan-for-wallet", "");
const command_line::arg_descriptor<std::string> arg_addr_to_compare ( "addr-to-compare", "");
const command_line::arg_descriptor<bool> arg_disable_tor_relay ( "disable-tor-relay", "Disable TOR relay", false);
const command_line::arg_descriptor<unsigned int> arg_set_timeout("set-timeout", "Set timeout for the wallet");
const command_line::arg_descriptor< std::vector<std::string> > arg_command ("command", "");
@ -261,6 +262,29 @@ bool simple_wallet::set_log(const std::vector<std::string> &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<std::string>());
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<std::string>());
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);

View file

@ -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),

View file

@ -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<bool> *plast_daemon_is_disconnected);
void set_plast_daemon_is_disconnected(std::atomic<bool> *plast_daemon_is_disconnected);
default_http_core_proxy();
private:

View file

@ -63,6 +63,7 @@ namespace tools
std::shared_ptr<const proxy_diagnostic_info> get_proxy_diagnostic_info() const { return m_pdiganostic_info; }
std::shared_ptr<proxy_diagnostic_info> 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<proxy_diagnostic_info> m_pdiganostic_info;
};

View file

@ -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)
{

View file

@ -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

View file

@ -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})

View file

@ -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<tools::i_core_proxy> 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;
}

View file

@ -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<uint64_t>(CURRENCY_PUBLIC_ADDRESS_BASE58_PREFIX);
// std::string buf2 = tools::get_varint_data<uint64_t>(CURRENCY_PUBLIC_INTEG_ADDRESS_BASE58_PREFIX);