aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/epee/include')
-rw-r--r--contrib/epee/include/misc_log_ex.h2
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.inl9
-rw-r--r--contrib/epee/include/net/http_auth.h6
-rw-r--r--contrib/epee/include/net/net_utils_base.h28
-rw-r--r--contrib/epee/include/serialization/keyvalue_serialization_overloads.h4
-rw-r--r--contrib/epee/include/wipeable_string.h70
6 files changed, 105 insertions, 14 deletions
diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h
index 7ac07d112..67fd93206 100644
--- a/contrib/epee/include/misc_log_ex.h
+++ b/contrib/epee/include/misc_log_ex.h
@@ -169,7 +169,7 @@ namespace debug
#define ASSERT_MES_AND_THROW(message) {LOG_ERROR(message); std::stringstream ss; ss << message; throw std::runtime_error(ss.str());}
-#define CHECK_AND_ASSERT_THROW_MES(expr, message) {if(!(expr)) ASSERT_MES_AND_THROW(message);}
+#define CHECK_AND_ASSERT_THROW_MES(expr, message) do {if(!(expr)) ASSERT_MES_AND_THROW(message);} while(0)
#ifndef CHECK_AND_ASSERT
diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl
index 00d03567c..04d884af2 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.inl
+++ b/contrib/epee/include/net/abstract_tcp_server2.inl
@@ -286,7 +286,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
{
CRITICAL_REGION_LOCAL( epee::net_utils::network_throttle_manager::network_throttle_manager::m_lock_get_global_throttle_in );
- epee::net_utils::network_throttle_manager::network_throttle_manager::get_global_throttle_in().handle_trafic_exact(bytes_transferred * 1024);
+ epee::net_utils::network_throttle_manager::network_throttle_manager::get_global_throttle_in().handle_trafic_exact(bytes_transferred);
}
double delay=0; // will be calculated - how much we should sleep to obey speed limit etc
@@ -297,7 +297,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
{
{ //_scope_dbg1("CRITICAL_REGION_LOCAL");
CRITICAL_REGION_LOCAL( epee::net_utils::network_throttle_manager::m_lock_get_global_throttle_in );
- delay = epee::net_utils::network_throttle_manager::get_global_throttle_in().get_sleep_time_after_tick( bytes_transferred ); // decission from global throttle
+ delay = epee::net_utils::network_throttle_manager::get_global_throttle_in().get_sleep_time_after_tick( bytes_transferred );
}
delay *= 0.5;
@@ -482,9 +482,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
//some data should be wrote to stream
//request complete
- if (speed_limit_is_enabled()) {
- sleep_before_packet(cb, 1, 1);
- }
+ // No sleeping here; sleeping is done once and for all in "handle_write"
m_send_que_lock.lock(); // *** critical ***
epee::misc_utils::auto_scope_leave_caller scope_exit_handler = epee::misc_utils::create_scope_leave_handler([&](){m_send_que_lock.unlock();});
@@ -607,6 +605,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
}
logger_handle_net_write(cb);
+ // The single sleeping that is needed for correctly handling "out" speed throttling
if (speed_limit_is_enabled()) {
sleep_before_packet(cb, 1, 1);
}
diff --git a/contrib/epee/include/net/http_auth.h b/contrib/epee/include/net/http_auth.h
index bf368e6f4..841cebc17 100644
--- a/contrib/epee/include/net/http_auth.h
+++ b/contrib/epee/include/net/http_auth.h
@@ -33,7 +33,7 @@
#include <functional>
#include <string>
#include <utility>
-
+#include "wipeable_string.h"
#include "http_base.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
@@ -48,12 +48,12 @@ namespace net_utils
struct login
{
login() : username(), password() {}
- login(std::string username_, std::string password_)
+ login(std::string username_, wipeable_string password_)
: username(std::move(username_)), password(std::move(password_))
{}
std::string username;
- std::string password;
+ wipeable_string password;
};
//! Implements RFC 2617 digest auth. Digests from RFC 7616 can be added.
diff --git a/contrib/epee/include/net/net_utils_base.h b/contrib/epee/include/net/net_utils_base.h
index 0e31ee86f..04e3fe6a4 100644
--- a/contrib/epee/include/net/net_utils_base.h
+++ b/contrib/epee/include/net/net_utils_base.h
@@ -166,15 +166,37 @@ namespace net_utils
BEGIN_KV_SERIALIZE_MAP()
uint8_t type = is_store ? this_ref.get_type_id() : 0;
- epee::serialization::selector<is_store>::serialize(type, stg, hparent_section, "type");
+ if (!epee::serialization::selector<is_store>::serialize(type, stg, hparent_section, "type"))
+ return false;
switch (type)
{
case ipv4_network_address::ID:
+ {
if (!is_store)
+ {
const_cast<network_address&>(this_ref) = ipv4_network_address{0, 0};
- KV_SERIALIZE(template as_mutable<ipv4_network_address>());
+ auto &addr = this_ref.template as_mutable<ipv4_network_address>();
+ if (epee::serialization::selector<is_store>::serialize(addr, stg, hparent_section, "addr"))
+ MDEBUG("Found as addr: " << this_ref.str());
+ else if (epee::serialization::selector<is_store>::serialize(addr, stg, hparent_section, "template as<ipv4_network_address>()"))
+ MDEBUG("Found as template as<ipv4_network_address>(): " << this_ref.str());
+ else if (epee::serialization::selector<is_store>::serialize(addr, stg, hparent_section, "template as_mutable<ipv4_network_address>()"))
+ MDEBUG("Found as template as_mutable<ipv4_network_address>(): " << this_ref.str());
+ else
+ {
+ MWARNING("Address not found");
+ return false;
+ }
+ }
+ else
+ {
+ auto &addr = this_ref.template as_mutable<ipv4_network_address>();
+ if (!epee::serialization::selector<is_store>::serialize(addr, stg, hparent_section, "addr"))
+ return false;
+ }
break;
- default: MERROR("Unsupported network address type: " << type); return false;
+ }
+ default: MERROR("Unsupported network address type: " << (unsigned)type); return false;
}
END_KV_SERIALIZE_MAP()
};
diff --git a/contrib/epee/include/serialization/keyvalue_serialization_overloads.h b/contrib/epee/include/serialization/keyvalue_serialization_overloads.h
index a94ecacc5..2e020b136 100644
--- a/contrib/epee/include/serialization/keyvalue_serialization_overloads.h
+++ b/contrib/epee/include/serialization/keyvalue_serialization_overloads.h
@@ -73,7 +73,7 @@ namespace epee
template<class serializible_type, class t_storage>
static bool unserialize_t_obj(serializible_type& obj, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{
- typename t_storage::hsection hchild_section = stg.open_section(pname, hparent_section, true);
+ typename t_storage::hsection hchild_section = stg.open_section(pname, hparent_section, false);
if(!hchild_section) return false;
return obj._load(stg, hchild_section);
}
@@ -90,7 +90,7 @@ namespace epee
static bool unserialize_t_obj(enableable<serializible_type>& obj, t_storage& stg, typename t_storage::hsection hparent_section, const char* pname)
{
obj.enabled = false;
- typename t_storage::hsection hchild_section = stg.open_section(pname, hparent_section, true);
+ typename t_storage::hsection hchild_section = stg.open_section(pname, hparent_section, false);
if(!hchild_section) return false;
obj.enabled = true;
return obj.v._load(stg, hchild_section);
diff --git a/contrib/epee/include/wipeable_string.h b/contrib/epee/include/wipeable_string.h
new file mode 100644
index 000000000..66d3e8e2b
--- /dev/null
+++ b/contrib/epee/include/wipeable_string.h
@@ -0,0 +1,70 @@
+// Copyright (c) 2017, 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.
+
+#pragma once
+
+#include <stddef.h>
+#include <vector>
+#include <string>
+
+namespace epee
+{
+ class wipeable_string
+ {
+ public:
+ wipeable_string() {}
+ wipeable_string(const wipeable_string &other);
+ wipeable_string(wipeable_string &&other);
+ wipeable_string(const std::string &other);
+ wipeable_string(std::string &&other);
+ wipeable_string(const char *s);
+ ~wipeable_string();
+ void wipe();
+ void push_back(char c);
+ void pop_back();
+ const char *data() const noexcept { return buffer.data(); }
+ size_t size() const noexcept { return buffer.size(); }
+ bool empty() const noexcept { return buffer.empty(); }
+ void resize(size_t sz);
+ void reserve(size_t sz);
+ void clear();
+ bool operator==(const wipeable_string &other) const noexcept { return buffer == other.buffer; }
+ bool operator!=(const wipeable_string &other) const noexcept { return buffer != other.buffer; }
+ wipeable_string &operator=(wipeable_string &&other);
+ wipeable_string &operator=(const wipeable_string &other);
+
+ static void set_wipe(void *(*f)(void*, size_t)) { wipefunc = f; }
+
+ private:
+ void grow(size_t sz, size_t reserved = 0);
+
+ private:
+ std::vector<char> buffer;
+ static void *(*wipefunc)(void*, size_t);
+ };
+}