aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--contrib/epee/include/console_handler.h5
-rw-r--r--contrib/epee/include/net/levin_protocol_handler_async.h3
-rw-r--r--contrib/epee/include/syncobj.h10
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.cpp89
-rw-r--r--src/blockchain_db/berkeleydb/db_bdb.h1
-rw-r--r--src/blockchain_utilities/CMakeLists.txt8
-rw-r--r--src/common/dns_utils.cpp42
-rw-r--r--src/p2p/data_logger.cpp3
-rw-r--r--src/p2p/net_node.h2
-rw-r--r--src/p2p/net_node.inl2
-rw-r--r--src/simplewallet/simplewallet.cpp15
11 files changed, 133 insertions, 47 deletions
diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h
index 5c63556ae..d76d7930c 100644
--- a/contrib/epee/include/console_handler.h
+++ b/contrib/epee/include/console_handler.h
@@ -36,6 +36,7 @@
#ifdef __OpenBSD__
#include <stdio.h>
#endif
+#include <boost/thread.hpp>
namespace epee
{
@@ -47,7 +48,7 @@ namespace epee
, m_has_read_request(false)
, m_read_status(state_init)
{
- m_reader_thread = std::thread(std::bind(&async_stdin_reader::reader_thread_func, this));
+ m_reader_thread = boost::thread(std::bind(&async_stdin_reader::reader_thread_func, this));
}
~async_stdin_reader()
@@ -212,7 +213,7 @@ namespace epee
};
private:
- std::thread m_reader_thread;
+ boost::thread m_reader_thread;
std::atomic<bool> m_run;
std::string m_line;
diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h
index a7fbffb4b..7331faa35 100644
--- a/contrib/epee/include/net/levin_protocol_handler_async.h
+++ b/contrib/epee/include/net/levin_protocol_handler_async.h
@@ -26,6 +26,7 @@
#pragma once
#include <boost/uuid/uuid_generators.hpp>
+#include <boost/unordered_map.hpp>
#include <boost/interprocess/detail/atomic.hpp>
#include <boost/smart_ptr/make_shared.hpp>
@@ -52,7 +53,7 @@ class async_protocol_handler;
template<class t_connection_context>
class async_protocol_handler_config
{
- typedef std::map<boost::uuids::uuid, async_protocol_handler<t_connection_context>* > connections_map;
+ typedef boost::unordered_map<boost::uuids::uuid, async_protocol_handler<t_connection_context>* > connections_map;
critical_section m_connects_lock;
connections_map m_connects;
diff --git a/contrib/epee/include/syncobj.h b/contrib/epee/include/syncobj.h
index b81eb43a9..275324436 100644
--- a/contrib/epee/include/syncobj.h
+++ b/contrib/epee/include/syncobj.h
@@ -30,8 +30,6 @@
#ifndef __WINH_OBJ_H__
#define __WINH_OBJ_H__
-#include <condition_variable>
-#include <mutex>
#include <boost/thread/locks.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/recursive_mutex.hpp>
@@ -51,22 +49,22 @@ namespace epee
void raise()
{
- std::unique_lock<std::mutex> lock(m_mx);
+ boost::unique_lock<boost::mutex> lock(m_mx);
m_rised = true;
m_cond_var.notify_one();
}
void wait()
{
- std::unique_lock<std::mutex> lock(m_mx);
+ boost::unique_lock<boost::mutex> lock(m_mx);
while (!m_rised)
m_cond_var.wait(lock);
m_rised = false;
}
private:
- std::mutex m_mx;
- std::condition_variable m_cond_var;
+ boost::mutex m_mx;
+ boost::condition_variable m_cond_var;
bool m_rised;
};
diff --git a/src/blockchain_db/berkeleydb/db_bdb.cpp b/src/blockchain_db/berkeleydb/db_bdb.cpp
index 55fd2e31f..bfdb22a10 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.cpp
+++ b/src/blockchain_db/berkeleydb/db_bdb.cpp
@@ -1073,8 +1073,10 @@ void BlockchainBDB::sync()
m_spent_keys->sync(0);
- m_hf_starting_heights->sync(0);
- m_hf_versions->sync(0);
+ if (m_hf_starting_heights != nullptr)
+ m_hf_starting_heights->sync(0);
+ if (m_hf_versions != nullptr)
+ m_hf_versions->sync(0);
m_properties->sync(0);
}
@@ -2208,12 +2210,91 @@ uint64_t BlockchainBDB::get_hard_fork_starting_height(uint8_t version) const
void BlockchainBDB::check_hard_fork_info()
{
- /* FIXME: Some other time */
+ LOG_PRINT_L3("BlockchainBDB::" << __func__);
+ check_open();
+
+ if (m_hf_versions == nullptr)
+ {
+ LOG_PRINT_L0("hf versions DB not open, so not checking");
+ return;
+ }
+
+ DB_BTREE_STAT* db_stat1, * db_stat2;
+
+ // DB_FAST_STAT can apparently cause an incorrect number of records
+ // to be returned. The flag should be set to 0 instead if this proves
+ // to be the case.
+
+ // Set txn to NULL and DB_FAST_STAT to zero (0) for reliability.
+ m_blocks->stat(NULL, &db_stat1, 0);
+ m_hf_versions->stat(NULL, &db_stat2, 0);
+ if (db_stat1->bt_nkeys != db_stat2->bt_nkeys)
+ {
+ LOG_PRINT_L0("num blocks " << db_stat1->bt_nkeys << " != " << "num hf_versions " << db_stat2->bt_nkeys << " - will clear the two hard fork DBs");
+
+ bdb_txn_safe txn;
+ bdb_txn_safe* txn_ptr = &txn;
+ if (m_write_txn)
+ txn_ptr = m_write_txn;
+ else
+ {
+ if (m_env->txn_begin(NULL, txn, 0))
+ throw0(DB_ERROR("Failed to create a transaction for the db"));
+ }
+
+ try
+ {
+ uint32_t count;
+ m_hf_starting_heights->truncate(*txn_ptr, &count, 0);
+ LOG_PRINT_L0("hf_starting_heights count: " << count);
+ m_hf_versions->truncate(*txn_ptr, &count, 0);
+ LOG_PRINT_L0("hf_versions count: " << count);
+
+ if (!m_write_txn)
+ txn.commit();
+ }
+ catch (const std::exception& e)
+ {
+ throw0(DB_ERROR(std::string("Failed to clear two hard fork DBs: ").append(e.what()).c_str()));
+ }
+ }
+ delete db_stat1;
+ delete db_stat2;
}
void BlockchainBDB::drop_hard_fork_info()
{
- /* TODO */
+ LOG_PRINT_L3("BlockchainBDB::" << __func__);
+ check_open();
+
+ bdb_txn_safe txn;
+ bdb_txn_safe* txn_ptr = &txn;
+ if (m_write_txn)
+ txn_ptr = m_write_txn;
+ else
+ {
+ if (m_env->txn_begin(NULL, txn, 0))
+ throw0(DB_ERROR("Failed to create a transaction for the db"));
+ }
+
+ try
+ {
+ m_hf_starting_heights->close(0);
+ m_hf_versions->close(0);
+ m_hf_starting_heights = nullptr;
+ m_hf_versions = nullptr;
+ if (m_env->dbremove(*txn_ptr, BDB_HF_STARTING_HEIGHTS, NULL, 0) != 0)
+ LOG_ERROR("Error removing hf_starting_heights");
+ if (m_env->dbremove(*txn_ptr, BDB_HF_VERSIONS, NULL, 0) != 0)
+ LOG_ERROR("Error removing hf_versions");
+
+ if (!m_write_txn)
+ txn.commit();
+ }
+ catch (const std::exception& e)
+ {
+ throw0(DB_ERROR(std::string("Failed to drop hard fork info: ").append(e.what()).c_str()));
+ }
}
void BlockchainBDB::set_hard_fork_version(uint64_t height, uint8_t version)
diff --git a/src/blockchain_db/berkeleydb/db_bdb.h b/src/blockchain_db/berkeleydb/db_bdb.h
index 38bef3934..bf9665cae 100644
--- a/src/blockchain_db/berkeleydb/db_bdb.h
+++ b/src/blockchain_db/berkeleydb/db_bdb.h
@@ -31,6 +31,7 @@
#include "cryptonote_protocol/blobdatatype.h" // for type blobdata
#include <unordered_map>
+#include <condition_variable>
// ND: Enables multi-threaded bulk reads for when getting indices.
// TODO: Disabled for now, as it doesn't seem to provide noticeable improvements (??. Reason: TBD.
diff --git a/src/blockchain_utilities/CMakeLists.txt b/src/blockchain_utilities/CMakeLists.txt
index 41c3098a0..96b30b83b 100644
--- a/src/blockchain_utilities/CMakeLists.txt
+++ b/src/blockchain_utilities/CMakeLists.txt
@@ -99,9 +99,9 @@ target_link_libraries(blockchain_converter
blockchain_db
${CMAKE_THREAD_LIBS_INIT})
-if(${ARCH_WIDTH} EQUAL 32)
+if(ARCH_WIDTH)
target_compile_definitions(blockchain_converter
- PUBLIC -DARCH_WIDTH=32)
+ PUBLIC -DARCH_WIDTH=${ARCH_WIDTH})
endif()
add_dependencies(blockchain_converter
@@ -122,9 +122,9 @@ target_link_libraries(blockchain_import
p2p
${CMAKE_THREAD_LIBS_INIT})
-if(${ARCH_WIDTH} EQUAL 32)
+if(ARCH_WIDTH)
target_compile_definitions(blockchain_import
- PUBLIC -DARCH_WIDTH=32)
+ PUBLIC -DARCH_WIDTH=${ARCH_WIDTH})
endif()
add_dependencies(blockchain_import
diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp
index eb7b6608b..e6e53a5c0 100644
--- a/src/common/dns_utils.cpp
+++ b/src/common/dns_utils.cpp
@@ -38,7 +38,7 @@
using namespace epee;
namespace bf = boost::filesystem;
-static std::mutex instance_lock;
+static boost::mutex instance_lock;
namespace
{
@@ -181,6 +181,17 @@ struct DNSResolverData
ub_ctx* m_ub_context;
};
+// work around for bug https://www.nlnetlabs.nl/bugs-script/show_bug.cgi?id=515 needed for it to compile on e.g. Debian 7
+class string_copy {
+public:
+ string_copy(const char *s): str(strdup(s)) {}
+ ~string_copy() { free(str); }
+ operator char*() { return str; }
+
+public:
+ char *str;
+};
+
DNSResolver::DNSResolver() : m_data(new DNSResolverData())
{
int use_dns_public = 0;
@@ -201,9 +212,9 @@ DNSResolver::DNSResolver() : m_data(new DNSResolverData())
if (use_dns_public)
{
- ub_ctx_set_fwd(m_data->m_ub_context, dns_public_addr);
- ub_ctx_set_option(m_data->m_ub_context, "do-udp:", "no");
- ub_ctx_set_option(m_data->m_ub_context, "do-tcp:", "yes");
+ ub_ctx_set_fwd(m_data->m_ub_context, string_copy(dns_public_addr));
+ ub_ctx_set_option(m_data->m_ub_context, string_copy("do-udp:"), string_copy("no"));
+ ub_ctx_set_option(m_data->m_ub_context, string_copy("do-tcp:"), string_copy("yes"));
}
else {
// look for "/etc/resolv.conf" and "/etc/hosts" or platform equivalent
@@ -211,24 +222,7 @@ DNSResolver::DNSResolver() : m_data(new DNSResolverData())
ub_ctx_hosts(m_data->m_ub_context, NULL);
}
- #ifdef DEVELOPER_LIBUNBOUND_OLD
- #pragma message "Using the work around for old libunbound"
- { // work around for bug https://www.nlnetlabs.nl/bugs-script/show_bug.cgi?id=515 needed for it to compile on e.g. Debian 7
- char * ds_copy = NULL; // this will be the writable copy of string that bugged version of libunbound requires
- try {
- char * ds_copy = strdup( ::get_builtin_ds() );
- ub_ctx_add_ta(m_data->m_ub_context, ds_copy);
- } catch(...) { // probably not needed but to work correctly in every case...
- if (ds_copy) { free(ds_copy); ds_copy=NULL; } // for the strdup
- throw ;
- }
- if (ds_copy) { free(ds_copy); ds_copy=NULL; } // for the strdup
- }
- #else
- // normal version for fixed libunbound
- ub_ctx_add_ta(m_data->m_ub_context, ::get_builtin_ds() );
- #endif
-
+ ub_ctx_add_ta(m_data->m_ub_context, string_copy(::get_builtin_ds()));
}
DNSResolver::~DNSResolver()
@@ -258,7 +252,7 @@ std::vector<std::string> DNSResolver::get_record(const std::string& url, int rec
ub_result_ptr result;
// call DNS resolver, blocking. if return value not zero, something went wrong
- if (!ub_resolve(m_data->m_ub_context, url.c_str(), record_type, DNS_CLASS_IN, &result))
+ if (!ub_resolve(m_data->m_ub_context, string_copy(url.c_str()), record_type, DNS_CLASS_IN, &result))
{
dnssec_available = (result->secure || (!result->secure && result->bogus));
dnssec_valid = result->secure && !result->bogus;
@@ -304,7 +298,7 @@ std::string DNSResolver::get_dns_format_from_oa_address(const std::string& oa_ad
DNSResolver& DNSResolver::instance()
{
- std::lock_guard<std::mutex> lock(instance_lock);
+ boost::lock_guard<boost::mutex> lock(instance_lock);
static DNSResolver* staticInstance = NULL;
if (staticInstance == NULL)
diff --git a/src/p2p/data_logger.cpp b/src/p2p/data_logger.cpp
index f875cb8f0..7fc85e3bc 100644
--- a/src/p2p/data_logger.cpp
+++ b/src/p2p/data_logger.cpp
@@ -31,6 +31,7 @@
#include <boost/chrono.hpp>
#include <boost/filesystem.hpp>
+#include <boost/thread.hpp>
#include <chrono>
#include "../../contrib/otshell_utils/utils.hpp"
@@ -85,7 +86,7 @@ namespace net_utils
_info_c("dbg/data","Creating thread for data logger"); // create timer thread
m_thread_maybe_running=true;
- std::shared_ptr<std::thread> logger_thread(new std::thread([&]() {
+ std::shared_ptr<boost::thread> logger_thread(new boost::thread([&]() {
_info_c("dbg/data","Inside thread for data logger");
while (m_state == data_logger_state::state_during_init) { // wait for creation to be done (in other thread, in singleton) before actually running
std::this_thread::sleep_for(std::chrono::seconds(1));
diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h
index 2ae849e2a..260dd813d 100644
--- a/src/p2p/net_node.h
+++ b/src/p2p/net_node.h
@@ -270,7 +270,7 @@ namespace nodetool
bool m_offline;
std::atomic<bool> m_save_graph;
std::atomic<bool> is_closing;
- std::unique_ptr<std::thread> mPeersLoggerThread;
+ std::unique_ptr<boost::thread> mPeersLoggerThread;
//critical_section m_connections_lock;
//connections_indexed_container m_connections;
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 47a5dc6c3..56717ec66 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -567,7 +567,7 @@ namespace nodetool
bool node_server<t_payload_net_handler>::run()
{
// creating thread to log number of connections
- mPeersLoggerThread.reset(new std::thread([&]()
+ mPeersLoggerThread.reset(new boost::thread([&]()
{
_note("Thread monitor number of peers - start");
while (!is_closing && !m_net_server.is_stop_signal_sent())
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index f4dcb6a35..55bddcddd 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -1814,9 +1814,18 @@ bool simple_wallet::transfer_main(bool new_algorithm, const std::vector<std::str
total_fee += ptx_vector[n].fee;
}
- std::string prompt_str = (boost::format(tr("Your transaction needs to be split into %llu transactions. "
- "This will result in a transaction fee being applied to each transaction, for a total fee of %s. Is this okay? (Y/Yes/N/No)")) %
- ((unsigned long long)ptx_vector.size()) % print_money(total_fee)).str();
+ std::string prompt_str;
+ if (ptx_vector.size() > 1)
+ {
+ prompt_str = (boost::format(tr("Your transaction needs to be split into %llu transactions. "
+ "This will result in a transaction fee being applied to each transaction, for a total fee of %s. Is this okay? (Y/Yes/N/No)")) %
+ ((unsigned long long)ptx_vector.size()) % print_money(total_fee)).str();
+ }
+ else
+ {
+ prompt_str = (boost::format(tr("The transaction fee is %s. Is this okay? (Y/Yes/N/No)")) %
+ print_money(total_fee)).str();
+ }
std::string accepted = command_line::input_line(prompt_str);
if (accepted != "Y" && accepted != "y" && accepted != "Yes" && accepted != "yes")
{