diff options
21 files changed, 220 insertions, 19 deletions
diff --git a/contrib/epee/src/mlog.cpp b/contrib/epee/src/mlog.cpp index cb617bb9a..70782d9d3 100644 --- a/contrib/epee/src/mlog.cpp +++ b/contrib/epee/src/mlog.cpp @@ -88,7 +88,7 @@ static const char *get_default_categories(int level) switch (level) { case 0: - categories = "*:WARNING,net:FATAL,net.p2p:FATAL,global:INFO,verify:FATAL,stacktrace:INFO"; + categories = "*:WARNING,net:FATAL,net.p2p:FATAL,net.cn:FATAL,global:INFO,verify:FATAL,stacktrace:INFO"; break; case 1: categories = "*:WARNING,global:INFO,stacktrace:INFO"; @@ -142,7 +142,7 @@ void mlog_configure(const std::string &filename_base, bool console) void mlog_set_categories(const char *categories) { el::Loggers::setCategories(categories); - MGINFO("New log categories: " << categories); + MDEBUG("New log categories: " << categories); } // maps epee style log level to new logging system @@ -150,7 +150,7 @@ void mlog_set_log_level(int level) { const char *categories = get_default_categories(level); el::Loggers::setCategories(categories); - MGINFO("New log categories: " << categories); + MDEBUG("New log categories: " << categories); } void mlog_set_log(const char *log) diff --git a/src/blockchain_db/blockchain_db.h b/src/blockchain_db/blockchain_db.h index 39208250d..674b844c1 100644 --- a/src/blockchain_db/blockchain_db.h +++ b/src/blockchain_db/blockchain_db.h @@ -37,7 +37,7 @@ #include "cryptonote_protocol/blobdatatype.h" #include "cryptonote_basic/cryptonote_basic.h" #include "cryptonote_basic/difficulty.h" -#include "cryptonote_basic/hardfork.h" +#include "cryptonote_core/hardfork.h" /** \file * Cryptonote Blockchain Database Interface diff --git a/src/cryptonote_basic/CMakeLists.txt b/src/cryptonote_basic/CMakeLists.txt index 9df157a9e..db478c690 100644 --- a/src/cryptonote_basic/CMakeLists.txt +++ b/src/cryptonote_basic/CMakeLists.txt @@ -32,8 +32,7 @@ set(cryptonote_basic_sources cryptonote_basic_impl.cpp cryptonote_format_utils.cpp difficulty.cpp - miner.cpp - hardfork.cpp) + miner.cpp) set(cryptonote_basic_headers) @@ -50,8 +49,7 @@ set(cryptonote_basic_private_headers difficulty.h miner.h tx_extra.h - verification_context.h - hardfork.h) + verification_context.h) monero_private_headers(cryptonote_basic ${crypto_private_headers}) diff --git a/src/cryptonote_core/CMakeLists.txt b/src/cryptonote_core/CMakeLists.txt index 5944ddcd1..8a72dd259 100644 --- a/src/cryptonote_core/CMakeLists.txt +++ b/src/cryptonote_core/CMakeLists.txt @@ -30,6 +30,7 @@ set(cryptonote_core_sources blockchain.cpp cryptonote_core.cpp tx_pool.cpp + hardfork.cpp cryptonote_tx_utils.cpp) set(cryptonote_core_headers) @@ -37,6 +38,7 @@ set(cryptonote_core_headers) set(cryptonote_core_private_headers blockchain_storage_boost_serialization.h blockchain.h + hardfork.h cryptonote_core.h tx_pool.h cryptonote_tx_utils.h) diff --git a/src/cryptonote_core/blockchain.h b/src/cryptonote_core/blockchain.h index 2c7420e18..6e4ba5e2a 100644 --- a/src/cryptonote_core/blockchain.h +++ b/src/cryptonote_core/blockchain.h @@ -51,7 +51,7 @@ #include "cryptonote_basic/verification_context.h" #include "crypto/hash.h" #include "cryptonote_basic/checkpoints.h" -#include "cryptonote_basic/hardfork.h" +#include "cryptonote_core/hardfork.h" #include "blockchain_db/blockchain_db.h" namespace cryptonote diff --git a/src/cryptonote_basic/hardfork.cpp b/src/cryptonote_core/hardfork.cpp index 24d6655f0..50da70050 100644 --- a/src/cryptonote_basic/hardfork.cpp +++ b/src/cryptonote_core/hardfork.cpp @@ -29,7 +29,7 @@ #include <algorithm> #include <cstdio> -#include "cryptonote_basic.h" +#include "cryptonote_basic/cryptonote_basic.h" #include "blockchain_db/blockchain_db.h" #include "hardfork.h" diff --git a/src/cryptonote_basic/hardfork.h b/src/cryptonote_core/hardfork.h index 11241e657..6c6fbcb84 100644 --- a/src/cryptonote_basic/hardfork.h +++ b/src/cryptonote_core/hardfork.h @@ -29,7 +29,7 @@ #pragma once #include "syncobj.h" -#include "cryptonote_basic.h" +#include "cryptonote_basic/cryptonote_basic.h" namespace cryptonote { diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp b/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp index e06d9cd31..e31276031 100644 --- a/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp +++ b/src/cryptonote_protocol/cryptonote_protocol_handler-base.cpp @@ -122,7 +122,7 @@ cryptonote_protocol_handler_base::~cryptonote_protocol_handler_base() { void cryptonote_protocol_handler_base::handler_request_blocks_history(std::list<crypto::hash>& ids) { using namespace epee::net_utils; MDEBUG("### ~~~RRRR~~~~ ### sending request (type 2), limit = " << ids.size()); - MWARNING("RATE LIMIT NOT IMPLEMENTED HERE YET (download at unlimited speed?)"); + MDEBUG("RATE LIMIT NOT IMPLEMENTED HERE YET (download at unlimited speed?)"); // TODO } diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp index 8daaac611..4e6e83eb5 100644 --- a/src/daemon/command_parser_executor.cpp +++ b/src/daemon/command_parser_executor.cpp @@ -552,4 +552,15 @@ bool t_command_parser_executor::print_blockchain_dynamic_stats(const std::vector return m_executor.print_blockchain_dynamic_stats(nblocks); } +bool t_command_parser_executor::update(const std::vector<std::string>& args) +{ + if(args.size() != 1) + { + std::cout << "Exactly one parameter is needed: check, download, or update" << std::endl; + return false; + } + + return m_executor.update(args.front()); +} + } // namespace daemonize diff --git a/src/daemon/command_parser_executor.h b/src/daemon/command_parser_executor.h index 37f431974..0a5ca8dd9 100644 --- a/src/daemon/command_parser_executor.h +++ b/src/daemon/command_parser_executor.h @@ -130,6 +130,8 @@ public: bool alt_chain_info(const std::vector<std::string>& args); bool print_blockchain_dynamic_stats(const std::vector<std::string>& args); + + bool update(const std::vector<std::string>& args); }; } // namespace daemonize diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp index 4a063268f..0081e00dc 100644 --- a/src/daemon/command_server.cpp +++ b/src/daemon/command_server.cpp @@ -243,6 +243,11 @@ t_command_server::t_command_server( , std::bind(&t_command_parser_executor::print_blockchain_dynamic_stats, &m_parser, p::_1) , "Print information about current blockchain dynamic state" ); + m_command_lookup.set_handler( + "update" + , std::bind(&t_command_parser_executor::update, &m_parser, p::_1) + , "subcommands: check (check if an update is available), download (download it is there is), update (not implemented)" + ); } bool t_command_server::process_command_str(const std::string& cmd) diff --git a/src/daemon/protocol.h b/src/daemon/protocol.h index a59b6ab1e..fc5edbcaa 100644 --- a/src/daemon/protocol.h +++ b/src/daemon/protocol.h @@ -79,7 +79,6 @@ public: m_protocol.deinit(); m_protocol.set_p2p_endpoint(nullptr); MGINFO("Cryptonote protocol stopped successfully"); - tools::success_msg_writer() << "Daemon stopped successfully"; } catch (...) { LOG_ERROR("Failed to stop cryptonote protocol!"); } diff --git a/src/daemon/rpc_command_executor.cpp b/src/daemon/rpc_command_executor.cpp index b33736839..5135ecb4b 100644 --- a/src/daemon/rpc_command_executor.cpp +++ b/src/daemon/rpc_command_executor.cpp @@ -34,7 +34,7 @@ #include "daemon/rpc_command_executor.h" #include "rpc/core_rpc_server_commands_defs.h" #include "cryptonote_core/cryptonote_core.h" -#include "cryptonote_basic/hardfork.h" +#include "cryptonote_core/hardfork.h" #include <boost/format.hpp> #include <ctime> #include <string> @@ -1580,4 +1580,51 @@ bool t_rpc_command_executor::print_blockchain_dynamic_stats(uint64_t nblocks) return true; } +bool t_rpc_command_executor::update(const std::string &command) +{ + cryptonote::COMMAND_RPC_UPDATE::request req; + cryptonote::COMMAND_RPC_UPDATE::response res; + epee::json_rpc::error error_resp; + + std::string fail_message = "Problem fetching info"; + + req.command = command; + if (m_is_rpc) + { + if (!m_rpc_client->rpc_request(req, res, "/update", fail_message.c_str())) + { + return true; + } + } + else + { + if (!m_rpc_server->on_update(req, res) || res.status != CORE_RPC_STATUS_OK) + { + tools::fail_msg_writer() << fail_message.c_str(); + return true; + } + } + + if (!res.update) + { + tools::msg_writer() << "No update available"; + return true; + } + + tools::msg_writer() << "Update available: v" << res.version << ": " << res.user_uri << ", hash " << res.hash; + if (command == "check") + return true; + + if (!res.path.empty()) + tools::msg_writer() << "Update downloaded to: " << res.path; + else + tools::msg_writer() << "Update download failed: " << res.status; + if (command == "download") + return true; + + tools::msg_writer() << "'update' not implemented yet"; + + return true; +} + }// namespace daemonize diff --git a/src/daemon/rpc_command_executor.h b/src/daemon/rpc_command_executor.h index eb95101ce..a015c83ea 100644 --- a/src/daemon/rpc_command_executor.h +++ b/src/daemon/rpc_command_executor.h @@ -151,6 +151,8 @@ public: bool alt_chain_info(); bool print_blockchain_dynamic_stats(uint64_t nblocks); + + bool update(const std::string &command); }; } // namespace daemonize diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index d79621de4..a01125120 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -33,6 +33,9 @@ using namespace epee; #include "core_rpc_server.h" #include "common/command_line.h" +#include "common/updates.h" +#include "common/download.h" +#include "common/util.h" #include "cryptonote_basic/cryptonote_format_utils.h" #include "cryptonote_basic/account.h" #include "cryptonote_basic/cryptonote_basic_impl.h" @@ -1455,6 +1458,98 @@ namespace cryptonote return true; } //------------------------------------------------------------------------------------------------------------------------------ + bool core_rpc_server::on_update(const COMMAND_RPC_UPDATE::request& req, COMMAND_RPC_UPDATE::response& res) + { + static const char software[] = "monero"; +#ifdef BUILDTAG + static const char buildtag[] = BOOST_PP_STRINGIZE(BUILDTAG); +#else + static const char buildtag[] = "source"; +#endif + + if (req.command != "check" && req.command != "download" && req.command != "update") + { + res.status = std::string("unknown command: '") + req.command + "'"; + return true; + } + + std::string version, hash; + if (!tools::check_updates(software, buildtag, version, hash)) + { + res.status = "Error checking for updates"; + return true; + } + if (tools::vercmp(version.c_str(), MONERO_VERSION) <= 0) + { + res.update = false; + res.status = CORE_RPC_STATUS_OK; + return true; + } + res.update = true; + res.version = version; + res.user_uri = tools::get_update_url(software, "cli", buildtag, version, true); + res.auto_uri = tools::get_update_url(software, "cli", buildtag, version, false); + res.hash = hash; + if (req.command == "check") + { + res.status = CORE_RPC_STATUS_OK; + return true; + } + + boost::filesystem::path path; + if (req.path.empty()) + { + std::string filename; + const char *slash = strrchr(res.auto_uri.c_str(), '/'); + if (slash) + filename = slash + 1; + else + filename = std::string(software) + "-update-" + version; + path = epee::string_tools::get_current_module_folder(); + path /= filename; + } + else + { + path = req.path; + } + + crypto::hash file_hash; + if (!tools::sha256sum(path.string(), file_hash) || (hash != epee::string_tools::pod_to_hex(file_hash))) + { + MDEBUG("We don't have that file already, downloading"); + if (!tools::download(path.string(), res.auto_uri)) + { + MERROR("Failed to download " << res.auto_uri); + return false; + } + if (!tools::sha256sum(path.string(), file_hash)) + { + MERROR("Failed to hash " << path); + return false; + } + if (hash != epee::string_tools::pod_to_hex(file_hash)) + { + MERROR("Download from " << res.auto_uri << " does not match the expected hash"); + return false; + } + MINFO("New version downloaded to " << path); + } + else + { + MDEBUG("We already have " << path << " with expected hash"); + } + res.path = path.string(); + + if (req.command == "download") + { + res.status = CORE_RPC_STATUS_OK; + return true; + } + + res.status = "'update' not implemented yet"; + return true; + } + //------------------------------------------------------------------------------------------------------------------------------ const command_line::arg_descriptor<std::string> core_rpc_server::arg_rpc_bind_port = { "rpc-bind-port" diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h index 00db47c2d..900f473a9 100644 --- a/src/rpc/core_rpc_server.h +++ b/src/rpc/core_rpc_server.h @@ -98,6 +98,7 @@ namespace cryptonote MAP_URI_AUTO_JON2_IF("/start_save_graph", on_start_save_graph, COMMAND_RPC_START_SAVE_GRAPH, !m_restricted) MAP_URI_AUTO_JON2_IF("/stop_save_graph", on_stop_save_graph, COMMAND_RPC_STOP_SAVE_GRAPH, !m_restricted) MAP_URI_AUTO_JON2("/get_outs", on_get_outs, COMMAND_RPC_GET_OUTPUTS) + MAP_URI_AUTO_JON2_IF("/update", on_update, COMMAND_RPC_UPDATE, !m_restricted) BEGIN_JSON_RPC_MAP("/json_rpc") MAP_JON_RPC("getblockcount", on_getblockcount, COMMAND_RPC_GETBLOCKCOUNT) MAP_JON_RPC_WE("on_getblockhash", on_getblockhash, COMMAND_RPC_GETBLOCKHASH) @@ -148,6 +149,7 @@ namespace cryptonote bool on_out_peers(const COMMAND_RPC_OUT_PEERS::request& req, COMMAND_RPC_OUT_PEERS::response& res); bool on_start_save_graph(const COMMAND_RPC_START_SAVE_GRAPH::request& req, COMMAND_RPC_START_SAVE_GRAPH::response& res); bool on_stop_save_graph(const COMMAND_RPC_STOP_SAVE_GRAPH::request& req, COMMAND_RPC_STOP_SAVE_GRAPH::response& res); + bool on_update(const COMMAND_RPC_UPDATE::request& req, COMMAND_RPC_UPDATE::response& res); //json_rpc bool on_getblockcount(const COMMAND_RPC_GETBLOCKCOUNT::request& req, COMMAND_RPC_GETBLOCKCOUNT::response& res); diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index 9f15da82a..47fa10d85 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -1438,4 +1438,39 @@ namespace cryptonote END_KV_SERIALIZE_MAP() }; }; + + struct COMMAND_RPC_UPDATE + { + struct request + { + std::string command; + std::string path; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(command); + KV_SERIALIZE(path); + END_KV_SERIALIZE_MAP() + }; + + struct response + { + std::string status; + bool update; + std::string version; + std::string user_uri; + std::string auto_uri; + std::string hash; + std::string path; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(status) + KV_SERIALIZE(update) + KV_SERIALIZE(version) + KV_SERIALIZE(user_uri) + KV_SERIALIZE(auto_uri) + KV_SERIALIZE(hash) + KV_SERIALIZE(path) + END_KV_SERIALIZE_MAP() + }; + }; } diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index c798d4d31..99645189a 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -656,9 +656,11 @@ string WalletImpl::keysFilename() const return m_wallet->get_keys_file(); } -bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transaction_size_limit) +bool WalletImpl::init(const std::string &daemon_address, uint64_t upper_transaction_size_limit, const std::string &daemon_username, const std::string &daemon_password) { clearStatus(); + if(daemon_username != "") + m_daemon_login.emplace(daemon_username, daemon_password); return doInit(daemon_address, upper_transaction_size_limit); } @@ -1365,7 +1367,7 @@ bool WalletImpl::isNewWallet() const bool WalletImpl::doInit(const string &daemon_address, uint64_t upper_transaction_size_limit) { - if (!m_wallet->init(daemon_address, boost::none, upper_transaction_size_limit)) + if (!m_wallet->init(daemon_address, m_daemon_login, upper_transaction_size_limit)) return false; // in case new wallet, this will force fast-refresh (pulling hashes instead of blocks) diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index 3501fa0ac..456110908 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h @@ -78,7 +78,7 @@ public: bool store(const std::string &path); std::string filename() const; std::string keysFilename() const; - bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0); + bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit = 0, const std::string &daemon_username = "", const std::string &daemon_password = ""); bool connectToDaemon(); ConnectionStatus connected() const; void setTrustedDaemon(bool arg); @@ -170,6 +170,7 @@ private: std::atomic<bool> m_rebuildWalletCache; // cache connection status to avoid unnecessary RPC calls mutable std::atomic<bool> m_is_connected; + boost::optional<epee::net_utils::http::login> m_daemon_login{}; }; diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h index eec4f8b8f..e32d23d9f 100644 --- a/src/wallet/wallet2_api.h +++ b/src/wallet/wallet2_api.h @@ -340,7 +340,7 @@ struct Wallet * \param upper_transaction_size_limit * \return - true on success */ - virtual bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit) = 0; + virtual bool init(const std::string &daemon_address, uint64_t upper_transaction_size_limit, const std::string &daemon_username = "", const std::string &daemon_password = "") = 0; /*! * \brief createWatchOnly - Creates a watch only wallet diff --git a/tests/unit_tests/hardfork.cpp b/tests/unit_tests/hardfork.cpp index 08c4276c8..512216ded 100644 --- a/tests/unit_tests/hardfork.cpp +++ b/tests/unit_tests/hardfork.cpp @@ -33,7 +33,7 @@ #include "blockchain_db/lmdb/db_lmdb.h" #include "cryptonote_basic/cryptonote_format_utils.h" -#include "cryptonote_basic/hardfork.h" +#include "cryptonote_core/hardfork.h" using namespace cryptonote; |