diff options
22 files changed, 212 insertions, 101 deletions
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp index fd2600bab..7d06ae57a 100644 --- a/src/blockchain_db/lmdb/db_lmdb.cpp +++ b/src/blockchain_db/lmdb/db_lmdb.cpp @@ -808,9 +808,13 @@ void BlockchainLMDB::open(const std::string& filename, const int mdb_flags) if (auto result = mdb_env_open(m_env, filename.c_str(), mdb_flags, 0644)) throw0(DB_ERROR(std::string("Failed to open lmdb environment: ").append(mdb_strerror(result)).c_str())); - // get a read/write MDB_txn + int txn_flags = 0; + if (mdb_flags & MDB_RDONLY) + txn_flags |= MDB_RDONLY; + + // get a read/write MDB_txn, depending on mdb_flags mdb_txn_safe txn; - if (mdb_txn_begin(m_env, NULL, 0, txn)) + if (mdb_txn_begin(m_env, NULL, txn_flags, txn)) throw0(DB_ERROR("Failed to create a transaction for the db")); // open necessary databases, and set properties as needed diff --git a/src/blockchain_utilities/blockchain_export.cpp b/src/blockchain_utilities/blockchain_export.cpp index aa34ea1dc..ec885ea98 100644 --- a/src/blockchain_utilities/blockchain_export.cpp +++ b/src/blockchain_utilities/blockchain_export.cpp @@ -38,7 +38,7 @@ using namespace epee; // log_space int main(int argc, char* argv[]) { uint32_t log_level = 0; - uint64_t block_height = 0; + uint64_t block_stop = 0; std::string import_filename = BLOCKCHAIN_RAW; boost::filesystem::path default_data_path {tools::get_default_data_dir()}; @@ -46,9 +46,9 @@ int main(int argc, char* argv[]) po::options_description desc_cmd_only("Command line options"); po::options_description desc_cmd_sett("Command line options and settings options"); - const command_line::arg_descriptor<uint32_t> arg_log_level = {"log-level", "", log_level}; - const command_line::arg_descriptor<uint64_t> arg_block_height = {"block-number", "", block_height}; - const command_line::arg_descriptor<bool> arg_testnet_on = { + const command_line::arg_descriptor<uint32_t> arg_log_level = {"log-level", "", log_level}; + const command_line::arg_descriptor<uint64_t> arg_block_stop = {"block-stop", "Stop at block number", block_stop}; + const command_line::arg_descriptor<bool> arg_testnet_on = { "testnet" , "Run on testnet." , false @@ -57,9 +57,9 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_cmd_sett, command_line::arg_data_dir, default_data_path.string()); command_line::add_arg(desc_cmd_sett, command_line::arg_testnet_data_dir, default_testnet_data_path.string()); - command_line::add_arg(desc_cmd_sett, arg_log_level); - command_line::add_arg(desc_cmd_sett, arg_block_height); command_line::add_arg(desc_cmd_sett, arg_testnet_on); + command_line::add_arg(desc_cmd_sett, arg_log_level); + command_line::add_arg(desc_cmd_sett, arg_block_stop); command_line::add_arg(desc_cmd_only, command_line::arg_help); @@ -84,7 +84,7 @@ int main(int argc, char* argv[]) } log_level = command_line::get_arg(vm, arg_log_level); - block_height = command_line::get_arg(vm, arg_block_height); + block_stop = command_line::get_arg(vm, arg_block_stop); log_space::get_set_log_detalisation_level(true, log_level); log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL); @@ -129,11 +129,14 @@ int main(int argc, char* argv[]) BlockchainDB* db = new BlockchainLMDB(); boost::filesystem::path folder(m_config_folder); folder /= db->get_db_name(); - LOG_PRINT_L0("Loading blockchain from folder " << folder.string() << " ..."); + int lmdb_flags = 0; + lmdb_flags |= MDB_RDONLY; const std::string filename = folder.string(); + + LOG_PRINT_L0("Loading blockchain from folder " << filename << " ..."); try { - db->open(filename); + db->open(filename, lmdb_flags); } catch (const std::exception& e) { @@ -148,7 +151,7 @@ int main(int argc, char* argv[]) LOG_PRINT_L0("Exporting blockchain raw data..."); BootstrapFile bootstrap; - r = bootstrap.store_blockchain_raw(core_storage, NULL, output_dir, block_height); + r = bootstrap.store_blockchain_raw(core_storage, NULL, output_dir, block_stop); CHECK_AND_ASSERT_MES(r, false, "Failed to export blockchain raw data"); LOG_PRINT_L0("Blockchain raw data exported OK"); } diff --git a/src/blockchain_utilities/blockchain_import.cpp b/src/blockchain_utilities/blockchain_import.cpp index 6777cc8fb..aeed2b335 100644 --- a/src/blockchain_utilities/blockchain_import.cpp +++ b/src/blockchain_utilities/blockchain_import.cpp @@ -142,8 +142,12 @@ int pop_blocks(FakeCore& simple_core, int num_blocks) std::vector<transaction> popped_txs; for (int i=0; i < num_blocks; ++i) { +#if defined(BLOCKCHAIN_DB) && (BLOCKCHAIN_DB == DB_MEMORY) + simple_core.m_storage.debug_pop_block_from_blockchain(); +#else // simple_core.m_storage.pop_block_from_blockchain() is private, so call directly through db simple_core.m_storage.get_db().pop_block(popped_block, popped_txs); +#endif quit = 1; } @@ -169,7 +173,7 @@ int pop_blocks(FakeCore& simple_core, int num_blocks) } template <typename FakeCore> -int import_from_file(FakeCore& simple_core, std::string& import_file_path, uint64_t stop_height=0) +int import_from_file(FakeCore& simple_core, std::string& import_file_path, uint64_t block_stop=0) { #if !defined(BLOCKCHAIN_DB) static_assert(std::is_same<fake_core_memory, FakeCore>::value || std::is_same<fake_core_lmdb, FakeCore>::value, @@ -230,15 +234,15 @@ int import_from_file(FakeCore& simple_core, std::string& import_file_path, uint6 // Note that a new blockchain will start with block number 0 (total blocks: 1) // due to genesis block being added at initialization. - if (! stop_height) + if (! block_stop) { - stop_height = total_source_blocks - 1; + block_stop = total_source_blocks - 1; } // These are what we'll try to use, and they don't have to be a determination // from source and destination blockchains, but those are the defaults. LOG_PRINT_L0("start block: " << start_height << " stop block: " << - stop_height); + block_stop); bool use_batch = false; if (opt_batch) @@ -277,7 +281,7 @@ int import_from_file(FakeCore& simple_core, std::string& import_file_path, uint6 { throw std::runtime_error("Error in deserialization of chunk size"); } - LOG_PRINT_L1("chunk_size: " << chunk_size); + LOG_PRINT_L3("chunk_size: " << chunk_size); if (chunk_size > BUFFER_SIZE) { @@ -288,8 +292,8 @@ int import_from_file(FakeCore& simple_core, std::string& import_file_path, uint6 { LOG_PRINT_L0("NOTE: chunk_size " << chunk_size << " > 100000"); } - else if (chunk_size < 0) { - LOG_PRINT_L0("ERROR: chunk_size " << chunk_size << " < 0"); + else if (chunk_size == 0) { + LOG_PRINT_L0("ERROR: chunk_size == 0"); return 2; } import_file.read(buffer_block, chunk_size); @@ -306,10 +310,10 @@ int import_from_file(FakeCore& simple_core, std::string& import_file_path, uint6 h += NUM_BLOCKS_PER_CHUNK; continue; } - if (h > stop_height) + if (h > block_stop) { std::cout << refresh_string << "block " << h-1 - << " / " << stop_height + << " / " << block_stop << std::flush; std::cout << ENDL << ENDL; LOG_PRINT_L0("Specified block number reached - stopping. block: " << h-1 << " total blocks: " << h); @@ -345,7 +349,7 @@ int import_from_file(FakeCore& simple_core, std::string& import_file_path, uint6 if ((h-1) % progress_interval == 0) { std::cout << refresh_string << "block " << h-1 - << " / " << stop_height + << " / " << block_stop << std::flush; } @@ -531,7 +535,7 @@ int main(int argc, char* argv[]) uint32_t log_level = LOG_LEVEL_0; uint64_t num_blocks = 0; - uint64_t block_height = 0; + uint64_t block_stop = 0; std::string dirname; std::string db_arg_str; @@ -540,10 +544,10 @@ int main(int argc, char* argv[]) po::options_description desc_cmd_only("Command line options"); po::options_description desc_cmd_sett("Command line options and settings options"); - const command_line::arg_descriptor<uint32_t> arg_log_level = {"log-level", "", log_level}; - const command_line::arg_descriptor<uint64_t> arg_block_height = {"block-number", "stop at block number", block_height}; - const command_line::arg_descriptor<uint64_t> arg_batch_size = {"batch-size", "", db_batch_size}; - const command_line::arg_descriptor<uint64_t> arg_pop_blocks = {"pop-blocks", "", num_blocks}; + const command_line::arg_descriptor<uint32_t> arg_log_level = {"log-level", "", log_level}; + const command_line::arg_descriptor<uint64_t> arg_block_stop = {"block-stop", "Stop at block number", block_stop}; + const command_line::arg_descriptor<uint64_t> arg_batch_size = {"batch-size", "", db_batch_size}; + const command_line::arg_descriptor<uint64_t> arg_pop_blocks = {"pop-blocks", "Remove blocks from end of blockchain", num_blocks}; const command_line::arg_descriptor<bool> arg_testnet_on = { "testnet" , "Run on testnet." @@ -567,14 +571,14 @@ int main(int argc, char* argv[]) command_line::add_arg(desc_cmd_sett, command_line::arg_data_dir, default_data_path.string()); command_line::add_arg(desc_cmd_sett, command_line::arg_testnet_data_dir, default_testnet_data_path.string()); - command_line::add_arg(desc_cmd_sett, arg_log_level); - command_line::add_arg(desc_cmd_sett, arg_block_height); - command_line::add_arg(desc_cmd_sett, arg_batch_size); - command_line::add_arg(desc_cmd_sett, arg_pop_blocks); command_line::add_arg(desc_cmd_sett, arg_testnet_on); + command_line::add_arg(desc_cmd_sett, arg_log_level); command_line::add_arg(desc_cmd_sett, arg_database); + command_line::add_arg(desc_cmd_sett, arg_batch_size); + command_line::add_arg(desc_cmd_sett, arg_block_stop); command_line::add_arg(desc_cmd_only, arg_count_blocks); + command_line::add_arg(desc_cmd_only, arg_pop_blocks); command_line::add_arg(desc_cmd_only, command_line::arg_help); // call add_options() directly for these arguments since @@ -602,7 +606,7 @@ int main(int argc, char* argv[]) opt_verify = command_line::get_arg(vm, arg_verify); opt_batch = command_line::get_arg(vm, arg_batch); opt_resume = command_line::get_arg(vm, arg_resume); - block_height = command_line::get_arg(vm, arg_block_height); + block_stop = command_line::get_arg(vm, arg_block_stop); db_batch_size = command_line::get_arg(vm, arg_batch_size); if (command_line::get_arg(vm, command_line::arg_help)) @@ -615,12 +619,12 @@ int main(int argc, char* argv[]) if (! opt_batch && ! vm["batch-size"].defaulted()) { std::cerr << "Error: batch-size set, but batch option not enabled" << ENDL; - exit(1); + return 1; } if (! db_batch_size) { std::cerr << "Error: batch-size must be > 0" << ENDL; - exit(1); + return 1; } if (opt_verify && vm["batch-size"].defaulted()) { @@ -634,11 +638,6 @@ int main(int argc, char* argv[]) db_batch_size = db_batch_size_verify; } } - uint64_t stop_height = 0; - if (! vm["block-number"].defaulted()) - { - stop_height = block_height; - } std::vector<std::string> db_engines {"memory", "lmdb"}; @@ -660,7 +659,7 @@ int main(int argc, char* argv[]) { BootstrapFile bootstrap; bootstrap.count_blocks(import_file_path); - exit(0); + return 0; } @@ -671,13 +670,13 @@ int main(int argc, char* argv[]) if (res) { std::cerr << "Error parsing database argument(s)" << ENDL; - exit(1); + return 1; } if (std::find(db_engines.begin(), db_engines.end(), db_engine) == db_engines.end()) { std::cerr << "Invalid database engine: " << db_engine << std::endl; - exit(1); + return 1; } LOG_PRINT_L0("database: " << db_engine); @@ -712,17 +711,17 @@ int main(int argc, char* argv[]) if (db_engine == "lmdb") { fake_core_lmdb simple_core(dirname, opt_testnet, opt_batch, mdb_flags); - import_from_file(simple_core, import_file_path, stop_height); + import_from_file(simple_core, import_file_path, block_stop); } else if (db_engine == "memory") { fake_core_memory simple_core(dirname, opt_testnet); - import_from_file(simple_core, import_file_path, stop_height); + import_from_file(simple_core, import_file_path, block_stop); } else { std::cerr << "database engine unrecognized" << ENDL; - exit(1); + return 1; } // for multi_db_compile: @@ -730,7 +729,7 @@ int main(int argc, char* argv[]) if (db_engine != default_db_engine) { std::cerr << "Invalid database engine for compiled version: " << db_engine << std::endl; - exit(1); + return 1; } #if BLOCKCHAIN_DB == DB_LMDB fake_core_lmdb simple_core(dirname, opt_testnet, opt_batch, mdb_flags); @@ -744,17 +743,17 @@ int main(int argc, char* argv[]) LOG_PRINT_L0("height: " << simple_core.m_storage.get_current_blockchain_height()); pop_blocks(simple_core, num_blocks); LOG_PRINT_L0("height: " << simple_core.m_storage.get_current_blockchain_height()); - exit(0); + return 0; } - import_from_file(simple_core, import_file_path, stop_height); + import_from_file(simple_core, import_file_path, block_stop); #endif } catch (const DB_ERROR& e) { std::cout << std::string("Error loading blockchain db: ") + e.what() + " -- shutting down now" << ENDL; - exit(1); + return 1; } // destructors called at exit: @@ -767,4 +766,5 @@ int main(int argc, char* argv[]) // LMDB fake_core, it calls Blockchain::deinit() on its object, which in turn // calls delete on its BlockchainDB derived class' object, which closes its // files. + return 0; } diff --git a/src/blockchain_utilities/bootstrap_file.cpp b/src/blockchain_utilities/bootstrap_file.cpp index fb67e12bc..70f0b1fec 100644 --- a/src/blockchain_utilities/bootstrap_file.cpp +++ b/src/blockchain_utilities/bootstrap_file.cpp @@ -286,9 +286,9 @@ bool BootstrapFile::close() #if SOURCE_DB == DB_MEMORY -bool BootstrapFile::store_blockchain_raw(blockchain_storage* _blockchain_storage, tx_memory_pool* _tx_pool, boost::filesystem::path& output_dir, uint64_t requested_block_height) +bool BootstrapFile::store_blockchain_raw(blockchain_storage* _blockchain_storage, tx_memory_pool* _tx_pool, boost::filesystem::path& output_dir, uint64_t requested_block_stop) #else -bool BootstrapFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_memory_pool* _tx_pool, boost::filesystem::path& output_dir, uint64_t requested_block_height) +bool BootstrapFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_memory_pool* _tx_pool, boost::filesystem::path& output_dir, uint64_t requested_block_stop) #endif { uint64_t num_blocks_written = 0; @@ -303,20 +303,24 @@ bool BootstrapFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_mem return false; } block b; - uint64_t height_start = m_height; // height_start uses 0-based height, m_height uses 1-based height. so height_start doesn't need to add 1 here, as it's already at the next height - uint64_t height_stop = 0; + + // block_start, block_stop use 0-based height. m_height uses 1-based height. So to resume export + // from last exported block, block_start doesn't need to add 1 here, as it's already at the next + // height. + uint64_t block_start = m_height; + uint64_t block_stop = 0; LOG_PRINT_L0("source blockchain height: " << m_blockchain_storage->get_current_blockchain_height()-1); - if ((requested_block_height > 0) && (requested_block_height < m_blockchain_storage->get_current_blockchain_height())) + if ((requested_block_stop > 0) && (requested_block_stop < m_blockchain_storage->get_current_blockchain_height())) { - LOG_PRINT_L0("Using requested block height: " << requested_block_height); - height_stop = requested_block_height; + LOG_PRINT_L0("Using requested block height: " << requested_block_stop); + block_stop = requested_block_stop; } else { - height_stop = m_blockchain_storage->get_current_blockchain_height() - 1; - LOG_PRINT_L0("Using block height of source blockchain: " << height_stop); + block_stop = m_blockchain_storage->get_current_blockchain_height() - 1; + LOG_PRINT_L0("Using block height of source blockchain: " << block_stop); } - for (m_cur_height = height_start; m_cur_height <= height_stop; ++m_cur_height) + for (m_cur_height = block_start; m_cur_height <= block_stop; ++m_cur_height) { // this method's height refers to 0-based height (genesis block = height 0) crypto::hash hash = m_blockchain_storage->get_block_id_by_height(m_cur_height); @@ -328,7 +332,7 @@ bool BootstrapFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_mem } if (m_cur_height % progress_interval == 0) { std::cout << refresh_string; - std::cout << "block " << m_cur_height << "/" << height_stop << std::flush; + std::cout << "block " << m_cur_height << "/" << block_stop << std::flush; } } // NOTE: use of NUM_BLOCKS_PER_CHUNK is a placeholder in case multi-block chunks are later supported. @@ -338,7 +342,7 @@ bool BootstrapFile::store_blockchain_raw(Blockchain* _blockchain_storage, tx_mem } // print message for last block, which may not have been printed yet due to progress_interval std::cout << refresh_string; - std::cout << "block " << m_cur_height-1 << "/" << height_stop << ENDL; + std::cout << "block " << m_cur_height-1 << "/" << block_stop << ENDL; LOG_PRINT_L0("Number of blocks exported: " << num_blocks_written); if (num_blocks_written > 0) diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index 347cf758a..98e3d0ea6 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -205,15 +205,13 @@ std::vector<std::string> DNSResolver::get_ipv4(const std::string& url, bool& dns dnssec_valid = false; char urlC[1000]; // waaaay too big, but just in case... - std::string url_copy{url}; - if (!check_address_syntax(url_copy)) + strncpy(urlC, url.c_str(), 999); + urlC[999] = '\0'; + if (!check_address_syntax(urlC)) { return addresses; } - strncpy(urlC, url_copy.c_str(), 999); - urlC[999] = '\0'; - // destructor takes care of cleanup ub_result_ptr result; @@ -241,15 +239,14 @@ std::vector<std::string> DNSResolver::get_ipv6(const std::string& url, bool& dns dnssec_valid = false; char urlC[1000]; // waaaay too big, but just in case... - std::string url_copy{url}; - if (!check_address_syntax(url_copy)) + strncpy(urlC, url.c_str(), 999); + urlC[999] = '\0'; + + if (!check_address_syntax(urlC)) { return addresses; } - strncpy(urlC, url_copy.c_str(), 999); - urlC[999] = '\0'; - ub_result_ptr result; // call DNS resolver, blocking. if return value not zero, something went wrong @@ -276,15 +273,14 @@ std::vector<std::string> DNSResolver::get_txt_record(const std::string& url, boo dnssec_valid = false; char urlC[1000]; // waaaay too big, but just in case... - std::string url_copy{url}; - if (!check_address_syntax(url_copy)) + strncpy(urlC, url.c_str(), 999); + urlC[999] = '\0'; + + if (!check_address_syntax(urlC)) { return records; } - strncpy(urlC, url_copy.c_str(), 999); - urlC[999] = '\0'; - ub_result_ptr result; // call DNS resolver, blocking. if return value not zero, something went wrong @@ -308,6 +304,19 @@ std::vector<std::string> DNSResolver::get_txt_record(const std::string& url, boo return records; } +std::string DNSResolver::get_dns_format_from_oa_address(const std::string& oa_addr) +{ + std::string addr(oa_addr); + auto first_at = addr.find("@"); + if (first_at == std::string::npos) + return addr; + + // convert name@domain.tld to name.domain.tld + addr.replace(first_at, 1, "."); + + return addr; +} + DNSResolver& DNSResolver::instance() { static DNSResolver* staticInstance = NULL; @@ -318,17 +327,13 @@ DNSResolver& DNSResolver::instance() return *staticInstance; } -bool DNSResolver::check_address_syntax(std::string& addr) +bool DNSResolver::check_address_syntax(const std::string& addr) { // if string doesn't contain a dot, we won't consider it a url for now. - auto first_dot = addr.find("."); - if (first_dot == std::string::npos) + if (addr.find(".") == std::string::npos) { return false; } - - // allow name@domain.tld to work - addr.replace(first_dot, 1, "@"); return true; } diff --git a/src/common/dns_utils.h b/src/common/dns_utils.h index 4e48acb09..d98523a30 100644 --- a/src/common/dns_utils.h +++ b/src/common/dns_utils.h @@ -101,6 +101,18 @@ public: std::vector<std::string> get_txt_record(const std::string& url, bool& dnssec_available, bool& dnssec_valid); /** + * @brief Gets a DNS address from OpenAlias format + * + * If the address looks good, but contains one @ symbol, replace that with a . + * e.g. donate@getmonero.org becomes donate.getmonero.org + * + * @param oa_addr OpenAlias address + * + * @return dns_addr DNS address + */ + std::string get_dns_format_from_oa_address(const std::string& oa_addr); + + /** * @brief Gets the singleton instance of DNSResolver * * @return returns a pointer to the singleton @@ -112,14 +124,11 @@ private: /** * @brief Checks a string to see if it looks like a URL * - * If the address looks good, but contains one @ symbol, replace that with a . - * e.g. donate@getmonero.org becomes donate.getmonero.org - * * @param addr the string to be checked * * @return true if it looks enough like a URL, false if not */ - bool check_address_syntax(std::string& addr); + bool check_address_syntax(const std::string& addr); DNSResolverData *m_data; }; // class DNSResolver diff --git a/src/cryptonote_core/blockchain_storage.h b/src/cryptonote_core/blockchain_storage.h index 50a62a428..2c2fb5250 100644 --- a/src/cryptonote_core/blockchain_storage.h +++ b/src/cryptonote_core/blockchain_storage.h @@ -190,6 +190,9 @@ namespace cryptonote difficulty_type get_block_cumulative_difficulty(uint64_t height) const { return m_blocks[height].cumulative_difficulty; } uint64_t get_block_coins_generated(uint64_t height) const { return m_blocks[height].already_generated_coins; } + // use for testing only + bool debug_pop_block_from_blockchain() { return pop_block_from_blockchain(); } + private: typedef std::unordered_map<crypto::hash, size_t> blocks_by_id_index; typedef std::unordered_map<crypto::hash, transaction_chain_entry> transactions_container; diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp index fd7b40be2..1b86ff269 100644 --- a/src/daemon/command_parser_executor.cpp +++ b/src/daemon/command_parser_executor.cpp @@ -251,7 +251,10 @@ bool t_command_parser_executor::print_status(const std::vector<std::string>& arg bool t_command_parser_executor::set_limit(const std::vector<std::string>& args) { - if(args.size()!=1) return false; + if(args.size()>1) return false; + if(args.size()==0) { + return m_executor.get_limit(); + } int limit; try { limit = std::stoi(args[0]); @@ -267,7 +270,10 @@ bool t_command_parser_executor::set_limit(const std::vector<std::string>& args) bool t_command_parser_executor::set_limit_up(const std::vector<std::string>& args) { - if(args.size()!=1) return false; + if(args.size()>1) return false; + if(args.size()==0) { + return m_executor.get_limit_up(); + } int limit; try { limit = std::stoi(args[0]); @@ -283,7 +289,10 @@ bool t_command_parser_executor::set_limit_up(const std::vector<std::string>& arg bool t_command_parser_executor::set_limit_down(const std::vector<std::string>& args) { - if(args.size()!=1) return false; + if(args.size()>1) return false; + if(args.size()==0) { + return m_executor.get_limit_down(); + } int limit; try { limit = std::stoi(args[0]); diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index 8ef91600c..79b52711a 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -737,6 +737,15 @@ bool t_rpc_command_executor::print_status() return true; } +bool t_rpc_command_executor::get_limit() +{ + int limit_down = epee::net_utils::connection_basic::get_rate_down_limit( ); + int limit_up = epee::net_utils::connection_basic::get_rate_up_limit( ); + std::cout << "limit-down is " << limit_down/1024 << " kB/s" << std::endl; + std::cout << "limit-up is " << limit_up/1024 << " kB/s" << std::endl; + return true; +} + bool t_rpc_command_executor::set_limit(int limit) { epee::net_utils::connection_basic::set_rate_down_limit( limit ); @@ -746,6 +755,13 @@ bool t_rpc_command_executor::set_limit(int limit) return true; } +bool t_rpc_command_executor::get_limit_up() +{ + int limit_up = epee::net_utils::connection_basic::get_rate_up_limit( ); + std::cout << "limit-up is " << limit_up/1024 << " kB/s" << std::endl; + return true; +} + bool t_rpc_command_executor::set_limit_up(int limit) { epee::net_utils::connection_basic::set_rate_up_limit( limit ); @@ -753,6 +769,13 @@ bool t_rpc_command_executor::set_limit_up(int limit) return true; } +bool t_rpc_command_executor::get_limit_down() +{ + int limit_down = epee::net_utils::connection_basic::get_rate_down_limit( ); + std::cout << "limit-down is " << limit_down/1024 << " kB/s" << std::endl; + return true; +} + bool t_rpc_command_executor::set_limit_down(int limit) { epee::net_utils::connection_basic::set_rate_down_limit( limit ); diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h index 43b8a9fe0..21229c577 100644 --- a/src/daemon/rpc_command_executor.h +++ b/src/daemon/rpc_command_executor.h @@ -99,6 +99,12 @@ public: bool print_status(); + bool get_limit(); + + bool get_limit_up(); + + bool get_limit_down(); + bool set_limit(int limit); bool set_limit_up(int limit); diff --git a/src/p2p/connection_basic.cpp b/src/p2p/connection_basic.cpp index 0454f30e3..d3f6415c5 100644 --- a/src/p2p/connection_basic.cpp +++ b/src/p2p/connection_basic.cpp @@ -199,6 +199,23 @@ void connection_basic::set_rate_down_limit(uint64_t limit) { save_limit_to_file(limit); } +uint64_t connection_basic::get_rate_up_limit() { + uint64_t limit; + { + CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_out ); + limit = network_throttle_manager::get_global_throttle_out().get_target_speed(); + } + return limit; +} + +uint64_t connection_basic::get_rate_down_limit() { + uint64_t limit; + { + CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_in ); + limit = network_throttle_manager::get_global_throttle_in().get_target_speed(); + } + return limit; +} void connection_basic::save_limit_to_file(int limit) { // saving limit to file @@ -207,12 +224,12 @@ void connection_basic::save_limit_to_file(int limit) { { CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_out ); - epee::net_utils::data_logger::get_instance().add_data("upload_limit", network_throttle_manager::get_global_throttle_out().get_terget_speed() / 1024); + epee::net_utils::data_logger::get_instance().add_data("upload_limit", network_throttle_manager::get_global_throttle_out().get_target_speed() / 1024); } { CRITICAL_REGION_LOCAL( network_throttle_manager::m_lock_get_global_throttle_in ); - epee::net_utils::data_logger::get_instance().add_data("download_limit", network_throttle_manager::get_global_throttle_in().get_terget_speed() / 1024); + epee::net_utils::data_logger::get_instance().add_data("download_limit", network_throttle_manager::get_global_throttle_in().get_target_speed() / 1024); } } diff --git a/src/p2p/connection_basic.hpp b/src/p2p/connection_basic.hpp index d8101afe4..945cd982c 100644 --- a/src/p2p/connection_basic.hpp +++ b/src/p2p/connection_basic.hpp @@ -119,6 +119,8 @@ class connection_basic { // not-templated base class for rapid developmet of som static void set_rate_up_limit(uint64_t limit); static void set_rate_down_limit(uint64_t limit); + static uint64_t get_rate_up_limit(); + static uint64_t get_rate_down_limit(); // config misc static void set_tos_flag(int tos); // ToS / QoS flag diff --git a/src/p2p/network_throttle-detail.cpp b/src/p2p/network_throttle-detail.cpp index 6fa27b62a..6e6989d44 100644 --- a/src/p2p/network_throttle-detail.cpp +++ b/src/p2p/network_throttle-detail.cpp @@ -172,7 +172,7 @@ void network_throttle::set_real_target_speed( network_speed_kbps real_target ) m_real_target_speed = real_target * 1024; } -network_speed_kbps network_throttle::get_terget_speed() +network_speed_kbps network_throttle::get_target_speed() { return m_real_target_speed / 1024; } diff --git a/src/p2p/network_throttle-detail.hpp b/src/p2p/network_throttle-detail.hpp index 063dac850..9f0003332 100644 --- a/src/p2p/network_throttle-detail.hpp +++ b/src/p2p/network_throttle-detail.hpp @@ -81,7 +81,7 @@ class network_throttle : public i_network_throttle { virtual void set_name(const std::string &name); virtual void set_target_speed( network_speed_kbps target ); virtual void set_real_target_speed( network_speed_kbps real_target ); // only for throttle_out - virtual network_speed_kbps get_terget_speed(); + virtual network_speed_kbps get_target_speed(); // add information about events: virtual void handle_trafic_exact(size_t packet_size); ///< count the new traffic/packet; the size is exact considering all network costs diff --git a/src/p2p/network_throttle.hpp b/src/p2p/network_throttle.hpp index add4daa86..b93cfc563 100644 --- a/src/p2p/network_throttle.hpp +++ b/src/p2p/network_throttle.hpp @@ -147,7 +147,7 @@ class i_network_throttle { virtual void set_name(const std::string &name)=0; virtual void set_target_speed( network_speed_kbps target )=0; virtual void set_real_target_speed(network_speed_kbps real_target)=0; - virtual network_speed_kbps get_terget_speed()=0; + virtual network_speed_kbps get_target_speed()=0; virtual void handle_trafic_exact(size_t packet_size) =0; // count the new traffic/packet; the size is exact considering all network costs virtual void handle_trafic_tcp(size_t packet_size) =0; // count the new traffic/packet; the size is as TCP, we will consider MTU etc diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 9ac80fa9e..2b2488952 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -208,6 +208,13 @@ bool simple_wallet::viewkey(const std::vector<std::string> &args/* = std::vector return true; } +bool simple_wallet::spendkey(const std::vector<std::string> &args/* = std::vector<std::string>()*/) +{ + success_msg_writer() << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_spend_secret_key) << std::endl; + + return true; +} + bool simple_wallet::seed(const std::vector<std::string> &args/* = std::vector<std::string>()*/) { bool success = false; @@ -288,6 +295,7 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("address", boost::bind(&simple_wallet::print_address, this, _1), "Show current wallet public address"); m_cmd_binder.set_handler("save", boost::bind(&simple_wallet::save, this, _1), "Save wallet synchronized data"); m_cmd_binder.set_handler("viewkey", boost::bind(&simple_wallet::viewkey, this, _1), "Get viewkey"); + m_cmd_binder.set_handler("spendkey", boost::bind(&simple_wallet::spendkey, this, _1), "Get spendkey"); m_cmd_binder.set_handler("seed", boost::bind(&simple_wallet::seed, this, _1), "Get deterministic seed"); m_cmd_binder.set_handler("set", boost::bind(&simple_wallet::set_variable, this, _1), "available options: seed language - Set wallet seed langage"); m_cmd_binder.set_handler("help", boost::bind(&simple_wallet::help, this, _1), "Show this help"); diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h index a8fe78414..de5b3674e 100644 --- a/src/simplewallet/simplewallet.h +++ b/src/simplewallet/simplewallet.h @@ -80,6 +80,7 @@ namespace cryptonote bool close_wallet(); bool viewkey(const std::vector<std::string> &args = std::vector<std::string>()); + bool spendkey(const std::vector<std::string> &args = std::vector<std::string>()); bool seed(const std::vector<std::string> &args = std::vector<std::string>()); /*! diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 6698e7296..7928e1c62 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -1016,7 +1016,8 @@ std::vector<std::string> wallet2::addresses_from_url(const std::string& url, boo std::vector<std::string> addresses; // get txt records bool dnssec_available, dnssec_isvalid; - auto records = tools::DNSResolver::instance().get_txt_record(url, dnssec_available, dnssec_isvalid); + std::string oa_addr = tools::DNSResolver::instance().get_dns_format_from_oa_address(url); + auto records = tools::DNSResolver::instance().get_txt_record(oa_addr, dnssec_available, dnssec_isvalid); // TODO: update this to allow for conveying that dnssec was not available if (dnssec_available && dnssec_isvalid) diff --git a/tests/functional_tests/transactions_flow_test.cpp b/tests/functional_tests/transactions_flow_test.cpp index 5d88b65f2..5d276ec2a 100644 --- a/tests/functional_tests/transactions_flow_test.cpp +++ b/tests/functional_tests/transactions_flow_test.cpp @@ -112,7 +112,7 @@ uint64_t get_money_in_first_transfers(const tools::wallet2::transfer_container& bool transactions_flow_test(std::string& working_folder, std::string path_source_wallet, - std::string path_terget_wallet, + std::string path_target_wallet, std::string& daemon_addr_a, std::string& daemon_addr_b, uint64_t amount_to_transfer, size_t mix_in_factor, size_t transactions_count, size_t transactions_per_second) @@ -122,14 +122,14 @@ bool transactions_flow_test(std::string& working_folder, if(path_source_wallet.empty()) path_source_wallet = generate_random_wallet_name(); - if(path_terget_wallet.empty()) - path_terget_wallet = generate_random_wallet_name(); + if(path_target_wallet.empty()) + path_target_wallet = generate_random_wallet_name(); try { w1.generate(working_folder + "/" + path_source_wallet, ""); - w2.generate(working_folder + "/" + path_terget_wallet, ""); + w2.generate(working_folder + "/" + path_target_wallet, ""); } catch (const std::exception& e) { @@ -152,7 +152,7 @@ bool transactions_flow_test(std::string& working_folder, LOG_PRINT_GREEN("Using wallets: " << ENDL << "Source: " << w1.get_account().get_public_address_str(false) << ENDL << "Path: " << working_folder + "/" + path_source_wallet << ENDL - << "Target: " << w2.get_account().get_public_address_str(false) << ENDL << "Path: " << working_folder + "/" + path_terget_wallet, LOG_LEVEL_1); + << "Target: " << w2.get_account().get_public_address_str(false) << ENDL << "Path: " << working_folder + "/" + path_target_wallet, LOG_LEVEL_1); //lets do some money epee::net_utils::http::http_simple_client http_client; diff --git a/tests/functional_tests/transactions_flow_test.h b/tests/functional_tests/transactions_flow_test.h index 0d2f28700..95c8b397e 100644 --- a/tests/functional_tests/transactions_flow_test.h +++ b/tests/functional_tests/transactions_flow_test.h @@ -30,7 +30,7 @@ bool transactions_flow_test(std::string& working_folder, std::string path_source_wallet, - std::string path_terget_wallet, + std::string path_target_wallet, std::string& daemon_addr_a, std::string& daemon_addr_b, uint64_t amount_to_transfer, size_t mix_in_factor, size_t transactions_count, size_t transactions_per_second); diff --git a/tests/unit_tests/address_from_url.cpp b/tests/unit_tests/address_from_url.cpp index fe2f072de..99df75d74 100644 --- a/tests/unit_tests/address_from_url.cpp +++ b/tests/unit_tests/address_from_url.cpp @@ -93,6 +93,14 @@ TEST(AddressFromURL, Success) { EXPECT_STREQ(addr.c_str(), addresses[0].c_str()); } + + // OpenAlias address with an @ instead of first . + addresses = tools::wallet2::addresses_from_url("donate@getmonero.org", dnssec_result); + EXPECT_EQ(1, addresses.size()); + if (addresses.size() == 1) + { + EXPECT_STREQ(addr.c_str(), addresses[0].c_str()); + } } TEST(AddressFromURL, Failure) diff --git a/tests/unit_tests/dns_resolver.cpp b/tests/unit_tests/dns_resolver.cpp index 6717e990a..0709a773f 100644 --- a/tests/unit_tests/dns_resolver.cpp +++ b/tests/unit_tests/dns_resolver.cpp @@ -148,4 +148,12 @@ TEST(DNSResolver, GetTXTRecord) { std::cout << "TXT record for donate.getmonero.org: " << rec << std::endl; } + + // replace first @ with . + std::string addr = tools::DNSResolver::instance().get_dns_format_from_oa_address("donate@getmonero.org"); + EXPECT_STREQ("donate.getmonero.org", addr.c_str()); + + // no change + addr = tools::DNSResolver::instance().get_dns_format_from_oa_address("donate.getmonero.org"); + EXPECT_STREQ("donate.getmonero.org", addr.c_str()); } |