forked from lthn/blockchain
implemented online/offline status detecting
This commit is contained in:
parent
0c0689a888
commit
fccf9933af
8 changed files with 38 additions and 83 deletions
|
|
@ -873,6 +873,7 @@ using namespace std;
|
|||
if (!tr.connect(u_c.host, static_cast<int>(u_c.port), timeout))
|
||||
{
|
||||
LOG_PRINT_L2("invoke_request: cannot connect to " << u_c.host << ":" << u_c.port);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
#include "core_rpc_proxy.h"
|
||||
#include "storages/http_abstract_invoke.h"
|
||||
|
||||
#define WALLET_RCP_CONNECTION_TIMEOUT 200000
|
||||
#define WALLET_RCP_CONNECTION_TIMEOUT 10000
|
||||
#define WALLET_RCP_COUNT_ATTEMNTS 3
|
||||
|
||||
namespace tools
|
||||
|
|
@ -63,7 +63,10 @@ namespace tools
|
|||
ret = request();
|
||||
}
|
||||
|
||||
m_plast_daemon_is_disconnected->store(!ret);
|
||||
if (ret)
|
||||
m_last_success_interract_time = time(nullptr);
|
||||
else
|
||||
m_plast_daemon_is_disconnected = true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
@ -90,10 +93,16 @@ namespace tools
|
|||
return epee::net_utils::invoke_http_json_remote_command2(m_daemon_address + url, req, res, m_http_client, WALLET_RCP_CONNECTION_TIMEOUT);
|
||||
});
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
virtual time_t get_last_success_interract_time()
|
||||
{
|
||||
return m_last_success_interract_time;
|
||||
}
|
||||
|
||||
epee::critical_section m_lock;
|
||||
epee::net_utils::http::http_simple_client m_http_client;
|
||||
std::string m_daemon_address;
|
||||
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;
|
||||
|
||||
|
|
|
|||
|
|
@ -138,6 +138,11 @@ namespace tools
|
|||
{
|
||||
return tools::get_transfer_address(adr_str, addr, payment_id, this);
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------------
|
||||
virtual time_t get_last_success_interract_time()
|
||||
{
|
||||
return time(nullptr);
|
||||
}
|
||||
|
||||
private:
|
||||
currency::core_rpc_server& m_rpc;
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ namespace tools
|
|||
|
||||
|
||||
virtual bool check_connection(){ return false; }
|
||||
virtual time_t get_last_success_interract_time() { return 0; }
|
||||
virtual bool get_transfer_address(const std::string& adr_str, currency::account_public_address& addr, std::string& payment_id){ return false; }
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -524,11 +524,13 @@ public:
|
|||
|
||||
struct wallet_sync_status_info
|
||||
{
|
||||
bool is_daemon_connected;
|
||||
uint64_t wallet_state;
|
||||
bool is_in_long_refresh;
|
||||
uint64_t progress;
|
||||
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(is_daemon_connected)
|
||||
KV_SERIALIZE(wallet_state)
|
||||
KV_SERIALIZE(is_in_long_refresh)
|
||||
KV_SERIALIZE(progress)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ if (it == m_wallets.end()) \
|
|||
return API_RETURN_CODE_WALLET_WRONG_ID; \
|
||||
auto& name = it->second.w;
|
||||
|
||||
|
||||
#define DAEMON_IDLE_UPDATE_TIME_MS 1000
|
||||
|
||||
wallets_manager::wallets_manager():m_pview(&m_view_stub),
|
||||
m_stop_singal_sent(false),
|
||||
|
|
@ -232,7 +232,9 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler)
|
|||
if (command_line::has_arg(m_vm, arg_remote_node))
|
||||
{
|
||||
m_remote_node_mode = true;
|
||||
m_rpc_proxy.reset(new tools::default_http_core_proxy());
|
||||
auto proxy_ptr = new tools::default_http_core_proxy();
|
||||
proxy_ptr->set_plast_daemon_is_disconnected(&m_last_daemon_is_disconnected);
|
||||
m_rpc_proxy.reset(proxy_ptr);
|
||||
m_rpc_proxy->set_connection_addr(command_line::get_arg(m_vm, arg_remote_node));
|
||||
}
|
||||
|
||||
|
|
@ -567,7 +569,7 @@ void wallets_manager::loop()
|
|||
while(!m_stop_singal_sent)
|
||||
{
|
||||
update_state_info();
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(DAEMON_IDLE_UPDATE_TIME_MS));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1185,11 +1187,23 @@ std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_par
|
|||
return API_RETURN_CODE_OK;
|
||||
}
|
||||
|
||||
bool wallets_manager::get_is_remote_daemon_connected()
|
||||
{
|
||||
if (!m_remote_node_mode)
|
||||
return true;
|
||||
if (m_last_daemon_is_disconnected)
|
||||
return false;
|
||||
if (time(nullptr) - m_rpc_proxy->get_last_success_interract_time() > DAEMON_IDLE_UPDATE_TIME_MS * 2)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string wallets_manager::get_wallet_status(uint64_t wallet_id)
|
||||
{
|
||||
GET_WALLET_OPT_BY_ID(wallet_id, wo);
|
||||
view::wallet_sync_status_info wsi = AUTO_VAL_INIT(wsi);
|
||||
wsi.is_in_long_refresh = wo.long_refresh_in_progress;
|
||||
wsi.is_daemon_connected = get_is_remote_daemon_connected();
|
||||
wsi.progress = wo.w.unlocked_get().get()->get_sync_progress();
|
||||
wsi.wallet_state = wo.wallet_state;
|
||||
return epee::serialization::store_t_to_json(wsi);
|
||||
|
|
|
|||
|
|
@ -162,6 +162,7 @@ private:
|
|||
void update_wallets_info();
|
||||
void init_wallet_entry(wallet_vs_options& wo, uint64_t id);
|
||||
static void prepare_wallet_status_info(wallet_vs_options& wo, view::wallet_status_info& wsi);
|
||||
bool get_is_remote_daemon_connected();
|
||||
//----- i_backend_wallet_callback ------
|
||||
virtual void on_new_block(size_t wallet_id, uint64_t height, const currency::block& block);
|
||||
virtual void on_transfer2(size_t wallet_id, const tools::wallet_public::wallet_transfer_info& wti, uint64_t balance, uint64_t unlocked_balance, uint64_t total_mined);
|
||||
|
|
|
|||
|
|
@ -1,78 +0,0 @@
|
|||
set -x #echo on
|
||||
cd ..
|
||||
rm -r _builds_android
|
||||
cmake -S. -B_builds_android -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install_android
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to perform command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cmake --build _builds_android --config Debug --target install -- -j 4
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to perform command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -r _builds_android
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to perform command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cmake -S. -B_builds_android -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install_android
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to perform command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cmake --build _builds_android --config Debug --target install -- -j 4
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to perform command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -r _builds_android
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to perform command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
cmake -S. -B_builds_android -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install_android
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to perform command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cmake --build _builds_android --config Debug --target install -- -j 4
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to perform command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -r _builds_android
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to perform command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
cmake -S. -B_builds_android -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_ARCH_ABI=x86_64 -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install_android
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to perform command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cmake --build _builds_android --config Debug --target install -- -j 4
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to perform command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
rm -r _builds_android
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "Failed to perform command"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
Loading…
Add table
Reference in a new issue