diff --git a/src/common/updates.cpp b/src/common/updates.cpp index d32fd2d1..25e55f33 100644 --- a/src/common/updates.cpp +++ b/src/common/updates.cpp @@ -1,4 +1,5 @@ -// Copyright (c) 2017-2018, The Monero Project +// Copyright (c) 2017-2019, The Monero Project +// Copyright (c) 2019, The NERVA Project // // All rights reserved. // @@ -37,7 +38,7 @@ namespace tools { - bool check_updates(const std::string &software, const std::string &buildtag, std::string &version, std::string &hash) + bool check_updates(const std::string &software, std::string &version, std::string &codename, std::string ¬ice) { std::vector records; bool found = false; @@ -63,33 +64,21 @@ namespace tools continue; } - if (software != fields[0] || buildtag != fields[1]) + if (software != fields[0]) continue; - bool alnum = true; - for (auto c: fields[3]) - if (!isalnum(c)) - alnum = false; - if (fields[3].size() != 64 && !alnum) - { - MWARNING("Invalid hash: " << fields[3]); - continue; - } - - // use highest version if (found) { - int cmp = vercmp(version.c_str(), fields[2].c_str()); + int cmp = vercmp(version.c_str(), fields[1].c_str()); if (cmp > 0) continue; - if (cmp == 0 && hash != fields[3]) - MWARNING("Two matches found for " << software << " version " << version << " on " << buildtag); } - version = fields[2]; - hash = fields[3]; + version = fields[1]; + codename = fields[2]; + notice = fields[3]; - LOG_PRINT_L1("Found new version " << version << " with hash " << hash); + LOG_PRINT_L1("Found new version " << version << ":" << codename); found = true; } return found; diff --git a/src/common/updates.h b/src/common/updates.h index 335bc32c..afebbb5d 100644 --- a/src/common/updates.h +++ b/src/common/updates.h @@ -32,6 +32,6 @@ namespace tools { - bool check_updates(const std::string &software, const std::string &buildtag, std::string &version, std::string &hash); + bool check_updates(const std::string &software, std::string &version, std::string &codename, std::string ¬ice); std::string get_update_url(const std::string &software, const std::string &buildtag, const std::string &version); } diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 74e265a9..17483d48 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -40,7 +40,6 @@ using namespace epee; #include "common/command_line.h" #include "common/util.h" #include "common/updates.h" -#include "common/download.h" #include "common/threadpool.h" #include "common/command_line.h" #include "warnings.h" @@ -185,7 +184,6 @@ namespace cryptonote m_last_json_checkpoints_update(0), m_disable_dns_checkpoints(false), m_threadpool(tools::threadpool::getInstance()), - m_update_download(0), m_nettype(UNDEFINED), m_pad_transactions(false) { @@ -253,15 +251,6 @@ namespace cryptonote { m_miner.stop(); m_blockchain_storage.cancel(); - - tools::download_async_handle handle; - { - boost::lock_guard lock(m_update_mutex); - handle = m_update_download; - m_update_download = 0; - } - if (handle) - tools::download_cancel(handle); } //----------------------------------------------------------------------------------- void core::init_options(boost::program_options::options_description& desc) @@ -570,10 +559,6 @@ namespace cryptonote check_updates_level = UPDATES_DISABLED; else if (check_updates_string == "notify") check_updates_level = UPDATES_NOTIFY; - else if (check_updates_string == "download") - check_updates_level = UPDATES_DOWNLOAD; - else if (check_updates_string == "update") - check_updates_level = UPDATES_UPDATE; else { MERROR("Invalid argument to --dns-versions-check: " << check_updates_string); return false; @@ -1544,7 +1529,7 @@ namespace cryptonote //----------------------------------------------------------------------------------------------- bool core::check_updates() { - static const char software[] = "amity"; + static const char software[] = "amity-cli"; #ifdef BUILD_TAG static const char buildtag[] = BOOST_PP_STRINGIZE(BUILD_TAG); #else @@ -1557,9 +1542,9 @@ namespace cryptonote if (check_updates_level == UPDATES_DISABLED) return true; - std::string version, hash; + std::string version, codename, notice; MCDEBUG("updates", "Checking for a new " << software << " version for " << buildtag); - if (!tools::check_updates(software, buildtag, version, hash)) + if (!tools::check_updates(software, version, codename, notice)) return false; if (tools::vercmp(version.c_str(), MONERO_VERSION) <= 0) @@ -1567,105 +1552,10 @@ namespace cryptonote std::string url = tools::get_update_url(software, buildtag, version); MGUSER_CYAN(ENDL - << "Version " << version << " of " << software << " for " << buildtag << " is available" << ENDL + << "Version " << version << ":" << codename << " is available" << ENDL << url << ENDL - << "SHA256: " << hash); - - if (check_updates_level == UPDATES_NOTIFY) - return true; - - url = tools::get_update_url(software, buildtag, version); - std::string filename; - const char *slash = strrchr(url.c_str(), '/'); - if (slash) - filename = slash + 1; - else - filename = std::string(software) + "-update-" + version; - boost::filesystem::path path(epee::string_tools::get_current_module_folder()); - path /= filename; - - boost::unique_lock lock(m_update_mutex); - - if (m_update_download != 0) - { - MCDEBUG("updates", "Already downloading update"); - return true; - } - - crypto::hash file_hash; - if (!tools::sha256sum(path.string(), file_hash) || (hash != epee::string_tools::pod_to_hex(file_hash))) - { - MCDEBUG("updates", "We don't have that file already, downloading"); - const std::string tmppath = path.string() + ".tmp"; - if (epee::file_io_utils::is_file_exist(tmppath)) - { - MCDEBUG("updates", "We have part of the file already, resuming download"); - } - m_last_update_length = 0; - m_update_download = tools::download_async(tmppath, url, [this, hash, path](const std::string &tmppath, const std::string &uri, bool success) { - bool remove = false, good = true; - if (success) - { - crypto::hash file_hash; - if (!tools::sha256sum(tmppath, file_hash)) - { - MCERROR("updates", "Failed to hash " << tmppath); - remove = true; - good = false; - } - else if (hash != epee::string_tools::pod_to_hex(file_hash)) - { - MCERROR("updates", "Download from " << uri << " does not match the expected hash"); - remove = true; - good = false; - } - } - else - { - MCERROR("updates", "Failed to download " << uri); - good = false; - } - boost::unique_lock lock(m_update_mutex); - m_update_download = 0; - if (success && !remove) - { - std::error_code e = tools::replace_file(tmppath, path.string()); - if (e) - { - MCERROR("updates", "Failed to rename downloaded file"); - good = false; - } - } - else if (remove) - { - if (!boost::filesystem::remove(tmppath)) - { - MCERROR("updates", "Failed to remove invalid downloaded file"); - good = false; - } - } - if (good) - MCLOG_CYAN(el::Level::Info, "updates", "New version downloaded to " << path.string()); - }, [this](const std::string &path, const std::string &uri, size_t length, ssize_t content_length) { - if (length >= m_last_update_length + 1024 * 1024 * 10) - { - m_last_update_length = length; - MCDEBUG("updates", "Downloaded " << length << "/" << (content_length ? std::to_string(content_length) : "unknown")); - } - return true; - }); - } - else - { - MCDEBUG("updates", "We already have " << path << " with expected hash"); - } - - lock.unlock(); - - if (check_updates_level == UPDATES_DOWNLOAD) - return true; + << "Release note: " << notice); - MCERROR("updates", "Download/update not implemented yet"); return true; } //----------------------------------------------------------------------------------------------- diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index 4dfd4dcf..d659c48c 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -38,7 +38,6 @@ #include "cryptonote_protocol/cryptonote_protocol_handler_common.h" #include "storages/portable_storage_template_helper.h" -#include "common/download.h" #include "common/threadpool.h" #include "common/command_line.h" #include "tx_pool.h" @@ -985,16 +984,10 @@ namespace cryptonote enum { UPDATES_DISABLED, UPDATES_NOTIFY, - UPDATES_DOWNLOAD, - UPDATES_UPDATE, } check_updates_level; - tools::download_async_handle m_update_download; - size_t m_last_update_length; - boost::mutex m_update_mutex; - bool m_offline; - bool m_pad_transactions; + bool m_pad_transactions; }; } diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 210dd8d3..c62cbe99 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -2225,15 +2225,15 @@ namespace cryptonote bool core_rpc_server::on_update(const COMMAND_RPC_UPDATE::request& req, COMMAND_RPC_UPDATE::response& res, const connection_context *ctx) { PERF_TIMER(on_update); - static const char software[] = "amity"; + static const char software[] = "amity-cli"; #ifdef BUILD_TAG static const char buildtag[] = BOOST_PP_STRINGIZE(BUILD_TAG); #else static const char buildtag[] = "x64"; #endif - std::string version, hash; - if (!tools::check_updates(software, buildtag, version, hash)) + std::string version, codename, notice; + if (!tools::check_updates(software, version, codename, notice)) { res.status = "Error checking for updates"; return true; @@ -2246,8 +2246,9 @@ namespace cryptonote } res.update = true; res.version = version; + res.codename = codename; res.uri = tools::get_update_url(software, buildtag, version); - res.hash = hash; + res.release_note = notice; res.status = CORE_RPC_STATUS_OK; return true; diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h index da1f0c88..794bc0f7 100644 --- a/src/rpc/core_rpc_server_commands_defs.h +++ b/src/rpc/core_rpc_server_commands_defs.h @@ -2029,6 +2029,8 @@ namespace cryptonote std::string status; bool update; std::string version; + std::string codename; + std::string release_note; std::string uri; std::string hash;