aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'contrib')
-rw-r--r--contrib/depends/Makefile18
-rw-r--r--contrib/depends/README.md14
-rw-r--r--contrib/depends/config.site.in19
-rw-r--r--contrib/depends/packages/bdb.mk31
-rw-r--r--contrib/depends/packages/ldns.mk2
-rw-r--r--contrib/depends/packages/libICE.mk2
-rw-r--r--contrib/depends/packages/libSM.mk2
-rw-r--r--contrib/depends/packages/libusb.mk8
-rw-r--r--contrib/depends/packages/miniupnpc.mk28
-rw-r--r--contrib/depends/packages/native_cdrkit.mk2
-rw-r--r--contrib/depends/packages/packages.mk2
-rw-r--r--contrib/depends/packages/qt.mk2
-rw-r--r--contrib/depends/packages/unbound.mk2
-rw-r--r--contrib/depends/packages/unwind.mk2
-rw-r--r--contrib/depends/packages/xproto.mk2
-rw-r--r--contrib/depends/packages/zlib.mk2
-rw-r--r--contrib/epee/include/int-util.h258
-rw-r--r--contrib/epee/include/misc_os_dependent.h9
-rw-r--r--contrib/epee/include/mlocker.h2
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.h4
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.inl18
-rw-r--r--contrib/epee/include/net/connection_basic.hpp13
-rw-r--r--contrib/epee/include/net/http_server_impl_base.h3
-rw-r--r--contrib/epee/include/net/levin_client.inl41
-rw-r--r--contrib/epee/include/net/levin_helper.h41
-rw-r--r--contrib/epee/include/net/levin_protocol_handler.h19
-rw-r--r--contrib/epee/include/net/levin_protocol_handler_async.h60
-rw-r--r--contrib/epee/include/span.h2
-rw-r--r--contrib/epee/include/storages/portable_storage.h9
-rw-r--r--contrib/epee/include/string_tools.h50
-rw-r--r--contrib/epee/src/connection_basic.cpp33
-rw-r--r--contrib/epee/src/mlocker.cpp31
-rw-r--r--contrib/epee/src/mlog.cpp8
-rw-r--r--contrib/epee/src/net_utils_base.cpp2
-rw-r--r--contrib/epee/src/network_throttle-detail.cpp16
-rw-r--r--contrib/epee/src/readline_buffer.cpp4
-rw-r--r--contrib/epee/tests/src/net/test_net.h4
-rw-r--r--contrib/valgrind/monero.supp9
38 files changed, 490 insertions, 284 deletions
diff --git a/contrib/depends/Makefile b/contrib/depends/Makefile
index b0c032c09..bf33d706d 100644
--- a/contrib/depends/Makefile
+++ b/contrib/depends/Makefile
@@ -3,9 +3,6 @@
SOURCES_PATH ?= $(BASEDIR)/sources
BASE_CACHE ?= $(BASEDIR)/built
SDK_PATH ?= $(BASEDIR)/SDKs
-NO_QT ?=
-NO_WALLET ?=
-NO_UPNP ?=
FALLBACK_DOWNLOAD_PATH ?= https://bitcoincore.org/depends-sources
BUILD = $(shell ./config.guess)
@@ -97,17 +94,10 @@ $(host_arch)_$(host_os)_id_string+=$(shell $(host_CXX) --version 2>/dev/null)
$(host_arch)_$(host_os)_id_string+=$(shell $(host_RANLIB) --version 2>/dev/null)
$(host_arch)_$(host_os)_id_string+=$(shell $(host_STRIP) --version 2>/dev/null)
-qt_packages_$(NO_QT) = $(qt_packages) $(qt_$(host_os)_packages) $(qt_$(host_arch)_$(host_os)_packages)
-wallet_packages_$(NO_WALLET) = $(wallet_packages)
-upnp_packages_$(NO_UPNP) = $(upnp_packages)
-packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages) $(qt_packages_) $(wallet_packages_) $(upnp_packages_)
+packages += $($(host_arch)_$(host_os)_packages) $($(host_os)_packages)
native_packages += $($(host_arch)_$(host_os)_native_packages) $($(host_os)_native_packages)
-ifneq ($(qt_packages_),)
-native_packages += $(qt_native_packages)
-endif
-
all_packages = $(packages) $(native_packages)
meta_depends = Makefile funcs.mk builders/default.mk hosts/default.mk hosts/$(host_os).mk builders/$(build_os).mk
@@ -153,9 +143,6 @@ $(host_prefix)/share/config.site : config.site.in $(host_prefix)/.stamp_$(final_
-e 's|@CPPFLAGS@|$(strip $(host_CPPFLAGS) $(host_$(release_type)_CPPFLAGS))|' \
-e 's|@LDFLAGS@|$(strip $(host_LDFLAGS) $(host_$(release_type)_LDFLAGS))|' \
-e 's|@allow_host_packages@|$(ALLOW_HOST_PACKAGES)|' \
- -e 's|@no_qt@|$(NO_QT)|' \
- -e 's|@no_wallet@|$(NO_WALLET)|' \
- -e 's|@no_upnp@|$(NO_UPNP)|' \
-e 's|@debug@|$(DEBUG)|' \
$< > $@
$(AT)touch $@
@@ -176,9 +163,6 @@ $(host_prefix)/share/toolchain.cmake : toolchain.cmake.in $(host_prefix)/.stamp_
-e 's|@CPPFLAGS@|$(strip $(host_CPPFLAGS) $(host_$(release_type)_CPPFLAGS))|' \
-e 's|@LDFLAGS@|$(strip $(host_LDFLAGS) $(host_$(release_type)_LDFLAGS))|' \
-e 's|@allow_host_packages@|$(ALLOW_HOST_PACKAGES)|' \
- -e 's|@no_qt@|$(NO_QT)|' \
- -e 's|@no_wallet@|$(NO_WALLET)|' \
- -e 's|@no_upnp@|$(NO_UPNP)|' \
-e 's|@debug@|$(DEBUG)|' \
-e 's|@depends@|$(host_cmake)|' \
-e 's|@prefix@|$($(host_arch)_$(host_os)_prefix)|'\
diff --git a/contrib/depends/README.md b/contrib/depends/README.md
index dd2824569..597398369 100644
--- a/contrib/depends/README.md
+++ b/contrib/depends/README.md
@@ -12,11 +12,11 @@ For example:
make HOST=x86_64-w64-mingw32 -j4
-A prefix will be generated that's suitable for plugging into Bitcoin's
-configure. In the above example, a dir named x86_64-w64-mingw32 will be
-created. To use it for Bitcoin:
+A toolchain will be generated that's suitable for plugging into Monero's
+cmake. In the above example, a dir named x86_64-w64-mingw32 will be
+created. To use it for Monero:
- ./configure --prefix=`pwd`/depends/x86_64-w64-mingw32
+ cmake -DCMAKE_TOOLCHAIN=`pwd`/contrib/depends/x86_64-w64-mingw32
Common `host-platform-triplets` for cross compilation are:
@@ -35,16 +35,10 @@ The following can be set when running make: make FOO=bar
BASE_CACHE: built packages will be placed here
SDK_PATH: Path where sdk's can be found (used by OSX)
FALLBACK_DOWNLOAD_PATH: If a source file can't be fetched, try here before giving up
- NO_QT: Don't download/build/cache qt and its dependencies
- NO_WALLET: Don't download/build/cache libs needed to enable the wallet
- NO_UPNP: Don't download/build/cache packages needed for enabling upnp
DEBUG: disable some optimizations and enable more runtime checking
HOST_ID_SALT: Optional salt to use when generating host package ids
BUILD_ID_SALT: Optional salt to use when generating build package ids
-If some packages are not built, for example `make NO_WALLET=1`, the appropriate
-options will be passed to bitcoin's configure. In this case, `--disable-wallet`.
-
Additional targets:
download: run 'make download' to fetch all sources without building them
diff --git a/contrib/depends/config.site.in b/contrib/depends/config.site.in
index 0a4a9c327..dd91bcb2a 100644
--- a/contrib/depends/config.site.in
+++ b/contrib/depends/config.site.in
@@ -13,25 +13,6 @@ fi
if test -z $with_qt_translationdir; then
with_qt_translationdir=$depends_prefix/translations
fi
-if test -z $with_qt_bindir && test -z "@no_qt@"; then
- with_qt_bindir=$depends_prefix/native/bin
-fi
-if test -z $with_protoc_bindir && test -z "@no_qt@"; then
- with_protoc_bindir=$depends_prefix/native/bin
-fi
-
-
-if test -z $enable_wallet && test -n "@no_wallet@"; then
- enable_wallet=no
-fi
-
-if test -z $with_miniupnpc && test -n "@no_upnp@"; then
- with_miniupnpc=no
-fi
-
-if test -z $with_gui && test -n "@no_qt@"; then
- with_gui=no
-fi
if test x@host_os@ = xdarwin; then
BREW=no
diff --git a/contrib/depends/packages/bdb.mk b/contrib/depends/packages/bdb.mk
deleted file mode 100644
index 6c9876c2c..000000000
--- a/contrib/depends/packages/bdb.mk
+++ /dev/null
@@ -1,31 +0,0 @@
-package=bdb
-$(package)_version=4.8.30
-$(package)_download_path=http://download.oracle.com/berkeley-db
-$(package)_file_name=db-$($(package)_version).NC.tar.gz
-$(package)_sha256_hash=12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef
-$(package)_build_subdir=build_unix
-
-define $(package)_set_vars
-$(package)_config_opts=--disable-shared --enable-cxx --disable-replication
-$(package)_config_opts_mingw32=--enable-mingw
-$(package)_config_opts_linux=--with-pic
-$(package)_cxxflags=-std=c++11
-endef
-
-define $(package)_preprocess_cmds
- sed -i.old 's/__atomic_compare_exchange/__atomic_compare_exchange_db/' dbinc/atomic.h && \
- sed -i.old 's/atomic_init/atomic_init_db/' dbinc/atomic.h mp/mp_region.c mp/mp_mvcc.c mp/mp_fget.c mutex/mut_method.c mutex/mut_tas.c && \
- cp -f $(BASEDIR)/config.guess $(BASEDIR)/config.sub dist
-endef
-
-define $(package)_config_cmds
- ../dist/$($(package)_autoconf)
-endef
-
-define $(package)_build_cmds
- $(MAKE) libdb_cxx-4.8.a libdb-4.8.a
-endef
-
-define $(package)_stage_cmds
- $(MAKE) DESTDIR=$($(package)_staging_dir) install_lib install_include
-endef
diff --git a/contrib/depends/packages/ldns.mk b/contrib/depends/packages/ldns.mk
index a9565a581..0b7c3806a 100644
--- a/contrib/depends/packages/ldns.mk
+++ b/contrib/depends/packages/ldns.mk
@@ -1,6 +1,6 @@
package=ldns
$(package)_version=1.6.17
-$(package)_download_path=http://www.nlnetlabs.nl/downloads/ldns/
+$(package)_download_path=https://www.nlnetlabs.nl/downloads/ldns/
$(package)_file_name=$(package)-$($(package)_version).tar.gz
$(package)_sha256_hash=8b88e059452118e8949a2752a55ce59bc71fa5bc414103e17f5b6b06f9bcc8cd
$(package)_dependencies=openssl
diff --git a/contrib/depends/packages/libICE.mk b/contrib/depends/packages/libICE.mk
index fc60323b1..a897d9aed 100644
--- a/contrib/depends/packages/libICE.mk
+++ b/contrib/depends/packages/libICE.mk
@@ -1,6 +1,6 @@
package=libICE
$(package)_version=1.0.9
-$(package)_download_path=http://xorg.freedesktop.org/releases/individual/lib/
+$(package)_download_path=https://xorg.freedesktop.org/releases/individual/lib/
$(package)_file_name=$(package)-$($(package)_version).tar.bz2
$(package)_sha256_hash=8f7032f2c1c64352b5423f6b48a8ebdc339cc63064af34d66a6c9aa79759e202
$(package)_dependencies=xtrans xproto
diff --git a/contrib/depends/packages/libSM.mk b/contrib/depends/packages/libSM.mk
index 0f9307ca7..83fcd4cdb 100644
--- a/contrib/depends/packages/libSM.mk
+++ b/contrib/depends/packages/libSM.mk
@@ -1,6 +1,6 @@
package=libSM
$(package)_version=1.2.2
-$(package)_download_path=http://xorg.freedesktop.org/releases/individual/lib/
+$(package)_download_path=https://xorg.freedesktop.org/releases/individual/lib/
$(package)_file_name=$(package)-$($(package)_version).tar.bz2
$(package)_sha256_hash=0baca8c9f5d934450a70896c4ad38d06475521255ca63b717a6510fdb6e287bd
$(package)_dependencies=xtrans xproto libICE
diff --git a/contrib/depends/packages/libusb.mk b/contrib/depends/packages/libusb.mk
index 47f8b3cbc..6d60cce26 100644
--- a/contrib/depends/packages/libusb.mk
+++ b/contrib/depends/packages/libusb.mk
@@ -1,8 +1,8 @@
package=libusb
-$(package)_version=1.0.9
-$(package)_download_path=http://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-1.0.9/
+$(package)_version=1.0.22
+$(package)_download_path=https://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-$($(package)_version)/
$(package)_file_name=$(package)-$($(package)_version).tar.bz2
-$(package)_sha256_hash=e920eedc2d06b09606611c99ec7304413c6784cba6e33928e78243d323195f9b
+$(package)_sha256_hash=75aeb9d59a4fdb800d329a545c2e6799f732362193b465ea198f2aa275518157
define $(package)_preprocess_cmds
autoreconf -i
@@ -10,7 +10,7 @@ endef
define $(package)_set_vars
$(package)_config_opts=--disable-shared
- $(package)_config_opts_linux=--with-pic
+ $(package)_config_opts_linux=--with-pic --disable-udev
endef
define $(package)_config_cmds
diff --git a/contrib/depends/packages/miniupnpc.mk b/contrib/depends/packages/miniupnpc.mk
deleted file mode 100644
index 1bb8cb5d2..000000000
--- a/contrib/depends/packages/miniupnpc.mk
+++ /dev/null
@@ -1,28 +0,0 @@
-package=miniupnpc
-$(package)_version=2.0.20170509
-$(package)_download_path=http://miniupnp.free.fr/files
-$(package)_file_name=$(package)-$($(package)_version).tar.gz
-$(package)_sha256_hash=d3c368627f5cdfb66d3ebd64ca39ba54d6ff14a61966dbecb8dd296b7039f16a
-
-define $(package)_set_vars
-$(package)_build_opts=CC="$($(package)_cc)"
-$(package)_build_opts_darwin=OS=Darwin LIBTOOL="$($(package)_libtool)"
-$(package)_build_opts_mingw32=-f Makefile.mingw
-$(package)_build_env+=CFLAGS="$($(package)_cflags) $($(package)_cppflags)" AR="$($(package)_ar)"
-endef
-
-define $(package)_preprocess_cmds
- mkdir dll && \
- sed -e 's|MINIUPNPC_VERSION_STRING \"version\"|MINIUPNPC_VERSION_STRING \"$($(package)_version)\"|' -e 's|OS/version|$(host)|' miniupnpcstrings.h.in > miniupnpcstrings.h && \
- sed -i.old "s|miniupnpcstrings.h: miniupnpcstrings.h.in wingenminiupnpcstrings|miniupnpcstrings.h: miniupnpcstrings.h.in|" Makefile.mingw
-endef
-
-define $(package)_build_cmds
- $(MAKE) libminiupnpc.a $($(package)_build_opts)
-endef
-
-define $(package)_stage_cmds
- mkdir -p $($(package)_staging_prefix_dir)/include/miniupnpc $($(package)_staging_prefix_dir)/lib &&\
- install *.h $($(package)_staging_prefix_dir)/include/miniupnpc &&\
- install libminiupnpc.a $($(package)_staging_prefix_dir)/lib
-endef
diff --git a/contrib/depends/packages/native_cdrkit.mk b/contrib/depends/packages/native_cdrkit.mk
index cf694edb3..8243458ec 100644
--- a/contrib/depends/packages/native_cdrkit.mk
+++ b/contrib/depends/packages/native_cdrkit.mk
@@ -1,6 +1,6 @@
package=native_cdrkit
$(package)_version=1.1.11
-$(package)_download_path=http://distro.ibiblio.org/fatdog/source/600/c
+$(package)_download_path=https://distro.ibiblio.org/fatdog/source/600/c
$(package)_file_name=cdrkit-$($(package)_version).tar.bz2
$(package)_sha256_hash=b50d64c214a65b1a79afe3a964c691931a4233e2ba605d793eb85d0ac3652564
$(package)_patches=cdrkit-deterministic.patch
diff --git a/contrib/depends/packages/packages.mk b/contrib/depends/packages/packages.mk
index f814c14d6..234adbdd4 100644
--- a/contrib/depends/packages/packages.mk
+++ b/contrib/depends/packages/packages.mk
@@ -1,8 +1,6 @@
packages:=boost openssl libevent zeromq cppzmq zlib expat ldns cppzmq readline libiconv qt hidapi
native_packages := native_ccache
-wallet_packages=bdb
-
darwin_native_packages = native_biplist native_ds_store native_mac_alias
darwin_packages = sodium-darwin
diff --git a/contrib/depends/packages/qt.mk b/contrib/depends/packages/qt.mk
index 32ca4a84c..bca2926cb 100644
--- a/contrib/depends/packages/qt.mk
+++ b/contrib/depends/packages/qt.mk
@@ -1,6 +1,6 @@
PACKAGE=qt
$(package)_version=5.7.1
-$(package)_download_path=http://download.qt.io/official_releases/qt/5.7/$($(package)_version)/submodules
+$(package)_download_path=https://download.qt.io/archive/qt/5.7/5.7.1/submodules
$(package)_suffix=opensource-src-$($(package)_version).tar.gz
$(package)_file_name=qtbase-$($(package)_suffix)
$(package)_sha256_hash=95f83e532d23b3ddbde7973f380ecae1bac13230340557276f75f2e37984e410
diff --git a/contrib/depends/packages/unbound.mk b/contrib/depends/packages/unbound.mk
index beeeb54c1..733a7f232 100644
--- a/contrib/depends/packages/unbound.mk
+++ b/contrib/depends/packages/unbound.mk
@@ -1,6 +1,6 @@
package=unbound
$(package)_version=1.6.8
-$(package)_download_path=http://www.unbound.net/downloads/
+$(package)_download_path=https://www.unbound.net/downloads/
$(package)_file_name=$(package)-$($(package)_version).tar.gz
$(package)_sha256_hash=e3b428e33f56a45417107448418865fe08d58e0e7fea199b855515f60884dd49
$(package)_dependencies=openssl expat ldns
diff --git a/contrib/depends/packages/unwind.mk b/contrib/depends/packages/unwind.mk
index e1bcb35b2..543f868a5 100644
--- a/contrib/depends/packages/unwind.mk
+++ b/contrib/depends/packages/unwind.mk
@@ -1,6 +1,6 @@
package=unwind
$(package)_version=1.2
-$(package)_download_path=http://download.savannah.nongnu.org/releases/libunwind
+$(package)_download_path=https://download.savannah.nongnu.org/releases/libunwind
$(package)_file_name=lib$(package)-$($(package)_version).tar.gz
$(package)_sha256_hash=1de38ffbdc88bd694d10081865871cd2bfbb02ad8ef9e1606aee18d65532b992
diff --git a/contrib/depends/packages/xproto.mk b/contrib/depends/packages/xproto.mk
index 50a90b268..52fe253c7 100644
--- a/contrib/depends/packages/xproto.mk
+++ b/contrib/depends/packages/xproto.mk
@@ -1,6 +1,6 @@
package=xproto
$(package)_version=7.0.26
-$(package)_download_path=http://xorg.freedesktop.org/releases/individual/proto
+$(package)_download_path=https://xorg.freedesktop.org/releases/individual/proto
$(package)_file_name=$(package)-$($(package)_version).tar.bz2
$(package)_sha256_hash=636162c1759805a5a0114a369dffdeccb8af8c859ef6e1445f26a4e6e046514f
diff --git a/contrib/depends/packages/zlib.mk b/contrib/depends/packages/zlib.mk
index 589490800..1600b11a0 100644
--- a/contrib/depends/packages/zlib.mk
+++ b/contrib/depends/packages/zlib.mk
@@ -1,6 +1,6 @@
package=zlib
$(package)_version=1.2.11
-$(package)_download_path=http://www.zlib.net
+$(package)_download_path=https://www.zlib.net
$(package)_file_name=$(package)-$($(package)_version).tar.gz
$(package)_sha256_hash=c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1
diff --git a/contrib/epee/include/int-util.h b/contrib/epee/include/int-util.h
new file mode 100644
index 000000000..3bcc085e2
--- /dev/null
+++ b/contrib/epee/include/int-util.h
@@ -0,0 +1,258 @@
+// Copyright (c) 2014-2018, The Monero Project
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification, are
+// permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this list of
+// conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice, this list
+// of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be
+// used to endorse or promote products derived from this software without specific
+// prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
+
+#pragma once
+
+#include <assert.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <string.h>
+
+#ifndef _MSC_VER
+#include <sys/param.h>
+#endif
+
+#if defined(__ANDROID__)
+#include <byteswap.h>
+#endif
+
+#if defined(__sun) && defined(__SVR4)
+#include <endian.h>
+#endif
+
+#if defined(_MSC_VER)
+#include <stdlib.h>
+
+static inline uint32_t rol32(uint32_t x, int r) {
+ static_assert(sizeof(uint32_t) == sizeof(unsigned int), "this code assumes 32-bit integers");
+ return _rotl(x, r);
+}
+
+static inline uint64_t rol64(uint64_t x, int r) {
+ return _rotl64(x, r);
+}
+
+#else
+
+static inline uint32_t rol32(uint32_t x, int r) {
+ return (x << (r & 31)) | (x >> (-r & 31));
+}
+
+static inline uint64_t rol64(uint64_t x, int r) {
+ return (x << (r & 63)) | (x >> (-r & 63));
+}
+
+#endif
+
+static inline uint64_t hi_dword(uint64_t val) {
+ return val >> 32;
+}
+
+static inline uint64_t lo_dword(uint64_t val) {
+ return val & 0xFFFFFFFF;
+}
+
+static inline uint64_t mul128(uint64_t multiplier, uint64_t multiplicand, uint64_t* product_hi) {
+ // multiplier = ab = a * 2^32 + b
+ // multiplicand = cd = c * 2^32 + d
+ // ab * cd = a * c * 2^64 + (a * d + b * c) * 2^32 + b * d
+ uint64_t a = hi_dword(multiplier);
+ uint64_t b = lo_dword(multiplier);
+ uint64_t c = hi_dword(multiplicand);
+ uint64_t d = lo_dword(multiplicand);
+
+ uint64_t ac = a * c;
+ uint64_t ad = a * d;
+ uint64_t bc = b * c;
+ uint64_t bd = b * d;
+
+ uint64_t adbc = ad + bc;
+ uint64_t adbc_carry = adbc < ad ? 1 : 0;
+
+ // multiplier * multiplicand = product_hi * 2^64 + product_lo
+ uint64_t product_lo = bd + (adbc << 32);
+ uint64_t product_lo_carry = product_lo < bd ? 1 : 0;
+ *product_hi = ac + (adbc >> 32) + (adbc_carry << 32) + product_lo_carry;
+ assert(ac <= *product_hi);
+
+ return product_lo;
+}
+
+static inline uint64_t div_with_reminder(uint64_t dividend, uint32_t divisor, uint32_t* remainder) {
+ dividend |= ((uint64_t)*remainder) << 32;
+ *remainder = dividend % divisor;
+ return dividend / divisor;
+}
+
+// Long division with 2^32 base
+static inline uint32_t div128_32(uint64_t dividend_hi, uint64_t dividend_lo, uint32_t divisor, uint64_t* quotient_hi, uint64_t* quotient_lo) {
+ uint64_t dividend_dwords[4];
+ uint32_t remainder = 0;
+
+ dividend_dwords[3] = hi_dword(dividend_hi);
+ dividend_dwords[2] = lo_dword(dividend_hi);
+ dividend_dwords[1] = hi_dword(dividend_lo);
+ dividend_dwords[0] = lo_dword(dividend_lo);
+
+ *quotient_hi = div_with_reminder(dividend_dwords[3], divisor, &remainder) << 32;
+ *quotient_hi |= div_with_reminder(dividend_dwords[2], divisor, &remainder);
+ *quotient_lo = div_with_reminder(dividend_dwords[1], divisor, &remainder) << 32;
+ *quotient_lo |= div_with_reminder(dividend_dwords[0], divisor, &remainder);
+
+ return remainder;
+}
+
+#define IDENT32(x) ((uint32_t) (x))
+#define IDENT64(x) ((uint64_t) (x))
+
+#define SWAP32(x) ((((uint32_t) (x) & 0x000000ff) << 24) | \
+ (((uint32_t) (x) & 0x0000ff00) << 8) | \
+ (((uint32_t) (x) & 0x00ff0000) >> 8) | \
+ (((uint32_t) (x) & 0xff000000) >> 24))
+#define SWAP64(x) ((((uint64_t) (x) & 0x00000000000000ff) << 56) | \
+ (((uint64_t) (x) & 0x000000000000ff00) << 40) | \
+ (((uint64_t) (x) & 0x0000000000ff0000) << 24) | \
+ (((uint64_t) (x) & 0x00000000ff000000) << 8) | \
+ (((uint64_t) (x) & 0x000000ff00000000) >> 8) | \
+ (((uint64_t) (x) & 0x0000ff0000000000) >> 24) | \
+ (((uint64_t) (x) & 0x00ff000000000000) >> 40) | \
+ (((uint64_t) (x) & 0xff00000000000000) >> 56))
+
+static inline uint32_t ident32(uint32_t x) { return x; }
+static inline uint64_t ident64(uint64_t x) { return x; }
+
+#ifndef __OpenBSD__
+# if defined(__ANDROID__) && defined(__swap32) && !defined(swap32)
+# define swap32 __swap32
+# elif !defined(swap32)
+static inline uint32_t swap32(uint32_t x) {
+ x = ((x & 0x00ff00ff) << 8) | ((x & 0xff00ff00) >> 8);
+ return (x << 16) | (x >> 16);
+}
+# endif
+# if defined(__ANDROID__) && defined(__swap64) && !defined(swap64)
+# define swap64 __swap64
+# elif !defined(swap64)
+static inline uint64_t swap64(uint64_t x) {
+ x = ((x & 0x00ff00ff00ff00ff) << 8) | ((x & 0xff00ff00ff00ff00) >> 8);
+ x = ((x & 0x0000ffff0000ffff) << 16) | ((x & 0xffff0000ffff0000) >> 16);
+ return (x << 32) | (x >> 32);
+}
+# endif
+#endif /* __OpenBSD__ */
+
+#if defined(__GNUC__)
+#define UNUSED __attribute__((unused))
+#else
+#define UNUSED
+#endif
+static inline void mem_inplace_ident(void *mem UNUSED, size_t n UNUSED) { }
+#undef UNUSED
+
+static inline void mem_inplace_swap32(void *mem, size_t n) {
+ size_t i;
+ for (i = 0; i < n; i++) {
+ ((uint32_t *) mem)[i] = swap32(((const uint32_t *) mem)[i]);
+ }
+}
+static inline void mem_inplace_swap64(void *mem, size_t n) {
+ size_t i;
+ for (i = 0; i < n; i++) {
+ ((uint64_t *) mem)[i] = swap64(((const uint64_t *) mem)[i]);
+ }
+}
+
+static inline void memcpy_ident32(void *dst, const void *src, size_t n) {
+ memcpy(dst, src, 4 * n);
+}
+static inline void memcpy_ident64(void *dst, const void *src, size_t n) {
+ memcpy(dst, src, 8 * n);
+}
+
+static inline void memcpy_swap32(void *dst, const void *src, size_t n) {
+ size_t i;
+ for (i = 0; i < n; i++) {
+ ((uint32_t *) dst)[i] = swap32(((const uint32_t *) src)[i]);
+ }
+}
+static inline void memcpy_swap64(void *dst, const void *src, size_t n) {
+ size_t i;
+ for (i = 0; i < n; i++) {
+ ((uint64_t *) dst)[i] = swap64(((const uint64_t *) src)[i]);
+ }
+}
+
+#ifdef _MSC_VER
+# define LITTLE_ENDIAN 1234
+# define BIG_ENDIAN 4321
+# define BYTE_ORDER LITTLE_ENDIAN
+#endif
+
+#if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN) || !defined(BIG_ENDIAN)
+static_assert(false, "BYTE_ORDER is undefined. Perhaps, GNU extensions are not enabled");
+#endif
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define SWAP32LE IDENT32
+#define SWAP32BE SWAP32
+#define swap32le ident32
+#define swap32be swap32
+#define mem_inplace_swap32le mem_inplace_ident
+#define mem_inplace_swap32be mem_inplace_swap32
+#define memcpy_swap32le memcpy_ident32
+#define memcpy_swap32be memcpy_swap32
+#define SWAP64LE IDENT64
+#define SWAP64BE SWAP64
+#define swap64le ident64
+#define swap64be swap64
+#define mem_inplace_swap64le mem_inplace_ident
+#define mem_inplace_swap64be mem_inplace_swap64
+#define memcpy_swap64le memcpy_ident64
+#define memcpy_swap64be memcpy_swap64
+#endif
+
+#if BYTE_ORDER == BIG_ENDIAN
+#define SWAP32BE IDENT32
+#define SWAP32LE SWAP32
+#define swap32be ident32
+#define swap32le swap32
+#define mem_inplace_swap32be mem_inplace_ident
+#define mem_inplace_swap32le mem_inplace_swap32
+#define memcpy_swap32be memcpy_ident32
+#define memcpy_swap32le memcpy_swap32
+#define SWAP64BE IDENT64
+#define SWAP64LE SWAP64
+#define swap64be ident64
+#define swap64le swap64
+#define mem_inplace_swap64be mem_inplace_ident
+#define mem_inplace_swap64le mem_inplace_swap64
+#define memcpy_swap64be memcpy_ident64
+#define memcpy_swap64le memcpy_swap64
+#endif
diff --git a/contrib/epee/include/misc_os_dependent.h b/contrib/epee/include/misc_os_dependent.h
index 0d09683d6..5fffde8d5 100644
--- a/contrib/epee/include/misc_os_dependent.h
+++ b/contrib/epee/include/misc_os_dependent.h
@@ -124,5 +124,14 @@ namespace misc_utils
return boost::lexical_cast<std::string>(pthread_self());
#endif
}
+
+ inline bool get_gmt_time(time_t t, struct tm &tm)
+ {
+#ifdef _WIN32
+ return gmtime_s(&tm, &t);
+#else
+ return gmtime_r(&t, &tm);
+#endif
+ }
}
}
diff --git a/contrib/epee/include/mlocker.h b/contrib/epee/include/mlocker.h
index d2fc2ed58..a6d94b3d2 100644
--- a/contrib/epee/include/mlocker.h
+++ b/contrib/epee/include/mlocker.h
@@ -73,7 +73,7 @@ namespace epee
mlocked(const T &&t): T(t) { mlocker::lock(this, sizeof(T)); }
mlocked(const mlocked<T> &&mt): T(mt) { mlocker::lock(this, sizeof(T)); }
mlocked<T> &operator=(const mlocked<T> &mt) { T::operator=(mt); return *this; }
- ~mlocked() { mlocker::unlock(this, sizeof(T)); }
+ ~mlocked() { try { mlocker::unlock(this, sizeof(T)); } catch (...) { /* do not propagate */ } }
};
template<typename T>
diff --git a/contrib/epee/include/net/abstract_tcp_server2.h b/contrib/epee/include/net/abstract_tcp_server2.h
index 3f726a352..e6b2755af 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.h
+++ b/contrib/epee/include/net/abstract_tcp_server2.h
@@ -36,7 +36,6 @@
#define _ABSTRACT_TCP_SERVER2_H_
-#include <boost/asio.hpp>
#include <string>
#include <vector>
#include <boost/noncopyable.hpp>
@@ -155,7 +154,8 @@ namespace net_utils
//this should be the last one, because it could be wait on destructor, while other activities possible on other threads
t_protocol_handler m_protocol_handler;
//typename t_protocol_handler::config_type m_dummy_config;
- std::list<boost::shared_ptr<connection<t_protocol_handler> > > m_self_refs; // add_ref/release support
+ size_t m_reference_count = 0; // reference count managed through add_ref/release support
+ boost::shared_ptr<connection<t_protocol_handler> > m_self_ref; // the reference to hold
critical_section m_self_refs_lock;
critical_section m_chunking_lock; // held while we add small chunks of the big do_send() to small do_send_chunk()
critical_section m_shutdown_lock; // held while shutting down
diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl
index 9b03941ee..d8779f372 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.inl
+++ b/contrib/epee/include/net/abstract_tcp_server2.inl
@@ -32,16 +32,13 @@
-//#include "net_utils_base.h"
-#include <boost/lambda/bind.hpp>
+#include <boost/bind.hpp>
#include <boost/foreach.hpp>
-#include <boost/lambda/lambda.hpp>
#include <boost/uuid/random_generator.hpp>
#include <boost/chrono.hpp>
#include <boost/utility/value_init.hpp>
#include <boost/asio/deadline_timer.hpp>
#include <boost/date_time/posix_time/posix_time.hpp> // TODO
-#include <boost/thread/thread.hpp> // TODO
#include <boost/thread/condition_variable.hpp> // TODO
#include "warnings.h"
#include "string_tools.h"
@@ -230,7 +227,8 @@ PRAGMA_WARNING_DISABLE_VS(4355)
//_dbg3("[sock " << socket_.native_handle() << "] add_ref 2, m_peer_number=" << mI->m_peer_number);
if(m_was_shutdown)
return false;
- m_self_refs.push_back(self);
+ ++m_reference_count;
+ m_self_ref = std::move(self);
return true;
CATCH_ENTRY_L0("connection<t_protocol_handler>::add_ref()", false);
}
@@ -242,10 +240,12 @@ PRAGMA_WARNING_DISABLE_VS(4355)
boost::shared_ptr<connection<t_protocol_handler> > back_connection_copy;
LOG_TRACE_CC(context, "[sock " << socket_.native_handle() << "] release");
CRITICAL_REGION_BEGIN(m_self_refs_lock);
- CHECK_AND_ASSERT_MES(m_self_refs.size(), false, "[sock " << socket_.native_handle() << "] m_self_refs empty at connection<t_protocol_handler>::release() call");
- //erasing from container without additional copy can cause start deleting object, including m_self_refs
- back_connection_copy = m_self_refs.back();
- m_self_refs.pop_back();
+ CHECK_AND_ASSERT_MES(m_reference_count, false, "[sock " << socket_.native_handle() << "] m_reference_count already at 0 at connection<t_protocol_handler>::release() call");
+ // is this the last reference?
+ if (--m_reference_count == 0) {
+ // move the held reference to a local variable, keeping the object alive until the function terminates
+ std::swap(back_connection_copy, m_self_ref);
+ }
CRITICAL_REGION_END();
return true;
CATCH_ENTRY_L0("connection<t_protocol_handler>::release()", false);
diff --git a/contrib/epee/include/net/connection_basic.hpp b/contrib/epee/include/net/connection_basic.hpp
index 7e8750047..9b6fc14a7 100644
--- a/contrib/epee/include/net/connection_basic.hpp
+++ b/contrib/epee/include/net/connection_basic.hpp
@@ -42,22 +42,11 @@
#define INCLUDED_p2p_connection_basic_hpp
-#include <boost/asio.hpp>
#include <string>
-#include <vector>
-#include <boost/noncopyable.hpp>
-#include <boost/shared_ptr.hpp>
#include <atomic>
+#include <memory>
#include <boost/asio.hpp>
-#include <boost/array.hpp>
-#include <boost/noncopyable.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/enable_shared_from_this.hpp>
-#include <boost/interprocess/detail/atomic.hpp>
-#include <boost/thread/thread.hpp>
-
-#include <memory>
#include "net/net_utils_base.h"
#include "syncobj.h"
diff --git a/contrib/epee/include/net/http_server_impl_base.h b/contrib/epee/include/net/http_server_impl_base.h
index 1a97e610a..5669824c1 100644
--- a/contrib/epee/include/net/http_server_impl_base.h
+++ b/contrib/epee/include/net/http_server_impl_base.h
@@ -33,7 +33,8 @@
#include <boost/thread.hpp>
#include <boost/bind.hpp>
-#include "net/http_server_cp2.h"
+#include "net/abstract_tcp_server2.h"
+#include "http_protocol_handler.h"
#include "net/http_server_handlers_map2.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
diff --git a/contrib/epee/include/net/levin_client.inl b/contrib/epee/include/net/levin_client.inl
index ab7c32c32..a580e81fd 100644
--- a/contrib/epee/include/net/levin_client.inl
+++ b/contrib/epee/include/net/levin_client.inl
@@ -80,10 +80,10 @@ int levin_client_impl::invoke(int command, const std::string& in_buff, std::stri
return -1;
bucket_head head = {0};
- head.m_signature = LEVIN_SIGNATURE;
- head.m_cb = in_buff.size();
+ head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
+ head.m_cb = SWAP64LE(in_buff.size());
head.m_have_to_return_data = true;
- head.m_command = command;
+ head.m_command = SWAP32LE(command);
if(!m_transport.send(&head, sizeof(head)))
return -1;
@@ -97,7 +97,7 @@ int levin_client_impl::invoke(int command, const std::string& in_buff, std::stri
head = *(bucket_head*)local_buff.data();
- if(head.m_signature!=LEVIN_SIGNATURE)
+ if(head.m_signature!=SWAP64LE(LEVIN_SIGNATURE))
{
LOG_PRINT_L1("Signature mismatch in response");
return -1;
@@ -116,10 +116,10 @@ int levin_client_impl::notify(int command, const std::string& in_buff)
return -1;
bucket_head head = {0};
- head.m_signature = LEVIN_SIGNATURE;
- head.m_cb = in_buff.size();
+ head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
+ head.m_cb = SWAP64LE(in_buff.size());
head.m_have_to_return_data = false;
- head.m_command = command;
+ head.m_command = SWAP32LE(command);
if(!m_transport.send((const char*)&head, sizeof(head)))
return -1;
@@ -139,12 +139,13 @@ inline
return -1;
bucket_head2 head = {0};
- head.m_signature = LEVIN_SIGNATURE;
- head.m_cb = in_buff.size();
+ head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
+ head.m_cb = SWAP64LE(in_buff.size());
head.m_have_to_return_data = true;
- head.m_command = command;
- head.m_protocol_version = LEVIN_PROTOCOL_VER_1;
- head.m_flags = LEVIN_PACKET_REQUEST;
+ head.m_command = SWAP32LE(command);
+ head.m_return_code = SWAP32LE(0);
+ head.m_flags = SWAP32LE(LEVIN_PACKET_REQUEST);
+ head.m_protocol_version = SWAP32LE(LEVIN_PROTOCOL_VER_1);
if(!m_transport.send(&head, sizeof(head)))
return -1;
@@ -157,14 +158,13 @@ inline
head = *(bucket_head2*)local_buff.data();
-
- if(head.m_signature!=LEVIN_SIGNATURE)
+ if(head.m_signature != SWAP64LE(LEVIN_SIGNATURE))
{
LOG_PRINT_L1("Signature mismatch in response");
return -1;
}
- if(!m_transport.recv_n(buff_out, head.m_cb))
+ if(!m_transport.recv_n(buff_out, SWAP64LE(head.m_cb)))
return -1;
return head.m_return_code;
@@ -177,12 +177,13 @@ inline
return -1;
bucket_head2 head = {0};
- head.m_signature = LEVIN_SIGNATURE;
- head.m_cb = in_buff.size();
+ head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
+ head.m_cb = SWAP64LE(in_buff.size());
head.m_have_to_return_data = false;
- head.m_command = command;
- head.m_protocol_version = LEVIN_PROTOCOL_VER_1;
- head.m_flags = LEVIN_PACKET_REQUEST;
+ head.m_command = SWAP32LE(command);
+ head.m_return_code = SWAP32LE(0);
+ head.m_flags = SWAP32LE(LEVIN_PACKET_REQUEST);
+ head.m_protocol_version = SWAP32LE(LEVIN_PROTOCOL_VER_1);
if(!m_transport.send((const char*)&head, sizeof(head)))
return -1;
diff --git a/contrib/epee/include/net/levin_helper.h b/contrib/epee/include/net/levin_helper.h
index 05560dd90..da926a914 100644
--- a/contrib/epee/include/net/levin_helper.h
+++ b/contrib/epee/include/net/levin_helper.h
@@ -30,6 +30,7 @@
#include "levin_base.h"
#include "serializeble_struct_helper.h"
+#include "int-util.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "net"
@@ -43,11 +44,11 @@ namespace levin
{
buff.resize(sizeof(levin::bucket_head));
levin::bucket_head& head = *(levin::bucket_head*)(&buff[0]);
- head.m_signature = LEVIN_SIGNATURE;
+ head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
head.m_cb = 0;
head.m_have_to_return_data = true;
- head.m_command = command_id;
- head.m_return_code = 1;
+ head.m_command = SWAP32LE(command_id);
+ head.m_return_code = SWAP32LE(1);
head.m_reservedA = rand(); //probably some flags in future
head.m_reservedB = rand(); //probably some check summ in future
@@ -55,7 +56,7 @@ namespace levin
if(!StorageNamed::save_struct_as_storage_to_buff_t<t_struct, StorageNamed::DefaultStorageType>(t, buff_strg))
return false;
- head.m_cb = buff_strg.size();
+ head.m_cb = SWAP64LE(buff_strg.size());
buff.append(buff_strg);
return true;
}
@@ -65,15 +66,15 @@ namespace levin
{
buff.resize(sizeof(levin::bucket_head));
levin::bucket_head& head = *(levin::bucket_head*)(&buff[0]);
- head.m_signature = LEVIN_SIGNATURE;
+ head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
head.m_cb = 0;
head.m_have_to_return_data = true;
- head.m_command = command_id;
- head.m_return_code = 1;
+ head.m_command = SWAP32LE(command_id);
+ head.m_return_code = SWAP32LE(1);
head.m_reservedA = rand(); //probably some flags in future
head.m_reservedB = rand(); //probably some check summ in future
- head.m_cb = data.size();
+ head.m_cb = SWAP64LE(data.size());
buff.append(data);
return true;
}
@@ -86,7 +87,17 @@ namespace levin
return false;
}
- levin::bucket_head& head = *(levin::bucket_head*)(&buff[0]);
+#if BYTE_ORDER == LITTLE_ENDIAN
+ levin::bucket_head &head = *(levin::bucket_head*)(&buff[0]);
+#else
+ levin::bucket_head head = *(levin::bucket_head*)(&buff[0]);
+ head.m_signature = SWAP64LE(head.m_signature);
+ head.m_cb = SWAP64LE(head.m_cb);
+ head.m_command = SWAP32LE(head.m_command);
+ head.m_return_code = SWAP32LE(head.m_return_code);
+ head.m_reservedA = SWAP32LE(head.m_reservedA);
+ head.m_reservedB = SWAP32LE(head.m_reservedB);
+#endif
if(head.m_signature != LEVIN_SIGNATURE)
{
LOG_PRINT_L3("Failed to read signature in levin message, at load_struct_from_levin_message");
@@ -113,7 +124,17 @@ namespace levin
return false;
}
- levin::bucket_head& head = *(levin::bucket_head*)(&buff[0]);
+#if BYTE_ORDER == LITTLE_ENDIAN
+ levin::bucket_head &head = *(levin::bucket_head*)(&buff[0]);
+#else
+ levin::bucket_head head = *(levin::bucket_head*)(&buff[0]);
+ head.m_signature = SWAP64LE(head.m_signature);
+ head.m_cb = SWAP64LE(head.m_cb);
+ head.m_command = SWAP32LE(head.m_command);
+ head.m_return_code = SWAP32LE(head.m_return_code);
+ head.m_reservedA = SWAP32LE(head.m_reservedA);
+ head.m_reservedB = SWAP32LE(head.m_reservedB);
+#endif
if(head.m_signature != LEVIN_SIGNATURE)
{
LOG_ERROR("Failed to read signature in levin message, at load_struct_from_levin_message");
diff --git a/contrib/epee/include/net/levin_protocol_handler.h b/contrib/epee/include/net/levin_protocol_handler.h
index b3a75bedc..791766762 100644
--- a/contrib/epee/include/net/levin_protocol_handler.h
+++ b/contrib/epee/include/net/levin_protocol_handler.h
@@ -31,6 +31,7 @@
#include <boost/uuid/uuid_generators.hpp>
#include "levin_base.h"
+#include "int-util.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "net"
@@ -103,7 +104,7 @@ namespace levin
case conn_state_reading_head:
if(m_cach_in_buffer.size() < sizeof(bucket_head))
{
- if(m_cach_in_buffer.size() >= sizeof(uint64_t) && *((uint64_t*)m_cach_in_buffer.data()) != LEVIN_SIGNATURE)
+ if(m_cach_in_buffer.size() >= sizeof(uint64_t) && *((uint64_t*)m_cach_in_buffer.data()) != SWAP64LE(LEVIN_SIGNATURE))
{
LOG_ERROR_CC(m_conn_context, "Signature mismatch on accepted connection");
return false;
@@ -112,13 +113,23 @@ namespace levin
break;
}
{
- bucket_head* phead = (bucket_head*)m_cach_in_buffer.data();
- if(LEVIN_SIGNATURE != phead->m_signature)
+#if BYTE_ORDER == LITTLE_ENDIAN
+ bucket_head &phead = *(bucket_head*)m_cach_in_buffer.data();
+#else
+ bucket_head phead = *(bucket_head*)m_cach_in_buffer.data();
+ phead.m_signature = SWAP64LE(phead.m_signature);
+ phead.m_cb = SWAP64LE(phead.m_cb);
+ phead.m_command = SWAP32LE(phead.m_command);
+ phead.m_return_code = SWAP32LE(phead.m_return_code);
+ phead.m_reservedA = SWAP32LE(phead.m_reservedA);
+ phead.m_reservedB = SWAP32LE(phead.m_reservedB);
+#endif
+ if(LEVIN_SIGNATURE != phead.m_signature)
{
LOG_ERROR_CC(m_conn_context, "Signature mismatch on accepted connection");
return false;
}
- m_current_head = *phead;
+ m_current_head = phead;
}
m_cach_in_buffer.erase(0, sizeof(bucket_head));
m_state = conn_state_reading_body;
diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h
index 08aa1d468..6b1528caf 100644
--- a/contrib/epee/include/net/levin_protocol_handler_async.h
+++ b/contrib/epee/include/net/levin_protocol_handler_async.h
@@ -37,6 +37,7 @@
#include "misc_language.h"
#include "syncobj.h"
#include "misc_os_dependent.h"
+#include "int-util.h"
#include <random>
#include <chrono>
@@ -469,7 +470,18 @@ public:
m_current_head.m_have_to_return_data = false;
m_current_head.m_protocol_version = LEVIN_PROTOCOL_VER_1;
m_current_head.m_flags = LEVIN_PACKET_RESPONSE;
+#if BYTE_ORDER == LITTLE_ENDIAN
std::string send_buff((const char*)&m_current_head, sizeof(m_current_head));
+#else
+ bucket_head2 head = m_current_head;
+ head.m_signature = SWAP64LE(head.m_signature);
+ head.m_cb = SWAP64LE(head.m_cb);
+ head.m_command = SWAP32LE(head.m_command);
+ head.m_return_code = SWAP32LE(head.m_return_code);
+ head.m_flags = SWAP32LE(head.m_flags);
+ head.m_protocol_version = SWAP32LE(head.m_protocol_version);
+ std::string send_buff((const char*)&head, sizeof(head));
+#endif
send_buff += return_buff;
CRITICAL_REGION_BEGIN(m_send_lock);
if(!m_pservice_endpoint->do_send(send_buff.data(), send_buff.size()))
@@ -491,7 +503,7 @@ public:
{
if(m_cache_in_buffer.size() < sizeof(bucket_head2))
{
- if(m_cache_in_buffer.size() >= sizeof(uint64_t) && *((uint64_t*)m_cache_in_buffer.data()) != LEVIN_SIGNATURE)
+ if(m_cache_in_buffer.size() >= sizeof(uint64_t) && *((uint64_t*)m_cache_in_buffer.data()) != SWAP64LE(LEVIN_SIGNATURE))
{
MWARNING(m_connection_context << "Signature mismatch, connection will be closed");
return false;
@@ -500,13 +512,23 @@ public:
break;
}
- bucket_head2* phead = (bucket_head2*)m_cache_in_buffer.data();
- if(LEVIN_SIGNATURE != phead->m_signature)
+#if BYTE_ORDER == LITTLE_ENDIAN
+ bucket_head2& phead = *(bucket_head2*)m_cache_in_buffer.data();
+#else
+ bucket_head2 phead = *(bucket_head2*)m_cache_in_buffer.data();
+ phead.m_signature = SWAP64LE(phead.m_signature);
+ phead.m_cb = SWAP64LE(phead.m_cb);
+ phead.m_command = SWAP32LE(phead.m_command);
+ phead.m_return_code = SWAP32LE(phead.m_return_code);
+ phead.m_flags = SWAP32LE(phead.m_flags);
+ phead.m_protocol_version = SWAP32LE(phead.m_protocol_version);
+#endif
+ if(LEVIN_SIGNATURE != phead.m_signature)
{
LOG_ERROR_CC(m_connection_context, "Signature mismatch, connection will be closed");
return false;
}
- m_current_head = *phead;
+ m_current_head = phead;
m_cache_in_buffer.erase(0, sizeof(bucket_head2));
m_state = stream_state_body;
@@ -566,13 +588,13 @@ public:
}
bucket_head2 head = {0};
- head.m_signature = LEVIN_SIGNATURE;
- head.m_cb = in_buff.size();
+ head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
+ head.m_cb = SWAP64LE(in_buff.size());
head.m_have_to_return_data = true;
- head.m_flags = LEVIN_PACKET_REQUEST;
- head.m_command = command;
- head.m_protocol_version = LEVIN_PROTOCOL_VER_1;
+ head.m_flags = SWAP32LE(LEVIN_PACKET_REQUEST);
+ head.m_command = SWAP32LE(command);
+ head.m_protocol_version = SWAP32LE(LEVIN_PROTOCOL_VER_1);
boost::interprocess::ipcdetail::atomic_write32(&m_invoke_buf_ready, 0);
CRITICAL_REGION_BEGIN(m_send_lock);
@@ -624,13 +646,13 @@ public:
return LEVIN_ERROR_CONNECTION_DESTROYED;
bucket_head2 head = {0};
- head.m_signature = LEVIN_SIGNATURE;
- head.m_cb = in_buff.size();
+ head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
+ head.m_cb = SWAP64LE(in_buff.size());
head.m_have_to_return_data = true;
- head.m_flags = LEVIN_PACKET_REQUEST;
- head.m_command = command;
- head.m_protocol_version = LEVIN_PROTOCOL_VER_1;
+ head.m_flags = SWAP32LE(LEVIN_PACKET_REQUEST);
+ head.m_command = SWAP32LE(command);
+ head.m_protocol_version = SWAP32LE(LEVIN_PROTOCOL_VER_1);
boost::interprocess::ipcdetail::atomic_write32(&m_invoke_buf_ready, 0);
CRITICAL_REGION_BEGIN(m_send_lock);
@@ -698,13 +720,13 @@ public:
return LEVIN_ERROR_CONNECTION_DESTROYED;
bucket_head2 head = {0};
- head.m_signature = LEVIN_SIGNATURE;
+ head.m_signature = SWAP64LE(LEVIN_SIGNATURE);
head.m_have_to_return_data = false;
- head.m_cb = in_buff.size();
+ head.m_cb = SWAP64LE(in_buff.size());
- head.m_command = command;
- head.m_protocol_version = LEVIN_PROTOCOL_VER_1;
- head.m_flags = LEVIN_PACKET_REQUEST;
+ head.m_command = SWAP32LE(command);
+ head.m_protocol_version = SWAP32LE(LEVIN_PROTOCOL_VER_1);
+ head.m_flags = SWAP32LE(LEVIN_PACKET_REQUEST);
CRITICAL_REGION_BEGIN(m_send_lock);
if(!m_pservice_endpoint->do_send(&head, sizeof(head)))
{
diff --git a/contrib/epee/include/span.h b/contrib/epee/include/span.h
index 174915ecf..b1296a0b7 100644
--- a/contrib/epee/include/span.h
+++ b/contrib/epee/include/span.h
@@ -109,6 +109,8 @@ namespace epee
constexpr std::size_t size() const noexcept { return len; }
constexpr std::size_t size_bytes() const noexcept { return size() * sizeof(value_type); }
+ const T &operator[](size_t idx) const { return ptr[idx]; }
+
private:
T* ptr;
std::size_t len;
diff --git a/contrib/epee/include/storages/portable_storage.h b/contrib/epee/include/storages/portable_storage.h
index 2023e2f2a..0f0c6210f 100644
--- a/contrib/epee/include/storages/portable_storage.h
+++ b/contrib/epee/include/storages/portable_storage.h
@@ -35,6 +35,7 @@
#include "portable_storage_to_json.h"
#include "portable_storage_from_json.h"
#include "portable_storage_val_converters.h"
+#include "int-util.h"
namespace epee
{
@@ -135,8 +136,8 @@ namespace epee
TRY_ENTRY();
std::stringstream ss;
storage_block_header sbh = AUTO_VAL_INIT(sbh);
- sbh.m_signature_a = PORTABLE_STORAGE_SIGNATUREA;
- sbh.m_signature_b = PORTABLE_STORAGE_SIGNATUREB;
+ 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((const char*)&sbh, sizeof(storage_block_header));
pack_entry_to_buff(ss, m_root);
@@ -154,8 +155,8 @@ namespace epee
return false;
}
storage_block_header* pbuff = (storage_block_header*)source.data();
- if(pbuff->m_signature_a != PORTABLE_STORAGE_SIGNATUREA ||
- pbuff->m_signature_b != PORTABLE_STORAGE_SIGNATUREB
+ 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");
diff --git a/contrib/epee/include/string_tools.h b/contrib/epee/include/string_tools.h
index aba065cc7..6a063cc36 100644
--- a/contrib/epee/include/string_tools.h
+++ b/contrib/epee/include/string_tools.h
@@ -59,6 +59,26 @@
#pragma comment (lib, "Rpcrt4.lib")
#endif
+static const constexpr unsigned char isx[256] =
+{
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 10, 11, 12, 13, 14, 15, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 10, 11, 12, 13, 14, 15, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
+};
+
namespace epee
{
namespace string_tools
@@ -98,30 +118,30 @@ namespace string_tools
}
//----------------------------------------------------------------------------
template<class CharT>
- bool parse_hexstr_to_binbuff(const std::basic_string<CharT>& s, std::basic_string<CharT>& res, bool allow_partial_byte = false)
+ bool parse_hexstr_to_binbuff(const std::basic_string<CharT>& s, std::basic_string<CharT>& res)
{
res.clear();
- if (!allow_partial_byte && (s.size() & 1))
+ if (s.size() & 1)
return false;
try
{
- long v = 0;
- for(size_t i = 0; i < (s.size() + 1) / 2; i++)
+ res.resize(s.size() / 2);
+ unsigned char *dst = (unsigned char *)res.data();
+ const unsigned char *src = (const unsigned char *)s.data();
+ for(size_t i = 0; i < s.size(); i += 2)
{
- CharT byte_str[3];
- size_t copied = s.copy(byte_str, 2, 2 * i);
- byte_str[copied] = CharT(0);
- CharT* endptr;
- v = strtoul(byte_str, &endptr, 16);
- if (v < 0 || 0xFF < v || endptr != byte_str + copied)
- {
- return false;
- }
- res.push_back(static_cast<unsigned char>(v));
+ int tmp = *src++;
+ tmp = isx[tmp];
+ if (tmp == 0xff) return false;
+ int t2 = *src++;
+ t2 = isx[t2];
+ if (t2 == 0xff) return false;
+ *dst++ = (tmp << 4) | t2;
}
return true;
- }catch(...)
+ }
+ catch(...)
{
return false;
}
diff --git a/contrib/epee/src/connection_basic.cpp b/contrib/epee/src/connection_basic.cpp
index 9ab485839..7d145ee46 100644
--- a/contrib/epee/src/connection_basic.cpp
+++ b/contrib/epee/src/connection_basic.cpp
@@ -34,47 +34,15 @@
#include "net/connection_basic.hpp"
-#include <boost/asio.hpp>
-#include <string>
-#include <vector>
-#include <boost/noncopyable.hpp>
-#include <boost/shared_ptr.hpp>
-#include <atomic>
-
-#include <boost/asio.hpp>
-#include <boost/array.hpp>
-#include <boost/noncopyable.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/enable_shared_from_this.hpp>
-#include <boost/interprocess/detail/atomic.hpp>
-#include <boost/thread/thread.hpp>
-
-#include <memory>
-
-#include "syncobj.h"
-
#include "net/net_utils_base.h"
#include "misc_log_ex.h"
-#include <boost/lambda/bind.hpp>
-#include <boost/lambda/lambda.hpp>
-#include <boost/uuid/random_generator.hpp>
-#include <boost/chrono.hpp>
-#include <boost/utility/value_init.hpp>
-#include <boost/asio/deadline_timer.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/thread/thread.hpp>
-#include <boost/filesystem.hpp>
#include "misc_language.h"
#include "pragma_comp_defs.h"
-#include <fstream>
-#include <sstream>
#include <iomanip>
-#include <algorithm>
-#include <mutex>
#include <boost/asio/basic_socket.hpp>
-#include <boost/asio/ip/unicast.hpp>
-#include "net/abstract_tcp_server2.h"
// TODO:
#include "net/network_throttle-detail.hpp"
@@ -161,7 +129,6 @@ connection_basic::connection_basic(boost::asio::io_service& io_service, std::ato
try { boost::system::error_code e; remote_addr_str = socket_.remote_endpoint(e).address().to_string(); } catch(...){} ;
_note("Spawned connection p2p#"<<mI->m_peer_number<<" to " << remote_addr_str << " currently we have sockets count:" << m_ref_sock_count);
- //boost::filesystem::create_directories("log/dr-monero/net/");
}
connection_basic::~connection_basic() noexcept(false) {
diff --git a/contrib/epee/src/mlocker.cpp b/contrib/epee/src/mlocker.cpp
index c3262e8f4..078a84ce3 100644
--- a/contrib/epee/src/mlocker.cpp
+++ b/contrib/epee/src/mlocker.cpp
@@ -38,6 +38,12 @@
#include "syncobj.h"
#include "mlocker.h"
+#include <atomic>
+
+// did an mlock operation previously fail? we only
+// want to log an error once and be done with it
+static std::atomic<bool> previously_failed{ false };
+
static size_t query_page_size()
{
#if defined HAVE_MLOCK
@@ -47,7 +53,6 @@ static size_t query_page_size()
MERROR("Failed to determine page size");
return 0;
}
- MINFO("Page size: " << ret);
return ret;
#else
#warning Missing query_page_size implementation
@@ -59,8 +64,8 @@ static void do_lock(void *ptr, size_t len)
{
#if defined HAVE_MLOCK
int ret = mlock(ptr, len);
- if (ret < 0)
- MERROR("Error locking page at " << ptr << ": " << strerror(errno));
+ if (ret < 0 && !previously_failed.exchange(true))
+ MERROR("Error locking page at " << ptr << ": " << strerror(errno) << ", subsequent mlock errors will be silenced");
#else
#warning Missing do_lock implementation
#endif
@@ -70,7 +75,10 @@ static void do_unlock(void *ptr, size_t len)
{
#if defined HAVE_MLOCK
int ret = munlock(ptr, len);
- if (ret < 0)
+ // check whether we previously failed, but don't set it, this is just
+ // to pacify the errors of mlock()ing failed, in which case unlocking
+ // is also not going to work of course
+ if (ret < 0 && !previously_failed.load())
MERROR("Error unlocking page at " << ptr << ": " << strerror(errno));
#else
#warning Missing implementation of page size detection
@@ -89,8 +97,8 @@ namespace epee
}
std::map<size_t, unsigned int> &mlocker::map()
{
- static std::map<size_t, unsigned int> vmap;
- return vmap;
+ static std::map<size_t, unsigned int> *vmap = new std::map<size_t, unsigned int>();
+ return *vmap;
}
size_t mlocker::get_page_size()
@@ -108,11 +116,14 @@ namespace epee
mlocker::~mlocker()
{
- unlock(ptr, len);
+ try { unlock(ptr, len); }
+ catch (...) { /* ignore and do not propagate through the dtor */ }
}
void mlocker::lock(void *ptr, size_t len)
{
+ TRY_ENTRY();
+
size_t page_size = get_page_size();
if (page_size == 0)
return;
@@ -123,10 +134,14 @@ namespace epee
for (size_t page = first; page <= last; ++page)
lock_page(page);
++num_locked_objects;
+
+ CATCH_ENTRY_L1("mlocker::lock", void());
}
void mlocker::unlock(void *ptr, size_t len)
{
+ TRY_ENTRY();
+
size_t page_size = get_page_size();
if (page_size == 0)
return;
@@ -136,6 +151,8 @@ namespace epee
for (size_t page = first; page <= last; ++page)
unlock_page(page);
--num_locked_objects;
+
+ CATCH_ENTRY_L1("mlocker::lock", void());
}
size_t mlocker::get_num_locked_pages()
diff --git a/contrib/epee/src/mlog.cpp b/contrib/epee/src/mlog.cpp
index 638155b6b..00d848388 100644
--- a/contrib/epee/src/mlog.cpp
+++ b/contrib/epee/src/mlog.cpp
@@ -40,6 +40,7 @@
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
#include "string_tools.h"
+#include "misc_os_dependent.h"
#include "misc_log_ex.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
@@ -58,12 +59,7 @@ static std::string generate_log_filename(const char *base)
char tmp[200];
struct tm tm;
time_t now = time(NULL);
- if
-#ifdef WIN32
- (!gmtime_s(&tm, &now))
-#else
- (!gmtime_r(&now, &tm))
-#endif
+ if (!epee::misc_utils::get_gmt_time(now, tm))
snprintf(tmp, sizeof(tmp), "part-%u", ++fallback_counter);
else
strftime(tmp, sizeof(tmp), "%Y-%m-%d-%H-%M-%S", &tm);
diff --git a/contrib/epee/src/net_utils_base.cpp b/contrib/epee/src/net_utils_base.cpp
index 2f4015e81..354c3d2c3 100644
--- a/contrib/epee/src/net_utils_base.cpp
+++ b/contrib/epee/src/net_utils_base.cpp
@@ -2,8 +2,6 @@
#include "net/net_utils_base.h"
#include "string_tools.h"
-#include <cstring>
-#include <typeindex>
#include "net/local_ip.h"
namespace epee { namespace net_utils
diff --git a/contrib/epee/src/network_throttle-detail.cpp b/contrib/epee/src/network_throttle-detail.cpp
index 6f727a1cf..d2e776df0 100644
--- a/contrib/epee/src/network_throttle-detail.cpp
+++ b/contrib/epee/src/network_throttle-detail.cpp
@@ -32,20 +32,11 @@
/* rfree: implementation for throttle details */
-#include <boost/asio.hpp>
#include <string>
#include <vector>
-#include <boost/noncopyable.hpp>
-#include <boost/shared_ptr.hpp>
#include <atomic>
#include <boost/asio.hpp>
-#include <boost/array.hpp>
-#include <boost/noncopyable.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/enable_shared_from_this.hpp>
-#include <boost/interprocess/detail/atomic.hpp>
-#include <boost/thread/thread.hpp>
#include <memory>
@@ -53,14 +44,7 @@
#include "net/net_utils_base.h"
#include "misc_log_ex.h"
-#include <boost/lambda/bind.hpp>
-#include <boost/lambda/lambda.hpp>
-#include <boost/uuid/random_generator.hpp>
#include <boost/chrono.hpp>
-#include <boost/utility/value_init.hpp>
-#include <boost/asio/deadline_timer.hpp>
-#include <boost/date_time/posix_time/posix_time.hpp>
-#include <boost/thread/thread.hpp>
#include "misc_language.h"
#include "pragma_comp_defs.h"
#include <sstream>
diff --git a/contrib/epee/src/readline_buffer.cpp b/contrib/epee/src/readline_buffer.cpp
index da264471f..c5949da0a 100644
--- a/contrib/epee/src/readline_buffer.cpp
+++ b/contrib/epee/src/readline_buffer.cpp
@@ -1,9 +1,9 @@
#include "readline_buffer.h"
#include <readline/readline.h>
#include <readline/history.h>
-#include <unistd.h>
#include <iostream>
-#include <boost/thread.hpp>
+#include <boost/thread/mutex.hpp>
+#include <boost/thread/lock_guard.hpp>
#include <boost/algorithm/string.hpp>
static void install_line_handler();
diff --git a/contrib/epee/tests/src/net/test_net.h b/contrib/epee/tests/src/net/test_net.h
index 04fef089c..51b1f1ec6 100644
--- a/contrib/epee/tests/src/net/test_net.h
+++ b/contrib/epee/tests/src/net/test_net.h
@@ -29,7 +29,9 @@
#include <boost/thread.hpp>
#include <boost/bind.hpp>
-#include "net/levin_server_cp2.h"
+#include "net/abstract_tcp_server2.h"
+#include "net/levin_protocol_handler.h"
+#include "net/levin_protocol_handler_async.h"
#include "storages/abstract_invoke.h"
namespace epee
diff --git a/contrib/valgrind/monero.supp b/contrib/valgrind/monero.supp
index 16e34e82f..015b05a1c 100644
--- a/contrib/valgrind/monero.supp
+++ b/contrib/valgrind/monero.supp
@@ -17,3 +17,12 @@
fun:maybe_unlock_and_signal_one<boost::asio::detail::scoped_lock<boost::asio::detail::posix_mutex> >
...
}
+
+{
+ we leak the logger, for performance reasons in on-the-fly init
+ Memcheck:Leak
+ match-leak-kinds: definite
+ fun:_Znwm
+ fun:_ZN2el4base7Storage7getELPPEv
+ ...
+}