1
0
Fork 0
forked from lthn/blockchain

fixed critical issue with SSL support(failed re-connections)

This commit is contained in:
cryptozoidberg 2025-03-14 00:49:14 +04:00
parent a54c00e823
commit dfe5238f77
No known key found for this signature in database
GPG key ID: 2E10CC61CAC8F36D
4 changed files with 69 additions and 31 deletions

View file

@ -116,7 +116,9 @@ namespace epee
void on_after_connect()
{
LOG_PRINT_L2("SSL Handshake....");
m_socket.handshake(boost::asio::ssl::stream_base::client);
LOG_PRINT_L2("SSL Handshake OK");
}
private:
@ -149,11 +151,52 @@ namespace epee
{
}
void reset()
{
}
private:
boost::asio::ip::tcp::socket m_socket;
};
template<bool is_ssl>
struct socket_backend_resetable
{
socket_backend_resetable(boost::asio::io_service& _io_service) : mr_io_service(_io_service), m_pbackend(std::make_shared<socket_backend<is_ssl>>(_io_service))
{}
boost::asio::ip::tcp::socket& get_socket()
{
return m_pbackend->get_socket();
}
void set_domain(const std::string& domain_name)
{
return m_pbackend->set_domain(domain_name);
}
auto& get_stream()
{
return m_pbackend->get_stream();
}
void on_after_connect()
{
return m_pbackend->on_after_connect();
}
void reset()
{
m_pbackend = std::make_shared<socket_backend<is_ssl>>(mr_io_service);
}
private:
boost::asio::io_service& mr_io_service;
std::shared_ptr<socket_backend<is_ssl>> m_pbackend;
};
template<bool is_ssl>
@ -227,6 +270,7 @@ namespace epee
inline
bool connect(const std::string& addr, const std::string& port, unsigned int connect_timeout, unsigned int reciev_timeout, const std::string& bind_ip = "0.0.0.0")
{
LOG_PRINT_L1("Connecting to " << addr << ":" << port << ", cn_timeout: " << connect_timeout << ", rv_timeout: " << reciev_timeout);
m_connect_timeout = connect_timeout;
m_reciev_timeout = reciev_timeout;
m_connected = false;
@ -238,7 +282,7 @@ namespace epee
m_sct_back.get_socket().close();
// Get a list of endpoints corresponding to the server name.
m_sct_back.reset();
//////////////////////////////////////////////////////////////////////////
boost::asio::ip::tcp::resolver resolver(m_io_service);
@ -281,13 +325,14 @@ namespace epee
if (!ec && m_sct_back.get_socket().is_open())
{
m_sct_back.on_after_connect();
m_connected = true;
m_connected = true;
m_deadline.expires_at(boost::posix_time::pos_infin);
LOG_PRINT_L1("Connected OK: " << addr << ":" << port);
return true;
}
else
{
LOG_PRINT("Some problems at connect, message: " << ec.message(), LOG_LEVEL_3);
LOG_PRINT("Error on connect to " << addr << ":" << port << ", message: " << ec.message(), LOG_LEVEL_3);
return false;
}
@ -652,7 +697,7 @@ namespace epee
// The deadline has passed. The socket is closed so that any outstanding
// asynchronous operations are cancelled. This allows the blocked
// connect(), read_line() or write_line() functions to return.
LOG_PRINT_L3("Timed out socket");
LOG_PRINT_L2("Timed out socket");
m_connected = false;
m_sct_back.get_socket().close();
@ -669,7 +714,7 @@ namespace epee
protected:
boost::asio::io_service m_io_service;
socket_backend<is_ssl> m_sct_back;
socket_backend_resetable<is_ssl> m_sct_back;//socket_backend<is_ssl> m_sct_back;
int m_connect_timeout;
int m_reciev_timeout;
bool m_initialized;

View file

@ -87,13 +87,9 @@ namespace tools
inline bool invoke_http_json_rpc_update_is_disconnect(const std::string& method_name, const t_request& req, t_response& res)
{
return call_request([&](){
#ifdef MOBILE_WALLET_BUILD
LOG_PRINT_L0("[INVOKE_JSON_METHOD] ---> " << method_name)
#endif
LOG_PRINT_L2("[INVOKE_JSON_METHOD] ---> " << method_name)
bool r = epee::net_utils::invoke_http_json_rpc("/json_rpc", method_name, req, res, m_http_client);
#ifdef MOBILE_WALLET_BUILD
LOG_PRINT_L0("[INVOKE_JSON_METHOD] <---" << method_name)
#endif
LOG_PRINT_L2("[INVOKE_JSON_METHOD] <---" << method_name)
return r;
});
}
@ -102,13 +98,9 @@ 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([&](){
#ifdef MOBILE_WALLET_BUILD
LOG_PRINT_L0("[INVOKE_BIN] --->" << typeid(t_request).name())
#endif
LOG_PRINT_L2("[INVOKE_BIN] --->" << typeid(t_request).name())
bool r = epee::net_utils::invoke_http_bin_remote_command2(m_daemon_address + url, req, res, m_http_client, m_connection_timeout);
#ifdef MOBILE_WALLET_BUILD
LOG_PRINT_L0("[INVOKE_BIN] <---" << typeid(t_request).name())
#endif
LOG_PRINT_L2("[INVOKE_BIN] <---" << typeid(t_request).name())
return r;
});
}
@ -117,13 +109,9 @@ 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([&](){
#ifdef MOBILE_WALLET_BUILD
LOG_PRINT_L0("[INVOKE_JSON_URL] --->" << typeid(t_request).name() )
#endif
LOG_PRINT_L2("[INVOKE_JSON_URL] --->" << typeid(t_request).name() )
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_URL] <---" << typeid(t_request).name())
#endif
LOG_PRINT_L2("[INVOKE_JSON_URL] <---" << typeid(t_request).name())
return r;
});
}

View file

@ -603,8 +603,7 @@ void wallet2::process_new_transaction(const currency::transaction& tx, uint64_t
{
if (pglobal_indexes->size())
{
//@#@
WLT_LOG_L2("add_to_last_zc_global_indexs: h: " << height << ", b: " << currency::get_block_hash(b) << " , tx: " << currency::get_transaction_hash(tx) << ", last_zc_output_index: " << pglobal_indexes->back());
WLT_LOG_L3("add_to_last_zc_global_indexs: h: " << height << ", b: " << currency::get_block_hash(b) << " , tx: " << currency::get_transaction_hash(tx) << ", last_zc_output_index: " << pglobal_indexes->back());
add_to_last_zc_global_indexs(ptc.height, pglobal_indexes->back());
}
}

View file

@ -33,26 +33,30 @@ DISABLE_VS_WARNINGS(4244)
#include "jwt-cpp/jwt.h"
POP_VS_WARNINGS
void test_plain_wallet()
{
//std::string res = plain_wallet::init("195.201.107.230", "33340", "C:\\Users\\roky\\home\\", 0);
//std::string res = plain_wallet::init("", "", "C:\\Users\\roky\\home\\", 0);
std::string res = plain_wallet::init("http://zano.api.puffin.systems", "80", "C:\\Users\\roky\\home\\", 0);
std::string res = plain_wallet::init("https://node.zano.org", "443", "C:\\Users\\roky\\home\\", LOG_LEVEL_2);
//std::string res = plain_wallet::init("127.0.0.1", "12111", "C:\\Users\\roky\\home22\\", 0);
plain_wallet::configure_object conf = AUTO_VAL_INIT(conf);
//plain_wallet::configure_response conf_resp = AUTO_VAL_INIT(conf_resp);
conf.postponed_run_wallet = true;
std::string r = plain_wallet::sync_call("configure", 0, epee::serialization::store_t_to_json(conf));
std::string seed;
if (!epee::file_io_utils::load_file_to_string("C:\\Users\\roky\\home\\temp\\wallets\\seed.txt", seed))
return;
std::string res___ = plain_wallet::get_wallet_files();
uint64_t instance_id = 0;
res = plain_wallet::open("test_restored_2.zan", "111");
//res = plain_wallet::restore("",
// "test_restored_2.zan", "111", "");
res = plain_wallet::open("test_restored_3.zan", "111");
//res = plain_wallet::restore(seed,
// "test_restored_3.zan", "111", "test");
epee::misc_utils::sleep_no_w(2000);
@ -67,7 +71,7 @@ void test_plain_wallet()
res = plain_wallet::sync_call("get_wallet_status", instance_id, "");
view::wallet_sync_status_info wsi = AUTO_VAL_INIT(wsi);
epee::serialization::load_t_from_json(wsi, res);
LOG_PRINT_L0("Progress: " << wsi.progress);
LOG_PRINT_L0("Progress: " << wsi.progress << " state: " << wsi.wallet_state << ", height: " << wsi.current_wallet_height << " of " << wsi.current_daemon_height);
if (wsi.wallet_state == 2)
break;
}
@ -75,6 +79,8 @@ void test_plain_wallet()
std::string invoke_body = "{\"method\":\"store\",\"params\":{}}";
std::string res1 = plain_wallet::sync_call("invoke", instance_id, invoke_body);
LOG_PRINT_L0("Store: " << res1);
return;
{
invoke_body = "{\"method\":\"getbalance\",\"params\":{}}";
std::string res3 = plain_wallet::sync_call("invoke", instance_id, invoke_body);