From 8d6a04a9f089cb656debb6b8397947f815d65f12 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 12:27:16 -0400 Subject: [PATCH 01/63] Default to static linking on both MSVC and MINGW --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 09973721..e3a08a6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,12 @@ if(APPLE) include_directories(SYSTEM /usr/include/malloc) endif() -set(STATIC ${MSVC} CACHE BOOL "Link libraries statically") +if(MSVC OR MINGW) + set(DEFAULT_STATIC true) +else() + set(DEFAULT_STATIC false) +endif() +set(STATIC ${DEFAULT_STATIC} CACHE BOOL "Link libraries statically") if (UNIX AND NOT APPLE) # Note that at the time of this writing the -Wstrict-prototypes flag added below will make this fail From 0fe311b2f05c30d6287c54516181c24e48192d92 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 12:30:12 -0400 Subject: [PATCH 02/63] Remove unused CMake function --- CMakeLists.txt | 6 ------ 1 file changed, 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3a08a6d..8c6b0289 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,12 +51,6 @@ endif() # elseif(CMAKE_SYSTEM_NAME MATCHES ".*BSDI.*") # set(BSDI TRUE) -function(set_static_flags) - if (NOT APPLE AND NOT FREEBSD) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") - endif() -endfunction(set_static_flags) - include_directories(src contrib/epee/include external "${CMAKE_BINARY_DIR}/version") if(APPLE) From 9c848ceae7e7e3dbb102f6116f076f0ef10ef189 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 12:32:59 -0400 Subject: [PATCH 03/63] Ignore another warning to make mingw happy --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c6b0289..79e0152e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,7 +98,7 @@ else() set(CMAKE_RANLIB "gcc-ranlib") endif() if(MINGW) - set(WARNINGS "${WARNINGS} -Wno-error=unused-value") + set(WARNINGS "${WARNINGS} -Wno-error=unused-value -Wno-error=unused-but-set-variable") set(MINGW_FLAG "-DWIN32_LEAN_AND_MEAN") include_directories(SYSTEM src/platform/mingw) else() From a31d6bb9fbc9b8b922bf40abd943eddeff3d6ff9 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 12:42:24 -0400 Subject: [PATCH 04/63] Hack to allow toolchains to pass flags to mingw --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 79e0152e..dbbd097b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,7 +99,7 @@ else() endif() if(MINGW) set(WARNINGS "${WARNINGS} -Wno-error=unused-value -Wno-error=unused-but-set-variable") - set(MINGW_FLAG "-DWIN32_LEAN_AND_MEAN") + set(MINGW_FLAG "${MINGW_FLAG} -DWIN32_LEAN_AND_MEAN") include_directories(SYSTEM src/platform/mingw) else() set(MINGW_FLAG "") From 44f920b0fd9f8730473c690f63aebcc633d1a90f Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 12:43:01 -0400 Subject: [PATCH 05/63] Set the boost thread api for mingw --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index dbbd097b..cb06e719 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,7 @@ else() if(MINGW) set(WARNINGS "${WARNINGS} -Wno-error=unused-value -Wno-error=unused-but-set-variable") set(MINGW_FLAG "${MINGW_FLAG} -DWIN32_LEAN_AND_MEAN") + set(Boost_THREADAPI win32) include_directories(SYSTEM src/platform/mingw) else() set(MINGW_FLAG "") From f9f4fc1b00168f965bbcdbada8e49dc3b1f201ac Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 12:45:47 -0400 Subject: [PATCH 06/63] Change to -static gcc flag --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cb06e719..a87a03b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,7 +136,7 @@ else() set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${RELEASE_FLAGS}") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${RELEASE_FLAGS}") if(STATIC AND NOT APPLE AND NOT FREEBSD) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") endif() endif() From 1b90c6f3d5d62c1929968266f6e920a4edf4fab6 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 12:50:12 -0400 Subject: [PATCH 07/63] Hack to add pthread to link libraries on mingw This should link winpthreads. We really shouldn't be passing these this way, but that seems to be the existing solution, and it works for now. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a87a03b9..4f380610 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,11 +150,11 @@ if((${Boost_MAJOR_VERSION} EQUAL 1) AND (${Boost_MINOR_VERSION} EQUAL 54)) endif() include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) if(MINGW) - set(Boost_LIBRARIES "${Boost_LIBRARIES};ws2_32;mswsock") + set(Boost_LIBRARIES "${Boost_LIBRARIES};pthread;mswsock;ws2_32") elseif(APPLE OR FREEBSD) set(Boost_LIBRARIES "${Boost_LIBRARIES}") elseif(NOT MSVC) - set(Boost_LIBRARIES "${Boost_LIBRARIES};rt;pthread") + #set(Boost_LIBRARIES "${Boost_LIBRARIES};rt;pthread") endif() file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/version") From e1dfd58bdb515feb904d2851aa87aa5a90cb6a5a Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 12:50:48 -0400 Subject: [PATCH 08/63] Remove unnecessary else --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f380610..ecb16666 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,8 +102,6 @@ else() set(MINGW_FLAG "${MINGW_FLAG} -DWIN32_LEAN_AND_MEAN") set(Boost_THREADAPI win32) include_directories(SYSTEM src/platform/mingw) - else() - set(MINGW_FLAG "") endif() set(C_WARNINGS "-Waggregate-return -Wnested-externs -Wold-style-definition -Wstrict-prototypes") set(CXX_WARNINGS "-Wno-reorder -Wno-missing-field-initializers") From 729d4bb91da9458df2da05ca5c214ee1ab331aa9 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 12:52:25 -0400 Subject: [PATCH 09/63] User setting to turn LTO on and off This isn't currently working on mingw --- CMakeLists.txt | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ecb16666..857e927f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -92,11 +92,6 @@ else() else() set(WARNINGS "${WARNINGS} -Wlogical-op -Wno-error=maybe-uninitialized") endif() - # Since gcc 4.9 the LTO format is non-standard (slim), so we need the gcc-specific ar and ranlib binaries - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0)) - set(CMAKE_AR "gcc-ar") - set(CMAKE_RANLIB "gcc-ranlib") - endif() if(MINGW) set(WARNINGS "${WARNINGS} -Wno-error=unused-value -Wno-error=unused-but-set-variable") set(MINGW_FLAG "${MINGW_FLAG} -DWIN32_LEAN_AND_MEAN") @@ -121,14 +116,23 @@ else() else() set(DEBUG_FLAGS "-g3 -O0") endif() + set(RELEASE_FLAGS "-Ofast -DNDEBUG -Wno-unused-variable") - if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + + set(USE_LTO false CACHE BOOL "Use Link-Time Optimization (Release mode only)") + if(USE_LTO) # There is a clang bug that does not allow to compile code that uses AES-NI intrinsics if -flto is enabled set(RELEASE_FLAGS "${RELEASE_FLAGS} -flto") + if(STATIC) + set(RELEASE_FLAGS "${RELEASE_FLAGS} -ffat-lto-objects") + endif() + # Since gcc 4.9 the LTO format is non-standard (slim), so we need the gcc-specific ar and ranlib binaries + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0)) + set(CMAKE_AR "gcc-ar") + set(CMAKE_RANLIB "gcc-ranlib") + endif() endif() - #if(CMAKE_C_COMPILER_ID STREQUAL "GNU" AND NOT MINGW) - # set(RELEASE_FLAGS "${RELEASE_FLAGS} -fno-fat-lto-objects") - #endif() + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${DEBUG_FLAGS}") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${DEBUG_FLAGS}") set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${RELEASE_FLAGS}") From 2b76e9d8a3bb47f78abaa9b5eb99c1e111316264 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 13:06:03 -0400 Subject: [PATCH 10/63] Change Windows include to windows mingw is case sensitive --- src/crypto/slow-hash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/slow-hash.c b/src/crypto/slow-hash.c index 3aff7bd5..b33ef0f4 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) From cf91545734134866e93fa8cc8d36a7b8cf45bafb Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 13:07:36 -0400 Subject: [PATCH 11/63] Correct includes for mingw in slow-hash This needs testing --- src/crypto/slow-hash.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/crypto/slow-hash.c b/src/crypto/slow-hash.c index b33ef0f4..2d3197d6 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 From aba3497fdd6c47500dbbbce54c29900f24a3d55b Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 13:08:15 -0400 Subject: [PATCH 12/63] More preprocessor fixes for slow-hash --- src/crypto/slow-hash.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/crypto/slow-hash.c b/src/crypto/slow-hash.c index 2d3197d6..d4f27e1e 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); From 45bc24d69b2e790d5707215f654f6d4c63146984 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 13:09:31 -0400 Subject: [PATCH 13/63] Another preprocessor fix (difficulty.cpp) --- src/cryptonote_core/difficulty.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cryptonote_core/difficulty.cpp b/src/cryptonote_core/difficulty.cpp index c26f8d90..d4d733e6 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 From ceb6977f82328747d9e97cbcbdd064275ae6abab Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 6 Aug 2014 13:13:06 -0400 Subject: [PATCH 14/63] msys2 32/64-bit toolchains --- toolchains/msys2-m32-toolchain.cmake | 18 ++++++++++++++++++ toolchains/msys2-m64-toolchain.cmake | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 toolchains/msys2-m32-toolchain.cmake create mode 100644 toolchains/msys2-m64-toolchain.cmake diff --git a/toolchains/msys2-m32-toolchain.cmake b/toolchains/msys2-m32-toolchain.cmake new file mode 100644 index 00000000..7cc463a5 --- /dev/null +++ b/toolchains/msys2-m32-toolchain.cmake @@ -0,0 +1,18 @@ +set (CMAKE_SYSTEM_NAME Windows) + +set (GCC_PREFIX i686-w64-mingw32) +set (CMAKE_C_COMPILER ${GCC_PREFIX}-gcc) +set (CMAKE_CXX_COMPILER ${GCC_PREFIX}-g++) +set (CMAKE_AR ${GCC_PREFIX}-gcc-ar CACHE FILEPATH "" FORCE) +set (CMAKE_NM ${GCC_PREFIX}-gcc-nm CACHE FILEPATH "" FORCE) +set (CMAKE_RANLIB ${GCC_PREFIX}-gcc-ranlib CACHE FILEPATH "" FORCE) +set (CMAKE_RC_COMPILER windres) + +set (CMAKE_FIND_ROOT_PATH c:/msys2/mingw32) + +# Ensure cmake doesn't find things in the wrong places +set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # Find programs on host +set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) # Find libs in target +set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # Find includes in target + +set (MINGW_FLAG "-m64") diff --git a/toolchains/msys2-m64-toolchain.cmake b/toolchains/msys2-m64-toolchain.cmake new file mode 100644 index 00000000..45816895 --- /dev/null +++ b/toolchains/msys2-m64-toolchain.cmake @@ -0,0 +1,18 @@ +set (CMAKE_SYSTEM_NAME Windows) + +set (GCC_PREFIX x86_64-w64-mingw32) +set (CMAKE_C_COMPILER ${GCC_PREFIX}-gcc) +set (CMAKE_CXX_COMPILER ${GCC_PREFIX}-g++) +set (CMAKE_AR ${GCC_PREFIX}-gcc-ar CACHE FILEPATH "" FORCE) +set (CMAKE_NM ${GCC_PREFIX}-gcc-nm CACHE FILEPATH "" FORCE) +set (CMAKE_RANLIB ${GCC_PREFIX}-gcc-ranlib CACHE FILEPATH "" FORCE) +set (CMAKE_RC_COMPILER windres) + +set (CMAKE_FIND_ROOT_PATH c:/msys2/mingw64) + +# Ensure cmake doesn't find things in the wrong places +set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # Find programs on host +set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) # Find libs in target +set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # Find includes in target + +set (MINGW_FLAG "-m64") From f64a68e7cc8ae1587b0f34ac305f5222fe87351d Mon Sep 17 00:00:00 2001 From: Zachary Michaels <> Date: Wed, 6 Aug 2014 19:41:38 -0400 Subject: [PATCH 15/63] Force CMake to link the runtime statically --- src/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9673e36e..28bffea1 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") From dfa11575f2e195542eff4c19c11434c8dabd2e40 Mon Sep 17 00:00:00 2001 From: Zachary Michaels <> Date: Thu, 7 Aug 2014 14:27:12 -0400 Subject: [PATCH 16/63] Use unwrapped binutils for msys2 The default binutils wrappers are built without plugin support. This will streamline the build process until we decide to start supporting LTO. --- toolchains/msys2-m32-toolchain.cmake | 6 +++--- toolchains/msys2-m64-toolchain.cmake | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/toolchains/msys2-m32-toolchain.cmake b/toolchains/msys2-m32-toolchain.cmake index 7cc463a5..21baf503 100644 --- a/toolchains/msys2-m32-toolchain.cmake +++ b/toolchains/msys2-m32-toolchain.cmake @@ -3,9 +3,9 @@ set (CMAKE_SYSTEM_NAME Windows) set (GCC_PREFIX i686-w64-mingw32) set (CMAKE_C_COMPILER ${GCC_PREFIX}-gcc) set (CMAKE_CXX_COMPILER ${GCC_PREFIX}-g++) -set (CMAKE_AR ${GCC_PREFIX}-gcc-ar CACHE FILEPATH "" FORCE) -set (CMAKE_NM ${GCC_PREFIX}-gcc-nm CACHE FILEPATH "" FORCE) -set (CMAKE_RANLIB ${GCC_PREFIX}-gcc-ranlib CACHE FILEPATH "" FORCE) +set (CMAKE_AR ar CACHE FILEPATH "" FORCE) +set (CMAKE_NM nm CACHE FILEPATH "" FORCE) +#set (CMAKE_RANLIB ${GCC_PREFIX}-gcc-ranlib CACHE FILEPATH "" FORCE) set (CMAKE_RC_COMPILER windres) set (CMAKE_FIND_ROOT_PATH c:/msys2/mingw32) diff --git a/toolchains/msys2-m64-toolchain.cmake b/toolchains/msys2-m64-toolchain.cmake index 45816895..8884ae28 100644 --- a/toolchains/msys2-m64-toolchain.cmake +++ b/toolchains/msys2-m64-toolchain.cmake @@ -3,9 +3,9 @@ set (CMAKE_SYSTEM_NAME Windows) set (GCC_PREFIX x86_64-w64-mingw32) set (CMAKE_C_COMPILER ${GCC_PREFIX}-gcc) set (CMAKE_CXX_COMPILER ${GCC_PREFIX}-g++) -set (CMAKE_AR ${GCC_PREFIX}-gcc-ar CACHE FILEPATH "" FORCE) -set (CMAKE_NM ${GCC_PREFIX}-gcc-nm CACHE FILEPATH "" FORCE) -set (CMAKE_RANLIB ${GCC_PREFIX}-gcc-ranlib CACHE FILEPATH "" FORCE) +set (CMAKE_AR ar CACHE FILEPATH "" FORCE) +set (CMAKE_NM nm CACHE FILEPATH "" FORCE) +#set (CMAKE_RANLIB ${GCC_PREFIX}-gcc-ranlib CACHE FILEPATH "" FORCE) set (CMAKE_RC_COMPILER windres) set (CMAKE_FIND_ROOT_PATH c:/msys2/mingw64) From 4fd7752d954f248ad9ea3225a1601c6c674e0ed5 Mon Sep 17 00:00:00 2001 From: Zachary Michaels <> Date: Thu, 7 Aug 2014 14:28:50 -0400 Subject: [PATCH 17/63] Fix march flag for 32-bit build --- toolchains/msys2-m32-toolchain.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/toolchains/msys2-m32-toolchain.cmake b/toolchains/msys2-m32-toolchain.cmake index 21baf503..111122a9 100644 --- a/toolchains/msys2-m32-toolchain.cmake +++ b/toolchains/msys2-m32-toolchain.cmake @@ -15,4 +15,4 @@ set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # Find programs on host set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) # Find libs in target set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # Find includes in target -set (MINGW_FLAG "-m64") +set (MINGW_FLAG "-m32") From 59c1ac503f320bac31816937e5e872cd57638971 Mon Sep 17 00:00:00 2001 From: Zachary Michaels <> Date: Thu, 7 Aug 2014 18:23:34 -0400 Subject: [PATCH 18/63] Move toolchain files --- .../msys2-m32-toolchain.cmake => msys2/32-bit-toolchain.cmake | 0 .../msys2-m64-toolchain.cmake => msys2/64-bit-toolchain.cmake | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename toolchains/msys2-m32-toolchain.cmake => msys2/32-bit-toolchain.cmake (100%) rename toolchains/msys2-m64-toolchain.cmake => msys2/64-bit-toolchain.cmake (100%) diff --git a/toolchains/msys2-m32-toolchain.cmake b/msys2/32-bit-toolchain.cmake similarity index 100% rename from toolchains/msys2-m32-toolchain.cmake rename to msys2/32-bit-toolchain.cmake diff --git a/toolchains/msys2-m64-toolchain.cmake b/msys2/64-bit-toolchain.cmake similarity index 100% rename from toolchains/msys2-m64-toolchain.cmake rename to msys2/64-bit-toolchain.cmake From ed41ee4c264ee26cd786eebf1476f97dbe81c9b8 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Thu, 7 Aug 2014 19:34:10 -0400 Subject: [PATCH 19/63] Use LTO by default The mingw toolchains override this for now. --- CMakeLists.txt | 5 ++++- msys2/32-bit-toolchain.cmake | 1 + msys2/64-bit-toolchain.cmake | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 857e927f..e182f714 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -119,7 +119,10 @@ else() set(RELEASE_FLAGS "-Ofast -DNDEBUG -Wno-unused-variable") - set(USE_LTO false CACHE BOOL "Use Link-Time Optimization (Release mode only)") + if(NOT DEFINED USE_LTO_DEFAULT) + set(USE_LTO_DEFAULT true) + endif() + set(USE_LTO ${USE_LTO_DEFAULT} CACHE BOOL "Use Link-Time Optimization (Release mode only)") if(USE_LTO) # There is a clang bug that does not allow to compile code that uses AES-NI intrinsics if -flto is enabled set(RELEASE_FLAGS "${RELEASE_FLAGS} -flto") diff --git a/msys2/32-bit-toolchain.cmake b/msys2/32-bit-toolchain.cmake index 111122a9..91665a21 100644 --- a/msys2/32-bit-toolchain.cmake +++ b/msys2/32-bit-toolchain.cmake @@ -16,3 +16,4 @@ set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) # Find libs in target set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # Find includes in target set (MINGW_FLAG "-m32") +set (USE_LTO_DEFAULT false) diff --git a/msys2/64-bit-toolchain.cmake b/msys2/64-bit-toolchain.cmake index 8884ae28..93d69d89 100644 --- a/msys2/64-bit-toolchain.cmake +++ b/msys2/64-bit-toolchain.cmake @@ -16,3 +16,4 @@ set (CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) # Find libs in target set (CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) # Find includes in target set (MINGW_FLAG "-m64") +set (USE_LTO_DEFAULT false) From 9db881864db916310c11270c1939db700689c9a3 Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Wed, 20 Aug 2014 11:57:29 -0400 Subject: [PATCH 20/63] 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(-) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 870e7572..954d794b 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 b0232690..e3e387bb 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 a14d00dc..44b8c5b5 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 From d8257fb67b5714af8dc5690201954432add4b229 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Mon, 15 Sep 2014 22:47:26 +0200 Subject: [PATCH 21/63] explicitly disable LTO for Clang --- CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e182f714..190fcc5c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,8 +123,12 @@ else() set(USE_LTO_DEFAULT true) endif() set(USE_LTO ${USE_LTO_DEFAULT} CACHE BOOL "Use Link-Time Optimization (Release mode only)") + + # There is a clang bug that does not allow to compile code that uses AES-NI intrinsics if -flto is enabled, so explicitly disable + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + set(USE_LTO false) + endif() if(USE_LTO) - # There is a clang bug that does not allow to compile code that uses AES-NI intrinsics if -flto is enabled set(RELEASE_FLAGS "${RELEASE_FLAGS} -flto") if(STATIC) set(RELEASE_FLAGS "${RELEASE_FLAGS} -ffat-lto-objects") From 070ff889d2dc757ca909cf545639a3cbe1e0bc7f Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Mon, 15 Sep 2014 23:01:50 +0200 Subject: [PATCH 22/63] More robust versioning in CMake, plus comments --- src/version.cmake | 75 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 62 insertions(+), 13 deletions(-) diff --git a/src/version.cmake b/src/version.cmake index e851cdf0..0d1e52a2 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 From de442fb9ad2a42687cd5254d218259327953b4e1 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Mon, 15 Sep 2014 23:04:58 +0200 Subject: [PATCH 23/63] Prevent CMake choking on empty vars --- src/version.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/version.cmake b/src/version.cmake index 0d1e52a2..02f5ec0a 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) From ffe7bf8c1cd373b4cd2d256a5f4ea5359a0a35c0 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Mon, 15 Sep 2014 23:07:47 +0200 Subject: [PATCH 24/63] another fix for CMake empty vars --- src/version.cmake | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/version.cmake b/src/version.cmake index 02f5ec0a..2f3aa0b2 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.") From 59ab569da1fa16d379f519f5480c03e39f05b44d Mon Sep 17 00:00:00 2001 From: Zachary Michaels Date: Mon, 15 Sep 2014 16:28:27 -0400 Subject: [PATCH 25/63] 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(-) diff --git a/src/daemon/daemon_commands_handler.h b/src/daemon/daemon_commands_handler.h index 58112e16..869c2adf 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 22e95a1f..e80451cd 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 7914ff8e..ebec931e 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) { } From 0e21944b97dfecc2633f6cdd0a0a7910939bfb3f Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Mon, 15 Sep 2014 23:17:24 +0200 Subject: [PATCH 26/63] turns out we do need -static-libgcc etc. on Linux --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 190fcc5c..593ef87d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,7 +145,7 @@ else() set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} ${RELEASE_FLAGS}") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${RELEASE_FLAGS}") if(STATIC AND NOT APPLE AND NOT FREEBSD) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static") + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++") endif() endif() From d34f681ed6fb4d75c5ef0eaae22c910cdb292b7a Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Sun, 21 Sep 2014 02:23:28 +0200 Subject: [PATCH 27/63] fixed miniupnpc static building --- external/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index fd8cd4eb..177c2115 100755 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -216,7 +216,7 @@ MARK_AS_ADVANCED(MINIUPNP_INCLUDE_DIR MINIUPNP_LIBRARY) # And now on to the Monero part of things -if(MINIUPNP_FOUND AND MINIUPNPC_VERSION_1_7_OR_HIGHER) +if(MINIUPNP_FOUND AND MINIUPNPC_VERSION_1_7_OR_HIGHER AND !STATIC) message(STATUS "Using shared miniupnpc found at ${MINIUPNP_INCLUDE_DIR}") set(UPNP_STATIC false PARENT_SCOPE) From ca569549ec56ec91d76f0667c563fc395d026cf4 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Mon, 22 Sep 2014 12:09:46 +0200 Subject: [PATCH 28/63] added mikezackles' missing boost function in CMakeLists --- CMakeLists.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 593ef87d..bf3b8cf1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,21 @@ cmake_minimum_required(VERSION 2.8.6) +if (NOT DEFINED ENV{DEVELOPER_LOCAL_TOOLS}) + message(STATUS "Could not find DEVELOPER_LOCAL_TOOLS in env") + set(BOOST_IGNORE_SYSTEM_PATHS_DEFAULT OFF) +elseif ("$ENV{DEVELOPER_LOCAL_TOOLS}" EQUAL 1) + message(STATUS "found: env DEVELOPER_LOCAL_TOOLS = 1") + set(BOOST_IGNORE_SYSTEM_PATHS_DEFAULT ON) + option(BOOST_IGNORE_SYSTEM_PATHS "Ignore boost system paths for local boost installation" ON) +else() + message(STATUS "found: env DEVELOPER_LOCAL_TOOLS = 0") + set(BOOST_IGNORE_SYSTEM_PATHS_DEFAULT OFF) +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() From b5d51e30d9d86bba5a08d33fa4fd2173565061c7 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Mon, 22 Sep 2014 12:30:53 +0200 Subject: [PATCH 29/63] moved msys2 toolchain, boost libs fix --- CMakeLists.txt | 4 ++++ {msys2 => cmake}/32-bit-toolchain.cmake | 2 +- {msys2 => cmake}/64-bit-toolchain.cmake | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) rename {msys2 => cmake}/32-bit-toolchain.cmake (92%) rename {msys2 => cmake}/64-bit-toolchain.cmake (92%) diff --git a/CMakeLists.txt b/CMakeLists.txt index bf3b8cf1..87567473 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,6 +164,10 @@ else() endif() endif() +if (BOOST_IGNORE_SYSTEM_PATHS) + set(Boost_NO_SYSTEM_PATHS TRUE) +endif() + if(STATIC) set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_STATIC_RUNTIME ON) diff --git a/msys2/32-bit-toolchain.cmake b/cmake/32-bit-toolchain.cmake similarity index 92% rename from msys2/32-bit-toolchain.cmake rename to cmake/32-bit-toolchain.cmake index 91665a21..4543c106 100644 --- a/msys2/32-bit-toolchain.cmake +++ b/cmake/32-bit-toolchain.cmake @@ -8,7 +8,7 @@ set (CMAKE_NM nm CACHE FILEPATH "" FORCE) #set (CMAKE_RANLIB ${GCC_PREFIX}-gcc-ranlib CACHE FILEPATH "" FORCE) set (CMAKE_RC_COMPILER windres) -set (CMAKE_FIND_ROOT_PATH c:/msys2/mingw32) +set (CMAKE_FIND_ROOT_PATH "${MSYS2_FOLDER}/mingw32") # Ensure cmake doesn't find things in the wrong places set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # Find programs on host diff --git a/msys2/64-bit-toolchain.cmake b/cmake/64-bit-toolchain.cmake similarity index 92% rename from msys2/64-bit-toolchain.cmake rename to cmake/64-bit-toolchain.cmake index 93d69d89..e9b3cc51 100644 --- a/msys2/64-bit-toolchain.cmake +++ b/cmake/64-bit-toolchain.cmake @@ -8,7 +8,7 @@ set (CMAKE_NM nm CACHE FILEPATH "" FORCE) #set (CMAKE_RANLIB ${GCC_PREFIX}-gcc-ranlib CACHE FILEPATH "" FORCE) set (CMAKE_RC_COMPILER windres) -set (CMAKE_FIND_ROOT_PATH c:/msys2/mingw64) +set (CMAKE_FIND_ROOT_PATH "${MSYS2_FOLDER}/mingw64") # Ensure cmake doesn't find things in the wrong places set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) # Find programs on host From 8bf4b75e2709528382ca999b3b963b2a5f6ffe4d Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Tue, 23 Sep 2014 15:23:40 +0200 Subject: [PATCH 30/63] added oranjuice and tewinget's GPG keys --- utils/gpg_keys/oranjuice.asc | 31 +++++++++++++++++++++++++++++++ utils/gpg_keys/tewinget.asc | 19 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 utils/gpg_keys/oranjuice.asc create mode 100644 utils/gpg_keys/tewinget.asc diff --git a/utils/gpg_keys/oranjuice.asc b/utils/gpg_keys/oranjuice.asc new file mode 100644 index 00000000..48ef9fc8 --- /dev/null +++ b/utils/gpg_keys/oranjuice.asc @@ -0,0 +1,31 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v1 + +mQENBFQdV4IBCADBdDmK+nzA5ICNBe5hu3V+PGvJcgqZET6rtc9eAqWJJB+JkdqN +FEnlVtXNi00jM4aokCV3PSDKLhMsxmPgUjjDP7LCU/r1OYMlJGVsnvEYII6bpKji +J8bWb3FeA1ZJvD4dhn6RIkloCkBjTsgjWwyB1HraTdY4DfKjwoDl299M99gZi4LZ +YVz0klugeRmdbFg3SrURgpfx/jZArJXFEHwHac6cVRVxdlSOatf3wurFMMgOBb9c +Q44WAtxL+G7EtICdtN0y81OJ2cyFzN38jPGMh9uR1jDbOgLB27aYANo9FhXKi3xm +pYJCl7/B3VrUxfyDQxTztRhIcAY5wIu9GIhZABEBAAG0ME9yYW4gSnVpY2UgKC8v +IEdQRyBrZXkpIDxvcmFuanVpY2VzQGhvdG1haWwuY29tPokBPgQTAQIAKAUCVB1X +ggIbAwUJAeEzgAYLCQgHAwIGFQgCCQoLBBYCAwECHgECF4AACgkQccWvRsyygSR2 +KAf/b94PbLsKKwqDkoQYLCYDCjkWfqiY8R8f6jvAEhzmbW1BwRfSMbrCBbnT1li5 +80Ld2M1yHsefeU2D/wZd/sxtqa9jmpPh6GRBL4pWTV98SDqQOvo46N78Y8mzivg3 +e3rPyD6AiDY/c24d+FMynk29qc08YSR1evxbYt9K2ec02fHuutAb7ujTKc2IgkYG +YlQXgnd3sVTw6uiieH+yp0MD2HYLaPaneAboHG/H58EmFbR7fmPkyGTjetLR0o3J +PyYE2liU5GJWwuIxhuNxRh6EV3vmjYL5dQF1sl99JIBUSMmKQWch3Jq+uIKPFC28 +EUuvCc6sQEKTCg+yE0yXvPgXorkBDQRUHVeCAQgA7G7fRs16tmOLZjHwkqSMjNGg +6nAPzqTe+8xdfbgahgBJC9iq3ceK26jwZQkQjJWPZ6EXL8vB0nQTxc/ghGEorJ03 +Pa7vBNhX3WVWuG4sZqZhX4mfLN2DAYr197C4KOW5Hmw+PP/Ru55xuyIL7tUIv/Fi +ohe55P7HunZ811zu5ypk7nJIza97VnKhWj6U7gaFKTEA6DI/3D6fobjgT2jXT5uG +lKO9QyRSfuZpt6nvRzDOIjorkF0cg9XYktsL5T34KLvJ2vnHJoHAbxvo1LRTdFzq +gfomwrgi+dSe41uNZZwFSKZWz+NMnSADj3A4ea2yyCrEMDyOXJPQ/PdlsCmkywAR +AQABiQElBBgBAgAPBQJUHVeCAhsMBQkB4TOAAAoJEHHFr0bMsoEka/8IAKdYJ03D +MZ6chIfy3uEMBTi9kHBRffltqSG4Z5/l4eT/JmF5prY075c/hEy9iv8uGntPNfoG +TzIAFXUBtAifyzvTP0CQExXdRJQjGjwCKPpF3w8fYW0zNOITuyJi+MD1RPSMz7/v +hvFh1SSbUBCfY3yBL80P81diPYqSyWVCZzFADiLZ0BPJJnQW09NNcUvfu71PS2SQ +JCpgVbRaxu4h6oEeq7R1Oodwm4FD8KaEg+QBSjysqPXnyHLfd+zT+mfI6xqiQAcf +khMh42KT/uKuaqb3/Xpk1invRDBisQVY/D5Jp5ThWBHUb+LkVLQZd0cS0EQlb1CM +S3iMwD+QAYLrhZs= +=q3wo +-----END PGP PUBLIC KEY BLOCK----- diff --git a/utils/gpg_keys/tewinget.asc b/utils/gpg_keys/tewinget.asc new file mode 100644 index 00000000..1153d2c2 --- /dev/null +++ b/utils/gpg_keys/tewinget.asc @@ -0,0 +1,19 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v1 + +mQENBFQZzOoBCACidWQPdZTfNsJqQs7mTJQSH6IHlaZuDuFFXvnnD5c+FEdHInib +a3BgISAsZ9k54F+duJbel8GLJSu+/DfdFVkdLoIRIpiVTicvrQkh/a4cm+5Zmg/Z +R4Syo4VQFJK52CVu0nGFWISYVSoXalEbSna9AjoLPJ/ZSCyhTw1+LvjH6te5hoQP +VGuDj7ZxbQX5I1qT4QtuGxKRqSGf/ISSyWmbVjzarPv3Mzqqvza26cxksnvxVmib +o6ITmbp51ZncLyw/QRwQIdl28C4He6/CQgWZccuOVbO2T9aCT5toSkoyG8wYbBTH +AnV/IxogjFkLZIaq4HXjEvhJsMfSsNDftwl7ABEBAAG0O1Rob21hcyBXaW5nZXQg +KFNpZ25pbmcga2V5IGZvciBNb25lcm8pIDx0ZXdpbmdldEBnbWFpbC5jb20+iQE4 +BBMBAgAiBQJUGczqAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRBYExoW +B4nmMOTaB/952ZSgf0FdOeUNma2gI9Ipz5tFk73fvvVQ5YXZASIroAVWDJ7e6jTk +ESrrubrQnuiVSj5GHjPfqyWEcA0EJ2OKtKi3f1sM0j+aBsR1yfyC9tuWJvIC1E60 +4BTXXlK1q3tMXhnxBvrqOnNiuLouxWdx6q+R17xu3kguPkXrsrl8ZDEjUl9JaoXi +OKlmCmujB2IVCf5If44ZoRANoF6MdvlBq5TZv1p2etzz+sJ8cWrcalRlUdA8DcdJ +ENfsqndAsm8ID8fYokiCr49jE1QSypWElE65JDsVgX6Yjzz98BYy/9s15YbE5McG +Wvg1RzElvwv588XbqxJhEhDZTQW8Dx0z +=3FSH +-----END PGP PUBLIC KEY BLOCK----- \ No newline at end of file From 869f79e5b66f49133c33f89845cc1393a663ec6a Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Tue, 23 Sep 2014 18:15:59 +0200 Subject: [PATCH 31/63] updated mingw build instructions --- README.md | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e275c0eb..cd5410c6 100644 --- a/README.md +++ b/README.md @@ -77,16 +77,40 @@ Alternatively, it can be built in an easier and more automated fashion using Hom ### On Windows: -Dependencies: MSVC 2013 or later, CMake 2.8.6 or later, and Boost 1.53 or later (except 1.54, [more details here](http://goo.gl/RrCFmA)). +Dependencies: mingw-w64, msys2, CMake 2.8.6 or later, and Boost 1.53 or 1.55 (except 1.54, [more details here](http://goo.gl/RrCFmA), and 1.56 as it causes an internal compiler error on mingw-w64). -* To build, change to the root of the source code directory, and run these commands: +**Preparing the Build Environment** + +* Download the [MSYS2 installer](http://msys2.github.io), 64-bit or 32-bit as needed, and run it. +* Use the shortcut associated with your architecture to launch the MSYS2 environment. On 64-bit systems that would be the MinGW-w64 Win64 Shell shortcut. Note that if you are running 64-bit Windows, you will have both 64-bit and 32-bit environments. +* Update the packages in your MSYS2 install: +``` +pacman -Sy +pacman -Su --ignoregroup base +pacman -Su +``` +* For those of you already familiar with pacman, you can run the normal `pacman -Syu` to update, but you may get errors and need to restart MSYS2 if pacman's dependencies are updated. +* Install dependencies: `pacman -S mingw-w64-x86_64-gcc make mingw-w64-x86_64-cmake` (note: in future, once the boost 1.56 mingw-w64 issues are fixed, you can add `mingw-w64-x86_64-boost` to that list to have it installed as well) +* Download the [boost 1.55 msys2 package](http://downloads.sourceforge.net/project/msys2/REPOS/MINGW/x86_64/mingw-w64-x86_64-boost-1.55.0-7-any.pkg.tar.xz), and install it by running `pacman -U mingw-w64-x86_64-boost-1.55.0-7-any.pkg.tar.xz` + +**Building* + +* From the root of the source code directory run: ``` mkdir build cd build -cmake -G "Visual Studio 12 Win64" -DBOOST_ROOT="c:\folder\to\boost_1_55_0" -DBOOST_LIBRARYDIR="c:\folder\to\boost_1_55_0\lib64-msvc-12.0" -msbuild Project.sln /p:Configuration=Release ``` -* If you don't have your path environment variable configured with the VS paths, you may may want to run `C:\program files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat` (or equivalent) to temporarily set the environment variables. +* If you are on a 64-bit system, run: +``` +cmake -G "MSYS Makefiles" -D CMAKE_BUILD_TYPE=Release -D CMAKE_TOOLCHAIN_FILE=../cmake/64-bit-toolchain.cmake -D MSYS2_FOLDER=c:/msys64 .. +``` +* If you are on a 32-bit system, run: +``` +cmake -G "MSYS Makefiles" -D CMAKE_BUILD_TYPE=Release -D CMAKE_TOOLCHAIN_FILE=../cmake/32-bit-toolchain.cmake -D MSYS2_FOLDER=c:/msys32 .. +``` +* You can now run `make` to have it build + +If you installed MSYS2 in a folder other than c:/msys64, make the appropriate substitution above. ### On FreeBSD: From fffca2b1e4e4a78928f55cda5d9ecc90487c4223 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Tue, 23 Sep 2014 18:18:23 +0200 Subject: [PATCH 32/63] updated mingw build instructions --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index cd5410c6..01215361 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ pacman -Su * Install dependencies: `pacman -S mingw-w64-x86_64-gcc make mingw-w64-x86_64-cmake` (note: in future, once the boost 1.56 mingw-w64 issues are fixed, you can add `mingw-w64-x86_64-boost` to that list to have it installed as well) * Download the [boost 1.55 msys2 package](http://downloads.sourceforge.net/project/msys2/REPOS/MINGW/x86_64/mingw-w64-x86_64-boost-1.55.0-7-any.pkg.tar.xz), and install it by running `pacman -U mingw-w64-x86_64-boost-1.55.0-7-any.pkg.tar.xz` -**Building* +**Building** * From the root of the source code directory run: ``` From 564a9f4cb52f9aaf9c9a18ebb4e854972584c9b6 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Tue, 23 Sep 2014 22:57:42 +0200 Subject: [PATCH 33/63] added unbound dependencies to readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 01215361..6f5b45d8 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Parts of the project are originally copyright (c) 2012-2013 The Cryptonote devel ### On Unix and Linux: -Dependencies: GCC 4.7.3 or later, CMake 2.8.6 or later, and Boost 1.53 or later (except 1.54, [more details here](http://goo.gl/RrCFmA)). +Dependencies: GCC 4.7.3 or later, CMake 2.8.6 or later, Unbound 1.4.16 or later, and Boost 1.53 or later (except 1.54, [more details here](http://goo.gl/RrCFmA)). **Basic Process:** @@ -77,7 +77,7 @@ Alternatively, it can be built in an easier and more automated fashion using Hom ### On Windows: -Dependencies: mingw-w64, msys2, CMake 2.8.6 or later, and Boost 1.53 or 1.55 (except 1.54, [more details here](http://goo.gl/RrCFmA), and 1.56 as it causes an internal compiler error on mingw-w64). +Dependencies: mingw-w64, msys2, CMake 2.8.6 or later, Unbound 1.4.16 or later, and Boost 1.53 or 1.55 (except 1.54, [more details here](http://goo.gl/RrCFmA), and 1.56 as it causes an internal compiler error on mingw-w64). **Preparing the Build Environment** @@ -90,7 +90,7 @@ pacman -Su --ignoregroup base pacman -Su ``` * For those of you already familiar with pacman, you can run the normal `pacman -Syu` to update, but you may get errors and need to restart MSYS2 if pacman's dependencies are updated. -* Install dependencies: `pacman -S mingw-w64-x86_64-gcc make mingw-w64-x86_64-cmake` (note: in future, once the boost 1.56 mingw-w64 issues are fixed, you can add `mingw-w64-x86_64-boost` to that list to have it installed as well) +* Install dependencies: `pacman -S mingw-w64-x86_64-gcc make mingw-w64-x86_64-cmake mingw-w64-x86_64-unbound` (note: in future, once the boost 1.56 mingw-w64 issues are fixed, you can add `mingw-w64-x86_64-boost` to that list to have it installed as well) * Download the [boost 1.55 msys2 package](http://downloads.sourceforge.net/project/msys2/REPOS/MINGW/x86_64/mingw-w64-x86_64-boost-1.55.0-7-any.pkg.tar.xz), and install it by running `pacman -U mingw-w64-x86_64-boost-1.55.0-7-any.pkg.tar.xz` **Building** From 1ae6db25e6c11cc22d308b96b6c50b225b91c5c7 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 14:55:28 -0400 Subject: [PATCH 34/63] 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 diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp new file mode 100644 index 00000000..0bacc4d4 --- /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 From dea98df6b1ae9a3f5b062f9d0be61e1fc1313b28 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 15:17:31 -0400 Subject: [PATCH 35/63] 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 diff --git a/CMake/FindUnbound.cmake b/CMake/FindUnbound.cmake new file mode 100644 index 00000000..3d2e8f6d --- /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 87567473..6a2c66bc 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 28bffea1..7cef257d 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 8bc68d9b..1c0bff67 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") From 578050e91d8fad8834a7c180a15824f5a46940f9 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 15:35:52 -0400 Subject: [PATCH 36/63] 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 | 107 ++++++++++++++++++++++++++---- 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, 226 insertions(+), 34 deletions(-) create mode 100644 tests/unit_tests/dns_resolver.cpp diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index 0bacc4d4..f95a8d72 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; +}; - std::vector get_ipv4(const std::string& uri) +DNSResolver::DNSResolver() : m_data(new DNSResolverData()) +{ + // init libunbound context + m_data->m_ub_context = ub_ctx_create(); + + // 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 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)) + { + if (result->havedata) + { + 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::vector get_ipv6(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)) { - std::vectorhavedata) + { + 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); + } + } + } } - std::string get_payment_address(const std::string& uri) - { - std::string retval; - return retval; - } + // 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) + { + staticInstance = new DNSResolver(); + } + return *staticInstance; +} -} // namespace dns } // namespace tools diff --git a/src/common/dns_utils.h b/src/common/dns_utils.h index 2919100d..6697d8ff 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(const std::string& uri); + DNSResolver(); /** - * @brief gets ipv4 addresses from DNS query + * @brief takes care of freeing C pointers and such + */ + ~DNSResolver(); + + /** + * @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 759b21fc..53a13f32 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 954d794b..60bc870e 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 00000000..fe8fe602 --- /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()); +} From 9a3b18dbc25632b801611f5030707fff5c6b098d Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 15:38:15 -0400 Subject: [PATCH 37/63] Use the loop iterator, previous version of me. --- src/common/dns_utils.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index f95a8d72..e3be7937 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); } From 3fb0fc020f4af5038ce4b2d99578aecb625cda6a Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 17:25:19 -0400 Subject: [PATCH 38/63] 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 | 154 +++++++++++++++++++++++++++++++------------ 1 file changed, 112 insertions(+), 42 deletions(-) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 60bc870e..34895a29 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) { - 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); + // make sure port in valid range (could check > 1000, really) + if (portNum < 65536 && portNum > 0) + { + return false; + } } else { - LOG_PRINT_L2("IPv6 doesn't supported, skip '" << host << "' -> " << endpoint.address().to_v6().to_string(ec)); + 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 = 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 + { + 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"); } } From a5757a628f0da0affae66345a5f3209a44613d56 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 17:26:51 -0400 Subject: [PATCH 39/63] 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 diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index e3be7937..2ad98ca2 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 6697d8ff..ff54c1e0 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 9ba6f245..adc9c1f6 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 3311e343..6e6d7caf 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 00000000..18025718 --- /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 fe8fe602..3b52a5f4 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()); +} From f437cb58bf4556ecd18e570a89036c590ff2c997 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 17:38:15 -0400 Subject: [PATCH 40/63] 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(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index fbe7c473..07b2f793 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]); From c14c7e16839b6cfe32527f2b01a9a1507e3d419e Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 17:38:54 -0400 Subject: [PATCH 41/63] 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(-) diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index 2ad98ca2..6755a30b 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 ff54c1e0..e57e5586 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 07b2f793..e2564236 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 adc9c1f6..3161f3b1 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 6e6d7caf..90918677 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 18025718..22301d56 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 3b52a5f4..27e981ef 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; + } } From 5bd343778fb5da91c81d086ca02580a0f0ea65b1 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 17:44:35 -0400 Subject: [PATCH 42/63] Fixed CMake search for libunbound As it turns out, some of CMake's built-in modules for detecting headers and libraries don't work if you have certain compiler flags set, such as -Werror=old-style-definition, as they do "int main()" rather than "int main(void)". Having CMake search for libs before compiler flags are set alleviates this issue, and I believe the underlying issue will be fixed in future releases of CMake. --- CMakeLists.txt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a2c66bc..1f8222a3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,8 @@ if (UNIX AND NOT APPLE) find_package(Threads) endif() +find_package(Unbound REQUIRED) + 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__") # set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Dinline=__inline") @@ -197,11 +199,6 @@ 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 From 24f325a33d149125b7cf5e91615cbc9e5b686a2b Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 17 Sep 2014 18:37:32 -0400 Subject: [PATCH 43/63] Fixed artifacts from cherry-picking devel->master --- CMakeLists.txt | 3 ++- src/simplewallet/simplewallet.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f8222a3..c9a794c9 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 e2564236..37974088 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 { From 1dece111cc7a97101f53fb3944385c1249ed6e40 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Thu, 18 Sep 2014 09:07:46 -0400 Subject: [PATCH 44/63] 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(-) diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index 6755a30b..60f00916 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 e57e5586..375f6ba3 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 From 1e193d687de908d466d0c24f162befa66ad84e6b Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Tue, 23 Sep 2014 19:27:03 -0400 Subject: [PATCH 45/63] temp commit --- src/common/dns_utils.cpp | 57 +++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index 60f00916..ab41ea60 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])); } } } From d1a7f699c67fc8c5b43b3119d9e577ef97a22c37 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Wed, 24 Sep 2014 14:45:34 +0200 Subject: [PATCH 46/63] use boost::asio::ip::address because cross-platform plz --- src/p2p/net_node.inl | 123 ++++++++++--------------------------------- 1 file changed, 27 insertions(+), 96 deletions(-) diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl index 34895a29..08fd1d1e 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); + 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); } - -/* 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 { - 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; } } From 777d1ac93071ef0562bc0459d788c8907c2a2213 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Wed, 24 Sep 2014 20:08:50 +0200 Subject: [PATCH 47/63] added tomerkon's GPG key, cmake folder fix --- {cmake => cmaketmp}/32-bit-toolchain.cmake | 0 {cmake => cmaketmp}/64-bit-toolchain.cmake | 0 {CMake => cmaketmp}/FindUnbound.cmake | 0 utils/gpg_keys/tomerkon.asc | 30 ++++++++++++++++++++++ 4 files changed, 30 insertions(+) rename {cmake => cmaketmp}/32-bit-toolchain.cmake (100%) rename {cmake => cmaketmp}/64-bit-toolchain.cmake (100%) rename {CMake => cmaketmp}/FindUnbound.cmake (100%) create mode 100644 utils/gpg_keys/tomerkon.asc diff --git a/cmake/32-bit-toolchain.cmake b/cmaketmp/32-bit-toolchain.cmake similarity index 100% rename from cmake/32-bit-toolchain.cmake rename to cmaketmp/32-bit-toolchain.cmake diff --git a/cmake/64-bit-toolchain.cmake b/cmaketmp/64-bit-toolchain.cmake similarity index 100% rename from cmake/64-bit-toolchain.cmake rename to cmaketmp/64-bit-toolchain.cmake diff --git a/CMake/FindUnbound.cmake b/cmaketmp/FindUnbound.cmake similarity index 100% rename from CMake/FindUnbound.cmake rename to cmaketmp/FindUnbound.cmake diff --git a/utils/gpg_keys/tomerkon.asc b/utils/gpg_keys/tomerkon.asc new file mode 100644 index 00000000..4e946a6e --- /dev/null +++ b/utils/gpg_keys/tomerkon.asc @@ -0,0 +1,30 @@ +-----BEGIN PGP PUBLIC KEY BLOCK----- +Version: GnuPG v1 + +mQENBFQi1rkBCAC/hoa6yhCpPG3tZINuGBbY/dJWIlKECJ/3dgDN/LMumHqEH91X +goS6Ulw0R+fwDWna/bYMWHNbw9mBujHfaZDBCmMzfbcMgAt1jC/+rnd39rNPcvh+ +4gpRx6Wt20hxqtkNAnND+5ce9t4RA9wXjZA2/M5R9EYXX/Xna0Z6tWkB51aKkxm4 +N5Wz6PmUjScmhCd1IP7P/yDv6Aen6M8Lu8ogCfui1C3a6Cel8MevfkC9fGCkMvoq +3v5NhEVop8Q8Am4Ts+DOcDNXSp8GPUlhyBy1cK7NelxLADM+TFtkPapEJZedW1KR ++V/nn3L1pKoT2XJAWWi0VXwpLIwrYQJuqrK1ABEBAAG0IXRvbWVyIGtvbmZvcnR5 +IDx0b21lcmtAa29uNDAuY29tPokBOAQTAQIAIgUCVCLWuQIbAwYLCQgHAwIGFQgC +CQoLBBYCAwECHgECF4AACgkQlqdxPzlO6quNRQgAratbsWbgSphSaBgLHrRYpO2D +8TWsK5Qy9ZxGVud2ynmXKcUZukqWRyw9+X22wpNTCeZNHI7srGohF7SeyfIemSx9 +7OfN6Tu2hxz1zi1lq7hMnCNoI9UQSdZaGDm+loI07OnMHugit7ojn9lcW3CKUYzP +AfTc1IAV5ZQpwPmPN0yf6SKnFIkD3X9SZRWhGeoUOZKr2KEMvBpNWoFfee91cCR2 +eTiTkaIE8P6Cfdv6rdlQFNqsj7TuBq6Zfru1DtUOdHYs089KR0av81W+U2RpGXc2 +AfOmn4kzVffZXdh6D/i4oTg8D6YcVvOZzVtAJVshayYSjD09kjNw+uKAO0nyebkB +DQRUIta5AQgA23KCSdFdnvTJK+kOcMD/99zZz1XMcqpjBc2aP8+zdilC6XjZDjcg +8+NSdOCYCCHeO80Zd16yynrjvUW4D+PnaM3thdoigYJjEelx7wJls7C4U8hKfcFs +U3YhZEKm2vXqomgrpCT5NExHcOjzi5yMUQ7ocUct79jui0XRhzkmj0vu67rSRWpT +fSpvBwrhCUnC71aNy2QgbadxziLw2Gm983cpdO/wd3wnoz3JTXAYntJOg+7Q8VDg +fiYesuPpCiAJLKZ3z/b5kQXMnK82Oi8H5FTFb10OEDhbgyIqABWOXmds2Uj211ux +Ui5IIH4AScKvo+iKRbgWCs1kCkXQaD9OvQARAQABiQEfBBgBAgAJBQJUIta5AhsM +AAoJEJancT85TuqrSCwH/Rpnp+35opS9b1MvfhUBuJAjIPy9tVwMuz4+NyUfh+g6 +M3ksbtGbzZ8EWZi3KJ3iQVdcwvzzMYZxFPXeLmH/FLu37uFtLTlBg7SDEzoHV6dE +/dvGtYRFM7/QdCu9rrWt7zaEDjH7UnasGoZ6mY/v78UK7Q506w7fG8rtMFFupq7D +rWfuA8Dbq31FJ0hdbkezGEF55+jsRwIqmVGHaNvdTm+GyiFibwkc7p6+ynBco8xv +zr98VSNx5fM50XBc+pzhAHxzxhIgrmwx5zsQxMmd8pAh4deZUKIyk40XKrwikjoy +KLjUdEc73bEjhr1rlVGj6tBVNspHVx5XbUvmDtD1s7E= +=EaRm +-----END PGP PUBLIC KEY BLOCK----- \ No newline at end of file From 71f4b10b15fb5f6764da9f8e5cdce03d62ff015b Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Wed, 24 Sep 2014 20:09:30 +0200 Subject: [PATCH 48/63] fixed cmake folder --- {cmaketmp => cmake}/32-bit-toolchain.cmake | 0 {cmaketmp => cmake}/64-bit-toolchain.cmake | 0 {cmaketmp => cmake}/FindUnbound.cmake | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename {cmaketmp => cmake}/32-bit-toolchain.cmake (100%) rename {cmaketmp => cmake}/64-bit-toolchain.cmake (100%) rename {cmaketmp => cmake}/FindUnbound.cmake (100%) diff --git a/cmaketmp/32-bit-toolchain.cmake b/cmake/32-bit-toolchain.cmake similarity index 100% rename from cmaketmp/32-bit-toolchain.cmake rename to cmake/32-bit-toolchain.cmake diff --git a/cmaketmp/64-bit-toolchain.cmake b/cmake/64-bit-toolchain.cmake similarity index 100% rename from cmaketmp/64-bit-toolchain.cmake rename to cmake/64-bit-toolchain.cmake diff --git a/cmaketmp/FindUnbound.cmake b/cmake/FindUnbound.cmake similarity index 100% rename from cmaketmp/FindUnbound.cmake rename to cmake/FindUnbound.cmake From bff1f9d4c4c33a12349bc3e861fe4d387b749a74 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Wed, 24 Sep 2014 20:38:24 +0200 Subject: [PATCH 49/63] redo FindUnbound.cmake --- CMakeLists.txt | 4 ++++ cmake/FindUnbound.cmake | 48 ++++++++++++++++++++--------------------- src/CMakeLists.txt | 8 +++---- 3 files changed, 31 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c9a794c9..fcbd64ce 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 3d2e8f6d..8d6f4ae7 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) +MESSAGE("Looking for libunbound") -set (Unbound_FOUND FALSE) -MESSAGE("Attempting to find 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_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}") +find_library(UNBOUND_LIBRARIES unbound) -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) +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 7cef257d..e5502cdb 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) From f93de2f553cb47dbae0eb368bf177c00821d0c0e Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Wed, 24 Sep 2014 20:42:54 +0200 Subject: [PATCH 50/63] fixed unbound libs in test --- tests/CMakeLists.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1c0bff67..92c21dad 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} ${CMAKE_UNBOUND_LIB}) -target_link_libraries(coretests cryptonote_core common crypto ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) +target_link_libraries(core_proxy cryptonote_core common crypto ${UNBOUND_LIBRARIES} ${UPNP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +target_link_libraries(coretests cryptonote_core common crypto ${UNBOUND_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) target_link_libraries(difficulty-tests cryptonote_core) -target_link_libraries(functional_tests cryptonote_core wallet common crypto ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} ${CMAKE_UNBOUND_LIB}) +target_link_libraries(functional_tests cryptonote_core wallet common crypto ${UNBOUND_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) 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} ${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}) +target_link_libraries(performance_tests cryptonote_core common crypto ${UNBOUND_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +target_link_libraries(unit_tests gtest_main cryptonote_core wallet crypto common ${UNBOUND_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +target_link_libraries(net_load_tests_clt cryptonote_core common crypto gtest_main ${UNBOUND_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +target_link_libraries(net_load_tests_srv cryptonote_core common crypto gtest_main ${UNBOUND_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) 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") From 524eae58cce1ce22d8a2b0aacbdb567fca75de72 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Wed, 24 Sep 2014 20:57:09 +0200 Subject: [PATCH 51/63] never use the baked-in miniupnpc on FreeBSD because explosions --- CMakeLists.txt | 2 -- external/CMakeLists.txt | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fcbd64ce..5655bfc8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -212,7 +212,5 @@ else() include_directories(${UPNP_INCLUDE}) endif() - - add_subdirectory(src) add_subdirectory(tests) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 177c2115..f75c420e 100755 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -216,7 +216,7 @@ MARK_AS_ADVANCED(MINIUPNP_INCLUDE_DIR MINIUPNP_LIBRARY) # And now on to the Monero part of things -if(MINIUPNP_FOUND AND MINIUPNPC_VERSION_1_7_OR_HIGHER AND !STATIC) +if(MINIUPNP_FOUND AND MINIUPNPC_VERSION_1_7_OR_HIGHER AND !STATIC AND !FREEBSD) message(STATUS "Using shared miniupnpc found at ${MINIUPNP_INCLUDE_DIR}") set(UPNP_STATIC false PARENT_SCOPE) From dda5a03146b3b709db1489edc5aa10d92d6a3fee Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Wed, 24 Sep 2014 21:23:23 +0200 Subject: [PATCH 52/63] fixed FreeBSD miniupnpc niggly --- external/CMakeLists.txt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index f75c420e..f121162d 100755 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -216,7 +216,20 @@ MARK_AS_ADVANCED(MINIUPNP_INCLUDE_DIR MINIUPNP_LIBRARY) # And now on to the Monero part of things -if(MINIUPNP_FOUND AND MINIUPNPC_VERSION_1_7_OR_HIGHER AND !STATIC AND !FREEBSD) +# FreeBSD doesn't play well with the local copy +SET(USE_SHARED false) + +# If we have the correct shared version and we're not building static, use it +IF(MINIUPNP_FOUND AND MINIUPNPC_VERSION_1_7_OR_HIGHER AND !STATIC) + SET(USE_SHARED true) +ENDIF() + +# If we're on FreeBSD +IF(FREEBSD) + SET(USE_SHARED true) +ENDIF() + +if(USE_SHARED) message(STATUS "Using shared miniupnpc found at ${MINIUPNP_INCLUDE_DIR}") set(UPNP_STATIC false PARENT_SCOPE) From 400f1016dd5c978a49cb90898c7a34edf4de5ed2 Mon Sep 17 00:00:00 2001 From: iamsmooth Date: Tue, 23 Sep 2014 12:55:19 +0000 Subject: [PATCH 53/63] checkpoints --- src/cryptonote_core/checkpoints_create.h | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h index 9d65dc24..b5901a86 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; } } From b1d586af4b6a9c2035c3a33b66ed281266ce8060 Mon Sep 17 00:00:00 2001 From: iamsmooth Date: Tue, 23 Sep 2014 20:41:04 +0000 Subject: [PATCH 54/63] checkpoint --- src/cryptonote_core/checkpoints_create.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h index b5901a86..2fc7ab54 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; } } From c428c29051f3837c344b025e220f572b1ffbe86a Mon Sep 17 00:00:00 2001 From: iamsmooth Date: Tue, 23 Sep 2014 21:21:12 +0000 Subject: [PATCH 55/63] checkpoints --- src/cryptonote_core/checkpoints_create.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h index 2fc7ab54..314f10ca 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"); From d19cf1f458ae194bfbbe59add0bb2f5eb5b4fd44 Mon Sep 17 00:00:00 2001 From: iamsmooth Date: Wed, 24 Sep 2014 07:14:39 +0000 Subject: [PATCH 56/63] checkpoint --- src/cryptonote_core/checkpoints_create.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h index 314f10ca..c124ed3a 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; } } From 9956b68b1838874ad8b58d93494f6a982307e216 Mon Sep 17 00:00:00 2001 From: iamsmooth Date: Wed, 24 Sep 2014 21:25:50 +0000 Subject: [PATCH 57/63] checkpoint --- src/cryptonote_core/checkpoints_create.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cryptonote_core/checkpoints_create.h b/src/cryptonote_core/checkpoints_create.h index c124ed3a..f75829ab 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; } From 06a4578bf253cfde6f0ab352994b3aadf61ec372 Mon Sep 17 00:00:00 2001 From: Tomer Konforty Date: Wed, 24 Sep 2014 17:36:04 +0300 Subject: [PATCH 58/63] 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(+) diff --git a/src/cryptonote_core/checkpoints.cpp b/src/cryptonote_core/checkpoints.cpp index 3669a721..c76a2384 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 11c4b5eb..3dee4868 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 f75829ab..7512ddd9 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 5eda6cb6..5c209482 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); From 738357459b355862d35005ab7165b317cc37586d Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 24 Sep 2014 19:55:19 -0400 Subject: [PATCH 59/63] libunbound has const correctness issues... --- src/common/dns_utils.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index ab41ea60..e1151e19 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) { From 4e2b2b942daa4206ec44c66e59863670dfe3fde4 Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Wed, 24 Sep 2014 22:28:25 +0200 Subject: [PATCH 60/63] 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 +- .../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(-) diff --git a/src/common/varint.h b/src/common/varint.h index 5a73c274..57386597 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 dfdfa03e..fca4e227 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 964d61e2..e6aa679d 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 ba2aed01..e9ab2011 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 33cad30c..e46bd390 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 9fa7f054..58186b8c 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 81f93201..3764cfe7 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 7617765c..fb623a3d 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 4a254b5a..3ae5bcdf 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; From 22481244535e05bb308eedf9c2d2a5abe2d79a9d Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 24 Sep 2014 17:15:49 -0400 Subject: [PATCH 61/63] 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(-) diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index e1151e19..4b43c749 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 375f6ba3..d22e3fb1 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; /** From fab95aef64e2e5ba209ca2f27763a8db489d4294 Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 24 Sep 2014 23:19:14 -0400 Subject: [PATCH 62/63] 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(-) diff --git a/src/common/dns_utils.cpp b/src/common/dns_utils.cpp index 4b43c749..346761e7 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 d22e3fb1..dd6946dc 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; From 59a8366bb18653f14142321a9d85377ceaef8fad Mon Sep 17 00:00:00 2001 From: Riccardo Spagni Date: Thu, 25 Sep 2014 08:24:42 +0200 Subject: [PATCH 63/63] 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 +- .../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(-) diff --git a/src/common/varint.h b/src/common/varint.h index 57386597..5a73c274 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 fca4e227..dfdfa03e 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 e6aa679d..964d61e2 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 e9ab2011..ba2aed01 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 e46bd390..33cad30c 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 58186b8c..9fa7f054 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 3764cfe7..81f93201 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 fb623a3d..7617765c 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 3ae5bcdf..4a254b5a 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;