Merge pull request #1767

708758b7 core: do not download an update we already downloaded (moneromooo-monero)
45101550 updates: use updates host, not downloads, for HTTP (moneromooo-monero)
This commit is contained in:
Riccardo Spagni 2017-02-22 09:35:35 +02:00
commit 80a088a4fe
No known key found for this signature in database
GPG key ID: 55432DF31CCD4FCD
2 changed files with 24 additions and 15 deletions

View file

@ -96,7 +96,7 @@ namespace tools
std::string get_update_url(const std::string &software, const std::string &subdir, const std::string &buildtag, const std::string &version) std::string get_update_url(const std::string &software, const std::string &subdir, const std::string &buildtag, const std::string &version)
{ {
static const char base[] = "https://downloads.getmonero.org/"; static const char base[] = "https://updates.getmonero.org/";
#ifdef _WIN32 #ifdef _WIN32
static const char extension[] = ".zip"; static const char extension[] = ".zip";
#else #else

View file

@ -1100,7 +1100,7 @@ namespace cryptonote
return true; return true;
std::string version, hash; std::string version, hash;
MDEBUG("Checking for a new " << software << " version for " << buildtag); MCDEBUG("updates", "Checking for a new " << software << " version for " << buildtag);
if (!tools::check_updates(software, buildtag, m_testnet, version, hash)) if (!tools::check_updates(software, buildtag, m_testnet, version, hash))
return false; return false;
@ -1121,28 +1121,37 @@ namespace cryptonote
filename = std::string(software) + "-update-" + version; filename = std::string(software) + "-update-" + version;
boost::filesystem::path path(epee::string_tools::get_current_module_folder()); boost::filesystem::path path(epee::string_tools::get_current_module_folder());
path /= filename; path /= filename;
if (!tools::download(path.string(), url))
{
MERROR("Failed to download " << url);
return false;
}
crypto::hash file_hash; crypto::hash file_hash;
if (!tools::sha256sum(path.string(), file_hash)) if (!tools::sha256sum(path.string(), file_hash) || (hash != epee::string_tools::pod_to_hex(file_hash)))
{ {
MERROR("Failed to hash " << path); MCDEBUG("updates", "We don't have that file already, downloading");
return false; 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;
}
MCINFO("updates", "New version downloaded to " << path);
} }
if (hash != epee::string_tools::pod_to_hex(file_hash)) else
{ {
MERROR("Download from " << url << " does not match the expected hash"); MCDEBUG("updates", "We already have " << path << " with expected hash");
return false;
} }
MGINFO("New version downloaded to " << path);
if (check_updates_level == UPDATES_DOWNLOAD) if (check_updates_level == UPDATES_DOWNLOAD)
return true; return true;
MERROR("Download/update not implemented yet"); MCERROR("updates", "Download/update not implemented yet");
return true; return true;
} }
//----------------------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------------------