forked from townforge/townforge
Merge remote-tracking branch 'origin/master' into cc
This commit is contained in:
commit
931773c40e
43
.github/workflows/build.yml
vendored
43
.github/workflows/build.yml
vendored
@ -14,7 +14,7 @@ jobs:
|
||||
submodules: recursive
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.ccache
|
||||
path: /Users/runner/Library/Caches/ccache
|
||||
key: ccache-macos-build-${{ github.sha }}
|
||||
restore-keys: ccache-macos-build-
|
||||
- name: install dependencies
|
||||
@ -26,6 +26,10 @@ jobs:
|
||||
|
||||
build-windows:
|
||||
runs-on: windows-latest
|
||||
env:
|
||||
CCACHE_COMPRESS: 1
|
||||
CCACHE_TEMPDIR: C:\Users\runneradmin\.ccache-temp
|
||||
CCACHE_DIR: C:\Users\runneradmin\.ccache
|
||||
defaults:
|
||||
run:
|
||||
shell: msys2 {0}
|
||||
@ -33,12 +37,19 @@ jobs:
|
||||
- uses: actions/checkout@v1
|
||||
with:
|
||||
submodules: recursive
|
||||
- uses: actions/cache@v2
|
||||
with:
|
||||
path: C:\Users\runneradmin\.ccache
|
||||
key: ccache-windows-build-${{ github.sha }}
|
||||
restore-keys: ccache-windows-build-
|
||||
- uses: eine/setup-msys2@v2
|
||||
with:
|
||||
update: true
|
||||
install: mingw-w64-x86_64-toolchain make mingw-w64-x86_64-cmake mingw-w64-x86_64-boost mingw-w64-x86_64-openssl mingw-w64-x86_64-zeromq mingw-w64-x86_64-libsodium mingw-w64-x86_64-hidapi mingw-w64-x86_64-protobuf-c mingw-w64-x86_64-libusb git
|
||||
install: mingw-w64-x86_64-toolchain make mingw-w64-x86_64-cmake mingw-w64-x86_64-ccache mingw-w64-x86_64-boost mingw-w64-x86_64-openssl mingw-w64-x86_64-zeromq mingw-w64-x86_64-libsodium mingw-w64-x86_64-hidapi mingw-w64-x86_64-protobuf-c mingw-w64-x86_64-libusb git
|
||||
- name: build
|
||||
run: make release-static-win64 -j2
|
||||
run: |
|
||||
ccache --max-size=150M
|
||||
make release-static-win64 -j2
|
||||
|
||||
build-ubuntu:
|
||||
runs-on: ubuntu-latest
|
||||
@ -104,10 +115,19 @@ jobs:
|
||||
test-ubuntu:
|
||||
needs: build-ubuntu
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
CCACHE_COMPRESS: 1
|
||||
CCACHE_TEMPDIR: /tmp/.ccache-temp
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: ccache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.ccache
|
||||
key: test-ubuntu-ccache-${{ github.sha }}
|
||||
restore-keys: test-ubuntu-ccache-
|
||||
- name: remove bundled boost
|
||||
run: sudo rm -rf /usr/local/share/boost
|
||||
- name: set apt conf
|
||||
@ -118,10 +138,19 @@ jobs:
|
||||
- name: update apt
|
||||
run: sudo apt update
|
||||
- name: install monero dependencies
|
||||
run: sudo apt -y install build-essential cmake libboost-all-dev miniupnpc libunbound-dev graphviz doxygen libunwind8-dev pkg-config libssl-dev libzmq3-dev libsodium-dev libhidapi-dev libnorm-dev libusb-1.0-0-dev libpgm-dev libprotobuf-dev protobuf-compiler
|
||||
- name: install requests
|
||||
run: pip install requests
|
||||
run: sudo apt -y install build-essential cmake libboost-all-dev miniupnpc libunbound-dev graphviz doxygen libunwind8-dev pkg-config libssl-dev libzmq3-dev libsodium-dev libhidapi-dev libnorm-dev libusb-1.0-0-dev libpgm-dev libprotobuf-dev protobuf-compiler ccache
|
||||
- name: install Python dependencies
|
||||
run: pip install requests psutil monotonic
|
||||
- name: tests
|
||||
env:
|
||||
CTEST_OUTPUT_ON_FAILURE: ON
|
||||
run: make release-test -j3
|
||||
run: |
|
||||
ccache --max-size=150M
|
||||
DIR_BUILD="build/ci/release"
|
||||
DIR_SRC="`pwd`"
|
||||
mkdir -p "${DIR_BUILD}" && cd "${DIR_BUILD}"
|
||||
cmake -S "${DIR_SRC}" -D ARCH="default" -D BUILD_SHARED_LIBS=ON -D BUILD_TESTS=ON -D CMAKE_BUILD_TYPE=release && make -j3 && make test
|
||||
|
||||
# ARCH="default" (not "native") ensures, that a different execution host can execute binaries compiled elsewhere.
|
||||
# BUILD_SHARED_LIBS=ON speeds up the linkage part a bit, reduces size, and is the only place where the dynamic linkage is tested.
|
||||
|
||||
|
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -4,8 +4,7 @@
|
||||
branch = monero
|
||||
[submodule "external/miniupnp"]
|
||||
path = external/miniupnp
|
||||
url = https://github.com/monero-project/miniupnp
|
||||
branch = monero
|
||||
url = https://github.com/miniupnp/miniupnp
|
||||
[submodule "external/rapidjson"]
|
||||
path = external/rapidjson
|
||||
url = https://github.com/Tencent/rapidjson
|
||||
|
@ -500,7 +500,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "(SunOS|Solaris)")
|
||||
endif ()
|
||||
|
||||
if (APPLE AND NOT IOS)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=x86-64 -fvisibility=default -std=c++11")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=default -std=c++11")
|
||||
if (NOT OPENSSL_ROOT_DIR)
|
||||
EXECUTE_PROCESS(COMMAND brew --prefix openssl
|
||||
OUTPUT_VARIABLE OPENSSL_ROOT_DIR
|
||||
@ -568,6 +568,20 @@ add_definitions(-DAUTO_INITIALIZE_EASYLOGGINGPP)
|
||||
set(MONERO_GENERATED_HEADERS_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated_include")
|
||||
include_directories(${MONERO_GENERATED_HEADERS_DIR})
|
||||
|
||||
option(COVERAGE "Enable profiling for test coverage report" OFF)
|
||||
if(COVERAGE)
|
||||
message(STATUS "Building with profiling for test coverage report")
|
||||
endif()
|
||||
macro (monero_enable_coverage)
|
||||
if(COVERAGE)
|
||||
foreach(COV_FLAG -fprofile-arcs -ftest-coverage --coverage)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COV_FLAG}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COV_FLAG}")
|
||||
endforeach()
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
|
||||
# Generate header for embedded translations
|
||||
# Generate header for embedded translations, use target toolchain if depends, otherwise use the
|
||||
# lrelease and lupdate binaries from the host
|
||||
@ -577,7 +591,7 @@ ExternalProject_Add(generate_translations_header
|
||||
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/translations"
|
||||
STAMP_DIR ${LRELEASE_PATH}
|
||||
CMAKE_ARGS -DLRELEASE_PATH=${LRELEASE_PATH}
|
||||
INSTALL_COMMAND cmake -E echo "")
|
||||
INSTALL_COMMAND ${CMAKE_COMMAND} -E echo "")
|
||||
include_directories("${CMAKE_CURRENT_BINARY_DIR}/translations")
|
||||
add_subdirectory(external)
|
||||
|
||||
@ -609,6 +623,17 @@ endif()
|
||||
# Trezor support check
|
||||
include(CheckTrezor)
|
||||
|
||||
# As of OpenBSD 6.8, -march=<anything> breaks the build
|
||||
function(set_default_arch)
|
||||
if (OPENBSD)
|
||||
set(ARCH default)
|
||||
else()
|
||||
set(ARCH native)
|
||||
endif()
|
||||
|
||||
set(ARCH ${ARCH} CACHE STRING "CPU to build for: -march value or 'default' to not pass -march at all")
|
||||
endfunction()
|
||||
|
||||
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")
|
||||
@ -622,7 +647,7 @@ if(MSVC)
|
||||
else()
|
||||
include(TestCXXAcceptsFlag)
|
||||
if (NOT ARCH)
|
||||
set(ARCH native CACHE STRING "CPU to build for: -march value or 'default' to not pass -march at all")
|
||||
set_default_arch()
|
||||
endif()
|
||||
message(STATUS "Building on ${CMAKE_SYSTEM_PROCESSOR} for ${ARCH}")
|
||||
if(ARCH STREQUAL "default")
|
||||
@ -684,7 +709,7 @@ else()
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${ARCH_FLAG}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ARCH_FLAG}")
|
||||
|
||||
set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-unused-variable -Wno-error=unused-variable -Wno-error=undef -Wno-error=uninitialized")
|
||||
set(WARNINGS "-Wall -Wextra -Wpointer-arith -Wundef -Wvla -Wwrite-strings -Wno-error=extra -Wno-error=deprecated-declarations -Wno-unused-parameter -Wno-error=unused-variable -Wno-error=undef -Wno-error=uninitialized")
|
||||
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
|
||||
if(ARM)
|
||||
set(WARNINGS "${WARNINGS} -Wno-error=inline-asm")
|
||||
@ -720,13 +745,7 @@ else()
|
||||
set(STATIC_ASSERT_CPP_FLAG "-Dstatic_assert=_Static_assert")
|
||||
endif()
|
||||
|
||||
option(COVERAGE "Enable profiling for test coverage report" 0)
|
||||
|
||||
if(COVERAGE)
|
||||
message(STATUS "Building with profiling for test coverage report")
|
||||
set(COVERAGE_FLAGS "-fprofile-arcs -ftest-coverage --coverage")
|
||||
endif()
|
||||
|
||||
monero_enable_coverage()
|
||||
# With GCC 6.1.1 the compiled binary malfunctions due to aliasing. Until that
|
||||
# is fixed in the code (Issue #847), force compiler to be conservative.
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-strict-aliasing")
|
||||
@ -769,9 +788,10 @@ else()
|
||||
endif()
|
||||
|
||||
# linker
|
||||
if (NOT SANITIZE AND NOT OSSFUZZ AND NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 9.1)))
|
||||
if (NOT SANITIZE AND NOT OSSFUZZ AND NOT (WIN32 AND (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND (CMAKE_C_COMPILER_VERSION VERSION_LESS 9.1 OR NOT STATIC))))
|
||||
# PIE executables randomly crash at startup with ASAN
|
||||
# Windows binaries die on startup with PIE when compiled with GCC <9.x
|
||||
# Windows dynamically-linked binaries die on startup with PIE regardless of GCC version
|
||||
add_linker_flag_if_supported(-pie LD_SECURITY_FLAGS)
|
||||
endif()
|
||||
add_linker_flag_if_supported(-Wl,-z,relro LD_SECURITY_FLAGS)
|
||||
@ -804,8 +824,8 @@ else()
|
||||
message(STATUS "Using C++ security hardening flags: ${CXX_SECURITY_FLAGS}")
|
||||
message(STATUS "Using linker security hardening flags: ${LD_SECURITY_FLAGS}")
|
||||
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${C_WARNINGS} ${COVERAGE_FLAGS} ${PIC_FLAG} ${C_SECURITY_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_CPP_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${COVERAGE_FLAGS} ${PIC_FLAG} ${CXX_SECURITY_FLAGS}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_FLAG} ${WARNINGS} ${C_WARNINGS} ${PIC_FLAG} ${C_SECURITY_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -D_GNU_SOURCE ${MINGW_FLAG} ${STATIC_ASSERT_CPP_FLAG} ${WARNINGS} ${CXX_WARNINGS} ${PIC_FLAG} ${CXX_SECURITY_FLAGS}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LD_SECURITY_FLAGS} ${LD_BACKCOMPAT_FLAGS}")
|
||||
|
||||
# With GCC 6.1.1 the compiled binary malfunctions due to aliasing. Until that
|
||||
|
@ -55,8 +55,8 @@ RUN set -ex \
|
||||
ENV BOOST_ROOT /usr/local/boost_${BOOST_VERSION}
|
||||
|
||||
# OpenSSL
|
||||
ARG OPENSSL_VERSION=1.1.1g
|
||||
ARG OPENSSL_HASH=ddb04774f1e32f0c49751e21b67216ac87852ceb056b75209af2443400636d46
|
||||
ARG OPENSSL_VERSION=1.1.1i
|
||||
ARG OPENSSL_HASH=e8be6a35fe41d10603c3cc635e93289ed00bf34b79671a3a4de64fcee00d5242
|
||||
RUN set -ex \
|
||||
&& curl -s -O https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz \
|
||||
&& echo "${OPENSSL_HASH} openssl-${OPENSSL_VERSION}.tar.gz" | sha256sum -c \
|
||||
|
6
Doxyfile
6
Doxyfile
@ -68,7 +68,7 @@ OUTPUT_DIRECTORY = doc
|
||||
# performance problems for the file system.
|
||||
# The default value is: NO.
|
||||
|
||||
CREATE_SUBDIRS = NO
|
||||
CREATE_SUBDIRS = YES
|
||||
|
||||
# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII
|
||||
# characters to appear in the names of generated files. If set to NO, non-ASCII
|
||||
@ -754,7 +754,7 @@ WARN_LOGFILE =
|
||||
# spaces.
|
||||
# Note: If this tag is empty the current directory is searched.
|
||||
|
||||
INPUT = src
|
||||
INPUT = .
|
||||
|
||||
# This tag can be used to specify the character encoding of the source files
|
||||
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
|
||||
@ -1552,7 +1552,7 @@ EXTRA_SEARCH_MAPPINGS =
|
||||
# If the GENERATE_LATEX tag is set to YES doxygen will generate LaTeX output.
|
||||
# The default value is: YES.
|
||||
|
||||
GENERATE_LATEX = YES
|
||||
GENERATE_LATEX = NO
|
||||
|
||||
# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. If a
|
||||
# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of
|
||||
|
22
README.md
22
README.md
@ -1,7 +1,7 @@
|
||||
# Townforge
|
||||
|
||||
Copyright (c) 2019-2020 Crypto City
|
||||
Copyright (c) 2014-2020 The Monero Project.
|
||||
Copyright (c) 2019-2021 Crypto City
|
||||
Copyright (c) 2014-2021 The Monero Project.
|
||||
Portions Copyright (c) 2012-2013 The Cryptonote developers.
|
||||
|
||||
## Table of Contents
|
||||
@ -63,7 +63,7 @@ library archives (`.a`).
|
||||
| CMake | 3.5 | NO | `cmake` | `cmake` | `cmake` | `cmake` | NO | |
|
||||
| pkg-config | any | NO | `pkg-config` | `base-devel` | `base-devel` | `pkgconf` | NO | |
|
||||
| OpenSSL | basically any | NO | `libssl-dev` | `openssl` | `libressl-devel` | `openssl-devel` | NO | sha256 sum |
|
||||
| libzmq | 3.0.0 | NO | `libzmq3-dev` | `zeromq` | `zeromq-devel` | `zeromq-devel` | NO | ZeroMQ library |
|
||||
| libzmq | 4.2.0 | NO | `libzmq3-dev` | `zeromq` | `zeromq-devel` | `zeromq-devel` | NO | ZeroMQ library |
|
||||
| OpenPGM | ? | NO | `libpgm-dev` | `libpgm` | | `openpgm-devel` | NO | For ZeroMQ |
|
||||
| libnorm[2] | ? | NO | `libnorm-dev` | | | | YES | For ZeroMQ |
|
||||
| libunbound | 1.4.16 | YES | `libunbound-dev` | `unbound` | `unbound-devel` | `unbound-devel` | NO | DNS resolver |
|
||||
@ -74,6 +74,7 @@ library archives (`.a`).
|
||||
| ldns | 1.6.17 | NO | `libldns-dev` | `ldns` | `libldns-devel` | `ldns-devel` | YES | SSL toolkit |
|
||||
| expat | 1.1 | NO | `libexpat1-dev` | `expat` | `expat-devel` | `expat-devel` | YES | XML parsing |
|
||||
| GTest | 1.5 | YES | `libgtest-dev`[1] | `gtest` | `gtest-devel` | `gtest-devel` | YES | Test suite |
|
||||
| ccache | any | NO | `ccache` | `ccache` | `ccache` | `ccache` | YES | Compil. cache |
|
||||
| Doxygen | any | NO | `doxygen` | `doxygen` | `doxygen` | `doxygen` | YES | Documentation |
|
||||
| Graphviz | any | NO | `graphviz` | `graphviz` | `graphviz` | `graphviz` | YES | Documentation |
|
||||
| lrelease | ? | NO | `qttools5-dev-tools` | `qt5-tools` | `qt5-tools` | `qt5-linguist` | YES | Translations |
|
||||
@ -81,6 +82,7 @@ library archives (`.a`).
|
||||
| libusb | ? | NO | `libusb-1.0-0-dev` | `libusb` | `libusb-devel` | `libusbx-devel` | YES | Hardware wallet |
|
||||
| libprotobuf | ? | NO | `libprotobuf-dev` | `protobuf` | `protobuf-devel` | `protobuf-devel` | YES | Hardware wallet |
|
||||
| protoc | ? | NO | `protobuf-compiler` | `protobuf` | `protobuf` | `protobuf-compiler` | YES | Hardware wallet |
|
||||
| libudev | ? | No | `libudev-dev` | `systemd` | `eudev-libudev-devel` | `systemd-devel` | YES | Hardware wallet |
|
||||
| OpenGL[3] | ? | NO | | | | | NO | Graphics API |
|
||||
| libudev | ? | No | `libudev-dev` | `systemd` | `eudev-libudev-devel` | `systemd-devel` | YES | Hardware wallet |
|
||||
| flex | ? | No | | | | `flex` | NO | Script language |
|
||||
@ -93,7 +95,7 @@ build the library binary manually. This can be done with the following command `
|
||||
|
||||
Install all dependencies at once on Debian/Ubuntu:
|
||||
|
||||
``` sudo apt update && sudo apt install build-essential cmake pkg-config libboost-all-dev libssl-dev libzmq3-dev libunbound-dev libsodium-dev libunwind8-dev liblzma-dev libreadline6-dev libldns-dev libexpat1-dev doxygen graphviz libpgm-dev qttools5-dev-tools libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler libudev-dev libxinerama-dev libxrender-dev libxext-dev libgl1-mesa-dev xinput ```
|
||||
``` sudo apt update && sudo apt install build-essential cmake pkg-config libssl-dev libzmq3-dev libunbound-dev libsodium-dev libunwind8-dev liblzma-dev libreadline6-dev libldns-dev libexpat1-dev libpgm-dev qttools5-dev-tools libhidapi-dev libusb-1.0-0-dev libprotobuf-dev protobuf-compiler libudev-dev libboost-chrono-dev libboost-date-time-dev libboost-filesystem-dev libboost-locale-dev libboost-program-options-dev libboost-regex-dev libboost-serialization-dev libboost-system-dev libboost-thread-dev ccache doxygen graphviz libxinerama-dev libxrender-dev libxext-dev libgl1-mesa-dev xinput ```
|
||||
|
||||
Install all dependencies at once on macOS with the provided Brewfile:
|
||||
``` brew update && brew bundle --file=contrib/brew/Brewfile ```
|
||||
@ -111,6 +113,10 @@ If you already have a repo cloned, initialize and update:
|
||||
|
||||
`$ cd townforge && git submodule init && git submodule update`
|
||||
|
||||
*Note*: If there are submodule differences between branches, you may need
|
||||
to use ```git submodule sync && git submodule update``` after changing branches
|
||||
to build successfully.
|
||||
|
||||
### Build instructions
|
||||
|
||||
Townforge uses the CMake build system and a top-level [Makefile](Makefile) that
|
||||
@ -462,14 +468,16 @@ DNS_PUBLIC=tcp torsocks ./townforged --p2p-bind-ip 127.0.0.1 --no-igd --rpc-bind
|
||||
|
||||
## Pruning
|
||||
|
||||
As of May 2020, the full Monero blockchain file is about 80 GB. One can store a pruned blockchain, which is about 28 GB.
|
||||
As of May 2020, the full Monero blockchain file is about 100 GB. One can store a pruned blockchain, which is about 30 GB.
|
||||
A pruned blockchain can only serve part of the historical chain data to other peers, but is otherwise identical in
|
||||
functionality to the full blockchain.
|
||||
To use a pruned blockchain, it is best to start the initial sync with --prune-blockchain. However, it is also possible
|
||||
to prune an existing blockchain using the monero-blockchain-prune tool or using the --prune-blockchain monerod option
|
||||
To use a pruned blockchain, it is best to start the initial sync with `--prune-blockchain`. However, it is also possible
|
||||
to prune an existing blockchain using the `monero-blockchain-prune` tool or using the `--prune-blockchain` `monerod` option
|
||||
with an existing chain. If an existing chain exists, pruning will temporarily require disk space to store both the full
|
||||
and pruned blockchains.
|
||||
|
||||
For more detailed information see the ['Pruning' entry in the Moneropedia](https://www.getmonero.org/resources/moneropedia/pruning.html)
|
||||
|
||||
## Debugging
|
||||
|
||||
This section contains general instructions for debugging failed installs or problems encountered with Townforge. First, ensure you are running the latest version built from the git repo.
|
||||
|
@ -42,12 +42,19 @@
|
||||
find_program(CCACHE_FOUND ccache)
|
||||
if (CCACHE_FOUND)
|
||||
# Try to compile a test program with ccache, in order to verify if it really works. (needed on exotic setups)
|
||||
# Create a temporary file with a simple program.
|
||||
set(TEMP_CPP_FILE "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakeTmp/test-program.cpp")
|
||||
file(WRITE "${TEMP_CPP_FILE}" "int main() { return 0; }")
|
||||
# And run the found ccache on it.
|
||||
execute_process(COMMAND "${CCACHE_FOUND}" "${CMAKE_CXX_COMPILER}" "${TEMP_CPP_FILE}" RESULT_VARIABLE RET)
|
||||
if (${RET} EQUAL 0)
|
||||
set(TEST_PROJECT "${CMAKE_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/CMakeTmp")
|
||||
file(WRITE "${TEST_PROJECT}/CMakeLists.txt" [=[
|
||||
cmake_minimum_required(VERSION 3.1)
|
||||
project(test)
|
||||
option (CCACHE "")
|
||||
file(WRITE "${CMAKE_SOURCE_DIR}/test.cpp" "int main() { return 0; }")
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE}")
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "${CCACHE}")
|
||||
add_executable(test test.cpp)
|
||||
]=])
|
||||
try_compile(RET "${TEST_PROJECT}/build" "${TEST_PROJECT}" "test" CMAKE_FLAGS -DCCACHE="${CCACHE_FOUND}")
|
||||
unset(TEST_PROJECT)
|
||||
if (${RET})
|
||||
# Success
|
||||
message(STATUS "Found usable ccache: ${CCACHE_FOUND}")
|
||||
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_FOUND}")
|
||||
|
@ -26,5 +26,6 @@
|
||||
# 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.
|
||||
|
||||
monero_enable_coverage()
|
||||
add_subdirectory(epee)
|
||||
|
||||
|
@ -27,6 +27,7 @@ brew "miniupnpc"
|
||||
brew "readline"
|
||||
brew "ldns"
|
||||
brew "expat"
|
||||
brew "ccache"
|
||||
brew "doxygen"
|
||||
brew "graphviz"
|
||||
brew "libunwind-headers"
|
||||
|
@ -1,8 +1,8 @@
|
||||
package=openssl
|
||||
$(package)_version=1.1.1i
|
||||
$(package)_version=1.1.1k
|
||||
$(package)_download_path=https://www.openssl.org/source
|
||||
$(package)_file_name=$(package)-$($(package)_version).tar.gz
|
||||
$(package)_sha256_hash=e8be6a35fe41d10603c3cc635e93289ed00bf34b79671a3a4de64fcee00d5242
|
||||
$(package)_sha256_hash=892a0875b9872acd04a9fde79b1f943075d5ea162415de3047c327df33fbaee5
|
||||
|
||||
define $(package)_set_vars
|
||||
$(package)_config_env=AR="$($(package)_ar)" ARFLAGS=$($(package)_arflags) RANLIB="$($(package)_ranlib)" CC="$($(package)_cc)"
|
||||
|
@ -112,7 +112,7 @@ namespace epee
|
||||
explicit byte_slice(std::string&& buffer);
|
||||
|
||||
//! Convert `stream` into a slice with zero allocations.
|
||||
explicit byte_slice(byte_stream&& stream) noexcept;
|
||||
explicit byte_slice(byte_stream&& stream, bool shrink = true);
|
||||
|
||||
byte_slice(byte_slice&& source) noexcept;
|
||||
~byte_slice() noexcept = default;
|
||||
|
@ -24,211 +24,23 @@
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
|
||||
#ifndef _FILE_IO_UTILS_H_
|
||||
#define _FILE_IO_UTILS_H_
|
||||
|
||||
#include <fstream>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#include "string_tools.h"
|
||||
#endif
|
||||
|
||||
// On Windows there is a problem with non-ASCII characters in path and file names
|
||||
// as far as support by the standard components used is concerned:
|
||||
|
||||
// The various file stream classes, e.g. std::ifstream and std::ofstream, are
|
||||
// part of the GNU C++ Library / libstdc++. On the most basic level they use the
|
||||
// fopen() call as defined / made accessible to programs compiled within MSYS2
|
||||
// by the stdio.h header file maintained by the MinGW project.
|
||||
|
||||
// The critical point: The implementation of fopen() is part of MSVCRT, the
|
||||
// Microsoft Visual C/C++ Runtime Library, and this method does NOT offer any
|
||||
// Unicode support.
|
||||
|
||||
// Monero code that would want to continue to use the normal file stream classes
|
||||
// but WITH Unicode support could therefore not solve this problem on its own,
|
||||
// but 2 different projects from 2 different maintaining groups would need changes
|
||||
// in this particular direction - something probably difficult to achieve and
|
||||
// with a long time to wait until all new versions / releases arrive.
|
||||
|
||||
// Implemented solution approach: Circumvent the problem by stopping to use std
|
||||
// file stream classes on Windows and directly use Unicode-capable WIN32 API
|
||||
// calls. Most of the code doing so is concentrated in this header file here.
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
|
||||
namespace epee
|
||||
{
|
||||
namespace file_io_utils
|
||||
{
|
||||
inline
|
||||
bool is_file_exist(const std::string& path)
|
||||
{
|
||||
boost::filesystem::path p(path);
|
||||
return boost::filesystem::exists(p);
|
||||
}
|
||||
|
||||
inline
|
||||
bool save_string_to_file(const std::string& path_to_file, const std::string& str)
|
||||
{
|
||||
#ifdef WIN32
|
||||
std::wstring wide_path;
|
||||
try { wide_path = string_tools::utf8_to_utf16(path_to_file); } catch (...) { return false; }
|
||||
HANDLE file_handle = CreateFileW(wide_path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (file_handle == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
DWORD bytes_written;
|
||||
DWORD bytes_to_write = (DWORD)str.size();
|
||||
BOOL result = WriteFile(file_handle, str.data(), bytes_to_write, &bytes_written, NULL);
|
||||
CloseHandle(file_handle);
|
||||
if (bytes_written != bytes_to_write)
|
||||
result = FALSE;
|
||||
return result;
|
||||
#else
|
||||
try
|
||||
{
|
||||
std::ofstream fstream;
|
||||
fstream.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
fstream.open(path_to_file, std::ios_base::binary | std::ios_base::out | std::ios_base::trunc);
|
||||
fstream << str;
|
||||
fstream.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
catch(...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
inline
|
||||
bool get_file_time(const std::string& path_to_file, time_t& ft)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
ft = boost::filesystem::last_write_time(boost::filesystem::path(path_to_file), ec);
|
||||
if(!ec)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
inline
|
||||
bool set_file_time(const std::string& path_to_file, const time_t& ft)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
boost::filesystem::last_write_time(boost::filesystem::path(path_to_file), ft, ec);
|
||||
if(!ec)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
bool load_file_to_string(const std::string& path_to_file, std::string& target_str, size_t max_size = 1000000000)
|
||||
{
|
||||
#ifdef WIN32
|
||||
std::wstring wide_path;
|
||||
try { wide_path = string_tools::utf8_to_utf16(path_to_file); } catch (...) { return false; }
|
||||
HANDLE file_handle = CreateFileW(wide_path.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (file_handle == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
DWORD file_size = GetFileSize(file_handle, NULL);
|
||||
if ((file_size == INVALID_FILE_SIZE) || (uint64_t)file_size > (uint64_t)max_size) {
|
||||
CloseHandle(file_handle);
|
||||
return false;
|
||||
}
|
||||
target_str.resize(file_size);
|
||||
DWORD bytes_read;
|
||||
BOOL result = ReadFile(file_handle, &target_str[0], file_size, &bytes_read, NULL);
|
||||
CloseHandle(file_handle);
|
||||
if (bytes_read != file_size)
|
||||
result = FALSE;
|
||||
return result;
|
||||
#else
|
||||
try
|
||||
{
|
||||
std::ifstream fstream;
|
||||
fstream.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
fstream.open(path_to_file, std::ios_base::binary | std::ios_base::in | std::ios::ate);
|
||||
|
||||
std::ifstream::pos_type file_size = fstream.tellg();
|
||||
|
||||
if((uint64_t)file_size > (uint64_t)max_size) // ensure a large domain for comparison, and negative -> too large
|
||||
return false;//don't go crazy
|
||||
size_t file_size_t = static_cast<size_t>(file_size);
|
||||
|
||||
target_str.resize(file_size_t);
|
||||
|
||||
fstream.seekg (0, std::ios::beg);
|
||||
fstream.read((char*)target_str.data(), target_str.size());
|
||||
fstream.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
catch(...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
inline
|
||||
bool append_string_to_file(const std::string& path_to_file, const std::string& str)
|
||||
{
|
||||
// No special Windows implementation because so far not used in Monero code
|
||||
try
|
||||
{
|
||||
std::ofstream fstream;
|
||||
fstream.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
fstream.open(path_to_file.c_str(), std::ios_base::binary | std::ios_base::out | std::ios_base::app);
|
||||
fstream << str;
|
||||
fstream.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
catch(...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
inline
|
||||
bool get_file_size(const std::string& path_to_file, uint64_t &size)
|
||||
{
|
||||
#ifdef WIN32
|
||||
std::wstring wide_path;
|
||||
try { wide_path = string_tools::utf8_to_utf16(path_to_file); } catch (...) { return false; }
|
||||
HANDLE file_handle = CreateFileW(wide_path.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (file_handle == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
LARGE_INTEGER file_size;
|
||||
BOOL result = GetFileSizeEx(file_handle, &file_size);
|
||||
CloseHandle(file_handle);
|
||||
if (result) {
|
||||
size = file_size.QuadPart;
|
||||
}
|
||||
return size;
|
||||
#else
|
||||
try
|
||||
{
|
||||
std::ifstream fstream;
|
||||
fstream.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
fstream.open(path_to_file, std::ios_base::binary | std::ios_base::in | std::ios::ate);
|
||||
size = fstream.tellg();
|
||||
fstream.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
catch(...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
bool is_file_exist(const std::string& path);
|
||||
bool save_string_to_file(const std::string& path_to_file, const std::string& str);
|
||||
bool get_file_time(const std::string& path_to_file, time_t& ft);
|
||||
bool set_file_time(const std::string& path_to_file, const time_t& ft);
|
||||
bool load_file_to_string(const std::string& path_to_file, std::string& target_str, size_t max_size = 1000000000);
|
||||
bool append_string_to_file(const std::string& path_to_file, const std::string& str);
|
||||
bool get_file_size(const std::string& path_to_file, uint64_t &size);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
|
||||
extern "C" {
|
||||
#endif
|
||||
|
@ -28,9 +28,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <limits>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/utility/value_init.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <limits>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
namespace epee
|
||||
{
|
||||
#define STD_TRY_BEGIN() try {
|
||||
@ -95,16 +97,7 @@ namespace misc_utils
|
||||
return memcmp(&_Left, &_Right, sizeof(_Left)) < 0;
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
bool sleep_no_w(long ms )
|
||||
{
|
||||
boost::this_thread::sleep(
|
||||
boost::get_system_time() +
|
||||
boost::posix_time::milliseconds( std::max<long>(ms,0) ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
bool sleep_no_w(long ms );
|
||||
|
||||
template <typename T>
|
||||
T get_mid(const T &a, const T &b)
|
||||
|
@ -41,7 +41,7 @@
|
||||
#define MAX_LOG_FILES 50
|
||||
|
||||
#define MCLOG_TYPE(level, cat, color, type, x) do { \
|
||||
if (ELPP->vRegistry()->allowed(level, cat)) { \
|
||||
if (el::Loggers::allowed(level, cat)) { \
|
||||
el::base::Writer(level, color, __FILE__, __LINE__, ELPP_FUNC, type).construct(cat) << x; \
|
||||
} \
|
||||
} while (0)
|
||||
@ -89,7 +89,7 @@
|
||||
|
||||
#define IFLOG(level, cat, color, type, init, x) \
|
||||
do { \
|
||||
if (ELPP->vRegistry()->allowed(level, cat)) { \
|
||||
if (el::Loggers::allowed(level, cat)) { \
|
||||
init; \
|
||||
el::base::Writer(level, color, __FILE__, __LINE__, ELPP_FUNC, type).construct(cat) << x; \
|
||||
} \
|
||||
|
@ -47,7 +47,7 @@
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <ctime>
|
||||
|
||||
#pragma once
|
||||
namespace epee
|
||||
@ -115,15 +115,7 @@ namespace misc_utils
|
||||
|
||||
}
|
||||
|
||||
|
||||
inline std::string get_thread_string_id()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return boost::lexical_cast<std::string>(GetCurrentThreadId());
|
||||
#elif defined(__GNUC__)
|
||||
return boost::lexical_cast<std::string>(pthread_self());
|
||||
#endif
|
||||
}
|
||||
std::string get_thread_string_id();
|
||||
|
||||
inline bool get_gmt_time(time_t t, struct tm &tm)
|
||||
{
|
||||
|
@ -265,6 +265,12 @@ namespace net_utils
|
||||
template<class t_callback>
|
||||
bool connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeot, const t_callback &cb, const std::string& bind_ip = "0.0.0.0", epee::net_utils::ssl_support_t ssl_support = epee::net_utils::ssl_support_t::e_ssl_support_autodetect);
|
||||
|
||||
boost::asio::ssl::context& get_ssl_context() noexcept
|
||||
{
|
||||
assert(m_state != nullptr);
|
||||
return m_state->ssl_context;
|
||||
}
|
||||
|
||||
typename t_protocol_handler::config_type& get_config_object()
|
||||
{
|
||||
assert(m_state != nullptr); // always set in constructor
|
||||
|
@ -40,8 +40,9 @@
|
||||
#include <boost/date_time/posix_time/posix_time.hpp> // TODO
|
||||
#include <boost/thread/condition_variable.hpp> // TODO
|
||||
#include <boost/make_shared.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include "warnings.h"
|
||||
#include "string_tools.h"
|
||||
#include "string_tools_lexical.h"
|
||||
#include "misc_language.h"
|
||||
#include "net/local_ip.h"
|
||||
#include "pragma_comp_defs.h"
|
||||
@ -269,8 +270,6 @@ PRAGMA_WARNING_DISABLE_VS(4355)
|
||||
//_dbg3("[sock " << socket().native_handle() << "] add_ref, m_peer_number=" << mI->m_peer_number);
|
||||
CRITICAL_REGION_LOCAL(self->m_self_refs_lock);
|
||||
//_dbg3("[sock " << socket().native_handle() << "] add_ref 2, m_peer_number=" << mI->m_peer_number);
|
||||
if(m_was_shutdown)
|
||||
return false;
|
||||
++m_reference_count;
|
||||
m_self_ref = std::move(self);
|
||||
return true;
|
||||
@ -562,7 +561,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
|
||||
{ // LOCK: chunking
|
||||
epee::critical_region_t<decltype(m_chunking_lock)> send_guard(m_chunking_lock); // *** critical ***
|
||||
|
||||
MDEBUG("do_send() will SPLIT into small chunks, from packet="<<message_size<<" B for ptr="<<message_data);
|
||||
MDEBUG("do_send() will SPLIT into small chunks, from packet="<<message_size<<" B for ptr="<<(const void*)message_data);
|
||||
// 01234567890
|
||||
// ^^^^ (pos=0, len=4) ; pos:=pos+len, pos=4
|
||||
// ^^^^ (pos=4, len=4) ; pos:=pos+len, pos=8
|
||||
@ -575,14 +574,14 @@ PRAGMA_WARNING_DISABLE_VS(4355)
|
||||
while (!message.empty()) {
|
||||
byte_slice chunk = message.take_slice(chunksize_good);
|
||||
|
||||
MDEBUG("chunk_start="<<(void*)chunk.data()<<" ptr="<<message_data<<" pos="<<(chunk.data() - message_data));
|
||||
MDEBUG("chunk_start="<<(void*)chunk.data()<<" ptr="<<(const void*)message_data<<" pos="<<(chunk.data() - message_data));
|
||||
MDEBUG("part of " << message.size() << ": pos="<<(chunk.data() - message_data) << " len="<<chunk.size());
|
||||
|
||||
bool ok = do_send_chunk(std::move(chunk)); // <====== ***
|
||||
|
||||
all_ok = all_ok && ok;
|
||||
if (!all_ok) {
|
||||
MDEBUG("do_send() DONE ***FAILED*** from packet="<<message_size<<" B for ptr="<<message_data);
|
||||
MDEBUG("do_send() DONE ***FAILED*** from packet="<<message_size<<" B for ptr="<<(const void*)message_data);
|
||||
MDEBUG("do_send() SEND was aborted in middle of big package - this is mostly harmless "
|
||||
<< " (e.g. peer closed connection) but if it causes trouble tell us at #monero-dev. " << message_size);
|
||||
return false; // partial failure in sending
|
||||
@ -590,7 +589,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
|
||||
// (in catch block, or uniq pointer) delete buf;
|
||||
} // each chunk
|
||||
|
||||
MDEBUG("do_send() DONE SPLIT from packet="<<message_size<<" B for ptr="<<message_data);
|
||||
MDEBUG("do_send() DONE SPLIT from packet="<<message_size<<" B for ptr="<<(const void*)message_data);
|
||||
|
||||
MDEBUG("do_send() m_connection_type = " << m_connection_type);
|
||||
|
||||
|
@ -27,14 +27,13 @@
|
||||
|
||||
|
||||
#pragma once
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#include "memwipe.h"
|
||||
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "memwipe.h"
|
||||
#include "string_tools.h"
|
||||
#include <list>
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "net.http"
|
||||
@ -66,34 +65,9 @@ namespace net_utils
|
||||
|
||||
typedef std::list<std::pair<std::string, std::string> > fields_list;
|
||||
|
||||
inline
|
||||
std::string get_value_from_fields_list(const std::string& param_name, const net_utils::http::fields_list& fields)
|
||||
{
|
||||
fields_list::const_iterator it = fields.begin();
|
||||
for(; it != fields.end(); it++)
|
||||
if(!string_tools::compare_no_case(param_name, it->first))
|
||||
break;
|
||||
std::string get_value_from_fields_list(const std::string& param_name, const net_utils::http::fields_list& fields);
|
||||
|
||||
if(it==fields.end())
|
||||
return std::string();
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
std::string get_value_from_uri_line(const std::string& param_name, const std::string& uri)
|
||||
{
|
||||
std::string buff = "([\\?|&])";
|
||||
buff += param_name + "=([^&]*)";
|
||||
boost::regex match_param(buff.c_str(), boost::regex::icase | boost::regex::normal);
|
||||
boost::smatch result;
|
||||
if(boost::regex_search(uri, result, match_param, boost::match_default) && result[0].matched)
|
||||
{
|
||||
return result[2];
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
std::string get_value_from_uri_line(const std::string& param_name, const std::string& uri);
|
||||
|
||||
static inline void add_field(std::string& out, const boost::string_ref name, const boost::string_ref value)
|
||||
{
|
||||
|
@ -30,7 +30,6 @@
|
||||
#include <ctype.h>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/optional/optional.hpp>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
//#include <mbstring.h>
|
||||
@ -46,6 +45,7 @@
|
||||
#endif
|
||||
|
||||
#include "string_tools.h"
|
||||
#include "string_tools_lexical.h"
|
||||
#include "reg_exp_definer.h"
|
||||
#include "abstract_http_client.h"
|
||||
#include "http_base.h"
|
||||
|
@ -74,7 +74,13 @@
|
||||
uint64_t ticks = misc_utils::get_tick_count(); \
|
||||
boost::value_initialized<command_type::request> req; \
|
||||
bool parse_res = epee::serialization::load_t_from_json(static_cast<command_type::request&>(req), query_info.m_body); \
|
||||
CHECK_AND_ASSERT_MES(parse_res, false, "Failed to parse json: \r\n" << query_info.m_body); \
|
||||
if (!parse_res) \
|
||||
{ \
|
||||
MERROR("Failed to parse json: \r\n" << query_info.m_body); \
|
||||
response_info.m_response_code = 400; \
|
||||
response_info.m_response_comment = "Bad request"; \
|
||||
return true; \
|
||||
} \
|
||||
uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
|
||||
boost::value_initialized<command_type::response> resp;\
|
||||
MINFO(m_conn_context << "calling " << s_pattern); \
|
||||
@ -104,7 +110,13 @@
|
||||
uint64_t ticks = misc_utils::get_tick_count(); \
|
||||
boost::value_initialized<command_type::request> req; \
|
||||
bool parse_res = epee::serialization::load_t_from_binary(static_cast<command_type::request&>(req), epee::strspan<uint8_t>(query_info.m_body)); \
|
||||
CHECK_AND_ASSERT_MES(parse_res, false, "Failed to parse bin body data, body size=" << query_info.m_body.size()); \
|
||||
if (!parse_res) \
|
||||
{ \
|
||||
MERROR("Failed to parse bin body data, body size=" << query_info.m_body.size()); \
|
||||
response_info.m_response_code = 400; \
|
||||
response_info.m_response_comment = "Bad request"; \
|
||||
return true; \
|
||||
} \
|
||||
uint64_t ticks1 = misc_utils::get_tick_count(); \
|
||||
boost::value_initialized<command_type::response> resp;\
|
||||
MINFO(m_conn_context << "calling " << s_pattern); \
|
||||
|
@ -31,6 +31,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "byte_stream.h"
|
||||
#include "net_utils_base.h"
|
||||
#include "span.h"
|
||||
|
||||
@ -83,11 +84,12 @@ namespace levin
|
||||
|
||||
#define LEVIN_PROTOCOL_VER_0 0
|
||||
#define LEVIN_PROTOCOL_VER_1 1
|
||||
|
||||
|
||||
template<class t_connection_context = net_utils::connection_context_base>
|
||||
struct levin_commands_handler
|
||||
{
|
||||
virtual int invoke(int command, const epee::span<const uint8_t> in_buff, byte_slice& buff_out, t_connection_context& context)=0;
|
||||
virtual int invoke(int command, const epee::span<const uint8_t> in_buff, byte_stream& buff_out, t_connection_context& context)=0;
|
||||
virtual int notify(int command, const epee::span<const uint8_t> in_buff, t_connection_context& context)=0;
|
||||
virtual void callback(t_connection_context& context){};
|
||||
|
||||
@ -125,12 +127,41 @@ namespace levin
|
||||
}
|
||||
}
|
||||
|
||||
//! Provides space for levin (p2p) header, so that payload can be sent without copy
|
||||
class message_writer
|
||||
{
|
||||
byte_slice finalize(uint32_t command, uint32_t flags, uint32_t return_code, bool expect_response);
|
||||
public:
|
||||
using header = bucket_head2;
|
||||
|
||||
explicit message_writer(std::size_t reserve = 8192);
|
||||
|
||||
message_writer(const message_writer&) = delete;
|
||||
message_writer(message_writer&&) = default;
|
||||
~message_writer() = default;
|
||||
message_writer& operator=(const message_writer&) = delete;
|
||||
message_writer& operator=(message_writer&&) = default;
|
||||
|
||||
//! \return Size of payload (excludes header size).
|
||||
std::size_t payload_size() const noexcept
|
||||
{
|
||||
return buffer.size() < sizeof(header) ? 0 : buffer.size() - sizeof(header);
|
||||
}
|
||||
|
||||
byte_slice finalize_invoke(uint32_t command) { return finalize(command, LEVIN_PACKET_REQUEST, 0, true); }
|
||||
byte_slice finalize_notify(uint32_t command) { return finalize(command, LEVIN_PACKET_REQUEST, 0, false); }
|
||||
byte_slice finalize_response(uint32_t command, uint32_t return_code)
|
||||
{
|
||||
return finalize(command, LEVIN_PACKET_RESPONSE, return_code, false);
|
||||
}
|
||||
|
||||
//! Has space for levin header until a finalize method is used
|
||||
byte_stream buffer;
|
||||
};
|
||||
|
||||
//! \return Intialized levin header.
|
||||
bucket_head2 make_header(uint32_t command, uint64_t msg_size, uint32_t flags, bool expect_response) noexcept;
|
||||
|
||||
//! \return A levin notification message.
|
||||
byte_slice make_notify(int command, epee::span<const std::uint8_t> payload);
|
||||
|
||||
/*! Generate a dummy levin message.
|
||||
|
||||
\param noise_bytes Total size of the returned `byte_slice`.
|
||||
@ -140,12 +171,11 @@ namespace levin
|
||||
|
||||
/*! Generate 1+ levin messages that are identical to the noise message size.
|
||||
|
||||
\param noise Each levin message will be identical to the size of this
|
||||
message. The bytes from this message will be used for padding.
|
||||
\param noise_size Each levin message will be identical to this value.
|
||||
\return `nullptr` if `noise.size()` is less than the levin header size.
|
||||
Otherwise, a levin notification message OR 2+ levin fragment messages.
|
||||
Each message is `noise.size()` in length. */
|
||||
byte_slice make_fragmented_notify(const byte_slice& noise, int command, epee::span<const std::uint8_t> payload);
|
||||
byte_slice make_fragmented_notify(const std::size_t noise_size, int command, message_writer message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,6 +51,21 @@
|
||||
#define MIN_BYTES_WANTED 512
|
||||
#endif
|
||||
|
||||
template<typename context_t>
|
||||
void on_levin_traffic(const context_t &context, bool initiator, bool sent, bool error, size_t bytes, const char* category)
|
||||
{
|
||||
MCINFO("net.p2p.traffic", context << bytes << " bytes " << (sent ? "sent" : "received") << (error ? "/corrupt" : "")
|
||||
<< " for category " << category << " initiated by " << (initiator ? "us" : "peer"));
|
||||
}
|
||||
|
||||
template<typename context_t>
|
||||
void on_levin_traffic(const context_t &context, bool initiator, bool sent, bool error, size_t bytes, int command)
|
||||
{
|
||||
char buf[32];
|
||||
snprintf(buf, sizeof(buf), "command-%u", command);
|
||||
on_levin_traffic(context, initiator, sent, error, bytes, buf);
|
||||
}
|
||||
|
||||
namespace epee
|
||||
{
|
||||
namespace levin
|
||||
@ -88,11 +103,10 @@ public:
|
||||
uint64_t m_max_packet_size;
|
||||
uint64_t m_invoke_timeout;
|
||||
|
||||
int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, boost::uuids::uuid connection_id);
|
||||
int invoke(int command, message_writer in_msg, std::string& buff_out, boost::uuids::uuid connection_id);
|
||||
template<class callback_t>
|
||||
int invoke_async(int command, const epee::span<const uint8_t> in_buff, boost::uuids::uuid connection_id, const callback_t &cb, size_t timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED);
|
||||
int invoke_async(int command, message_writer in_msg, boost::uuids::uuid connection_id, const callback_t &cb, size_t timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED);
|
||||
|
||||
int notify(int command, const epee::span<const uint8_t> in_buff, boost::uuids::uuid connection_id);
|
||||
int send(epee::byte_slice message, const boost::uuids::uuid& connection_id);
|
||||
bool close(boost::uuids::uuid connection_id);
|
||||
bool update_connection_context(const t_connection_context& contxt);
|
||||
@ -122,12 +136,17 @@ class async_protocol_handler
|
||||
{
|
||||
std::string m_fragment_buffer;
|
||||
|
||||
bool send_message(uint32_t command, epee::span<const uint8_t> in_buff, uint32_t flags, bool expect_response)
|
||||
bool send_message(byte_slice message)
|
||||
{
|
||||
const bucket_head2 head = make_header(command, in_buff.size(), flags, expect_response);
|
||||
if(!m_pservice_endpoint->do_send(byte_slice{as_byte_span(head), in_buff}))
|
||||
if (message.size() < sizeof(message_writer::header))
|
||||
return false;
|
||||
|
||||
message_writer::header head;
|
||||
std::memcpy(std::addressof(head), message.data(), sizeof(head));
|
||||
if(!m_pservice_endpoint->do_send(std::move(message)))
|
||||
return false;
|
||||
|
||||
on_levin_traffic(m_connection_context, true, true, false, head.m_cb, head.m_command);
|
||||
MDEBUG(m_connection_context << "LEVIN_PACKET_SENT. [len=" << head.m_cb
|
||||
<< ", flags" << head.m_flags
|
||||
<< ", r?=" << head.m_have_to_return_data
|
||||
@ -146,7 +165,6 @@ public:
|
||||
stream_state_body
|
||||
};
|
||||
|
||||
std::atomic<bool> m_deletion_initiated;
|
||||
std::atomic<bool> m_protocol_released;
|
||||
volatile uint32_t m_invoke_buf_ready;
|
||||
|
||||
@ -297,7 +315,6 @@ public:
|
||||
m_state(stream_state_head)
|
||||
{
|
||||
m_close_called = 0;
|
||||
m_deletion_initiated = false;
|
||||
m_protocol_released = false;
|
||||
m_wait_count = 0;
|
||||
m_oponent_protocol_ver = 0;
|
||||
@ -310,7 +327,6 @@ public:
|
||||
try
|
||||
{
|
||||
|
||||
m_deletion_initiated = true;
|
||||
if(m_connection_initialized)
|
||||
{
|
||||
m_config.del_connection(this);
|
||||
@ -526,26 +542,17 @@ public:
|
||||
{
|
||||
if(m_current_head.m_have_to_return_data)
|
||||
{
|
||||
byte_slice return_buff;
|
||||
levin::message_writer return_message{32 * 1024};
|
||||
const uint32_t return_code = m_config.m_pcommands_handler->invoke(
|
||||
m_current_head.m_command, buff_to_invoke, return_buff, m_connection_context
|
||||
m_current_head.m_command, buff_to_invoke, return_message.buffer, m_connection_context
|
||||
);
|
||||
|
||||
// peer_id remains unset if dropped
|
||||
if (m_current_head.m_command == m_connection_context.handshake_command() && m_connection_context.handshake_complete())
|
||||
m_max_packet_size = m_config.m_max_packet_size;
|
||||
|
||||
bucket_head2 head = make_header(m_current_head.m_command, return_buff.size(), LEVIN_PACKET_RESPONSE, false);
|
||||
head.m_return_code = SWAP32LE(return_code);
|
||||
|
||||
if(!m_pservice_endpoint->do_send(byte_slice{{epee::as_byte_span(head), epee::to_span(return_buff)}}))
|
||||
if(!send_message(return_message.finalize_response(m_current_head.m_command, return_code)))
|
||||
return false;
|
||||
|
||||
MDEBUG(m_connection_context << "LEVIN_PACKET_SENT. [len=" << head.m_cb
|
||||
<< ", flags" << head.m_flags
|
||||
<< ", r?=" << head.m_have_to_return_data
|
||||
<<", cmd = " << head.m_command
|
||||
<< ", ver=" << head.m_protocol_version);
|
||||
}
|
||||
else
|
||||
m_config.m_pcommands_handler->notify(m_current_head.m_command, buff_to_invoke, m_connection_context);
|
||||
@ -622,7 +629,7 @@ public:
|
||||
}
|
||||
|
||||
template<class callback_t>
|
||||
bool async_invoke(int command, const epee::span<const uint8_t> in_buff, const callback_t &cb, size_t timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED)
|
||||
bool async_invoke(int command, message_writer in_msg, const callback_t &cb, size_t timeout = LEVIN_DEFAULT_TIMEOUT_PRECONFIGURED)
|
||||
{
|
||||
misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler(
|
||||
boost::bind(&async_protocol_handler::finish_outer_call, this));
|
||||
@ -633,27 +640,15 @@ public:
|
||||
int err_code = LEVIN_OK;
|
||||
do
|
||||
{
|
||||
if(m_deletion_initiated)
|
||||
{
|
||||
err_code = LEVIN_ERROR_CONNECTION_DESTROYED;
|
||||
break;
|
||||
}
|
||||
|
||||
CRITICAL_REGION_LOCAL(m_call_lock);
|
||||
|
||||
if(m_deletion_initiated)
|
||||
{
|
||||
err_code = LEVIN_ERROR_CONNECTION_DESTROYED;
|
||||
break;
|
||||
}
|
||||
|
||||
boost::interprocess::ipcdetail::atomic_write32(&m_invoke_buf_ready, 0);
|
||||
CRITICAL_REGION_BEGIN(m_invoke_response_handlers_lock);
|
||||
|
||||
if (command == m_connection_context.handshake_command())
|
||||
m_max_packet_size = m_config.m_max_packet_size;
|
||||
|
||||
if(!send_message(command, in_buff, LEVIN_PACKET_REQUEST, true))
|
||||
if(!send_message(in_msg.finalize_invoke(command)))
|
||||
{
|
||||
LOG_ERROR_CC(m_connection_context, "Failed to do_send");
|
||||
err_code = LEVIN_ERROR_CONNECTION;
|
||||
@ -679,25 +674,19 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
int invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out)
|
||||
int invoke(int command, message_writer in_msg, std::string& buff_out)
|
||||
{
|
||||
misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler(
|
||||
boost::bind(&async_protocol_handler::finish_outer_call, this));
|
||||
|
||||
if(m_deletion_initiated)
|
||||
return LEVIN_ERROR_CONNECTION_DESTROYED;
|
||||
|
||||
CRITICAL_REGION_LOCAL(m_call_lock);
|
||||
|
||||
if(m_deletion_initiated)
|
||||
return LEVIN_ERROR_CONNECTION_DESTROYED;
|
||||
|
||||
boost::interprocess::ipcdetail::atomic_write32(&m_invoke_buf_ready, 0);
|
||||
|
||||
if (command == m_connection_context.handshake_command())
|
||||
m_max_packet_size = m_config.m_max_packet_size;
|
||||
|
||||
if (!send_message(command, in_buff, LEVIN_PACKET_REQUEST, true))
|
||||
if (!send_message(in_msg.finalize_invoke(command)))
|
||||
{
|
||||
LOG_ERROR_CC(m_connection_context, "Failed to send request");
|
||||
return LEVIN_ERROR_CONNECTION;
|
||||
@ -706,7 +695,7 @@ public:
|
||||
uint64_t ticks_start = misc_utils::get_tick_count();
|
||||
size_t prev_size = 0;
|
||||
|
||||
while(!boost::interprocess::ipcdetail::atomic_read32(&m_invoke_buf_ready) && !m_deletion_initiated && !m_protocol_released)
|
||||
while(!boost::interprocess::ipcdetail::atomic_read32(&m_invoke_buf_ready) && !m_protocol_released)
|
||||
{
|
||||
if(m_cache_in_buffer.size() - prev_size >= MIN_BYTES_WANTED)
|
||||
{
|
||||
@ -723,7 +712,7 @@ public:
|
||||
return LEVIN_ERROR_CONNECTION_DESTROYED;
|
||||
}
|
||||
|
||||
if(m_deletion_initiated || m_protocol_released)
|
||||
if(m_protocol_released)
|
||||
return LEVIN_ERROR_CONNECTION_DESTROYED;
|
||||
|
||||
CRITICAL_REGION_BEGIN(m_local_inv_buff_lock);
|
||||
@ -734,31 +723,9 @@ public:
|
||||
return m_invoke_result_code;
|
||||
}
|
||||
|
||||
int notify(int command, const epee::span<const uint8_t> in_buff)
|
||||
{
|
||||
misc_utils::auto_scope_leave_caller scope_exit_handler = misc_utils::create_scope_leave_handler(
|
||||
boost::bind(&async_protocol_handler::finish_outer_call, this));
|
||||
|
||||
if(m_deletion_initiated)
|
||||
return LEVIN_ERROR_CONNECTION_DESTROYED;
|
||||
|
||||
CRITICAL_REGION_LOCAL(m_call_lock);
|
||||
|
||||
if(m_deletion_initiated)
|
||||
return LEVIN_ERROR_CONNECTION_DESTROYED;
|
||||
|
||||
if (!send_message(command, in_buff, LEVIN_PACKET_REQUEST, false))
|
||||
{
|
||||
LOG_ERROR_CC(m_connection_context, "Failed to send notify message");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*! Sends `message` without adding a levin header. The message must have
|
||||
been created with `make_notify`, `make_noise_notify` or
|
||||
`make_fragmented_notify`. See additional instructions for
|
||||
/*! Sends `message` without adding a levin header. The message must have been
|
||||
created with `make_noise_notify`, `make_fragmented_notify`, or
|
||||
`message_writer::finalize_notify`. See additional instructions for
|
||||
`make_fragmented_notify`.
|
||||
|
||||
\return 1 on success */
|
||||
@ -768,17 +735,11 @@ public:
|
||||
boost::bind(&async_protocol_handler::finish_outer_call, this)
|
||||
);
|
||||
|
||||
if(m_deletion_initiated)
|
||||
return LEVIN_ERROR_CONNECTION_DESTROYED;
|
||||
|
||||
const std::size_t length = message.size();
|
||||
if (!m_pservice_endpoint->do_send(std::move(message)))
|
||||
if (!send_message(std::move(message)))
|
||||
{
|
||||
LOG_ERROR_CC(m_connection_context, "Failed to send message, dropping it");
|
||||
return -1;
|
||||
}
|
||||
|
||||
MDEBUG(m_connection_context << "LEVIN_PACKET_SENT. [len=" << (length - sizeof(bucket_head2)) << ", r?=0]");
|
||||
return 1;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------
|
||||
@ -799,36 +760,32 @@ void async_protocol_handler_config<t_connection_context>::del_connection(async_p
|
||||
template<class t_connection_context>
|
||||
void async_protocol_handler_config<t_connection_context>::delete_connections(size_t count, bool incoming)
|
||||
{
|
||||
std::vector <boost::uuids::uuid> connections;
|
||||
std::vector<typename connections_map::mapped_type> connections;
|
||||
|
||||
auto scope_exit_handler = misc_utils::create_scope_leave_handler([&connections]{
|
||||
for (auto &aph: connections)
|
||||
aph->finish_outer_call();
|
||||
});
|
||||
|
||||
CRITICAL_REGION_BEGIN(m_connects_lock);
|
||||
for (auto& c: m_connects)
|
||||
{
|
||||
if (c.second->m_connection_context.m_is_income == incoming)
|
||||
connections.push_back(c.first);
|
||||
if (c.second->start_outer_call())
|
||||
connections.push_back(c.second);
|
||||
}
|
||||
|
||||
// close random connections from the provided set
|
||||
// TODO or better just keep removing random elements (performance)
|
||||
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
|
||||
shuffle(connections.begin(), connections.end(), std::default_random_engine(seed));
|
||||
while (count > 0 && connections.size() > 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto i = connections.end() - 1;
|
||||
async_protocol_handler<t_connection_context> *conn = m_connects.at(*i);
|
||||
del_connection(conn);
|
||||
conn->close();
|
||||
connections.erase(i);
|
||||
}
|
||||
catch (const std::out_of_range &e)
|
||||
{
|
||||
MWARNING("Connection not found in m_connects, continuing");
|
||||
}
|
||||
--count;
|
||||
}
|
||||
for (size_t i = 0; i < connections.size() && i < count; ++i)
|
||||
m_connects.erase(connections[i]->get_connection_id());
|
||||
|
||||
CRITICAL_REGION_END();
|
||||
|
||||
for (size_t i = 0; i < connections.size() && i < count; ++i)
|
||||
connections[i]->close();
|
||||
}
|
||||
//------------------------------------------------------------------------------------------
|
||||
template<class t_connection_context>
|
||||
@ -872,41 +829,53 @@ int async_protocol_handler_config<t_connection_context>::find_and_lock_connectio
|
||||
}
|
||||
//------------------------------------------------------------------------------------------
|
||||
template<class t_connection_context>
|
||||
int async_protocol_handler_config<t_connection_context>::invoke(int command, const epee::span<const uint8_t> in_buff, std::string& buff_out, boost::uuids::uuid connection_id)
|
||||
int async_protocol_handler_config<t_connection_context>::invoke(int command, message_writer in_msg, std::string& buff_out, boost::uuids::uuid connection_id)
|
||||
{
|
||||
async_protocol_handler<t_connection_context>* aph;
|
||||
int r = find_and_lock_connection(connection_id, aph);
|
||||
return LEVIN_OK == r ? aph->invoke(command, in_buff, buff_out) : r;
|
||||
return LEVIN_OK == r ? aph->invoke(command, std::move(in_msg), buff_out) : r;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------
|
||||
template<class t_connection_context> template<class callback_t>
|
||||
int async_protocol_handler_config<t_connection_context>::invoke_async(int command, const epee::span<const uint8_t> in_buff, boost::uuids::uuid connection_id, const callback_t &cb, size_t timeout)
|
||||
int async_protocol_handler_config<t_connection_context>::invoke_async(int command, message_writer in_msg, boost::uuids::uuid connection_id, const callback_t &cb, size_t timeout)
|
||||
{
|
||||
async_protocol_handler<t_connection_context>* aph;
|
||||
int r = find_and_lock_connection(connection_id, aph);
|
||||
return LEVIN_OK == r ? aph->async_invoke(command, in_buff, cb, timeout) : r;
|
||||
return LEVIN_OK == r ? aph->async_invoke(command, std::move(in_msg), cb, timeout) : r;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------
|
||||
template<class t_connection_context> template<class callback_t>
|
||||
bool async_protocol_handler_config<t_connection_context>::foreach_connection(const callback_t &cb)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_connects_lock);
|
||||
for(auto& c: m_connects)
|
||||
{
|
||||
async_protocol_handler<t_connection_context>* aph = c.second;
|
||||
if(!cb(aph->get_context_ref()))
|
||||
std::vector<typename connections_map::mapped_type> conn;
|
||||
|
||||
auto scope_exit_handler = misc_utils::create_scope_leave_handler([&conn]{
|
||||
for (auto &aph: conn)
|
||||
aph->finish_outer_call();
|
||||
});
|
||||
|
||||
CRITICAL_REGION_BEGIN(m_connects_lock);
|
||||
conn.reserve(m_connects.size());
|
||||
for (auto &e: m_connects)
|
||||
if (e.second->start_outer_call())
|
||||
conn.push_back(e.second);
|
||||
CRITICAL_REGION_END()
|
||||
|
||||
for (auto &aph: conn)
|
||||
if (!cb(aph->get_context_ref()))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------
|
||||
template<class t_connection_context> template<class callback_t>
|
||||
bool async_protocol_handler_config<t_connection_context>::for_connection(const boost::uuids::uuid &connection_id, const callback_t &cb)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_connects_lock);
|
||||
async_protocol_handler<t_connection_context>* aph = find_connection(connection_id);
|
||||
if (!aph)
|
||||
async_protocol_handler<t_connection_context>* aph = nullptr;
|
||||
if (find_and_lock_connection(connection_id, aph) != LEVIN_OK)
|
||||
return false;
|
||||
auto scope_exit_handler = misc_utils::create_scope_leave_handler(
|
||||
boost::bind(&async_protocol_handler<t_connection_context>::finish_outer_call, aph));
|
||||
if(!cb(aph->get_context_ref()))
|
||||
return false;
|
||||
return true;
|
||||
@ -951,14 +920,6 @@ void async_protocol_handler_config<t_connection_context>::set_handler(levin_comm
|
||||
}
|
||||
//------------------------------------------------------------------------------------------
|
||||
template<class t_connection_context>
|
||||
int async_protocol_handler_config<t_connection_context>::notify(int command, const epee::span<const uint8_t> in_buff, boost::uuids::uuid connection_id)
|
||||
{
|
||||
async_protocol_handler<t_connection_context>* aph;
|
||||
int r = find_and_lock_connection(connection_id, aph);
|
||||
return LEVIN_OK == r ? aph->notify(command, in_buff) : r;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------
|
||||
template<class t_connection_context>
|
||||
int async_protocol_handler_config<t_connection_context>::send(byte_slice message, const boost::uuids::uuid& connection_id)
|
||||
{
|
||||
async_protocol_handler<t_connection_context>* aph;
|
||||
@ -969,12 +930,14 @@ int async_protocol_handler_config<t_connection_context>::send(byte_slice message
|
||||
template<class t_connection_context>
|
||||
bool async_protocol_handler_config<t_connection_context>::close(boost::uuids::uuid connection_id)
|
||||
{
|
||||
CRITICAL_REGION_LOCAL(m_connects_lock);
|
||||
async_protocol_handler<t_connection_context>* aph = find_connection(connection_id);
|
||||
if (!aph)
|
||||
async_protocol_handler<t_connection_context>* aph = nullptr;
|
||||
if (find_and_lock_connection(connection_id, aph) != LEVIN_OK)
|
||||
return false;
|
||||
auto scope_exit_handler = misc_utils::create_scope_leave_handler(
|
||||
boost::bind(&async_protocol_handler<t_connection_context>::finish_outer_call, aph));
|
||||
if (!aph->close())
|
||||
return false;
|
||||
CRITICAL_REGION_LOCAL(m_connects_lock);
|
||||
m_connects.erase(connection_id);
|
||||
return true;
|
||||
}
|
||||
|
@ -24,12 +24,9 @@
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "http_base.h"
|
||||
#include "reg_exp_definer.h"
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "net"
|
||||
@ -38,173 +35,8 @@ namespace epee
|
||||
{
|
||||
namespace net_utils
|
||||
{
|
||||
|
||||
inline bool parse_uri_query(const std::string& query, std::list<std::pair<std::string, std::string> >& params)
|
||||
{
|
||||
enum state
|
||||
{
|
||||
st_param_name,
|
||||
st_param_val
|
||||
};
|
||||
state st = st_param_name;
|
||||
std::string::const_iterator start_it = query.begin();
|
||||
std::pair<std::string, std::string> e;
|
||||
for(std::string::const_iterator it = query.begin(); it != query.end(); it++)
|
||||
{
|
||||
switch(st)
|
||||
{
|
||||
case st_param_name:
|
||||
if(*it == '=')
|
||||
{
|
||||
e.first.assign(start_it, it);
|
||||
start_it = it;++start_it;
|
||||
st = st_param_val;
|
||||
}
|
||||
break;
|
||||
case st_param_val:
|
||||
if(*it == '&')
|
||||
{
|
||||
e.second.assign(start_it, it);
|
||||
start_it = it;++start_it;
|
||||
params.push_back(e);
|
||||
e.first.clear();e.second.clear();
|
||||
st = st_param_name;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("Unknown state " << (int)st);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(st == st_param_name)
|
||||
{
|
||||
if(start_it != query.end())
|
||||
{
|
||||
e.first.assign(start_it, query.end());
|
||||
params.push_back(e);
|
||||
}
|
||||
}else
|
||||
{
|
||||
if(start_it != query.end())
|
||||
e.second.assign(start_it, query.end());
|
||||
|
||||
if(e.first.size())
|
||||
params.push_back(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline
|
||||
bool parse_uri(const std::string uri, http::uri_content& content)
|
||||
{
|
||||
|
||||
///iframe_test.html?api_url=http://api.vk.com/api.php&api_id=3289090&api_settings=1&viewer_id=562964060&viewer_type=0&sid=0aad8d1c5713130f9ca0076f2b7b47e532877424961367d81e7fa92455f069be7e21bc3193cbd0be11895&secret=368ebbc0ef&access_token=668bc03f43981d883f73876ffff4aa8564254b359cc745dfa1b3cde7bdab2e94105d8f6d8250717569c0a7&user_id=0&group_id=0&is_app_user=1&auth_key=d2f7a895ca5ff3fdb2a2a8ae23fe679a&language=0&parent_language=0&ad_info=ElsdCQBaQlxiAQRdFUVUXiN2AVBzBx5pU1BXIgZUJlIEAWcgAUoLQg==&referrer=unknown&lc_name=9834b6a3&hash=
|
||||
content.m_query_params.clear();
|
||||
STATIC_REGEXP_EXPR_1(rexp_match_uri, "^([^?#]*)(\\?([^#]*))?(#(.*))?", boost::regex::icase | boost::regex::normal);
|
||||
|
||||
boost::smatch result;
|
||||
if(!(boost::regex_search(uri, result, rexp_match_uri, boost::match_default) && result[0].matched))
|
||||
{
|
||||
LOG_PRINT_L1("[PARSE URI] regex not matched for uri: " << uri);
|
||||
content.m_path = uri;
|
||||
return true;
|
||||
}
|
||||
if(result[1].matched)
|
||||
{
|
||||
content.m_path = result[1];
|
||||
}
|
||||
if(result[3].matched)
|
||||
{
|
||||
content.m_query = result[3];
|
||||
}
|
||||
if(result[5].matched)
|
||||
{
|
||||
content.m_fragment = result[5];
|
||||
}
|
||||
if(content.m_query.size())
|
||||
{
|
||||
parse_uri_query(content.m_query, content.m_query_params);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline
|
||||
bool parse_url_ipv6(const std::string url_str, http::url_content& content)
|
||||
{
|
||||
STATIC_REGEXP_EXPR_1(rexp_match_uri, "^(([^:]*?)://)?(\\[(.*)\\](:(\\d+))?)(.*)?", boost::regex::icase | boost::regex::normal);
|
||||
// 12 3 4 5 6 7
|
||||
|
||||
content.port = 0;
|
||||
boost::smatch result;
|
||||
if(!(boost::regex_search(url_str, result, rexp_match_uri, boost::match_default) && result[0].matched))
|
||||
{
|
||||
LOG_PRINT_L1("[PARSE URI] regex not matched for uri: " << rexp_match_uri);
|
||||
//content.m_path = uri;
|
||||
return false;
|
||||
}
|
||||
if(result[2].matched)
|
||||
{
|
||||
content.schema = result[2];
|
||||
}
|
||||
if(result[4].matched)
|
||||
{
|
||||
content.host = result[4];
|
||||
}
|
||||
else // if host not matched, matching should be considered failed
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(result[6].matched)
|
||||
{
|
||||
content.port = boost::lexical_cast<uint64_t>(result[6]);
|
||||
}
|
||||
if(result[7].matched)
|
||||
{
|
||||
content.uri = result[7];
|
||||
return parse_uri(result[7], content.m_uri_content);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline
|
||||
bool parse_url(const std::string url_str, http::url_content& content)
|
||||
{
|
||||
|
||||
if (parse_url_ipv6(url_str, content)) return true;
|
||||
|
||||
///iframe_test.html?api_url=http://api.vk.com/api.php&api_id=3289090&api_settings=1&viewer_id=562964060&viewer_type=0&sid=0aad8d1c5713130f9ca0076f2b7b47e532877424961367d81e7fa92455f069be7e21bc3193cbd0be11895&secret=368ebbc0ef&access_token=668bc03f43981d883f73876ffff4aa8564254b359cc745dfa1b3cde7bdab2e94105d8f6d8250717569c0a7&user_id=0&group_id=0&is_app_user=1&auth_key=d2f7a895ca5ff3fdb2a2a8ae23fe679a&language=0&parent_language=0&ad_info=ElsdCQBaQlxiAQRdFUVUXiN2AVBzBx5pU1BXIgZUJlIEAWcgAUoLQg==&referrer=unknown&lc_name=9834b6a3&hash=
|
||||
//STATIC_REGEXP_EXPR_1(rexp_match_uri, "^([^?#]*)(\\?([^#]*))?(#(.*))?", boost::regex::icase | boost::regex::normal);
|
||||
STATIC_REGEXP_EXPR_1(rexp_match_uri, "^(([^:]*?)://)?(([^/:]*)(:(\\d+))?)(.*)?", boost::regex::icase | boost::regex::normal);
|
||||
// 12 34 5 6 7
|
||||
content.port = 0;
|
||||
boost::smatch result;
|
||||
if(!(boost::regex_search(url_str, result, rexp_match_uri, boost::match_default) && result[0].matched))
|
||||
{
|
||||
LOG_PRINT_L1("[PARSE URI] regex not matched for uri: " << rexp_match_uri);
|
||||
//content.m_path = uri;
|
||||
return true;
|
||||
}
|
||||
if(result[2].matched)
|
||||
{
|
||||
content.schema = result[2];
|
||||
}
|
||||
if(result[4].matched)
|
||||
{
|
||||
content.host = result[4];
|
||||
}
|
||||
if(result[6].matched)
|
||||
{
|
||||
content.port = boost::lexical_cast<uint64_t>(result[6]);
|
||||
}
|
||||
if(result[7].matched)
|
||||
{
|
||||
content.uri = result[7];
|
||||
return parse_uri(result[7], content.m_uri_content);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_uri(const std::string uri, http::uri_content& content);
|
||||
bool parse_url_ipv6(const std::string url_str, http::url_content& content);
|
||||
bool parse_url(const std::string url_str, http::url_content& content);
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
#include <boost/asio/ssl.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
|
||||
#define SSL_FINGERPRINT_SIZE 32
|
||||
@ -144,6 +145,9 @@ namespace net_utils
|
||||
|
||||
bool create_ec_ssl_certificate(EVP_PKEY *&pkey, X509 *&cert);
|
||||
bool create_rsa_ssl_certificate(EVP_PKEY *&pkey, X509 *&cert);
|
||||
|
||||
//! Store private key for `ssl` at `base + ".key"` unencrypted and certificate for `ssl` at `base + ".crt"`.
|
||||
boost::system::error_code store_ssl_keys(boost::asio::ssl::context& ssl, const boost::filesystem::path& base);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
#define _REG_EXP_DEFINER_H_
|
||||
|
||||
#include <boost/interprocess/detail/atomic.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
#include "syncobj.h"
|
||||
|
||||
namespace epee
|
||||
|
@ -73,7 +73,8 @@ public: \
|
||||
template<bool is_store, class t_storage> \
|
||||
bool serialize_map(t_storage& stg, typename t_storage::hsection hparent_section) \
|
||||
{ \
|
||||
decltype(*this) &this_ref = *this;
|
||||
decltype(*this) &this_ref = *this; \
|
||||
(void) this_ref; // Suppress unused var warnings. Sometimes this var is used, sometimes not.
|
||||
|
||||
#define KV_SERIALIZE_N(varialble, val_name) \
|
||||
epee::serialization::selector<is_store>::serialize(this_ref.varialble, stg, hparent_section, val_name);
|
||||
|
@ -37,21 +37,14 @@
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "net"
|
||||
|
||||
template<typename context_t>
|
||||
void on_levin_traffic(const context_t &context, bool initiator, bool sent, bool error, size_t bytes, const char *category);
|
||||
|
||||
template<typename context_t>
|
||||
void on_levin_traffic(const context_t &context, bool initiator, bool sent, bool error, size_t bytes, int command);
|
||||
|
||||
namespace
|
||||
{
|
||||
template<typename context_t>
|
||||
void on_levin_traffic(const context_t &context, bool initiator, bool sent, bool error, size_t bytes, const char *category)
|
||||
{
|
||||
MCINFO("net.p2p.traffic", context << bytes << " bytes " << (sent ? "sent" : "received") << (error ? "/corrupt" : "")
|
||||
<< " for category " << category << " initiated by " << (initiator ? "us" : "peer"));
|
||||
}
|
||||
template<typename context_t>
|
||||
void on_levin_traffic(const context_t &context, bool initiator, bool sent, bool error, size_t bytes, int command)
|
||||
{
|
||||
char buf[32];
|
||||
snprintf(buf, sizeof(buf), "command-%u", command);
|
||||
return on_levin_traffic(context, initiator, sent, error, bytes, buf);
|
||||
}
|
||||
static const constexpr epee::serialization::portable_storage::limits_t default_levin_limits = {
|
||||
8192, // objects
|
||||
16384, // fields
|
||||
@ -117,12 +110,11 @@ namespace epee
|
||||
const boost::uuids::uuid &conn_id = context.m_connection_id;
|
||||
typename serialization::portable_storage stg;
|
||||
out_struct.store(stg);
|
||||
byte_slice buff_to_send;
|
||||
levin::message_writer to_send{16 * 1024};
|
||||
std::string buff_to_recv;
|
||||
stg.store_to_binary(buff_to_send, 16 * 1024);
|
||||
stg.store_to_binary(to_send.buffer);
|
||||
|
||||
on_levin_traffic(context, true, true, false, buff_to_send.size(), command);
|
||||
int res = transport.invoke(command, boost::string_ref{reinterpret_cast<const char*>(buff_to_send.data()), buff_to_send.size()}, buff_to_recv, conn_id);
|
||||
int res = transport.invoke(command, std::move(to_send), buff_to_recv, conn_id);
|
||||
if( res <=0 )
|
||||
{
|
||||
LOG_PRINT_L1("Failed to invoke command " << command << " return code " << res);
|
||||
@ -145,10 +137,9 @@ namespace epee
|
||||
const boost::uuids::uuid &conn_id = context.m_connection_id;
|
||||
typename serialization::portable_storage stg;
|
||||
const_cast<t_arg&>(out_struct).store(stg);//TODO: add true const support to searilzation
|
||||
byte_slice buff_to_send;
|
||||
stg.store_to_binary(buff_to_send, 16 * 1024);
|
||||
on_levin_traffic(context, true, true, false, buff_to_send.size(), command);
|
||||
int res = transport.invoke_async(command, epee::to_span(buff_to_send), conn_id, [cb, command](int code, const epee::span<const uint8_t> buff, typename t_transport::connection_context& context)->bool
|
||||
levin::message_writer to_send{16 * 1024};
|
||||
stg.store_to_binary(to_send.buffer);
|
||||
int res = transport.invoke_async(command, std::move(to_send), conn_id, [cb, command](int code, const epee::span<const uint8_t> buff, typename t_transport::connection_context& context)->bool
|
||||
{
|
||||
t_result result_struct = AUTO_VAL_INIT(result_struct);
|
||||
if( code <=0 )
|
||||
@ -192,11 +183,10 @@ namespace epee
|
||||
const boost::uuids::uuid &conn_id = context.m_connection_id;
|
||||
serialization::portable_storage stg;
|
||||
out_struct.store(stg);
|
||||
byte_slice buff_to_send;
|
||||
stg.store_to_binary(buff_to_send);
|
||||
levin::message_writer to_send;
|
||||
stg.store_to_binary(to_send.buffer);
|
||||
|
||||
on_levin_traffic(context, true, true, false, buff_to_send.size(), command);
|
||||
int res = transport.notify(command, epee::to_span(buff_to_send), conn_id);
|
||||
int res = transport.send(to_send.finalize_notify(command), conn_id);
|
||||
if(res <=0 )
|
||||
{
|
||||
MERROR("Failed to notify command " << command << " return code " << res);
|
||||
@ -207,7 +197,7 @@ namespace epee
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
template<class t_owner, class t_in_type, class t_out_type, class t_context, class callback_t>
|
||||
int buff_to_t_adapter(int command, const epee::span<const uint8_t> in_buff, byte_slice& buff_out, callback_t cb, t_context& context )
|
||||
int buff_to_t_adapter(int command, const epee::span<const uint8_t> in_buff, byte_stream& buff_out, callback_t cb, t_context& context )
|
||||
{
|
||||
serialization::portable_storage strg;
|
||||
if(!strg.load_from_binary(in_buff, &default_levin_limits))
|
||||
@ -230,12 +220,11 @@ namespace epee
|
||||
serialization::portable_storage strg_out;
|
||||
static_cast<t_out_type&>(out_struct).store(strg_out);
|
||||
|
||||
if(!strg_out.store_to_binary(buff_out, 32 * 1024))
|
||||
if(!strg_out.store_to_binary(buff_out))
|
||||
{
|
||||
LOG_ERROR("Failed to store_to_binary in command" << command);
|
||||
return -1;
|
||||
}
|
||||
on_levin_traffic(context, false, true, false, buff_out.size(), command);
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -262,7 +251,7 @@ namespace epee
|
||||
}
|
||||
|
||||
#define CHAIN_LEVIN_INVOKE_MAP2(context_type) \
|
||||
int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_slice& buff_out, context_type& context) \
|
||||
int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_stream& buff_out, context_type& context) \
|
||||
{ \
|
||||
bool handled = false; \
|
||||
return handle_invoke_map(false, command, in_buff, buff_out, context, handled); \
|
||||
@ -271,13 +260,13 @@ namespace epee
|
||||
#define CHAIN_LEVIN_NOTIFY_MAP2(context_type) \
|
||||
int notify(int command, const epee::span<const uint8_t> in_buff, context_type& context) \
|
||||
{ \
|
||||
bool handled = false; epee::byte_slice fake_str; \
|
||||
return handle_invoke_map(true, command, in_buff, fake_str, context, handled); \
|
||||
bool handled = false; epee::byte_stream fake_str; \
|
||||
return handle_invoke_map(true, command, in_buff, fake_str, context, handled); \
|
||||
}
|
||||
|
||||
|
||||
#define CHAIN_LEVIN_INVOKE_MAP() \
|
||||
int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_slice& buff_out, epee::net_utils::connection_context_base& context) \
|
||||
int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_stream& buff_out, epee::net_utils::connection_context_base& context) \
|
||||
{ \
|
||||
bool handled = false; \
|
||||
return handle_invoke_map(false, command, in_buff, buff_out, context, handled); \
|
||||
@ -297,7 +286,7 @@ namespace epee
|
||||
}
|
||||
|
||||
#define BEGIN_INVOKE_MAP2(owner_type) \
|
||||
template <class t_context> int handle_invoke_map(bool is_notify, int command, const epee::span<const uint8_t> in_buff, epee::byte_slice& buff_out, t_context& context, bool& handled) \
|
||||
template <class t_context> int handle_invoke_map(bool is_notify, int command, const epee::span<const uint8_t> in_buff, epee::byte_stream& buff_out, t_context& context, bool& handled) \
|
||||
{ \
|
||||
try { \
|
||||
typedef owner_type internal_owner_type_name;
|
||||
|
@ -24,24 +24,17 @@
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include "misc_language.h"
|
||||
#include "portable_storage_base.h"
|
||||
#include "portable_storage_from_bin.h"
|
||||
#include "portable_storage_to_json.h"
|
||||
#include "portable_storage_from_json.h"
|
||||
#include "portable_storage_val_converters.h"
|
||||
#include "misc_log_ex.h"
|
||||
#include "span.h"
|
||||
#include "int-util.h"
|
||||
|
||||
namespace epee
|
||||
{
|
||||
class byte_slice;
|
||||
class byte_stream;
|
||||
namespace serialization
|
||||
{
|
||||
/************************************************************************/
|
||||
@ -91,8 +84,13 @@ namespace epee
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
bool store_to_binary(byte_slice& target, std::size_t initial_buffer_size = 8192);
|
||||
bool load_from_binary(const epee::span<const uint8_t> target, const limits_t *limits = NULL);
|
||||
bool load_from_binary(const std::string& target, const limits_t *limits = NULL) { return load_from_binary(epee::strspan<uint8_t>(target), limits); }
|
||||
bool store_to_binary(byte_stream& ss);
|
||||
bool load_from_binary(const epee::span<const uint8_t> target, const limits_t *limits = nullptr);
|
||||
bool load_from_binary(const std::string& target, const limits_t *limits = nullptr)
|
||||
{
|
||||
return load_from_binary(epee::strspan<uint8_t>(target), limits);
|
||||
}
|
||||
|
||||
template<class trace_policy>
|
||||
bool dump_as_xml(std::string& targetObj, const std::string& root_name = "");
|
||||
bool dump_as_json(std::string& targetObj, size_t indent = 0, bool insert_newlines = true);
|
||||
@ -118,90 +116,13 @@ namespace epee
|
||||
};
|
||||
#pragma pack(pop)
|
||||
};
|
||||
inline
|
||||
bool portable_storage::dump_as_json(std::string& buff, size_t indent, bool insert_newlines)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
std::stringstream ss;
|
||||
epee::serialization::dump_as_json(ss, m_root, indent, insert_newlines);
|
||||
buff = ss.str();
|
||||
return true;
|
||||
CATCH_ENTRY("portable_storage::dump_as_json", false)
|
||||
}
|
||||
inline
|
||||
bool portable_storage::load_from_json(const std::string& source)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
return json::load_from_json(source, *this);
|
||||
CATCH_ENTRY("portable_storage::load_from_json", false)
|
||||
}
|
||||
inline
|
||||
bool portable_storage::load_from_json_can_throw(const std::string& source)
|
||||
{
|
||||
return json::load_from_json_can_throw(source, *this);
|
||||
}
|
||||
|
||||
template<class trace_policy>
|
||||
bool portable_storage::dump_as_xml(std::string& targetObj, const std::string& root_name)
|
||||
{
|
||||
return false;//TODO: don't think i ever again will use xml - ambiguous and "overtagged" format
|
||||
}
|
||||
inline
|
||||
bool portable_storage::load_from_binary(const epee::span<const uint8_t> source, const limits_t *limits)
|
||||
{
|
||||
m_root.m_entries.clear();
|
||||
if(source.size() < sizeof(storage_block_header))
|
||||
{
|
||||
LOG_ERROR("portable_storage: wrong binary format, packet size = " << source.size() << " less than expected sizeof(storage_block_header)=" << sizeof(storage_block_header));
|
||||
return false;
|
||||
}
|
||||
storage_block_header* pbuff = (storage_block_header*)source.data();
|
||||
if(pbuff->m_signature_a != SWAP32LE(PORTABLE_STORAGE_SIGNATUREA) ||
|
||||
pbuff->m_signature_b != SWAP32LE(PORTABLE_STORAGE_SIGNATUREB)
|
||||
)
|
||||
{
|
||||
LOG_ERROR("portable_storage: wrong binary format - signature mismatch");
|
||||
return false;
|
||||
}
|
||||
if(pbuff->m_ver != PORTABLE_STORAGE_FORMAT_VER)
|
||||
{
|
||||
LOG_ERROR("portable_storage: wrong binary format - unknown format ver = " << pbuff->m_ver);
|
||||
return false;
|
||||
}
|
||||
TRY_ENTRY();
|
||||
throwable_buffer_reader buf_reader(source.data()+sizeof(storage_block_header), source.size()-sizeof(storage_block_header));
|
||||
if (limits)
|
||||
buf_reader.set_limits(limits->n_objects, limits->n_fields, limits->n_strings);
|
||||
buf_reader.read(m_root);
|
||||
return true;//TODO:
|
||||
CATCH_ENTRY("portable_storage::load_from_binary", false);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
inline
|
||||
hsection portable_storage::open_section(const std::string& section_name, hsection hparent_section, bool create_if_notexist)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
hparent_section = hparent_section ? hparent_section:&m_root;
|
||||
storage_entry* pentry = find_storage_entry(section_name, hparent_section);
|
||||
if(!pentry)
|
||||
{
|
||||
if(!create_if_notexist)
|
||||
return nullptr;
|
||||
return insert_new_section(section_name, hparent_section);
|
||||
}
|
||||
CHECK_AND_ASSERT(pentry , nullptr);
|
||||
//check that section_entry we find is real "CSSection"
|
||||
if(pentry->type() != typeid(section))
|
||||
{
|
||||
if(create_if_notexist)
|
||||
*pentry = storage_entry(section());//replace
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
return &boost::get<section>(*pentry);
|
||||
CATCH_ENTRY("portable_storage::open_section", nullptr);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
}
|
||||
|
||||
template<class to_type>
|
||||
struct get_value_visitor: boost::static_visitor<void>
|
||||
{
|
||||
@ -227,20 +148,6 @@ namespace epee
|
||||
//CATCH_ENTRY("portable_storage::template<>get_value", false);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
inline
|
||||
bool portable_storage::get_value(const std::string& value_name, storage_entry& val, hsection hparent_section)
|
||||
{
|
||||
//TRY_ENTRY();
|
||||
if(!hparent_section) hparent_section = &m_root;
|
||||
storage_entry* pentry = find_storage_entry(value_name, hparent_section);
|
||||
if(!pentry)
|
||||
return false;
|
||||
|
||||
val = *pentry;
|
||||
return true;
|
||||
//CATCH_ENTRY("portable_storage::template<>get_value", false);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
template<class t_value>
|
||||
bool portable_storage::set_value(const std::string& value_name, t_value&& v, hsection hparent_section)
|
||||
{
|
||||
@ -262,19 +169,6 @@ namespace epee
|
||||
CATCH_ENTRY("portable_storage::template<>set_value", false);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
inline
|
||||
storage_entry* portable_storage::find_storage_entry(const std::string& pentry_name, hsection psection)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
CHECK_AND_ASSERT(psection, nullptr);
|
||||
auto it = psection->m_entries.find(pentry_name);
|
||||
if(it == psection->m_entries.end())
|
||||
return nullptr;
|
||||
|
||||
return &it->second;
|
||||
CATCH_ENTRY("portable_storage::find_storage_entry", nullptr);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
template<class entry_type>
|
||||
storage_entry* portable_storage::insert_new_entry_get_storage_entry(const std::string& pentry_name, hsection psection, entry_type&& entry)
|
||||
{
|
||||
@ -287,16 +181,6 @@ namespace epee
|
||||
CATCH_ENTRY("portable_storage::insert_new_entry_get_storage_entry", nullptr);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
inline
|
||||
hsection portable_storage::insert_new_section(const std::string& pentry_name, hsection psection)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
storage_entry* pse = insert_new_entry_get_storage_entry(pentry_name, psection, section());
|
||||
if(!pse) return nullptr;
|
||||
return &boost::get<section>(*pse);
|
||||
CATCH_ENTRY("portable_storage::insert_new_section", nullptr);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
template<class to_type>
|
||||
struct get_first_value_visitor: boost::static_visitor<bool>
|
||||
{
|
||||
@ -350,7 +234,6 @@ namespace epee
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<class t_value>
|
||||
bool portable_storage::get_next_value(harray hval_array, t_value& target)
|
||||
{
|
||||
@ -408,83 +291,5 @@ namespace epee
|
||||
return true;
|
||||
CATCH_ENTRY("portable_storage::insert_next_value", false);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
//sections
|
||||
inline
|
||||
harray portable_storage::get_first_section(const std::string& sec_name, hsection& h_child_section, hsection hparent_section)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
if(!hparent_section) hparent_section = &m_root;
|
||||
storage_entry* pentry = find_storage_entry(sec_name, hparent_section);
|
||||
if(!pentry)
|
||||
return nullptr;
|
||||
if(pentry->type() != typeid(array_entry))
|
||||
return nullptr;
|
||||
array_entry& ar_entry = boost::get<array_entry>(*pentry);
|
||||
if(ar_entry.type() != typeid(array_entry_t<section>))
|
||||
return nullptr;
|
||||
array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(ar_entry);
|
||||
section* psec = sec_array.get_first_val();
|
||||
if(!psec)
|
||||
return nullptr;
|
||||
h_child_section = psec;
|
||||
return &ar_entry;
|
||||
CATCH_ENTRY("portable_storage::get_first_section", nullptr);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
inline
|
||||
bool portable_storage::get_next_section(harray hsec_array, hsection& h_child_section)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
CHECK_AND_ASSERT(hsec_array, false);
|
||||
if(hsec_array->type() != typeid(array_entry_t<section>))
|
||||
return false;
|
||||
array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(*hsec_array);
|
||||
h_child_section = sec_array.get_next_val();
|
||||
if(!h_child_section)
|
||||
return false;
|
||||
return true;
|
||||
CATCH_ENTRY("portable_storage::get_next_section", false);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
inline
|
||||
harray portable_storage::insert_first_section(const std::string& sec_name, hsection& hinserted_childsection, hsection hparent_section)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
if(!hparent_section) hparent_section = &m_root;
|
||||
storage_entry* pentry = find_storage_entry(sec_name, hparent_section);
|
||||
if(!pentry)
|
||||
{
|
||||
pentry = insert_new_entry_get_storage_entry(sec_name, hparent_section, array_entry(array_entry_t<section>()));
|
||||
if(!pentry)
|
||||
return nullptr;
|
||||
}
|
||||
if(pentry->type() != typeid(array_entry))
|
||||
*pentry = storage_entry(array_entry(array_entry_t<section>()));
|
||||
|
||||
array_entry& ar_entry = boost::get<array_entry>(*pentry);
|
||||
if(ar_entry.type() != typeid(array_entry_t<section>))
|
||||
ar_entry = array_entry(array_entry_t<section>());
|
||||
|
||||
array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(ar_entry);
|
||||
hinserted_childsection = &sec_array.insert_first_val(section());
|
||||
return &ar_entry;
|
||||
CATCH_ENTRY("portable_storage::insert_first_section", nullptr);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
inline
|
||||
bool portable_storage::insert_next_section(harray hsec_array, hsection& hinserted_childsection)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
CHECK_AND_ASSERT(hsec_array, false);
|
||||
CHECK_AND_ASSERT_MES(hsec_array->type() == typeid(array_entry_t<section>),
|
||||
false, "unexpected type(not 'section') in insert_next_section, type: " << hsec_array->type().name());
|
||||
|
||||
array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(*hsec_array);
|
||||
hinserted_childsection = &sec_array.insert_next_value(section());
|
||||
return true;
|
||||
CATCH_ENTRY("portable_storage::insert_next_section", false);
|
||||
}
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
}
|
||||
}
|
||||
|
@ -29,10 +29,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/variant.hpp>
|
||||
#include <boost/any.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include <map>
|
||||
|
||||
#define PORTABLE_STORAGE_SIGNATUREA 0x01011101
|
||||
#define PORTABLE_STORAGE_SIGNATUREB 0x01020101 // bender's nightmare
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
#pragma once
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include "parserse_base_utils.h"
|
||||
#include "file_io_utils.h"
|
||||
|
@ -29,12 +29,15 @@
|
||||
#include <string>
|
||||
|
||||
#include "byte_slice.h"
|
||||
#include "parserse_base_utils.h"
|
||||
#include "parserse_base_utils.h" /// TODO: (mj-xmr) This will be reduced in an another PR
|
||||
#include "portable_storage.h"
|
||||
#include "file_io_utils.h"
|
||||
#include "span.h"
|
||||
|
||||
namespace epee
|
||||
{
|
||||
class byte_stream;
|
||||
|
||||
namespace serialization
|
||||
{
|
||||
//-----------------------------------------------------------------------------------------------------------
|
||||
@ -126,5 +129,14 @@ namespace epee
|
||||
store_t_to_binary(str_in, binary_buff, initial_buffer_size);
|
||||
return binary_buff;
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------------------
|
||||
template<class t_struct>
|
||||
bool store_t_to_binary(t_struct& str_in, byte_stream& binary_buff)
|
||||
{
|
||||
portable_storage ps;
|
||||
str_in.store(ps);
|
||||
return ps.store_to_binary(binary_buff);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "misc_language.h"
|
||||
#include "portable_storage_base.h"
|
||||
#include "portable_storage_bin_utils.h"
|
||||
#include "misc_log_ex.h"
|
||||
|
||||
namespace epee
|
||||
{
|
||||
|
@ -28,12 +28,17 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <time.h>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
#include "misc_language.h"
|
||||
#include "portable_storage_base.h"
|
||||
#include "parserse_base_utils.h"
|
||||
#include "warnings.h"
|
||||
#include "misc_log_ex.h"
|
||||
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <typeinfo>
|
||||
#include <iomanip>
|
||||
|
||||
namespace epee
|
||||
{
|
||||
|
@ -24,33 +24,16 @@
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
|
||||
|
||||
#ifndef _STRING_TOOLS_H_
|
||||
#define _STRING_TOOLS_H_
|
||||
|
||||
// Previously pulled in by ASIO, further cleanup still required ...
|
||||
#ifdef _WIN32
|
||||
# include <winsock2.h>
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <locale>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include "misc_log_ex.h"
|
||||
#include "storages/parserse_base_utils.h"
|
||||
#include "hex.h"
|
||||
#include "memwipe.h"
|
||||
#include "mlocker.h"
|
||||
#include "span.h"
|
||||
#include "warnings.h"
|
||||
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
#ifndef OUT
|
||||
#define OUT
|
||||
@ -74,182 +57,28 @@ namespace string_tools
|
||||
{
|
||||
return from_hex::to_string(res, s);
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
PUSH_WARNINGS
|
||||
DISABLE_GCC_WARNING(maybe-uninitialized)
|
||||
template<class XType>
|
||||
inline bool get_xtype_from_string(OUT XType& val, const std::string& str_id)
|
||||
{
|
||||
if (std::is_integral<XType>::value && !std::numeric_limits<XType>::is_signed && !std::is_same<XType, bool>::value)
|
||||
{
|
||||
for (char c : str_id)
|
||||
{
|
||||
if (!epee::misc_utils::parse::isdigit(c))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
val = boost::lexical_cast<XType>(str_id);
|
||||
return true;
|
||||
}
|
||||
catch(const std::exception& /*e*/)
|
||||
{
|
||||
//const char* pmsg = e.what();
|
||||
return false;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
POP_WARNINGS
|
||||
//----------------------------------------------------------------------------
|
||||
template<class XType>
|
||||
inline bool xtype_to_string(const XType& val, std::string& str)
|
||||
{
|
||||
try
|
||||
{
|
||||
str = boost::lexical_cast<std::string>(val);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
std::string get_ip_string_from_int32(uint32_t ip);
|
||||
//----------------------------------------------------------------------------
|
||||
bool get_ip_int32_from_string(uint32_t& ip, const std::string& ip_str);
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool parse_peer_from_string(uint32_t& ip, uint16_t& port, const std::string& addres)
|
||||
{
|
||||
//parse ip and address
|
||||
std::string::size_type p = addres.find(':');
|
||||
std::string ip_str, port_str;
|
||||
if(p == std::string::npos)
|
||||
{
|
||||
port = 0;
|
||||
ip_str = addres;
|
||||
}
|
||||
else
|
||||
{
|
||||
ip_str = addres.substr(0, p);
|
||||
port_str = addres.substr(p+1, addres.size());
|
||||
}
|
||||
|
||||
if(!get_ip_int32_from_string(ip, ip_str))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(p != std::string::npos && !get_xtype_from_string(port, port_str))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline std::string num_to_string_fast(int64_t val)
|
||||
{
|
||||
/*
|
||||
char buff[30] = {0};
|
||||
i64toa_s(val, buff, sizeof(buff)-1, 10);
|
||||
return buff;*/
|
||||
return boost::lexical_cast<std::string>(val);
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
inline std::string to_string_hex(const T &val)
|
||||
{
|
||||
static_assert(std::is_arithmetic<T>::value, "only arithmetic types");
|
||||
std::stringstream ss;
|
||||
ss << std::hex << val;
|
||||
std::string s;
|
||||
ss >> s;
|
||||
return s;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
std::string get_ip_string_from_int32(uint32_t ip);
|
||||
bool get_ip_int32_from_string(uint32_t& ip, const std::string& ip_str);
|
||||
bool parse_peer_from_string(uint32_t& ip, uint16_t& port, const std::string& addres);
|
||||
std::string num_to_string_fast(int64_t val);
|
||||
|
||||
inline bool compare_no_case(const std::string& str1, const std::string& str2)
|
||||
{
|
||||
|
||||
return !boost::iequals(str1, str2);
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
inline std::string& get_current_module_name()
|
||||
{
|
||||
static std::string module_name;
|
||||
return module_name;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
inline std::string& get_current_module_folder()
|
||||
{
|
||||
static std::string module_folder;
|
||||
return module_folder;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
bool compare_no_case(const std::string& str1, const std::string& str2);
|
||||
std::string& get_current_module_name();
|
||||
std::string& get_current_module_folder();
|
||||
#ifdef _WIN32
|
||||
inline std::string get_current_module_path()
|
||||
{
|
||||
char pname [5000] = {0};
|
||||
GetModuleFileNameA( NULL, pname, sizeof(pname));
|
||||
pname[sizeof(pname)-1] = 0; //be happy ;)
|
||||
return pname;
|
||||
}
|
||||
std::string get_current_module_path();
|
||||
#endif
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool set_module_name_and_folder(const std::string& path_to_process_)
|
||||
{
|
||||
std::string path_to_process = path_to_process_;
|
||||
#ifdef _WIN32
|
||||
path_to_process = get_current_module_path();
|
||||
#endif
|
||||
std::string::size_type a = path_to_process.rfind( '\\' );
|
||||
if(a == std::string::npos )
|
||||
{
|
||||
a = path_to_process.rfind( '/' );
|
||||
}
|
||||
if ( a != std::string::npos )
|
||||
{
|
||||
get_current_module_name() = path_to_process.substr(a+1, path_to_process.size());
|
||||
get_current_module_folder() = path_to_process.substr(0, a);
|
||||
return true;
|
||||
}else
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool trim_left(std::string& str)
|
||||
{
|
||||
for(std::string::iterator it = str.begin(); it!= str.end() && isspace(static_cast<unsigned char>(*it));)
|
||||
str.erase(str.begin());
|
||||
|
||||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
inline bool trim_right(std::string& str)
|
||||
{
|
||||
|
||||
for(std::string::reverse_iterator it = str.rbegin(); it!= str.rend() && isspace(static_cast<unsigned char>(*it));)
|
||||
str.erase( --((it++).base()));
|
||||
|
||||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
inline std::string& trim(std::string& str)
|
||||
{
|
||||
|
||||
trim_left(str);
|
||||
trim_right(str);
|
||||
return str;
|
||||
}
|
||||
bool set_module_name_and_folder(const std::string& path_to_process_);
|
||||
bool trim_left(std::string& str);
|
||||
bool trim_right(std::string& str);
|
||||
//----------------------------------------------------------------------------
|
||||
inline std::string& trim(std::string& str)
|
||||
{
|
||||
trim_left(str);
|
||||
trim_right(str);
|
||||
return str;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
inline std::string trim(const std::string& str_)
|
||||
{
|
||||
@ -258,18 +87,8 @@ POP_WARNINGS
|
||||
trim_right(str);
|
||||
return str;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
inline std::string pad_string(std::string s, size_t n, char c = ' ', bool prepend = false)
|
||||
{
|
||||
if (s.size() < n)
|
||||
{
|
||||
if (prepend)
|
||||
s = std::string(n - s.size(), c) + s;
|
||||
else
|
||||
s.append(n - s.size(), c);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
std::string pad_string(std::string s, size_t n, char c = ' ', bool prepend = false);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
template<class t_pod_type>
|
||||
std::string pod_to_hex(const t_pod_type& s)
|
||||
@ -296,64 +115,25 @@ POP_WARNINGS
|
||||
{
|
||||
return hex_to_pod(hex_str, unwrap(s));
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
//----------------------------------------------------------------------------
|
||||
template<typename T>
|
||||
inline std::string to_string_hex(const T &val)
|
||||
{
|
||||
static_assert(std::is_arithmetic<T>::value, "only arithmetic types");
|
||||
std::stringstream ss;
|
||||
ss << std::hex << val;
|
||||
std::string s;
|
||||
ss >> s;
|
||||
return s;
|
||||
}
|
||||
|
||||
bool validate_hex(uint64_t length, const std::string& str);
|
||||
//----------------------------------------------------------------------------
|
||||
inline std::string get_extension(const std::string& str)
|
||||
{
|
||||
std::string res;
|
||||
std::string::size_type pos = str.rfind('.');
|
||||
if(std::string::npos == pos)
|
||||
return res;
|
||||
|
||||
res = str.substr(pos+1, str.size()-pos);
|
||||
return res;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
inline std::string cut_off_extension(const std::string& str)
|
||||
{
|
||||
std::string res;
|
||||
std::string::size_type pos = str.rfind('.');
|
||||
if(std::string::npos == pos)
|
||||
return str;
|
||||
|
||||
res = str.substr(0, pos);
|
||||
return res;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
std::string get_extension(const std::string& str);
|
||||
std::string cut_off_extension(const std::string& str);
|
||||
|
||||
#ifdef _WIN32
|
||||
inline std::wstring utf8_to_utf16(const std::string& str)
|
||||
{
|
||||
if (str.empty())
|
||||
return {};
|
||||
int wstr_size = MultiByteToWideChar(CP_UTF8, 0, &str[0], str.size(), NULL, 0);
|
||||
if (wstr_size == 0)
|
||||
{
|
||||
throw std::runtime_error(std::error_code(GetLastError(), std::system_category()).message());
|
||||
}
|
||||
std::wstring wstr(wstr_size, wchar_t{});
|
||||
if (!MultiByteToWideChar(CP_UTF8, 0, &str[0], str.size(), &wstr[0], wstr_size))
|
||||
{
|
||||
throw std::runtime_error(std::error_code(GetLastError(), std::system_category()).message());
|
||||
}
|
||||
return wstr;
|
||||
}
|
||||
inline std::string utf16_to_utf8(const std::wstring& wstr)
|
||||
{
|
||||
if (wstr.empty())
|
||||
return {};
|
||||
int str_size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], wstr.size(), NULL, 0, NULL, NULL);
|
||||
if (str_size == 0)
|
||||
{
|
||||
throw std::runtime_error(std::error_code(GetLastError(), std::system_category()).message());
|
||||
}
|
||||
std::string str(str_size, char{});
|
||||
if (!WideCharToMultiByte(CP_UTF8, 0, &wstr[0], wstr.size(), &str[0], str_size, NULL, NULL))
|
||||
{
|
||||
throw std::runtime_error(std::error_code(GetLastError(), std::system_category()).message());
|
||||
}
|
||||
return str;
|
||||
}
|
||||
std::wstring utf8_to_utf16(const std::string& str);
|
||||
std::string utf16_to_utf8(const std::wstring& wstr);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
91
contrib/epee/include/string_tools_lexical.h
Normal file
91
contrib/epee/include/string_tools_lexical.h
Normal file
@ -0,0 +1,91 @@
|
||||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * 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.
|
||||
// * Neither the name of the Andrey N. Sabelnikov 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 OWNER 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.
|
||||
//
|
||||
|
||||
#ifndef _STRING_TOOLS_LEXICAL_H_
|
||||
#define _STRING_TOOLS_LEXICAL_H_
|
||||
|
||||
#include "warnings.h"
|
||||
#include "storages/parserse_base_utils.h"
|
||||
#include <boost/lexical_cast.hpp> // A heavy header, that was extracted from the rest
|
||||
|
||||
#ifndef OUT
|
||||
#define OUT
|
||||
#endif
|
||||
|
||||
namespace epee
|
||||
{
|
||||
namespace string_tools
|
||||
{
|
||||
PUSH_WARNINGS
|
||||
DISABLE_GCC_WARNING(maybe-uninitialized)
|
||||
template<class XType>
|
||||
inline bool get_xtype_from_string(OUT XType& val, const std::string& str_id)
|
||||
{
|
||||
if (std::is_integral<XType>::value && !std::numeric_limits<XType>::is_signed && !std::is_same<XType, bool>::value)
|
||||
{
|
||||
for (char c : str_id)
|
||||
{
|
||||
if (!epee::misc_utils::parse::isdigit(c))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
val = boost::lexical_cast<XType>(str_id);
|
||||
return true;
|
||||
}
|
||||
catch(const std::exception& /*e*/)
|
||||
{
|
||||
//const char* pmsg = e.what();
|
||||
return false;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
POP_WARNINGS
|
||||
|
||||
template<class XType>
|
||||
inline bool xtype_to_string(const XType& val, std::string& str)
|
||||
{
|
||||
try
|
||||
{
|
||||
str = boost::lexical_cast<std::string>(val);
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif //_STRING_TOOLS_LEXICAL_H_
|
@ -28,8 +28,6 @@
|
||||
#ifndef _TINY_INI_H_
|
||||
#define _TINY_INI_H_
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include "string_tools.h"
|
||||
|
||||
namespace epee
|
||||
@ -37,20 +35,8 @@ namespace epee
|
||||
namespace tiny_ini
|
||||
{
|
||||
|
||||
inline
|
||||
bool get_param_value(const std::string& param_name, const std::string& ini_entry, std::string& res)
|
||||
{
|
||||
std::string expr_str = std::string() + "^("+ param_name +") *=(.*?)$";
|
||||
const boost::regex match_ini_entry( expr_str, boost::regex::icase | boost::regex::normal);
|
||||
boost::smatch result;
|
||||
if(!boost::regex_search(ini_entry, result, match_ini_entry, boost::match_default))
|
||||
return false;
|
||||
res = result[2];
|
||||
string_tools::trim(res);
|
||||
return true;
|
||||
}
|
||||
inline
|
||||
std::string get_param_value(const std::string& param_name, const std::string& ini_entry)
|
||||
bool get_param_value(const std::string& param_name, const std::string& ini_entry, std::string& res);
|
||||
inline std::string get_param_value(const std::string& param_name, const std::string& ini_entry)
|
||||
{
|
||||
std::string buff;
|
||||
get_param_value(param_name, ini_entry, buff);
|
||||
|
@ -26,10 +26,25 @@
|
||||
# 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.
|
||||
|
||||
set(EPEE_INCLUDE_DIR_BASE "${CMAKE_CURRENT_SOURCE_DIR}/../include")
|
||||
|
||||
# Adding headers to the file list, to be able to search for them in IDEs.
|
||||
file(GLOB EPEE_HEADERS_PUBLIC
|
||||
"${EPEE_INCLUDE_DIR_BASE}/*.h*" # h* will include hpps as well.
|
||||
"${EPEE_INCLUDE_DIR_BASE}/**/*.h*" # Any number of subdirs will be included.
|
||||
)
|
||||
|
||||
add_library(epee STATIC byte_slice.cpp byte_stream.cpp hex.cpp abstract_http_client.cpp http_auth.cpp mlog.cpp net_helper.cpp net_utils_base.cpp string_tools.cpp
|
||||
wipeable_string.cpp levin_base.cpp memwipe.c connection_basic.cpp network_throttle.cpp network_throttle-detail.cpp mlocker.cpp buffer.cpp net_ssl.cpp
|
||||
int-util.cpp portable_storage.cpp)
|
||||
int-util.cpp portable_storage.cpp
|
||||
misc_language.cpp
|
||||
misc_os_dependent.cpp
|
||||
file_io_utils.cpp
|
||||
net_parse_helpers.cpp
|
||||
http_base.cpp
|
||||
tiny_ini.cpp
|
||||
${EPEE_HEADERS_PUBLIC}
|
||||
)
|
||||
|
||||
if (NOT CC_NO_EXTERNAL_DEPS)
|
||||
add_dependencies(epee boost_ext)
|
||||
@ -78,3 +93,6 @@ if (USE_READLINE AND (GNU_READLINE_FOUND OR (DEPENDS AND NOT MINGW)))
|
||||
PRIVATE
|
||||
${GNU_READLINE_LIBRARY})
|
||||
endif()
|
||||
|
||||
target_include_directories(epee PUBLIC "${EPEE_INCLUDE_DIR_BASE}")
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "net/abstract_http_client.h"
|
||||
#include "net/http_base.h"
|
||||
#include "net/net_parse_helpers.h"
|
||||
#include "misc_log_ex.h"
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "net.http"
|
||||
|
@ -36,6 +36,11 @@
|
||||
#include "byte_slice.h"
|
||||
#include "byte_stream.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
const std::size_t page_size = 4096;
|
||||
}
|
||||
|
||||
namespace epee
|
||||
{
|
||||
struct byte_slice_data
|
||||
@ -173,16 +178,27 @@ namespace epee
|
||||
: byte_slice(adapt_buffer{}, std::move(buffer))
|
||||
{}
|
||||
|
||||
byte_slice::byte_slice(byte_stream&& stream) noexcept
|
||||
byte_slice::byte_slice(byte_stream&& stream, const bool shrink)
|
||||
: storage_(nullptr), portion_(stream.data(), stream.size())
|
||||
{
|
||||
if (stream.size())
|
||||
if (portion_.size())
|
||||
{
|
||||
std::uint8_t* const data = stream.take_buffer().release() - sizeof(raw_byte_slice);
|
||||
byte_buffer buf;
|
||||
if (shrink && page_size <= stream.available())
|
||||
{
|
||||
buf = byte_buffer_resize(stream.take_buffer(), portion_.size());
|
||||
if (!buf)
|
||||
throw std::bad_alloc{};
|
||||
portion_ = {buf.get(), portion_.size()};
|
||||
}
|
||||
else // no need to shrink buffer
|
||||
buf = stream.take_buffer();
|
||||
|
||||
std::uint8_t* const data = buf.release() - sizeof(raw_byte_slice);
|
||||
new (data) raw_byte_slice{};
|
||||
storage_.reset(reinterpret_cast<raw_byte_slice*>(data));
|
||||
}
|
||||
else
|
||||
else // empty stream
|
||||
portion_ = nullptr;
|
||||
}
|
||||
|
||||
|
231
contrib/epee/src/file_io_utils.cpp
Normal file
231
contrib/epee/src/file_io_utils.cpp
Normal file
@ -0,0 +1,231 @@
|
||||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * 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.
|
||||
// * Neither the name of the Andrey N. Sabelnikov 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 OWNER 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 "file_io_utils.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#include "string_tools.h"
|
||||
#endif
|
||||
|
||||
// On Windows there is a problem with non-ASCII characters in path and file names
|
||||
// as far as support by the standard components used is concerned:
|
||||
|
||||
// The various file stream classes, e.g. std::ifstream and std::ofstream, are
|
||||
// part of the GNU C++ Library / libstdc++. On the most basic level they use the
|
||||
// fopen() call as defined / made accessible to programs compiled within MSYS2
|
||||
// by the stdio.h header file maintained by the MinGW project.
|
||||
|
||||
// The critical point: The implementation of fopen() is part of MSVCRT, the
|
||||
// Microsoft Visual C/C++ Runtime Library, and this method does NOT offer any
|
||||
// Unicode support.
|
||||
|
||||
// Monero code that would want to continue to use the normal file stream classes
|
||||
// but WITH Unicode support could therefore not solve this problem on its own,
|
||||
// but 2 different projects from 2 different maintaining groups would need changes
|
||||
// in this particular direction - something probably difficult to achieve and
|
||||
// with a long time to wait until all new versions / releases arrive.
|
||||
|
||||
// Implemented solution approach: Circumvent the problem by stopping to use std
|
||||
// file stream classes on Windows and directly use Unicode-capable WIN32 API
|
||||
// calls. Most of the code doing so is concentrated in this header file here.
|
||||
|
||||
namespace epee
|
||||
{
|
||||
namespace file_io_utils
|
||||
{
|
||||
|
||||
bool is_file_exist(const std::string& path)
|
||||
{
|
||||
boost::filesystem::path p(path);
|
||||
return boost::filesystem::exists(p);
|
||||
}
|
||||
|
||||
|
||||
bool save_string_to_file(const std::string& path_to_file, const std::string& str)
|
||||
{
|
||||
#ifdef WIN32
|
||||
std::wstring wide_path;
|
||||
try { wide_path = string_tools::utf8_to_utf16(path_to_file); } catch (...) { return false; }
|
||||
HANDLE file_handle = CreateFileW(wide_path.c_str(), GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (file_handle == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
DWORD bytes_written;
|
||||
DWORD bytes_to_write = (DWORD)str.size();
|
||||
BOOL result = WriteFile(file_handle, str.data(), bytes_to_write, &bytes_written, NULL);
|
||||
CloseHandle(file_handle);
|
||||
if (bytes_written != bytes_to_write)
|
||||
result = FALSE;
|
||||
return result;
|
||||
#else
|
||||
try
|
||||
{
|
||||
std::ofstream fstream;
|
||||
fstream.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
fstream.open(path_to_file, std::ios_base::binary | std::ios_base::out | std::ios_base::trunc);
|
||||
fstream << str;
|
||||
fstream.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
catch(...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool get_file_time(const std::string& path_to_file, time_t& ft)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
ft = boost::filesystem::last_write_time(boost::filesystem::path(path_to_file), ec);
|
||||
if(!ec)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool set_file_time(const std::string& path_to_file, const time_t& ft)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
boost::filesystem::last_write_time(boost::filesystem::path(path_to_file), ft, ec);
|
||||
if(!ec)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool load_file_to_string(const std::string& path_to_file, std::string& target_str, size_t max_size)
|
||||
{
|
||||
#ifdef WIN32
|
||||
std::wstring wide_path;
|
||||
try { wide_path = string_tools::utf8_to_utf16(path_to_file); } catch (...) { return false; }
|
||||
HANDLE file_handle = CreateFileW(wide_path.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (file_handle == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
DWORD file_size = GetFileSize(file_handle, NULL);
|
||||
if ((file_size == INVALID_FILE_SIZE) || (uint64_t)file_size > (uint64_t)max_size) {
|
||||
CloseHandle(file_handle);
|
||||
return false;
|
||||
}
|
||||
target_str.resize(file_size);
|
||||
DWORD bytes_read;
|
||||
BOOL result = ReadFile(file_handle, &target_str[0], file_size, &bytes_read, NULL);
|
||||
CloseHandle(file_handle);
|
||||
if (bytes_read != file_size)
|
||||
result = FALSE;
|
||||
return result;
|
||||
#else
|
||||
try
|
||||
{
|
||||
std::ifstream fstream;
|
||||
fstream.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
fstream.open(path_to_file, std::ios_base::binary | std::ios_base::in | std::ios::ate);
|
||||
|
||||
std::ifstream::pos_type file_size = fstream.tellg();
|
||||
|
||||
if((uint64_t)file_size > (uint64_t)max_size) // ensure a large domain for comparison, and negative -> too large
|
||||
return false;//don't go crazy
|
||||
size_t file_size_t = static_cast<size_t>(file_size);
|
||||
|
||||
target_str.resize(file_size_t);
|
||||
|
||||
fstream.seekg (0, std::ios::beg);
|
||||
fstream.read((char*)target_str.data(), target_str.size());
|
||||
fstream.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
catch(...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
bool append_string_to_file(const std::string& path_to_file, const std::string& str)
|
||||
{
|
||||
// No special Windows implementation because so far not used in Monero code
|
||||
try
|
||||
{
|
||||
std::ofstream fstream;
|
||||
fstream.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
fstream.open(path_to_file.c_str(), std::ios_base::binary | std::ios_base::out | std::ios_base::app);
|
||||
fstream << str;
|
||||
fstream.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
catch(...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool get_file_size(const std::string& path_to_file, uint64_t &size)
|
||||
{
|
||||
#ifdef WIN32
|
||||
std::wstring wide_path;
|
||||
try { wide_path = string_tools::utf8_to_utf16(path_to_file); } catch (...) { return false; }
|
||||
HANDLE file_handle = CreateFileW(wide_path.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
if (file_handle == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
LARGE_INTEGER file_size;
|
||||
BOOL result = GetFileSizeEx(file_handle, &file_size);
|
||||
CloseHandle(file_handle);
|
||||
if (result) {
|
||||
size = file_size.QuadPart;
|
||||
}
|
||||
return size;
|
||||
#else
|
||||
try
|
||||
{
|
||||
std::ifstream fstream;
|
||||
fstream.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
||||
fstream.open(path_to_file, std::ios_base::binary | std::ios_base::in | std::ios::ate);
|
||||
size = fstream.tellg();
|
||||
fstream.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
catch(...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
}
|
71
contrib/epee/src/http_base.cpp
Normal file
71
contrib/epee/src/http_base.cpp
Normal file
@ -0,0 +1,71 @@
|
||||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * 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.
|
||||
// * Neither the name of the Andrey N. Sabelnikov 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 OWNER 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 "net/http_base.h"
|
||||
#include "memwipe.h"
|
||||
#include "string_tools.h"
|
||||
|
||||
#include <boost/regex.hpp>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "net.http"
|
||||
|
||||
namespace epee
|
||||
{
|
||||
namespace net_utils
|
||||
{
|
||||
namespace http
|
||||
{
|
||||
std::string get_value_from_fields_list(const std::string& param_name, const net_utils::http::fields_list& fields)
|
||||
{
|
||||
fields_list::const_iterator it = fields.begin();
|
||||
for(; it != fields.end(); it++)
|
||||
if(!string_tools::compare_no_case(param_name, it->first))
|
||||
break;
|
||||
|
||||
if(it==fields.end())
|
||||
return std::string();
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
std::string get_value_from_uri_line(const std::string& param_name, const std::string& uri)
|
||||
{
|
||||
std::string buff = "([\\?|&])";
|
||||
buff += param_name + "=([^&]*)";
|
||||
boost::regex match_param(buff.c_str(), boost::regex::icase | boost::regex::normal);
|
||||
boost::smatch result;
|
||||
if(boost::regex_search(uri, result, match_param, boost::match_default) && result[0].matched)
|
||||
{
|
||||
return result[2];
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -34,6 +34,25 @@ namespace epee
|
||||
{
|
||||
namespace levin
|
||||
{
|
||||
message_writer::message_writer(const std::size_t reserve)
|
||||
: buffer()
|
||||
{
|
||||
buffer.reserve(reserve);
|
||||
buffer.put_n(0, sizeof(header));
|
||||
}
|
||||
|
||||
byte_slice message_writer::finalize(const uint32_t command, const uint32_t flags, const uint32_t return_code, const bool expect_response)
|
||||
{
|
||||
if (buffer.size() < sizeof(header))
|
||||
throw std::runtime_error{"levin_writer::finalize already called"};
|
||||
|
||||
header head = make_header(command, payload_size(), flags, expect_response);
|
||||
head.m_return_code = SWAP32LE(return_code);
|
||||
|
||||
std::memcpy(buffer.tellp() - buffer.size(), std::addressof(head), sizeof(head));
|
||||
return byte_slice{std::move(buffer)};
|
||||
}
|
||||
|
||||
bucket_head2 make_header(uint32_t command, uint64_t msg_size, uint32_t flags, bool expect_response) noexcept
|
||||
{
|
||||
bucket_head2 head = {0};
|
||||
@ -47,12 +66,6 @@ namespace levin
|
||||
return head;
|
||||
}
|
||||
|
||||
byte_slice make_notify(int command, epee::span<const std::uint8_t> payload)
|
||||
{
|
||||
const bucket_head2 head = make_header(command, payload.size(), LEVIN_PACKET_REQUEST, false);
|
||||
return byte_slice{epee::as_byte_span(head), payload};
|
||||
}
|
||||
|
||||
byte_slice make_noise_notify(const std::size_t noise_bytes)
|
||||
{
|
||||
static constexpr const std::uint32_t flags =
|
||||
@ -68,46 +81,40 @@ namespace levin
|
||||
return byte_slice{std::move(buffer)};
|
||||
}
|
||||
|
||||
byte_slice make_fragmented_notify(const byte_slice& noise_message, int command, epee::span<const std::uint8_t> payload)
|
||||
byte_slice make_fragmented_notify(const std::size_t noise_size, const int command, message_writer message)
|
||||
{
|
||||
const size_t noise_size = noise_message.size();
|
||||
if (noise_size < sizeof(bucket_head2) * 2)
|
||||
return nullptr;
|
||||
|
||||
if (payload.size() <= noise_size - sizeof(bucket_head2))
|
||||
if (message.buffer.size() <= noise_size)
|
||||
{
|
||||
/* The entire message can be sent at once, and the levin binary parser
|
||||
will ignore extra bytes. So just pad with zeroes and otherwise send
|
||||
a "normal", not fragmented message. */
|
||||
const size_t padding = noise_size - sizeof(bucket_head2) - payload.size();
|
||||
const span<const uint8_t> padding_bytes{noise_message.end() - padding, padding};
|
||||
|
||||
const bucket_head2 head = make_header(command, noise_size - sizeof(bucket_head2), LEVIN_PACKET_REQUEST, false);
|
||||
return byte_slice{as_byte_span(head), payload, padding_bytes};
|
||||
message.buffer.put_n(0, noise_size - message.buffer.size());
|
||||
return message.finalize_notify(command);
|
||||
}
|
||||
|
||||
// fragment message
|
||||
const byte_slice payload_bytes = message.finalize_notify(command);
|
||||
span<const std::uint8_t> payload = to_span(payload_bytes);
|
||||
|
||||
const size_t payload_space = noise_size - sizeof(bucket_head2);
|
||||
const size_t expected_fragments = ((payload.size() - 2) / payload_space) + 1;
|
||||
|
||||
std::string buffer{};
|
||||
buffer.reserve((expected_fragments + 1) * noise_size); // +1 here overselects for internal bucket_head2 value
|
||||
byte_stream buffer{};
|
||||
buffer.reserve(expected_fragments * noise_size);
|
||||
|
||||
bucket_head2 head = make_header(0, noise_size - sizeof(bucket_head2), LEVIN_PACKET_BEGIN, false);
|
||||
buffer.append(reinterpret_cast<const char*>(&head), sizeof(head));
|
||||
bucket_head2 head = make_header(0, payload_space, LEVIN_PACKET_BEGIN, false);
|
||||
buffer.write(as_byte_span(head));
|
||||
|
||||
head.m_command = command;
|
||||
head.m_flags = LEVIN_PACKET_REQUEST;
|
||||
head.m_cb = payload.size();
|
||||
buffer.append(reinterpret_cast<const char*>(&head), sizeof(head));
|
||||
// internal levin header is in payload already
|
||||
|
||||
size_t copy_size = payload.remove_prefix(payload_space - sizeof(bucket_head2));
|
||||
buffer.append(reinterpret_cast<const char*>(payload.data()) - copy_size, copy_size);
|
||||
size_t copy_size = payload.remove_prefix(payload_space);
|
||||
buffer.write(payload.data() - copy_size, copy_size);
|
||||
|
||||
head.m_command = 0;
|
||||
head.m_flags = 0;
|
||||
head.m_cb = noise_size - sizeof(bucket_head2);
|
||||
|
||||
while (!payload.empty())
|
||||
{
|
||||
copy_size = payload.remove_prefix(payload_space);
|
||||
@ -115,12 +122,12 @@ namespace levin
|
||||
if (payload.empty())
|
||||
head.m_flags = LEVIN_PACKET_END;
|
||||
|
||||
buffer.append(reinterpret_cast<const char*>(&head), sizeof(head));
|
||||
buffer.append(reinterpret_cast<const char*>(payload.data()) - copy_size, copy_size);
|
||||
buffer.write(as_byte_span(head));
|
||||
buffer.write(payload.data() - copy_size, copy_size);
|
||||
}
|
||||
|
||||
const size_t padding = noise_size - copy_size - sizeof(bucket_head2);
|
||||
buffer.append(reinterpret_cast<const char*>(noise_message.end()) - padding, padding);
|
||||
buffer.put_n(0, padding);
|
||||
|
||||
return byte_slice{std::move(buffer)};
|
||||
}
|
||||
|
44
contrib/epee/src/misc_language.cpp
Normal file
44
contrib/epee/src/misc_language.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * 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.
|
||||
// * Neither the name of the Andrey N. Sabelnikov 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 OWNER 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 "misc_language.h"
|
||||
|
||||
#include <boost/thread.hpp>
|
||||
|
||||
namespace epee
|
||||
{
|
||||
namespace misc_utils
|
||||
{
|
||||
bool sleep_no_w(long ms )
|
||||
{
|
||||
boost::this_thread::sleep(
|
||||
boost::get_system_time() +
|
||||
boost::posix_time::milliseconds( std::max<long>(ms,0) ) );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
44
contrib/epee/src/misc_os_dependent.cpp
Normal file
44
contrib/epee/src/misc_os_dependent.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * 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.
|
||||
// * Neither the name of the Andrey N. Sabelnikov 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 OWNER 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 "misc_os_dependent.h"
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
namespace epee
|
||||
{
|
||||
namespace misc_utils
|
||||
{
|
||||
// TODO: (vtnerd) This function is weird since boost::this_thread::get_id() exists but returns a different value.
|
||||
std::string get_thread_string_id()
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
return boost::lexical_cast<std::string>(GetCurrentThreadId());
|
||||
#elif defined(__GNUC__)
|
||||
return boost::lexical_cast<std::string>(pthread_self());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
206
contrib/epee/src/net_parse_helpers.cpp
Normal file
206
contrib/epee/src/net_parse_helpers.cpp
Normal file
@ -0,0 +1,206 @@
|
||||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * 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.
|
||||
// * Neither the name of the Andrey N. Sabelnikov 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 OWNER 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 "net/net_parse_helpers.h"
|
||||
#include "net/http_base.h"
|
||||
#include "misc_log_ex.h"
|
||||
#include "reg_exp_definer.h"
|
||||
#include <boost/lexical_cast.hpp>
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "net"
|
||||
|
||||
namespace epee
|
||||
{
|
||||
namespace net_utils
|
||||
{
|
||||
|
||||
static bool parse_uri_query(const std::string& query, std::list<std::pair<std::string, std::string> >& params)
|
||||
{
|
||||
enum state
|
||||
{
|
||||
st_param_name,
|
||||
st_param_val
|
||||
};
|
||||
state st = st_param_name;
|
||||
std::string::const_iterator start_it = query.begin();
|
||||
std::pair<std::string, std::string> e;
|
||||
for(std::string::const_iterator it = query.begin(); it != query.end(); it++)
|
||||
{
|
||||
switch(st)
|
||||
{
|
||||
case st_param_name:
|
||||
if(*it == '=')
|
||||
{
|
||||
e.first.assign(start_it, it);
|
||||
start_it = it;++start_it;
|
||||
st = st_param_val;
|
||||
}
|
||||
break;
|
||||
case st_param_val:
|
||||
if(*it == '&')
|
||||
{
|
||||
e.second.assign(start_it, it);
|
||||
start_it = it;++start_it;
|
||||
params.push_back(e);
|
||||
e.first.clear();e.second.clear();
|
||||
st = st_param_name;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
LOG_ERROR("Unknown state " << (int)st);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(st == st_param_name)
|
||||
{
|
||||
if(start_it != query.end())
|
||||
{
|
||||
e.first.assign(start_it, query.end());
|
||||
params.push_back(e);
|
||||
}
|
||||
}else
|
||||
{
|
||||
if(start_it != query.end())
|
||||
e.second.assign(start_it, query.end());
|
||||
|
||||
if(e.first.size())
|
||||
params.push_back(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_uri(const std::string uri, http::uri_content& content)
|
||||
{
|
||||
|
||||
///iframe_test.html?api_url=http://api.vk.com/api.php&api_id=3289090&api_settings=1&viewer_id=562964060&viewer_type=0&sid=0aad8d1c5713130f9ca0076f2b7b47e532877424961367d81e7fa92455f069be7e21bc3193cbd0be11895&secret=368ebbc0ef&access_token=668bc03f43981d883f73876ffff4aa8564254b359cc745dfa1b3cde7bdab2e94105d8f6d8250717569c0a7&user_id=0&group_id=0&is_app_user=1&auth_key=d2f7a895ca5ff3fdb2a2a8ae23fe679a&language=0&parent_language=0&ad_info=ElsdCQBaQlxiAQRdFUVUXiN2AVBzBx5pU1BXIgZUJlIEAWcgAUoLQg==&referrer=unknown&lc_name=9834b6a3&hash=
|
||||
content.m_query_params.clear();
|
||||
STATIC_REGEXP_EXPR_1(rexp_match_uri, "^([^?#]*)(\\?([^#]*))?(#(.*))?", boost::regex::icase | boost::regex::normal);
|
||||
|
||||
boost::smatch result;
|
||||
if(!(boost::regex_search(uri, result, rexp_match_uri, boost::match_default) && result[0].matched))
|
||||
{
|
||||
LOG_PRINT_L1("[PARSE URI] regex not matched for uri: " << uri);
|
||||
content.m_path = uri;
|
||||
return true;
|
||||
}
|
||||
if(result[1].matched)
|
||||
{
|
||||
content.m_path = result[1];
|
||||
}
|
||||
if(result[3].matched)
|
||||
{
|
||||
content.m_query = result[3];
|
||||
}
|
||||
if(result[5].matched)
|
||||
{
|
||||
content.m_fragment = result[5];
|
||||
}
|
||||
if(content.m_query.size())
|
||||
{
|
||||
parse_uri_query(content.m_query, content.m_query_params);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_url_ipv6(const std::string url_str, http::url_content& content)
|
||||
{
|
||||
STATIC_REGEXP_EXPR_1(rexp_match_uri, "^(([^:]*?)://)?(\\[(.*)\\](:(\\d+))?)(.*)?", boost::regex::icase | boost::regex::normal);
|
||||
// 12 3 4 5 6 7
|
||||
|
||||
content.port = 0;
|
||||
boost::smatch result;
|
||||
if(!(boost::regex_search(url_str, result, rexp_match_uri, boost::match_default) && result[0].matched))
|
||||
{
|
||||
LOG_PRINT_L1("[PARSE URI] regex not matched for uri: " << rexp_match_uri);
|
||||
//content.m_path = uri;
|
||||
return false;
|
||||
}
|
||||
if(result[2].matched)
|
||||
{
|
||||
content.schema = result[2];
|
||||
}
|
||||
if(result[4].matched)
|
||||
{
|
||||
content.host = result[4];
|
||||
}
|
||||
else // if host not matched, matching should be considered failed
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if(result[6].matched)
|
||||
{
|
||||
content.port = boost::lexical_cast<uint64_t>(result[6]);
|
||||
}
|
||||
if(result[7].matched)
|
||||
{
|
||||
content.uri = result[7];
|
||||
return parse_uri(result[7], content.m_uri_content);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool parse_url(const std::string url_str, http::url_content& content)
|
||||
{
|
||||
|
||||
if (parse_url_ipv6(url_str, content)) return true;
|
||||
|
||||
///iframe_test.html?api_url=http://api.vk.com/api.php&api_id=3289090&api_settings=1&viewer_id=562964060&viewer_type=0&sid=0aad8d1c5713130f9ca0076f2b7b47e532877424961367d81e7fa92455f069be7e21bc3193cbd0be11895&secret=368ebbc0ef&access_token=668bc03f43981d883f73876ffff4aa8564254b359cc745dfa1b3cde7bdab2e94105d8f6d8250717569c0a7&user_id=0&group_id=0&is_app_user=1&auth_key=d2f7a895ca5ff3fdb2a2a8ae23fe679a&language=0&parent_language=0&ad_info=ElsdCQBaQlxiAQRdFUVUXiN2AVBzBx5pU1BXIgZUJlIEAWcgAUoLQg==&referrer=unknown&lc_name=9834b6a3&hash=
|
||||
//STATIC_REGEXP_EXPR_1(rexp_match_uri, "^([^?#]*)(\\?([^#]*))?(#(.*))?", boost::regex::icase | boost::regex::normal);
|
||||
STATIC_REGEXP_EXPR_1(rexp_match_uri, "^(([^:]*?)://)?(([^/:]*)(:(\\d+))?)(.*)?", boost::regex::icase | boost::regex::normal);
|
||||
// 12 34 5 6 7
|
||||
content.port = 0;
|
||||
boost::smatch result;
|
||||
if(!(boost::regex_search(url_str, result, rexp_match_uri, boost::match_default) && result[0].matched))
|
||||
{
|
||||
LOG_PRINT_L1("[PARSE URI] regex not matched for uri: " << rexp_match_uri);
|
||||
//content.m_path = uri;
|
||||
return true;
|
||||
}
|
||||
if(result[2].matched)
|
||||
{
|
||||
content.schema = result[2];
|
||||
}
|
||||
if(result[4].matched)
|
||||
{
|
||||
content.host = result[4];
|
||||
}
|
||||
if(result[6].matched)
|
||||
{
|
||||
content.port = boost::lexical_cast<uint64_t>(result[6]);
|
||||
}
|
||||
if(result[7].matched)
|
||||
{
|
||||
content.uri = result[7];
|
||||
return parse_uri(result[7], content.m_uri_content);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -29,6 +29,8 @@
|
||||
#include <string.h>
|
||||
#include <thread>
|
||||
#include <boost/asio/ssl.hpp>
|
||||
#include <boost/cerrno.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/lambda/lambda.hpp>
|
||||
#include <openssl/ssl.h>
|
||||
#include <openssl/pem.h>
|
||||
@ -567,6 +569,51 @@ bool ssl_support_from_string(ssl_support_t &ssl, boost::string_ref s)
|
||||
return true;
|
||||
}
|
||||
|
||||
boost::system::error_code store_ssl_keys(boost::asio::ssl::context& ssl, const boost::filesystem::path& base)
|
||||
{
|
||||
EVP_PKEY* ssl_key = nullptr;
|
||||
X509* ssl_cert = nullptr;
|
||||
const auto ctx = ssl.native_handle();
|
||||
CHECK_AND_ASSERT_MES(ctx, boost::system::error_code(EINVAL, boost::system::system_category()), "Context is null");
|
||||
CHECK_AND_ASSERT_MES(base.has_filename(), boost::system::error_code(EINVAL, boost::system::system_category()), "Need filename");
|
||||
if (!(ssl_key = SSL_CTX_get0_privatekey(ctx)) || !(ssl_cert = SSL_CTX_get0_certificate(ctx)))
|
||||
return {EINVAL, boost::system::system_category()};
|
||||
|
||||
using file_closer = int(std::FILE*);
|
||||
boost::system::error_code error{};
|
||||
std::unique_ptr<std::FILE, file_closer*> file{nullptr, std::fclose};
|
||||
|
||||
// write key file unencrypted
|
||||
{
|
||||
const boost::filesystem::path key_file{base.string() + ".key"};
|
||||
file.reset(std::fopen(key_file.string().c_str(), "wb"));
|
||||
if (!file)
|
||||
return {errno, boost::system::system_category()};
|
||||
boost::filesystem::permissions(key_file, boost::filesystem::owner_read, error);
|
||||
if (error)
|
||||
return error;
|
||||
if (!PEM_write_PrivateKey(file.get(), ssl_key, nullptr, nullptr, 0, nullptr, nullptr))
|
||||
return boost::asio::error::ssl_errors(ERR_get_error());
|
||||
if (std::fclose(file.release()) != 0)
|
||||
return {errno, boost::system::system_category()};
|
||||
}
|
||||
|
||||
// write certificate file in standard SSL X.509 unencrypted
|
||||
const boost::filesystem::path cert_file{base.string() + ".crt"};
|
||||
file.reset(std::fopen(cert_file.string().c_str(), "wb"));
|
||||
if (!file)
|
||||
return {errno, boost::system::system_category()};
|
||||
const auto cert_perms = (boost::filesystem::owner_read | boost::filesystem::group_read | boost::filesystem::others_read);
|
||||
boost::filesystem::permissions(cert_file, cert_perms, error);
|
||||
if (error)
|
||||
return error;
|
||||
if (!PEM_write_X509(file.get(), ssl_cert))
|
||||
return boost::asio::error::ssl_errors(ERR_get_error());
|
||||
if (std::fclose(file.release()) != 0)
|
||||
return {errno, boost::system::system_category()};
|
||||
return error;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
|
@ -1,10 +1,43 @@
|
||||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * 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.
|
||||
// * Neither the name of the Andrey N. Sabelnikov 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 OWNER 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 "byte_slice.h"
|
||||
#include "byte_stream.h"
|
||||
#include "misc_log_ex.h"
|
||||
#include "span.h"
|
||||
#include "storages/portable_storage.h"
|
||||
#include "storages/portable_storage_to_json.h"
|
||||
#include "storages/portable_storage_from_json.h"
|
||||
#include "storages/portable_storage_to_bin.h"
|
||||
#include "storages/portable_storage_from_bin.h"
|
||||
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
|
||||
namespace epee
|
||||
{
|
||||
@ -15,15 +48,200 @@ namespace serialization
|
||||
TRY_ENTRY();
|
||||
byte_stream ss;
|
||||
ss.reserve(initial_buffer_size);
|
||||
store_to_binary(ss);
|
||||
target = epee::byte_slice{std::move(ss)};
|
||||
return true;
|
||||
CATCH_ENTRY("portable_storage::store_to_binary", false);
|
||||
}
|
||||
|
||||
bool portable_storage::store_to_binary(byte_stream& ss)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
storage_block_header sbh{};
|
||||
sbh.m_signature_a = SWAP32LE(PORTABLE_STORAGE_SIGNATUREA);
|
||||
sbh.m_signature_b = SWAP32LE(PORTABLE_STORAGE_SIGNATUREB);
|
||||
sbh.m_ver = PORTABLE_STORAGE_FORMAT_VER;
|
||||
ss.write(epee::as_byte_span(sbh));
|
||||
pack_entry_to_buff(ss, m_root);
|
||||
target = epee::byte_slice{std::move(ss)};
|
||||
return true;
|
||||
CATCH_ENTRY("portable_storage::store_to_binary", false)
|
||||
CATCH_ENTRY("portable_storage::store_to_binary", false);
|
||||
}
|
||||
|
||||
bool portable_storage::dump_as_json(std::string& buff, size_t indent, bool insert_newlines)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
std::stringstream ss;
|
||||
epee::serialization::dump_as_json(ss, m_root, indent, insert_newlines);
|
||||
buff = ss.str();
|
||||
return true;
|
||||
CATCH_ENTRY("portable_storage::dump_as_json", false)
|
||||
}
|
||||
|
||||
bool portable_storage::load_from_json(const std::string& source)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
return json::load_from_json(source, *this);
|
||||
CATCH_ENTRY("portable_storage::load_from_json", false)
|
||||
}
|
||||
|
||||
bool portable_storage::load_from_binary(const epee::span<const uint8_t> source, const limits_t *limits)
|
||||
{
|
||||
m_root.m_entries.clear();
|
||||
if(source.size() < sizeof(storage_block_header))
|
||||
{
|
||||
LOG_ERROR("portable_storage: wrong binary format, packet size = " << source.size() << " less than expected sizeof(storage_block_header)=" << sizeof(storage_block_header));
|
||||
return false;
|
||||
}
|
||||
storage_block_header* pbuff = (storage_block_header*)source.data();
|
||||
if(pbuff->m_signature_a != SWAP32LE(PORTABLE_STORAGE_SIGNATUREA) ||
|
||||
pbuff->m_signature_b != SWAP32LE(PORTABLE_STORAGE_SIGNATUREB)
|
||||
)
|
||||
{
|
||||
LOG_ERROR("portable_storage: wrong binary format - signature mismatch");
|
||||
return false;
|
||||
}
|
||||
if(pbuff->m_ver != PORTABLE_STORAGE_FORMAT_VER)
|
||||
{
|
||||
LOG_ERROR("portable_storage: wrong binary format - unknown format ver = " << pbuff->m_ver);
|
||||
return false;
|
||||
}
|
||||
TRY_ENTRY();
|
||||
throwable_buffer_reader buf_reader(source.data()+sizeof(storage_block_header), source.size()-sizeof(storage_block_header));
|
||||
if (limits)
|
||||
buf_reader.set_limits(limits->n_objects, limits->n_fields, limits->n_strings);
|
||||
buf_reader.read(m_root);
|
||||
return true;//TODO:
|
||||
CATCH_ENTRY("portable_storage::load_from_binary", false);
|
||||
}
|
||||
|
||||
hsection portable_storage::open_section(const std::string& section_name, hsection hparent_section, bool create_if_notexist)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
hparent_section = hparent_section ? hparent_section:&m_root;
|
||||
storage_entry* pentry = find_storage_entry(section_name, hparent_section);
|
||||
if(!pentry)
|
||||
{
|
||||
if(!create_if_notexist)
|
||||
return nullptr;
|
||||
return insert_new_section(section_name, hparent_section);
|
||||
}
|
||||
CHECK_AND_ASSERT(pentry , nullptr);
|
||||
//check that section_entry we find is real "CSSection"
|
||||
if(pentry->type() != typeid(section))
|
||||
{
|
||||
if(create_if_notexist)
|
||||
*pentry = storage_entry(section());//replace
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
return &boost::get<section>(*pentry);
|
||||
CATCH_ENTRY("portable_storage::open_section", nullptr);
|
||||
}
|
||||
|
||||
bool portable_storage::get_value(const std::string& value_name, storage_entry& val, hsection hparent_section)
|
||||
{
|
||||
//TRY_ENTRY();
|
||||
if(!hparent_section) hparent_section = &m_root;
|
||||
storage_entry* pentry = find_storage_entry(value_name, hparent_section);
|
||||
if(!pentry)
|
||||
return false;
|
||||
|
||||
val = *pentry;
|
||||
return true;
|
||||
//CATCH_ENTRY("portable_storage::template<>get_value", false);
|
||||
}
|
||||
|
||||
storage_entry* portable_storage::find_storage_entry(const std::string& pentry_name, hsection psection)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
CHECK_AND_ASSERT(psection, nullptr);
|
||||
auto it = psection->m_entries.find(pentry_name);
|
||||
if(it == psection->m_entries.end())
|
||||
return nullptr;
|
||||
|
||||
return &it->second;
|
||||
CATCH_ENTRY("portable_storage::find_storage_entry", nullptr);
|
||||
}
|
||||
|
||||
hsection portable_storage::insert_new_section(const std::string& pentry_name, hsection psection)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
storage_entry* pse = insert_new_entry_get_storage_entry(pentry_name, psection, section());
|
||||
if(!pse) return nullptr;
|
||||
return &boost::get<section>(*pse);
|
||||
CATCH_ENTRY("portable_storage::insert_new_section", nullptr);
|
||||
}
|
||||
|
||||
harray portable_storage::get_first_section(const std::string& sec_name, hsection& h_child_section, hsection hparent_section)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
if(!hparent_section) hparent_section = &m_root;
|
||||
storage_entry* pentry = find_storage_entry(sec_name, hparent_section);
|
||||
if(!pentry)
|
||||
return nullptr;
|
||||
if(pentry->type() != typeid(array_entry))
|
||||
return nullptr;
|
||||
array_entry& ar_entry = boost::get<array_entry>(*pentry);
|
||||
if(ar_entry.type() != typeid(array_entry_t<section>))
|
||||
return nullptr;
|
||||
array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(ar_entry);
|
||||
section* psec = sec_array.get_first_val();
|
||||
if(!psec)
|
||||
return nullptr;
|
||||
h_child_section = psec;
|
||||
return &ar_entry;
|
||||
CATCH_ENTRY("portable_storage::get_first_section", nullptr);
|
||||
}
|
||||
|
||||
bool portable_storage::get_next_section(harray hsec_array, hsection& h_child_section)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
CHECK_AND_ASSERT(hsec_array, false);
|
||||
if(hsec_array->type() != typeid(array_entry_t<section>))
|
||||
return false;
|
||||
array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(*hsec_array);
|
||||
h_child_section = sec_array.get_next_val();
|
||||
if(!h_child_section)
|
||||
return false;
|
||||
return true;
|
||||
CATCH_ENTRY("portable_storage::get_next_section", false);
|
||||
}
|
||||
|
||||
harray portable_storage::insert_first_section(const std::string& sec_name, hsection& hinserted_childsection, hsection hparent_section)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
if(!hparent_section) hparent_section = &m_root;
|
||||
storage_entry* pentry = find_storage_entry(sec_name, hparent_section);
|
||||
if(!pentry)
|
||||
{
|
||||
pentry = insert_new_entry_get_storage_entry(sec_name, hparent_section, array_entry(array_entry_t<section>()));
|
||||
if(!pentry)
|
||||
return nullptr;
|
||||
}
|
||||
if(pentry->type() != typeid(array_entry))
|
||||
*pentry = storage_entry(array_entry(array_entry_t<section>()));
|
||||
|
||||
array_entry& ar_entry = boost::get<array_entry>(*pentry);
|
||||
if(ar_entry.type() != typeid(array_entry_t<section>))
|
||||
ar_entry = array_entry(array_entry_t<section>());
|
||||
|
||||
array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(ar_entry);
|
||||
hinserted_childsection = &sec_array.insert_first_val(section());
|
||||
return &ar_entry;
|
||||
CATCH_ENTRY("portable_storage::insert_first_section", nullptr);
|
||||
}
|
||||
|
||||
bool portable_storage::insert_next_section(harray hsec_array, hsection& hinserted_childsection)
|
||||
{
|
||||
TRY_ENTRY();
|
||||
CHECK_AND_ASSERT(hsec_array, false);
|
||||
CHECK_AND_ASSERT_MES(hsec_array->type() == typeid(array_entry_t<section>),
|
||||
false, "unexpected type(not 'section') in insert_next_section, type: " << hsec_array->type().name());
|
||||
|
||||
array_entry_t<section>& sec_array = boost::get<array_entry_t<section>>(*hsec_array);
|
||||
hinserted_childsection = &sec_array.insert_next_value(section());
|
||||
return true;
|
||||
CATCH_ENTRY("portable_storage::insert_next_section", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,29 @@
|
||||
//
|
||||
|
||||
#include "string_tools.h"
|
||||
#include "string_tools_lexical.h"
|
||||
|
||||
|
||||
// Previously pulled in by ASIO, further cleanup still required ...
|
||||
#ifdef _WIN32
|
||||
# include <winsock2.h>
|
||||
# include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <locale>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include "misc_log_ex.h"
|
||||
#include "storages/parserse_base_utils.h"
|
||||
#include "hex.h"
|
||||
#include "memwipe.h"
|
||||
#include "mlocker.h"
|
||||
#include "span.h"
|
||||
#include "warnings.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
@ -68,6 +91,180 @@ namespace string_tools
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
bool parse_peer_from_string(uint32_t& ip, uint16_t& port, const std::string& addres)
|
||||
{
|
||||
//parse ip and address
|
||||
std::string::size_type p = addres.find(':');
|
||||
std::string ip_str, port_str;
|
||||
if(p == std::string::npos)
|
||||
{
|
||||
port = 0;
|
||||
ip_str = addres;
|
||||
}
|
||||
else
|
||||
{
|
||||
ip_str = addres.substr(0, p);
|
||||
port_str = addres.substr(p+1, addres.size());
|
||||
}
|
||||
|
||||
if(!get_ip_int32_from_string(ip, ip_str))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(p != std::string::npos && !get_xtype_from_string(port, port_str))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string num_to_string_fast(int64_t val)
|
||||
{
|
||||
/*
|
||||
char buff[30] = {0};
|
||||
i64toa_s(val, buff, sizeof(buff)-1, 10);
|
||||
return buff;*/
|
||||
return boost::lexical_cast<std::string>(val);
|
||||
}
|
||||
|
||||
|
||||
bool compare_no_case(const std::string& str1, const std::string& str2)
|
||||
{
|
||||
|
||||
return !boost::iequals(str1, str2);
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
std::string& get_current_module_name()
|
||||
{
|
||||
static std::string module_name;
|
||||
return module_name;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
std::string& get_current_module_folder()
|
||||
{
|
||||
static std::string module_folder;
|
||||
return module_folder;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
std::string get_current_module_path()
|
||||
{
|
||||
char pname [5000] = {0};
|
||||
GetModuleFileNameA( NULL, pname, sizeof(pname));
|
||||
pname[sizeof(pname)-1] = 0; //be happy ;)
|
||||
return pname;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool set_module_name_and_folder(const std::string& path_to_process_)
|
||||
{
|
||||
std::string path_to_process = path_to_process_;
|
||||
#ifdef _WIN32
|
||||
path_to_process = get_current_module_path();
|
||||
#endif
|
||||
std::string::size_type a = path_to_process.rfind( '\\' );
|
||||
if(a == std::string::npos )
|
||||
{
|
||||
a = path_to_process.rfind( '/' );
|
||||
}
|
||||
if ( a != std::string::npos )
|
||||
{
|
||||
get_current_module_name() = path_to_process.substr(a+1, path_to_process.size());
|
||||
get_current_module_folder() = path_to_process.substr(0, a);
|
||||
return true;
|
||||
}else
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool trim_left(std::string& str)
|
||||
{
|
||||
for(std::string::iterator it = str.begin(); it!= str.end() && isspace(static_cast<unsigned char>(*it));)
|
||||
str.erase(str.begin());
|
||||
|
||||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
bool trim_right(std::string& str)
|
||||
{
|
||||
|
||||
for(std::string::reverse_iterator it = str.rbegin(); it!= str.rend() && isspace(static_cast<unsigned char>(*it));)
|
||||
str.erase( --((it++).base()));
|
||||
|
||||
return true;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
std::string pad_string(std::string s, size_t n, char c, bool prepend)
|
||||
{
|
||||
if (s.size() < n)
|
||||
{
|
||||
if (prepend)
|
||||
s = std::string(n - s.size(), c) + s;
|
||||
else
|
||||
s.append(n - s.size(), c);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
std::string get_extension(const std::string& str)
|
||||
{
|
||||
std::string res;
|
||||
std::string::size_type pos = str.rfind('.');
|
||||
if(std::string::npos == pos)
|
||||
return res;
|
||||
|
||||
res = str.substr(pos+1, str.size()-pos);
|
||||
return res;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
std::string cut_off_extension(const std::string& str)
|
||||
{
|
||||
std::string res;
|
||||
std::string::size_type pos = str.rfind('.');
|
||||
if(std::string::npos == pos)
|
||||
return str;
|
||||
|
||||
res = str.substr(0, pos);
|
||||
return res;
|
||||
}
|
||||
//----------------------------------------------------------------------------
|
||||
#ifdef _WIN32
|
||||
std::wstring utf8_to_utf16(const std::string& str)
|
||||
{
|
||||
if (str.empty())
|
||||
return {};
|
||||
int wstr_size = MultiByteToWideChar(CP_UTF8, 0, &str[0], str.size(), NULL, 0);
|
||||
if (wstr_size == 0)
|
||||
{
|
||||
throw std::runtime_error(std::error_code(GetLastError(), std::system_category()).message());
|
||||
}
|
||||
std::wstring wstr(wstr_size, wchar_t{});
|
||||
if (!MultiByteToWideChar(CP_UTF8, 0, &str[0], str.size(), &wstr[0], wstr_size))
|
||||
{
|
||||
throw std::runtime_error(std::error_code(GetLastError(), std::system_category()).message());
|
||||
}
|
||||
return wstr;
|
||||
}
|
||||
std::string utf16_to_utf8(const std::wstring& wstr)
|
||||
{
|
||||
if (wstr.empty())
|
||||
return {};
|
||||
int str_size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], wstr.size(), NULL, 0, NULL, NULL);
|
||||
if (str_size == 0)
|
||||
{
|
||||
throw std::runtime_error(std::error_code(GetLastError(), std::system_category()).message());
|
||||
}
|
||||
std::string str(str_size, char{});
|
||||
if (!WideCharToMultiByte(CP_UTF8, 0, &wstr[0], wstr.size(), &str[0], str_size, NULL, NULL))
|
||||
{
|
||||
throw std::runtime_error(std::error_code(GetLastError(), std::system_category()).message());
|
||||
}
|
||||
return str;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
46
contrib/epee/src/tiny_ini.cpp
Normal file
46
contrib/epee/src/tiny_ini.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * 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.
|
||||
// * Neither the name of the Andrey N. Sabelnikov 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 OWNER 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 "string_tools.h"
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
namespace epee
|
||||
{
|
||||
namespace tiny_ini
|
||||
{
|
||||
bool get_param_value(const std::string& param_name, const std::string& ini_entry, std::string& res)
|
||||
{
|
||||
std::string expr_str = std::string() + "^("+ param_name +") *=(.*?)$";
|
||||
const boost::regex match_ini_entry( expr_str, boost::regex::icase | boost::regex::normal);
|
||||
boost::smatch result;
|
||||
if(!boost::regex_search(ini_entry, result, match_ini_entry, boost::match_default))
|
||||
return false;
|
||||
res = result[2];
|
||||
string_tools::trim(res);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -36,6 +36,10 @@ This guide explains how to set up the environment, and how to start the builds.
|
||||
|
||||
You need to create a new user called `gitianuser` and be logged in as that user. The user needs `sudo` access.
|
||||
|
||||
```bash
|
||||
sudo adduser gitianuser
|
||||
sudo usermod -aG sudo gitianuser
|
||||
```
|
||||
|
||||
LXC
|
||||
---
|
||||
@ -83,7 +87,7 @@ Docker
|
||||
Prepare for building with docker:
|
||||
|
||||
```bash
|
||||
sudo apt-get install git make curl docker.io
|
||||
sudo bash -c 'apt-get update && apt-get upgrade -y && apt-get install git curl docker.io'
|
||||
```
|
||||
|
||||
Consider adding `gitianuser` to the `docker` group after reading about [the security implications](https://docs.docker.com/v17.09/engine/installation/linux/linux-postinstall/):
|
||||
@ -96,13 +100,12 @@ sudo usermod -aG docker gitianuser
|
||||
Optionally add yourself to the docker group. Note that this will give docker root access to your system.
|
||||
|
||||
```bash
|
||||
sudo usermod -aG docker gitianuser
|
||||
sudo usermod -aG docker $USER
|
||||
```
|
||||
|
||||
Manual Building
|
||||
-------------------
|
||||
|
||||
The instructions below use the automated script [gitian-build.py](gitian-build.py) which only works in Ubuntu.
|
||||
=======
|
||||
The script automatically installs some packages with apt. If you are not running it on a debian-like system, pass `--no-apt` along with the other
|
||||
arguments to it. It calls all available .yml descriptors, which in turn pass the build configurations for different platforms to gitian.
|
||||
@ -122,17 +125,23 @@ cp monero/contrib/gitian/gitian-build.py .
|
||||
|
||||
### Setup the required environment
|
||||
|
||||
Setup for LXC:
|
||||
Common setup part:
|
||||
|
||||
```bash
|
||||
GH_USER=fluffypony
|
||||
VERSION=v0.17.0.0
|
||||
su - gitianuser
|
||||
|
||||
./gitian-build.py --setup $GH_USER $VERSION
|
||||
GH_USER=YOUR_GITHUB_USER_NAME
|
||||
VERSION=v0.17.2.0
|
||||
```
|
||||
|
||||
Where `GH_USER` is your Github user name and `VERSION` is the version tag you want to build.
|
||||
|
||||
Setup for LXC:
|
||||
|
||||
```bash
|
||||
./gitian-build.py --setup $GH_USER $VERSION
|
||||
```
|
||||
|
||||
Setup for docker:
|
||||
|
||||
```bash
|
||||
@ -145,8 +154,10 @@ fork the [gitian.sigs repository](https://github.com/monero-project/gitian.sigs)
|
||||
or pass the signed assert file back to your build machine.
|
||||
|
||||
```bash
|
||||
git clone git@github.com:monero-project/gitian.sigs.git
|
||||
git remote add $GH_USER git@github.com:$GH_USER/gitian.sigs.git
|
||||
git clone https://github.com/monero-project/gitian.sigs/
|
||||
pushd gitian.sigs
|
||||
git remote add $GH_USER https://github.com/$GH_USER/gitian.sigs
|
||||
popd
|
||||
```
|
||||
|
||||
Build the binaries
|
||||
@ -154,13 +165,26 @@ Build the binaries
|
||||
|
||||
**Note:** if you intend to build MacOS binaries, please follow [these instructions](https://github.com/bitcoin-core/docs/blob/master/gitian-building/gitian-building-mac-os-sdk.md) to get the required SDK.
|
||||
|
||||
Currently working MacOS solution:
|
||||
|
||||
```bash
|
||||
curl -O https://bitcoincore.org/depends-sources/sdks/MacOSX10.11.sdk.tar.gz
|
||||
mv MacOSX10.11.sdk.tar.gz builder/inputs
|
||||
```
|
||||
|
||||
To build the most recent tag (pass in `--docker` if using docker):
|
||||
|
||||
```bash
|
||||
./gitian-build.py --detach-sign --no-commit --build $GH_USER $VERSION
|
||||
```
|
||||
|
||||
To speed up the build, use `-j 5 --memory 5000` as the first arguments, where `5` is the number of CPU's you allocated to the VM plus one, and 5000 is a little bit less than then the MB's of RAM you allocated. If there is memory corruption on your machine, try to tweak these values.
|
||||
To speed up the build, use `-j 5 --memory 10000` as the first arguments, where `5` is the number of CPU's you allocated to the VM plus one, and 10000 is a little bit less than then the MB's of RAM you allocated. If there is memory corruption on your machine, try to tweak these values. A good rule of thumb is, that Monero currently needs about 2 GB of RAM per core.
|
||||
|
||||
A full example for `docker` would look like the following:
|
||||
|
||||
```bash
|
||||
./gitian-build.py -j 5 --memory 10000 --docker --detach-sign --no-commit --build $GH_USER $VERSION
|
||||
```
|
||||
|
||||
If all went well, this produces a number of (uncommitted) `.assert` files in the gitian.sigs directory.
|
||||
|
||||
@ -171,6 +195,22 @@ Take a look in the assert files and note the SHA256 checksums listed there.
|
||||
|
||||
You should verify that the checksum that is listed matches each of the binaries you actually built.
|
||||
This may be done on Linux using the `sha256sum` command or on MacOS using `shasum --algorithm 256` for example.
|
||||
An example script to verify the checksums would be:
|
||||
|
||||
```bash
|
||||
pushd out/${VERSION}
|
||||
|
||||
for ASSERT in ../../sigs/${VERSION}-*/*/*.assert; do
|
||||
if ! sha256sum --ignore-missing -c "${ASSERT}" ; then
|
||||
echo "FAILED for ${ASSERT} ! Please inspect manually."
|
||||
fi
|
||||
done
|
||||
|
||||
popd
|
||||
```
|
||||
|
||||
Don't ignore the incorrect formatting of the found assert files. These files you'll have to compare manually (currently OSX and FreeBSD).
|
||||
|
||||
|
||||
You can also look in the [gitian.sigs](https://github.com/monero-project/gitian.sigs/) repo and / or [getmonero.org release checksums](https://web.getmonero.org/downloads/hashes.txt) to see if others got the same checksum for the same version tag. If there is ever a mismatch -- **STOP! Something is wrong**. Contact others on IRC / github to figure out what is going on.
|
||||
|
||||
@ -181,14 +221,7 @@ Signing assert files
|
||||
If you chose to do detached signing using `--detach-sign` above (recommended), you need to copy these uncommitted changes to your host machine, then sign them using your gpg key like so:
|
||||
|
||||
```bash
|
||||
GH_USER=fluffypony
|
||||
VERSION=v0.17.0.0
|
||||
|
||||
gpg --detach-sign ${VERSION}-linux/${GH_USER}/monero-linux-*-build.assert
|
||||
gpg --detach-sign ${VERSION}-win/${GH_USER}/monero-win-*-build.assert
|
||||
gpg --detach-sign ${VERSION}-osx/${GH_USER}/monero-osx-*-build.assert
|
||||
gpg --detach-sign ${VERSION}-android/${GH_USER}/monero-android-*-build.assert
|
||||
gpg --detach-sign ${VERSION}-freebsd/${GH_USER}/monero-freebsd-*-build.assert
|
||||
for ASSERT in sigs/${VERSION}-*/*/*.assert; do gpg --detach-sign ${ASSERT}; done
|
||||
```
|
||||
|
||||
This will create a `.sig` file for each `.assert` file above (2 files for each platform).
|
||||
@ -201,6 +234,7 @@ Make a pull request (both the `.assert` and `.assert.sig` files) to the
|
||||
[monero-project/gitian.sigs](https://github.com/monero-project/gitian.sigs/) repository:
|
||||
|
||||
```bash
|
||||
cd gitian.sigs
|
||||
git checkout -b $VERSION
|
||||
# add your assert and sig files...
|
||||
git commit -S -a -m "Add $GH_USER $VERSION"
|
||||
|
@ -94,10 +94,6 @@ def build():
|
||||
os.chdir('builder')
|
||||
os.makedirs('inputs', exist_ok=True)
|
||||
|
||||
subprocess.check_call(['wget', '-N', '-P', 'inputs', 'https://downloads.sourceforge.net/project/osslsigncode/osslsigncode/osslsigncode-1.7.1.tar.gz'])
|
||||
subprocess.check_call(['wget', '-N', '-P', 'inputs', 'https://bitcoincore.org/cfields/osslsigncode-Backports-to-1.7.1.patch'])
|
||||
subprocess.check_output(["echo 'a8c4e9cafba922f89de0df1f2152e7be286aba73f78505169bc351a7938dd911 inputs/osslsigncode-Backports-to-1.7.1.patch' | sha256sum -c"], shell=True)
|
||||
subprocess.check_output(["echo 'f9a8cdb38b9c309326764ebc937cba1523a3a751a7ab05df3ecc99d18ae466c9 inputs/osslsigncode-1.7.1.tar.gz' | sha256sum -c"], shell=True)
|
||||
subprocess.check_call(['make', '-C', 'inputs/monero/contrib/depends', 'download', 'SOURCES_PATH=' + os.getcwd() + '/cache/common'])
|
||||
|
||||
rebuild()
|
||||
|
@ -36,10 +36,6 @@ with additional exclusive IPv4 address(es).
|
||||
|
||||
## Usage
|
||||
|
||||
Anonymity networks have no seed nodes (the feature is still considered
|
||||
experimental), so a user must specify an address. If configured properly,
|
||||
additional peers can be found through typical p2p peerlist sharing.
|
||||
|
||||
### Outbound Connections
|
||||
|
||||
Connecting to an anonymous address requires the command line option
|
||||
@ -54,8 +50,9 @@ separate process. On most systems the configuration will look like:
|
||||
which tells `monerod` that ".onion" p2p addresses can be forwarded to a socks
|
||||
proxy at IP 127.0.0.1 port 9050 with a max of 10 outgoing connections and
|
||||
".b32.i2p" p2p addresses can be forwarded to a socks proxy at IP 127.0.0.1 port
|
||||
9000 with the default max outgoing connections. Since there are no seed nodes
|
||||
for anonymity connections, peers must be manually specified:
|
||||
9000 with the default max outgoing connections.
|
||||
|
||||
If desired, peers can be manually specified:
|
||||
|
||||
```
|
||||
--add-exclusive-node rveahdfho7wo4b2m.onion:28083
|
||||
|
2
external/CMakeLists.txt
vendored
2
external/CMakeLists.txt
vendored
@ -38,8 +38,10 @@
|
||||
find_package(Miniupnpc REQUIRED)
|
||||
|
||||
message(STATUS "Using in-tree miniupnpc")
|
||||
set(UPNPC_NO_INSTALL TRUE CACHE BOOL "Disable miniupnp installation" FORCE)
|
||||
add_subdirectory(miniupnp/miniupnpc)
|
||||
set_property(TARGET libminiupnpc-static PROPERTY FOLDER "external")
|
||||
set_property(TARGET libminiupnpc-static PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
if(MSVC)
|
||||
set_property(TARGET libminiupnpc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -wd4244 -wd4267")
|
||||
elseif(NOT MSVC)
|
||||
|
10
external/db_drivers/liblmdb/mdb.c
vendored
10
external/db_drivers/liblmdb/mdb.c
vendored
@ -3461,9 +3461,9 @@ mdb_freelist_save(MDB_txn *txn)
|
||||
} else {
|
||||
x = mdb_mid2l_search(dl, mp->mp_pgno);
|
||||
mdb_tassert(txn, dl[x].mid == mp->mp_pgno);
|
||||
mdb_dpage_free(env, mp);
|
||||
}
|
||||
dl[x].mptr = NULL;
|
||||
mdb_dpage_free(env, mp);
|
||||
}
|
||||
{
|
||||
/* squash freed slots out of the dirty list */
|
||||
@ -4882,9 +4882,6 @@ mdb_env_open2(MDB_env *env, int prev)
|
||||
#endif
|
||||
env->me_maxpg = env->me_mapsize / env->me_psize;
|
||||
|
||||
if (env->me_txns)
|
||||
env->me_txns->mti_txnid = meta.mm_txnid;
|
||||
|
||||
#if MDB_DEBUG
|
||||
{
|
||||
MDB_meta *meta = mdb_env_pick_meta(env);
|
||||
@ -4984,6 +4981,9 @@ static int ESECT
|
||||
mdb_env_share_locks(MDB_env *env, int *excl)
|
||||
{
|
||||
int rc = 0;
|
||||
MDB_meta *meta = mdb_env_pick_meta(env);
|
||||
|
||||
env->me_txns->mti_txnid = meta->mm_txnid;
|
||||
|
||||
#ifdef _WIN32
|
||||
{
|
||||
@ -7867,7 +7867,7 @@ put_sub:
|
||||
xdata.mv_size = 0;
|
||||
xdata.mv_data = "";
|
||||
leaf = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]);
|
||||
if (flags == MDB_CURRENT) {
|
||||
if ((flags & (MDB_CURRENT|MDB_APPENDDUP)) == MDB_CURRENT) {
|
||||
xflags = MDB_CURRENT|MDB_NOSPILL;
|
||||
} else {
|
||||
mdb_xcursor_init1(mc, leaf);
|
||||
|
1
external/easylogging++/CMakeLists.txt
vendored
1
external/easylogging++/CMakeLists.txt
vendored
@ -31,6 +31,7 @@ cmake_minimum_required(VERSION 2.8.7)
|
||||
project(easylogging CXX)
|
||||
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
monero_enable_coverage()
|
||||
|
||||
find_package(Threads)
|
||||
find_package(Backtrace)
|
||||
|
59
external/easylogging++/easylogging++.cc
vendored
59
external/easylogging++/easylogging++.cc
vendored
@ -17,6 +17,7 @@
|
||||
#define EASYLOGGING_CC
|
||||
#include "easylogging++.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <unistd.h>
|
||||
|
||||
#if defined(AUTO_INITIALIZE_EASYLOGGINGPP)
|
||||
@ -2035,7 +2036,7 @@ void RegisteredLoggers::unsafeFlushAll(void) {
|
||||
|
||||
// VRegistry
|
||||
|
||||
VRegistry::VRegistry(base::type::VerboseLevel level, base::type::EnumType* pFlags) : m_level(level), m_pFlags(pFlags), m_lowest_priority(INT_MAX) {
|
||||
VRegistry::VRegistry(base::type::VerboseLevel level, base::type::EnumType* pFlags) : m_level(level), m_pFlags(pFlags) {
|
||||
}
|
||||
|
||||
/// @brief Sets verbose level. Accepted range is 0-9
|
||||
@ -2131,18 +2132,30 @@ static int priority(Level level) {
|
||||
return 7;
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
std::atomic<int> s_lowest_priority{INT_MAX};
|
||||
}
|
||||
|
||||
void VRegistry::clearCategories(void) {
|
||||
const base::threading::ScopedLock scopedLock(lock());
|
||||
m_categories.clear();
|
||||
m_cached_allowed_categories.clear();
|
||||
s_lowest_priority = INT_MAX;
|
||||
}
|
||||
|
||||
void VRegistry::setCategories(const char* categories, bool clear) {
|
||||
base::threading::ScopedLock scopedLock(lock());
|
||||
auto insert = [&](std::stringstream& ss, Level level) {
|
||||
m_categories.push_back(std::make_pair(ss.str(), level));
|
||||
m_cached_allowed_categories.clear();
|
||||
int pri = priority(level);
|
||||
if (pri > m_lowest_priority)
|
||||
m_lowest_priority = pri;
|
||||
if (pri > s_lowest_priority)
|
||||
s_lowest_priority = pri;
|
||||
};
|
||||
|
||||
if (clear) {
|
||||
m_lowest_priority = 0;
|
||||
s_lowest_priority = 0;
|
||||
m_categories.clear();
|
||||
m_cached_allowed_categories.clear();
|
||||
m_categoriesString.clear();
|
||||
@ -2200,9 +2213,9 @@ std::string VRegistry::getCategories() {
|
||||
}
|
||||
|
||||
bool VRegistry::allowed(Level level, const std::string &category) {
|
||||
const int pri = priority(level);
|
||||
if (pri > m_lowest_priority)
|
||||
return false;
|
||||
return priority_allowed(priority(level), category);
|
||||
}
|
||||
bool VRegistry::priority_allowed(const int pri, const std::string &category) {
|
||||
base::threading::ScopedLock scopedLock(lock());
|
||||
const std::map<std::string, int>::const_iterator it = m_cached_allowed_categories.find(category);
|
||||
if (it != m_cached_allowed_categories.end())
|
||||
@ -2477,20 +2490,20 @@ void DefaultLogDispatchCallback::handle(const LogDispatchData* data) {
|
||||
|
||||
|
||||
template<typename Transform>
|
||||
static inline std::string utf8canonical(const std::string &s, Transform t = [](wint_t c)->wint_t { return c; })
|
||||
static inline void utf8canonical(std::string &s, Transform t = [](wint_t c)->wint_t { return c; })
|
||||
{
|
||||
std::string sc = "";
|
||||
size_t avail = s.size();
|
||||
const char *ptr = s.data();
|
||||
wint_t cp = 0;
|
||||
int bytes = 1;
|
||||
int rbytes = 1, bytes = -1;
|
||||
char wbuf[8], *wptr;
|
||||
size_t w_offset = 0;
|
||||
while (avail--)
|
||||
{
|
||||
if ((*ptr & 0x80) == 0)
|
||||
{
|
||||
cp = *ptr++;
|
||||
bytes = 1;
|
||||
rbytes = 1;
|
||||
}
|
||||
else if ((*ptr & 0xe0) == 0xc0)
|
||||
{
|
||||
@ -2499,7 +2512,7 @@ static inline std::string utf8canonical(const std::string &s, Transform t = [](w
|
||||
cp = (*ptr++ & 0x1f) << 6;
|
||||
cp |= *ptr++ & 0x3f;
|
||||
--avail;
|
||||
bytes = 2;
|
||||
rbytes = 2;
|
||||
}
|
||||
else if ((*ptr & 0xf0) == 0xe0)
|
||||
{
|
||||
@ -2509,7 +2522,7 @@ static inline std::string utf8canonical(const std::string &s, Transform t = [](w
|
||||
cp |= (*ptr++ & 0x3f) << 6;
|
||||
cp |= *ptr++ & 0x3f;
|
||||
avail -= 2;
|
||||
bytes = 3;
|
||||
rbytes = 3;
|
||||
}
|
||||
else if ((*ptr & 0xf8) == 0xf0)
|
||||
{
|
||||
@ -2520,7 +2533,7 @@ static inline std::string utf8canonical(const std::string &s, Transform t = [](w
|
||||
cp |= (*ptr++ & 0x3f) << 6;
|
||||
cp |= *ptr++ & 0x3f;
|
||||
avail -= 3;
|
||||
bytes = 4;
|
||||
rbytes = 4;
|
||||
}
|
||||
else
|
||||
throw std::runtime_error("Invalid UTF-8");
|
||||
@ -2537,6 +2550,9 @@ static inline std::string utf8canonical(const std::string &s, Transform t = [](w
|
||||
else
|
||||
throw std::runtime_error("Invalid code point UTF-8 transformation");
|
||||
|
||||
if (bytes > rbytes)
|
||||
throw std::runtime_error("In place sanitization requires replacements to not take more space than the original code points");
|
||||
|
||||
wptr = wbuf;
|
||||
switch (bytes)
|
||||
{
|
||||
@ -2547,16 +2563,17 @@ static inline std::string utf8canonical(const std::string &s, Transform t = [](w
|
||||
default: throw std::runtime_error("Invalid UTF-8");
|
||||
}
|
||||
*wptr = 0;
|
||||
sc.append(wbuf, bytes);
|
||||
memcpy(&s[w_offset], wbuf, bytes);
|
||||
w_offset += bytes;
|
||||
cp = 0;
|
||||
bytes = 1;
|
||||
}
|
||||
return sc;
|
||||
s.resize(w_offset);
|
||||
}
|
||||
|
||||
void sanitize(std::string &s)
|
||||
{
|
||||
s = utf8canonical(s, [](wint_t c)->wint_t {
|
||||
utf8canonical(s, [](wint_t c)->wint_t {
|
||||
if (c == 9 || c == 10 || c == 13)
|
||||
return c;
|
||||
if (c < 0x20)
|
||||
@ -3335,6 +3352,14 @@ void Helpers::logCrashReason(int sig, bool stackTraceIfAvailable, Level level, c
|
||||
|
||||
// Loggers
|
||||
|
||||
bool Loggers::allowed(Level level, const char* cat)
|
||||
{
|
||||
const int pri = base::priority(level);
|
||||
if (pri > base::s_lowest_priority)
|
||||
return false;
|
||||
return ELPP->vRegistry()->priority_allowed(pri, std::string{cat});
|
||||
}
|
||||
|
||||
Logger* Loggers::getLogger(const std::string& identity, bool registerIfNotAvailable) {
|
||||
return ELPP->registeredLoggers()->get(identity, registerIfNotAvailable);
|
||||
}
|
||||
|
12
external/easylogging++/easylogging++.h
vendored
12
external/easylogging++/easylogging++.h
vendored
@ -412,7 +412,6 @@ ELPP_INTERNAL_DEBUGGING_OUT_INFO << ELPP_INTERNAL_DEBUGGING_MSG(internalInfoStre
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <atomic>
|
||||
#if ELPP_THREADING_ENABLED
|
||||
# if ELPP_USE_STD_THREADING
|
||||
# include <mutex>
|
||||
@ -2464,12 +2463,7 @@ class VRegistry : base::NoCopy, public base::threading::ThreadSafe {
|
||||
return m_level;
|
||||
}
|
||||
|
||||
inline void clearCategories(void) {
|
||||
base::threading::ScopedLock scopedLock(lock());
|
||||
m_categories.clear();
|
||||
m_cached_allowed_categories.clear();
|
||||
m_lowest_priority = INT_MAX;
|
||||
}
|
||||
void clearCategories(void);
|
||||
|
||||
inline void clearModules(void) {
|
||||
base::threading::ScopedLock scopedLock(lock());
|
||||
@ -2482,6 +2476,7 @@ class VRegistry : base::NoCopy, public base::threading::ThreadSafe {
|
||||
|
||||
void setModules(const char* modules);
|
||||
|
||||
bool priority_allowed(int priority, const std::string &category);
|
||||
bool allowed(Level level, const std::string &category);
|
||||
|
||||
bool allowed(base::type::VerboseLevel vlevel, const char* file);
|
||||
@ -2513,7 +2508,6 @@ class VRegistry : base::NoCopy, public base::threading::ThreadSafe {
|
||||
std::map<std::string, int> m_cached_allowed_categories;
|
||||
std::string m_categoriesString;
|
||||
std::string m_filenameCommonPrefix;
|
||||
std::atomic<int> m_lowest_priority;
|
||||
};
|
||||
} // namespace base
|
||||
class LogMessage {
|
||||
@ -3868,6 +3862,8 @@ class Helpers : base::StaticClass {
|
||||
/// @brief Static helpers to deal with loggers and their configurations
|
||||
class Loggers : base::StaticClass {
|
||||
public:
|
||||
/// @brief Determines whether logging will occur at this level and category
|
||||
static bool allowed(Level leve, const char* cat);
|
||||
/// @brief Gets existing or registers new logger
|
||||
static Logger* getLogger(const std::string& identity, bool registerIfNotAvailable = true);
|
||||
/// @brief Changes default log builder for future loggers
|
||||
|
2
external/miniupnp
vendored
2
external/miniupnp
vendored
@ -1 +1 @@
|
||||
Subproject commit 4c700e09526a7d546394e85628c57e9490feefa0
|
||||
Subproject commit 544e6fcc73c5ad9af48a8985c94f0f1d742ef2e0
|
@ -1436,7 +1436,6 @@ uint64_t BlockchainLMDB::add_transaction_data(const crypto::hash& blk_hash, cons
|
||||
throw0(DB_ERROR(lmdb_error("Failed to add tx data to db transaction: ", result).c_str()));
|
||||
|
||||
const cryptonote::blobdata_ref &blob = txp.second;
|
||||
MDB_val_sized(blobval, blob);
|
||||
|
||||
unsigned int unprunable_size = tx.unprunable_size;
|
||||
if (unprunable_size == 0)
|
||||
@ -3896,9 +3895,8 @@ bool BlockchainLMDB::get_blocks_from(uint64_t start_height, size_t min_block_cou
|
||||
uint64_t size = 0;
|
||||
size_t num_txes = 0;
|
||||
MDB_val_copy<uint64_t> key(start_height);
|
||||
MDB_val k, v, val_tx_id;
|
||||
MDB_val v, val_tx_id;
|
||||
uint64_t tx_id = ~0;
|
||||
MDB_cursor_op op = MDB_SET;
|
||||
for (uint64_t h = start_height; h < blockchain_height && blocks.size() < max_block_count && (size < max_size || blocks.size() < min_block_count); ++h)
|
||||
{
|
||||
MDB_cursor_op op = h == start_height ? MDB_SET : MDB_NEXT;
|
||||
@ -4020,7 +4018,7 @@ bool BlockchainLMDB::get_prunable_tx_hash(const crypto::hash& tx_hash, crypto::h
|
||||
RCURSOR(txs_prunable_hash);
|
||||
|
||||
MDB_val_set(v, tx_hash);
|
||||
MDB_val result, val_tx_prunable_hash;
|
||||
MDB_val result;
|
||||
auto get_result = mdb_cursor_get(m_cur_tx_indices, (MDB_val *)&zerokval, &v, MDB_GET_BOTH);
|
||||
if (get_result == 0)
|
||||
{
|
||||
@ -5048,7 +5046,6 @@ bool BlockchainLMDB::get_output_distribution(uint64_t amount, uint64_t from_heig
|
||||
return false;
|
||||
distribution.resize(db_height - from_height, 0);
|
||||
|
||||
bool fret = true;
|
||||
MDB_val_set(k, amount);
|
||||
MDB_val v;
|
||||
MDB_cursor_op op = MDB_SET;
|
||||
@ -10930,11 +10927,10 @@ void BlockchainLMDB::migrate_0_1()
|
||||
void BlockchainLMDB::migrate_1_2()
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||
uint64_t i, z;
|
||||
uint64_t i;
|
||||
int result;
|
||||
mdb_txn_safe txn(false);
|
||||
MDB_val k, v;
|
||||
char *ptr;
|
||||
MDB_val v;
|
||||
|
||||
MGINFO_YELLOW("Migrating blockchain from DB version 1 to 2 - this may take a while:");
|
||||
MINFO("updating txs_pruned and txs_prunable tables...");
|
||||
@ -11135,7 +11131,6 @@ void BlockchainLMDB::migrate_2_3()
|
||||
if (result)
|
||||
throw0(DB_ERROR(lmdb_error("Failed to open a cursor for block_info: ", result).c_str()));
|
||||
if (!i) {
|
||||
MDB_stat db_stat;
|
||||
result = mdb_stat(txn, m_block_info, &db_stats);
|
||||
if (result)
|
||||
throw0(DB_ERROR(lmdb_error("Failed to query m_block_info: ", result).c_str()));
|
||||
@ -11267,7 +11262,6 @@ void BlockchainLMDB::migrate_3_4()
|
||||
if (result)
|
||||
throw0(DB_ERROR(lmdb_error("Failed to open a cursor for blocks: ", result).c_str()));
|
||||
if (!i) {
|
||||
MDB_stat db_stat;
|
||||
result = mdb_stat(txn, m_block_info, &db_stats);
|
||||
if (result)
|
||||
throw0(DB_ERROR(lmdb_error("Failed to query m_block_info: ", result).c_str()));
|
||||
@ -11421,7 +11415,6 @@ void BlockchainLMDB::migrate_4_5()
|
||||
if (result)
|
||||
throw0(DB_ERROR(lmdb_error("Failed to open a cursor for block_info: ", result).c_str()));
|
||||
if (!i) {
|
||||
MDB_stat db_stat;
|
||||
result = mdb_stat(txn, m_block_info, &db_stats);
|
||||
if (result)
|
||||
throw0(DB_ERROR(lmdb_error("Failed to query m_block_info: ", result).c_str()));
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/archive/portable_binary_iarchive.hpp>
|
||||
#include <boost/archive/portable_binary_oarchive.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include "common/unordered_containers_boost_serialization.h"
|
||||
#include "common/command_line.h"
|
||||
#include "common/varint.h"
|
||||
@ -149,7 +150,7 @@ struct ancestry_state_t
|
||||
{
|
||||
std::unordered_map<crypto::hash, cryptonote::transaction> old_tx_cache;
|
||||
a & old_tx_cache;
|
||||
for (const auto i: old_tx_cache)
|
||||
for (const auto& i: old_tx_cache)
|
||||
tx_cache.insert(std::make_pair(i.first, ::tx_data_t(i.second)));
|
||||
}
|
||||
else
|
||||
@ -161,7 +162,7 @@ struct ancestry_state_t
|
||||
std::unordered_map<uint64_t, cryptonote::block> old_block_cache;
|
||||
a & old_block_cache;
|
||||
block_cache.resize(old_block_cache.size());
|
||||
for (const auto i: old_block_cache)
|
||||
for (const auto& i: old_block_cache)
|
||||
block_cache[i.first] = i.second;
|
||||
}
|
||||
else
|
||||
@ -575,7 +576,6 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
add_ancestry(state.ancestry, txid, ancestor{amount, offset});
|
||||
// find the tx which created this output
|
||||
bool found = false;
|
||||
crypto::hash output_txid;
|
||||
if (!get_output_txid(state, db, amount, offset, output_txid))
|
||||
{
|
||||
@ -693,7 +693,6 @@ int main(int argc, char* argv[])
|
||||
add_ancestor(ancestry, amount, offset);
|
||||
|
||||
// find the tx which created this output
|
||||
bool found = false;
|
||||
crypto::hash output_txid;
|
||||
if (!get_output_txid(state, db, amount, offset, output_txid))
|
||||
{
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
#include <boost/range/adaptor/transformed.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "common/unordered_containers_boost_serialization.h"
|
||||
#include "common/command_line.h"
|
||||
#include "common/varint.h"
|
||||
@ -47,9 +48,6 @@ namespace po = boost::program_options;
|
||||
using namespace epee;
|
||||
using namespace cryptonote;
|
||||
|
||||
static const char zerokey[8] = {0};
|
||||
static const MDB_val zerokval = { sizeof(zerokey), (void *)zerokey };
|
||||
|
||||
static uint64_t records_per_sync = 200;
|
||||
static uint64_t db_flags = 0;
|
||||
static MDB_dbi dbi_relative_rings;
|
||||
@ -703,7 +701,6 @@ static void get_per_amount_outputs(MDB_txn *txn, uint64_t amount, uint64_t &tota
|
||||
int dbr = mdb_cursor_open(txn, dbi_per_amount, &cur);
|
||||
CHECK_AND_ASSERT_THROW_MES(!dbr, "Failed to open cursor for per amount outputs: " + std::string(mdb_strerror(dbr)));
|
||||
MDB_val k, v;
|
||||
mdb_size_t count = 0;
|
||||
k.mv_size = sizeof(uint64_t);
|
||||
k.mv_data = (void*)&amount;
|
||||
dbr = mdb_cursor_get(cur, &k, &v, MDB_SET);
|
||||
@ -726,7 +723,6 @@ static void inc_per_amount_outputs(MDB_txn *txn, uint64_t amount, uint64_t total
|
||||
int dbr = mdb_cursor_open(txn, dbi_per_amount, &cur);
|
||||
CHECK_AND_ASSERT_THROW_MES(!dbr, "Failed to open cursor for per amount outputs: " + std::string(mdb_strerror(dbr)));
|
||||
MDB_val k, v;
|
||||
mdb_size_t count = 0;
|
||||
k.mv_size = sizeof(uint64_t);
|
||||
k.mv_data = (void*)&amount;
|
||||
dbr = mdb_cursor_get(cur, &k, &v, MDB_SET);
|
||||
@ -1077,7 +1073,6 @@ static std::vector<std::pair<uint64_t, uint64_t>> load_outputs(const std::string
|
||||
s[len - 1] = 0;
|
||||
if (!s[0])
|
||||
continue;
|
||||
std::pair<uint64_t, uint64_t> output;
|
||||
uint64_t offset, num_offsets;
|
||||
if (sscanf(s, "@%" PRIu64, &amount) == 1)
|
||||
{
|
||||
@ -1269,8 +1264,6 @@ int main(int argc, char* argv[])
|
||||
|
||||
LOG_PRINT_L0("Scanning for spent outputs...");
|
||||
|
||||
size_t done = 0;
|
||||
|
||||
const uint64_t start_blackballed_outputs = get_num_spent_outputs();
|
||||
|
||||
tools::ringdb ringdb(output_file_path.string(), epee::string_tools::pod_to_hex(get_genesis_block_hash(inputs[0])));
|
||||
|
@ -27,6 +27,7 @@
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <boost/range/adaptor/transformed.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include "common/command_line.h"
|
||||
#include "common/varint.h"
|
||||
|
@ -227,7 +227,7 @@ int import_from_file(cryptonote::core& core, const std::string& import_file_path
|
||||
return false;
|
||||
}
|
||||
|
||||
uint64_t block_first, block_last;
|
||||
uint64_t block_first;
|
||||
uint64_t start_height = 1, seek_height;
|
||||
if (opt_resume)
|
||||
start_height = core.get_blockchain_storage().get_current_blockchain_height();
|
||||
|
@ -29,6 +29,8 @@
|
||||
#include <array>
|
||||
#include <lmdb.h>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "common/command_line.h"
|
||||
#include "common/pruning.h"
|
||||
#include "cryptonote_core/cryptonote_core.h"
|
||||
|
@ -27,6 +27,7 @@
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "common/command_line.h"
|
||||
#include "serialization/crypto.h"
|
||||
#include "cryptonote_core/tx_pool.h"
|
||||
@ -66,7 +67,6 @@ static std::map<uint64_t, uint64_t> load_outputs(const std::string &filename)
|
||||
s[len - 1] = 0;
|
||||
if (!s[0])
|
||||
continue;
|
||||
std::pair<uint64_t, uint64_t> output;
|
||||
uint64_t offset, num_offsets;
|
||||
if (sscanf(s, "@%" PRIu64, &amount) == 1)
|
||||
{
|
||||
|
@ -27,6 +27,7 @@
|
||||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include "common/command_line.h"
|
||||
#include "common/varint.h"
|
||||
#include "cryptonote_basic/cryptonote_boost_serialization.h"
|
||||
|
@ -28,6 +28,7 @@
|
||||
|
||||
#include <boost/range/adaptor/transformed.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include "common/command_line.h"
|
||||
#include "common/varint.h"
|
||||
#include "cryptonote_core/tx_pool.h"
|
||||
@ -180,7 +181,6 @@ int main(int argc, char* argv[])
|
||||
|
||||
LOG_PRINT_L0("Building usage patterns...");
|
||||
|
||||
size_t done = 0;
|
||||
std::unordered_map<output_data, std::list<reference>> outputs;
|
||||
std::unordered_map<uint64_t,uint64_t> indices;
|
||||
|
||||
@ -195,7 +195,7 @@ int main(int argc, char* argv[])
|
||||
{
|
||||
if (opt_rct_only && out.amount)
|
||||
continue;
|
||||
uint64_t index = indices[out.amount]++;
|
||||
indices[out.amount]++;
|
||||
output_data od(out.amount, indices[out.amount], coinbase, height);
|
||||
auto itb = outputs.emplace(od, std::list<reference>());
|
||||
itb.first->first.info(coinbase, height);
|
||||
|
@ -34,6 +34,8 @@
|
||||
#include "string_tools.h"
|
||||
#include "storages/portable_storage_template_helper.h" // epee json include
|
||||
#include "serialization/keyvalue_serialization.h"
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
using namespace epee;
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
@ -124,6 +125,7 @@ static const char *get_record_name(int record_type)
|
||||
case DNS_TYPE_A: return "A";
|
||||
case DNS_TYPE_TXT: return "TXT";
|
||||
case DNS_TYPE_AAAA: return "AAAA";
|
||||
case DNS_TYPE_TLSA: return "TLSA";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
@ -186,6 +188,13 @@ boost::optional<std::string> txt_to_string(const char* src, size_t len)
|
||||
return std::string(src+1, len-1);
|
||||
}
|
||||
|
||||
boost::optional<std::string> tlsa_to_string(const char* src, size_t len)
|
||||
{
|
||||
if (len < 4)
|
||||
return boost::none;
|
||||
return std::string(src, len);
|
||||
}
|
||||
|
||||
// custom smart pointer.
|
||||
// TODO: see if std::auto_ptr and the like support custom destructors
|
||||
template<typename type, void (*freefunc)(type*)>
|
||||
@ -326,11 +335,15 @@ std::vector<std::string> DNSResolver::get_record(const std::string& url, int rec
|
||||
// destructor takes care of cleanup
|
||||
ub_result_ptr result;
|
||||
|
||||
MDEBUG("Performing DNSSEC " << get_record_name(record_type) << " record query for " << url);
|
||||
|
||||
// call DNS resolver, blocking. if return value not zero, something went wrong
|
||||
if (!ub_resolve(m_data->m_ub_context, string_copy(url.c_str()), record_type, DNS_CLASS_IN, &result))
|
||||
{
|
||||
dnssec_available = (result->secure || result->bogus);
|
||||
dnssec_valid = result->secure && !result->bogus;
|
||||
if (dnssec_available && !dnssec_valid)
|
||||
MWARNING("Invalid DNSSEC " << get_record_name(record_type) << " record signature for " << url << ": " << result->why_bogus);
|
||||
if (result->havedata)
|
||||
{
|
||||
for (size_t i=0; result->data[i] != NULL; i++)
|
||||
@ -338,8 +351,9 @@ std::vector<std::string> DNSResolver::get_record(const std::string& url, int rec
|
||||
boost::optional<std::string> res = (*reader)(result->data[i], result->len[i]);
|
||||
if (res)
|
||||
{
|
||||
MINFO("Found \"" << *res << "\" in " << get_record_name(record_type) << " record for " << url);
|
||||
addresses.push_back(*res);
|
||||
// do not dump dns record directly from dns into log
|
||||
MINFO("Found " << get_record_name(record_type) << " record for " << url);
|
||||
addresses.push_back(std::move(*res));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -363,6 +377,17 @@ std::vector<std::string> DNSResolver::get_txt_record(const std::string& url, boo
|
||||
return get_record(url, DNS_TYPE_TXT, txt_to_string, dnssec_available, dnssec_valid);
|
||||
}
|
||||
|
||||
std::vector<std::string> DNSResolver::get_tlsa_tcp_record(const boost::string_ref url, const boost::string_ref port, bool& dnssec_available, bool& dnssec_valid)
|
||||
{
|
||||
std::string service_addr;
|
||||
service_addr.reserve(url.size() + port.size() + 7);
|
||||
service_addr.push_back('_');
|
||||
service_addr.append(port.data(), port.size());
|
||||
service_addr.append("._tcp.");
|
||||
service_addr.append(url.data(), url.size());
|
||||
return get_record(service_addr, DNS_TYPE_TLSA, tlsa_to_string, dnssec_available, dnssec_valid);
|
||||
}
|
||||
|
||||
std::string DNSResolver::get_dns_format_from_oa_address(const std::string& oa_addr)
|
||||
{
|
||||
std::string addr(oa_addr);
|
||||
@ -480,36 +505,12 @@ std::string get_account_address_as_str_from_url(const std::string& url, bool& dn
|
||||
return dns_confirm(url, addresses, dnssec_valid);
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
bool dns_records_match(const std::vector<std::string>& a, const std::vector<std::string>& b)
|
||||
{
|
||||
if (a.size() != b.size()) return false;
|
||||
|
||||
for (const auto& record_in_a : a)
|
||||
{
|
||||
bool ok = false;
|
||||
for (const auto& record_in_b : b)
|
||||
{
|
||||
if (record_in_a == record_in_b)
|
||||
{
|
||||
ok = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!ok) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool load_txt_records_from_dns(std::vector<std::string> &good_records, const std::vector<std::string> &dns_urls)
|
||||
{
|
||||
// Prevent infinite recursion when distributing
|
||||
if (dns_urls.empty()) return false;
|
||||
|
||||
std::vector<std::vector<std::string> > records;
|
||||
std::vector<std::set<std::string> > records;
|
||||
records.resize(dns_urls.size());
|
||||
|
||||
size_t first_index = crypto::rand_idx(dns_urls.size());
|
||||
@ -521,7 +522,9 @@ bool load_txt_records_from_dns(std::vector<std::string> &good_records, const std
|
||||
for (size_t n = 0; n < dns_urls.size(); ++n)
|
||||
{
|
||||
tpool.submit(&waiter,[n, dns_urls, &records, &avail, &valid](){
|
||||
records[n] = tools::DNSResolver::instance().get_txt_record(dns_urls[n], avail[n], valid[n]);
|
||||
const auto res = tools::DNSResolver::instance().get_txt_record(dns_urls[n], avail[n], valid[n]);
|
||||
for (const auto &s: res)
|
||||
records[n].insert(s);
|
||||
});
|
||||
}
|
||||
waiter.wait();
|
||||
@ -564,29 +567,31 @@ bool load_txt_records_from_dns(std::vector<std::string> &good_records, const std
|
||||
return false;
|
||||
}
|
||||
|
||||
int good_records_index = -1;
|
||||
for (size_t i = 0; i < records.size() - 1; ++i)
|
||||
typedef std::map<std::set<std::string>, uint32_t> map_t;
|
||||
map_t record_count;
|
||||
for (const auto &e: records)
|
||||
{
|
||||
if (records[i].size() == 0) continue;
|
||||
|
||||
for (size_t j = i + 1; j < records.size(); ++j)
|
||||
{
|
||||
if (dns_records_match(records[i], records[j]))
|
||||
{
|
||||
good_records_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (good_records_index >= 0) break;
|
||||
if (!e.empty())
|
||||
++record_count[e];
|
||||
}
|
||||
|
||||
if (good_records_index < 0)
|
||||
map_t::const_iterator good_record = record_count.end();
|
||||
for (map_t::const_iterator i = record_count.begin(); i != record_count.end(); ++i)
|
||||
{
|
||||
LOG_PRINT_L0("WARNING: no two DNS TXT records matched");
|
||||
if (good_record == record_count.end() || i->second > good_record->second)
|
||||
good_record = i;
|
||||
}
|
||||
|
||||
MDEBUG("Found " << (good_record == record_count.end() ? 0 : good_record->second) << "/" << dns_urls.size() << " matching records from " << num_valid_records << " valid records");
|
||||
if (good_record == record_count.end() || good_record->second < dns_urls.size() / 2 + 1)
|
||||
{
|
||||
LOG_PRINT_L0("WARNING: no majority of DNS TXT records matched (only " << good_record->second << "/" << dns_urls.size() << ")");
|
||||
return false;
|
||||
}
|
||||
|
||||
good_records = records[good_records_index];
|
||||
good_records = {};
|
||||
for (const auto &s: good_record->first)
|
||||
good_records.push_back(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -31,15 +31,17 @@
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <boost/optional/optional_fwd.hpp>
|
||||
#include <boost/utility/string_ref_fwd.hpp>
|
||||
|
||||
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 = 16;
|
||||
const static int DNS_TYPE_AAAA = 8;
|
||||
constexpr const int DNS_CLASS_IN = 1;
|
||||
constexpr const int DNS_TYPE_A = 1;
|
||||
constexpr const int DNS_TYPE_TXT = 16;
|
||||
constexpr const int DNS_TYPE_AAAA = 8;
|
||||
constexpr const int DNS_TYPE_TLSA = 52;
|
||||
|
||||
struct DNSResolverData;
|
||||
|
||||
@ -105,6 +107,17 @@ public:
|
||||
// TODO: modify this to accommodate DNSSEC
|
||||
std::vector<std::string> get_txt_record(const std::string& url, bool& dnssec_available, bool& dnssec_valid);
|
||||
|
||||
/**
|
||||
* @brief gets all TLSA TCP records from a DNS query for the supplied URL;
|
||||
* if no TLSA record present returns an empty vector.
|
||||
*
|
||||
* @param url A string containing a URL to query for
|
||||
* @param port The service port number (as string) to query
|
||||
*
|
||||
* @return A vector of strings containing all TLSA records; or an empty vector
|
||||
*/
|
||||
std::vector<std::string> get_tlsa_tcp_record(boost::string_ref url, boost::string_ref port, bool& dnssec_available, bool& dnssec_valid);
|
||||
|
||||
/**
|
||||
* @brief Gets a DNS address from OpenAlias format
|
||||
*
|
||||
|
@ -35,6 +35,10 @@
|
||||
#include "common/i18n.h"
|
||||
#include "translation_files.h"
|
||||
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "i18n"
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include "net/abstract_http_client.h"
|
||||
#include "net/http.h"
|
||||
#include "storages/portable_storage.h"
|
||||
|
@ -51,7 +51,10 @@ namespace tools
|
||||
static const std::vector<std::string> dns_urls = {
|
||||
"updates.moneropulse.org",
|
||||
"updates.moneropulse.net",
|
||||
"updates.moneropulse.co",
|
||||
"updates.moneropulse.fr",
|
||||
"updates.moneropulse.de",
|
||||
"updates.moneropulse.no",
|
||||
"updates.moneropulse.ch",
|
||||
"updates.moneropulse.se"
|
||||
};
|
||||
|
||||
|
@ -322,14 +322,16 @@ void rx_slow_hash(const uint64_t mainheight, const uint64_t seedheight, const ch
|
||||
|
||||
cache = rx_sp->rs_cache;
|
||||
if (cache == NULL) {
|
||||
if (cache == NULL) {
|
||||
if (!(disabled_flags() & RANDOMX_FLAG_LARGE_PAGES)) {
|
||||
cache = randomx_alloc_cache(flags | RANDOMX_FLAG_LARGE_PAGES);
|
||||
if (cache == NULL) {
|
||||
static unsigned int warnings = 0;
|
||||
if (warnings++ % 1024 == 0)
|
||||
mdebug(RX_LOGCAT, "Couldn't use largePages for RandomX cache (%u times)", warnings);
|
||||
cache = randomx_alloc_cache(flags);
|
||||
}
|
||||
}
|
||||
if (cache == NULL) {
|
||||
cache = randomx_alloc_cache(flags);
|
||||
if (cache == NULL)
|
||||
local_abort("Couldn't allocate RandomX cache");
|
||||
}
|
||||
@ -351,13 +353,16 @@ void rx_slow_hash(const uint64_t mainheight, const uint64_t seedheight, const ch
|
||||
CTHR_MUTEX_LOCK(rx_dataset_mutex);
|
||||
if (!rx_dataset_nomem) {
|
||||
if (rx_dataset == NULL) {
|
||||
static unsigned int warnings = 0;
|
||||
rx_dataset = randomx_alloc_dataset(RANDOMX_FLAG_LARGE_PAGES);
|
||||
if (rx_dataset == NULL) {
|
||||
if (warnings++ % 1024 == 0)
|
||||
mdebug(RX_LOGCAT, "Couldn't use largePages for RandomX dataset");
|
||||
rx_dataset = randomx_alloc_dataset(RANDOMX_FLAG_DEFAULT);
|
||||
if (!(disabled_flags() & RANDOMX_FLAG_LARGE_PAGES)) {
|
||||
rx_dataset = randomx_alloc_dataset(RANDOMX_FLAG_LARGE_PAGES);
|
||||
if (rx_dataset == NULL) {
|
||||
static unsigned int warnings = 0;
|
||||
if (warnings++ % 1024 == 0)
|
||||
mdebug(RX_LOGCAT, "Couldn't use largePages for RandomX dataset");
|
||||
}
|
||||
}
|
||||
if (rx_dataset == NULL)
|
||||
rx_dataset = randomx_alloc_dataset(RANDOMX_FLAG_DEFAULT);
|
||||
if (rx_dataset != NULL)
|
||||
rx_initdata(rx_sp->rs_cache, miners, seedheight);
|
||||
}
|
||||
@ -373,13 +378,16 @@ void rx_slow_hash(const uint64_t mainheight, const uint64_t seedheight, const ch
|
||||
}
|
||||
CTHR_MUTEX_UNLOCK(rx_dataset_mutex);
|
||||
}
|
||||
rx_vm = randomx_create_vm(flags | RANDOMX_FLAG_LARGE_PAGES, rx_sp->rs_cache, rx_dataset);
|
||||
if(rx_vm == NULL) { //large pages failed
|
||||
static unsigned int warnings = 0;
|
||||
if (warnings++ % 1024 == 0)
|
||||
mdebug(RX_LOGCAT, "Couldn't use largePages for RandomX VM (%u times)", warnings);
|
||||
rx_vm = randomx_create_vm(flags, rx_sp->rs_cache, rx_dataset);
|
||||
if (!(disabled_flags() & RANDOMX_FLAG_LARGE_PAGES)) {
|
||||
rx_vm = randomx_create_vm(flags | RANDOMX_FLAG_LARGE_PAGES, rx_sp->rs_cache, rx_dataset);
|
||||
if(rx_vm == NULL) { //large pages failed
|
||||
static unsigned int warnings = 0;
|
||||
if (warnings++ % 1024 == 0)
|
||||
mdebug(RX_LOGCAT, "Couldn't use largePages for RandomX VM (%u times)", warnings);
|
||||
}
|
||||
}
|
||||
if (rx_vm == NULL)
|
||||
rx_vm = randomx_create_vm(flags, rx_sp->rs_cache, rx_dataset);
|
||||
if(rx_vm == NULL) {//fallback if everything fails
|
||||
flags = RANDOMX_FLAG_DEFAULT | (miners ? RANDOMX_FLAG_FULL_MEM : 0);
|
||||
rx_vm = randomx_create_vm(flags, rx_sp->rs_cache, rx_dataset);
|
||||
|
@ -77,6 +77,8 @@ namespace cryptonote
|
||||
int m_expect_response;
|
||||
uint64_t m_expect_height;
|
||||
size_t m_num_requested;
|
||||
epee::copyable_atomic m_new_stripe_notification{0};
|
||||
epee::copyable_atomic m_idle_peer_notification{0};
|
||||
};
|
||||
|
||||
inline std::string get_protocol_state_string(cryptonote_connection_context::state s)
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include "wipeable_string.h"
|
||||
#include "string_tools.h"
|
||||
#include "string_tools_lexical.h"
|
||||
#include "serialization/string.h"
|
||||
#include "cryptonote_format_utils.h"
|
||||
#include "cryptonote_config.h"
|
||||
@ -105,7 +106,6 @@ namespace cryptonote
|
||||
|
||||
uint64_t get_transaction_weight_clawback(const transaction &tx, size_t n_padded_outputs)
|
||||
{
|
||||
const rct::rctSig &rv = tx.rct_signatures;
|
||||
const uint64_t bp_base = 368;
|
||||
const size_t n_outputs = tx.vout.size();
|
||||
if (n_padded_outputs <= 2)
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "string_tools.h"
|
||||
#include "storages/portable_storage_template_helper.h"
|
||||
#include "boost/logic/tribool.hpp"
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <sys/times.h>
|
||||
|
@ -197,7 +197,6 @@
|
||||
#define CRYPTONOTE_PRUNING_STRIPE_SIZE 4096 // the smaller, the smoother the increase
|
||||
#define CRYPTONOTE_PRUNING_LOG_STRIPES 3 // the higher, the more space saved
|
||||
#define CRYPTONOTE_PRUNING_TIP_BLOCKS 5500 // the smaller, the more space saved
|
||||
//#define CRYPTONOTE_PRUNING_DEBUG_SPOOF_SEED
|
||||
|
||||
#define RPC_CREDITS_PER_HASH_SCALE ((float)(1<<24))
|
||||
|
||||
@ -238,12 +237,12 @@ namespace config
|
||||
const unsigned char HASH_KEY_RPC_PAYMENT_NONCE = 0x58;
|
||||
const unsigned char HASH_KEY_MEMORY = 'k';
|
||||
const unsigned char HASH_KEY_MULTISIG[] = {'M', 'u', 'l', 't' , 'i', 's', 'i', 'g', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
const unsigned char HASH_KEY_MM_SLOT = 'm';
|
||||
const unsigned char HASH_KEY_TXPROOF_V2[] = "TXPROOF_V2";
|
||||
const unsigned char HASH_KEY_CLSAG_ROUND[] = "CLSAG_round";
|
||||
const unsigned char HASH_KEY_CLSAG_AGG_0[] = "CLSAG_agg_0";
|
||||
const unsigned char HASH_KEY_CLSAG_AGG_1[] = "CLSAG_agg_1";
|
||||
const char HASH_KEY_MESSAGE_SIGNING[] = "TownforgeMessageSignature";
|
||||
const unsigned char HASH_KEY_MM_SLOT = 'm';
|
||||
|
||||
namespace testnet
|
||||
{
|
||||
|
@ -58,6 +58,7 @@
|
||||
#include "common/notify.h"
|
||||
#include "common/varint.h"
|
||||
#include "common/pruning.h"
|
||||
#include "time_helper.h"
|
||||
#include "cc/cc.h"
|
||||
#include "cc/cc_game_update.h"
|
||||
|
||||
@ -1031,7 +1032,7 @@ start:
|
||||
std::pair<bool, uint64_t> Blockchain::check_difficulty_checkpoints() const
|
||||
{
|
||||
uint64_t res = 0;
|
||||
for (const std::pair<uint64_t, difficulty_type>& i : m_checkpoints.get_difficulty_points())
|
||||
for (const std::pair<const uint64_t, difficulty_type>& i : m_checkpoints.get_difficulty_points())
|
||||
{
|
||||
if (i.first >= m_db->height())
|
||||
break;
|
||||
@ -3593,7 +3594,6 @@ bool Blockchain::check_tx_inputs(transaction& tx, tx_verification_context &tvc,
|
||||
bool failed = false;
|
||||
for (size_t i = 0; i < tx.vin.size(); i++)
|
||||
{
|
||||
const txin_to_key& in_to_key = boost::get<txin_to_key>(tx.vin[i]);
|
||||
if(!failed && !results[i])
|
||||
failed = true;
|
||||
}
|
||||
|
@ -61,6 +61,8 @@ using namespace epee;
|
||||
#include "cc/cc_command_handler_new_item.h"
|
||||
#include "version.h"
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "cn"
|
||||
|
||||
@ -645,7 +647,7 @@ namespace cryptonote
|
||||
|
||||
void operator()(std::uint64_t, epee::span<const block> blocks) const
|
||||
{
|
||||
for (const block bl : blocks)
|
||||
for (const block& bl : blocks)
|
||||
cmdline.notify("%s", epee::string_tools::pod_to_hex(get_block_hash(bl)).c_str(), NULL);
|
||||
}
|
||||
};
|
||||
|
@ -45,10 +45,10 @@ namespace cryptonote
|
||||
typedef std::pair<uint64_t, rct::ctkey> output_entry;
|
||||
|
||||
std::vector<output_entry> outputs; //index + key + optional ringct commitment
|
||||
size_t real_output; //index in outputs vector of real output_entry
|
||||
uint64_t real_output; //index in outputs vector of real output_entry
|
||||
crypto::public_key real_out_tx_key; //incoming real tx public key
|
||||
std::vector<crypto::public_key> real_out_additional_tx_keys; //incoming real tx additional public keys
|
||||
size_t real_output_in_tx_index; //index in transaction outputs vector
|
||||
uint64_t real_output_in_tx_index; //index in transaction outputs vector
|
||||
uint64_t amount; //money
|
||||
bool rct; //true if the output is rct
|
||||
rct::key mask; //ringct amount mask
|
||||
|
@ -620,7 +620,6 @@ namespace cryptonote
|
||||
bool tx_memory_pool::add_tx(transaction &tx, tx_verification_context& tvc, relay_method tx_relay, bool relayed, uint8_t version)
|
||||
{
|
||||
crypto::hash h = null_hash;
|
||||
size_t blob_size = 0;
|
||||
cryptonote::blobdata bl;
|
||||
t_serializable_object_to_blob(tx, bl);
|
||||
if (bl.size() == 0 || !get_transaction_hash(tx, h))
|
||||
@ -1907,7 +1906,6 @@ namespace cryptonote
|
||||
return true;
|
||||
}, true, category);
|
||||
|
||||
txpool_tx_meta_t meta;
|
||||
for (const key_images_container::value_type& kee : m_spent_key_images) {
|
||||
const crypto::key_image& k_image = kee.first;
|
||||
const std::unordered_set<crypto::hash>& kei_image_set = kee.second;
|
||||
|
@ -46,6 +46,8 @@
|
||||
#include "block_queue.h"
|
||||
#include "common/perf_timer.h"
|
||||
#include "cryptonote_basic/connection_context.h"
|
||||
#include "net/levin_base.h"
|
||||
#include "p2p/net_node_common.h"
|
||||
#include <boost/circular_buffer.hpp>
|
||||
|
||||
PUSH_WARNINGS
|
||||
@ -195,10 +197,11 @@ namespace cryptonote
|
||||
bool post_notify(typename t_parameter::request& arg, cryptonote_connection_context& context)
|
||||
{
|
||||
LOG_PRINT_L2("[" << epee::net_utils::print_connection_context_short(context) << "] post " << typeid(t_parameter).name() << " -->");
|
||||
epee::byte_slice blob;
|
||||
epee::serialization::store_t_to_binary(arg, blob, 256 * 1024); // optimize for block responses
|
||||
|
||||
epee::levin::message_writer out{256 * 1024}; // optimize for block responses
|
||||
epee::serialization::store_t_to_binary(arg, out.buffer);
|
||||
//handler_response_blocks_now(blob.size()); // XXX
|
||||
return m_p2p->invoke_notify_to_peer(t_parameter::ID, epee::to_span(blob), context);
|
||||
return m_p2p->invoke_notify_to_peer(t_parameter::ID, std::move(out), context);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -137,6 +137,41 @@ namespace cryptonote
|
||||
CHECK_AND_ASSERT_MES_CC( context.m_callback_request_count > 0, false, "false callback fired, but context.m_callback_request_count=" << context.m_callback_request_count);
|
||||
--context.m_callback_request_count;
|
||||
|
||||
uint32_t notified = true;
|
||||
if (context.m_idle_peer_notification.compare_exchange_strong(notified, not notified))
|
||||
{
|
||||
if (context.m_state == cryptonote_connection_context::state_synchronizing && context.m_last_request_time != boost::date_time::not_a_date_time)
|
||||
{
|
||||
const boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time();
|
||||
const boost::posix_time::time_duration dt = now - context.m_last_request_time;
|
||||
const auto ms = dt.total_microseconds();
|
||||
if (ms > IDLE_PEER_KICK_TIME || (context.m_expect_response && ms > NON_RESPONSIVE_PEER_KICK_TIME))
|
||||
{
|
||||
if (context.m_score-- >= 0)
|
||||
{
|
||||
MINFO(context << " kicking idle peer, last update " << (dt.total_microseconds() / 1.e6) << " seconds ago, expecting " << (int)context.m_expect_response);
|
||||
context.m_last_request_time = boost::date_time::not_a_date_time;
|
||||
context.m_expect_response = 0;
|
||||
context.m_expect_height = 0;
|
||||
context.m_state = cryptonote_connection_context::state_standby; // we'll go back to adding, then (if we can't), download
|
||||
}
|
||||
else
|
||||
{
|
||||
MINFO(context << "dropping idle peer with negative score");
|
||||
drop_connection_with_score(context, context.m_expect_response == 0 ? 1 : 5, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
notified = true;
|
||||
if (context.m_new_stripe_notification.compare_exchange_strong(notified, not notified))
|
||||
{
|
||||
if (context.m_state == cryptonote_connection_context::state_normal)
|
||||
context.m_state = cryptonote_connection_context::state_synchronizing;
|
||||
}
|
||||
|
||||
if(context.m_state == cryptonote_connection_context::state_synchronizing && context.m_last_request_time == boost::posix_time::not_a_date_time)
|
||||
{
|
||||
NOTIFY_REQUEST_CHAIN::request r = {};
|
||||
@ -338,10 +373,6 @@ namespace cryptonote
|
||||
}
|
||||
context.m_remote_blockchain_height = hshd.current_height;
|
||||
context.m_pruning_seed = hshd.pruning_seed;
|
||||
#ifdef CRYPTONOTE_PRUNING_DEBUG_SPOOF_SEED
|
||||
context.m_pruning_seed = tools::make_pruning_seed(1 + (context.m_remote_address.as<epee::net_utils::ipv4_network_address>().ip()) % (1 << CRYPTONOTE_PRUNING_LOG_STRIPES), CRYPTONOTE_PRUNING_LOG_STRIPES);
|
||||
LOG_INFO_CC(context, "New connection posing as pruning seed " << epee::string_tools::to_string_hex(context.m_pruning_seed) << ", seed address " << &context.m_pruning_seed);
|
||||
#endif
|
||||
|
||||
uint64_t target = m_core.get_target_blockchain_height();
|
||||
if (target == 0)
|
||||
@ -1707,7 +1738,7 @@ skip:
|
||||
const uint32_t peer_stripe = tools::get_pruning_stripe(context.m_pruning_seed);
|
||||
if (stripe && peer_stripe && peer_stripe != stripe)
|
||||
return true;
|
||||
context.m_state = cryptonote_connection_context::state_synchronizing;
|
||||
context.m_new_stripe_notification = true;
|
||||
LOG_PRINT_CCONTEXT_L2("requesting callback");
|
||||
++context.m_callback_request_count;
|
||||
m_p2p->request_callback(context);
|
||||
@ -1730,7 +1761,6 @@ skip:
|
||||
bool t_cryptonote_protocol_handler<t_core>::kick_idle_peers()
|
||||
{
|
||||
MTRACE("Checking for idle peers...");
|
||||
std::vector<std::pair<boost::uuids::uuid, unsigned>> idle_peers;
|
||||
m_p2p->for_each_connection([&](cryptonote_connection_context& context, nodetool::peerid_type peer_id, uint32_t support_flags)->bool
|
||||
{
|
||||
if (context.m_state == cryptonote_connection_context::state_synchronizing && context.m_last_request_time != boost::date_time::not_a_date_time)
|
||||
@ -1740,36 +1770,16 @@ skip:
|
||||
const auto ms = dt.total_microseconds();
|
||||
if (ms > IDLE_PEER_KICK_TIME || (context.m_expect_response && ms > NON_RESPONSIVE_PEER_KICK_TIME))
|
||||
{
|
||||
if (context.m_score-- >= 0)
|
||||
{
|
||||
MINFO(context << " kicking idle peer, last update " << (dt.total_microseconds() / 1.e6) << " seconds ago, expecting " << (int)context.m_expect_response);
|
||||
LOG_PRINT_CCONTEXT_L2("requesting callback");
|
||||
context.m_last_request_time = boost::date_time::not_a_date_time;
|
||||
context.m_expect_response = 0;
|
||||
context.m_expect_height = 0;
|
||||
context.m_state = cryptonote_connection_context::state_standby; // we'll go back to adding, then (if we can't), download
|
||||
++context.m_callback_request_count;
|
||||
m_p2p->request_callback(context);
|
||||
}
|
||||
else
|
||||
{
|
||||
idle_peers.push_back(std::make_pair(context.m_connection_id, context.m_expect_response == 0 ? 1 : 5));
|
||||
}
|
||||
context.m_idle_peer_notification = true;
|
||||
LOG_PRINT_CCONTEXT_L2("requesting callback");
|
||||
++context.m_callback_request_count;
|
||||
m_p2p->request_callback(context);
|
||||
MLOG_PEER_STATE("requesting callback");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
for (const auto &e: idle_peers)
|
||||
{
|
||||
const auto &uuid = e.first;
|
||||
m_p2p->for_connection(uuid, [&](cryptonote_connection_context& ctx, nodetool::peerid_type peer_id, uint32_t f)->bool{
|
||||
MINFO(ctx << "dropping idle peer with negative score");
|
||||
drop_connection_with_score(ctx, e.second, false);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------
|
||||
@ -1865,10 +1875,8 @@ skip:
|
||||
bool t_cryptonote_protocol_handler<t_core>::should_download_next_span(cryptonote_connection_context& context, bool standby)
|
||||
{
|
||||
std::vector<crypto::hash> hashes;
|
||||
boost::uuids::uuid span_connection_id;
|
||||
boost::posix_time::ptime request_time;
|
||||
boost::uuids::uuid connection_id;
|
||||
std::pair<uint64_t, uint64_t> span;
|
||||
bool filled;
|
||||
|
||||
const uint64_t blockchain_height = m_core.get_current_blockchain_height();
|
||||
@ -1894,7 +1902,6 @@ skip:
|
||||
|
||||
// in standby, be ready to double download early since we're idling anyway
|
||||
// let the fastest peer trigger first
|
||||
long threshold;
|
||||
const double dl_speed = context.m_max_speed_down;
|
||||
if (standby && dt >= REQUEST_NEXT_SCHEDULED_SPAN_THRESHOLD_STANDBY && dl_speed > 0)
|
||||
{
|
||||
@ -2722,15 +2729,15 @@ skip:
|
||||
// send fluffy ones first, we want to encourage people to run that
|
||||
if (!fluffyConnections.empty())
|
||||
{
|
||||
epee::byte_slice fluffyBlob;
|
||||
epee::serialization::store_t_to_binary(fluffy_arg, fluffyBlob, 32 * 1024);
|
||||
m_p2p->relay_notify_to_list(NOTIFY_NEW_FLUFFY_BLOCK::ID, epee::to_span(fluffyBlob), std::move(fluffyConnections));
|
||||
epee::levin::message_writer fluffyBlob{32 * 1024};
|
||||
epee::serialization::store_t_to_binary(fluffy_arg, fluffyBlob.buffer);
|
||||
m_p2p->relay_notify_to_list(NOTIFY_NEW_FLUFFY_BLOCK::ID, std::move(fluffyBlob), std::move(fluffyConnections));
|
||||
}
|
||||
if (!fullConnections.empty())
|
||||
{
|
||||
epee::byte_slice fullBlob;
|
||||
epee::serialization::store_t_to_binary(arg, fullBlob, 128 * 1024);
|
||||
m_p2p->relay_notify_to_list(NOTIFY_NEW_BLOCK::ID, epee::to_span(fullBlob), std::move(fullConnections));
|
||||
epee::levin::message_writer fullBlob{128 * 1024};
|
||||
epee::serialization::store_t_to_binary(arg, fullBlob.buffer);
|
||||
m_p2p->relay_notify_to_list(NOTIFY_NEW_BLOCK::ID, std::move(fullBlob), std::move(fullConnections));
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -2863,15 +2870,12 @@ skip:
|
||||
epee::string_tools::to_string_hex(context.m_pruning_seed) <<
|
||||
"), score " << score << ", flush_all_spans " << flush_all_spans);
|
||||
|
||||
if (score > 0)
|
||||
m_p2p->add_host_fail(context.m_remote_address, score);
|
||||
|
||||
m_block_queue.flush_spans(context.m_connection_id, flush_all_spans);
|
||||
|
||||
// copy since dropping the connection will invalidate the context, and thus the address
|
||||
const auto remote_address = context.m_remote_address;
|
||||
|
||||
m_p2p->drop_connection(context);
|
||||
|
||||
if (score > 0)
|
||||
m_p2p->add_host_fail(remote_address, score);
|
||||
}
|
||||
//------------------------------------------------------------------------------------------------------------------------
|
||||
template<class t_core>
|
||||
|
@ -30,8 +30,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "p2p/net_node_common.h"
|
||||
#include "cryptonote_protocol/cryptonote_protocol_defs.h"
|
||||
#include "cryptonote_protocol/enums.h"
|
||||
#include "cryptonote_basic/connection_context.h"
|
||||
namespace cryptonote
|
||||
{
|
||||
|
@ -159,7 +159,7 @@ namespace levin
|
||||
return get_out_connections(p2p, get_blockchain_height(p2p, core));
|
||||
}
|
||||
|
||||
epee::byte_slice make_tx_payload(std::vector<blobdata>&& txs, const bool pad, const bool fluff)
|
||||
epee::levin::message_writer make_tx_message(std::vector<blobdata>&& txs, const bool pad, const bool fluff)
|
||||
{
|
||||
NOTIFY_NEW_TRANSACTIONS::request request{};
|
||||
request.txs = std::move(txs);
|
||||
@ -193,21 +193,17 @@ namespace levin
|
||||
// if the size of _ moved enough, we might lose byte in size encoding, we don't care
|
||||
}
|
||||
|
||||
epee::byte_slice fullBlob;
|
||||
if (!epee::serialization::store_t_to_binary(request, fullBlob))
|
||||
epee::levin::message_writer out;
|
||||
if (!epee::serialization::store_t_to_binary(request, out.buffer))
|
||||
throw std::runtime_error{"Failed to serialize to epee binary format"};
|
||||
|
||||
return fullBlob;
|
||||
return out;
|
||||
}
|
||||
|
||||
bool make_payload_send_txs(connections& p2p, std::vector<blobdata>&& txs, const boost::uuids::uuid& destination, const bool pad, const bool fluff)
|
||||
{
|
||||
const epee::byte_slice blob = make_tx_payload(std::move(txs), pad, fluff);
|
||||
p2p.for_connection(destination, [&blob](detail::p2p_context& context) {
|
||||
on_levin_traffic(context, true, true, false, blob.size(), NOTIFY_NEW_TRANSACTIONS::ID);
|
||||
return true;
|
||||
});
|
||||
return p2p.notify(NOTIFY_NEW_TRANSACTIONS::ID, epee::to_span(blob), destination);
|
||||
epee::byte_slice blob = make_tx_message(std::move(txs), pad, fluff).finalize_notify(NOTIFY_NEW_TRANSACTIONS::ID);
|
||||
return p2p.send(std::move(blob), destination);
|
||||
}
|
||||
|
||||
/* The current design uses `asio::strand`s. The documentation isn't as clear
|
||||
@ -653,10 +649,6 @@ namespace levin
|
||||
else
|
||||
message = zone_->noise.clone();
|
||||
|
||||
zone_->p2p->for_connection(channel.connection, [&](detail::p2p_context& context) {
|
||||
on_levin_traffic(context, true, true, false, message.size(), "noise");
|
||||
return true;
|
||||
});
|
||||
if (zone_->p2p->send(std::move(message), channel.connection))
|
||||
{
|
||||
if (!channel.queue.empty() && channel.active.empty())
|
||||
@ -816,9 +808,8 @@ namespace levin
|
||||
|
||||
// Padding is not useful when using noise mode. Send as stem so receiver
|
||||
// forwards in Dandelion++ mode.
|
||||
const epee::byte_slice payload = make_tx_payload(std::move(txs), false, false);
|
||||
epee::byte_slice message = epee::levin::make_fragmented_notify(
|
||||
zone_->noise, NOTIFY_NEW_TRANSACTIONS::ID, epee::to_span(payload)
|
||||
zone_->noise.size(), NOTIFY_NEW_TRANSACTIONS::ID, make_tx_message(std::move(txs), false, false)
|
||||
);
|
||||
if (CRYPTONOTE_MAX_FRAGMENTS * zone_->noise.size() < message.size())
|
||||
{
|
||||
|
@ -30,6 +30,8 @@
|
||||
#include "common/command_line.h"
|
||||
#include "net/parse.h"
|
||||
#include "daemon/command_parser_executor.h"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
#define MONERO_DEFAULT_LOG_CATEGORY "daemon"
|
||||
@ -1015,17 +1017,67 @@ bool t_command_parser_executor::check_blockchain_pruning(const std::vector<std::
|
||||
|
||||
bool t_command_parser_executor::set_bootstrap_daemon(const std::vector<std::string>& args)
|
||||
{
|
||||
const size_t args_count = args.size();
|
||||
if (args_count < 1 || args_count > 3)
|
||||
struct parsed_t
|
||||
{
|
||||
std::string address;
|
||||
std::string user;
|
||||
std::string password;
|
||||
std::string proxy;
|
||||
};
|
||||
|
||||
boost::optional<parsed_t> parsed = [&args]() -> boost::optional<parsed_t> {
|
||||
const size_t args_count = args.size();
|
||||
if (args_count == 0)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
if (args[0] == "auto")
|
||||
{
|
||||
if (args_count == 1)
|
||||
{
|
||||
return {{args[0], "", "", ""}};
|
||||
}
|
||||
if (args_count == 2)
|
||||
{
|
||||
return {{args[0], "", "", args[1]}};
|
||||
}
|
||||
}
|
||||
else if (args[0] == "none")
|
||||
{
|
||||
if (args_count == 1)
|
||||
{
|
||||
return {{"", "", "", ""}};
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (args_count == 1)
|
||||
{
|
||||
return {{args[0], "", "", ""}};
|
||||
}
|
||||
if (args_count == 2)
|
||||
{
|
||||
return {{args[0], "", "", args[1]}};
|
||||
}
|
||||
if (args_count == 3)
|
||||
{
|
||||
return {{args[0], args[1], args[2], ""}};
|
||||
}
|
||||
if (args_count == 4)
|
||||
{
|
||||
return {{args[0], args[1], args[2], args[3]}};
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}();
|
||||
|
||||
if (!parsed)
|
||||
{
|
||||
std::cout << "Invalid syntax: Wrong number of parameters. For more details, use the help command." << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
return m_executor.set_bootstrap_daemon(
|
||||
args[0] != "none" ? args[0] : std::string(),
|
||||
args_count > 1 ? args[1] : std::string(),
|
||||
args_count > 2 ? args[2] : std::string());
|
||||
return m_executor.set_bootstrap_daemon(parsed->address, parsed->user, parsed->password, parsed->proxy);
|
||||
}
|
||||
|
||||
bool t_command_parser_executor::flush_cache(const std::vector<std::string>& args)
|
||||
|
@ -331,7 +331,7 @@ t_command_server::t_command_server(
|
||||
m_command_lookup.set_handler(
|
||||
"set_bootstrap_daemon"
|
||||
, std::bind(&t_command_parser_executor::set_bootstrap_daemon, &m_parser, p::_1)
|
||||
, "set_bootstrap_daemon (auto | none | host[:port] [username] [password])"
|
||||
, "set_bootstrap_daemon (auto | none | host[:port] [username] [password]) [proxy_ip:proxy_port]"
|
||||
, "URL of a 'bootstrap' remote daemon that the connected wallets can use while this daemon is still not fully synced.\n"
|
||||
"Use 'auto' to enable automatic public nodes discovering and bootstrap daemon switching"
|
||||
);
|
||||
|
@ -1077,7 +1077,6 @@ bool t_rpc_command_executor::print_transaction(crypto::hash transaction_hash,
|
||||
// Print json if requested
|
||||
if (include_json)
|
||||
{
|
||||
crypto::hash tx_hash, tx_prefix_hash;
|
||||
cryptonote::transaction tx;
|
||||
cryptonote::blobdata blob;
|
||||
std::string source = as_hex.empty() ? pruned_as_hex + prunable_as_hex : as_hex;
|
||||
@ -2504,7 +2503,8 @@ bool t_rpc_command_executor::check_blockchain_pruning()
|
||||
bool t_rpc_command_executor::set_bootstrap_daemon(
|
||||
const std::string &address,
|
||||
const std::string &username,
|
||||
const std::string &password)
|
||||
const std::string &password,
|
||||
const std::string &proxy)
|
||||
{
|
||||
cryptonote::COMMAND_RPC_SET_BOOTSTRAP_DAEMON::request req;
|
||||
cryptonote::COMMAND_RPC_SET_BOOTSTRAP_DAEMON::response res;
|
||||
@ -2513,6 +2513,7 @@ bool t_rpc_command_executor::set_bootstrap_daemon(
|
||||
req.address = address;
|
||||
req.username = username;
|
||||
req.password = password;
|
||||
req.proxy = proxy;
|
||||
|
||||
if (m_is_rpc)
|
||||
{
|
||||
|
@ -170,7 +170,8 @@ public:
|
||||
bool set_bootstrap_daemon(
|
||||
const std::string &address,
|
||||
const std::string &username,
|
||||
const std::string &password);
|
||||
const std::string &password,
|
||||
const std::string &proxy);
|
||||
|
||||
bool rpc_payments();
|
||||
|
||||
|
@ -131,7 +131,7 @@ int main(int argc, char* argv[])
|
||||
|
||||
lookup(LOOKUP_A, {"seeds.moneroseeds.se", "seeds.moneroseeds.ae.org", "seeds.moneroseeds.ch", "seeds.moneroseeds.li"});
|
||||
|
||||
lookup(LOOKUP_TXT, {"updates.moneropulse.org", "updates.moneropulse.net", "updates.moneropulse.co", "updates.moneropulse.se"});
|
||||
lookup(LOOKUP_TXT, {"updates.moneropulse.org", "updates.moneropulse.net", "updates.moneropulse.co", "updates.moneropulse.se", "updates.moneropulse.fr", "updates.moneropulse.de", "updates.moneropulse.no", "updates.moneropulse.ch"});
|
||||
|
||||
lookup(LOOKUP_TXT, {"checkpoints.moneropulse.org", "checkpoints.moneropulse.net", "checkpoints.moneropulse.co", "checkpoints.moneropulse.se"});
|
||||
|
||||
|
@ -181,7 +181,6 @@ namespace hw {
|
||||
unsigned char padding_buffer[MAX_BLOCK+1];
|
||||
unsigned int result;
|
||||
int hid_ret;
|
||||
unsigned int sw_offset;
|
||||
unsigned int remaining;
|
||||
unsigned int offset = 0;
|
||||
|
||||
|
@ -28,6 +28,8 @@
|
||||
//
|
||||
|
||||
#include "device_trezor.hpp"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
|
||||
namespace hw {
|
||||
namespace trezor {
|
||||
|
@ -31,6 +31,7 @@
|
||||
#include "memwipe.h"
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include <boost/regex.hpp>
|
||||
|
||||
namespace hw {
|
||||
@ -365,15 +366,14 @@ namespace trezor {
|
||||
void device_trezor_base::device_state_initialize_unsafe()
|
||||
{
|
||||
require_connected();
|
||||
std::string tmp_session_id;
|
||||
auto initMsg = std::make_shared<messages::management::Initialize>();
|
||||
const auto data_cleaner = epee::misc_utils::create_scope_leave_handler([&]() {
|
||||
memwipe(&tmp_session_id[0], tmp_session_id.size());
|
||||
if (initMsg->has_session_id())
|
||||
memwipe(&(*initMsg->mutable_session_id())[0], initMsg->mutable_session_id()->size());
|
||||
});
|
||||
|
||||
if(!m_device_session_id.empty()) {
|
||||
tmp_session_id.assign(m_device_session_id.data(), m_device_session_id.size());
|
||||
initMsg->set_allocated_session_id(&tmp_session_id);
|
||||
initMsg->set_allocated_session_id(new std::string(m_device_session_id.data(), m_device_session_id.size()));
|
||||
}
|
||||
|
||||
m_features = this->client_exchange<messages::management::Features>(initMsg);
|
||||
@ -382,8 +382,6 @@ namespace trezor {
|
||||
} else {
|
||||
m_device_session_id.clear();
|
||||
}
|
||||
|
||||
initMsg->release_session_id();
|
||||
}
|
||||
|
||||
void device_trezor_base::device_state_reset()
|
||||
@ -453,18 +451,14 @@ namespace trezor {
|
||||
pin = m_pin;
|
||||
}
|
||||
|
||||
std::string pin_field;
|
||||
messages::common::PinMatrixAck m;
|
||||
if (pin) {
|
||||
pin_field.assign(pin->data(), pin->size());
|
||||
m.set_allocated_pin(&pin_field);
|
||||
m.set_allocated_pin(new std::string(pin->data(), pin->size()));
|
||||
}
|
||||
|
||||
const auto data_cleaner = epee::misc_utils::create_scope_leave_handler([&]() {
|
||||
m.release_pin();
|
||||
if (!pin_field.empty()){
|
||||
memwipe(&pin_field[0], pin_field.size());
|
||||
}
|
||||
if (m.has_pin())
|
||||
memwipe(&(*m.mutable_pin())[0], m.mutable_pin()->size());
|
||||
});
|
||||
|
||||
resp = call_raw(&m);
|
||||
@ -499,7 +493,6 @@ namespace trezor {
|
||||
boost::optional<epee::wipeable_string> passphrase;
|
||||
TREZOR_CALLBACK_GET(passphrase, on_passphrase_request, on_device);
|
||||
|
||||
std::string passphrase_field;
|
||||
messages::common::PassphraseAck m;
|
||||
m.set_on_device(on_device);
|
||||
if (!on_device) {
|
||||
@ -512,16 +505,13 @@ namespace trezor {
|
||||
}
|
||||
|
||||
if (passphrase) {
|
||||
passphrase_field.assign(passphrase->data(), passphrase->size());
|
||||
m.set_allocated_passphrase(&passphrase_field);
|
||||
m.set_allocated_passphrase(new std::string(passphrase->data(), passphrase->size()));
|
||||
}
|
||||
}
|
||||
|
||||
const auto data_cleaner = epee::misc_utils::create_scope_leave_handler([&]() {
|
||||
m.release_passphrase();
|
||||
if (!passphrase_field.empty()){
|
||||
memwipe(&passphrase_field[0], passphrase_field.size());
|
||||
}
|
||||
if (m.has_passphrase())
|
||||
memwipe(&(m.mutable_passphrase())[0], m.mutable_passphrase()->size());
|
||||
});
|
||||
|
||||
resp = call_raw(&m);
|
||||
|
@ -165,7 +165,7 @@ namespace trezor {
|
||||
|
||||
// Scoped session closer
|
||||
BOOST_SCOPE_EXIT_ALL(&, this) {
|
||||
if (open_session){
|
||||
if (open_session && this->get_transport()){
|
||||
this->get_transport()->close();
|
||||
}
|
||||
};
|
||||
|
@ -502,21 +502,9 @@ namespace tx {
|
||||
}
|
||||
|
||||
void Signer::compute_integrated_indices(TsxData * tsx_data){
|
||||
if (m_aux_data == nullptr || m_aux_data->tx_recipients.empty()){
|
||||
return;
|
||||
}
|
||||
|
||||
auto & chg = tsx_data->change_dts();
|
||||
std::string change_hash = hash_addr(&chg.addr(), chg.amount(), chg.is_subaddress());
|
||||
|
||||
std::vector<uint32_t> integrated_indices;
|
||||
std::set<std::string> integrated_hashes;
|
||||
for (auto & cur : m_aux_data->tx_recipients){
|
||||
if (!cur.has_payment_id){
|
||||
continue;
|
||||
}
|
||||
integrated_hashes.emplace(hash_addr(&cur.address.m_spend_public_key, &cur.address.m_view_public_key));
|
||||
}
|
||||
|
||||
ssize_t idx = -1;
|
||||
for (auto & cur : tsx_data->outputs()){
|
||||
@ -527,8 +515,7 @@ namespace tx {
|
||||
continue;
|
||||
}
|
||||
|
||||
c_hash = hash_addr(&cur.addr());
|
||||
if (integrated_hashes.find(c_hash) != integrated_hashes.end()){
|
||||
if (cur.is_integrated()){
|
||||
integrated_indices.push_back((uint32_t)idx);
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include <boost/asio/ip/udp.hpp>
|
||||
#include <boost/date_time/posix_time/posix_time_types.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/algorithm/string/predicate.hpp>
|
||||
#include "common/apply_permutation.h"
|
||||
#include "transport.hpp"
|
||||
#include "messages/messages-common.pb.h"
|
||||
|
@ -165,7 +165,7 @@ DaemonController::DaemonController(const std::string &path):
|
||||
path(path),
|
||||
controlling(false)
|
||||
{
|
||||
daemon.reset(new cryptonote::bootstrap_daemon(DAEMON_ADDRESS, {}, false));
|
||||
daemon.reset(new cryptonote::bootstrap_daemon(DAEMON_ADDRESS, {}, false, ""));
|
||||
}
|
||||
|
||||
std::string DaemonController::FindDaemonBinary() const
|
||||
|
@ -4,7 +4,8 @@
|
||||
} \
|
||||
while(0)
|
||||
|
||||
#include <boost/algorithm/string/join.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <Urho3D/Core/CoreEvents.h>
|
||||
#include <Urho3D/Core/Thread.h>
|
||||
#include <Urho3D/Scene/Node.h>
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user