diff options
| author | Riccardo Spagni <ric@spagni.net> | 2017-03-06 15:17:08 +0000 |
|---|---|---|
| committer | Riccardo Spagni <ric@spagni.net> | 2017-03-06 15:17:08 +0000 |
| commit | ba0767477d58033824fb3a48134a0b4c14100d24 (patch) | |
| tree | e09471953b4cd85af8b04428525bd4d6a9400219 /src/cryptonote_core/cryptonote_core.cpp | |
| parent | ea047307da9e6761f8c55c0dc83ad4bf519269ac (diff) | |
| parent | b553c282fbe733ac35802845c0dfcfb316e2818d (diff) | |
| download | monzero-core-ba0767477d58033824fb3a48134a0b4c14100d24.tar.gz monzero-core-ba0767477d58033824fb3a48134a0b4c14100d24.tar.xz monzero-core-ba0767477d58033824fb3a48134a0b4c14100d24.zip | |
Merge pull request #1841
b553c282 rpc: fix BUILD_TAG mispelling (BUILDTAG) (moneromooo-monero)
02097c87 core: print the "new update found" message in cyan, for visibility (moneromooo-monero)
749ebace download: check available disk space before downloading (moneromooo-monero)
f36c5f1e download: give download threads distinct names (moneromooo-monero)
f6211322 core: make update download cancellable (moneromooo-monero)
63f0e074 download: async API (moneromooo-monero)
9bf017ed http_client: allow cancelling a download (moneromooo-monero)
0d90123c http_client: allow derived class to get headers at start (moneromooo-monero)
Diffstat (limited to 'src/cryptonote_core/cryptonote_core.cpp')
| -rw-r--r-- | src/cryptonote_core/cryptonote_core.cpp | 69 |
1 files changed, 51 insertions, 18 deletions
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index cfe3b5441..9c5fae4ef 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -75,7 +75,8 @@ namespace cryptonote m_target_blockchain_height(0), m_checkpoints_path(""), m_last_dns_checkpoints_update(0), - m_last_json_checkpoints_update(0) + m_last_json_checkpoints_update(0), + m_update_download(0) { set_cryptonote_protocol(pprotocol); } @@ -134,6 +135,15 @@ namespace cryptonote void core::stop() { m_blockchain_storage.cancel(); + + tools::download_async_handle handle; + { + boost::lock_guard<boost::mutex> 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) @@ -1118,7 +1128,7 @@ namespace cryptonote return true; std::string url = tools::get_update_url(software, subdir, buildtag, version, true); - MGINFO("Version " << version << " of " << software << " for " << buildtag << " is available: " << url << ", SHA256 hash " << hash); + MCLOG_CYAN(el::Level::Info, "global", "Version " << version << " of " << software << " for " << buildtag << " is available: " << url << ", SHA256 hash " << hash); if (check_updates_level == UPDATES_NOTIFY) return true; @@ -1133,32 +1143,55 @@ namespace cryptonote boost::filesystem::path path(epee::string_tools::get_current_module_folder()); path /= filename; + boost::unique_lock<boost::mutex> 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"); - if (!tools::download(path.string(), url)) - { - MCERROR("updates", "Failed to download " << url); - return false; - } - if (!tools::sha256sum(path.string(), file_hash)) - { - MCERROR("updates", "Failed to hash " << path); - return false; - } - if (hash != epee::string_tools::pod_to_hex(file_hash)) - { - MCERROR("updates", "Download from " << url << " does not match the expected hash"); - return false; - } - MGINFO("New version downloaded to " << path); + m_last_update_length = 0; + m_update_download = tools::download_async(path.string(), url, [this, hash](const std::string &path, const std::string &uri, bool success) { + if (success) + { + crypto::hash file_hash; + if (!tools::sha256sum(path, file_hash)) + { + MCERROR("updates", "Failed to hash " << path); + } + if (hash != epee::string_tools::pod_to_hex(file_hash)) + { + MCERROR("updates", "Download from " << uri << " does not match the expected hash"); + } + MCLOG_CYAN(el::Level::Info, "updates", "New version downloaded to " << path); + } + else + { + MCERROR("updates", "Failed to download " << uri); + } + boost::unique_lock<boost::mutex> lock(m_update_mutex); + m_update_download = 0; + }, [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; |
