forked from lthn/blockchain
improved timeouts for mobile wallet
This commit is contained in:
parent
57d9149626
commit
fe8c34eb17
4 changed files with 57 additions and 14 deletions
|
|
@ -230,7 +230,10 @@ using namespace std;
|
|||
blocked_mode_client m_net_client;
|
||||
std::string m_host_buff;
|
||||
std::string m_port;
|
||||
unsigned int m_timeout;
|
||||
//unsigned int m_timeout;
|
||||
unsigned int m_connection_timeout;
|
||||
unsigned int m_invoke_timeout;
|
||||
unsigned int m_recv_timeout;
|
||||
std::string m_header_cache;
|
||||
http_response_info m_response_info;
|
||||
size_t m_len_in_summary;
|
||||
|
|
@ -259,14 +262,25 @@ using namespace std;
|
|||
{
|
||||
return connect(host, std::to_string(port), timeout);
|
||||
}
|
||||
bool connect(const std::string& host, const std::string& port, unsigned int timeout)
|
||||
|
||||
bool set_timeouts(unsigned int connection_timeout, unsigned int invoke_timeout, unsigned int recv_timeout)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool connect(const std::string& host, std::string port)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_lock);
|
||||
m_host_buff = host;
|
||||
m_port = port;
|
||||
m_timeout = timeout;
|
||||
|
||||
return m_net_client.connect(host, port, timeout, timeout);
|
||||
return m_net_client.connect(host, port, m_connection_timeout, m_recv_timeout);
|
||||
}
|
||||
|
||||
bool connect(const std::string& host, const std::string& port, unsigned int timeout)
|
||||
{
|
||||
m_connection_timeout = m_invoke_timeout = m_recv_timeout = timeout;
|
||||
return connect(host, port);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
bool disconnect()
|
||||
|
|
@ -303,7 +317,7 @@ using namespace std;
|
|||
if(!is_connected())
|
||||
{
|
||||
LOG_PRINT("Reconnecting...", LOG_LEVEL_3);
|
||||
if(!connect(m_host_buff, m_port, m_timeout))
|
||||
if(!connect(m_host_buff, m_port))
|
||||
{
|
||||
LOG_PRINT("Failed to connect to " << m_host_buff << ":" << m_port, LOG_LEVEL_3);
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@ using namespace epee;
|
|||
#include "currency_core/currency_format_utils.h"
|
||||
#include "currency_core/alias_helper.h"
|
||||
|
||||
#undef LOG_DEFAULT_CHANNEL
|
||||
#define LOG_DEFAULT_CHANNEL "rpc_proxy"
|
||||
ENABLE_CHANNEL_BY_DEFAULT("rpc_proxy")
|
||||
|
||||
|
||||
namespace tools
|
||||
{
|
||||
bool default_http_core_proxy::set_connection_addr(const std::string& url)
|
||||
|
|
@ -131,7 +136,7 @@ namespace tools
|
|||
epee::net_utils::parse_url(m_daemon_address, u);
|
||||
if (!u.port)
|
||||
u.port = 8081;
|
||||
return m_http_client.connect(u.host, std::to_string(u.port), WALLET_RCP_CONNECTION_TIMEOUT);
|
||||
return m_http_client.connect(u.host, std::to_string(u.port), m_connection_timeout);
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
bool default_http_core_proxy::call_COMMAND_RPC_GET_ALL_ALIASES(currency::COMMAND_RPC_GET_ALL_ALIASES::response& res)
|
||||
|
|
@ -166,7 +171,17 @@ namespace tools
|
|||
m_plast_daemon_is_disconnected = plast_daemon_is_disconnected ? plast_daemon_is_disconnected : &m_last_daemon_is_disconnected_stub;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
default_http_core_proxy::default_http_core_proxy():m_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)
|
||||
{
|
||||
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),
|
||||
m_last_success_interract_time(0),
|
||||
m_connection_timeout(WALLET_RCP_CONNECTION_TIMEOUT),
|
||||
m_attempts_count(WALLET_RCP_COUNT_ATTEMNTS)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,11 @@
|
|||
#include "core_rpc_proxy.h"
|
||||
#include "storages/http_abstract_invoke.h"
|
||||
|
||||
#define WALLET_RCP_CONNECTION_TIMEOUT 10000
|
||||
#define WALLET_RCP_CONNECTION_TIMEOUT 3000
|
||||
#define WALLET_RCP_COUNT_ATTEMNTS 3
|
||||
|
||||
|
||||
|
||||
namespace tools
|
||||
{
|
||||
class default_http_core_proxy final : public i_core_proxy
|
||||
|
|
@ -22,6 +24,7 @@ namespace tools
|
|||
|
||||
|
||||
bool set_connection_addr(const std::string& url) override;
|
||||
bool 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;
|
||||
|
|
@ -58,7 +61,7 @@ namespace tools
|
|||
CRITICAL_REGION_LOCAL(m_lock);
|
||||
|
||||
bool ret = false;
|
||||
for(size_t i = WALLET_RCP_COUNT_ATTEMNTS; i && !ret; --i)
|
||||
for(size_t i = m_attempts_count; i && !ret; --i)
|
||||
{
|
||||
ret = request();
|
||||
}
|
||||
|
|
@ -82,7 +85,7 @@ namespace tools
|
|||
inline bool invoke_http_bin_remote_command2_update_is_disconnect(const std::string& url, const t_request& req, t_response& res)
|
||||
{
|
||||
return call_request([&](){
|
||||
return epee::net_utils::invoke_http_bin_remote_command2(m_daemon_address + url, req, res, m_http_client, WALLET_RCP_CONNECTION_TIMEOUT);
|
||||
return epee::net_utils::invoke_http_bin_remote_command2(m_daemon_address + url, req, res, m_http_client, m_connection_timeout);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -90,7 +93,14 @@ namespace tools
|
|||
inline bool invoke_http_json_remote_command2_update_is_disconnect(const std::string& url, const t_request& req, t_response& res)
|
||||
{
|
||||
return call_request([&](){
|
||||
return epee::net_utils::invoke_http_json_remote_command2(m_daemon_address + url, req, res, m_http_client, WALLET_RCP_CONNECTION_TIMEOUT);
|
||||
#ifdef MOBILE_WALLET_BUILD
|
||||
LOG_PRINT_L0("[INVOKE_JSON] --->" << typeid(t_request).name() )
|
||||
#endif
|
||||
bool r = epee::net_utils::invoke_http_json_remote_command2(m_daemon_address + url, req, res, m_http_client, m_connection_timeout);
|
||||
#ifdef MOBILE_WALLET_BUILD
|
||||
LOG_PRINT_L0("[INVOKE_JSON] <---" << typeid(t_request).name())
|
||||
#endif
|
||||
return r;
|
||||
});
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
|
|
@ -105,6 +115,8 @@ namespace tools
|
|||
std::atomic<time_t> m_last_success_interract_time;
|
||||
std::atomic<bool> *m_plast_daemon_is_disconnected;
|
||||
std::atomic<bool> m_last_daemon_is_disconnected_stub;
|
||||
unsigned int m_connection_timeout;
|
||||
size_t m_attempts_count;
|
||||
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,7 +29,9 @@ if (it == m_wallets.end()) \
|
|||
return API_RETURN_CODE_WALLET_WRONG_ID; \
|
||||
auto& name = it->second.w;
|
||||
|
||||
#define DAEMON_IDLE_UPDATE_TIME_MS 1000
|
||||
#define DAEMON_IDLE_UPDATE_TIME_MS 2000
|
||||
#define HTTP_PROXY_TIMEOUT 2000
|
||||
#define HTTP_PROXY_ATTEMPTS_COUNT 1
|
||||
|
||||
wallets_manager::wallets_manager():m_pview(&m_view_stub),
|
||||
m_stop_singal_sent(false),
|
||||
|
|
@ -234,6 +236,7 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler)
|
|||
m_remote_node_mode = true;
|
||||
auto proxy_ptr = new tools::default_http_core_proxy();
|
||||
proxy_ptr->set_plast_daemon_is_disconnected(&m_last_daemon_is_disconnected);
|
||||
proxy_ptr->set_connectivity(HTTP_PROXY_TIMEOUT, HTTP_PROXY_ATTEMPTS_COUNT);
|
||||
m_rpc_proxy.reset(proxy_ptr);
|
||||
m_rpc_proxy->set_connection_addr(command_line::get_arg(m_vm, arg_remote_node));
|
||||
}
|
||||
|
|
@ -505,10 +508,9 @@ bool wallets_manager::update_state_info()
|
|||
dsi.is_disconnected = true;
|
||||
m_last_daemon_network_state = dsi.daemon_network_state;
|
||||
m_pview->update_daemon_status(dsi);
|
||||
LOG_ERROR("Failed to call get_info");
|
||||
LOG_PRINT_RED_L0("Failed to call get_info");
|
||||
return false;
|
||||
}
|
||||
|
||||
m_is_pos_allowed = inf.pos_allowed;
|
||||
dsi.alias_count = inf.alias_count;
|
||||
dsi.pow_difficulty = std::to_string(inf.pow_difficulty);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue