40 #include <boost/date_time/posix_time/posix_time.hpp> 41 #include <boost/thread/thread.hpp> 46 #include <boost/asio/basic_socket.hpp> 51 #if BOOST_VERSION >= 107000 52 #define GET_IO_SERVICE(s) ((boost::asio::io_context&)(s).get_executor().context()) 54 #define GET_IO_SERVICE(s) ((s).get_io_service()) 57 #undef ELECTRONEUM_DEFAULT_LOG_CATEGORY 58 #define ELECTRONEUM_DEFAULT_LOG_CATEGORY "net.conn" 74 return state->ssl_context;
138 m_want_close_connection(
false),
139 m_was_shutdown(
false),
140 m_ssl_support(ssl_support)
143 assert(m_state !=
nullptr);
147 ++(m_state->sock_count);
148 mI->m_peer_number = m_state->sock_number.fetch_add(1);
151 try { boost::system::error_code e; remote_addr_str =
socket().remote_endpoint(e).address().to_string(); }
catch(...){} ;
153 _note(
"Spawned connection #"<<
mI->m_peer_number<<
" to " << remote_addr_str <<
" currently we have sockets count:" << m_state->sock_count);
161 socket_(io_service, get_context(m_state.
get())),
162 m_want_close_connection(
false),
163 m_was_shutdown(
false),
164 m_ssl_support(ssl_support)
167 assert(m_state !=
nullptr);
169 ++(m_state->sock_count);
170 mI->m_peer_number = m_state->sock_number.fetch_add(1);
173 try { boost::system::error_code e; remote_addr_str =
socket().remote_endpoint(e).address().to_string(); }
catch(...){} ;
175 _note(
"Spawned connection #"<<
mI->m_peer_number<<
" to " << remote_addr_str <<
" currently we have sockets count:" << m_state->sock_count);
179 --(m_state->sock_count);
182 try { boost::system::error_code e; remote_addr_str =
socket().remote_endpoint(e).address().to_string(); }
catch(...){} ;
183 _note(
"Destructing connection #"<<
mI->m_peer_number <<
" to " << remote_addr_str);
241 _dbg2(
"m_was_shutdown - so abort sleep");
252 long int ms = (
long int)(delay * 1000);
253 MTRACE(
"Sleeping in " << __FUNCTION__ <<
" for " << ms <<
" ms before packet_size="<<packet_size);
254 boost::this_thread::sleep(boost::posix_time::milliseconds( ms ) );
268 MTRACE(
"handler_write (direct) - before ASIO write, for packet="<<cb<<
" B (after sleep)");
273 MTRACE(
"handler_write (after write, from queue="<<q_len<<
") - before ASIO write, for packet="<<cb<<
" B (after sleep)");
283 CRITICAL_REGION_LOCAL(epee::net_utils::network_throttle_manager::network_throttle_manager::m_lock_get_global_throttle_out);
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
void logger_handle_net_write(size_t size)
static uint64_t get_rate_down_limit()
std::unique_ptr< connection_basic_pimpl > mI
static i_network_throttle & get_global_throttle_in()
singleton ; for friend class ; caller MUST use proper locks! like m_lock_get_global_throttle_in ...
static void set_tos_flag(int tos)
std::unique_ptr< void, close > socket
Unique ZMQ socket handle, calls zmq_close on destruction.
virtual network_speed_kbps get_target_speed()=0
void sleep_before_packet(size_t packet_size, int phase, int q_len)
static boost::mutex m_lock_get_global_throttle_out
void do_send_handler_write(const void *ptr, size_t cb)
static void set_save_graph(bool save_graph)
static void save_limit_to_file(int limit)
for dr-electroneum
boost::asio::ip::tcp::socket & socket()
static void set_rate_up_limit(uint64_t limit)
void do_send_handler_write_from_queue(const boost::system::error_code &e, size_t cb, int q_len)
virtual network_time_seconds get_sleep_time(size_t packet_size) const =0
unsigned __int64 uint64_t
static boost::mutex m_lock_get_global_throttle_in
#define CRITICAL_REGION_LOCAL(x)
std::unique_ptr< void, terminate > context
Unique ZMQ context handle, calls zmq_term on destruction.
virtual void set_target_speed(network_speed_kbps target)=0
connection_basic(boost::asio::ip::tcp::socket &&socket, boost::shared_ptr< connection_basic_shared_state > state, ssl_support_t ssl_support)
network_throttle_bw m_throttle
void logger_handle_net_read(size_t size)
static i_network_throttle & get_global_throttle_inreq()
ditto ; use lock ... use m_lock_get_global_throttle_inreq obviously
static int get_tos_flag()
virtual ~connection_basic() noexcept(false)
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > socket_
Socket for the connection.
const T & move(const T &t)
static boost::mutex m_lock_get_global_throttle_inreq
static void set_rate_down_limit(uint64_t limit)
connection_basic_pimpl(const std::string &name)
#define GET_IO_SERVICE(s)
static i_network_throttle & get_global_throttle_out()
ditto ; use lock ... use m_lock_get_global_throttle_out obviously
critical_section m_throttle_lock
std::string to_string(t_connection_type type)
implementaion for throttling of connection (count and rate-limit speed etc)
virtual void handle_trafic_exact(size_t packet_size)=0
void get(std::istream &input, bool &res)
std::atomic< bool > m_was_shutdown
static double get_sleep_time(size_t cb)
base for connection, contains e.g. the ratelimit hooks
static uint64_t get_rate_up_limit()
virtual network_time_seconds get_sleep_time_after_tick(size_t packet_size)=0