aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/epee/include')
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.inl19
-rw-r--r--contrib/epee/include/net/net_helper.h5
-rw-r--r--contrib/epee/include/net/net_ssl.h6
3 files changed, 26 insertions, 4 deletions
diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl
index 8d96e4a84..e455d0204 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"
@@ -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);
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..d2c1c1a3a 100644
--- a/contrib/epee/include/net/net_ssl.h
+++ b/contrib/epee/include/net/net_ssl.h
@@ -128,7 +128,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