forked from lthn/blockchain
Implemented debug mode for remote node
This commit is contained in:
parent
fc28894aee
commit
2382e9717b
5 changed files with 55 additions and 2 deletions
|
|
@ -70,6 +70,8 @@ namespace currency
|
|||
int64_t get_net_time_delta_median();
|
||||
bool add_time_delta_and_check_time_sync(int64_t delta);
|
||||
bool get_last_time_sync_difference(int64_t& last_median2local_time_difference, int64_t& last_ntp2local_time_difference); // returns true if differences in allowed bounds
|
||||
//-----------------------------------------------------------------------------------
|
||||
void set_to_debug_mode(uint32_t ip);
|
||||
|
||||
private:
|
||||
//----------------- commands handlers ----------------------------------------------
|
||||
|
|
@ -114,6 +116,7 @@ namespace currency
|
|||
std::mutex m_time_deltas_lock;
|
||||
int64_t m_last_median2local_time_difference;
|
||||
int64_t m_last_ntp2local_time_difference;
|
||||
uint32_t m_debug_ip_address;
|
||||
|
||||
template<class t_parametr>
|
||||
bool post_notify(typename t_parametr::request& arg, currency_connection_context& context)
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ namespace currency
|
|||
, m_want_stop(false)
|
||||
, m_last_median2local_time_difference(0)
|
||||
, m_last_ntp2local_time_difference(0)
|
||||
, m_debug_ip_address(0)
|
||||
{
|
||||
if(!m_p2p)
|
||||
m_p2p = &m_p2p_stub;
|
||||
|
|
@ -241,6 +242,10 @@ namespace currency
|
|||
template<class t_core>
|
||||
int t_currency_protocol_handler<t_core>::handle_notify_new_block(int command, NOTIFY_NEW_BLOCK::request& arg, currency_connection_context& context)
|
||||
{
|
||||
//do not process requests if it comes from node wich is debugged
|
||||
if (m_debug_ip_address != 0 && context.m_remote_ip == m_debug_ip_address)
|
||||
return 1;
|
||||
|
||||
if(context.m_state != currency_connection_context::state_normal)
|
||||
return 1;
|
||||
|
||||
|
|
@ -363,6 +368,10 @@ namespace currency
|
|||
template<class t_core>
|
||||
int t_currency_protocol_handler<t_core>::handle_notify_new_transactions(int command, NOTIFY_NEW_TRANSACTIONS::request& arg, currency_connection_context& context)
|
||||
{
|
||||
//do not process requests if it comes from node wich is debugged
|
||||
if (m_debug_ip_address != 0 && context.m_remote_ip == m_debug_ip_address)
|
||||
return 1;
|
||||
|
||||
if(context.m_state != currency_connection_context::state_normal)
|
||||
return 1;
|
||||
uint64_t inital_tx_count = arg.txs.size();
|
||||
|
|
@ -400,6 +409,10 @@ namespace currency
|
|||
template<class t_core>
|
||||
int t_currency_protocol_handler<t_core>::handle_request_get_objects(int command, NOTIFY_REQUEST_GET_OBJECTS::request& arg, currency_connection_context& context)
|
||||
{
|
||||
//do not process requests if it comes from node wich is debugged
|
||||
if (m_debug_ip_address != 0 && context.m_remote_ip == m_debug_ip_address)
|
||||
return 1;
|
||||
|
||||
LOG_PRINT_L2("[HANDLE]NOTIFY_REQUEST_GET_OBJECTS: arg.blocks.size() = " << arg.blocks.size() << ", arg.txs.size()="<< arg.txs.size());
|
||||
LOG_PRINT_L3("[HANDLE]NOTIFY_REQUEST_GET_OBJECTS: " << ENDL << currency::print_kv_structure(arg));
|
||||
|
||||
|
|
@ -445,6 +458,10 @@ namespace currency
|
|||
template<class t_core>
|
||||
int t_currency_protocol_handler<t_core>::handle_response_get_objects(int command, NOTIFY_RESPONSE_GET_OBJECTS::request& arg, currency_connection_context& context)
|
||||
{
|
||||
//do not process requests if it comes from node wich is debugged
|
||||
if (m_debug_ip_address != 0 && context.m_remote_ip == m_debug_ip_address)
|
||||
return 1;
|
||||
|
||||
LOG_PRINT_L2("[HANDLE]NOTIFY_RESPONSE_GET_OBJECTS: arg.blocks.size()=" << arg.blocks.size() << ", arg.missed_ids.size()=" << arg.missed_ids.size() << ", arg.txs.size()=" << arg.txs.size());
|
||||
LOG_PRINT_L3("[HANDLE]NOTIFY_RESPONSE_GET_OBJECTS: " << ENDL << currency::print_kv_structure(arg));
|
||||
if(context.m_last_response_height > arg.current_blockchain_height)
|
||||
|
|
@ -627,6 +644,10 @@ namespace currency
|
|||
template<class t_core>
|
||||
int t_currency_protocol_handler<t_core>::handle_request_chain(int command, NOTIFY_REQUEST_CHAIN::request& arg, currency_connection_context& context)
|
||||
{
|
||||
//do not process requests if it comes from node wich is debugged
|
||||
if (m_debug_ip_address != 0 && context.m_remote_ip == m_debug_ip_address)
|
||||
return 1;
|
||||
|
||||
LOG_PRINT_L2("[HANDLE]NOTIFY_REQUEST_CHAIN: block_ids.size()=" << arg.block_ids.size());
|
||||
LOG_PRINT_L3("[HANDLE]NOTIFY_REQUEST_CHAIN: " << print_kv_structure(arg));
|
||||
NOTIFY_RESPONSE_CHAIN_ENTRY::request r;
|
||||
|
|
@ -851,10 +872,19 @@ namespace currency
|
|||
|
||||
return !(std::abs(m_last_median2local_time_difference) > TIME_SYNC_DELTA_TO_LOCAL_MAX_DIFFERENCE && std::abs(m_last_ntp2local_time_difference) > TIME_SYNC_NTP_TO_LOCAL_MAX_DIFFERENCE);
|
||||
}
|
||||
template<class t_core>
|
||||
void t_currency_protocol_handler<t_core>::set_to_debug_mode(uint32_t ip)
|
||||
{
|
||||
m_debug_ip_address = ip;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------
|
||||
template<class t_core>
|
||||
int t_currency_protocol_handler<t_core>::handle_response_chain_entry(int command, NOTIFY_RESPONSE_CHAIN_ENTRY::request& arg, currency_connection_context& context)
|
||||
{
|
||||
//do not process requests if it comes from node wich is debugged
|
||||
if (m_debug_ip_address != 0 && context.m_remote_ip == m_debug_ip_address)
|
||||
return 1;
|
||||
|
||||
LOG_PRINT_L2("[HANDLE]NOTIFY_RESPONSE_CHAIN_ENTRY: m_block_ids.size()=" << arg.m_block_ids.size()
|
||||
<< ", m_start_height=" << arg.start_height << ", m_total_height=" << arg.total_height);
|
||||
LOG_PRINT_L3("[HANDLE]NOTIFY_RESPONSE_CHAIN_ENTRY: " << ENDL << currency::print_kv_structure(arg));
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
#include "warnings.h"
|
||||
#include "currency_core/bc_offers_service.h"
|
||||
#include "serialization/binary_utils.h"
|
||||
#include "simplewallet/password_container.h"
|
||||
|
||||
PUSH_VS_WARNINGS
|
||||
DISABLE_VS_WARNINGS(4100)
|
||||
|
|
@ -69,7 +70,7 @@ public:
|
|||
m_cmd_binder.set_handler("print_tx_from_hex_blob", boost::bind(&daemon_commands_handler::print_tx_from_hex_blob, this, _1), "Unserialize transaction from hex binary data to json-like representation");
|
||||
m_cmd_binder.set_handler("print_tx_outputs_usage", boost::bind(&daemon_commands_handler::print_tx_outputs_usage, this, _1), "Analyse if tx outputs for involved in subsequent transactions");
|
||||
m_cmd_binder.set_handler("print_difficulties_of_last_n_blocks", boost::bind(&daemon_commands_handler::print_difficulties_of_last_n_blocks, this, _1), "Print difficulties of last n blocks");
|
||||
|
||||
m_cmd_binder.set_handler("debug_remore_node_mode", boost::bind(&daemon_commands_handler::debug_remore_node_mode, this, _1), "<ip-address> - If node got connected put node into 'debug mode' i.e. no sync process of other communication except ping responses, maintenance secrete key will be requested");
|
||||
#ifdef _DEBUG
|
||||
m_cmd_binder.set_handler("debug_set_time_adj", boost::bind(&daemon_commands_handler::debug_set_time_adj, this, _1), "DEBUG: set core time adjustment");
|
||||
#endif
|
||||
|
|
@ -734,6 +735,24 @@ private:
|
|||
return true;
|
||||
}
|
||||
//--------------------------------------------------------------------------------
|
||||
bool debug_remore_node_mode(const std::vector<std::string>& args)
|
||||
{
|
||||
if (args.empty())
|
||||
{
|
||||
std::cout << "expected: ip address" << std::endl;
|
||||
return true;
|
||||
}
|
||||
uint32_t ip = AUTO_VAL_INIT(ip);
|
||||
if (!string_tools::get_ip_int32_from_string(ip, args.front()))
|
||||
{
|
||||
std::cout << "expected: ip address" << std::endl;
|
||||
return true;
|
||||
}
|
||||
m_srv.get_payload_object().set_to_debug_mode(ip);
|
||||
|
||||
return true;
|
||||
}
|
||||
//--------------------------------------------------------------------------------
|
||||
bool print_pool(const std::vector<std::string>& args)
|
||||
{
|
||||
LOG_PRINT_L0("Pool state: " << ENDL << m_srv.get_payload_object().get_core().print_pool(false));
|
||||
|
|
|
|||
|
|
@ -82,7 +82,6 @@ namespace nodetool
|
|||
m_use_only_priority_peers(false),
|
||||
m_peer_livetime{},
|
||||
m_debug_requests_enabled(false)
|
||||
|
||||
{}
|
||||
|
||||
static void init_options(boost::program_options::options_description& desc);
|
||||
|
|
@ -248,6 +247,7 @@ namespace nodetool
|
|||
bool m_debug_requests_enabled;
|
||||
uint64_t m_startup_time;
|
||||
|
||||
|
||||
//critical_section m_connections_lock;
|
||||
//connections_indexed_container m_connections;
|
||||
|
||||
|
|
|
|||
|
|
@ -1442,6 +1442,7 @@ namespace nodetool
|
|||
std::string s = ss.str();
|
||||
return s;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------------
|
||||
template<class t_payload_net_handler>
|
||||
void node_server<t_payload_net_handler>::on_connection_new(p2p_connection_context& context)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue