diff options
author | Thomas Winget <tewinget@gmail.com> | 2014-09-26 01:01:58 -0400 |
---|---|---|
committer | Thomas Winget <tewinget@gmail.com> | 2014-09-30 16:21:37 -0400 |
commit | b261d9207ba5cdc0334fab403204971f79b6ca03 (patch) | |
tree | b113fc0deb913b3e27be1d33f60daa62a52462b4 /src/cryptonote_core/checkpoints_create.cpp | |
parent | reload checkpoints file every ~hr and print if any fail (diff) | |
download | monero-b261d9207ba5cdc0334fab403204971f79b6ca03.tar.xz |
DNS checkpoint updating added, and daemon flag to enforce them
The daemon should now check for updated checkpoints from
checkpoints.moneropulse.org as well as from the configured json file
every ~1hr (and on launch).
The daemon now has a flag to enable enforcing these checkpoints (rather
than just printing a warning when they fail).
TODO: an easily configurable list of DNS servers to check for
checkpoints as opposed to the hard-coded "checkpoints.moneropulse.org"
Diffstat (limited to 'src/cryptonote_core/checkpoints_create.cpp')
-rw-r--r-- | src/cryptonote_core/checkpoints_create.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/cryptonote_core/checkpoints_create.cpp b/src/cryptonote_core/checkpoints_create.cpp index ff927396e..b81353539 100644 --- a/src/cryptonote_core/checkpoints_create.cpp +++ b/src/cryptonote_core/checkpoints_create.cpp @@ -29,6 +29,9 @@ // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers #include "checkpoints_create.h" +#include "common/dns_utils.h" +#include "include_base_utils.h" +#include <sstream> #include "storages/portable_storage_template_helper.h" // epee json include namespace cryptonote @@ -107,4 +110,51 @@ bool load_checkpoints_from_json(cryptonote::checkpoints& checkpoints, std::strin return true; } +bool load_checkpoints_from_dns(cryptonote::checkpoints& checkpoints, const std::string& url) +{ + bool avail, valid; + auto records = tools::DNSResolver::instance().get_txt_record(url, avail, valid); + + if (avail && !valid) + { + LOG_ERROR("DNSSEC present and failed validation for query to" << url); + return false; + } + + for (auto& record : records) + { + auto pos = record.find(":"); + if (pos != std::string::npos) + { + uint64_t height; + crypto::hash hash; + + // parse the first part as uint64_t, + // if this fails move on to the next record + std::stringstream ss(record.substr(0, pos)); + if (!(ss >> height)) + { + continue; + } + + // parse the second part as crypto::hash, + // if this fails move on to the next record + std::string hashStr = record.substr(pos + 1); + if (!epee::string_tools::parse_tpod_from_hex_string(hashStr, hash)) + { + continue; + } + + ADD_CHECKPOINT(height, hashStr); + } + } + return true; +} + +bool load_new_checkpoints(cryptonote::checkpoints& checkpoints, std::string json_hashfile_fullpath) +{ + // TODO: replace hard-coded url with const string or #define + return (load_checkpoints_from_json(checkpoints, json_hashfile_fullpath) && load_checkpoints_from_dns(checkpoints, "checkpoints.moneropulse.org")); +} + } // namespace cryptonote |