diff options
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/depends/packages/cppzmq.mk | 4 | ||||
-rw-r--r-- | contrib/depends/packages/zeromq.mk | 4 | ||||
-rw-r--r-- | contrib/epee/include/int-util.h | 20 | ||||
-rw-r--r-- | contrib/epee/include/math_helper.h | 5 | ||||
-rw-r--r-- | contrib/epee/include/net/abstract_tcp_server2.inl | 29 | ||||
-rw-r--r-- | contrib/epee/include/net/levin_protocol_handler_async.h | 5 | ||||
-rw-r--r-- | contrib/epee/include/net/net_helper.h | 5 | ||||
-rw-r--r-- | contrib/epee/include/net/net_ssl.h | 7 | ||||
-rw-r--r-- | contrib/epee/include/serialization/keyvalue_serialization.h | 24 | ||||
-rw-r--r-- | contrib/epee/include/storages/http_abstract_invoke.h | 11 | ||||
-rw-r--r-- | contrib/epee/src/CMakeLists.txt | 7 | ||||
-rw-r--r-- | contrib/epee/src/connection_basic.cpp | 2 | ||||
-rw-r--r-- | contrib/epee/src/int-util.cpp | 48 | ||||
-rw-r--r-- | contrib/epee/src/mlog.cpp | 2 | ||||
-rw-r--r-- | contrib/epee/src/net_ssl.cpp | 35 | ||||
-rwxr-xr-x | contrib/gitian/gitian-build.py | 65 |
16 files changed, 219 insertions, 54 deletions
diff --git a/contrib/depends/packages/cppzmq.mk b/contrib/depends/packages/cppzmq.mk index 6c0faf084..33178f445 100644 --- a/contrib/depends/packages/cppzmq.mk +++ b/contrib/depends/packages/cppzmq.mk @@ -1,8 +1,8 @@ package=cppzmq -$(package)_version=4.2.3 +$(package)_version=4.4.1 $(package)_download_path=https://github.com/zeromq/cppzmq/archive/ $(package)_file_name=v$($(package)_version).tar.gz -$(package)_sha256_hash=3e6b57bf49115f4ae893b1ff7848ead7267013087dc7be1ab27636a97144d373 +$(package)_sha256_hash=117fc1ca24d98dbe1a60c072cde13be863d429134907797f8e03f654ce679385 $(package)_dependencies=zeromq define $(package)_stage_cmds diff --git a/contrib/depends/packages/zeromq.mk b/contrib/depends/packages/zeromq.mk index f17dbeebe..c3a405a60 100644 --- a/contrib/depends/packages/zeromq.mk +++ b/contrib/depends/packages/zeromq.mk @@ -1,8 +1,8 @@ package=zeromq -$(package)_version=4.1.5 +$(package)_version=4.1.7 $(package)_download_path=https://github.com/zeromq/zeromq4-1/releases/download/v$($(package)_version)/ $(package)_file_name=$(package)-$($(package)_version).tar.gz -$(package)_sha256_hash=04aac57f081ffa3a2ee5ed04887be9e205df3a7ddade0027460b8042432bdbcf +$(package)_sha256_hash=31c383cfcd3be1dc8a66e448c403029e793687e70473b89c4cc0bd626e7da299 $(package)_patches=9114d3957725acd34aa8b8d011585812f3369411.patch 9e6745c12e0b100cd38acecc16ce7db02905e27c.patch define $(package)_set_vars diff --git a/contrib/epee/include/int-util.h b/contrib/epee/include/int-util.h index 8ef5be40a..dcd58a8c4 100644 --- a/contrib/epee/include/int-util.h +++ b/contrib/epee/include/int-util.h @@ -129,6 +129,26 @@ static inline uint32_t div128_32(uint64_t dividend_hi, uint64_t dividend_lo, uin return remainder; } +// Long divisor with 2^64 base +void div128_64(uint64_t dividend_hi, uint64_t dividend_lo, uint64_t divisor, uint64_t* quotient_hi, uint64_t *quotient_lo, uint64_t *remainder_hi, uint64_t *remainder_lo); + +static inline void add64clamp(uint64_t *value, uint64_t add) +{ + static const uint64_t maxval = (uint64_t)-1; + if (*value > maxval - add) + *value = maxval; + else + *value += add; +} + +static inline void sub64clamp(uint64_t *value, uint64_t sub) +{ + if (*value < sub) + *value = 0; + else + *value -= sub; +} + #define IDENT16(x) ((uint16_t) (x)) #define IDENT32(x) ((uint32_t) (x)) #define IDENT64(x) ((uint64_t) (x)) diff --git a/contrib/epee/include/math_helper.h b/contrib/epee/include/math_helper.h index ddc1f7f4b..604a04680 100644 --- a/contrib/epee/include/math_helper.h +++ b/contrib/epee/include/math_helper.h @@ -259,6 +259,11 @@ namespace math_helper m_last_worked_time = get_time(); } + void trigger() + { + m_last_worked_time = 0; + } + template<class functor_t> bool do_call(functor_t functr) { diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl index 8d96e4a84..5d12f9466 100644 --- a/contrib/epee/include/net/abstract_tcp_server2.inl +++ b/contrib/epee/include/net/abstract_tcp_server2.inl @@ -50,6 +50,8 @@ #include <sstream> #include <iomanip> #include <algorithm> +#include <functional> +#include <random> #undef MONERO_DEFAULT_LOG_CATEGORY #define MONERO_DEFAULT_LOG_CATEGORY "net" @@ -557,7 +559,7 @@ PRAGMA_WARNING_DISABLE_VS(4355) while (!message.empty()) { byte_slice chunk = message.take_slice(chunksize_good); - MDEBUG("chunk_start="<<chunk.data()<<" ptr="<<message_data<<" pos="<<(chunk.data() - message_data)); + MDEBUG("chunk_start="<<(void*)chunk.data()<<" ptr="<<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)); // <====== *** @@ -628,7 +630,17 @@ PRAGMA_WARNING_DISABLE_VS(4355) return false; // aborted }*/ - long int ms = 250 + (rand()%50); + using engine = std::mt19937; + + engine rng; + std::random_device dev; + std::seed_seq::result_type rand[engine::state_size]{}; // Use complete bit space + + std::generate_n(rand, engine::state_size, std::ref(dev)); + std::seed_seq seed(rand, rand + engine::state_size); + rng.seed(seed); + + long int ms = 250 + (rng() % 50); MDEBUG("Sleeping because QUEUE is FULL, in " << __FUNCTION__ << " for " << ms << " ms before packet_size="<<chunk.size()); // XXX debug sleep m_send_que_lock.unlock(); boost::this_thread::sleep(boost::posix_time::milliseconds( ms ) ); @@ -736,6 +748,11 @@ PRAGMA_WARNING_DISABLE_VS(4355) MERROR("Resetting timer on a dead object"); return; } + if (m_was_shutdown) + { + MERROR("Setting timer on a shut down object"); + return; + } if (add) ms += m_timer.expires_from_now(); m_timer.expires_from_now(ms); @@ -967,8 +984,9 @@ PRAGMA_WARNING_DISABLE_VS(4355) boost::asio::ip::tcp::resolver::query query(address, boost::lexical_cast<std::string>(port), boost::asio::ip::tcp::resolver::query::canonical_name); boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query); acceptor_.open(endpoint.protocol()); - // Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR). +#if !defined(_WIN32) acceptor_.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); +#endif acceptor_.bind(endpoint); acceptor_.listen(); boost::asio::ip::tcp::endpoint binded_endpoint = acceptor_.local_endpoint(); @@ -1002,8 +1020,9 @@ PRAGMA_WARNING_DISABLE_VS(4355) boost::asio::ip::tcp::resolver::query query(address_ipv6, boost::lexical_cast<std::string>(port_ipv6), boost::asio::ip::tcp::resolver::query::canonical_name); boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query); acceptor_ipv6.open(endpoint.protocol()); - // Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR). +#if !defined(_WIN32) acceptor_ipv6.set_option(boost::asio::ip::tcp::acceptor::reuse_address(true)); +#endif acceptor_ipv6.set_option(boost::asio::ip::v6_only(true)); acceptor_ipv6.bind(endpoint); acceptor_ipv6.listen(); @@ -1507,7 +1526,7 @@ POP_WARNINGS } - LOG_ERROR("Trying connect to " << adr << ":" << port << ", bind_ip = " << bind_ip_to_use); + MDEBUG("Trying to connect to " << adr << ":" << port << ", bind_ip = " << bind_ip_to_use); //boost::asio::ip::tcp::endpoint remote_endpoint(boost::asio::ip::address::from_string(addr.c_str()), port); boost::asio::ip::tcp::endpoint remote_endpoint(*iterator); diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h index 41f01e9a0..5774c0ba7 100644 --- a/contrib/epee/include/net/levin_protocol_handler_async.h +++ b/contrib/epee/include/net/levin_protocol_handler_async.h @@ -272,6 +272,11 @@ public: bool add_invoke_response_handler(const callback_t &cb, uint64_t timeout, async_protocol_handler& con, int command) { CRITICAL_REGION_LOCAL(m_invoke_response_handlers_lock); + if (m_protocol_released) + { + MERROR("Adding response handler to a released object"); + return false; + } boost::shared_ptr<invoke_response_handler_base> handler(boost::make_shared<anvoke_handler<callback_t>>(cb, timeout, con, command)); m_invoke_response_handlers.push_back(handler); return handler->is_timer_started(); diff --git a/contrib/epee/include/net/net_helper.h b/contrib/epee/include/net/net_helper.h index 2b02eafa4..81545e502 100644 --- a/contrib/epee/include/net/net_helper.h +++ b/contrib/epee/include/net/net_helper.h @@ -108,11 +108,12 @@ namespace net_utils m_ssl_options(epee::net_utils::ssl_support_t::e_ssl_support_autodetect), m_initialized(true), m_connected(false), - m_deadline(m_io_service), + m_deadline(m_io_service, std::chrono::steady_clock::time_point::max()), m_shutdowned(0), m_bytes_sent(0), m_bytes_received(0) { + check_deadline(); } /*! The first/second parameters are host/port respectively. The third @@ -177,7 +178,7 @@ namespace net_utils // SSL Options if (m_ssl_options.support == epee::net_utils::ssl_support_t::e_ssl_support_enabled || m_ssl_options.support == epee::net_utils::ssl_support_t::e_ssl_support_autodetect) { - if (!m_ssl_options.handshake(*m_ssl_socket, boost::asio::ssl::stream_base::client, addr)) + if (!m_ssl_options.handshake(*m_ssl_socket, boost::asio::ssl::stream_base::client, addr, timeout)) { if (m_ssl_options.support == epee::net_utils::ssl_support_t::e_ssl_support_autodetect) { diff --git a/contrib/epee/include/net/net_ssl.h b/contrib/epee/include/net/net_ssl.h index 3a97dfdaf..643b2c486 100644 --- a/contrib/epee/include/net/net_ssl.h +++ b/contrib/epee/include/net/net_ssl.h @@ -29,6 +29,7 @@ #ifndef _NET_SSL_H #define _NET_SSL_H +#include <chrono> #include <stdint.h> #include <string> #include <vector> @@ -128,7 +129,11 @@ namespace net_utils \return True if the SSL handshake completes with peer verification settings. */ - bool handshake(boost::asio::ssl::stream<boost::asio::ip::tcp::socket> &socket, boost::asio::ssl::stream_base::handshake_type type, const std::string& host = {}) const; + bool handshake( + boost::asio::ssl::stream<boost::asio::ip::tcp::socket> &socket, + boost::asio::ssl::stream_base::handshake_type type, + const std::string& host = {}, + std::chrono::milliseconds timeout = std::chrono::seconds(15)) const; }; // https://security.stackexchange.com/questions/34780/checking-client-hello-for-https-classification diff --git a/contrib/epee/include/serialization/keyvalue_serialization.h b/contrib/epee/include/serialization/keyvalue_serialization.h index 5459c8409..78d294d05 100644 --- a/contrib/epee/include/serialization/keyvalue_serialization.h +++ b/contrib/epee/include/serialization/keyvalue_serialization.h @@ -26,6 +26,7 @@ #pragma once +#include <type_traits> #include <boost/utility/value_init.hpp> #include <boost/foreach.hpp> #include "misc_log_ex.h" @@ -45,18 +46,20 @@ public: \ template<class t_storage> \ bool store( t_storage& st, typename t_storage::hsection hparent_section = nullptr) const\ {\ - return serialize_map<true>(*this, st, hparent_section);\ + using type = typename std::remove_const<typename std::remove_reference<decltype(*this)>::type>::type; \ + auto &self = const_cast<type&>(*this); \ + return self.template serialize_map<true>(st, hparent_section); \ }\ template<class t_storage> \ bool _load( t_storage& stg, typename t_storage::hsection hparent_section = nullptr)\ {\ - return serialize_map<false>(*this, stg, hparent_section);\ + return serialize_map<false>(stg, hparent_section);\ }\ template<class t_storage> \ bool load( t_storage& stg, typename t_storage::hsection hparent_section = nullptr)\ {\ try{\ - return serialize_map<false>(*this, stg, hparent_section);\ + return serialize_map<false>(stg, hparent_section);\ }\ catch(const std::exception& err) \ { \ @@ -65,13 +68,22 @@ public: \ return false; \ }\ }\ - template<bool is_store, class this_type, class t_storage> \ - static bool serialize_map(this_type& this_ref, t_storage& stg, typename t_storage::hsection hparent_section) \ - { + /*template<typename T> T& this_type_resolver() { return *this; }*/ \ + /*using this_type = std::result_of<decltype(this_type_resolver)>::type;*/ \ + template<bool is_store, class t_storage> \ + bool serialize_map(t_storage& stg, typename t_storage::hsection hparent_section) \ + { \ + decltype(*this) &this_ref = *this; #define KV_SERIALIZE_N(varialble, val_name) \ epee::serialization::selector<is_store>::serialize(this_ref.varialble, stg, hparent_section, val_name); +#define KV_SERIALIZE_PARENT(type) \ + do { \ + if (!((type*)this)->serialize_map<is_store, t_storage>(stg, hparent_section)) \ + return false; \ + } while(0); + template<typename T> inline void serialize_default(const T &t, T v) { } template<typename T> inline void serialize_default(T &t, T v) { t = v; } diff --git a/contrib/epee/include/storages/http_abstract_invoke.h b/contrib/epee/include/storages/http_abstract_invoke.h index 18b7f10c1..78e02c93a 100644 --- a/contrib/epee/include/storages/http_abstract_invoke.h +++ b/contrib/epee/include/storages/http_abstract_invoke.h @@ -101,7 +101,7 @@ namespace epee } template<class t_request, class t_response, class t_transport> - bool invoke_http_json_rpc(const boost::string_ref uri, std::string method_name, const t_request& out_struct, t_response& result_struct, t_transport& transport, std::chrono::milliseconds timeout = std::chrono::seconds(15), const boost::string_ref http_method = "GET", const std::string& req_id = "0") + bool invoke_http_json_rpc(const boost::string_ref uri, std::string method_name, const t_request& out_struct, t_response& result_struct, epee::json_rpc::error &error_struct, t_transport& transport, std::chrono::milliseconds timeout = std::chrono::seconds(15), const boost::string_ref http_method = "GET", const std::string& req_id = "0") { epee::json_rpc::request<t_request> req_t = AUTO_VAL_INIT(req_t); req_t.jsonrpc = "2.0"; @@ -111,10 +111,12 @@ namespace epee epee::json_rpc::response<t_response, epee::json_rpc::error> resp_t = AUTO_VAL_INIT(resp_t); if(!epee::net_utils::invoke_http_json(uri, req_t, resp_t, transport, timeout, http_method)) { + error_struct = {}; return false; } if(resp_t.error.code || resp_t.error.message.size()) { + error_struct = resp_t.error; LOG_ERROR("RPC call of \"" << req_t.method << "\" returned error: " << resp_t.error.code << ", message: " << resp_t.error.message); return false; } @@ -122,6 +124,13 @@ namespace epee return true; } + template<class t_request, class t_response, class t_transport> + bool invoke_http_json_rpc(const boost::string_ref uri, std::string method_name, const t_request& out_struct, t_response& result_struct, t_transport& transport, std::chrono::milliseconds timeout = std::chrono::seconds(15), const boost::string_ref http_method = "GET", const std::string& req_id = "0") + { + epee::json_rpc::error error_struct; + return invoke_http_json_rpc(uri, method_name, out_struct, result_struct, error_struct, transport, timeout, http_method, req_id); + } + template<class t_command, class t_transport> bool invoke_http_json_rpc(const boost::string_ref uri, typename t_command::request& out_struct, typename t_command::response& result_struct, t_transport& transport, std::chrono::milliseconds timeout = std::chrono::seconds(15), const boost::string_ref http_method = "GET", const std::string& req_id = "0") { diff --git a/contrib/epee/src/CMakeLists.txt b/contrib/epee/src/CMakeLists.txt index 5c92e32bd..5201f59c2 100644 --- a/contrib/epee/src/CMakeLists.txt +++ b/contrib/epee/src/CMakeLists.txt @@ -27,9 +27,10 @@ # THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. add_library(epee STATIC byte_slice.cpp hex.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) + 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) -if (USE_READLINE AND (GNU_READLINE_FOUND OR DEPENDS AND NOT MINGW)) +if (USE_READLINE AND (GNU_READLINE_FOUND OR (DEPENDS AND NOT MINGW))) add_library(epee_readline STATIC readline_buffer.cpp) endif() @@ -62,7 +63,7 @@ target_link_libraries(epee ${OPENSSL_LIBRARIES} ${EXTRA_LIBRARIES}) -if (USE_READLINE AND (GNU_READLINE_FOUND OR DEPENDS AND NOT MINGW)) +if (USE_READLINE AND (GNU_READLINE_FOUND OR (DEPENDS AND NOT MINGW))) target_link_libraries(epee_readline PUBLIC easylogging diff --git a/contrib/epee/src/connection_basic.cpp b/contrib/epee/src/connection_basic.cpp index 7526dde26..3ce7a1057 100644 --- a/contrib/epee/src/connection_basic.cpp +++ b/contrib/epee/src/connection_basic.cpp @@ -136,6 +136,7 @@ connection_basic::connection_basic(boost::asio::ip::tcp::socket&& sock, std::sha socket_(GET_IO_SERVICE(sock), get_context(m_state.get())), m_want_close_connection(false), m_was_shutdown(false), + m_is_multithreaded(false), m_ssl_support(ssl_support) { // add nullptr checks if removed @@ -160,6 +161,7 @@ connection_basic::connection_basic(boost::asio::io_service &io_service, std::sha socket_(io_service, get_context(m_state.get())), m_want_close_connection(false), m_was_shutdown(false), + m_is_multithreaded(false), m_ssl_support(ssl_support) { // add nullptr checks if removed diff --git a/contrib/epee/src/int-util.cpp b/contrib/epee/src/int-util.cpp new file mode 100644 index 000000000..e9d0822e0 --- /dev/null +++ b/contrib/epee/src/int-util.cpp @@ -0,0 +1,48 @@ +// Copyright (c) 2019, The Monero Project +// +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without modification, are +// permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this list of +// conditions and the following disclaimer. +// +// 2. Redistributions in binary form must reproduce the above copyright notice, this list +// of conditions and the following disclaimer in the documentation and/or other +// materials provided with the distribution. +// +// 3. Neither the name of the copyright holder nor the names of its contributors may be +// used to endorse or promote products derived from this software without specific +// prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY +// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF +// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <boost/multiprecision/cpp_int.hpp> + +void div128_64(uint64_t dividend_hi, uint64_t dividend_lo, uint64_t divisor, uint64_t* quotient_hi, uint64_t *quotient_lo, uint64_t *remainder_hi, uint64_t *remainder_lo) +{ + typedef boost::multiprecision::uint128_t uint128_t; + + uint128_t dividend = dividend_hi; + dividend <<= 64; + dividend |= dividend_lo; + + uint128_t q, r; + divide_qr(dividend, uint128_t(divisor), q, r); + + *quotient_hi = ((q >> 64) & 0xffffffffffffffffull).convert_to<uint64_t>(); + *quotient_lo = (q & 0xffffffffffffffffull).convert_to<uint64_t>(); + if (remainder_hi) + *remainder_hi = ((r >> 64) & 0xffffffffffffffffull).convert_to<uint64_t>(); + if (remainder_lo) + *remainder_lo = (r & 0xffffffffffffffffull).convert_to<uint64_t>(); +} diff --git a/contrib/epee/src/mlog.cpp b/contrib/epee/src/mlog.cpp index 66dfabcdf..e96bf627f 100644 --- a/contrib/epee/src/mlog.cpp +++ b/contrib/epee/src/mlog.cpp @@ -100,7 +100,7 @@ static const char *get_default_categories(int level) switch (level) { case 0: - categories = "*:WARNING,net:FATAL,net.http:FATAL,net.ssl:FATAL,net.p2p:FATAL,net.cn:FATAL,global:INFO,verify:FATAL,serialization:FATAL,stacktrace:INFO,logging:INFO,msgwriter:INFO"; + categories = "*:WARNING,net:FATAL,net.http:FATAL,net.ssl:FATAL,net.p2p:FATAL,net.cn:FATAL,global:INFO,verify:FATAL,serialization:FATAL,daemon.rpc.payment:ERROR,stacktrace:INFO,logging:INFO,msgwriter:INFO"; break; case 1: categories = "*:INFO,global:INFO,stacktrace:INFO,logging:INFO,msgwriter:INFO,perf.*:DEBUG"; diff --git a/contrib/epee/src/net_ssl.cpp b/contrib/epee/src/net_ssl.cpp index 7d48d2a64..16454fce0 100644 --- a/contrib/epee/src/net_ssl.cpp +++ b/contrib/epee/src/net_ssl.cpp @@ -27,10 +27,13 @@ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <string.h> +#include <thread> #include <boost/asio/ssl.hpp> +#include <boost/lambda/lambda.hpp> #include <openssl/ssl.h> #include <openssl/pem.h> #include "misc_log_ex.h" +#include "net/net_helper.h" #include "net/net_ssl.h" #undef MONERO_DEFAULT_LOG_CATEGORY @@ -456,7 +459,11 @@ bool ssl_options_t::has_fingerprint(boost::asio::ssl::verify_context &ctx) const return false; } -bool ssl_options_t::handshake(boost::asio::ssl::stream<boost::asio::ip::tcp::socket> &socket, boost::asio::ssl::stream_base::handshake_type type, const std::string& host) const +bool ssl_options_t::handshake( + boost::asio::ssl::stream<boost::asio::ip::tcp::socket> &socket, + boost::asio::ssl::stream_base::handshake_type type, + const std::string& host, + std::chrono::milliseconds timeout) const { socket.next_layer().set_option(boost::asio::ip::tcp::no_delay(true)); @@ -502,8 +509,30 @@ bool ssl_options_t::handshake(boost::asio::ssl::stream<boost::asio::ip::tcp::soc }); } - boost::system::error_code ec; - socket.handshake(type, ec); + auto& io_service = GET_IO_SERVICE(socket); + boost::asio::steady_timer deadline(io_service, timeout); + deadline.async_wait([&socket](const boost::system::error_code& error) { + if (error != boost::asio::error::operation_aborted) + { + socket.next_layer().close(); + } + }); + + boost::system::error_code ec = boost::asio::error::would_block; + socket.async_handshake(type, boost::lambda::var(ec) = boost::lambda::_1); + if (io_service.stopped()) + { + io_service.reset(); + } + while (ec == boost::asio::error::would_block && !io_service.stopped()) + { + // should poll_one(), can't run_one() because it can block if there is + // another worker thread executing io_service's tasks + // TODO: once we get Boost 1.66+, replace with run_one_for/run_until + std::this_thread::sleep_for(std::chrono::milliseconds(30)); + io_service.poll_one(); + } + if (ec) { MERROR("SSL handshake failed, connection dropped: " << ec.message()); diff --git a/contrib/gitian/gitian-build.py b/contrib/gitian/gitian-build.py index 5913fda3a..a8d164c2c 100755 --- a/contrib/gitian/gitian-build.py +++ b/contrib/gitian/gitian-build.py @@ -5,6 +5,9 @@ import os import subprocess import sys +gsigs = 'https://github.com/monero-project/gitian.sigs.git' +gbrepo = 'https://github.com/devrandom/gitian-builder.git' + def setup(): global args, workdir programs = ['apt-cacher-ng', 'ruby', 'git', 'make', 'wget'] @@ -14,14 +17,21 @@ def setup(): programs += ['lxc', 'debootstrap'] if not args.no_apt: subprocess.check_call(['sudo', 'apt-get', 'install', '-qq'] + programs) - if not os.path.isdir('gitian.sigs'): - subprocess.check_call(['git', 'clone', 'https://github.com/monero-project/gitian.sigs.git']) - if not os.path.isdir('gitian-builder'): - subprocess.check_call(['git', 'clone', 'https://github.com/devrandom/gitian-builder.git']) - if not os.path.isdir('monero'): - subprocess.check_call(['git', 'clone', 'https://github.com/monero-project/monero.git']) - os.chdir('gitian-builder') + if not os.path.isdir('sigs'): + subprocess.check_call(['git', 'clone', gsigs, 'sigs']) + if not os.path.isdir('builder'): + subprocess.check_call(['git', 'clone', gbrepo, 'builder']) + os.chdir('builder') + subprocess.check_call(['git', 'config', 'user.email', 'gitianuser@localhost']) + subprocess.check_call(['git', 'config', 'user.name', 'gitianuser']) subprocess.check_call(['git', 'checkout', '963322de8420c50502c4cc33d4d7c0d84437b576']) + subprocess.check_call(['git', 'fetch', 'origin', '72c51f0bd2adec4eedab4dbd06c9229b9c4eb0e3']) + subprocess.check_call(['git', 'cherry-pick', '72c51f0bd2adec4eedab4dbd06c9229b9c4eb0e3']) + os.makedirs('inputs', exist_ok=True) + os.chdir('inputs') + if not os.path.isdir('monero'): + subprocess.check_call(['git', 'clone', args.url, 'monero']) + os.chdir('..') make_image_prog = ['bin/make-base-vm', '--suite', 'bionic', '--arch', 'amd64'] if args.docker: if not subprocess.call(['docker', '--help'], shell=False, stdout=subprocess.DEVNULL): @@ -39,40 +49,40 @@ def setup(): def build(): global args, workdir - os.makedirs('monero-binaries/' + args.version, exist_ok=True) + os.makedirs('out/' + args.version, exist_ok=True) print('\nBuilding Dependencies\n') - os.chdir('gitian-builder') + 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', '../monero/contrib/depends', 'download', 'SOURCES_PATH=' + os.getcwd() + '/cache/common']) + subprocess.check_call(['make', '-C', 'inputs/monero/contrib/depends', 'download', 'SOURCES_PATH=' + os.getcwd() + '/cache/common']) if args.linux: print('\nCompiling ' + args.version + ' Linux') - subprocess.check_call(['bin/gbuild', '-j', args.jobs, '-m', args.memory, '--commit', 'monero='+args.commit, '--url', 'monero='+args.url, '../monero/contrib/gitian/gitian-linux.yml']) - subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version+'-linux', '--destination', '../gitian.sigs/', '../monero/contrib/gitian/gitian-linux.yml']) - subprocess.check_call('mv build/out/monero-*.tar.bz2 ../monero-binaries/'+args.version, shell=True) + subprocess.check_call(['bin/gbuild', '-j', args.jobs, '-m', args.memory, '--commit', 'monero='+args.commit, '--url', 'monero='+args.url, 'inputs/monero/contrib/gitian/gitian-linux.yml']) + subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version+'-linux', '--destination', '../sigs/', 'inputs/monero/contrib/gitian/gitian-linux.yml']) + subprocess.check_call('mv build/out/monero-*.tar.bz2 ../out/'+args.version, shell=True) if args.windows: print('\nCompiling ' + args.version + ' Windows') - subprocess.check_call(['bin/gbuild', '-j', args.jobs, '-m', args.memory, '--commit', 'monero='+args.commit, '--url', 'monero='+args.url, '../monero/contrib/gitian/gitian-win.yml']) - subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version+'-win', '--destination', '../gitian.sigs/', '../monero/contrib/gitian/gitian-win.yml']) - subprocess.check_call('mv build/out/monero*.zip ../monero-binaries/'+args.version, shell=True) + subprocess.check_call(['bin/gbuild', '-j', args.jobs, '-m', args.memory, '--commit', 'monero='+args.commit, '--url', 'monero='+args.url, 'inputs/monero/contrib/gitian/gitian-win.yml']) + subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version+'-win', '--destination', '../sigs/', 'inputs/monero/contrib/gitian/gitian-win.yml']) + subprocess.check_call('mv build/out/monero*.zip ../out/'+args.version, shell=True) if args.macos: print('\nCompiling ' + args.version + ' MacOS') - subprocess.check_call(['bin/gbuild', '-j', args.jobs, '-m', args.memory, '--commit', 'monero='+args.commit, '--url', 'monero='+args.url, '../monero/contrib/gitian/gitian-osx.yml']) - subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version+'-osx', '--destination', '../gitian.sigs/', '../monero/contrib/gitian/gitian-osx.yml']) - subprocess.check_call('mv build/out/monero*.tar.bz2 ../monero-binaries/'+args.version, shell=True) + subprocess.check_call(['bin/gbuild', '-j', args.jobs, '-m', args.memory, '--commit', 'monero='+args.commit, '--url', 'monero'+args.url, 'inputs/monero/contrib/gitian/gitian-osx.yml']) + subprocess.check_call(['bin/gsign', '-p', args.sign_prog, '--signer', args.signer, '--release', args.version+'-osx', '--destination', '../sigs/', 'inputs/monero/contrib/gitian/gitian-osx.yml']) + subprocess.check_call('mv build/out/monero*.tar.bz2 ../out/'+args.version, shell=True) os.chdir(workdir) if args.commit_files: print('\nCommitting '+args.version+' Unsigned Sigs\n') - os.chdir('gitian.sigs') + os.chdir('sigs') subprocess.check_call(['git', 'add', args.version+'-linux/'+args.signer]) subprocess.check_call(['git', 'add', args.version+'-win/'+args.signer]) subprocess.check_call(['git', 'add', args.version+'-osx/'+args.signer]) @@ -81,14 +91,14 @@ def build(): def verify(): global args, workdir - os.chdir('gitian-builder') + os.chdir('builder') print('\nVerifying v'+args.version+' Linux\n') - subprocess.check_call(['bin/gverify', '-v', '-d', '../gitian.sigs/', '-r', args.version+'-linux', '../monero/contrib/gitian/gitian-linux.yml']) + subprocess.check_call(['bin/gverify', '-v', '-d', '../sigs/', '-r', args.version+'-linux', 'inputs/monero/contrib/gitian/gitian-linux.yml']) print('\nVerifying v'+args.version+' Windows\n') - subprocess.check_call(['bin/gverify', '-v', '-d', '../gitian.sigs/', '-r', args.version+'-win', '../monero/contrib/gitian/gitian-win.yml']) + subprocess.check_call(['bin/gverify', '-v', '-d', '../sigs/', '-r', args.version+'-win', 'inputs/monero/contrib/gitian/gitian-win.yml']) print('\nVerifying v'+args.version+' MacOS\n') - subprocess.check_call(['bin/gverify', '-v', '-d', '../gitian.sigs/', '-r', args.version+'-osx', '../monero/contrib/gitian/gitian-osx.yml']) + subprocess.check_call(['bin/gverify', '-v', '-d', '../sigs/', '-r', args.version+'-osx', 'inputs/monero/contrib/gitian/gitian-osx.yml']) os.chdir(workdir) def main(): @@ -142,7 +152,7 @@ def main(): os.environ['LXC_GUEST_IP'] = '10.0.3.5' # Disable MacOS build if no SDK found - if args.build and args.macos and not os.path.isfile('gitian-builder/inputs/MacOSX10.11.sdk.tar.gz'): + if args.build and args.macos and not os.path.isfile('builder/inputs/MacOSX10.11.sdk.tar.gz'): print('Cannot build for MacOS, SDK does not exist. Will build for other OSes') args.macos = False @@ -165,11 +175,10 @@ def main(): if args.setup: setup() - os.chdir('monero') + os.makedirs('builder/inputs/monero', exist_ok=True) + os.chdir('builder/inputs/monero') if args.pull: subprocess.check_call(['git', 'fetch', args.url, 'refs/pull/'+args.version+'/merge']) - os.chdir('../gitian-builder/inputs/monero') - subprocess.check_call(['git', 'fetch', args.url, 'refs/pull/'+args.version+'/merge']) args.commit = subprocess.check_output(['git', 'show', '-s', '--format=%H', 'FETCH_HEAD'], universal_newlines=True).strip() args.version = 'pull-' + args.version print(args.commit) |