Merge pull request #2878

abebe392 rpc: add offline state in info rpc (moneromooo-monero)
7696e849 core: make --offline also disable DNS lookups (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2017-12-16 23:27:00 +02:00
commit 8da24c2a57
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
7 changed files with 42 additions and 13 deletions

View file

@ -305,7 +305,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);
@ -327,6 +327,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)
@ -414,11 +415,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;
@ -3641,14 +3642,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();

View file

@ -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<bool> m_cancel;

View file

@ -75,6 +75,10 @@ namespace cryptonote
, "Run on testnet. The wallet must be launched with --testnet flag."
, false
};
const command_line::arg_descriptor<bool> arg_offline = {
"offline"
, "Do not listen for peers, nor connect to any"
};
static const command_line::arg_descriptor<bool> 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();
@ -1340,8 +1346,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 <level|categories>\" command," << ENDL
<< "where <level> is between 0 (no details) and 4 (very verbose), or custom category based levels (eg, *:WARNING)." << ENDL
@ -1404,6 +1415,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;

View file

@ -62,6 +62,7 @@ namespace cryptonote
extern const command_line::arg_descriptor<std::string> arg_data_dir;
extern const command_line::arg_descriptor<std::string> arg_testnet_data_dir;
extern const command_line::arg_descriptor<bool, false> arg_testnet_on;
extern const command_line::arg_descriptor<bool> 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;
};
}