diff --git a/src/common/command_line.cpp b/src/common/command_line.cpp index 244fe5e1..6595763f 100644 --- a/src/common/command_line.cpp +++ b/src/common/command_line.cpp @@ -28,6 +28,7 @@ namespace command_line const arg_descriptor arg_show_rpc_autodoc = { "show_rpc_autodoc", "Display rpc auto-generated documentation template" }; const arg_descriptor arg_disable_upnp = { "disable-upnp", "Disable UPnP (enhances local network privacy)", false, true }; + const arg_descriptor arg_disable_ntp = { "disable-ntp", "Disable NTP, could enhance to time synchronization issue but increase network privacy, consider using disable-stop-if-time-out-of-sync with it", false, true }; const arg_descriptor arg_disable_stop_if_time_out_of_sync = { "disable-stop-if-time-out-of-sync", "Do not stop the daemon if serious time synchronization problem is detected", false, true }; const arg_descriptor arg_disable_stop_on_low_free_space = { "disable-stop-on-low-free-space", "Do not stop the daemon if free space at data dir is critically low", false, true }; diff --git a/src/common/command_line.h b/src/common/command_line.h index d7c44207..652d1777 100644 --- a/src/common/command_line.h +++ b/src/common/command_line.h @@ -216,6 +216,7 @@ namespace command_line extern const arg_descriptor arg_show_details; extern const arg_descriptor arg_show_rpc_autodoc; extern const arg_descriptor arg_disable_upnp; + extern const arg_descriptor arg_disable_ntp; extern const arg_descriptor arg_disable_stop_if_time_out_of_sync; extern const arg_descriptor arg_disable_stop_on_low_free_space; extern const arg_descriptor arg_enable_offers_service; diff --git a/src/currency_protocol/currency_protocol_handler.h b/src/currency_protocol/currency_protocol_handler.h index eaf06bda..cae17241 100644 --- a/src/currency_protocol/currency_protocol_handler.h +++ b/src/currency_protocol/currency_protocol_handler.h @@ -117,6 +117,7 @@ namespace currency int64_t m_last_median2local_time_difference; int64_t m_last_ntp2local_time_difference; uint32_t m_debug_ip_address; + bool m_disable_ntp; template bool post_notify(typename t_parametr::request& arg, currency_connection_context& context) diff --git a/src/currency_protocol/currency_protocol_handler.inl b/src/currency_protocol/currency_protocol_handler.inl index 39e42a3c..03b93b67 100644 --- a/src/currency_protocol/currency_protocol_handler.inl +++ b/src/currency_protocol/currency_protocol_handler.inl @@ -23,6 +23,7 @@ namespace currency , m_last_median2local_time_difference(0) , m_last_ntp2local_time_difference(0) , m_debug_ip_address(0) + , m_disable_ntp(false) { if(!m_p2p) m_p2p = &m_p2p_stub; @@ -38,6 +39,8 @@ namespace currency bool t_currency_protocol_handler::init(const boost::program_options::variables_map& vm) { m_relay_que_thread = std::thread([this](){relay_que_worker();}); + if (command_line::has_arg(vm, command_line::arg_disable_ntp)) + m_disable_ntp = command_line::get_arg(vm, command_line::arg_disable_ntp); return true; } //------------------------------------------------------------------------------------------------------------------------ @@ -834,6 +837,12 @@ namespace currency LOG_PRINT_MAGENTA("TIME: network time difference is " << m_last_median2local_time_difference << " (max is " << TIME_SYNC_DELTA_TO_LOCAL_MAX_DIFFERENCE << ")", ((m_last_median2local_time_difference >= 3) ? LOG_LEVEL_2 : LOG_LEVEL_3)); if (std::abs(m_last_median2local_time_difference) > TIME_SYNC_DELTA_TO_LOCAL_MAX_DIFFERENCE) { + // treat as error getting ntp time + if (m_disable_ntp) + { + LOG_PRINT_RED("TIME: network time difference is " << m_last_median2local_time_difference << " (max is " << TIME_SYNC_DELTA_TO_LOCAL_MAX_DIFFERENCE << ") while NTP is disabled", LOG_LEVEL_0); + return false; + } int64_t ntp_time = tools::get_ntp_time(); LOG_PRINT_L2("NTP: received time " << ntp_time << " (" << epee::misc_utils::get_time_str_v2(ntp_time) << "), diff: " << std::showpos << get_core_time() - ntp_time); if (ntp_time == 0) diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 8cbaf4f1..889c1c55 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -164,6 +164,7 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_cmd_sett, command_line::arg_force_predownload); command_line::add_arg(desc_cmd_sett, command_line::arg_validate_predownload); command_line::add_arg(desc_cmd_sett, command_line::arg_predownload_link); + command_line::add_arg(desc_cmd_sett, command_line::arg_disable_ntp); arg_market_disable.default_value = true; diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index be508df3..9171a27f 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -184,6 +184,7 @@ bool wallets_manager::init_command_line(int argc, char* argv[], std::string& fai command_line::add_arg(desc_cmd_sett, command_line::arg_validate_predownload); command_line::add_arg(desc_cmd_sett, command_line::arg_predownload_link); command_line::add_arg(desc_cmd_sett, command_line::arg_deeplink); + command_line::add_arg(desc_cmd_sett, command_line::arg_disable_ntp); #ifndef MOBILE_WALLET_BUILD