aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/epee/include')
-rw-r--r--contrib/epee/include/console_handler.h389
-rw-r--r--contrib/epee/include/copyable_atomic.h54
-rw-r--r--contrib/epee/include/math_helper.h12
-rw-r--r--contrib/epee/include/misc_log_ex.h57
-rw-r--r--contrib/epee/include/misc_os_dependent.h2
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.h22
-rw-r--r--contrib/epee/include/net/abstract_tcp_server2.inl15
-rw-r--r--contrib/epee/include/net/http_base.h2
-rw-r--r--contrib/epee/include/net/http_protocol_handler.h21
-rw-r--r--contrib/epee/include/net/http_protocol_handler.inl66
-rw-r--r--contrib/epee/include/net/http_server_cp2.h4
-rw-r--r--contrib/epee/include/net/http_server_handlers_map2.h46
-rw-r--r--contrib/epee/include/net/http_server_impl_base.h6
-rw-r--r--contrib/epee/include/net/levin_base.h28
-rw-r--r--contrib/epee/include/net/levin_client_async.h20
-rw-r--r--contrib/epee/include/net/levin_protocol_handler.h2
-rw-r--r--contrib/epee/include/net/levin_protocol_handler_async.h8
-rw-r--r--contrib/epee/include/net/local_ip.h4
-rw-r--r--contrib/epee/include/net/net_helper.h4
-rw-r--r--contrib/epee/include/net/net_parse_helpers.h2
-rw-r--r--contrib/epee/include/net/net_utils_base.h31
-rw-r--r--contrib/epee/include/net/protocol_switcher.h4
-rw-r--r--contrib/epee/include/profile_tools.h12
-rw-r--r--contrib/epee/include/reg_exp_definer.h12
-rw-r--r--contrib/epee/include/soci_helper.h8
-rw-r--r--contrib/epee/include/storages/portable_storage_from_json.h2
-rw-r--r--contrib/epee/include/string_tools.h54
-rw-r--r--contrib/epee/include/syncobj.h18
28 files changed, 597 insertions, 308 deletions
diff --git a/contrib/epee/include/console_handler.h b/contrib/epee/include/console_handler.h
index 238abc80c..778679e75 100644
--- a/contrib/epee/include/console_handler.h
+++ b/contrib/epee/include/console_handler.h
@@ -1,6 +1,6 @@
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
// All rights reserved.
-//
+//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
@@ -11,7 +11,7 @@
// * Neither the name of the Andrey N. Sabelnikov nor the
// names of its contributors may be used to endorse or promote products
// derived from this software without specific prior written permission.
-//
+//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -22,141 +22,301 @@
// 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 <atomic>
+#include <condition_variable>
+#include <functional>
+#include <mutex>
+#include <thread>
+
namespace epee
{
+ class async_stdin_reader
+ {
+ public:
+ async_stdin_reader()
+ : m_run(true)
+ , m_has_read_request(false)
+ , m_read_status(state_init)
+ {
+ m_reader_thread = std::thread(std::bind(&async_stdin_reader::reader_thread_func, this));
+ }
+ ~async_stdin_reader()
+ {
+ stop();
+ }
+ // Not thread safe. Only one thread can call this method at once.
+ bool get_line(std::string& line)
+ {
+ if (!start_read())
+ return false;
+ std::unique_lock<std::mutex> lock(m_response_mutex);
+ while (state_init == m_read_status)
+ {
+ m_response_cv.wait(lock);
+ }
- template<class t_server>
- bool empty_commands_handler(t_server* psrv, const std::string& command)
- {
- return true;
- }
-
+ bool res = false;
+ if (state_success == m_read_status)
+ {
+ line = m_line;
+ res = true;
+ }
- template<class t_server, class chain_handler>
- bool default_console_handler(t_server* psrv, chain_handler ch_handler, const std::string usage = "")
- {
- TRY_ENTRY();
- bool continue_handle = true;
- while(continue_handle)
+ m_read_status = state_init;
+
+ return res;
+ }
+
+ void stop()
+ {
+ if (m_run)
+ {
+ m_run.store(false, std::memory_order_relaxed);
+
+#if defined(WIN32)
+ ::CloseHandle(::GetStdHandle(STD_INPUT_HANDLE));
+#endif
+
+ m_request_cv.notify_one();
+ m_reader_thread.join();
+ }
+ }
+
+ private:
+ bool start_read()
+ {
+ std::unique_lock<std::mutex> lock(m_request_mutex);
+ if (!m_run.load(std::memory_order_relaxed) || m_has_read_request)
+ return false;
+
+ m_has_read_request = true;
+ m_request_cv.notify_one();
+ return true;
+ }
+
+ bool wait_read()
{
- char command_buff[400] = {0};
- std::string command;
- std::cin.getline(command_buff, 399);
- if(std::cin.eof() || std::cin.fail())
+ std::unique_lock<std::mutex> lock(m_request_mutex);
+ while (m_run.load(std::memory_order_relaxed) && !m_has_read_request)
{
- LOG_PRINT("std::cin.eof() or std::cin.fail(), stopping...", LOG_LEVEL_0);
- continue_handle = false;
- break;
+ m_request_cv.wait(lock);
}
- command = command_buff;
- if(!command.compare("exit") || !command.compare("q") )
+ if (m_has_read_request)
{
- psrv->send_stop_signal();
- continue_handle = false;
- }else if ( !command.compare(0, 7, "set_log"))
+ m_has_read_request = false;
+ return true;
+ }
+
+ return false;
+ }
+
+ bool wait_stdin_data()
+ {
+#if !defined(WIN32)
+ int stdin_fileno = ::fileno(stdin);
+
+ while (m_run.load(std::memory_order_relaxed))
{
- //parse set_log command
- if(command.size() != 9)
+ fd_set read_set;
+ FD_ZERO(&read_set);
+ FD_SET(stdin_fileno, &read_set);
+
+ struct timeval tv;
+ tv.tv_sec = 0;
+ tv.tv_usec = 100 * 1000;
+
+ int retval = ::select(stdin_fileno + 1, &read_set, NULL, NULL, &tv);
+ if (retval < 0)
+ return false;
+ else if (0 < retval)
+ return true;
+ }
+#endif
+
+ return true;
+ }
+
+ void reader_thread_func()
+ {
+ while (true)
+ {
+ if (!wait_read())
+ break;
+
+ std::string line;
+ bool read_ok = true;
+ if (wait_stdin_data())
{
- std::cout << "wrong syntax: " << command << std::endl << "use set_log n" << std::endl;
- continue;
+ if (m_run.load(std::memory_order_relaxed))
+ {
+ std::getline(std::cin, line);
+ read_ok = !std::cin.eof() && !std::cin.fail();
+ }
}
- int n = 0;
- if(!string_tools::get_xtype_from_string(n, command.substr(8, 1)))
+ else
{
- std::cout << "wrong syntax: " << command << std::endl << "use set_log n" << std::endl;
- continue;
+ read_ok = false;
+ }
+
+ {
+ std::unique_lock<std::mutex> lock(m_response_mutex);
+ if (m_run.load(std::memory_order_relaxed))
+ {
+ m_line = std::move(line);
+ m_read_status = read_ok ? state_success : state_error;
+ }
+ else
+ {
+ m_read_status = state_cancelled;
+ }
+ m_response_cv.notify_one();
}
- log_space::get_set_log_detalisation_level(true, n);
- LOG_PRINT_L0("New log level set " << n);
- }
- else if(ch_handler(psrv, command))
- continue;
- else
- {
- std::cout << "unknown command: " << command << std::endl;
- std::cout << usage;
}
}
+
+ enum t_state
+ {
+ state_init,
+ state_success,
+ state_error,
+ state_cancelled
+ };
+
+ private:
+ std::thread m_reader_thread;
+ std::atomic<bool> m_run;
+
+ std::string m_line;
+ bool m_has_read_request;
+ t_state m_read_status;
+
+ std::mutex m_request_mutex;
+ std::mutex m_response_mutex;
+ std::condition_variable m_request_cv;
+ std::condition_variable m_response_cv;
+ };
+
+
+ template<class t_server>
+ bool empty_commands_handler(t_server* psrv, const std::string& command)
+ {
return true;
- CATCH_ENTRY_L0("console_handler", false);
}
- template<class chain_handler>
- bool default_console_handler2(chain_handler ch_handler, const std::string usage)
+
+ class async_console_handler
{
- TRY_ENTRY();
- bool continue_handle = true;
- while(continue_handle)
+ public:
+ async_console_handler()
{
- char command_buff[400] = {0};
- std::string command;
- std::cin.getline(command_buff, 399);
- if(std::cin.eof() || std::cin.fail())
- {
+ }
- LOG_PRINT("std::cin.eof() or std::cin.fail(), stopping...", LOG_LEVEL_0);
- continue_handle = false;
- break;
- }
- command = command_buff;
+ template<class t_server, class chain_handler>
+ bool run(t_server* psrv, chain_handler ch_handler, const std::string& prompt = "#", const std::string& usage = "")
+ {
+ return run(prompt, usage, [&](const std::string& cmd) { return ch_handler(psrv, cmd); }, [&] { psrv->send_stop_signal(); });
+ }
- if(!command.compare("exit") || !command.compare("q") )
- {
- continue_handle = false;
- }else if ( !command.compare(0, 7, "set_log"))
+ template<class chain_handler>
+ bool run(chain_handler ch_handler, const std::string& prompt = "#", const std::string& usage = "")
+ {
+ return run(prompt, usage, [&](const std::string& cmd) { return ch_handler(cmd); }, [] { });
+ }
+
+ void stop()
+ {
+ m_stdin_reader.stop();
+ }
+
+ private:
+ template<typename t_cmd_handler, typename t_exit_handler>
+ bool run(const std::string& prompt, const std::string& usage, const t_cmd_handler& cmd_handler, const t_exit_handler& exit_handler)
+ {
+ TRY_ENTRY();
+ bool continue_handle = true;
+ while(continue_handle)
{
- //parse set_log command
- if(command.size() != 9)
+ if (!prompt.empty())
+ {
+ epee::log_space::set_console_color(epee::log_space::console_color_yellow, true);
+ std::cout << prompt;
+ if (' ' != prompt.back())
+ std::cout << ' ';
+ epee::log_space::reset_console_color();
+ std::cout.flush();
+ }
+
+ std::string command;
+ if(!m_stdin_reader.get_line(command))
+ {
+ LOG_PRINT("Failed to read line. Stopping...", LOG_LEVEL_0);
+ continue_handle = false;
+ break;
+ }
+
+ LOG_PRINT_L2("Read command: " << command);
+ if(0 == command.compare("exit") || 0 == command.compare("q"))
+ {
+ continue_handle = false;
+ }else if (!command.compare(0, 7, "set_log"))
+ {
+ //parse set_log command
+ if(command.size() != 9)
+ {
+ std::cout << "wrong syntax: " << command << std::endl << "use set_log n" << std::endl;
+ continue;
+ }
+ uint16_t n = 0;
+ if(!string_tools::get_xtype_from_string(n, command.substr(8, 1)))
+ {
+ std::cout << "wrong syntax: " << command << std::endl << "use set_log n" << std::endl;
+ continue;
+ }
+ log_space::get_set_log_detalisation_level(true, n);
+ LOG_PRINT_L0("New log level set " << n);
+ }else if (command.empty())
{
- std::cout << "wrong syntax: " << command << std::endl << "use set_log n" << std::endl;
continue;
}
- int n = 0;
- if(!string_tools::get_xtype_from_string(n, command.substr(8, 1)))
+ else if(cmd_handler(command))
{
- std::cout << "wrong syntax: " << command << std::endl << "use set_log n" << std::endl;
continue;
+ } else
+ {
+ std::cout << "unknown command: " << command << std::endl;
+ std::cout << usage;
}
- log_space::get_set_log_detalisation_level(true, n);
- LOG_PRINT_L0("New log level set " << n);
- }
- else if(ch_handler(command))
- continue;
- else
- {
- std::cout << "unknown command: " << command << std::endl;
- std::cout << usage;
}
+ exit_handler();
+ return true;
+ CATCH_ENTRY_L0("console_handler", false);
}
- return true;
- CATCH_ENTRY_L0("console_handler", false);
- }
-
+ private:
+ async_stdin_reader m_stdin_reader;
+ };
template<class t_server, class t_handler>
- bool start_default_console(t_server* ptsrv, t_handler handlr, const std::string& usage = "")
+ bool start_default_console(t_server* ptsrv, t_handler handlr, const std::string& prompt, const std::string& usage = "")
{
- boost::thread( boost::bind(default_console_handler<t_server, t_handler>, ptsrv, handlr, usage) );
+ std::shared_ptr<async_console_handler> console_handler = std::make_shared<async_console_handler>();
+ boost::thread(boost::bind(&async_console_handler::run<t_server, t_handler>, console_handler, ptsrv, handlr, prompt, usage)).detach();
return true;
}
template<class t_server>
- bool start_default_console(t_server* ptsrv, const std::string& usage = "")
+ bool start_default_console(t_server* ptsrv, const std::string& prompt, const std::string& usage = "")
{
- return start_default_console(ptsrv, empty_commands_handler<t_server>, usage);
+ return start_default_console(ptsrv, empty_commands_handler<t_server>, prompt, usage);
}
template<class t_server, class t_handler>
@@ -166,15 +326,16 @@ namespace epee
}
template<class t_server, class t_handler>
- bool run_default_console_handler_no_srv_param(t_server* ptsrv, t_handler handlr, const std::string& usage = "")
+ bool run_default_console_handler_no_srv_param(t_server* ptsrv, t_handler handlr, const std::string& prompt, const std::string& usage = "")
{
- return default_console_handler(ptsrv, boost::bind<bool>(no_srv_param_adapter<t_server, t_handler>, _1, _2, handlr), usage);
+ async_console_handler console_handler;
+ return console_handler.run(ptsrv, boost::bind<bool>(no_srv_param_adapter<t_server, t_handler>, _1, _2, handlr), prompt, usage);
}
template<class t_server, class t_handler>
- bool start_default_console_handler_no_srv_param(t_server* ptsrv, t_handler handlr, const std::string& usage = "")
+ bool start_default_console_handler_no_srv_param(t_server* ptsrv, t_handler handlr, const std::string& prompt, const std::string& usage = "")
{
- boost::thread( boost::bind(run_default_console_handler_no_srv_param<t_server, t_handler>, ptsrv, handlr, usage) );
+ boost::thread( boost::bind(run_default_console_handler_no_srv_param<t_server, t_handler>, ptsrv, handlr, prompt, usage) );
return true;
}
@@ -209,7 +370,8 @@ namespace epee
typedef std::map<std::string, std::pair<console_command_handler, std::string> > command_handlers_map;
std::unique_ptr<boost::thread> m_console_thread;
command_handlers_map m_command_handlers;
- public:
+ async_console_handler m_console_handler;
+ public:
std::string get_usage()
{
std::stringstream ss;
@@ -217,7 +379,7 @@ namespace epee
for(auto& x:m_command_handlers)
if(x.first.size() > max_command_len)
max_command_len = x.first.size();
-
+
for(auto& x:m_command_handlers)
{
ss.width(max_command_len + 3);
@@ -255,24 +417,22 @@ namespace epee
start_default_console_handler_no_srv_param(&srv, boost::bind(&console_handlers_binder::process_command_str, this, _1));
return true;
}*/
-
- bool start_handling(const std::string& usage_string = "")
+
+ bool start_handling(const std::string& prompt, const std::string& usage_string = "")
{
- m_console_thread.reset(new boost::thread(boost::bind(&console_handlers_binder::run_handling, this, usage_string) ));
+ m_console_thread.reset(new boost::thread(boost::bind(&console_handlers_binder::run_handling, this, prompt, usage_string)));
+ m_console_thread->detach();
return true;
}
- bool stop_handling()
+ void stop_handling()
{
- if(m_console_thread.get())
- m_console_thread->interrupt();
- return true;
+ m_console_handler.stop();
}
-
- bool run_handling(const std::string usage_string)
+ bool run_handling(const std::string& prompt, const std::string& usage_string)
{
- return default_console_handler2(boost::bind(&console_handlers_binder::process_command_str, this, _1), usage_string);
+ return m_console_handler.run(boost::bind(&console_handlers_binder::process_command_str, this, _1), prompt, usage_string);
}
/*template<class t_srv>
@@ -280,7 +440,6 @@ namespace epee
{
return run_default_console_handler_no_srv_param(&srv, boost::bind<bool>(&console_handlers_binder::process_command_str, this, _1), usage_string);
}*/
-
};
/* work around because of broken boost bind */
@@ -292,19 +451,23 @@ namespace epee
return console_handlers_binder::process_command_str(cmd);
}
public:
- bool start_handling(t_server* psrv, const std::string& usage_string = "")
+ bool start_handling(t_server* psrv, const std::string& prompt, const std::string& usage_string = "")
{
- boost::thread(boost::bind(&srv_console_handlers_binder<t_server>::run_handling, this, psrv, usage_string) );
+ boost::thread(boost::bind(&srv_console_handlers_binder<t_server>::run_handling, this, psrv, prompt, usage_string)).detach();
return true;
}
- bool run_handling(t_server* psrv, const std::string usage_string)
+ bool run_handling(t_server* psrv, const std::string& prompt, const std::string& usage_string)
{
- return default_console_handler(psrv, boost::bind(&srv_console_handlers_binder<t_server>::process_command_str, this, _1, _2), usage_string);
+ return m_console_handler.run(psrv, boost::bind(&srv_console_handlers_binder<t_server>::process_command_str, this, _1, _2), prompt, usage_string);
}
- };
+ void stop_handling()
+ {
+ m_console_handler.stop();
+ }
+ private:
+ async_console_handler m_console_handler;
+ };
}
-
-
diff --git a/contrib/epee/include/copyable_atomic.h b/contrib/epee/include/copyable_atomic.h
new file mode 100644
index 000000000..6b5691ab1
--- /dev/null
+++ b/contrib/epee/include/copyable_atomic.h
@@ -0,0 +1,54 @@
+// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of the Andrey N. Sabelnikov nor the
+// names of its contributors may be used to endorse or promote products
+// derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
+// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+#pragma once
+
+#include <atomic>
+
+namespace epee
+{
+ class copyable_atomic: public std::atomic<uint32_t>
+ {
+ public:
+ copyable_atomic()
+ {};
+ copyable_atomic(const copyable_atomic& a):std::atomic<uint32_t>(a.load())
+ {}
+ copyable_atomic& operator= (const copyable_atomic& a)
+ {
+ store(a.load());
+ return *this;
+ }
+ uint32_t operator++()
+ {
+ return std::atomic<uint32_t>::operator++();
+ }
+ uint32_t operator++(int fake)
+ {
+ return std::atomic<uint32_t>::operator++(fake);
+ }
+ };
+} \ No newline at end of file
diff --git a/contrib/epee/include/math_helper.h b/contrib/epee/include/math_helper.h
index 44efd4682..349d6d822 100644
--- a/contrib/epee/include/math_helper.h
+++ b/contrib/epee/include/math_helper.h
@@ -154,7 +154,7 @@ namespace math_helper
#endif
//#ifdef WINDOWS_PLATFORM_EX
- template<boost::uint64_t default_time_window>
+ template<uint64_t default_time_window>
class speed
{
public:
@@ -167,7 +167,7 @@ namespace math_helper
bool chick()
{
#ifndef DEBUG_STUB
- boost::uint64_t ticks = misc_utils::get_tick_count();
+ uint64_t ticks = misc_utils::get_tick_count();
CRITICAL_REGION_BEGIN(m_lock);
m_chicks.push_back(ticks);
CRITICAL_REGION_END();
@@ -192,10 +192,10 @@ namespace math_helper
}
private:
- bool flush(boost::uint64_t ticks)
+ bool flush(uint64_t ticks)
{
CRITICAL_REGION_BEGIN(m_lock);
- std::list<boost::uint64_t>::iterator it = m_chicks.begin();
+ std::list<uint64_t>::iterator it = m_chicks.begin();
while(it != m_chicks.end())
{
if(*it + m_time_window < ticks)
@@ -207,8 +207,8 @@ namespace math_helper
return true;
}
- std::list<boost::uint64_t> m_chicks;
- boost::uint64_t m_time_window;
+ std::list<uint64_t> m_chicks;
+ uint64_t m_time_window;
size_t m_last_speed_value;
critical_section m_lock;
};
diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h
index 446d4bd3b..f2bd03b02 100644
--- a/contrib/epee/include/misc_log_ex.h
+++ b/contrib/epee/include/misc_log_ex.h
@@ -29,6 +29,7 @@
#define _MISC_LOG_EX_H_
//#include <windows.h>
+#include <atomic>
#include <string>
#include <iostream>
#include <sstream>
@@ -43,17 +44,20 @@
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
+#if defined(WIN32)
+#include <io.h>
+#else
+#include <unistd.h>
+#endif
+
#include "static_initializer.h"
#include "string_tools.h"
#include "time_helper.h"
#include "misc_os_dependent.h"
-
#include "syncobj.h"
-
-
#define LOG_LEVEL_SILENT -1
#define LOG_LEVEL_0 0
#define LOG_LEVEL_1 1
@@ -64,8 +68,6 @@
#define LOG_LEVEL_MAX LOG_LEVEL_4
-
-
#define LOGGER_NULL 0
#define LOGGER_FILE 1
#define LOGGER_DEBUGGER 2
@@ -124,7 +126,7 @@ namespace log_space
virtual bool out_buffer( const char* buffer, int buffer_len , int log_level, int color, const char* plog_name = NULL)=0;
virtual int get_type(){return 0;}
- virtual bool set_max_logfile_size(boost::uint64_t max_size){return true;};
+ virtual bool set_max_logfile_size(uint64_t max_size){return true;};
virtual bool set_log_rotate_cmd(const std::string& cmd){return true;};
};
@@ -198,8 +200,29 @@ namespace log_space
};
#endif
+ inline bool is_stdout_a_tty()
+ {
+ static std::atomic<bool> initialized(false);
+ static std::atomic<bool> is_a_tty(false);
+
+ if (!initialized.load(std::memory_order_acquire))
+ {
+#if defined(WIN32)
+ is_a_tty.store(0 != _isatty(_fileno(stdout)), std::memory_order_relaxed);
+#else
+ is_a_tty.store(0 != isatty(fileno(stdout)), std::memory_order_relaxed);
+#endif
+ initialized.store(true, std::memory_order_release);
+ }
+
+ return is_a_tty.load(std::memory_order_relaxed);
+ }
+
inline void set_console_color(int color, bool bright)
{
+ if (!is_stdout_a_tty())
+ return;
+
switch(color)
{
case console_color_default:
@@ -315,11 +338,15 @@ namespace log_space
}
inline void reset_console_color() {
+ if (!is_stdout_a_tty())
+ return;
+
#ifdef WIN32
HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(h_stdout, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
#else
std::cout << "\033[0m";
+ std::cout.flush();
#endif
}
@@ -384,7 +411,7 @@ namespace log_space
}
}
- //boost::uint32_t b = 0;
+ //uint32_t b = 0;
//::WriteConsoleA(::GetStdHandle(STD_OUTPUT_HANDLE), ptarget_buf, buffer_len, (DWORD*)&b, 0);
std::cout << ptarget_buf;
if(pallocated_buf) delete [] pallocated_buf;
@@ -459,7 +486,7 @@ namespace log_space
std::ofstream* m_pdefault_file_stream;
std::string m_log_rotate_cmd;
std::string m_default_log_filename;
- boost::uint64_t m_max_logfile_size;
+ uint64_t m_max_logfile_size;
std::ofstream* add_new_stream_and_open(const char* pstream_name)
@@ -474,7 +501,7 @@ namespace log_space
return pstream;
}
- bool set_max_logfile_size(boost::uint64_t max_size)
+ bool set_max_logfile_size(uint64_t max_size)
{
m_max_logfile_size = max_size;
return true;
@@ -508,7 +535,7 @@ namespace log_space
if(m_max_logfile_size)
{
std::ofstream::pos_type pt = m_target_file_stream->tellp();
- boost::uint64_t current_sz = pt;
+ uint64_t current_sz = pt;
if(current_sz > m_max_logfile_size)
{
std::cout << "current_sz= " << current_sz << " m_max_logfile_size= " << m_max_logfile_size << std::endl;
@@ -579,7 +606,7 @@ namespace log_space
std::for_each(m_log_streams.begin(), m_log_streams.end(), delete_ptr());
}
- bool set_max_logfile_size(boost::uint64_t max_size)
+ bool set_max_logfile_size(uint64_t max_size)
{
for(streams_container::iterator it = m_log_streams.begin(); it!=m_log_streams.end();it++)
it->first->set_max_logfile_size(max_size);
@@ -725,7 +752,7 @@ namespace log_space
{
}
- bool set_max_logfile_size(boost::uint64_t max_size)
+ bool set_max_logfile_size(uint64_t max_size)
{
CRITICAL_REGION_BEGIN(m_critical_sec);
m_log_target.set_max_logfile_size(max_size);
@@ -895,7 +922,7 @@ namespace log_space
return res;
}
- static bool set_max_logfile_size(boost::uint64_t file_size)
+ static bool set_max_logfile_size(uint64_t file_size)
{
logger* plogger = get_or_create_instance();
if(!plogger) return false;
@@ -1004,9 +1031,9 @@ POP_WARNINGS
return is_need;
}
- static boost::uint64_t get_set_err_count(bool is_need_set = false, boost::uint64_t err_val = false)
+ static uint64_t get_set_err_count(bool is_need_set = false, uint64_t err_val = false)
{
- static boost::uint64_t err_count = 0;
+ static uint64_t err_count = 0;
if(is_need_set)
err_count = err_val;
diff --git a/contrib/epee/include/misc_os_dependent.h b/contrib/epee/include/misc_os_dependent.h
index 0850c7c07..4d9c991e4 100644
--- a/contrib/epee/include/misc_os_dependent.h
+++ b/contrib/epee/include/misc_os_dependent.h
@@ -48,7 +48,7 @@ namespace epee
namespace misc_utils
{
- inline boost::uint64_t get_tick_count()
+ inline uint64_t get_tick_count()
{
#if defined(_MSC_VER)
return ::GetTickCount64();
diff --git a/contrib/epee/include/net/abstract_tcp_server2.h b/contrib/epee/include/net/abstract_tcp_server2.h
index d49b8f864..29bf59a57 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.h
+++ b/contrib/epee/include/net/abstract_tcp_server2.h
@@ -57,7 +57,7 @@ namespace net_utils
struct i_connection_filter
{
- virtual bool is_remote_ip_allowed(boost::uint32_t adress)=0;
+ virtual bool is_remote_ip_allowed(uint32_t adress)=0;
protected:
virtual ~i_connection_filter(){}
};
@@ -76,7 +76,7 @@ namespace net_utils
typedef typename t_protocol_handler::connection_context t_connection_context;
/// Construct a connection with the given io_service.
explicit connection(boost::asio::io_service& io_service,
- typename t_protocol_handler::config_type& config, volatile boost::uint32_t& sock_count, i_connection_filter * &pfilter);
+ typename t_protocol_handler::config_type& config, volatile uint32_t& sock_count, i_connection_filter * &pfilter);
virtual ~connection();
/// Get the socket associated with the connection.
@@ -117,11 +117,11 @@ namespace net_utils
boost::array<char, 8192> buffer_;
t_connection_context context;
- volatile boost::uint32_t m_want_close_connection;
+ volatile uint32_t m_want_close_connection;
std::atomic<bool> m_was_shutdown;
critical_section m_send_que_lock;
std::list<std::string> m_send_que;
- volatile boost::uint32_t& m_ref_sockets_count;
+ volatile uint32_t& m_ref_sockets_count;
i_connection_filter* &m_pfilter;
volatile bool m_is_multithreaded;
@@ -156,7 +156,7 @@ namespace net_utils
bool run_server(size_t threads_count, bool wait = true);
/// wait for service workers stop
- bool timed_wait_server_stop(boost::uint64_t wait_mseconds);
+ bool timed_wait_server_stop(uint64_t wait_mseconds);
/// Stop the server.
void send_stop_signal();
@@ -171,9 +171,9 @@ namespace net_utils
void set_connection_filter(i_connection_filter* pfilter);
- bool connect(const std::string& adr, const std::string& port, boost::uint32_t conn_timeot, t_connection_context& cn, const std::string& bind_ip = "0.0.0.0");
+ bool connect(const std::string& adr, const std::string& port, uint32_t conn_timeot, t_connection_context& cn, const std::string& bind_ip = "0.0.0.0");
template<class t_callback>
- bool connect_async(const std::string& adr, const std::string& port, boost::uint32_t conn_timeot, t_callback cb, const std::string& bind_ip = "0.0.0.0");
+ bool connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeot, t_callback cb, const std::string& bind_ip = "0.0.0.0");
typename t_protocol_handler::config_type& get_config_object(){return m_config;}
@@ -191,13 +191,13 @@ namespace net_utils
m_timer(io_serice)
{}
boost::asio::deadline_timer m_timer;
- boost::uint64_t m_period;
+ uint64_t m_period;
};
template <class t_handler>
struct idle_callback_conext: public idle_callback_conext_base
{
- idle_callback_conext(boost::asio::io_service& io_serice, t_handler& h, boost::uint64_t period):
+ idle_callback_conext(boost::asio::io_service& io_serice, t_handler& h, uint64_t period):
idle_callback_conext_base(io_serice),
m_handler(h)
{this->m_period = period;}
@@ -210,7 +210,7 @@ namespace net_utils
};
template<class t_handler>
- bool add_idle_handler(t_handler t_callback, boost::uint64_t timeout_ms)
+ bool add_idle_handler(t_handler t_callback, uint64_t timeout_ms)
{
boost::shared_ptr<idle_callback_conext_base> ptr(new idle_callback_conext<t_handler>(io_service_, t_callback, timeout_ms));
//needed call handler here ?...
@@ -258,7 +258,7 @@ namespace net_utils
connection_ptr new_connection_;
std::atomic<bool> m_stop_signal_sent;
uint32_t m_port;
- volatile boost::uint32_t m_sockets_count;
+ volatile uint32_t m_sockets_count;
std::string m_address;
std::string m_thread_name_prefix;
size_t m_threads_count;
diff --git a/contrib/epee/include/net/abstract_tcp_server2.inl b/contrib/epee/include/net/abstract_tcp_server2.inl
index 1d6a1662f..236bc1599 100644
--- a/contrib/epee/include/net/abstract_tcp_server2.inl
+++ b/contrib/epee/include/net/abstract_tcp_server2.inl
@@ -49,10 +49,9 @@ PRAGMA_WARNING_DISABLE_VS(4355)
template<class t_protocol_handler>
connection<t_protocol_handler>::connection(boost::asio::io_service& io_service,
- typename t_protocol_handler::config_type& config, volatile boost::uint32_t& sock_count, i_connection_filter* &pfilter)
+ typename t_protocol_handler::config_type& config, volatile uint32_t& sock_count, i_connection_filter* &pfilter)
: strand_(io_service),
socket_(io_service),
- //context(typename boost::value_initialized<t_connection_context>())
m_protocol_handler(this, config, context),
m_want_close_connection(0),
m_was_shutdown(0),
@@ -217,6 +216,8 @@ PRAGMA_WARNING_DISABLE_VS(4355)
if (!e)
{
LOG_PRINT("[sock " << socket_.native_handle() << "] RECV " << bytes_transferred, LOG_LEVEL_4);
+ context.m_last_recv = time(NULL);
+ context.m_recv_cnt += bytes_transferred;
bool recv_res = m_protocol_handler.handle_recv(buffer_.data(), bytes_transferred);
if(!recv_res)
{
@@ -294,6 +295,8 @@ PRAGMA_WARNING_DISABLE_VS(4355)
return false;
LOG_PRINT("[sock " << socket_.native_handle() << "] SEND " << cb, LOG_LEVEL_4);
+ context.m_last_send = time(NULL);
+ context.m_send_cnt += cb;
//some data should be wrote to stream
//request complete
@@ -473,8 +476,8 @@ DISABLE_GCC_WARNING(maybe-uninitialized)
uint32_t p = 0;
if (port.size() && !string_tools::get_xtype_from_string(p, port)) {
+ LOG_ERROR("Failed to convert port no = " << port);
return false;
- LOG_ERROR("Failed to convert port no = port");
}
return this->init_server(p, address);
}
@@ -586,7 +589,7 @@ POP_WARNINGS
}
//---------------------------------------------------------------------------------
template<class t_protocol_handler>
- bool boosted_tcp_server<t_protocol_handler>::timed_wait_server_stop(boost::uint64_t wait_mseconds)
+ bool boosted_tcp_server<t_protocol_handler>::timed_wait_server_stop(uint64_t wait_mseconds)
{
TRY_ENTRY();
boost::chrono::milliseconds ms(wait_mseconds);
@@ -641,7 +644,7 @@ POP_WARNINGS
}
//---------------------------------------------------------------------------------
template<class t_protocol_handler>
- bool boosted_tcp_server<t_protocol_handler>::connect(const std::string& adr, const std::string& port, boost::uint32_t conn_timeout, t_connection_context& conn_context, const std::string& bind_ip)
+ bool boosted_tcp_server<t_protocol_handler>::connect(const std::string& adr, const std::string& port, uint32_t conn_timeout, t_connection_context& conn_context, const std::string& bind_ip)
{
TRY_ENTRY();
@@ -732,7 +735,7 @@ POP_WARNINGS
}
//---------------------------------------------------------------------------------
template<class t_protocol_handler> template<class t_callback>
- bool boosted_tcp_server<t_protocol_handler>::connect_async(const std::string& adr, const std::string& port, boost::uint32_t conn_timeout, t_callback cb, const std::string& bind_ip)
+ bool boosted_tcp_server<t_protocol_handler>::connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeout, t_callback cb, const std::string& bind_ip)
{
TRY_ENTRY();
connection_ptr new_connection_l(new connection<t_protocol_handler>(io_service_, m_config, m_sockets_count, m_pfilter) );
diff --git a/contrib/epee/include/net/http_base.h b/contrib/epee/include/net/http_base.h
index 6de537a4c..49b0839b2 100644
--- a/contrib/epee/include/net/http_base.h
+++ b/contrib/epee/include/net/http_base.h
@@ -127,7 +127,7 @@ namespace net_utils
std::string schema;
std::string host;
std::string uri;
- boost::uint64_t port;
+ uint64_t port;
uri_content m_uri_content;
};
diff --git a/contrib/epee/include/net/http_protocol_handler.h b/contrib/epee/include/net/http_protocol_handler.h
index 4aebcf2aa..4bf48750e 100644
--- a/contrib/epee/include/net/http_protocol_handler.h
+++ b/contrib/epee/include/net/http_protocol_handler.h
@@ -55,10 +55,11 @@ namespace net_utils
/************************************************************************/
/* */
/************************************************************************/
+ template<class t_connection_context = net_utils::connection_context_base>
class simple_http_connection_handler
{
public:
- typedef net_utils::connection_context_base connection_context;
+ typedef t_connection_context connection_context;//t_connection_context net_utils::connection_context_base connection_context;
typedef http_server_config config_type;
simple_http_connection_handler(i_service_endpoint* psnd_hndlr, config_type& config);
@@ -141,30 +142,32 @@ namespace net_utils
i_service_endpoint* m_psnd_hndlr;
};
-
+ template<class t_connection_context>
struct i_http_server_handler
{
virtual ~i_http_server_handler(){}
- virtual bool handle_http_request(const http_request_info& query_info, http_response_info& response, const net_utils::connection_context_base& m_conn_context)=0;
+ virtual bool handle_http_request(const http_request_info& query_info, http_response_info& response, t_connection_context& m_conn_context)=0;
virtual bool init_server_thread(){return true;}
virtual bool deinit_server_thread(){return true;}
};
-
+ template<class t_connection_context>
struct custum_handler_config: public http_server_config
{
- i_http_server_handler* m_phandler;
+ i_http_server_handler<t_connection_context>* m_phandler;
};
/************************************************************************/
/* */
/************************************************************************/
- class http_custom_handler: public simple_http_connection_handler
+
+ template<class t_connection_context = net_utils::connection_context_base>
+ class http_custom_handler: public simple_http_connection_handler<t_connection_context>
{
public:
- typedef custum_handler_config config_type;
+ typedef custum_handler_config<t_connection_context> config_type;
- http_custom_handler(i_service_endpoint* psnd_hndlr, config_type& config, const net_utils::connection_context_base& conn_context):simple_http_connection_handler(psnd_hndlr, config),
+ http_custom_handler(i_service_endpoint* psnd_hndlr, config_type& config, t_connection_context& conn_context):simple_http_connection_handler<t_connection_context>(psnd_hndlr, config),
m_config(config),
m_conn_context(conn_context)
{}
@@ -198,7 +201,7 @@ namespace net_utils
private:
//simple_http_connection_handler::config_type m_stub_config;
config_type& m_config;
- const net_utils::connection_context_base& m_conn_context;
+ t_connection_context& m_conn_context;
};
}
}
diff --git a/contrib/epee/include/net/http_protocol_handler.inl b/contrib/epee/include/net/http_protocol_handler.inl
index 810c46db9..b8eeb5993 100644
--- a/contrib/epee/include/net/http_protocol_handler.inl
+++ b/contrib/epee/include/net/http_protocol_handler.inl
@@ -191,8 +191,8 @@ namespace net_utils
//--------------------------------------------------------------------------------------------
- inline
- simple_http_connection_handler::simple_http_connection_handler(i_service_endpoint* psnd_hndlr, config_type& config):
+ template<class t_connection_context>
+ simple_http_connection_handler<t_connection_context>::simple_http_connection_handler(i_service_endpoint* psnd_hndlr, config_type& config):
m_state(http_state_retriving_comand_line),
m_body_transfer_type(http_body_transfer_undefined),
m_is_stop_handling(false),
@@ -205,7 +205,8 @@ namespace net_utils
}
//--------------------------------------------------------------------------------------------
- inline bool simple_http_connection_handler::set_ready_state()
+ template<class t_connection_context>
+ bool simple_http_connection_handler<t_connection_context>::set_ready_state()
{
m_is_stop_handling = false;
m_state = http_state_retriving_comand_line;
@@ -215,7 +216,8 @@ namespace net_utils
return true;
}
//--------------------------------------------------------------------------------------------
- inline bool simple_http_connection_handler::handle_recv(const void* ptr, size_t cb)
+ template<class t_connection_context>
+ bool simple_http_connection_handler<t_connection_context>::handle_recv(const void* ptr, size_t cb)
{
std::string buf((const char*)ptr, cb);
//LOG_PRINT_L0("HTTP_RECV: " << ptr << "\r\n" << buf);
@@ -227,7 +229,8 @@ namespace net_utils
return res;
}
//--------------------------------------------------------------------------------------------
- inline bool simple_http_connection_handler::handle_buff_in(std::string& buf)
+ template<class t_connection_context>
+ bool simple_http_connection_handler<t_connection_context>::handle_buff_in(std::string& buf)
{
if(m_cache.size())
@@ -324,9 +327,10 @@ namespace net_utils
}
//--------------------------------------------------------------------------------------------
- inline bool simple_http_connection_handler::handle_invoke_query_line()
+ template<class t_connection_context>
+ bool simple_http_connection_handler<t_connection_context>::handle_invoke_query_line()
{
- LOG_FRAME("simple_http_connection_handler::handle_recognize_protocol_out(*)", LOG_LEVEL_3);
+ LOG_FRAME("simple_http_connection_handler<t_connection_context>::handle_recognize_protocol_out(*)", LOG_LEVEL_3);
STATIC_REGEXP_EXPR_1(rexp_match_command_line, "^(((OPTIONS)|(GET)|(HEAD)|(POST)|(PUT)|(DELETE)|(TRACE)) (\\S+) HTTP/(\\d+).(\\d+))\r?\n", boost::regex::icase | boost::regex::normal);
// 123 4 5 6 7 8 9 10 11 12
@@ -348,14 +352,15 @@ namespace net_utils
}else
{
m_state = http_state_error;
- LOG_ERROR("simple_http_connection_handler::handle_invoke_query_line(): Failed to match first line: " << m_cache);
+ LOG_ERROR("simple_http_connection_handler<t_connection_context>::handle_invoke_query_line(): Failed to match first line: " << m_cache);
return false;
}
return false;
}
//--------------------------------------------------------------------------------------------
- inline std::string::size_type simple_http_connection_handler::match_end_of_header(const std::string& buf)
+ template<class t_connection_context>
+ std::string::size_type simple_http_connection_handler<t_connection_context>::match_end_of_header(const std::string& buf)
{
//Here we returning head size, including terminating sequence (\r\n\r\n or \n\n)
@@ -368,18 +373,19 @@ namespace net_utils
return res;
}
//--------------------------------------------------------------------------------------------
- inline bool simple_http_connection_handler::analize_cached_request_header_and_invoke_state(size_t pos)
+ template<class t_connection_context>
+ bool simple_http_connection_handler<t_connection_context>::analize_cached_request_header_and_invoke_state(size_t pos)
{
//LOG_PRINT_L4("HTTP HEAD:\r\n" << m_cache.substr(0, pos));
- LOG_FRAME("simple_http_connection_handler::analize_cached_request_header_and_invoke_state(*)", LOG_LEVEL_3);
+ LOG_FRAME("simple_http_connection_handler<t_connection_context>::analize_cached_request_header_and_invoke_state(*)", LOG_LEVEL_3);
m_query_info.m_full_request_buf_size = pos;
m_query_info.m_request_head.assign(m_cache.begin(), m_cache.begin()+pos);
if(!parse_cached_header(m_query_info.m_header_info, m_cache, pos))
{
- LOG_ERROR("simple_http_connection_handler::analize_cached_request_header_and_invoke_state(): failed to anilize request header: " << m_cache);
+ LOG_ERROR("simple_http_connection_handler<t_connection_context>::analize_cached_request_header_and_invoke_state(): failed to anilize request header: " << m_cache);
m_state = http_state_error;
}
@@ -394,7 +400,7 @@ namespace net_utils
m_body_transfer_type = http_body_transfer_measure;
if(!get_len_from_content_lenght(m_query_info.m_header_info.m_content_length, m_len_summary))
{
- LOG_ERROR("simple_http_connection_handler::analize_cached_request_header_and_invoke_state(): Failed to get_len_from_content_lenght();, m_query_info.m_content_length="<<m_query_info.m_header_info.m_content_length);
+ LOG_ERROR("simple_http_connection_handler<t_connection_context>::analize_cached_request_header_and_invoke_state(): Failed to get_len_from_content_lenght();, m_query_info.m_content_length="<<m_query_info.m_header_info.m_content_length);
m_state = http_state_error;
return false;
}
@@ -415,7 +421,8 @@ namespace net_utils
return true;
}
//-----------------------------------------------------------------------------------
- inline bool simple_http_connection_handler::handle_retriving_query_body()
+ template<class t_connection_context>
+ bool simple_http_connection_handler<t_connection_context>::handle_retriving_query_body()
{
switch(m_body_transfer_type)
{
@@ -426,7 +433,7 @@ namespace net_utils
case http_body_transfer_multipart:
case http_body_transfer_undefined:
default:
- LOG_ERROR("simple_http_connection_handler::handle_retriving_query_body(): Unexpected m_body_query_type state:" << m_body_transfer_type);
+ LOG_ERROR("simple_http_connection_handler<t_connection_context>::handle_retriving_query_body(): Unexpected m_body_query_type state:" << m_body_transfer_type);
m_state = http_state_error;
return false;
}
@@ -434,7 +441,8 @@ namespace net_utils
return true;
}
//-----------------------------------------------------------------------------------
- inline bool simple_http_connection_handler::handle_query_measure()
+ template<class t_connection_context>
+ bool simple_http_connection_handler<t_connection_context>::handle_query_measure()
{
if(m_len_remain >= m_cache.size())
@@ -459,7 +467,8 @@ namespace net_utils
return true;
}
//--------------------------------------------------------------------------------------------
- inline bool simple_http_connection_handler::parse_cached_header(http_header_info& body_info, const std::string& m_cache_to_process, size_t pos)
+ template<class t_connection_context>
+ bool simple_http_connection_handler<t_connection_context>::parse_cached_header(http_header_info& body_info, const std::string& m_cache_to_process, size_t pos)
{
LOG_FRAME("http_stream_filter::parse_cached_header(*)", LOG_LEVEL_3);
@@ -503,7 +512,7 @@ namespace net_utils
body_info.m_etc_fields.push_back(std::pair<std::string, std::string>(result[field_etc_name], result[field_val]));
else
{
- LOG_ERROR("simple_http_connection_handler::parse_cached_header() not matched last entry in:"<<m_cache_to_process);
+ LOG_ERROR("simple_http_connection_handler<t_connection_context>::parse_cached_header() not matched last entry in:"<<m_cache_to_process);
}
it_current_bound = result[(int)result.size()-1]. first;
@@ -511,7 +520,8 @@ namespace net_utils
return true;
}
//-----------------------------------------------------------------------------------
- inline bool simple_http_connection_handler::get_len_from_content_lenght(const std::string& str, size_t& OUT len)
+ template<class t_connection_context>
+ bool simple_http_connection_handler<t_connection_context>::get_len_from_content_lenght(const std::string& str, size_t& OUT len)
{
STATIC_REGEXP_EXPR_1(rexp_mach_field, "\\d+", boost::regex::normal);
std::string res;
@@ -523,7 +533,8 @@ namespace net_utils
return true;
}
//-----------------------------------------------------------------------------------
- inline bool simple_http_connection_handler::handle_request_and_send_response(const http::http_request_info& query_info)
+ template<class t_connection_context>
+ bool simple_http_connection_handler<t_connection_context>::handle_request_and_send_response(const http::http_request_info& query_info)
{
http_response_info response;
bool res = handle_request(query_info, response);
@@ -540,7 +551,8 @@ namespace net_utils
return res;
}
//-----------------------------------------------------------------------------------
- inline bool simple_http_connection_handler::handle_request(const http::http_request_info& query_info, http_response_info& response)
+ template<class t_connection_context>
+ bool simple_http_connection_handler<t_connection_context>::handle_request(const http::http_request_info& query_info, http_response_info& response)
{
std::string uri_to_path = query_info.m_uri_content.m_path;
@@ -570,7 +582,8 @@ namespace net_utils
return true;
}
//-----------------------------------------------------------------------------------
- inline std::string simple_http_connection_handler::get_response_header(const http_response_info& response)
+ template<class t_connection_context>
+ std::string simple_http_connection_handler<t_connection_context>::get_response_header(const http_response_info& response)
{
std::string buf = "HTTP/1.1 ";
buf += boost::lexical_cast<std::string>(response.m_response_code) + " " + response.m_response_comment + "\r\n" +
@@ -607,7 +620,8 @@ namespace net_utils
return buf;
}
//-----------------------------------------------------------------------------------
- inline std::string simple_http_connection_handler::get_file_mime_tipe(const std::string& path)
+ template<class t_connection_context>
+ std::string simple_http_connection_handler<t_connection_context>::get_file_mime_tipe(const std::string& path)
{
std::string result;
std::string ext = string_tools::get_extension(path);
@@ -632,7 +646,8 @@ namespace net_utils
return result;
}
//-----------------------------------------------------------------------------------
- inline std::string simple_http_connection_handler::get_not_found_response_body(const std::string& URI)
+ template<class t_connection_context>
+ std::string simple_http_connection_handler<t_connection_context>::get_not_found_response_body(const std::string& URI)
{
std::string body =
"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
@@ -648,7 +663,8 @@ namespace net_utils
return body;
}
//--------------------------------------------------------------------------------------------
- inline bool simple_http_connection_handler::slash_to_back_slash(std::string& str)
+ template<class t_connection_context>
+ bool simple_http_connection_handler<t_connection_context>::slash_to_back_slash(std::string& str)
{
for(std::string::iterator it = str.begin(); it!=str.end(); it++)
if('/' == *it)
diff --git a/contrib/epee/include/net/http_server_cp2.h b/contrib/epee/include/net/http_server_cp2.h
index dd76d06f8..1a503a4de 100644
--- a/contrib/epee/include/net/http_server_cp2.h
+++ b/contrib/epee/include/net/http_server_cp2.h
@@ -36,8 +36,8 @@ namespace epee
{
namespace net_utils
{
- typedef boosted_tcp_server<http::simple_http_connection_handler> boosted_http_server_file_system;
- typedef boosted_tcp_server<http::http_custom_handler> boosted_http_server_custum_handling;
+ typedef boosted_tcp_server<http::simple_http_connection_handler<> > boosted_http_server_file_system;
+ typedef boosted_tcp_server<http::http_custom_handler<> > boosted_http_server_custum_handling;
}
}
diff --git a/contrib/epee/include/net/http_server_handlers_map2.h b/contrib/epee/include/net/http_server_handlers_map2.h
index 7a8bdd4ad..80c32e3c5 100644
--- a/contrib/epee/include/net/http_server_handlers_map2.h
+++ b/contrib/epee/include/net/http_server_handlers_map2.h
@@ -31,9 +31,9 @@
#include "http_base.h"
-#define CHAIN_HTTP_TO_MAP2() bool handle_http_request(const epee::net_utils::http::http_request_info& query_info, \
+#define CHAIN_HTTP_TO_MAP2(context_type) bool handle_http_request(const epee::net_utils::http::http_request_info& query_info, \
epee::net_utils::http::http_response_info& response, \
- const epee::net_utils::connection_context_base& m_conn_context) \
+ context_type& m_conn_context) \
{\
LOG_PRINT_L2("HTTP [" << epee::string_tools::get_ip_string_from_int32(m_conn_context.m_remote_ip ) << "] " << query_info.m_http_method_str << " " << query_info.m_URI); \
response.m_response_code = 200; \
@@ -44,9 +44,9 @@
}
-#define BEGIN_URI_MAP2() bool handle_http_request_map(const epee::net_utils::http::http_request_info& query_info, \
+#define BEGIN_URI_MAP2() template<class t_context> bool handle_http_request_map(const epee::net_utils::http::http_request_info& query_info, \
epee::net_utils::http::http_response_info& response_info, \
- const epee::net_utils::connection_context_base& m_conn_context) { \
+ t_context& m_conn_context) { \
bool handled = false; \
if(false) return true; //just a stub to have "else if"
@@ -58,22 +58,22 @@
else if(query_info.m_URI == s_pattern) \
{ \
handled = true; \
- boost::uint64_t ticks = misc_utils::get_tick_count(); \
+ uint64_t ticks = misc_utils::get_tick_count(); \
boost::value_initialized<command_type::request> req; \
bool parse_res = epee::serialization::load_t_from_json(static_cast<command_type::request&>(req), query_info.m_body); \
CHECK_AND_ASSERT_MES(parse_res, false, "Failed to parse json: \r\n" << query_info.m_body); \
- boost::uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
+ uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
boost::value_initialized<command_type::response> resp;\
- if(!callback_f(static_cast<command_type::request&>(req), static_cast<command_type::response&>(resp))) \
+ if(!callback_f(static_cast<command_type::request&>(req), static_cast<command_type::response&>(resp), m_conn_context)) \
{ \
LOG_ERROR("Failed to " << #callback_f << "()"); \
response_info.m_response_code = 500; \
response_info.m_response_comment = "Internal Server Error"; \
return true; \
} \
- boost::uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
+ uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
epee::serialization::store_t_to_json(static_cast<command_type::response&>(resp), response_info.m_body); \
- boost::uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
+ uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
response_info.m_mime_tipe = "application/json"; \
response_info.m_header_info.m_content_type = " application/json"; \
LOG_PRINT( s_pattern << " processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2); \
@@ -83,22 +83,22 @@
else if(query_info.m_URI == s_pattern) \
{ \
handled = true; \
- boost::uint64_t ticks = misc_utils::get_tick_count(); \
+ uint64_t ticks = misc_utils::get_tick_count(); \
boost::value_initialized<command_type::request> req; \
bool parse_res = epee::serialization::load_t_from_binary(static_cast<command_type::request&>(req), query_info.m_body); \
CHECK_AND_ASSERT_MES(parse_res, false, "Failed to parse bin body data, body size=" << query_info.m_body.size()); \
- boost::uint64_t ticks1 = misc_utils::get_tick_count(); \
+ uint64_t ticks1 = misc_utils::get_tick_count(); \
boost::value_initialized<command_type::response> resp;\
- if(!callback_f(static_cast<command_type::request&>(req), static_cast<command_type::response&>(resp))) \
+ if(!callback_f(static_cast<command_type::request&>(req), static_cast<command_type::response&>(resp), m_conn_context)) \
{ \
LOG_ERROR("Failed to " << #callback_f << "()"); \
response_info.m_response_code = 500; \
response_info.m_response_comment = "Internal Server Error"; \
return true; \
} \
- boost::uint64_t ticks2 = misc_utils::get_tick_count(); \
+ uint64_t ticks2 = misc_utils::get_tick_count(); \
epee::serialization::store_t_to_binary(static_cast<command_type::response&>(resp), response_info.m_body); \
- boost::uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
+ uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
response_info.m_mime_tipe = " application/octet-stream"; \
response_info.m_header_info.m_content_type = " application/octet-stream"; \
LOG_PRINT( s_pattern << "() processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2); \
@@ -170,7 +170,7 @@ namespace epee
#define BEGIN_JSON_RPC_MAP(uri) else if(query_info.m_URI == uri) \
{ \
- boost::uint64_t ticks = epee::misc_utils::get_tick_count(); \
+ uint64_t ticks = epee::misc_utils::get_tick_count(); \
epee::serialization::portable_storage ps; \
if(!ps.load_from_json(query_info.m_body)) \
{ \
@@ -198,20 +198,20 @@ namespace epee
boost::value_initialized<epee::json_rpc::request<command_type::request> > req_; \
epee::json_rpc::request<command_type::request>& req = static_cast<epee::json_rpc::request<command_type::request>&>(req_);\
req.load(ps); \
- boost::uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
+ uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
boost::value_initialized<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> > resp_; \
epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error>& resp = static_cast<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> &>(resp_); \
resp.id = req.id; \
epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
fail_resp.id = req.id; \
- if(!callback_f(req.params, resp.result, fail_resp.error)) \
+ if(!callback_f(req.params, resp.result, fail_resp.error, m_conn_context)) \
{ \
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
return true; \
} \
- boost::uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
+ uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
epee::serialization::store_t_to_json(resp, response_info.m_body); \
- boost::uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
+ uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
response_info.m_mime_tipe = "application/json"; \
response_info.m_header_info.m_content_type = " application/json"; \
LOG_PRINT( query_info.m_URI << "[" << method_name << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2); \
@@ -226,11 +226,11 @@ namespace epee
boost::value_initialized<epee::json_rpc::request<command_type::request> > req_; \
epee::json_rpc::request<command_type::request>& req = static_cast<epee::json_rpc::request<command_type::request>&>(req_);\
req.load(ps); \
- boost::uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
+ uint64_t ticks1 = epee::misc_utils::get_tick_count(); \
boost::value_initialized<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> > resp_; \
epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error>& resp = static_cast<epee::json_rpc::response<command_type::response, epee::json_rpc::dummy_error> &>(resp_); \
resp.id = req.id; \
- if(!callback_f(req.params, resp.result)) \
+ if(!callback_f(req.params, resp.result, m_conn_context)) \
{ \
epee::json_rpc::error_response fail_resp = AUTO_VAL_INIT(fail_resp); \
fail_resp.id = req.id; \
@@ -239,9 +239,9 @@ namespace epee
epee::serialization::store_t_to_json(static_cast<epee::json_rpc::error_response&>(fail_resp), response_info.m_body); \
return true; \
} \
- boost::uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
+ uint64_t ticks2 = epee::misc_utils::get_tick_count(); \
epee::serialization::store_t_to_json(resp, response_info.m_body); \
- boost::uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
+ uint64_t ticks3 = epee::misc_utils::get_tick_count(); \
response_info.m_mime_tipe = "application/json"; \
response_info.m_header_info.m_content_type = " application/json"; \
LOG_PRINT( query_info.m_URI << "[" << method_name << "] processed with " << ticks1-ticks << "/"<< ticks2-ticks1 << "/" << ticks3-ticks2 << "ms", LOG_LEVEL_2); \
diff --git a/contrib/epee/include/net/http_server_impl_base.h b/contrib/epee/include/net/http_server_impl_base.h
index f81b4f601..c02475c34 100644
--- a/contrib/epee/include/net/http_server_impl_base.h
+++ b/contrib/epee/include/net/http_server_impl_base.h
@@ -39,8 +39,8 @@
namespace epee
{
- template<class t_child_class>
- class http_server_impl_base: public net_utils::http::i_http_server_handler
+ template<class t_child_class, class t_connection_context = epee::net_utils::connection_context_base>
+ class http_server_impl_base: public net_utils::http::i_http_server_handler<t_connection_context>
{
public:
@@ -107,6 +107,6 @@ namespace epee
}
protected:
- net_utils::boosted_http_server_custum_handling m_net_server;
+ net_utils::boosted_tcp_server<net_utils::http::http_custom_handler<t_connection_context> > m_net_server;
};
} \ No newline at end of file
diff --git a/contrib/epee/include/net/levin_base.h b/contrib/epee/include/net/levin_base.h
index 503a9e5df..d630bff19 100644
--- a/contrib/epee/include/net/levin_base.h
+++ b/contrib/epee/include/net/levin_base.h
@@ -41,13 +41,13 @@ namespace levin
#pragma pack(1)
struct bucket_head
{
- boost::uint64_t m_signature;
- boost::uint64_t m_cb;
- bool m_have_to_return_data;
- boost::uint32_t m_command;
- boost::int32_t m_return_code;
- boost::uint32_t m_reservedA; //probably some flags in future
- boost::uint32_t m_reservedB; //probably some check sum in future
+ uint64_t m_signature;
+ uint64_t m_cb;
+ bool m_have_to_return_data;
+ uint32_t m_command;
+ int32_t m_return_code;
+ uint32_t m_reservedA; //probably some flags in future
+ uint32_t m_reservedB; //probably some check sum in future
};
#pragma pack(pop)
@@ -56,13 +56,13 @@ namespace levin
#pragma pack(1)
struct bucket_head2
{
- boost::uint64_t m_signature;
- boost::uint64_t m_cb;
- bool m_have_to_return_data;
- boost::uint32_t m_command;
- boost::int32_t m_return_code;
- boost::uint32_t m_flags;
- boost::uint32_t m_protocol_version;
+ uint64_t m_signature;
+ uint64_t m_cb;
+ bool m_have_to_return_data;
+ uint32_t m_command;
+ int32_t m_return_code;
+ uint32_t m_flags;
+ uint32_t m_protocol_version;
};
#pragma pack(pop)
diff --git a/contrib/epee/include/net/levin_client_async.h b/contrib/epee/include/net/levin_client_async.h
index b02fa7ee7..9e76cd509 100644
--- a/contrib/epee/include/net/levin_client_async.h
+++ b/contrib/epee/include/net/levin_client_async.h
@@ -49,16 +49,16 @@ namespace levin
class levin_client_async
{
levin_commands_handler* m_pcommands_handler;
- volatile boost::uint32_t m_is_stop;
- volatile boost::uint32_t m_threads_count;
+ volatile uint32_t m_is_stop;
+ volatile uint32_t m_threads_count;
::critical_section m_send_lock;
std::string m_local_invoke_buff;
::critical_section m_local_invoke_buff_lock;
volatile int m_invoke_res;
- volatile boost::uint32_t m_invoke_data_ready;
- volatile boost::uint32_t m_invoke_is_active;
+ volatile uint32_t m_invoke_data_ready;
+ volatile uint32_t m_invoke_is_active;
boost::mutex m_invoke_event;
boost::condition_variable m_invoke_cond;
@@ -69,14 +69,14 @@ namespace levin
{
bucket_head m_hd;
std::string m_body;
- boost::uint32_t m_connection_index;
+ uint32_t m_connection_index;
};
std::list<packet_entry> m_recieved_packets;
/*
m_current_connection_index needed when some connection was broken and reconnected - in this
case we could have some received packets in que, which shoud not be handled
*/
- volatile boost::uint32_t m_current_connection_index;
+ volatile uint32_t m_current_connection_index;
::critical_section m_invoke_lock;
::critical_section m_reciev_packet_lock;
::critical_section m_connection_lock;
@@ -101,7 +101,7 @@ namespace levin
m_pcommands_handler = phandler;
}
- bool connect(boost::uint32_t ip, boost::uint32_t port, boost::uint32_t timeout)
+ bool connect(uint32_t ip, uint32_t port, uint32_t timeout)
{
loop_call_guard();
critical_region cr(m_connection_lock);
@@ -388,7 +388,7 @@ namespace levin
bool reciev_and_process_incoming_data()
{
bucket_head head = {0};
- boost::uint32_t conn_index = 0;
+ uint32_t conn_index = 0;
bool is_request = false;
std::string local_buff;
CRITICAL_REGION_BEGIN(m_reciev_packet_lock);//to protect from socket reconnect between head and body
@@ -485,7 +485,7 @@ namespace levin
return true;
}
- bool process_recieved_packet(bucket_head& head, const std::string& local_buff, boost::uint32_t conn_index)
+ bool process_recieved_packet(bucket_head& head, const std::string& local_buff, uint32_t conn_index)
{
net_utils::connection_context_base conn_context;
@@ -544,7 +544,7 @@ namespace levin
bool have_some_work = false;
std::string local_buff;
bucket_head bh = {0};
- boost::uint32_t conn_index = 0;
+ uint32_t conn_index = 0;
CRITICAL_REGION_BEGIN(m_recieved_packets_lock);
if(m_recieved_packets.size())
diff --git a/contrib/epee/include/net/levin_protocol_handler.h b/contrib/epee/include/net/levin_protocol_handler.h
index adc6e95d5..512ba1c3c 100644
--- a/contrib/epee/include/net/levin_protocol_handler.h
+++ b/contrib/epee/include/net/levin_protocol_handler.h
@@ -98,7 +98,7 @@ namespace levin
case conn_state_reading_head:
if(m_cach_in_buffer.size() < sizeof(bucket_head))
{
- if(m_cach_in_buffer.size() >= sizeof(boost::uint64_t) && *((boost::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()) != LEVIN_SIGNATURE)
{
LOG_ERROR("Signature missmatch on accepted connection");
return false;
diff --git a/contrib/epee/include/net/levin_protocol_handler_async.h b/contrib/epee/include/net/levin_protocol_handler_async.h
index dc4f41146..e7fb32fe0 100644
--- a/contrib/epee/include/net/levin_protocol_handler_async.h
+++ b/contrib/epee/include/net/levin_protocol_handler_async.h
@@ -64,8 +64,8 @@ class async_protocol_handler_config
public:
typedef t_connection_context connection_context;
levin_commands_handler<t_connection_context>* m_pcommands_handler;
- boost::uint64_t m_max_packet_size;
- boost::uint64_t m_invoke_timeout;
+ uint64_t m_max_packet_size;
+ uint64_t m_invoke_timeout;
int invoke(int command, const std::string& in_buff, std::string& buff_out, boost::uuids::uuid connection_id);
template<class callback_t>
@@ -122,7 +122,7 @@ public:
std::string m_cache_in_buffer;
stream_state m_state;
- boost::int32_t m_oponent_protocol_ver;
+ int32_t m_oponent_protocol_ver;
bool m_connection_initialized;
struct invoke_response_handler_base
@@ -424,7 +424,7 @@ public:
{
if(m_cache_in_buffer.size() < sizeof(bucket_head2))
{
- if(m_cache_in_buffer.size() >= sizeof(boost::uint64_t) && *((boost::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()) != LEVIN_SIGNATURE)
{
LOG_ERROR_CC(m_connection_context, "Signature mismatch, connection will be closed");
return false;
diff --git a/contrib/epee/include/net/local_ip.h b/contrib/epee/include/net/local_ip.h
index 028ad73ef..0d458963c 100644
--- a/contrib/epee/include/net/local_ip.h
+++ b/contrib/epee/include/net/local_ip.h
@@ -32,7 +32,7 @@ namespace epee
namespace net_utils
{
inline
- bool is_ip_local(boost::uint32_t ip)
+ bool is_ip_local(uint32_t ip)
{
/*
local ip area
@@ -55,7 +55,7 @@ namespace epee
return false;
}
inline
- bool is_ip_loopback(boost::uint32_t ip)
+ bool is_ip_loopback(uint32_t ip)
{
if( (ip | 0xffffff00) == 0xffffff7f)
return true;
diff --git a/contrib/epee/include/net/net_helper.h b/contrib/epee/include/net/net_helper.h
index d2a4cfec3..4f7ebfa04 100644
--- a/contrib/epee/include/net/net_helper.h
+++ b/contrib/epee/include/net/net_helper.h
@@ -429,7 +429,7 @@ namespace net_utils
}
- inline bool recv_n(std::string& buff, boost::int64_t sz)
+ inline bool recv_n(std::string& buff, int64_t sz)
{
try
@@ -564,7 +564,7 @@ namespace net_utils
bool m_initialized;
bool m_connected;
boost::asio::deadline_timer m_deadline;
- volatile boost::uint32_t m_shutdowned;
+ volatile uint32_t m_shutdowned;
};
diff --git a/contrib/epee/include/net/net_parse_helpers.h b/contrib/epee/include/net/net_parse_helpers.h
index 16641a970..586dac98d 100644
--- a/contrib/epee/include/net/net_parse_helpers.h
+++ b/contrib/epee/include/net/net_parse_helpers.h
@@ -153,7 +153,7 @@ namespace net_utils
}
if(result[6].matched)
{
- content.port = boost::lexical_cast<boost::uint64_t>(result[6]);
+ content.port = boost::lexical_cast<uint64_t>(result[6]);
}
if(result[7].matched)
{
diff --git a/contrib/epee/include/net/net_utils_base.h b/contrib/epee/include/net/net_utils_base.h
index 86797bb85..3afbbb119 100644
--- a/contrib/epee/include/net/net_utils_base.h
+++ b/contrib/epee/include/net/net_utils_base.h
@@ -47,23 +47,36 @@ namespace net_utils
struct connection_context_base
{
const boost::uuids::uuid m_connection_id;
- const boost::uint32_t m_remote_ip;
- const boost::uint32_t m_remote_port;
- const bool m_is_income;
-
- connection_context_base(boost::uuids::uuid connection_id, long remote_ip, int remote_port, bool is_income):
+ const uint32_t m_remote_ip;
+ const uint32_t m_remote_port;
+ const bool m_is_income;
+ const time_t m_started;
+ time_t m_last_recv;
+ time_t m_last_send;
+ uint64_t m_recv_cnt;
+ uint64_t m_send_cnt;
+
+ connection_context_base(boost::uuids::uuid connection_id, long remote_ip, int remote_port, bool is_income, time_t last_recv = 0, time_t last_send = 0, uint64_t recv_cnt = 0, uint64_t send_cnt = 0):
m_connection_id(connection_id),
m_remote_ip(remote_ip),
m_remote_port(remote_port),
- m_is_income(is_income)
-
-
+ m_is_income(is_income),
+ m_last_recv(last_recv),
+ m_last_send(last_send),
+ m_recv_cnt(recv_cnt),
+ m_send_cnt(send_cnt),
+ m_started(time(NULL))
{}
connection_context_base(): m_connection_id(),
m_remote_ip(0),
m_remote_port(0),
- m_is_income(false)
+ m_is_income(false),
+ m_last_recv(0),
+ m_last_send(0),
+ m_recv_cnt(0),
+ m_send_cnt(0),
+ m_started(time(NULL))
{}
connection_context_base& operator=(const connection_context_base& a)
diff --git a/contrib/epee/include/net/protocol_switcher.h b/contrib/epee/include/net/protocol_switcher.h
index f9a6dbe6f..ca0ce6f97 100644
--- a/contrib/epee/include/net/protocol_switcher.h
+++ b/contrib/epee/include/net/protocol_switcher.h
@@ -95,10 +95,10 @@ namespace net_utils
else
{
m_cached_buff.append((const char*)ptr, cb);
- if(m_cached_buff.size() < sizeof(boost::uint64_t))
+ if(m_cached_buff.size() < sizeof(uint64_t))
return true;
- if(*((boost::uint64_t*)&m_cached_buff[0]) == LEVIN_SIGNATURE)
+ if(*((uint64_t*)&m_cached_buff[0]) == LEVIN_SIGNATURE)
{
pcurrent_handler = &m_levin_handler;
return pcurrent_handler->handle_recv(m_cached_buff.data(), m_cached_buff.size());
diff --git a/contrib/epee/include/profile_tools.h b/contrib/epee/include/profile_tools.h
index ff925ea86..be45feafe 100644
--- a/contrib/epee/include/profile_tools.h
+++ b/contrib/epee/include/profile_tools.h
@@ -51,12 +51,12 @@ namespace epee
#define PROFILE_FUNC_THIRD(immortal_ptr_str)
#endif
-#define START_WAY_POINTS() boost::uint64_t _____way_point_time = misc_utils::get_tick_count();
-#define WAY_POINT(name) {boost::uint64_t delta = misc_utils::get_tick_count()-_____way_point_time; LOG_PRINT("Way point " << name << ": " << delta, LOG_LEVEL_2);_____way_point_time = misc_utils::get_tick_count();}
-#define WAY_POINT2(name, avrg_obj) {boost::uint64_t delta = misc_utils::get_tick_count()-_____way_point_time; avrg_obj.push(delta); LOG_PRINT("Way point " << name << ": " << delta, LOG_LEVEL_2);_____way_point_time = misc_utils::get_tick_count();}
+#define START_WAY_POINTS() uint64_t _____way_point_time = misc_utils::get_tick_count();
+#define WAY_POINT(name) {uint64_t delta = misc_utils::get_tick_count()-_____way_point_time; LOG_PRINT("Way point " << name << ": " << delta, LOG_LEVEL_2);_____way_point_time = misc_utils::get_tick_count();}
+#define WAY_POINT2(name, avrg_obj) {uint64_t delta = misc_utils::get_tick_count()-_____way_point_time; avrg_obj.push(delta); LOG_PRINT("Way point " << name << ": " << delta, LOG_LEVEL_2);_____way_point_time = misc_utils::get_tick_count();}
-#define TIME_MEASURE_START(var_name) boost::uint64_t var_name = misc_utils::get_tick_count();
+#define TIME_MEASURE_START(var_name) uint64_t var_name = misc_utils::get_tick_count();
#define TIME_MEASURE_FINISH(var_name) var_name = misc_utils::get_tick_count() - var_name;
namespace profile_tools
@@ -71,7 +71,7 @@ namespace profile_tools
}
size_t m_count_of_call;
- boost::uint64_t m_summary_time_used;
+ uint64_t m_summary_time_used;
const char* m_pname;
};
@@ -91,7 +91,7 @@ namespace profile_tools
boost::posix_time::ptime now_t(boost::posix_time::microsec_clock::local_time());
boost::posix_time::time_duration delta_microsec = now_t - m_call_time;
- boost::uint64_t miliseconds_used = delta_microsec.total_microseconds();
+ uint64_t miliseconds_used = delta_microsec.total_microseconds();
//::QueryPerformanceCounter((LARGE_INTEGER *)&ret_time);
//m_call_time = (ret_time-m_call_time)/1000;
diff --git a/contrib/epee/include/reg_exp_definer.h b/contrib/epee/include/reg_exp_definer.h
index b05e1a9ae..e2bed5c3f 100644
--- a/contrib/epee/include/reg_exp_definer.h
+++ b/contrib/epee/include/reg_exp_definer.h
@@ -45,8 +45,8 @@ namespace epee
const static global_regexp_critical_section gregexplock;
#define STATIC_REGEXP_EXPR_1(var_name, xpr_text, reg_exp_flags) \
- static volatile boost::uint32_t regexp_initialized_1 = 0;\
- volatile boost::uint32_t local_is_initialized_1 = regexp_initialized_1;\
+ static volatile uint32_t regexp_initialized_1 = 0;\
+ volatile uint32_t local_is_initialized_1 = regexp_initialized_1;\
if(!local_is_initialized_1)\
gregexplock.get_lock().lock();\
static const boost::regex var_name(xpr_text , reg_exp_flags);\
@@ -57,8 +57,8 @@ namespace epee
}
#define STATIC_REGEXP_EXPR_2(var_name, xpr_text, reg_exp_flags) \
- static volatile boost::uint32_t regexp_initialized_2 = 0;\
- volatile boost::uint32_t local_is_initialized_2 = regexp_initialized_2;\
+ static volatile uint32_t regexp_initialized_2 = 0;\
+ volatile uint32_t local_is_initialized_2 = regexp_initialized_2;\
if(!local_is_initialized_2)\
gregexplock.get_lock().lock().lock();\
static const boost::regex var_name(xpr_text , reg_exp_flags);\
@@ -69,8 +69,8 @@ namespace epee
}
#define STATIC_REGEXP_EXPR_3(var_name, xpr_text, reg_exp_flags) \
- static volatile boost::uint32_t regexp_initialized_3 = 0;\
- volatile boost::uint32_t local_is_initialized_3 = regexp_initialized_3;\
+ static volatile uint32_t regexp_initialized_3 = 0;\
+ volatile uint32_t local_is_initialized_3 = regexp_initialized_3;\
if(!local_is_initialized_3)\
gregexplock.get_lock().lock().lock();\
static const boost::regex var_name(xpr_text , reg_exp_flags);\
diff --git a/contrib/epee/include/soci_helper.h b/contrib/epee/include/soci_helper.h
index a154f97fc..813edc1fc 100644
--- a/contrib/epee/include/soci_helper.h
+++ b/contrib/epee/include/soci_helper.h
@@ -34,22 +34,22 @@ namespace soci
{
template <>
- struct type_conversion<boost::uint64_t>
+ struct type_conversion<uint64_t>
{
typedef long long base_type;
- static void from_base(base_type a_, indicator ind, boost::uint64_t & mi)
+ static void from_base(base_type a_, indicator ind, uint64_t & mi)
{
if (ind == i_null)
{
mi = 0;
//throw soci_error("Null value not allowed for this type");
}
- mi = (boost::uint64_t)a_;
+ mi = (uint64_t)a_;
//mi.set(i);
}
- static void to_base(const boost::uint64_t & mi, base_type & i, indicator & ind)
+ static void to_base(const uint64_t & mi, base_type & i, indicator & ind)
{
i = (base_type)mi;
ind = i_ok;
diff --git a/contrib/epee/include/storages/portable_storage_from_json.h b/contrib/epee/include/storages/portable_storage_from_json.h
index 557db3da6..4e74fb7a5 100644
--- a/contrib/epee/include/storages/portable_storage_from_json.h
+++ b/contrib/epee/include/storages/portable_storage_from_json.h
@@ -281,7 +281,7 @@ namespace epee
bool insert_res = false;
if(!is_v_float)
{
- boost::int64_t nval = boost::lexical_cast<int64_t>(val); //bool res = string_tools::string_to_num_fast(val, nval);
+ int64_t nval = boost::lexical_cast<int64_t>(val); //bool res = string_tools::string_to_num_fast(val, nval);
insert_res = stg.insert_next_value(h_array, nval);
}else
diff --git a/contrib/epee/include/string_tools.h b/contrib/epee/include/string_tools.h
index 53be7c3ae..4cc88418c 100644
--- a/contrib/epee/include/string_tools.h
+++ b/contrib/epee/include/string_tools.h
@@ -183,27 +183,35 @@ namespace string_tools
//----------------------------------------------------------------------------
PUSH_WARNINGS
DISABLE_GCC_WARNING(maybe-uninitialized)
- template<class XType>
- inline bool get_xtype_from_string(OUT XType& val, const std::string& str_id)
- {
- try
- {
- val = boost::lexical_cast<XType>(str_id);
- return true;
- }
- catch(std::exception& /*e*/)
- {
- //const char* pmsg = e.what();
- return false;
- }
+ template<class XType>
+ inline bool get_xtype_from_string(OUT XType& val, const std::string& str_id)
+ {
+ if (std::is_integral<XType>::value && !std::numeric_limits<XType>::is_signed && !std::is_same<XType, bool>::value)
+ {
+ for (char c : str_id)
+ {
+ if (!std::isdigit(c))
+ return false;
+ }
+ }
- catch(...)
- {
- return false;
- }
+ try
+ {
+ val = boost::lexical_cast<XType>(str_id);
+ return true;
+ }
+ catch(std::exception& /*e*/)
+ {
+ //const char* pmsg = e.what();
+ return false;
+ }
+ catch(...)
+ {
+ return false;
+ }
- return true;
- }
+ return true;
+ }
POP_WARNINGS
//---------------------------------------------------
template<typename int_t>
@@ -315,7 +323,7 @@ POP_WARNINGS
//----------------------------------------------------------------------------
//#ifdef _WINSOCK2API_
- inline std::string get_ip_string_from_int32(boost::uint32_t ip)
+ inline std::string get_ip_string_from_int32(uint32_t ip)
{
in_addr adr;
adr.s_addr = ip;
@@ -326,7 +334,7 @@ POP_WARNINGS
return "[failed]";
}
//----------------------------------------------------------------------------
- inline bool get_ip_int32_from_string(boost::uint32_t& ip, const std::string& ip_str)
+ inline bool get_ip_int32_from_string(uint32_t& ip, const std::string& ip_str)
{
ip = inet_addr(ip_str.c_str());
if(INADDR_NONE == ip)
@@ -369,7 +377,7 @@ POP_WARNINGS
return ss.str();
}
- inline std::string num_to_string_fast(boost::int64_t val)
+ inline std::string num_to_string_fast(int64_t val)
{
/*
char buff[30] = {0};
@@ -378,7 +386,7 @@ POP_WARNINGS
return boost::lexical_cast<std::string>(val);
}
//----------------------------------------------------------------------------
- inline bool string_to_num_fast(const std::string& buff, boost::int64_t& val)
+ inline bool string_to_num_fast(const std::string& buff, int64_t& val)
{
//return get_xtype_from_string(val, buff);
#if (defined _MSC_VER)
diff --git a/contrib/epee/include/syncobj.h b/contrib/epee/include/syncobj.h
index ca7514ede..b7273da8e 100644
--- a/contrib/epee/include/syncobj.h
+++ b/contrib/epee/include/syncobj.h
@@ -41,27 +41,29 @@ namespace epee
struct simple_event
{
- simple_event()
+ simple_event() : m_rised(false)
{
- rised = false;
}
- std::mutex m_mx;
- std::condition_variable m_cond_var;
- bool rised;
- void rise()
+ void raise()
{
std::unique_lock<std::mutex> lock(m_mx);
- rised = true;
+ m_rised = true;
m_cond_var.notify_one();
}
void wait()
{
std::unique_lock<std::mutex> lock(m_mx);
- while (!rised)
+ while (!m_rised)
m_cond_var.wait(lock);
+ m_rised = false;
}
+
+ private:
+ std::mutex m_mx;
+ std::condition_variable m_cond_var;
+ bool m_rised;
};
class critical_region;