From 2b76e9d8a3bb47f78abaa9b5eb99c1e111316264 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 13:06:03 -0400 Subject: Change Windows include to windows mingw is case sensitive --- src/crypto/slow-hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/crypto/slow-hash.c b/src/crypto/slow-hash.c index 3aff7bd5d..b33ef0f47 100644 --- a/src/crypto/slow-hash.c +++ b/src/crypto/slow-hash.c @@ -41,7 +41,7 @@ #if defined(_MSC_VER) #include -#include +#include #define STATIC #define INLINE __inline #if !defined(RDATA_ALIGN16) -- cgit v1.2.3 From cf91545734134866e93fa8cc8d36a7b8cf45bafb Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 13:07:36 -0400 Subject: Correct includes for mingw in slow-hash This needs testing --- src/crypto/slow-hash.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/crypto/slow-hash.c b/src/crypto/slow-hash.c index b33ef0f47..2d3197d62 100644 --- a/src/crypto/slow-hash.c +++ b/src/crypto/slow-hash.c @@ -47,6 +47,14 @@ #if !defined(RDATA_ALIGN16) #define RDATA_ALIGN16 __declspec(align(16)) #endif +#elif defined(__MINGW32__) +#include +#include +#define STATIC static +#define INLINE inline +#if !defined(RDATA_ALIGN16) +#define RDATA_ALIGN16 __attribute__ ((aligned(16))) +#endif #else #include #include -- cgit v1.2.3 From aba3497fdd6c47500dbbbce54c29900f24a3d55b Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 13:08:15 -0400 Subject: More preprocessor fixes for slow-hash --- src/crypto/slow-hash.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/crypto/slow-hash.c b/src/crypto/slow-hash.c index 2d3197d62..d4f27e1e1 100644 --- a/src/crypto/slow-hash.c +++ b/src/crypto/slow-hash.c @@ -295,7 +295,7 @@ STATIC INLINE void aes_pseudo_round_xor(const uint8_t *in, uint8_t *out, } } -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) BOOL SetLockPagesPrivilege(HANDLE hProcess, BOOL bEnable) { struct @@ -333,7 +333,7 @@ void slow_hash_allocate_state(void) if(hp_state != NULL) return; -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) SetLockPagesPrivilege(GetCurrentProcess(), TRUE); hp_state = (uint8_t *) VirtualAlloc(hp_state, MEMORY, MEM_LARGE_PAGES | MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE); @@ -365,7 +365,7 @@ void slow_hash_free_state(void) free(hp_state); else { -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) VirtualFree(hp_state, MEMORY, MEM_RELEASE); #else munmap(hp_state, MEMORY); -- cgit v1.2.3 From 45bc24d69b2e790d5707215f654f6d4c63146984 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 13:09:31 -0400 Subject: Another preprocessor fix (difficulty.cpp) --- src/cryptonote_core/difficulty.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/cryptonote_core/difficulty.cpp b/src/cryptonote_core/difficulty.cpp index c26f8d909..d4d733e69 100644 --- a/src/cryptonote_core/difficulty.cpp +++ b/src/cryptonote_core/difficulty.cpp @@ -45,7 +45,7 @@ namespace cryptonote { using std::uint64_t; using std::vector; -#if defined(_MSC_VER) +#if defined(_MSC_VER) || defined(__MINGW32__) #include #include -- cgit v1.2.3 From f64a68e7cc8ae1587b0f34ac305f5222fe87351d Mon Sep 17 00:00:00 2001 From: Zachary Michaels <> Date: Wed, 6 Aug 2014 19:41:38 -0400 Subject: Force CMake to link the runtime statically --- src/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9673e36e3..28bffea1b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -73,4 +73,8 @@ add_dependencies(simplewallet version) set_property(TARGET common crypto cryptonote_core rpc wallet PROPERTY FOLDER "libs") set_property(TARGET daemon simplewallet connectivity_tool simpleminer PROPERTY FOLDER "prog") +if (STATIC) + set_property(TARGET daemon simplewallet connectivity_tool simpleminer PROPERTY LINK_SEARCH_START_STATIC 1) + set_property(TARGET daemon simplewallet connectivity_tool simpleminer PROPERTY LINK_SEARCH_END_STATIC 1) +endif() set_property(TARGET daemon PROPERTY OUTPUT_NAME "bitmonerod") -- cgit v1.2.3 From 9db881864db916310c11270c1939db700689c9a3 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 20 Aug 2014 11:57:29 -0400 Subject: Fix time_t serialization issue On 32-bit MinGW-w64, time_t is int32_t. The existing code was serializing time_t directly and implicitly assuming that time_t is int64_t. This commit formalizes that assumption by serializing int64_t directly and casting to time_t where appropriate. Thanks go to greatwolf for reporting this issue. monero-project/bitmonero#88 --- src/p2p/net_node.inl | 8 ++++++-- src/p2p/net_peerlist.h | 4 ++-- src/p2p/p2p_protocol_defs.h | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 870e7572e..954d794b7 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -624,7 +624,9 @@ namespace nodetool peerlist_entry pe_local = AUTO_VAL_INIT(pe_local); pe_local.adr = na; pe_local.id = pi; - time(&pe_local.last_seen); + time_t last_seen; + time(&last_seen); + pe_local.last_seen = static_cast(last_seen); m_peerlist.append_with_peer_white(pe_local); //update last seen and push it to peerlist manager @@ -1102,7 +1104,9 @@ namespace nodetool peerlist_entry pe; pe.adr.ip = context.m_remote_ip; pe.adr.port = port_l; - time(&pe.last_seen); + time_t last_seen; + time(&last_seen); + pe.last_seen = static_cast(last_seen); pe.id = peer_id_l; this->m_peerlist.append_with_peer_white(pe); LOG_PRINT_CCONTEXT_L2("PING SUCCESS " << epee::string_tools::get_ip_string_from_int32(context.m_remote_ip) << ":" << port_l); diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h index b02326905..e3e387bbc 100644 --- a/src/p2p/net_peerlist.h +++ b/src/p2p/net_peerlist.h @@ -128,7 +128,7 @@ namespace nodetool // access by peerlist_entry::net_adress boost::multi_index::ordered_unique, boost::multi_index::member >, // sort by peerlist_entry::last_seen< - boost::multi_index::ordered_non_unique, boost::multi_index::member > + boost::multi_index::ordered_non_unique, boost::multi_index::member > > > peers_indexed; @@ -140,7 +140,7 @@ namespace nodetool // access by peerlist_entry::net_adress boost::multi_index::ordered_unique, boost::multi_index::member >, // sort by peerlist_entry::last_seen< - boost::multi_index::ordered_non_unique, boost::multi_index::member > + boost::multi_index::ordered_non_unique, boost::multi_index::member > > > peers_indexed_old; public: diff --git a/src/p2p/p2p_protocol_defs.h b/src/p2p/p2p_protocol_defs.h index a14d00dcd..44b8c5b50 100644 --- a/src/p2p/p2p_protocol_defs.h +++ b/src/p2p/p2p_protocol_defs.h @@ -53,7 +53,7 @@ namespace nodetool { net_address adr; peerid_type id; - time_t last_seen; + int64_t last_seen; }; struct connection_entry -- cgit v1.2.3 From 070ff889d2dc757ca909cf545639a3cbe1e0bc7f Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Mon, 15 Sep 2014 23:01:50 +0200 Subject: More robust versioning in CMake, plus comments --- src/version.cmake | 75 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/version.cmake b/src/version.cmake index e851cdf01..0d1e52a25 100644 --- a/src/version.cmake +++ b/src/version.cmake @@ -1,30 +1,79 @@ +# Copyright (c) 2014, The Monero Project +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are +# permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other +# materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be +# used to endorse or promote products derived from this software without specific +# prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers + +# Check what commit we're on execute_process(COMMAND "${GIT}" rev-parse --short HEAD RESULT_VARIABLE RET OUTPUT_VARIABLE COMMIT OUTPUT_STRIP_TRAILING_WHITESPACE) if(RET) + # Something went wrong, set the version tag to -unknown + message(WARNING "Cannot determine current commit. Make sure that you are building either from a Git working tree or from a source archive.") set(VERSIONTAG "unknown") configure_file("src/version.h.in" "${TO}") else() message(STATUS "You are currently on commit ${COMMIT}") + + # Get all the tags execute_process(COMMAND "${GIT}" show-ref --tags -d --abbrev RESULT_VARIABLE RET OUTPUT_VARIABLE TAGGEDCOMMITOUT OUTPUT_STRIP_TRAILING_WHITESPACE) - string(REPLACE " refs/" "\n" TAGGEDCOMMITOUT2 ${TAGGEDCOMMITOUT}) - string(REPLACE "\n" ";" TAGGEDCOMMITLIST ${TAGGEDCOMMITOUT2}) - list(GET TAGGEDCOMMITLIST -2 TAGGEDCOMMIT) + # Make sure we actually got some tags + string(LENGTH ${TAGGEDCOMMITOUT} TLEN) - if(RET OR NOT TAGGEDCOMMIT) + if(RET OR TLEN LESS 5) message(WARNING "Cannot determine most recent tag. Make sure that you are building either from a Git working tree or from a source archive.") - set(VERSIONTAG "${COMMIT}") + set(VERSIONTAG "${COMMIT}") else() - message(STATUS "The most recent tag was at ${TAGGEDCOMMIT}") - if(${COMMIT} MATCHES ${TAGGEDCOMMIT}) - message(STATUS "You are building a tagged release") - set(VERSIONTAG "release") + # Replace a bunch of things so we end up with a semi-colon separated list + string(REPLACE " refs/" "\n" TAGGEDCOMMITOUT2 ${TAGGEDCOMMITOUT}) + string(REPLACE "\n" ";" TAGGEDCOMMITLIST ${TAGGEDCOMMITOUT2}) + + # Grab the second-last item in the list, as that will be the hash of our most recent commit + list(GET TAGGEDCOMMITLIST -2 TAGGEDCOMMIT) + + if(NOT TAGGEDCOMMIT) + message(WARNING "Cannot determine most recent tag. Make sure that you are building either from a Git working tree or from a source archive.") + set(VERSIONTAG "${COMMIT}") else() - message(STATUS "You are ahead or behind of a tagged release") - set(VERSIONTAG "${COMMIT}") - endif() - endif() + message(STATUS "The most recent tag was at ${TAGGEDCOMMIT}") + + # Check if we're building that tagged commit or a different one + if(${COMMIT} MATCHES ${TAGGEDCOMMIT}) + message(STATUS "You are building a tagged release") + set(VERSIONTAG "release") + else() + message(STATUS "You are ahead or behind of a tagged release") + set(VERSIONTAG "${COMMIT}") + endif() + endif() + + endif() configure_file("src/version.h.in" "${TO}") endif() \ No newline at end of file -- cgit v1.2.3 From de442fb9ad2a42687cd5254d218259327953b4e1 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Mon, 15 Sep 2014 23:04:58 +0200 Subject: Prevent CMake choking on empty vars --- src/version.cmake | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/version.cmake b/src/version.cmake index 0d1e52a25..02f5ec0a6 100644 --- a/src/version.cmake +++ b/src/version.cmake @@ -40,6 +40,8 @@ if(RET) else() message(STATUS "You are currently on commit ${COMMIT}") + # Give our output variable a default value, because CMake likes to choke on empty variables + set(TAGGEDCOMMITOUT "a") # Get all the tags execute_process(COMMAND "${GIT}" show-ref --tags -d --abbrev RESULT_VARIABLE RET OUTPUT_VARIABLE TAGGEDCOMMITOUT OUTPUT_STRIP_TRAILING_WHITESPACE) -- cgit v1.2.3 From ffe7bf8c1cd373b4cd2d256a5f4ea5359a0a35c0 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Mon, 15 Sep 2014 23:07:47 +0200 Subject: another fix for CMake empty vars --- src/version.cmake | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/version.cmake b/src/version.cmake index 02f5ec0a6..2f3aa0b25 100644 --- a/src/version.cmake +++ b/src/version.cmake @@ -40,13 +40,15 @@ if(RET) else() message(STATUS "You are currently on commit ${COMMIT}") - # Give our output variable a default value, because CMake likes to choke on empty variables - set(TAGGEDCOMMITOUT "a") # Get all the tags execute_process(COMMAND "${GIT}" show-ref --tags -d --abbrev RESULT_VARIABLE RET OUTPUT_VARIABLE TAGGEDCOMMITOUT OUTPUT_STRIP_TRAILING_WHITESPACE) # Make sure we actually got some tags - string(LENGTH ${TAGGEDCOMMITOUT} TLEN) + if(TAGGEDCOMMITOUT) + string(LENGTH ${TAGGEDCOMMITOUT} TLEN) + else() + set(TLEN 1) + endif() if(RET OR TLEN LESS 5) message(WARNING "Cannot determine most recent tag. Make sure that you are building either from a Git working tree or from a source archive.") -- cgit v1.2.3 From 59ab569da1fa16d379f519f5480c03e39f05b44d Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 15 Sep 2014 16:28:27 -0400 Subject: Give up on brace initializers in initializer lists (MSVC bug) --- src/daemon/daemon_commands_handler.h | 2 +- src/rpc/core_rpc_server.cpp | 2 +- src/wallet/wallet_errors.h | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/daemon/daemon_commands_handler.h b/src/daemon/daemon_commands_handler.h index 58112e166..869c2adf7 100644 --- a/src/daemon/daemon_commands_handler.h +++ b/src/daemon/daemon_commands_handler.h @@ -55,7 +55,7 @@ public: , bool testnet ) : m_srv(srv) - , m_testnet {testnet} + , m_testnet(testnet) { m_cmd_binder.set_handler("help", boost::bind(&daemon_cmmands_handler::help, this, _1), "Show this help"); m_cmd_binder.set_handler("print_pl", boost::bind(&daemon_cmmands_handler::print_pl, this, _1), "Print peer list"); diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 22e95a1fc..e80451cda 100644 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -79,7 +79,7 @@ namespace cryptonote ) : m_core(cr) , m_p2p(p2p) - , m_testnet {testnet} + , m_testnet(testnet) {} //------------------------------------------------------------------------------------------------------------------------------ bool core_rpc_server::handle_command_line( diff --git a/src/wallet/wallet_errors.h b/src/wallet/wallet_errors.h index 7914ff8e1..ebec931e4 100644 --- a/src/wallet/wallet_errors.h +++ b/src/wallet/wallet_errors.h @@ -383,11 +383,11 @@ namespace tools , uint64_t unlock_time , bool testnet ) - : transfer_error {std::move(loc), "transaction was not constructed"} - , m_sources {sources} - , m_destinations {destinations} - , m_unlock_time {unlock_time} - , m_testnet {testnet} + : transfer_error(std::move(loc), "transaction was not constructed") + , m_sources(sources) + , m_destinations(destinations) + , m_unlock_time(unlock_time) + , m_testnet(testnet) { } @@ -471,10 +471,10 @@ namespace tools , uint64_t fee , bool testnet ) - : transfer_error {std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits::max())} - , m_destinations {destinations} - , m_fee {fee} - , m_testnet {testnet} + : transfer_error(std::move(loc), "transaction sum + fee exceeds " + cryptonote::print_money(std::numeric_limits::max())) + , m_destinations(destinations) + , m_fee(fee) + , m_testnet(testnet) { } -- cgit v1.2.3 From 1ae6db25e6c11cc22d308b96b6c50b225b91c5c7 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 14:55:28 -0400 Subject: Initial commit of DNS code --- src/common/dns_utils.cpp | 55 +++++++++++++++++++++++++++++++ src/common/dns_utils.h | 86 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 src/common/dns_utils.cpp create mode 100644 src/common/dns_utils.h (limited to 'src') diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp new file mode 100644 index 000000000..0bacc4d46 --- /dev/null +++ b/src/common/dns_utils.cpp @@ -0,0 +1,55 @@ +// Copyright (c) 2014, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include "common/dns_utils.h" + +namespace tools +{ +namespace dns +{ + + std::vector get_ipv4(const std::string& uri) + { + std::vector get_ipv6(const std::string& uri) + { + std::vector +#include + +namespace tools +{ + +/** + * @brief Provides high-level access to DNS resolution + * + * This class is designed to provide a high-level abstraction to DNS resolution + * functionality, including access to TXT records and such. It will also + * handle DNSSEC validation of the results. + */ +class DNSResolver +{ +public: + + /** + * @brief Constructs and sets the URI to be resolved + * + * @param uri the URI to be resolved + */ + DNSResolver(const std::string& uri); + + /** + * @brief gets ipv4 addresses from DNS query + * + * returns a vector of all IPv4 "A" records for given URI. + * If no "A" records found, returns an empty vector. + * + * @return vector of strings containing ipv4 addresses + */ + std::vector get_ipv4(); + + /** + * @brief gets ipv6 addresses from DNS query + * + * returns a vector of all IPv6 "A" records for given URI. + * If no "A" records found, returns an empty vector. + * + * @return vector of strings containing ipv6 addresses + */ + std::vector get_ipv6(); + + /** + * @brief gets a monero address from the TXT record of the DNS query response + * + * returns a monero address string from the TXT record associated with URI + * if no TXT record present, or no valid monero address in TXT, + * returns an empty string. + * + * @return + */ + std::string get_payment_address(); + +}; // class DNSResolver + +} // namespace tools -- cgit v1.2.3 From dea98df6b1ae9a3f5b062f9d0be61e1fc1313b28 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 15:17:31 -0400 Subject: Updated CMake files -- added libunbound linker flag CMake config file written, but was unable to test/get it working properly because of a bug in CMake with functions related to find_package. Simple "-lunbound" flag used in its stead for now. May not build on non-Linux systems, not sure yet. --- CMake/FindUnbound.cmake | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ CMakeLists.txt | 5 +++++ src/CMakeLists.txt | 8 +++---- tests/CMakeLists.txt | 14 ++++++------- 4 files changed, 71 insertions(+), 11 deletions(-) create mode 100644 CMake/FindUnbound.cmake (limited to 'src') diff --git a/CMake/FindUnbound.cmake b/CMake/FindUnbound.cmake new file mode 100644 index 000000000..3d2e8f6d7 --- /dev/null +++ b/CMake/FindUnbound.cmake @@ -0,0 +1,55 @@ +# Copyright (c) 2014, The Monero Project +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, are +# permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this list of +# conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, this list +# of conditions and the following disclaimer in the documentation and/or other +# materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors may be +# used to endorse or promote products derived from this software without specific +# prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +include (CheckIncludeFiles) +include (CheckLibraryExists) +include (CheckSymbolExists) + +set (Unbound_FOUND FALSE) +MESSAGE("Attempting to find libunbound") + +#FIND_PATH("unbound.h" CMAKE_HAVE_UNBOUND_H) +MESSAGE("CMAKE_INCLUDE_PATH: ${CMAKE_INCLUDE_PATH}") +MESSAGE("CMAKE_SYSTEM_INCLUDE_PATH: ${CMAKE_SYSTEM_INCLUDE_PATH}") +CHECK_INCLUDE_FILES("unbound.h" CMAKE_HAVE_UNBOUND_H) +MESSAGE("CMAKE_HAVE_UNBOUND_H: ${CMAKE_HAVE_UNBOUND_H}") + +if(CMAKE_HAVE_UNBOUND_H) + + MESSAGE("unbound.h found") + + CHECK_LIBRARY_EXISTS(unbound ub_ctx_create "" CMAKE_HAVE_UNBOUND) + + if(CMAKE_HAVE_UNBOUND) + MESSAGE("-lunbound works?") + set(CMAKE_UNBOUND_LIB "-lunbound") + set(Unbound_FOUND TRUE) + endif() +endif() + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(Unbound DEFAULT_MSG Unbound_FOUND) diff --git a/CMakeLists.txt b/CMakeLists.txt index 875674733..6a2c66bc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,6 +197,11 @@ else() add_custom_target(version ALL) endif() +# CMake bug making this not work. +#find_package(Unbound REQUIRED) +# Won't make sure this works, because that's broken. +set(CMAKE_UNBOUND_LIB "-lunbound") + add_subdirectory(external) # Final setup for miniupnpc diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 28bffea1b..7cef257de 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,13 +60,13 @@ add_library(cryptonote_core ${CRYPTONOTE_CORE}) add_executable(daemon ${DAEMON} ${P2P} ${CRYPTONOTE_PROTOCOL}) add_executable(connectivity_tool ${CONN_TOOL}) add_executable(simpleminer ${MINER}) -target_link_libraries(daemon rpc cryptonote_core crypto common ${UPNP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) -target_link_libraries(connectivity_tool cryptonote_core crypto common ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) -target_link_libraries(simpleminer cryptonote_core crypto common ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +target_link_libraries(daemon rpc cryptonote_core crypto common ${UPNP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) +target_link_libraries(connectivity_tool cryptonote_core crypto common ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) +target_link_libraries(simpleminer cryptonote_core crypto common ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) add_library(rpc ${RPC}) add_library(wallet ${WALLET}) add_executable(simplewallet ${SIMPLEWALLET} ) -target_link_libraries(simplewallet wallet rpc cryptonote_core crypto common ${UPNP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +target_link_libraries(simplewallet wallet rpc cryptonote_core crypto common ${UPNP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) add_dependencies(daemon version) add_dependencies(rpc version) add_dependencies(simplewallet version) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8bc68d9b6..1c0bff676 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -61,16 +61,16 @@ add_executable(unit_tests ${UNIT_TESTS}) add_executable(net_load_tests_clt net_load_tests/clt.cpp) add_executable(net_load_tests_srv net_load_tests/srv.cpp) -target_link_libraries(core_proxy cryptonote_core common crypto ${UPNP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) -target_link_libraries(coretests cryptonote_core common crypto ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +target_link_libraries(core_proxy cryptonote_core common crypto ${UPNP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) +target_link_libraries(coretests cryptonote_core common crypto ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) target_link_libraries(difficulty-tests cryptonote_core) -target_link_libraries(functional_tests cryptonote_core wallet common crypto ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +target_link_libraries(functional_tests cryptonote_core wallet common crypto ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) target_link_libraries(hash-tests crypto) target_link_libraries(hash-target-tests crypto cryptonote_core) -target_link_libraries(performance_tests cryptonote_core common crypto ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) -target_link_libraries(unit_tests cryptonote_core common crypto gtest_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) -target_link_libraries(net_load_tests_clt cryptonote_core common crypto gtest_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) -target_link_libraries(net_load_tests_srv cryptonote_core common crypto gtest_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +target_link_libraries(performance_tests cryptonote_core common crypto ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) +target_link_libraries(unit_tests gtest_main cryptonote_core wallet crypto common ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) +target_link_libraries(net_load_tests_clt cryptonote_core common crypto gtest_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) +target_link_libraries(net_load_tests_srv cryptonote_core common crypto gtest_main ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) if(NOT MSVC) set_property(TARGET gtest gtest_main unit_tests net_load_tests_clt net_load_tests_srv APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-undef -Wno-sign-compare") -- cgit v1.2.3 From 578050e91d8fad8834a7c180a15824f5a46940f9 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 15:35:52 -0400 Subject: ipv4 and ipv6 resolution working IPv4 and IPv6 name resolution working. Unit tests written (and passing). net_node.{h,inl} code modified to use DNS seeds. --- src/common/dns_utils.cpp | 103 ++++++++++++++++++++++++++++++++++---- src/common/dns_utils.h | 43 ++++++++++++---- src/p2p/net_node.h | 7 +++ src/p2p/net_node.inl | 38 ++++++++++---- tests/unit_tests/dns_resolver.cpp | 65 ++++++++++++++++++++++++ 5 files changed, 224 insertions(+), 32 deletions(-) create mode 100644 tests/unit_tests/dns_resolver.cpp (limited to 'src') diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index 0bacc4d46..f95a8d72b 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -27,29 +27,110 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "common/dns_utils.h" +#include // for RR type and class defs +#include +#include // for inet_ntoa (bytes to text for IPs) namespace tools { -namespace dns + +struct DNSResolverData +{ + ub_ctx* m_ub_context; +}; + +DNSResolver::DNSResolver() : m_data(new DNSResolverData()) { + // init libunbound context + m_data->m_ub_context = ub_ctx_create(); - std::vector get_ipv4(const std::string& uri) + // look for "/etc/resolv.conf" and "/etc/hosts" or platform equivalent + ub_ctx_resolvconf(m_data->m_ub_context, ""); + ub_ctx_hosts(m_data->m_ub_context, ""); +} + +DNSResolver::~DNSResolver() +{ + if (m_data) { - std::vectorm_ub_context != NULL) + { + ub_ctx_delete(m_data->m_ub_context); + } + delete m_data; } +} - std::vector get_ipv6(const std::string& uri) +std::vector DNSResolver::get_ipv4(const std::string& url) +{ + ub_result* result = NULL; + std::vector retval; + + // call DNS resolver, blocking. if return value not zero, something went wrong + if (!ub_resolve(m_data->m_ub_context, url.c_str(), LDNS_RR_TYPE_A, LDNS_RR_CLASS_IN, &result)) { - std::vectorhavedata) + { + for (int i=0; result->data[i] != NULL; i++) + { + char as_str[INET_ADDRSTRLEN]; + + // convert bytes to string, append if no error + if (inet_ntop(AF_INET, result->data[0], as_str, sizeof(as_str))) + { + retval.push_back(as_str); + } + } + } } - std::string get_payment_address(const std::string& uri) + // cleanup + ub_resolve_free(result); + return retval; +} + +std::vector DNSResolver::get_ipv6(const std::string& url) +{ + ub_result* result = NULL; + std::vector retval; + + // call DNS resolver, blocking. if return value not zero, something went wrong + if (!ub_resolve(m_data->m_ub_context, url.c_str(), LDNS_RR_TYPE_AAAA, LDNS_RR_CLASS_IN, &result)) + { + if (result->havedata) + { + for (int i=0; result->data[i] != NULL; i++) + { + char as_str[INET6_ADDRSTRLEN]; + + // convert bytes to string, append if no error + if (inet_ntop(AF_INET6, result->data[0], as_str, sizeof(as_str))) + { + retval.push_back(as_str); + } + } + } + } + + // cleanup + ub_resolve_free(result); + return retval; +} + +std::string DNSResolver::get_payment_address(const std::string& url) +{ + std::string retval; + return retval; +} + +DNSResolver& DNSResolver::instance() +{ + static DNSResolver* staticInstance = NULL; + if (staticInstance == NULL) { - std::string retval; - return retval; + staticInstance = new DNSResolver(); } + return *staticInstance; +} -} // namespace dns } // namespace tools diff --git a/src/common/dns_utils.h b/src/common/dns_utils.h index 2919100df..6697d8fff 100644 --- a/src/common/dns_utils.h +++ b/src/common/dns_utils.h @@ -32,6 +32,8 @@ namespace tools { +struct DNSResolverData; + /** * @brief Provides high-level access to DNS resolution * @@ -44,43 +46,64 @@ class DNSResolver public: /** - * @brief Constructs and sets the URI to be resolved + * @brief Constructs an instance of DNSResolver * - * @param uri the URI to be resolved + * Constructs a class instance and does setup stuff for the backend resolver. + */ + DNSResolver(); + + /** + * @brief takes care of freeing C pointers and such */ - DNSResolver(const std::string& uri); + ~DNSResolver(); /** - * @brief gets ipv4 addresses from DNS query + * @brief gets ipv4 addresses from DNS query of a URL * - * returns a vector of all IPv4 "A" records for given URI. + * returns a vector of all IPv4 "A" records for given URL. * If no "A" records found, returns an empty vector. * + * @param url A string containing a URL to query for + * * @return vector of strings containing ipv4 addresses */ - std::vector get_ipv4(); + std::vector get_ipv4(const std::string& url); /** * @brief gets ipv6 addresses from DNS query * - * returns a vector of all IPv6 "A" records for given URI. + * returns a vector of all IPv6 "A" records for given URL. * If no "A" records found, returns an empty vector. * + * @param url A string containing a URL to query for + * * @return vector of strings containing ipv6 addresses */ - std::vector get_ipv6(); + std::vector get_ipv6(const std::string& url); /** * @brief gets a monero address from the TXT record of the DNS query response * - * returns a monero address string from the TXT record associated with URI + * returns a monero address string from the TXT record associated with URL * if no TXT record present, or no valid monero address in TXT, * returns an empty string. * + * @param url A string containing a URL to query for + * * @return */ - std::string get_payment_address(); + std::string get_payment_address(const std::string& url); + + /** + * @brief Gets the singleton instance of DNSResolver + * + * @return returns a pointer to the singleton + */ + static DNSResolver& instance(); + +private: + DNSResolverData *m_data; }; // class DNSResolver } // namespace tools diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h index 759b21fcf..53a13f327 100644 --- a/src/p2p/net_node.h +++ b/src/p2p/net_node.h @@ -112,6 +112,13 @@ namespace nodetool size_t get_outgoing_connections_count(); peerlist_manager& get_peerlist_manager(){return m_peerlist;} private: + const std::vector m_seed_nodes_list = + { "seeds.moneroseeds.se" + , "seeds.moneroseeds.ae.org" + , "seeds.moneroseeds.ch" + , "seeds.moneroseeds.li" + }; + typedef COMMAND_REQUEST_STAT_INFO_T COMMAND_REQUEST_STAT_INFO; CHAIN_LEVIN_INVOKE_MAP2(p2p_connection_context); //move levin_commands_handler interface invoke(...) callbacks into invoke map diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 954d794b7..60bc870e7 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -245,17 +245,33 @@ namespace nodetool } else { - add_hardcoded_seed_node(m_seed_nodes, "62.210.78.186:18080"); - add_hardcoded_seed_node(m_seed_nodes, "195.12.60.154:18080"); - add_hardcoded_seed_node(m_seed_nodes, "54.241.246.125:18080"); - add_hardcoded_seed_node(m_seed_nodes, "107.170.157.169:18080"); - add_hardcoded_seed_node(m_seed_nodes, "54.207.112.216:18080"); - add_hardcoded_seed_node(m_seed_nodes, "78.27.112.54:18080"); - add_hardcoded_seed_node(m_seed_nodes, "209.222.30.57:18080"); - add_hardcoded_seed_node(m_seed_nodes, "80.71.13.55:18080"); - add_hardcoded_seed_node(m_seed_nodes, "107.178.112.126:18080"); - add_hardcoded_seed_node(m_seed_nodes, "107.158.233.98:18080"); - add_hardcoded_seed_node(m_seed_nodes, "64.22.111.2:18080"); + // for each hostname in the seed nodes list, attempt to DNS resolve and + // add the result addresses as seed nodes + // TODO: at some point add IPv6 support, but that won't be relevant + // for some time yet. + for (const std::string& addr_str : m_seed_nodes_list) + { + std::vector addr_list = tools::DNSResolver::instance().get_ipv4(addr_str); + for (const std::string& a : addr_list) + { + append_net_address(m_seed_nodes, a + ":18080"); + } + } + + if (!m_seed_nodes.size()) + { + add_hardcoded_seed_node(m_seed_nodes, "62.210.78.186:18080"); + add_hardcoded_seed_node(m_seed_nodes, "195.12.60.154:18080"); + add_hardcoded_seed_node(m_seed_nodes, "54.241.246.125:18080"); + add_hardcoded_seed_node(m_seed_nodes, "107.170.157.169:18080"); + add_hardcoded_seed_node(m_seed_nodes, "54.207.112.216:18080"); + add_hardcoded_seed_node(m_seed_nodes, "78.27.112.54:18080"); + add_hardcoded_seed_node(m_seed_nodes, "209.222.30.57:18080"); + add_hardcoded_seed_node(m_seed_nodes, "80.71.13.55:18080"); + add_hardcoded_seed_node(m_seed_nodes, "107.178.112.126:18080"); + add_hardcoded_seed_node(m_seed_nodes, "107.158.233.98:18080"); + add_hardcoded_seed_node(m_seed_nodes, "64.22.111.2:18080"); + } } bool res = handle_command_line(vm, testnet); diff --git a/tests/unit_tests/dns_resolver.cpp b/tests/unit_tests/dns_resolver.cpp new file mode 100644 index 000000000..fe8fe602b --- /dev/null +++ b/tests/unit_tests/dns_resolver.cpp @@ -0,0 +1,65 @@ +#include "gtest/gtest.h" + +#include "common/dns_utils.h" + +TEST(DNSResolver, IPv4Success) +{ + tools::DNSResolver resolver; + + auto ips = resolver.get_ipv4("example.com"); + + ASSERT_EQ(1, ips.size()); + + ASSERT_STREQ("93.184.216.119", ips[0].c_str()); + + ips = tools::DNSResolver::instance().get_ipv4("example.com"); + + ASSERT_EQ(1, ips.size()); + + ASSERT_STREQ("93.184.216.119", ips[0].c_str()); +} + +TEST(DNSResolver, IPv4Failure) +{ + // guaranteed by IANA/ICANN/RFC to be invalid + tools::DNSResolver resolver; + + auto ips = resolver.get_ipv4("example.invalid"); + + ASSERT_EQ(0, ips.size()); + + ips = tools::DNSResolver::instance().get_ipv4("example.invalid"); + + ASSERT_EQ(0, ips.size()); +} + +TEST(DNSResolver, IPv6Success) +{ + tools::DNSResolver resolver; + + auto ips = resolver.get_ipv6("example.com"); + + ASSERT_EQ(1, ips.size()); + + ASSERT_STREQ("2606:2800:220:6d:26bf:1447:1097:aa7", ips[0].c_str()); + + ips = tools::DNSResolver::instance().get_ipv6("example.com"); + + ASSERT_EQ(1, ips.size()); + + ASSERT_STREQ("2606:2800:220:6d:26bf:1447:1097:aa7", ips[0].c_str()); +} + +TEST(DNSResolver, IPv6Failure) +{ + // guaranteed by IANA/ICANN/RFC to be invalid + tools::DNSResolver resolver; + + auto ips = resolver.get_ipv6("example.invalid"); + + ASSERT_EQ(0, ips.size()); + + ips = tools::DNSResolver::instance().get_ipv6("example.invalid"); + + ASSERT_EQ(0, ips.size()); +} -- cgit v1.2.3 From 9a3b18dbc25632b801611f5030707fff5c6b098d Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 15:38:15 -0400 Subject: Use the loop iterator, previous version of me. --- src/common/dns_utils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index f95a8d72b..e3be79371 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -76,7 +76,7 @@ std::vector DNSResolver::get_ipv4(const std::string& url) char as_str[INET_ADDRSTRLEN]; // convert bytes to string, append if no error - if (inet_ntop(AF_INET, result->data[0], as_str, sizeof(as_str))) + if (inet_ntop(AF_INET, result->data[i], as_str, sizeof(as_str))) { retval.push_back(as_str); } @@ -104,7 +104,7 @@ std::vector DNSResolver::get_ipv6(const std::string& url) char as_str[INET6_ADDRSTRLEN]; // convert bytes to string, append if no error - if (inet_ntop(AF_INET6, result->data[0], as_str, sizeof(as_str))) + if (inet_ntop(AF_INET6, result->data[i], as_str, sizeof(as_str))) { retval.push_back(as_str); } -- cgit v1.2.3 From 3fb0fc020f4af5038ce4b2d99578aecb625cda6a Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 17:25:19 -0400 Subject: seed node DNS code updated to use DNSResolver Also implemented rudimentary IPv6 support, but commented it out because it's not widely supported by ISPs for now, and thus is not currently supported by Monero. --- src/p2p/net_node.inl | 152 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 111 insertions(+), 41 deletions(-) (limited to 'src') diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 60bc870e7..34895a292 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -31,10 +31,13 @@ #pragma once #include +#include +#include #include "version.h" #include "string_tools.h" #include "common/util.h" +#include "common/dns_utils.h" #include "net/net_helper.h" #include "math_helper.h" #include "p2p_protocol_defs.h" @@ -195,41 +198,108 @@ namespace nodetool return true; } //----------------------------------------------------------------------------------- - inline void add_hardcoded_seed_node( - std::vector & seed_nodes - , std::string const & addr - ) + namespace { - using namespace boost::asio; - - size_t pos = addr.find_last_of(':'); - CHECK_AND_ASSERT_MES_NO_RET(std::string::npos != pos && addr.length() - 1 != pos && 0 != pos, "Failed to parse seed address from string: '" << addr << '\''); - std::string host = addr.substr(0, pos); - std::string port = addr.substr(pos + 1); - - io_service io_srv; - ip::tcp::resolver resolver(io_srv); - ip::tcp::resolver::query query(host, port); - boost::system::error_code ec; - ip::tcp::resolver::iterator i = resolver.resolve(query, ec); - CHECK_AND_ASSERT_MES_NO_RET(!ec, "Failed to resolve host name '" << host << "': " << ec.message() << ':' << ec.value()); - - ip::tcp::resolver::iterator iend; - for (; i != iend; ++i) + template + bool append_net_address(T& nodes, const std::string& addr) { - ip::tcp::endpoint endpoint = *i; - if (endpoint.address().is_v4()) + in_addr_t bytes; + // in6_addr_t bytes6; // for IPv6 support, eventually + + size_t pos = addr.find_last_of(':'); + CHECK_AND_ASSERT_MES(std::string::npos != pos && addr.length() - 1 != pos && 0 != pos, false, "Failed to parse seed address from string: '" << addr << '\''); + std::string host = addr.substr(0, pos); + std::string port = addr.substr(pos + 1); + + // attempt to get port number from string + std::stringstream parser(port); + uint32_t portNum; + if (parser >> portNum) + { + // make sure port in valid range (could check > 1000, really) + if (portNum < 65536 && portNum > 0) + { + return false; + } + } + else + { + return false; + } + + // attempt to get network-bytes for ipv4 address + if (inet_pton(AF_INET, host.c_str(), &bytes) != 1) + { + // if that fails, maybe it's a hostname, try to resolve + std::vector addr_list = tools::DNSResolver::instance().get_ipv4(host); + + // if hostname DNS resolution fails, return false + if (addr_list.size() == 0) + { + return false; + } + + // add each resultant IP to seeds + for (const std::string& a : addr_list) + { + // could call append_net_address recursively here to avoid code repeat + if (inet_pton(AF_INET, a.c_str(), &bytes) == 1) + { + nodetool::net_address na; + na.ip = bytes; + na.port = portNum; + nodes.push_back(na); + } + } + } + // if conversion was success (passed string was IP address, not hostname), + // add IP to seeds + else { nodetool::net_address na; - na.ip = boost::asio::detail::socket_ops::host_to_network_long(endpoint.address().to_v4().to_ulong()); - na.port = endpoint.port(); - seed_nodes.push_back(na); - LOG_PRINT_L4("Added seed node: " << endpoint.address().to_v4().to_string(ec) << ':' << na.port); + na.ip = bytes; + na.port = portNum; + nodes.push_back(na); + } + +/* same as above, but for ipv6. Use when the time comes. + // attempt to get network-bytes for ipv6 address + if (inet_pton(AF_INET6, host.c_str(), &bytes6) != 1) + { + // if that fails, maybe it's a hostname, try to resolve + std::vector addr_list = tools::DNSResolver::instance().get_ipv6(host); + + // if hostname DNS resolution fails, return false + if (addr_list.size() == 0) + { + return false; + } + + // add each resultant IP to seeds + for (const std::string& a : addr_list) + { + // could call append_net_address recursively here to avoid code repeat + if (inet_pton(AF_INET6, a.c_str(), &bytes6) == 1) + { + nodetool::net_address6 na; + na.ip = bytes6; + na.port = portNum; + nodes.push_back(na); + } + } } + // if conversion was success (passed string was IP address, not hostname), + // add IP to seeds else { - LOG_PRINT_L2("IPv6 doesn't supported, skip '" << host << "' -> " << endpoint.address().to_v6().to_string(ec)); + nodetool::net_address6 na; + na.ip = bytes6; + na.port = portNum; + nodes.push_back(na); } +*/ + + return true; } } @@ -239,9 +309,9 @@ namespace nodetool { if (testnet) { - add_hardcoded_seed_node(m_seed_nodes, "107.152.187.202:28080"); - add_hardcoded_seed_node(m_seed_nodes, "197.242.158.240:28080"); - add_hardcoded_seed_node(m_seed_nodes, "107.152.130.98:28080"); + append_net_address(m_seed_nodes, "107.152.187.202:28080"); + append_net_address(m_seed_nodes, "197.242.158.240:28080"); + append_net_address(m_seed_nodes, "107.152.130.98:28080"); } else { @@ -260,17 +330,17 @@ namespace nodetool if (!m_seed_nodes.size()) { - add_hardcoded_seed_node(m_seed_nodes, "62.210.78.186:18080"); - add_hardcoded_seed_node(m_seed_nodes, "195.12.60.154:18080"); - add_hardcoded_seed_node(m_seed_nodes, "54.241.246.125:18080"); - add_hardcoded_seed_node(m_seed_nodes, "107.170.157.169:18080"); - add_hardcoded_seed_node(m_seed_nodes, "54.207.112.216:18080"); - add_hardcoded_seed_node(m_seed_nodes, "78.27.112.54:18080"); - add_hardcoded_seed_node(m_seed_nodes, "209.222.30.57:18080"); - add_hardcoded_seed_node(m_seed_nodes, "80.71.13.55:18080"); - add_hardcoded_seed_node(m_seed_nodes, "107.178.112.126:18080"); - add_hardcoded_seed_node(m_seed_nodes, "107.158.233.98:18080"); - add_hardcoded_seed_node(m_seed_nodes, "64.22.111.2:18080"); + append_net_address(m_seed_nodes, "62.210.78.186:18080"); + append_net_address(m_seed_nodes, "195.12.60.154:18080"); + append_net_address(m_seed_nodes, "54.241.246.125:18080"); + append_net_address(m_seed_nodes, "107.170.157.169:18080"); + append_net_address(m_seed_nodes, "54.207.112.216:18080"); + append_net_address(m_seed_nodes, "78.27.112.54:18080"); + append_net_address(m_seed_nodes, "209.222.30.57:18080"); + append_net_address(m_seed_nodes, "80.71.13.55:18080"); + append_net_address(m_seed_nodes, "107.178.112.126:18080"); + append_net_address(m_seed_nodes, "107.158.233.98:18080"); + append_net_address(m_seed_nodes, "64.22.111.2:18080"); } } -- cgit v1.2.3 From a5757a628f0da0affae66345a5f3209a44613d56 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 17:26:51 -0400 Subject: Monero addres from DNS TXT record implemented, tests pass Still need to deal with DNSSEC and optional fields in the TXT record. --- src/common/dns_utils.cpp | 57 +++++++++++++------ src/common/dns_utils.h | 12 ++-- src/wallet/wallet2.cpp | 54 ++++++++++++++++++ src/wallet/wallet2.h | 3 + tests/unit_tests/address_from_url.cpp | 102 ++++++++++++++++++++++++++++++++++ tests/unit_tests/dns_resolver.cpp | 39 +++++++++++++ 6 files changed, 243 insertions(+), 24 deletions(-) create mode 100644 tests/unit_tests/address_from_url.cpp (limited to 'src') diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index e3be79371..2ad98ca27 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -34,6 +34,22 @@ namespace tools { +// custom smart pointer. +// TODO: see if std::auto_ptr and the like support custom destructors +class ub_result_ptr +{ +public: + ub_result_ptr() + { + ptr = nullptr; + } + ~ub_result_ptr() + { + ub_resolve_free(ptr); + } + ub_result* ptr; +}; + struct DNSResolverData { ub_ctx* m_ub_context; @@ -63,20 +79,22 @@ DNSResolver::~DNSResolver() std::vector DNSResolver::get_ipv4(const std::string& url) { - ub_result* result = NULL; + // destructor takes care of cleanup + ub_result_ptr result; + std::vector retval; // call DNS resolver, blocking. if return value not zero, something went wrong - if (!ub_resolve(m_data->m_ub_context, url.c_str(), LDNS_RR_TYPE_A, LDNS_RR_CLASS_IN, &result)) + if (!ub_resolve(m_data->m_ub_context, url.c_str(), LDNS_RR_TYPE_A, LDNS_RR_CLASS_IN, &(result.ptr))) { - if (result->havedata) + if (result.ptr->havedata) { - for (int i=0; result->data[i] != NULL; i++) + for (int i=0; result.ptr->data[i] != NULL; i++) { char as_str[INET_ADDRSTRLEN]; // convert bytes to string, append if no error - if (inet_ntop(AF_INET, result->data[i], as_str, sizeof(as_str))) + if (inet_ntop(AF_INET, result.ptr->data[i], as_str, sizeof(as_str))) { retval.push_back(as_str); } @@ -84,27 +102,25 @@ std::vector DNSResolver::get_ipv4(const std::string& url) } } - // cleanup - ub_resolve_free(result); return retval; } std::vector DNSResolver::get_ipv6(const std::string& url) { - ub_result* result = NULL; + ub_result_ptr result; std::vector retval; // call DNS resolver, blocking. if return value not zero, something went wrong - if (!ub_resolve(m_data->m_ub_context, url.c_str(), LDNS_RR_TYPE_AAAA, LDNS_RR_CLASS_IN, &result)) + if (!ub_resolve(m_data->m_ub_context, url.c_str(), LDNS_RR_TYPE_AAAA, LDNS_RR_CLASS_IN, &(result.ptr))) { - if (result->havedata) + if (result.ptr->havedata) { - for (int i=0; result->data[i] != NULL; i++) + for (int i=0; result.ptr->data[i] != NULL; i++) { char as_str[INET6_ADDRSTRLEN]; // convert bytes to string, append if no error - if (inet_ntop(AF_INET6, result->data[i], as_str, sizeof(as_str))) + if (inet_ntop(AF_INET6, result.ptr->data[i], as_str, sizeof(as_str))) { retval.push_back(as_str); } @@ -112,15 +128,22 @@ std::vector DNSResolver::get_ipv6(const std::string& url) } } - // cleanup - ub_resolve_free(result); return retval; } -std::string DNSResolver::get_payment_address(const std::string& url) +std::string DNSResolver::get_txt_record(const std::string& url) { - std::string retval; - return retval; + 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(), LDNS_RR_TYPE_TXT, LDNS_RR_CLASS_IN, &(result.ptr))) + { + if (result.ptr->havedata) + { + return std::string(result.ptr->data[0]); + } + } + return std::string(); } DNSResolver& DNSResolver::instance() diff --git a/src/common/dns_utils.h b/src/common/dns_utils.h index 6697d8fff..ff54c1e07 100644 --- a/src/common/dns_utils.h +++ b/src/common/dns_utils.h @@ -82,17 +82,15 @@ public: std::vector get_ipv6(const std::string& url); /** - * @brief gets a monero address from the TXT record of the DNS query response - * - * returns a monero address string from the TXT record associated with URL - * if no TXT record present, or no valid monero address in TXT, - * returns an empty string. + * @brief gets a TXT record from a DNS query for the supplied URL; + * if no TXT record present returns an empty string. * * @param url A string containing a URL to query for * - * @return + * @return A string containing a TXT record; or an empty string */ - std::string get_payment_address(const std::string& url); + // TODO: modify this to accomodate DNSSEC + std::string get_txt_record(const std::string& url); /** * @brief Gets the singleton instance of DNSResolver diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 9ba6f245a..adc9c1f61 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -47,6 +47,7 @@ using namespace epee; #include "serialization/binary_utils.h" #include "cryptonote_protocol/blobdatatype.h" #include "crypto/electrum-words.h" +#include "common/dns_utils.h" extern "C" { @@ -751,6 +752,7 @@ void wallet2::add_unconfirmed_tx(const cryptonote::transaction& tx, uint64_t cha utd.m_sent_time = time(NULL); utd.m_tx = tx; } + //---------------------------------------------------------------------------------------------------- void wallet2::transfer(const std::vector& dsts, size_t fake_outputs_count, uint64_t unlock_time, uint64_t fee, const std::vector& extra, cryptonote::transaction& tx, pending_tx& ptx) @@ -815,6 +817,58 @@ std::vector> split_amounts( } } // anonymous namespace +/** + * @brief gets a monero address from the TXT record of a DNS entry + * + * gets the monero address from the TXT record of the DNS entry associated + * with . If this lookup fails, or the TXT record does not contain an + * XMR address in the correct format, returns an empty string. + * will be set true or false according to whether or not the DNS query passes + * DNSSEC validation. + * + * @param url the url to look up + * @param dnssec_valid return-by-reference for DNSSEC status of query + * + * @return a monero address (as a string) or an empty string + */ +std::string wallet2::address_from_url(const std::string& url, bool& dnssec_valid) +{ + // TODO: update this correctly once DNSResolver::get_txt_record() supports it. + dnssec_valid = false; + // get txt record + std::string txt = tools::DNSResolver::instance().get_txt_record(url); + + if (txt.size()) + { + return address_from_txt_record(txt); + } + return std::string(); +} + +//---------------------------------------------------------------------------------------------------- +std::string wallet2::address_from_txt_record(const std::string& s) +{ + // make sure the txt record has "oa1:xmr" and find it + auto pos = s.find("oa1:xmr"); + + // search from there to find "recipient_address=" + pos = s.find("recipient_address=", pos); + + pos += 18; // move past "recipient_address=" + + // find the next semicolon + auto pos2 = s.find(";", pos); + if (pos2 != std::string::npos) + { + // length of address == 95, we can at least validate that much here + if (pos2 - pos == 95) + { + return s.substr(pos, 95); + } + } + return std::string(); +} + //---------------------------------------------------------------------------------------------------- // take a pending tx and actually send it to the daemon void wallet2::commit_tx(pending_tx& ptx) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 3311e3438..6e6d7cafb 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -196,6 +196,9 @@ namespace tools static bool parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id); + static std::string address_from_url(const std::string& url, bool& dnssec_valid); + + static std::string address_from_txt_record(const std::string& s); private: bool store_keys(const std::string& keys_file_name, const std::string& password); void load_keys(const std::string& keys_file_name, const std::string& password); diff --git a/tests/unit_tests/address_from_url.cpp b/tests/unit_tests/address_from_url.cpp new file mode 100644 index 000000000..180257189 --- /dev/null +++ b/tests/unit_tests/address_from_url.cpp @@ -0,0 +1,102 @@ +// Copyright (c) 2014, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// FIXME: move this into a full wallet2 unit test suite, if possible + +#include "gtest/gtest.h" + +#include "wallet/wallet2.h" +#include + +TEST(AddressFromTXT, Success) +{ + std::string addr = "46BeWrHpwXmHDpDEUmZBWZfoQpdc6HaERCNmx1pEYL2rAcuwufPN9rXHHtyUA4QVy66qeFQkn6sfK8aHYjA3jk3o1Bv16em"; + + std::string txtr = "oa1:xmr"; + txtr += " recipient_address="; + txtr += addr; + txtr += ";"; + + std::string res = tools::wallet2::address_from_txt_record(txtr); + + EXPECT_STREQ(addr.c_str(), res.c_str()); + + std::string txtr2 = "foobar"; + + txtr2 += txtr; + + txtr2 += "more foobar"; + + res = tools::wallet2::address_from_txt_record(txtr2); + + EXPECT_STREQ(addr.c_str(), res.c_str()); + + std::string txtr3 = "foobar oa1:xmr tx_description=\"Donation for Monero Development Fund\"; "; + txtr3 += "recipient_address="; + txtr3 += addr; + txtr3 += "; foobar"; + + res = tools::wallet2::address_from_txt_record(txtr3); + + EXPECT_STREQ(addr.c_str(), res.c_str()); +} + +TEST(AddressFromTXT, Failure) +{ + std::string txtr = "oa1:xmr recipient_address=not a real address"; + + std::string res = tools::wallet2::address_from_txt_record(txtr); + + ASSERT_STREQ("", res.c_str()); + + txtr += ";"; + + res = tools::wallet2::address_from_txt_record(txtr); + ASSERT_STREQ("", res.c_str()); +} + +TEST(AddressFromURL, Success) +{ + std::string addr = "46BeWrHpwXmHDpDEUmZBWZfoQpdc6HaERCNmx1pEYL2rAcuwufPN9rXHHtyUA4QVy66qeFQkn6sfK8aHYjA3jk3o1Bv16em"; + + bool dnssec_result = false; + std::string res = tools::wallet2::address_from_url("donate.monero.cc", dnssec_result); + + EXPECT_STREQ(addr.c_str(), res.c_str()); +} + +TEST(AddressFromURL, Failure) +{ + bool dnssec_result = false; + + std::string res = tools::wallet2::address_from_url("example.invalid", dnssec_result); + + ASSERT_FALSE(dnssec_result); + + ASSERT_STREQ("", res.c_str()); +} diff --git a/tests/unit_tests/dns_resolver.cpp b/tests/unit_tests/dns_resolver.cpp index fe8fe602b..3b52a5f40 100644 --- a/tests/unit_tests/dns_resolver.cpp +++ b/tests/unit_tests/dns_resolver.cpp @@ -1,3 +1,33 @@ +// Copyright (c) 2014, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include + #include "gtest/gtest.h" #include "common/dns_utils.h" @@ -63,3 +93,12 @@ TEST(DNSResolver, IPv6Failure) ASSERT_EQ(0, ips.size()); } + +TEST(DNSResolver, GetTXTRecord) +{ + + std::string txt = tools::DNSResolver::instance().get_txt_record("donate.monero.cc"); + std::cout << "TXT record for donate.monero.cc: " << txt << std::endl; + + EXPECT_STRNE("", txt.c_str()); +} -- cgit v1.2.3 From f437cb58bf4556ecd18e570a89036c590ff2c997 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 17:38:15 -0400 Subject: Simplewallet should now resolve urls to addresses Simplewallet should now do a DNS query on an address if it fails to convert the given string to a binary representation of an address (base58->binary). It will prompt the user, telling of what the "url" passed was, what monero address it translated to, and whether or not DNSSEC validation was a success, and ask for a confirmation that these are all acceptable. --- src/simplewallet/simplewallet.cpp | 55 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index fbe7c4730..07b2f7935 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -910,8 +911,58 @@ bool simple_wallet::transfer(const std::vector &args_) cryptonote::tx_destination_entry de; if(!get_account_address_from_str(de.addr, m_wallet->testnet(), local_args[i])) { - fail_msg_writer() << "wrong address: " << local_args[i]; - return true; + // if treating as an address fails, try as url + bool dnssec_ok = false; + std::string addr_from_dns; + std::string url = local_args[i]; + + // attempt to get address from dns query + addr_from_dns = tools::wallet2::address_from_url(url, dnssec_ok); + + // if string not empty, see if it's an address + if (addr_from_dns.size()) + { + if (get_account_address_from_str(de.addr, addr_from_dns)) + { + // if it was an address, prompt user for confirmation. + // inform user of DNSSEC validation status as well. + + std::string dnssec_str; + if (dnssec_ok) + { + dnssec_str = "DNSSEC validation PASSED!"; + } + else + { + dnssec_str = "DNSSEC validation FAILED!"; + } + std::stringstream prompt; + prompt << "For URL: " << url + << "," << dnssec_str + << " Monero Address = " << addr_from_dns + << std::endl + << "Is this OK? (Y/n) " + ; + + // prompt the user for confirmation given the dns query and dnssec status + std::string confirm_dns_ok = command_line::input_line(prompt.str()); + if (confirm_dns_ok != "Y" && confirm_dns_ok != "y" && confirm_dns_ok != "Yes" && confirm_dns_ok != "yes") + { + fail_msg_writer() << "User terminated transfer request, disagreed with dns result from url: " << url; + return true; + } + } + else + { + fail_msg_writer() << "Failed to get a monero address from: " << local_args[i]; + return true; + } + } + else + { + fail_msg_writer() << "wrong address: " << local_args[i]; + return true; + } } bool ok = cryptonote::parse_amount(de.amount, local_args[i + 1]); -- cgit v1.2.3 From c14c7e16839b6cfe32527f2b01a9a1507e3d419e Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 17:38:54 -0400 Subject: change to allow (at least a bit) for multiple TXT records --- src/common/dns_utils.cpp | 15 ++++++++++----- src/common/dns_utils.h | 8 ++++---- src/simplewallet/simplewallet.cpp | 17 ++++++++++------- src/wallet/wallet2.cpp | 21 +++++++++++++++------ src/wallet/wallet2.h | 2 +- tests/unit_tests/address_from_url.cpp | 13 +++++++++---- tests/unit_tests/dns_resolver.cpp | 11 ++++++++--- 7 files changed, 57 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index 2ad98ca27..6755a30b2 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -89,7 +89,7 @@ std::vector DNSResolver::get_ipv4(const std::string& url) { if (result.ptr->havedata) { - for (int i=0; result.ptr->data[i] != NULL; i++) + for (size_t i=0; result.ptr->data[i] != NULL; i++) { char as_str[INET_ADDRSTRLEN]; @@ -115,7 +115,7 @@ std::vector DNSResolver::get_ipv6(const std::string& url) { if (result.ptr->havedata) { - for (int i=0; result.ptr->data[i] != NULL; i++) + for (size_t i=0; result.ptr->data[i] != NULL; i++) { char as_str[INET6_ADDRSTRLEN]; @@ -131,19 +131,24 @@ std::vector DNSResolver::get_ipv6(const std::string& url) return retval; } -std::string DNSResolver::get_txt_record(const std::string& url) +std::vector DNSResolver::get_txt_record(const std::string& url) { ub_result_ptr result; + std::vector records; // call DNS resolver, blocking. if return value not zero, something went wrong if (!ub_resolve(m_data->m_ub_context, url.c_str(), LDNS_RR_TYPE_TXT, LDNS_RR_CLASS_IN, &(result.ptr))) { if (result.ptr->havedata) { - return std::string(result.ptr->data[0]); + for (size_t i=0; result.ptr->data[i] != NULL; i++) + { + records.push_back(result.ptr->data[i]); + } } } - return std::string(); + + return records; } DNSResolver& DNSResolver::instance() diff --git a/src/common/dns_utils.h b/src/common/dns_utils.h index ff54c1e07..e57e55861 100644 --- a/src/common/dns_utils.h +++ b/src/common/dns_utils.h @@ -82,15 +82,15 @@ public: std::vector get_ipv6(const std::string& url); /** - * @brief gets a TXT record from a DNS query for the supplied URL; - * if no TXT record present returns an empty string. + * @brief gets all TXT records from a DNS query for the supplied URL; + * if no TXT record present returns an empty vector. * * @param url A string containing a URL to query for * - * @return A string containing a TXT record; or an empty string + * @return A vector of strings containing a TXT record; or an empty vector */ // TODO: modify this to accomodate DNSSEC - std::string get_txt_record(const std::string& url); + std::vector get_txt_record(const std::string& url); /** * @brief Gets the singleton instance of DNSResolver diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 07b2f7935..e2564236b 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -913,16 +913,15 @@ bool simple_wallet::transfer(const std::vector &args_) { // if treating as an address fails, try as url bool dnssec_ok = false; - std::string addr_from_dns; std::string url = local_args[i]; // attempt to get address from dns query - addr_from_dns = tools::wallet2::address_from_url(url, dnssec_ok); + auto addresses_from_dns = tools::wallet2::addresses_from_url(url, dnssec_ok); - // if string not empty, see if it's an address - if (addr_from_dns.size()) + // for now, move on only if one address found + if (addresses_from_dns.size() == 1) { - if (get_account_address_from_str(de.addr, addr_from_dns)) + if (get_account_address_from_str(de.addr, addresses_from_dns[0])) { // if it was an address, prompt user for confirmation. // inform user of DNSSEC validation status as well. @@ -938,8 +937,8 @@ bool simple_wallet::transfer(const std::vector &args_) } std::stringstream prompt; prompt << "For URL: " << url - << "," << dnssec_str - << " Monero Address = " << addr_from_dns + << "," << dnssec_str << std::endl + << " Monero Address = " << addresses_from_dns[0] << std::endl << "Is this OK? (Y/n) " ; @@ -958,6 +957,10 @@ bool simple_wallet::transfer(const std::vector &args_) return true; } } + else if (addresses_from_dns.size() > 1) + { + tools::fail_msg_writer() << "Multiple Monero addresses found for given URL: " << url << ", this is not yet supported."; + } else { fail_msg_writer() << "wrong address: " << local_args[i]; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index adc9c1f61..3161f3b16 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -831,21 +831,30 @@ std::vector> split_amounts( * * @return a monero address (as a string) or an empty string */ -std::string wallet2::address_from_url(const std::string& url, bool& dnssec_valid) +std::vector wallet2::addresses_from_url(const std::string& url, bool& dnssec_valid) { // TODO: update this correctly once DNSResolver::get_txt_record() supports it. dnssec_valid = false; - // get txt record - std::string txt = tools::DNSResolver::instance().get_txt_record(url); - if (txt.size()) + std::vector addresses; + // get txt records + auto records = tools::DNSResolver::instance().get_txt_record(url); + + // for each txt record, try to find a monero address in it. + for (auto& rec : records) { - return address_from_txt_record(txt); + std::string addr = address_from_txt_record(rec); + if (addr.size()) + { + addresses.push_back(addr); + } } - return std::string(); + + return addresses; } //---------------------------------------------------------------------------------------------------- +// TODO: parse the string in a less stupid way, probably with regex std::string wallet2::address_from_txt_record(const std::string& s) { // make sure the txt record has "oa1:xmr" and find it diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 6e6d7cafb..90918677e 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -196,7 +196,7 @@ namespace tools static bool parse_payment_id(const std::string& payment_id_str, crypto::hash& payment_id); - static std::string address_from_url(const std::string& url, bool& dnssec_valid); + static std::vector addresses_from_url(const std::string& url, bool& dnssec_valid); static std::string address_from_txt_record(const std::string& s); private: diff --git a/tests/unit_tests/address_from_url.cpp b/tests/unit_tests/address_from_url.cpp index 180257189..22301d568 100644 --- a/tests/unit_tests/address_from_url.cpp +++ b/tests/unit_tests/address_from_url.cpp @@ -85,18 +85,23 @@ TEST(AddressFromURL, Success) std::string addr = "46BeWrHpwXmHDpDEUmZBWZfoQpdc6HaERCNmx1pEYL2rAcuwufPN9rXHHtyUA4QVy66qeFQkn6sfK8aHYjA3jk3o1Bv16em"; bool dnssec_result = false; - std::string res = tools::wallet2::address_from_url("donate.monero.cc", dnssec_result); - EXPECT_STREQ(addr.c_str(), res.c_str()); + std::vector addresses = tools::wallet2::addresses_from_url("donate.monero.cc", dnssec_result); + + EXPECT_EQ(1, addresses.size()); + if (addresses.size() == 1) + { + EXPECT_STREQ(addr.c_str(), addresses[0].c_str()); + } } TEST(AddressFromURL, Failure) { bool dnssec_result = false; - std::string res = tools::wallet2::address_from_url("example.invalid", dnssec_result); + std::vector addresses = tools::wallet2::addresses_from_url("example.invalid", dnssec_result); ASSERT_FALSE(dnssec_result); - ASSERT_STREQ("", res.c_str()); + ASSERT_EQ(0, addresses.size()); } diff --git a/tests/unit_tests/dns_resolver.cpp b/tests/unit_tests/dns_resolver.cpp index 3b52a5f40..27e981ef1 100644 --- a/tests/unit_tests/dns_resolver.cpp +++ b/tests/unit_tests/dns_resolver.cpp @@ -27,6 +27,7 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include +#include #include "gtest/gtest.h" @@ -97,8 +98,12 @@ TEST(DNSResolver, IPv6Failure) TEST(DNSResolver, GetTXTRecord) { - std::string txt = tools::DNSResolver::instance().get_txt_record("donate.monero.cc"); - std::cout << "TXT record for donate.monero.cc: " << txt << std::endl; + std::vector records = tools::DNSResolver::instance().get_txt_record("donate.monero.cc"); - EXPECT_STRNE("", txt.c_str()); + EXPECT_NE(0, records.size()); + + for (auto& rec : records) + { + std::cout << "TXT record for donate.monero.cc: " << rec << std::endl; + } } -- cgit v1.2.3 From 24f325a33d149125b7cf5e91615cbc9e5b686a2b Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 18:37:32 -0400 Subject: Fixed artifacts from cherry-picking devel->master --- CMakeLists.txt | 3 ++- src/simplewallet/simplewallet.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f8222a35..c9a794c97 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,8 @@ cmake_minimum_required(VERSION 2.8.6) +set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") + if (NOT DEFINED ENV{DEVELOPER_LOCAL_TOOLS}) message(STATUS "Could not find DEVELOPER_LOCAL_TOOLS in env") set(BOOST_IGNORE_SYSTEM_PATHS_DEFAULT OFF) @@ -44,7 +46,6 @@ endif() message(STATUS "BOOST_IGNORE_SYSTEM_PATHS defaults to ${BOOST_IGNORE_SYSTEM_PATHS_DEFAULT}") option(BOOST_IGNORE_SYSTEM_PATHS "Ignore boost system paths for local boost ins tallation" $BOOST_IGNORE_SYSTEM_PATHS_DEFAULT) - set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(CMAKE_CONFIGURATION_TYPES "Debug;Release") enable_testing() diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index e2564236b..37974088a 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -921,7 +921,7 @@ bool simple_wallet::transfer(const std::vector &args_) // for now, move on only if one address found if (addresses_from_dns.size() == 1) { - if (get_account_address_from_str(de.addr, addresses_from_dns[0])) + if (get_account_address_from_str(de.addr, m_wallet->testnet(), addresses_from_dns[0])) { // if it was an address, prompt user for confirmation. // inform user of DNSSEC validation status as well. @@ -959,7 +959,7 @@ bool simple_wallet::transfer(const std::vector &args_) } else if (addresses_from_dns.size() > 1) { - tools::fail_msg_writer() << "Multiple Monero addresses found for given URL: " << url << ", this is not yet supported."; + fail_msg_writer() << "Multiple Monero addresses found for given URL: " << url << ", this is not yet supported."; } else { -- cgit v1.2.3 From 1dece111cc7a97101f53fb3944385c1249ed6e40 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Thu, 18 Sep 2014 09:07:46 -0400 Subject: Added function to check syntax of URL for DNS lookup For now, simply checks for '.' character, but that will be easy to change in the future if necessary/desired. --- src/common/dns_utils.cpp | 43 +++++++++++++++++++++++++++++++++++-------- src/common/dns_utils.h | 9 +++++++++ 2 files changed, 44 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index 6755a30b2..60f00916c 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -79,11 +79,16 @@ DNSResolver::~DNSResolver() std::vector DNSResolver::get_ipv4(const std::string& url) { + std::vector addresses; + + if (!check_address_syntax(url)) + { + return addresses; + } + // destructor takes care of cleanup ub_result_ptr result; - std::vector retval; - // call DNS resolver, blocking. if return value not zero, something went wrong if (!ub_resolve(m_data->m_ub_context, url.c_str(), LDNS_RR_TYPE_A, LDNS_RR_CLASS_IN, &(result.ptr))) { @@ -96,19 +101,25 @@ std::vector DNSResolver::get_ipv4(const std::string& url) // convert bytes to string, append if no error if (inet_ntop(AF_INET, result.ptr->data[i], as_str, sizeof(as_str))) { - retval.push_back(as_str); + addresses.push_back(as_str); } } } } - return retval; + return addresses; } std::vector DNSResolver::get_ipv6(const std::string& url) { + std::vector addresses; + + if (!check_address_syntax(url)) + { + return addresses; + } + ub_result_ptr result; - std::vector retval; // call DNS resolver, blocking. if return value not zero, something went wrong if (!ub_resolve(m_data->m_ub_context, url.c_str(), LDNS_RR_TYPE_AAAA, LDNS_RR_CLASS_IN, &(result.ptr))) @@ -122,20 +133,26 @@ std::vector DNSResolver::get_ipv6(const std::string& url) // convert bytes to string, append if no error if (inet_ntop(AF_INET6, result.ptr->data[i], as_str, sizeof(as_str))) { - retval.push_back(as_str); + addresses.push_back(as_str); } } } } - return retval; + return addresses; } std::vector DNSResolver::get_txt_record(const std::string& url) { - ub_result_ptr result; std::vector records; + if (!check_address_syntax(url)) + { + return records; + } + + 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(), LDNS_RR_TYPE_TXT, LDNS_RR_CLASS_IN, &(result.ptr))) { @@ -161,4 +178,14 @@ DNSResolver& DNSResolver::instance() return *staticInstance; } +bool DNSResolver::check_address_syntax(const std::string& addr) +{ + // if string doesn't contain a dot, we won't consider it a url for now. + if (addr.find(".") == std::string::npos) + { + return false; + } + return true; +} + } // namespace tools diff --git a/src/common/dns_utils.h b/src/common/dns_utils.h index e57e55861..375f6ba30 100644 --- a/src/common/dns_utils.h +++ b/src/common/dns_utils.h @@ -101,6 +101,15 @@ public: private: + /** + * @brief Checks a string to see if it looks like a URL + * + * @param addr the string to be checked + * + * @return true if it looks enough like a URL, false if not + */ + bool check_address_syntax(const std::string& addr); + DNSResolverData *m_data; }; // class DNSResolver -- cgit v1.2.3 From 1e193d687de908d466d0c24f162befa66ad84e6b Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Tue, 23 Sep 2014 19:27:03 -0400 Subject: temp commit --- src/common/dns_utils.cpp | 57 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index 60f00916c..ab41ea60e 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -27,13 +27,52 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "common/dns_utils.h" +#include #include // for RR type and class defs #include -#include // for inet_ntoa (bytes to text for IPs) namespace tools { +// fuck it, I'm tired of dealing with getnameinfo()/inet_ntop/etc +std::string ipv4_to_string(const char* src) +{ + std::stringstream ss; + unsigned int bytes[4]; + for (int i = 0; i < 4; i++) + { + unsigned char a = src[i]; + bytes[i] = a; + } + ss << bytes[0] << "." + << bytes[1] << "." + << bytes[2] << "." + << bytes[3]; + return ss.str(); +} + +// this obviously will need to change, but is here to reflect the above +// stop-gap measure and to make the tests pass at least... +std::string ipv6_to_string(const char* src) +{ + std::stringstream ss; + unsigned int bytes[8]; + for (int i = 0; i < 8; i++) + { + unsigned char a = src[i]; + bytes[i] = a; + } + ss << bytes[0] << ":" + << bytes[1] << ":" + << bytes[2] << ":" + << bytes[3] << ":" + << bytes[4] << ":" + << bytes[5] << ":" + << bytes[6] << ":" + << bytes[7]; + return ss.str(); +} + // custom smart pointer. // TODO: see if std::auto_ptr and the like support custom destructors class ub_result_ptr @@ -96,13 +135,7 @@ std::vector DNSResolver::get_ipv4(const std::string& url) { for (size_t i=0; result.ptr->data[i] != NULL; i++) { - char as_str[INET_ADDRSTRLEN]; - - // convert bytes to string, append if no error - if (inet_ntop(AF_INET, result.ptr->data[i], as_str, sizeof(as_str))) - { - addresses.push_back(as_str); - } + addresses.push_back(ipv4_to_string(result.ptr->data[i])); } } } @@ -128,13 +161,7 @@ std::vector DNSResolver::get_ipv6(const std::string& url) { for (size_t i=0; result.ptr->data[i] != NULL; i++) { - char as_str[INET6_ADDRSTRLEN]; - - // convert bytes to string, append if no error - if (inet_ntop(AF_INET6, result.ptr->data[i], as_str, sizeof(as_str))) - { - addresses.push_back(as_str); - } + addresses.push_back(ipv6_to_string(result.ptr->data[i])); } } } -- cgit v1.2.3 From d1a7f699c67fc8c5b43b3119d9e577ef97a22c37 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Wed, 24 Sep 2014 14:45:34 +0200 Subject: use boost::asio::ip::address because cross-platform plz --- src/p2p/net_node.inl | 123 +++++++++++---------------------------------------- 1 file changed, 27 insertions(+), 96 deletions(-) (limited to 'src') diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 34895a292..08fd1d1e6 100644 --- a/src/p2p/net_node.inl +++ b/src/p2p/net_node.inl @@ -31,8 +31,6 @@ #pragma once #include -#include -#include #include "version.h" #include "string_tools.h" @@ -198,108 +196,41 @@ namespace nodetool return true; } //----------------------------------------------------------------------------------- - namespace + inline void append_net_address( + std::vector & seed_nodes + , std::string const & addr + ) { - template - bool append_net_address(T& nodes, const std::string& addr) + using namespace boost::asio; + + size_t pos = addr.find_last_of(':'); + CHECK_AND_ASSERT_MES_NO_RET(std::string::npos != pos && addr.length() - 1 != pos && 0 != pos, "Failed to parse seed address from string: '" << addr << '\''); + std::string host = addr.substr(0, pos); + std::string port = addr.substr(pos + 1); + + io_service io_srv; + ip::tcp::resolver resolver(io_srv); + ip::tcp::resolver::query query(host, port); + boost::system::error_code ec; + ip::tcp::resolver::iterator i = resolver.resolve(query, ec); + CHECK_AND_ASSERT_MES_NO_RET(!ec, "Failed to resolve host name '" << host << "': " << ec.message() << ':' << ec.value()); + + ip::tcp::resolver::iterator iend; + for (; i != iend; ++i) { - in_addr_t bytes; - // in6_addr_t bytes6; // for IPv6 support, eventually - - size_t pos = addr.find_last_of(':'); - CHECK_AND_ASSERT_MES(std::string::npos != pos && addr.length() - 1 != pos && 0 != pos, false, "Failed to parse seed address from string: '" << addr << '\''); - std::string host = addr.substr(0, pos); - std::string port = addr.substr(pos + 1); - - // attempt to get port number from string - std::stringstream parser(port); - uint32_t portNum; - if (parser >> portNum) - { - // make sure port in valid range (could check > 1000, really) - if (portNum < 65536 && portNum > 0) - { - return false; - } - } - else - { - return false; - } - - // attempt to get network-bytes for ipv4 address - if (inet_pton(AF_INET, host.c_str(), &bytes) != 1) - { - // if that fails, maybe it's a hostname, try to resolve - std::vector addr_list = tools::DNSResolver::instance().get_ipv4(host); - - // if hostname DNS resolution fails, return false - if (addr_list.size() == 0) - { - return false; - } - - // add each resultant IP to seeds - for (const std::string& a : addr_list) - { - // could call append_net_address recursively here to avoid code repeat - if (inet_pton(AF_INET, a.c_str(), &bytes) == 1) - { - nodetool::net_address na; - na.ip = bytes; - na.port = portNum; - nodes.push_back(na); - } - } - } - // if conversion was success (passed string was IP address, not hostname), - // add IP to seeds - else + ip::tcp::endpoint endpoint = *i; + if (endpoint.address().is_v4()) { nodetool::net_address na; - na.ip = bytes; - na.port = portNum; - nodes.push_back(na); - } - -/* same as above, but for ipv6. Use when the time comes. - // attempt to get network-bytes for ipv6 address - if (inet_pton(AF_INET6, host.c_str(), &bytes6) != 1) - { - // if that fails, maybe it's a hostname, try to resolve - std::vector addr_list = tools::DNSResolver::instance().get_ipv6(host); - - // if hostname DNS resolution fails, return false - if (addr_list.size() == 0) - { - return false; - } - - // add each resultant IP to seeds - for (const std::string& a : addr_list) - { - // could call append_net_address recursively here to avoid code repeat - if (inet_pton(AF_INET6, a.c_str(), &bytes6) == 1) - { - nodetool::net_address6 na; - na.ip = bytes6; - na.port = portNum; - nodes.push_back(na); - } - } + na.ip = boost::asio::detail::socket_ops::host_to_network_long(endpoint.address().to_v4().to_ulong()); + na.port = endpoint.port(); + seed_nodes.push_back(na); + LOG_PRINT_L4("Added seed node: " << endpoint.address().to_v4().to_string(ec) << ':' << na.port); } - // if conversion was success (passed string was IP address, not hostname), - // add IP to seeds else { - nodetool::net_address6 na; - na.ip = bytes6; - na.port = portNum; - nodes.push_back(na); + LOG_PRINT_L2("IPv6 doesn't supported, skip '" << host << "' -> " << endpoint.address().to_v6().to_string(ec)); } -*/ - - return true; } } -- cgit v1.2.3 From bff1f9d4c4c33a12349bc3e861fe4d387b749a74 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Wed, 24 Sep 2014 20:38:24 +0200 Subject: redo FindUnbound.cmake --- CMakeLists.txt | 4 ++++ cmake/FindUnbound.cmake | 54 ++++++++++++++++++++++++------------------------- src/CMakeLists.txt | 8 ++++---- 3 files changed, 34 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/CMakeLists.txt b/CMakeLists.txt index c9a794c97..fcbd64ce4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,7 +85,9 @@ if (UNIX AND NOT APPLE) find_package(Threads) endif() +# Find unbound - don't move this to the end, cmake is weird about this find_package(Unbound REQUIRED) +include_directories(${UNBOUND_INCLUDE}) if(MSVC) add_definitions("/bigobj /MP /W3 /GS- /D_CRT_SECURE_NO_WARNINGS /wd4996 /wd4345 /D_WIN32_WINNT=0x0600 /DWIN32_LEAN_AND_MEAN /DGTEST_HAS_TR1_TUPLE=0 /FIinline_c.h /D__SSE4_1__") @@ -210,5 +212,7 @@ else() include_directories(${UPNP_INCLUDE}) endif() + + add_subdirectory(src) add_subdirectory(tests) diff --git a/cmake/FindUnbound.cmake b/cmake/FindUnbound.cmake index 3d2e8f6d7..8d6f4ae72 100644 --- a/cmake/FindUnbound.cmake +++ b/cmake/FindUnbound.cmake @@ -25,31 +25,29 @@ # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -include (CheckIncludeFiles) -include (CheckLibraryExists) -include (CheckSymbolExists) - -set (Unbound_FOUND FALSE) -MESSAGE("Attempting to find libunbound") - -#FIND_PATH("unbound.h" CMAKE_HAVE_UNBOUND_H) -MESSAGE("CMAKE_INCLUDE_PATH: ${CMAKE_INCLUDE_PATH}") -MESSAGE("CMAKE_SYSTEM_INCLUDE_PATH: ${CMAKE_SYSTEM_INCLUDE_PATH}") -CHECK_INCLUDE_FILES("unbound.h" CMAKE_HAVE_UNBOUND_H) -MESSAGE("CMAKE_HAVE_UNBOUND_H: ${CMAKE_HAVE_UNBOUND_H}") - -if(CMAKE_HAVE_UNBOUND_H) - - MESSAGE("unbound.h found") - - CHECK_LIBRARY_EXISTS(unbound ub_ctx_create "" CMAKE_HAVE_UNBOUND) - - if(CMAKE_HAVE_UNBOUND) - MESSAGE("-lunbound works?") - set(CMAKE_UNBOUND_LIB "-lunbound") - set(Unbound_FOUND TRUE) - endif() -endif() - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(Unbound DEFAULT_MSG Unbound_FOUND) +MESSAGE("Looking for libunbound") + +FIND_PATH(UNBOUND_INCLUDE_DIR + NAMES unbound.h + PATH_SUFFIXES include/ include/unbound/ + PATHS "${PROJECT_SOURCE_DIR}" + ${UNBOUND_ROOT} + $ENV{UNBOUND_ROOT} + /usr/local/ + /usr/ +) + +find_library(UNBOUND_LIBRARIES unbound) + +IF(UNBOUND_INCLUDE_DIR) + MESSAGE(STATUS "Found unbound include in ${UNBOUND_INCLUDE_DIR}") + IF(UNBOUND_LIBRARIES) + MESSAGE(STATUS "Found unbound library") + set(UNBOUND_INCLUDE ${UNBOUND_INCLUDE_DIR}) + set(UNBOUND_LIBRARY ${UNBOUND_LIBRARIES}) + ELSE() + MESSAGE(FATAL_ERROR "Could not find unbound library") + ENDIF() +ELSE() + MESSAGE(FATAL_ERROR "Could not find unbound library") +ENDIF() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7cef257de..e5502cdb9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,13 +60,13 @@ add_library(cryptonote_core ${CRYPTONOTE_CORE}) add_executable(daemon ${DAEMON} ${P2P} ${CRYPTONOTE_PROTOCOL}) add_executable(connectivity_tool ${CONN_TOOL}) add_executable(simpleminer ${MINER}) -target_link_libraries(daemon rpc cryptonote_core crypto common ${UPNP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) -target_link_libraries(connectivity_tool cryptonote_core crypto common ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) -target_link_libraries(simpleminer cryptonote_core crypto common ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) +target_link_libraries(daemon rpc cryptonote_core crypto common ${UNBOUND_LIBRARIES} ${UPNP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +target_link_libraries(connectivity_tool cryptonote_core crypto common ${UNBOUND_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +target_link_libraries(simpleminer cryptonote_core crypto common ${UNBOUND_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) add_library(rpc ${RPC}) add_library(wallet ${WALLET}) add_executable(simplewallet ${SIMPLEWALLET} ) -target_link_libraries(simplewallet wallet rpc cryptonote_core crypto common ${UPNP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) +target_link_libraries(simplewallet wallet rpc cryptonote_core crypto common ${UNBOUND_LIBRARIES} ${UPNP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) add_dependencies(daemon version) add_dependencies(rpc version) add_dependencies(simplewallet version) -- cgit v1.2.3 From 400f1016dd5c978a49cb90898c7a34edf4de5ed2 Mon Sep 17 00:00:00 2001 From: iamsmooth Date: Tue, 23 Sep 2014 12:55:19 +0000 Subject: checkpoints --- src/cryptonote_core/checkpoints_create.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h index 9d65dc243..b5901a860 100644 --- a/src/cryptonote_core/checkpoints_create.h +++ b/src/cryptonote_core/checkpoints_create.h @@ -43,9 +43,11 @@ namespace cryptonote { ADD_CHECKPOINT(50000, "0fe8758ab06a8b9cb35b7328fd4f757af530a5d37759f9d3e421023231f7b31c"); ADD_CHECKPOINT(80000, "a62dcd7b536f22e003ebae8726e9e7276f63d594e264b6f0cd7aab27b66e75e3"); ADD_CHECKPOINT(202612, "bbd604d2ba11ba27935e006ed39c9bfdd99b76bf4a50654bc1e1e61217962698"); - ADD_CHECKPOINT(202613, "e2aa337e78df1f98f462b3b1e560c6b914dec47b610698b7b7d1e3e86b6197c2"); // from chainradar; verify this - ADD_CHECKPOINT(202614, "c29e3dc37d8da3e72e506e31a213a58771b24450144305bcba9e70fa4d6ea6fb"); // from chainradar; verify this - ADD_CHECKPOINT(205000, "5d3d7a26e6dc7535e34f03def711daa8c263785f73ec1fadef8a45880fde8063"); // from chainradar; verify this + ADD_CHECKPOINT(202613, "e2aa337e78df1f98f462b3b1e560c6b914dec47b610698b7b7d1e3e86b6197c2"); + ADD_CHECKPOINT(202614, "c29e3dc37d8da3e72e506e31a213a58771b24450144305bcba9e70fa4d6ea6fb"); + ADD_CHECKPOINT(205000, "5d3d7a26e6dc7535e34f03def711daa8c263785f73ec1fadef8a45880fde8063"); + ADD_CHECKPOINT(220000, "9613f455933c00e3e33ac315cc6b455ee8aa0c567163836858c2d9caff111553"); + ADD_CHECKPOINT(230300, "bae7a80c46859db355556e3a9204a337ae8f24309926a1312323fdecf1920e61"); return true; } } -- cgit v1.2.3 From b1d586af4b6a9c2035c3a33b66ed281266ce8060 Mon Sep 17 00:00:00 2001 From: iamsmooth Date: Tue, 23 Sep 2014 20:41:04 +0000 Subject: checkpoint --- src/cryptonote_core/checkpoints_create.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h index b5901a860..2fc7ab549 100644 --- a/src/cryptonote_core/checkpoints_create.h +++ b/src/cryptonote_core/checkpoints_create.h @@ -48,6 +48,7 @@ namespace cryptonote { ADD_CHECKPOINT(205000, "5d3d7a26e6dc7535e34f03def711daa8c263785f73ec1fadef8a45880fde8063"); ADD_CHECKPOINT(220000, "9613f455933c00e3e33ac315cc6b455ee8aa0c567163836858c2d9caff111553"); ADD_CHECKPOINT(230300, "bae7a80c46859db355556e3a9204a337ae8f24309926a1312323fdecf1920e61"); + ADD_CHECKPOINT(230700, "93e631240ceac831da1aebfc5dac8f722c430463024763ebafa888796ceaeedf"); return true; } } -- cgit v1.2.3 From c428c29051f3837c344b025e220f572b1ffbe86a Mon Sep 17 00:00:00 2001 From: iamsmooth Date: Tue, 23 Sep 2014 21:21:12 +0000 Subject: checkpoints --- src/cryptonote_core/checkpoints_create.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h index 2fc7ab549..314f10caf 100644 --- a/src/cryptonote_core/checkpoints_create.h +++ b/src/cryptonote_core/checkpoints_create.h @@ -38,6 +38,11 @@ namespace cryptonote { inline bool create_checkpoints(cryptonote::checkpoints& checkpoints) { + ADD_CHECKPOINT(1, "771fbcd656ec1464d3a02ead5e18644030007a0fc664c0a964d30922821a8148"); + ADD_CHECKPOINT(10, "c0e3b387e47042f72d8ccdca88071ff96bff1ac7cde09ae113dbb7ad3fe92381"); + ADD_CHECKPOINT(100, "ac3e11ca545e57c49fca2b4e8c48c03c23be047c43e471e1394528b1f9f80b2d"); + ADD_CHECKPOINT(1000, "5acfc45acffd2b2e7345caf42fa02308c5793f15ec33946e969e829f40b03876"); + ADD_CHECKPOINT(10000, "c758b7c81f928be3295d45e230646de8b852ec96a821eac3fea4daf3fcac0ca2"); ADD_CHECKPOINT(22231, "7cb10e29d67e1c069e6e11b17d30b809724255fee2f6868dc14cfc6ed44dfb25"); ADD_CHECKPOINT(29556, "53c484a8ed91e4da621bb2fa88106dbde426fe90d7ef07b9c1e5127fb6f3a7f6"); ADD_CHECKPOINT(50000, "0fe8758ab06a8b9cb35b7328fd4f757af530a5d37759f9d3e421023231f7b31c"); -- cgit v1.2.3 From d19cf1f458ae194bfbbe59add0bb2f5eb5b4fd44 Mon Sep 17 00:00:00 2001 From: iamsmooth Date: Wed, 24 Sep 2014 07:14:39 +0000 Subject: checkpoint --- src/cryptonote_core/checkpoints_create.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h index 314f10caf..c124ed3a5 100644 --- a/src/cryptonote_core/checkpoints_create.h +++ b/src/cryptonote_core/checkpoints_create.h @@ -54,6 +54,8 @@ namespace cryptonote { ADD_CHECKPOINT(220000, "9613f455933c00e3e33ac315cc6b455ee8aa0c567163836858c2d9caff111553"); ADD_CHECKPOINT(230300, "bae7a80c46859db355556e3a9204a337ae8f24309926a1312323fdecf1920e61"); ADD_CHECKPOINT(230700, "93e631240ceac831da1aebfc5dac8f722c430463024763ebafa888796ceaeedf"); + ADD_CHECKPOINT(231350, "b5add137199b820e1ea26640e5c3e121fd85faa86a1e39cf7e6cc097bdeb1131"); + return true; } } -- cgit v1.2.3 From 9956b68b1838874ad8b58d93494f6a982307e216 Mon Sep 17 00:00:00 2001 From: iamsmooth Date: Wed, 24 Sep 2014 21:25:50 +0000 Subject: checkpoint --- src/cryptonote_core/checkpoints_create.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h index c124ed3a5..f75829aba 100644 --- a/src/cryptonote_core/checkpoints_create.h +++ b/src/cryptonote_core/checkpoints_create.h @@ -55,6 +55,7 @@ namespace cryptonote { ADD_CHECKPOINT(230300, "bae7a80c46859db355556e3a9204a337ae8f24309926a1312323fdecf1920e61"); ADD_CHECKPOINT(230700, "93e631240ceac831da1aebfc5dac8f722c430463024763ebafa888796ceaeedf"); ADD_CHECKPOINT(231350, "b5add137199b820e1ea26640e5c3e121fd85faa86a1e39cf7e6cc097bdeb1131"); + ADD_CHECKPOINT(232150, "955de8e6b6508af2c24f7334f97beeea651d78e9ade3ab18fec3763be3201aa8"); return true; } -- cgit v1.2.3 From 06a4578bf253cfde6f0ab352994b3aadf61ec372 Mon Sep 17 00:00:00 2001 From: Tomer Konforty Date: Wed, 24 Sep 2014 17:36:04 +0300 Subject: Added ability to read chechpoint hashes from json file in data folder --- src/cryptonote_core/checkpoints.cpp | 9 ++++++ src/cryptonote_core/checkpoints.h | 1 + src/cryptonote_core/checkpoints_create.h | 50 ++++++++++++++++++++++++++++++++ src/daemon/daemon.cpp | 5 ++++ 4 files changed, 65 insertions(+) (limited to 'src') diff --git a/src/cryptonote_core/checkpoints.cpp b/src/cryptonote_core/checkpoints.cpp index 3669a7217..c76a23841 100644 --- a/src/cryptonote_core/checkpoints.cpp +++ b/src/cryptonote_core/checkpoints.cpp @@ -93,4 +93,13 @@ namespace cryptonote uint64_t checkpoint_height = it->first; return checkpoint_height < block_height; } + uint64_t checkpoints::get_max_height() + { + std::map< uint64_t, crypto::hash >::const_iterator highest = + std::max_element( m_points.begin(), m_points.end(), + ( boost::bind(&std::map< uint64_t, crypto::hash >::value_type::first, _1) < + boost::bind(&std::map< uint64_t, crypto::hash >::value_type::first, _2 ) ) ); + return highest->first; + } + } diff --git a/src/cryptonote_core/checkpoints.h b/src/cryptonote_core/checkpoints.h index 11c4b5eb7..3dee48682 100644 --- a/src/cryptonote_core/checkpoints.h +++ b/src/cryptonote_core/checkpoints.h @@ -44,6 +44,7 @@ namespace cryptonote bool check_block(uint64_t height, const crypto::hash& h) const; bool check_block(uint64_t height, const crypto::hash& h, bool& is_a_checkpoint) const; bool is_alternative_block_allowed(uint64_t blockchain_height, uint64_t block_height) const; + uint64_t get_max_height(); private: std::map m_points; diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h index f75829aba..7512ddd95 100644 --- a/src/cryptonote_core/checkpoints_create.h +++ b/src/cryptonote_core/checkpoints_create.h @@ -34,6 +34,24 @@ #include "misc_log_ex.h" #define ADD_CHECKPOINT(h, hash) CHECK_AND_ASSERT(checkpoints.add_checkpoint(h, hash), false); +#define JSON_HASH_FILE_NAME "checkpoints.json" + +struct t_hashline +{ + uint64_t height; + std::string hash; + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(height) + KV_SERIALIZE(hash) + END_KV_SERIALIZE_MAP() +}; + +struct t_hash_json { + std::vector hashlines; + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(hashlines) + END_KV_SERIALIZE_MAP() +}; namespace cryptonote { inline bool create_checkpoints(cryptonote::checkpoints& checkpoints) @@ -59,4 +77,36 @@ namespace cryptonote { return true; } + + inline bool load_checkpoins_from_json(cryptonote::checkpoints& checkpoints, std::string json_hashfile_fullpath) + { + boost::system::error_code errcode; + if (! (boost::filesystem::exists(json_hashfile_fullpath, errcode))) + { + LOG_PRINT_L0("Blockchain checkpoints file not found"); + return true; + } + + LOG_PRINT_L0("Adding checkpoints from blockchain hashfile"); + + uint64_t prev_max_height = checkpoints.get_max_height(); + LOG_PRINT_L0("Hard-coded max checkpoint height is " << prev_max_height); + t_hash_json hashes; + epee::serialization::load_t_from_json_file(hashes, json_hashfile_fullpath); + for (std::vector::const_iterator it = hashes.hashlines.begin(); it != hashes.hashlines.end(); ) + { + uint64_t height; + height = it->height; + if (height <= prev_max_height) { + LOG_PRINT_L0("ignoring checkpoint height " << height); + } else { + std::string blockhash = it->hash; + LOG_PRINT_L0("Adding checkpoint height " << height << ", hash=" << blockhash); + ADD_CHECKPOINT(height, blockhash); + } + ++it; + } + + return true; + } } diff --git a/src/daemon/daemon.cpp b/src/daemon/daemon.cpp index 5eda6cb69..5c209482e 100644 --- a/src/daemon/daemon.cpp +++ b/src/daemon/daemon.cpp @@ -44,6 +44,7 @@ using namespace epee; #include "p2p/net_node.h" #include "cryptonote_config.h" #include "cryptonote_core/checkpoints_create.h" +#include "cryptonote_core/checkpoints.h" #include "cryptonote_core/cryptonote_core.h" #include "rpc/core_rpc_server.h" #include "cryptonote_protocol/cryptonote_protocol_handler.h" @@ -203,6 +204,10 @@ int main(int argc, char* argv[]) cryptonote::checkpoints checkpoints; res = cryptonote::create_checkpoints(checkpoints); CHECK_AND_ASSERT_MES(res, 1, "Failed to initialize checkpoints"); + boost::filesystem::path json(JSON_HASH_FILE_NAME); + boost::filesystem::path checkpoint_json_hashfile_fullpath = data_dir / json; + res = cryptonote::load_checkpoins_from_json(checkpoints, checkpoint_json_hashfile_fullpath.string().c_str()); + CHECK_AND_ASSERT_MES(res, 1, "Failed to load initial checkpoints"); //create objects and link them cryptonote::core ccore(NULL); -- cgit v1.2.3 From 738357459b355862d35005ab7165b317cc37586d Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 24 Sep 2014 19:55:19 -0400 Subject: libunbound has const correctness issues... --- src/common/dns_utils.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index ab41ea60e..e1151e190 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -27,6 +27,7 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "common/dns_utils.h" +#include #include #include // for RR type and class defs #include @@ -99,9 +100,11 @@ DNSResolver::DNSResolver() : m_data(new DNSResolverData()) // init libunbound context m_data->m_ub_context = ub_ctx_create(); + char empty_string = '\0'; + // look for "/etc/resolv.conf" and "/etc/hosts" or platform equivalent - ub_ctx_resolvconf(m_data->m_ub_context, ""); - ub_ctx_hosts(m_data->m_ub_context, ""); + ub_ctx_resolvconf(m_data->m_ub_context, &empty_string); + ub_ctx_hosts(m_data->m_ub_context, &empty_string); } DNSResolver::~DNSResolver() @@ -119,7 +122,10 @@ DNSResolver::~DNSResolver() std::vector DNSResolver::get_ipv4(const std::string& url) { std::vector addresses; + char urlC[1000]; // waaaay too big, but just in case... + strncpy(urlC, url.c_str(), 999); + urlC[999] = '\0'; if (!check_address_syntax(url)) { return addresses; @@ -129,7 +135,7 @@ std::vector DNSResolver::get_ipv4(const std::string& url) 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(), LDNS_RR_TYPE_A, LDNS_RR_CLASS_IN, &(result.ptr))) + if (!ub_resolve(m_data->m_ub_context, urlC, LDNS_RR_TYPE_A, LDNS_RR_CLASS_IN, &(result.ptr))) { if (result.ptr->havedata) { @@ -146,6 +152,10 @@ std::vector DNSResolver::get_ipv4(const std::string& url) std::vector DNSResolver::get_ipv6(const std::string& url) { std::vector addresses; + char urlC[1000]; // waaaay too big, but just in case... + + strncpy(urlC, url.c_str(), 999); + urlC[999] = '\0'; if (!check_address_syntax(url)) { @@ -155,7 +165,7 @@ std::vector DNSResolver::get_ipv6(const std::string& url) 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(), LDNS_RR_TYPE_AAAA, LDNS_RR_CLASS_IN, &(result.ptr))) + if (!ub_resolve(m_data->m_ub_context, urlC, LDNS_RR_TYPE_AAAA, LDNS_RR_CLASS_IN, &(result.ptr))) { if (result.ptr->havedata) { @@ -172,6 +182,10 @@ std::vector DNSResolver::get_ipv6(const std::string& url) std::vector DNSResolver::get_txt_record(const std::string& url) { std::vector records; + char urlC[1000]; // waaaay too big, but just in case... + + strncpy(urlC, url.c_str(), 999); + urlC[999] = '\0'; if (!check_address_syntax(url)) { @@ -181,7 +195,7 @@ std::vector DNSResolver::get_txt_record(const std::string& url) 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(), LDNS_RR_TYPE_TXT, LDNS_RR_CLASS_IN, &(result.ptr))) + if (!ub_resolve(m_data->m_ub_context, urlC, LDNS_RR_TYPE_TXT, LDNS_RR_CLASS_IN, &(result.ptr))) { if (result.ptr->havedata) { -- cgit v1.2.3 From 4e2b2b942daa4206ec44c66e59863670dfe3fde4 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Wed, 24 Sep 2014 22:28:25 +0200 Subject: low risk, potentially varint overflow bug patched thanks to BBR --- src/common/varint.h | 25 +++++++++++++++++++- src/cryptonote_core/cryptonote_basic.h | 1 - src/cryptonote_core/cryptonote_core.cpp | 8 +++---- src/cryptonote_core/cryptonote_core.h | 2 +- src/cryptonote_core/cryptonote_format_utils.cpp | 17 ++++++++++++++ src/cryptonote_core/cryptonote_format_utils.h | 2 ++ src/cryptonote_core/tx_pool.cpp | 9 ++++--- src/cryptonote_core/tx_pool.h | 4 ++-- tests/unit_tests/serialization.cpp | 31 +++++++++++++++++++++++++ 9 files changed, 85 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/common/varint.h b/src/common/varint.h index 5a73c2746..57386597a 100644 --- a/src/common/varint.h +++ b/src/common/varint.h @@ -36,7 +36,7 @@ #include #include /*! \file varint.h - * \breif provides the implementation of varint's + * \brief provides the implementation of varint's * * The representation of varints is rather odd. The first bit of each * octet is significant, it represents wheter there is another part @@ -52,6 +52,29 @@ namespace tools { + template + size_t get_varint_packed_size(T v) + { + if(v <= 127) + return 1; + else if(v <= 16383) + return 2; + else if(v <= 2097151) + return 3; + else if(v <= 268435455) + return 4; + else if(v <= 34359738367) + return 5; + else if(v <= 4398046511103) + return 6; + else if(v <= 4398046511103) + return 6; + else if(v <= 562949953421311) + return 7; + else + return 8; + } + /*! \brief Error codes for varint */ enum { diff --git a/src/cryptonote_core/cryptonote_basic.h b/src/cryptonote_core/cryptonote_basic.h index dfdfa03e5..fca4e227e 100644 --- a/src/cryptonote_core/cryptonote_basic.h +++ b/src/cryptonote_core/cryptonote_basic.h @@ -226,7 +226,6 @@ namespace cryptonote ar.end_array(); END_SERIALIZE() - private: static size_t get_signature_size(const txin_v& tx_in); }; diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index 964d61e2f..e6aa679d7 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -191,7 +191,7 @@ namespace cryptonote return false; } - bool r = add_new_tx(tx, tx_hash, tx_prefixt_hash, tx_blob.size(), tvc, keeped_by_block); + bool r = add_new_tx(tx, tx_hash, tx_prefixt_hash, tvc, keeped_by_block); if(tvc.m_verifivation_failed) {LOG_PRINT_RED_L1("Transaction verification failed: " << tx_hash);} else if(tvc.m_verifivation_impossible) @@ -284,7 +284,7 @@ namespace cryptonote crypto::hash tx_prefix_hash = get_transaction_prefix_hash(tx); blobdata bl; t_serializable_object_to_blob(tx, bl); - return add_new_tx(tx, tx_hash, tx_prefix_hash, bl.size(), tvc, keeped_by_block); + return add_new_tx(tx, tx_hash, tx_prefix_hash, tvc, keeped_by_block); } //----------------------------------------------------------------------------------------------- size_t core::get_blockchain_total_transactions() @@ -297,7 +297,7 @@ namespace cryptonote // return m_blockchain_storage.get_outs(amount, pkeys); //} //----------------------------------------------------------------------------------------------- - bool core::add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block) + bool core::add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, tx_verification_context& tvc, bool keeped_by_block) { if(m_mempool.have_tx(tx_hash)) { @@ -311,7 +311,7 @@ namespace cryptonote return true; } - return m_mempool.add_tx(tx, tx_hash, blob_size, tvc, keeped_by_block); + return m_mempool.add_tx(tx, tx_hash, tvc, keeped_by_block); } //----------------------------------------------------------------------------------------------- bool core::get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, const blobdata& ex_nonce) diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index ba2aed015..e9ab20114 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -120,7 +120,7 @@ namespace cryptonote uint64_t get_target_blockchain_height() const; private: - bool add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block); + bool add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, tx_verification_context& tvc, bool keeped_by_block); bool add_new_tx(const transaction& tx, tx_verification_context& tvc, bool keeped_by_block); bool add_new_block(const block& b, block_verification_context& bvc); bool load_state_data(); diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index 33cad30c4..e46bd390d 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -742,6 +742,23 @@ namespace cryptonote return true; } //--------------------------------------------------------------- + size_t get_object_blobsize(const transaction& t) + { + size_t prefix_blob = get_object_blobsize(static_cast(t)); + + if(is_coinbase(t)) + return prefix_blob; + + for(const auto& in: t.vin) + { + size_t sig_count = transaction::get_signature_size(in); + prefix_blob += 64*sig_count; + prefix_blob += tools::get_varint_packed_size(sig_count); + } + prefix_blob += tools::get_varint_packed_size(t.vin.size()); + return prefix_blob; + } + //--------------------------------------------------------------- blobdata block_to_blob(const block& b) { return t_serializable_object_to_blob(b); diff --git a/src/cryptonote_core/cryptonote_format_utils.h b/src/cryptonote_core/cryptonote_format_utils.h index 9fa7f0545..58186b8cf 100644 --- a/src/cryptonote_core/cryptonote_format_utils.h +++ b/src/cryptonote_core/cryptonote_format_utils.h @@ -157,6 +157,8 @@ namespace cryptonote return b.size(); } //--------------------------------------------------------------- + size_t get_object_blobsize(const transaction& t); + //--------------------------------------------------------------- template bool get_object_hash(const t_object& o, crypto::hash& res, size_t& blob_size) { diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 81f932014..3764cfe77 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -59,9 +59,9 @@ namespace cryptonote } //--------------------------------------------------------------------------------- - bool tx_memory_pool::add_tx(const transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block) + bool tx_memory_pool::add_tx(const transaction &tx, const crypto::hash &id, tx_verification_context& tvc, bool kept_by_block) { - + size_t blob_size = get_object_blobsize(tx); if(!check_inputs_types_supported(tx)) { @@ -179,9 +179,8 @@ namespace cryptonote bool tx_memory_pool::add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block) { crypto::hash h = null_hash; - size_t blob_size = 0; - get_transaction_hash(tx, h, blob_size); - return add_tx(tx, h, blob_size, tvc, keeped_by_block); + get_transaction_hash(tx, h); + return add_tx(tx, h, tvc, keeped_by_block); } //--------------------------------------------------------------------------------- bool tx_memory_pool::remove_transaction_keyimages(const transaction& tx) diff --git a/src/cryptonote_core/tx_pool.h b/src/cryptonote_core/tx_pool.h index 7617765cc..fb623a3d2 100644 --- a/src/cryptonote_core/tx_pool.h +++ b/src/cryptonote_core/tx_pool.h @@ -56,7 +56,7 @@ namespace cryptonote { public: tx_memory_pool(blockchain_storage& bchs); - bool add_tx(const transaction &tx, const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block); + bool add_tx(const transaction &tx, const crypto::hash &id, tx_verification_context& tvc, bool keeped_by_block); bool add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block); //gets tx and remove it from pool bool take_tx(const crypto::hash &id, transaction &tx, size_t& blob_size, uint64_t& fee); @@ -81,7 +81,7 @@ namespace cryptonote /*bool flush_pool(const std::strig& folder); bool inflate_pool(const std::strig& folder);*/ -#define CURRENT_MEMPOOL_ARCHIVE_VER 8 +#define CURRENT_MEMPOOL_ARCHIVE_VER 9 template void serialize(archive_t & a, const unsigned int version) diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp index 4a254b5a4..3ae5bcdf6 100644 --- a/tests/unit_tests/serialization.cpp +++ b/tests/unit_tests/serialization.cpp @@ -299,6 +299,37 @@ namespace } } +bool test_get_varint_packed_size_for_num(uint64_t n) +{ +std::stringstream ss; +typedef std::ostreambuf_iterator it; +tools::write_varint(it(ss), n); +uint64_t sz = ss.str().size(); +if(sz != tools::get_varint_packed_size(n)) +return false; +else +return true; +} +TEST(Serialization, validate_get_varint_packed_size) +{ +ASSERT_TRUE(test_get_varint_packed_size_for_num(127)); +ASSERT_TRUE(test_get_varint_packed_size_for_num(128)); +ASSERT_TRUE(test_get_varint_packed_size_for_num(16383)); +ASSERT_TRUE(test_get_varint_packed_size_for_num(16383+1)); +ASSERT_TRUE(test_get_varint_packed_size_for_num(2097151)); +ASSERT_TRUE(test_get_varint_packed_size_for_num(2097151+1)); +ASSERT_TRUE(test_get_varint_packed_size_for_num(268435455)); +ASSERT_TRUE(test_get_varint_packed_size_for_num(268435455+1)); +ASSERT_TRUE(test_get_varint_packed_size_for_num(34359738367)); +ASSERT_TRUE(test_get_varint_packed_size_for_num(34359738367+1)); +ASSERT_TRUE(test_get_varint_packed_size_for_num(4398046511103)); +ASSERT_TRUE(test_get_varint_packed_size_for_num(4398046511103+1)); +ASSERT_TRUE(test_get_varint_packed_size_for_num(4398046511103)); +ASSERT_TRUE(test_get_varint_packed_size_for_num(4398046511103+1)); +ASSERT_TRUE(test_get_varint_packed_size_for_num(562949953421311)); +ASSERT_TRUE(test_get_varint_packed_size_for_num(562949953421311+1)); +} + TEST(Serialization, serializes_transacion_signatures_correctly) { using namespace cryptonote; -- cgit v1.2.3 From 22481244535e05bb308eedf9c2d2a5abe2d79a9d Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 24 Sep 2014 17:15:49 -0400 Subject: Removed ldns dependency ldns dependency was only still around for constants defined in ldns/rr.h, but those constants are RFC specified DNS constants, and to reduce deps have been replicated in dns_utils.h instead of including ldns/rr.h. --- src/common/dns_utils.cpp | 7 +++---- src/common/dns_utils.h | 6 ++++++ 2 files changed, 9 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index e1151e190..4b43c7492 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -29,7 +29,6 @@ #include "common/dns_utils.h" #include #include -#include // for RR type and class defs #include namespace tools @@ -135,7 +134,7 @@ std::vector DNSResolver::get_ipv4(const std::string& url) ub_result_ptr result; // call DNS resolver, blocking. if return value not zero, something went wrong - if (!ub_resolve(m_data->m_ub_context, urlC, LDNS_RR_TYPE_A, LDNS_RR_CLASS_IN, &(result.ptr))) + if (!ub_resolve(m_data->m_ub_context, urlC, DNS_TYPE_A, DNS_CLASS_IN, &(result.ptr))) { if (result.ptr->havedata) { @@ -165,7 +164,7 @@ std::vector DNSResolver::get_ipv6(const std::string& url) ub_result_ptr result; // call DNS resolver, blocking. if return value not zero, something went wrong - if (!ub_resolve(m_data->m_ub_context, urlC, LDNS_RR_TYPE_AAAA, LDNS_RR_CLASS_IN, &(result.ptr))) + if (!ub_resolve(m_data->m_ub_context, urlC, DNS_TYPE_AAAA, DNS_CLASS_IN, &(result.ptr))) { if (result.ptr->havedata) { @@ -195,7 +194,7 @@ std::vector DNSResolver::get_txt_record(const std::string& url) ub_result_ptr result; // call DNS resolver, blocking. if return value not zero, something went wrong - if (!ub_resolve(m_data->m_ub_context, urlC, LDNS_RR_TYPE_TXT, LDNS_RR_CLASS_IN, &(result.ptr))) + if (!ub_resolve(m_data->m_ub_context, urlC, DNS_TYPE_TXT, DNS_CLASS_IN, &(result.ptr))) { if (result.ptr->havedata) { diff --git a/src/common/dns_utils.h b/src/common/dns_utils.h index 375f6ba30..d22e3fb1f 100644 --- a/src/common/dns_utils.h +++ b/src/common/dns_utils.h @@ -32,6 +32,12 @@ namespace tools { +// RFC defines for record types and classes for DNS, gleaned from ldns source +const static int DNS_CLASS_IN = 1; +const static int DNS_TYPE_A = 1; +const static int DNS_TYPE_TXT = 6; +const static int DNS_TYPE_AAAA = 8; + struct DNSResolverData; /** -- cgit v1.2.3 From fab95aef64e2e5ba209ca2f27763a8db489d4294 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 24 Sep 2014 23:19:14 -0400 Subject: Remove LDNS dep and fix a bug in libunbound const correctness fix --- src/common/dns_utils.cpp | 6 +++--- src/common/dns_utils.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index 4b43c7492..346761e74 100644 --- a/src/common/dns_utils.cpp +++ b/src/common/dns_utils.cpp @@ -125,7 +125,7 @@ std::vector DNSResolver::get_ipv4(const std::string& url) strncpy(urlC, url.c_str(), 999); urlC[999] = '\0'; - if (!check_address_syntax(url)) + if (!check_address_syntax(urlC)) { return addresses; } @@ -156,7 +156,7 @@ std::vector DNSResolver::get_ipv6(const std::string& url) strncpy(urlC, url.c_str(), 999); urlC[999] = '\0'; - if (!check_address_syntax(url)) + if (!check_address_syntax(urlC)) { return addresses; } @@ -186,7 +186,7 @@ std::vector DNSResolver::get_txt_record(const std::string& url) strncpy(urlC, url.c_str(), 999); urlC[999] = '\0'; - if (!check_address_syntax(url)) + if (!check_address_syntax(urlC)) { return records; } diff --git a/src/common/dns_utils.h b/src/common/dns_utils.h index d22e3fb1f..dd6946dc4 100644 --- a/src/common/dns_utils.h +++ b/src/common/dns_utils.h @@ -35,7 +35,7 @@ namespace tools // RFC defines for record types and classes for DNS, gleaned from ldns source const static int DNS_CLASS_IN = 1; const static int DNS_TYPE_A = 1; -const static int DNS_TYPE_TXT = 6; +const static int DNS_TYPE_TXT = 16; const static int DNS_TYPE_AAAA = 8; struct DNSResolverData; -- cgit v1.2.3 From 59a8366bb18653f14142321a9d85377ceaef8fad Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Thu, 25 Sep 2014 08:24:42 +0200 Subject: Revert "low risk, potentially varint overflow bug patched thanks to BBR" This reverts commit 4e2b2b942daa4206ec44c66e59863670dfe3fde4. --- src/common/varint.h | 25 +------------------- src/cryptonote_core/cryptonote_basic.h | 1 + src/cryptonote_core/cryptonote_core.cpp | 8 +++---- src/cryptonote_core/cryptonote_core.h | 2 +- src/cryptonote_core/cryptonote_format_utils.cpp | 17 -------------- src/cryptonote_core/cryptonote_format_utils.h | 2 -- src/cryptonote_core/tx_pool.cpp | 9 +++---- src/cryptonote_core/tx_pool.h | 4 ++-- tests/unit_tests/serialization.cpp | 31 ------------------------- 9 files changed, 14 insertions(+), 85 deletions(-) (limited to 'src') diff --git a/src/common/varint.h b/src/common/varint.h index 57386597a..5a73c2746 100644 --- a/src/common/varint.h +++ b/src/common/varint.h @@ -36,7 +36,7 @@ #include #include /*! \file varint.h - * \brief provides the implementation of varint's + * \breif provides the implementation of varint's * * The representation of varints is rather odd. The first bit of each * octet is significant, it represents wheter there is another part @@ -52,29 +52,6 @@ namespace tools { - template - size_t get_varint_packed_size(T v) - { - if(v <= 127) - return 1; - else if(v <= 16383) - return 2; - else if(v <= 2097151) - return 3; - else if(v <= 268435455) - return 4; - else if(v <= 34359738367) - return 5; - else if(v <= 4398046511103) - return 6; - else if(v <= 4398046511103) - return 6; - else if(v <= 562949953421311) - return 7; - else - return 8; - } - /*! \brief Error codes for varint */ enum { diff --git a/src/cryptonote_core/cryptonote_basic.h b/src/cryptonote_core/cryptonote_basic.h index fca4e227e..dfdfa03e5 100644 --- a/src/cryptonote_core/cryptonote_basic.h +++ b/src/cryptonote_core/cryptonote_basic.h @@ -226,6 +226,7 @@ namespace cryptonote ar.end_array(); END_SERIALIZE() + private: static size_t get_signature_size(const txin_v& tx_in); }; diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp index e6aa679d7..964d61e2f 100644 --- a/src/cryptonote_core/cryptonote_core.cpp +++ b/src/cryptonote_core/cryptonote_core.cpp @@ -191,7 +191,7 @@ namespace cryptonote return false; } - bool r = add_new_tx(tx, tx_hash, tx_prefixt_hash, tvc, keeped_by_block); + bool r = add_new_tx(tx, tx_hash, tx_prefixt_hash, tx_blob.size(), tvc, keeped_by_block); if(tvc.m_verifivation_failed) {LOG_PRINT_RED_L1("Transaction verification failed: " << tx_hash);} else if(tvc.m_verifivation_impossible) @@ -284,7 +284,7 @@ namespace cryptonote crypto::hash tx_prefix_hash = get_transaction_prefix_hash(tx); blobdata bl; t_serializable_object_to_blob(tx, bl); - return add_new_tx(tx, tx_hash, tx_prefix_hash, tvc, keeped_by_block); + return add_new_tx(tx, tx_hash, tx_prefix_hash, bl.size(), tvc, keeped_by_block); } //----------------------------------------------------------------------------------------------- size_t core::get_blockchain_total_transactions() @@ -297,7 +297,7 @@ namespace cryptonote // return m_blockchain_storage.get_outs(amount, pkeys); //} //----------------------------------------------------------------------------------------------- - bool core::add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, tx_verification_context& tvc, bool keeped_by_block) + bool core::add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block) { if(m_mempool.have_tx(tx_hash)) { @@ -311,7 +311,7 @@ namespace cryptonote return true; } - return m_mempool.add_tx(tx, tx_hash, tvc, keeped_by_block); + return m_mempool.add_tx(tx, tx_hash, blob_size, tvc, keeped_by_block); } //----------------------------------------------------------------------------------------------- bool core::get_block_template(block& b, const account_public_address& adr, difficulty_type& diffic, uint64_t& height, const blobdata& ex_nonce) diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h index e9ab20114..ba2aed015 100644 --- a/src/cryptonote_core/cryptonote_core.h +++ b/src/cryptonote_core/cryptonote_core.h @@ -120,7 +120,7 @@ namespace cryptonote uint64_t get_target_blockchain_height() const; private: - bool add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, tx_verification_context& tvc, bool keeped_by_block); + bool add_new_tx(const transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block); bool add_new_tx(const transaction& tx, tx_verification_context& tvc, bool keeped_by_block); bool add_new_block(const block& b, block_verification_context& bvc); bool load_state_data(); diff --git a/src/cryptonote_core/cryptonote_format_utils.cpp b/src/cryptonote_core/cryptonote_format_utils.cpp index e46bd390d..33cad30c4 100644 --- a/src/cryptonote_core/cryptonote_format_utils.cpp +++ b/src/cryptonote_core/cryptonote_format_utils.cpp @@ -742,23 +742,6 @@ namespace cryptonote return true; } //--------------------------------------------------------------- - size_t get_object_blobsize(const transaction& t) - { - size_t prefix_blob = get_object_blobsize(static_cast(t)); - - if(is_coinbase(t)) - return prefix_blob; - - for(const auto& in: t.vin) - { - size_t sig_count = transaction::get_signature_size(in); - prefix_blob += 64*sig_count; - prefix_blob += tools::get_varint_packed_size(sig_count); - } - prefix_blob += tools::get_varint_packed_size(t.vin.size()); - return prefix_blob; - } - //--------------------------------------------------------------- blobdata block_to_blob(const block& b) { return t_serializable_object_to_blob(b); diff --git a/src/cryptonote_core/cryptonote_format_utils.h b/src/cryptonote_core/cryptonote_format_utils.h index 58186b8cf..9fa7f0545 100644 --- a/src/cryptonote_core/cryptonote_format_utils.h +++ b/src/cryptonote_core/cryptonote_format_utils.h @@ -157,8 +157,6 @@ namespace cryptonote return b.size(); } //--------------------------------------------------------------- - size_t get_object_blobsize(const transaction& t); - //--------------------------------------------------------------- template bool get_object_hash(const t_object& o, crypto::hash& res, size_t& blob_size) { diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp index 3764cfe77..81f932014 100644 --- a/src/cryptonote_core/tx_pool.cpp +++ b/src/cryptonote_core/tx_pool.cpp @@ -59,9 +59,9 @@ namespace cryptonote } //--------------------------------------------------------------------------------- - bool tx_memory_pool::add_tx(const transaction &tx, const crypto::hash &id, tx_verification_context& tvc, bool kept_by_block) + bool tx_memory_pool::add_tx(const transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool kept_by_block) { - size_t blob_size = get_object_blobsize(tx); + if(!check_inputs_types_supported(tx)) { @@ -179,8 +179,9 @@ namespace cryptonote bool tx_memory_pool::add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block) { crypto::hash h = null_hash; - get_transaction_hash(tx, h); - return add_tx(tx, h, tvc, keeped_by_block); + size_t blob_size = 0; + get_transaction_hash(tx, h, blob_size); + return add_tx(tx, h, blob_size, tvc, keeped_by_block); } //--------------------------------------------------------------------------------- bool tx_memory_pool::remove_transaction_keyimages(const transaction& tx) diff --git a/src/cryptonote_core/tx_pool.h b/src/cryptonote_core/tx_pool.h index fb623a3d2..7617765cc 100644 --- a/src/cryptonote_core/tx_pool.h +++ b/src/cryptonote_core/tx_pool.h @@ -56,7 +56,7 @@ namespace cryptonote { public: tx_memory_pool(blockchain_storage& bchs); - bool add_tx(const transaction &tx, const crypto::hash &id, tx_verification_context& tvc, bool keeped_by_block); + bool add_tx(const transaction &tx, const crypto::hash &id, size_t blob_size, tx_verification_context& tvc, bool keeped_by_block); bool add_tx(const transaction &tx, tx_verification_context& tvc, bool keeped_by_block); //gets tx and remove it from pool bool take_tx(const crypto::hash &id, transaction &tx, size_t& blob_size, uint64_t& fee); @@ -81,7 +81,7 @@ namespace cryptonote /*bool flush_pool(const std::strig& folder); bool inflate_pool(const std::strig& folder);*/ -#define CURRENT_MEMPOOL_ARCHIVE_VER 9 +#define CURRENT_MEMPOOL_ARCHIVE_VER 8 template void serialize(archive_t & a, const unsigned int version) diff --git a/tests/unit_tests/serialization.cpp b/tests/unit_tests/serialization.cpp index 3ae5bcdf6..4a254b5a4 100644 --- a/tests/unit_tests/serialization.cpp +++ b/tests/unit_tests/serialization.cpp @@ -299,37 +299,6 @@ namespace } } -bool test_get_varint_packed_size_for_num(uint64_t n) -{ -std::stringstream ss; -typedef std::ostreambuf_iterator it; -tools::write_varint(it(ss), n); -uint64_t sz = ss.str().size(); -if(sz != tools::get_varint_packed_size(n)) -return false; -else -return true; -} -TEST(Serialization, validate_get_varint_packed_size) -{ -ASSERT_TRUE(test_get_varint_packed_size_for_num(127)); -ASSERT_TRUE(test_get_varint_packed_size_for_num(128)); -ASSERT_TRUE(test_get_varint_packed_size_for_num(16383)); -ASSERT_TRUE(test_get_varint_packed_size_for_num(16383+1)); -ASSERT_TRUE(test_get_varint_packed_size_for_num(2097151)); -ASSERT_TRUE(test_get_varint_packed_size_for_num(2097151+1)); -ASSERT_TRUE(test_get_varint_packed_size_for_num(268435455)); -ASSERT_TRUE(test_get_varint_packed_size_for_num(268435455+1)); -ASSERT_TRUE(test_get_varint_packed_size_for_num(34359738367)); -ASSERT_TRUE(test_get_varint_packed_size_for_num(34359738367+1)); -ASSERT_TRUE(test_get_varint_packed_size_for_num(4398046511103)); -ASSERT_TRUE(test_get_varint_packed_size_for_num(4398046511103+1)); -ASSERT_TRUE(test_get_varint_packed_size_for_num(4398046511103)); -ASSERT_TRUE(test_get_varint_packed_size_for_num(4398046511103+1)); -ASSERT_TRUE(test_get_varint_packed_size_for_num(562949953421311)); -ASSERT_TRUE(test_get_varint_packed_size_for_num(562949953421311+1)); -} - TEST(Serialization, serializes_transacion_signatures_correctly) { using namespace cryptonote; -- cgit v1.2.3