From 7696e84952b2475e8a1ceeede76614d6626559aa Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 30 Nov 2017 15:35:52 +0000 Subject: [PATCH 1/2] core: make --offline also disable DNS lookups --- src/cryptonote_core/blockchain.cpp | 11 ++++++----- src/cryptonote_core/blockchain.h | 7 +++++-- src/cryptonote_core/cryptonote_core.cpp | 16 +++++++++++++++- src/cryptonote_core/cryptonote_core.h | 9 +++++++++ src/p2p/net_node.inl | 6 ++---- 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp index 3d586a704..332d4324e 100644 --- a/src/cryptonote_core/blockchain.cpp +++ b/src/cryptonote_core/blockchain.cpp @@ -304,7 +304,7 @@ uint64_t Blockchain::get_current_blockchain_height() const //------------------------------------------------------------------ //FIXME: possibly move this into the constructor, to avoid accidentally // dereferencing a null BlockchainDB pointer -bool Blockchain::init(BlockchainDB* db, const bool testnet, const cryptonote::test_options *test_options) +bool Blockchain::init(BlockchainDB* db, const bool testnet, bool offline, const cryptonote::test_options *test_options) { LOG_PRINT_L3("Blockchain::" << __func__); CRITICAL_REGION_LOCAL(m_tx_pool); @@ -326,6 +326,7 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet, const cryptonote::te m_db = db; m_testnet = testnet; + m_offline = offline; if (m_hardfork == nullptr) { if (fakechain) @@ -413,11 +414,11 @@ bool Blockchain::init(BlockchainDB* db, const bool testnet, const cryptonote::te return true; } //------------------------------------------------------------------ -bool Blockchain::init(BlockchainDB* db, HardFork*& hf, const bool testnet) +bool Blockchain::init(BlockchainDB* db, HardFork*& hf, const bool testnet, bool offline) { if (hf != nullptr) m_hardfork = hf; - bool res = init(db, testnet, NULL); + bool res = init(db, testnet, offline, NULL); if (hf == nullptr) hf = m_hardfork; return res; @@ -3624,14 +3625,14 @@ bool Blockchain::update_checkpoints(const std::string& file_path, bool check_dns // if we're checking both dns and json, load checkpoints from dns. // if we're not hard-enforcing dns checkpoints, handle accordingly - if (m_enforce_dns_checkpoints && check_dns) + if (m_enforce_dns_checkpoints && check_dns && !m_offline) { if (!m_checkpoints.load_checkpoints_from_dns()) { return false; } } - else if (check_dns) + else if (check_dns && !m_offline) { checkpoints dns_points; dns_points.load_checkpoints_from_dns(); diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h index e0936da8f..b76d0555f 100644 --- a/src/cryptonote_core/blockchain.h +++ b/src/cryptonote_core/blockchain.h @@ -112,11 +112,12 @@ namespace cryptonote * * @param db a pointer to the backing store to use for the blockchain * @param testnet true if on testnet, else false + * @param offline true if running offline, else false * @param test_options test parameters * * @return true on success, false if any initialization steps fail */ - bool init(BlockchainDB* db, const bool testnet = false, const cryptonote::test_options *test_options = NULL); + bool init(BlockchainDB* db, const bool testnet = false, bool offline = false, const cryptonote::test_options *test_options = NULL); /** * @brief Initialize the Blockchain state @@ -124,10 +125,11 @@ namespace cryptonote * @param db a pointer to the backing store to use for the blockchain * @param hf a structure containing hardfork information * @param testnet true if on testnet, else false + * @param offline true if running offline, else false * * @return true on success, false if any initialization steps fail */ - bool init(BlockchainDB* db, HardFork*& hf, const bool testnet = false); + bool init(BlockchainDB* db, HardFork*& hf, const bool testnet = false, bool offline = false); /** * @brief Uninitializes the blockchain state @@ -1027,6 +1029,7 @@ namespace cryptonote HardFork *m_hardfork; bool m_testnet; + bool m_offline; std::atomic m_cancel; diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 5c181208f..a6d99424f 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -75,6 +75,10 @@ namespace cryptonote , "Run on testnet. The wallet must be launched with --testnet flag." , false }; + const command_line::arg_descriptor arg_offline = { + "offline" + , "Do not listen for peers, nor connect to any" + }; static const command_line::arg_descriptor arg_test_drop_download = { "test-drop-download" @@ -227,6 +231,7 @@ namespace cryptonote command_line::add_arg(desc, arg_check_updates); command_line::add_arg(desc, arg_fluffy_blocks); command_line::add_arg(desc, arg_test_dbg_lock_sleep); + command_line::add_arg(desc, arg_offline); // we now also need some of net_node's options (p2p bind arg, for separate data dir) command_line::add_arg(desc, nodetool::arg_testnet_p2p_bind_port, false); @@ -264,6 +269,7 @@ namespace cryptonote set_enforce_dns_checkpoints(command_line::get_arg(vm, arg_dns_checkpoints)); test_drop_download_height(command_line::get_arg(vm, arg_test_drop_download_height)); m_fluffy_blocks_enabled = m_testnet || get_arg(vm, arg_fluffy_blocks); + m_offline = get_arg(vm, arg_offline); if (command_line::get_arg(vm, arg_test_drop_download) == true) test_drop_download(); @@ -1322,8 +1328,13 @@ namespace cryptonote { if(!m_starter_message_showed) { + std::string main_message; + if (m_offline) + main_message = "The daemon is running offline and will not attempt to sync to the Monero network."; + else + main_message = "The daemon will start synchronizing with the network. This may take a long time to complete."; MGINFO_YELLOW(ENDL << "**********************************************************************" << ENDL - << "The daemon will start synchronizing with the network. This may take a long time to complete." << ENDL + << main_message << ENDL << ENDL << "You can set the level of process detailization* through \"set_log \" command*," << ENDL << "where is between 0 (no details) and 4 (very verbose), or custom category based levels (eg, *:WARNING)" << ENDL @@ -1385,6 +1396,9 @@ namespace cryptonote static const char subdir[] = "source"; // because it can never be simple #endif + if (m_offline) + return true; + if (check_updates_level == UPDATES_DISABLED) return true; diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index 905e67f6d..6cb4fc938 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -62,6 +62,7 @@ namespace cryptonote extern const command_line::arg_descriptor arg_data_dir; extern const command_line::arg_descriptor arg_testnet_data_dir; extern const command_line::arg_descriptor arg_testnet_on; + extern const command_line::arg_descriptor arg_offline; /************************************************************************/ /* */ @@ -773,6 +774,13 @@ namespace cryptonote */ uint64_t get_free_space() const; + /** + * @brief get whether the core is running offline + * + * @return whether the core is running offline + */ + bool offline() const { return m_offline; } + private: /** @@ -1000,6 +1008,7 @@ namespace cryptonote boost::mutex m_update_mutex; bool m_fluffy_blocks_enabled; + bool m_offline; }; } diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index f64b29c1f..5b55a4180 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -95,7 +95,6 @@ namespace nodetool const command_line::arg_descriptor arg_p2p_hide_my_port = {"hide-my-port", "Do not announce yourself as peerlist candidate", false, true}; const command_line::arg_descriptor arg_no_igd = {"no-igd", "Disable UPnP port mapping"}; - const command_line::arg_descriptor arg_offline = {"offline", "Do not listen for peers, nor connect to any"}; const command_line::arg_descriptor arg_out_peers = {"out-peers", "set max number of out peers", -1}; const command_line::arg_descriptor arg_tos_flag = {"tos-flag", "set TOS flag", -1}; @@ -120,7 +119,6 @@ namespace nodetool command_line::add_arg(desc, arg_p2p_seed_node); command_line::add_arg(desc, arg_p2p_hide_my_port); command_line::add_arg(desc, arg_no_igd); - command_line::add_arg(desc, arg_offline); command_line::add_arg(desc, arg_out_peers); command_line::add_arg(desc, arg_tos_flag); command_line::add_arg(desc, arg_limit_rate_up); @@ -306,7 +304,7 @@ namespace nodetool m_external_port = command_line::get_arg(vm, arg_p2p_external_port); m_allow_local_ip = command_line::get_arg(vm, arg_p2p_allow_local_ip); m_no_igd = command_line::get_arg(vm, arg_no_igd); - m_offline = command_line::get_arg(vm, arg_offline); + m_offline = command_line::get_arg(vm, cryptonote::arg_offline); if (command_line::has_arg(vm, arg_p2p_add_peer)) { @@ -1141,7 +1139,7 @@ namespace nodetool template bool node_server::connect_to_seed() { - if (m_seed_nodes.empty()) + if (m_seed_nodes.empty() || m_offline) return true; size_t try_count = 0; From abebe392c7bb9fb0ff716c9640cd752e579ba068 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 30 Nov 2017 15:44:01 +0000 Subject: [PATCH 2/2] rpc: add offline state in info rpc --- src/rpc/core_rpc_server.cpp | 2 ++ src/rpc/core_rpc_server_commands_defs.h | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index e9a6a18aa..336db9073 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -150,6 +150,7 @@ namespace cryptonote res.status = CORE_RPC_STATUS_OK; res.start_time = (uint64_t)m_core.get_start_time(); res.free_space = m_restricted ? std::numeric_limits::max() : m_core.get_free_space(); + res.offline = m_core.offline(); return true; } //------------------------------------------------------------------------------------------------------------------------------ @@ -1330,6 +1331,7 @@ namespace cryptonote res.status = CORE_RPC_STATUS_OK; res.start_time = (uint64_t)m_core.get_start_time(); res.free_space = m_restricted ? std::numeric_limits::max() : m_core.get_free_space(); + res.offline = m_core.offline(); return true; } //------------------------------------------------------------------------------------------------------------------------------ diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index d27d5611e..0746def78 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -49,7 +49,7 @@ namespace cryptonote // advance which version they will stop working with // Don't go over 32767 for any of these #define CORE_RPC_VERSION_MAJOR 1 -#define CORE_RPC_VERSION_MINOR 16 +#define CORE_RPC_VERSION_MINOR 17 #define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor)) #define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR) @@ -928,6 +928,7 @@ namespace cryptonote uint64_t block_size_limit; uint64_t start_time; uint64_t free_space; + bool offline; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(status) @@ -949,6 +950,7 @@ namespace cryptonote KV_SERIALIZE(block_size_limit) KV_SERIALIZE(start_time) KV_SERIALIZE(free_space) + KV_SERIALIZE(offline) END_KV_SERIALIZE_MAP() }; };