aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-02-20 20:48:36 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2017-02-20 22:58:37 +0000
commita5a0a3c8944f7cd6b5b72aaf2b9c41c7b3c40358 (patch)
tree5576b129e1f50c4e90f2c4db19605036cc331c9f /src/cryptonote_core
parentutil: add a SHA256 function (diff)
downloadmonero-a5a0a3c8944f7cd6b5b72aaf2b9c41c7b3c40358.tar.xz
core: updates can now be downloaded (and SHA256 hash checked)
Diffstat (limited to 'src/cryptonote_core')
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index 7ed01ca1d..fd509b603 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -36,6 +36,7 @@ using namespace epee;
#include "common/command_line.h"
#include "common/util.h"
#include "common/updates.h"
+#include "common/download.h"
#include "warnings.h"
#include "crypto/crypto.h"
#include "cryptonote_config.h"
@@ -1090,6 +1091,35 @@ namespace cryptonote
if (check_updates_level == UPDATES_NOTIFY)
return true;
+ 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;
+ if (!tools::download(path.string(), url))
+ {
+ MERROR("Failed to download " << url);
+ return false;
+ }
+ crypto::hash file_hash;
+ 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 " << url << " does not match the expected hash");
+ return false;
+ }
+ MGINFO("New version downloaded to " << path);
+
+ if (check_updates_level == UPDATES_DOWNLOAD)
+ return true;
+
MERROR("Download/update not implemented yet");
return true;
}