Electroneum
epee::net_utils::connection_basic Class Reference

#include <connection_basic.hpp>

Inheritance diagram for epee::net_utils::connection_basic:
Collaboration diagram for epee::net_utils::connection_basic:

Public Member Functions

 connection_basic (boost::asio::ip::tcp::socket &&socket, boost::shared_ptr< connection_basic_shared_state > state, ssl_support_t ssl_support)
 
 connection_basic (boost::asio::io_service &io_service, boost::shared_ptr< connection_basic_shared_state > state, ssl_support_t ssl_support)
 
virtual ~connection_basic () noexcept(false)
 
connection_basic_shared_stateget_state () noexcept
 
 connection_basic (boost::asio::io_service &io_service, std::atomic< long > &ref_sock_count, std::atomic< long > &sock_number, ssl_support_t ssl)
 
boost::asio::ip::tcp::socket & socket ()
 
ssl_support_t get_ssl_support () const
 
void disable_ssl ()
 
bool handshake (boost::asio::ssl::stream_base::handshake_type type)
 
template<typename MutableBufferSequence , typename ReadHandler >
void async_read_some (const MutableBufferSequence &buffers, ReadHandler &&handler)
 
template<typename ConstBufferSequence , typename WriteHandler >
void async_write_some (const ConstBufferSequence &buffers, WriteHandler &&handler)
 
template<typename ConstBufferSequence , typename WriteHandler >
void async_write (const ConstBufferSequence &buffers, WriteHandler &&handler)
 
void do_send_handler_write (const void *ptr, size_t cb)
 
void do_send_handler_write_from_queue (const boost::system::error_code &e, size_t cb, int q_len)
 
void logger_handle_net_write (size_t size)
 
void logger_handle_net_read (size_t size)
 
void sleep_before_packet (size_t packet_size, int phase, int q_len)
 

Static Public Member Functions

static void set_rate_up_limit (uint64_t limit)
 
static void set_rate_down_limit (uint64_t limit)
 
static uint64_t get_rate_up_limit ()
 
static uint64_t get_rate_down_limit ()
 
static void set_tos_flag (int tos)
 
static int get_tos_flag ()
 
static void save_limit_to_file (int limit)
 for dr-electroneum More...
 
static double get_sleep_time (size_t cb)
 
static void set_save_graph (bool save_graph)
 

Public Attributes

std::unique_ptr< connection_basic_pimplmI
 
volatile uint32_t m_want_close_connection
 
std::atomic< boolm_was_shutdown
 
critical_section m_send_que_lock
 
std::list< std::string > m_send_que
 
volatile bool m_is_multithreaded
 
boost::asio::io_service::strand strand_
 Strand to ensure the connection's handlers are not called concurrently. More...
 
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > socket_
 Socket for the connection. More...
 
ssl_support_t m_ssl_support
 

Detailed Description

Definition at line 101 of file connection_basic.hpp.

Constructor & Destructor Documentation

◆ connection_basic() [1/3]

epee::net_utils::connection_basic::connection_basic ( boost::asio::ip::tcp::socket &&  socket,
boost::shared_ptr< connection_basic_shared_state state,
ssl_support_t  ssl_support 
)

Definition at line 132 of file connection_basic.cpp.

133  :
134  m_state(std::move(state)),
135  mI( new connection_basic_pimpl("peer") ),
136  strand_(GET_IO_SERVICE(sock)),
137  socket_(GET_IO_SERVICE(sock), get_context(m_state.get())),
139  m_was_shutdown(false),
140  m_ssl_support(ssl_support)
141 {
142  // add nullptr checks if removed
143  assert(m_state != nullptr); // release runtime check in get_context
144 
145  socket_.next_layer() = std::move(sock);
146 
147  ++(m_state->sock_count); // increase the global counter
148  mI->m_peer_number = m_state->sock_number.fetch_add(1); // use, and increase the generated number
149 
150  std::string remote_addr_str = "?";
151  try { boost::system::error_code e; remote_addr_str = socket().remote_endpoint(e).address().to_string(); } catch(...){} ;
152 
153  _note("Spawned connection #"<<mI->m_peer_number<<" to " << remote_addr_str << " currently we have sockets count:" << m_state->sock_count);
154 }
::std::string string
Definition: gtest-port.h:1097
std::unique_ptr< connection_basic_pimpl > mI
boost::asio::ip::tcp::socket & socket()
#define _note(x)
Definition: misc_log_ex.h:109
boost::asio::io_service::strand strand_
Strand to ensure the connection&#39;s handlers are not called concurrently.
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > socket_
Socket for the connection.
const T & move(const T &t)
Definition: gtest-port.h:1317
Definition: blake256.h:37
#define GET_IO_SERVICE(s)
Here is the call graph for this function:

◆ connection_basic() [2/3]

epee::net_utils::connection_basic::connection_basic ( boost::asio::io_service &  io_service,
boost::shared_ptr< connection_basic_shared_state state,
ssl_support_t  ssl_support 
)

Definition at line 156 of file connection_basic.cpp.

157  :
158  m_state(std::move(state)),
159  mI( new connection_basic_pimpl("peer") ),
160  strand_(io_service),
161  socket_(io_service, get_context(m_state.get())),
163  m_was_shutdown(false),
164  m_ssl_support(ssl_support)
165 {
166  // add nullptr checks if removed
167  assert(m_state != nullptr); // release runtime check in get_context
168 
169  ++(m_state->sock_count); // increase the global counter
170  mI->m_peer_number = m_state->sock_number.fetch_add(1); // use, and increase the generated number
171 
172  std::string remote_addr_str = "?";
173  try { boost::system::error_code e; remote_addr_str = socket().remote_endpoint(e).address().to_string(); } catch(...){} ;
174 
175  _note("Spawned connection #"<<mI->m_peer_number<<" to " << remote_addr_str << " currently we have sockets count:" << m_state->sock_count);
176 }
::std::string string
Definition: gtest-port.h:1097
std::unique_ptr< connection_basic_pimpl > mI
boost::asio::ip::tcp::socket & socket()
#define _note(x)
Definition: misc_log_ex.h:109
boost::asio::io_service::strand strand_
Strand to ensure the connection&#39;s handlers are not called concurrently.
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > socket_
Socket for the connection.
const T & move(const T &t)
Definition: gtest-port.h:1317
Definition: blake256.h:37
Here is the call graph for this function:

◆ ~connection_basic()

epee::net_utils::connection_basic::~connection_basic ( )
virtualnoexcept

Definition at line 178 of file connection_basic.cpp.

178  {
179  --(m_state->sock_count);
180 
181  std::string remote_addr_str = "?";
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);
184 }
::std::string string
Definition: gtest-port.h:1097
std::unique_ptr< connection_basic_pimpl > mI
boost::asio::ip::tcp::socket & socket()
#define _note(x)
Definition: misc_log_ex.h:109
Here is the call graph for this function:

◆ connection_basic() [3/3]

epee::net_utils::connection_basic::connection_basic ( boost::asio::io_service &  io_service,
std::atomic< long > &  ref_sock_count,
std::atomic< long > &  sock_number,
ssl_support_t  ssl 
)

Member Function Documentation

◆ async_read_some()

template<typename MutableBufferSequence , typename ReadHandler >
void epee::net_utils::connection_basic::async_read_some ( const MutableBufferSequence &  buffers,
ReadHandler &&  handler 
)
inline

Definition at line 142 of file connection_basic.hpp.

143  {
145  socket_.async_read_some(buffers, std::forward<ReadHandler>(handler));
146  else
147  socket().async_read_some(buffers, std::forward<ReadHandler>(handler));
148  }
boost::asio::ip::tcp::socket & socket()
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > socket_
Socket for the connection.
Here is the call graph for this function:

◆ async_write()

template<typename ConstBufferSequence , typename WriteHandler >
void epee::net_utils::connection_basic::async_write ( const ConstBufferSequence &  buffers,
WriteHandler &&  handler 
)
inline

Definition at line 160 of file connection_basic.hpp.

161  {
163  boost::asio::async_write(socket_, buffers, std::forward<WriteHandler>(handler));
164  else
165  boost::asio::async_write(socket(), buffers, std::forward<WriteHandler>(handler));
166  }
boost::asio::ip::tcp::socket & socket()
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > socket_
Socket for the connection.
Here is the call graph for this function:

◆ async_write_some()

template<typename ConstBufferSequence , typename WriteHandler >
void epee::net_utils::connection_basic::async_write_some ( const ConstBufferSequence &  buffers,
WriteHandler &&  handler 
)
inline

Definition at line 151 of file connection_basic.hpp.

152  {
154  socket_.async_write_some(buffers, std::forward<WriteHandler>(handler));
155  else
156  socket().async_write_some(buffers, std::forward<WriteHandler>(handler));
157  }
boost::asio::ip::tcp::socket & socket()
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > socket_
Socket for the connection.
Here is the call graph for this function:

◆ disable_ssl()

void epee::net_utils::connection_basic::disable_ssl ( )
inline

◆ do_send_handler_write()

void epee::net_utils::connection_basic::do_send_handler_write ( const void *  ptr,
size_t  cb 
)

Definition at line 266 of file connection_basic.cpp.

266  {
267  // No sleeping here; sleeping is done once and for all in connection<t_protocol_handler>::handle_write
268  MTRACE("handler_write (direct) - before ASIO write, for packet="<<cb<<" B (after sleep)");
269 }
#define MTRACE(x)
Definition: misc_log_ex.h:77

◆ do_send_handler_write_from_queue()

void epee::net_utils::connection_basic::do_send_handler_write_from_queue ( const boost::system::error_code &  e,
size_t  cb,
int  q_len 
)

Definition at line 271 of file connection_basic.cpp.

271  {
272  // No sleeping here; sleeping is done once and for all in connection<t_protocol_handler>::handle_write
273  MTRACE("handler_write (after write, from queue="<<q_len<<") - before ASIO write, for packet="<<cb<<" B (after sleep)");
274 }
#define MTRACE(x)
Definition: misc_log_ex.h:77

◆ get_rate_down_limit()

uint64_t epee::net_utils::connection_basic::get_rate_down_limit ( )
static

Definition at line 216 of file connection_basic.cpp.

216  {
217  uint64_t limit;
218  {
221  }
222  return limit;
223 }
static i_network_throttle & get_global_throttle_in()
singleton ; for friend class ; caller MUST use proper locks! like m_lock_get_global_throttle_in ...
virtual network_speed_kbps get_target_speed()=0
unsigned __int64 uint64_t
Definition: stdint.h:136
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_rate_up_limit()

uint64_t epee::net_utils::connection_basic::get_rate_up_limit ( )
static

Definition at line 207 of file connection_basic.cpp.

207  {
208  uint64_t limit;
209  {
212  }
213  return limit;
214 }
virtual network_speed_kbps get_target_speed()=0
unsigned __int64 uint64_t
Definition: stdint.h:136
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228
static i_network_throttle & get_global_throttle_out()
ditto ; use lock ... use m_lock_get_global_throttle_out obviously
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_sleep_time()

double epee::net_utils::connection_basic::get_sleep_time ( size_t  cb)
static

Definition at line 282 of file connection_basic.cpp.

282  {
283  CRITICAL_REGION_LOCAL(epee::net_utils::network_throttle_manager::network_throttle_manager::m_lock_get_global_throttle_out);
285  return t;
286 }
virtual network_time_seconds get_sleep_time(size_t packet_size) const =0
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228
static i_network_throttle & get_global_throttle_out()
ditto ; use lock ... use m_lock_get_global_throttle_out obviously
Here is the call graph for this function:

◆ get_ssl_support()

ssl_support_t epee::net_utils::connection_basic::get_ssl_support ( ) const
inline

Definition at line 132 of file connection_basic.hpp.

132 { return m_ssl_support; }

◆ get_state()

connection_basic_shared_state& epee::net_utils::connection_basic::get_state ( )
inlinenoexcept
Returns
shared_state object passed in construction (ptr never changes).

Definition at line 128 of file connection_basic.hpp.

128 { return *m_state; /* verified in constructor */ }

◆ get_tos_flag()

int epee::net_utils::connection_basic::get_tos_flag ( )
static

Definition at line 232 of file connection_basic.cpp.

◆ handshake()

bool epee::net_utils::connection_basic::handshake ( boost::asio::ssl::stream_base::handshake_type  type)
inline

Definition at line 135 of file connection_basic.hpp.

136  {
137  //m_state != nullptr verified in constructor
138  return m_state->ssl_options().handshake(socket_, type);
139  }
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > socket_
Socket for the connection.

◆ logger_handle_net_read()

void epee::net_utils::connection_basic::logger_handle_net_read ( size_t  size)

Definition at line 276 of file connection_basic.cpp.

276  { // network data read
277 }

◆ logger_handle_net_write()

void epee::net_utils::connection_basic::logger_handle_net_write ( size_t  size)

Definition at line 279 of file connection_basic.cpp.

279  {
280 }

◆ save_limit_to_file()

void epee::net_utils::connection_basic::save_limit_to_file ( int  limit)
static

for dr-electroneum

Definition at line 225 of file connection_basic.cpp.

225  {
226 }
Here is the caller graph for this function:

◆ set_rate_down_limit()

void epee::net_utils::connection_basic::set_rate_down_limit ( uint64_t  limit)
static

Definition at line 194 of file connection_basic.cpp.

194  {
195  {
198  }
199 
200  {
203  }
204  save_limit_to_file(limit);
205 }
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 save_limit_to_file(int limit)
for dr-electroneum
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228
virtual void set_target_speed(network_speed_kbps target)=0
static i_network_throttle & get_global_throttle_inreq()
ditto ; use lock ... use m_lock_get_global_throttle_inreq obviously
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_rate_up_limit()

void epee::net_utils::connection_basic::set_rate_up_limit ( uint64_t  limit)
static

Definition at line 186 of file connection_basic.cpp.

186  {
187  {
190  }
191  save_limit_to_file(limit);
192 }
static void save_limit_to_file(int limit)
for dr-electroneum
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228
virtual void set_target_speed(network_speed_kbps target)=0
static i_network_throttle & get_global_throttle_out()
ditto ; use lock ... use m_lock_get_global_throttle_out obviously
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_save_graph()

void epee::net_utils::connection_basic::set_save_graph ( bool  save_graph)
static

Definition at line 288 of file connection_basic.cpp.

288  {
289 }
Here is the caller graph for this function:

◆ set_tos_flag()

void epee::net_utils::connection_basic::set_tos_flag ( int  tos)
static

Definition at line 228 of file connection_basic.cpp.

◆ sleep_before_packet()

void epee::net_utils::connection_basic::sleep_before_packet ( size_t  packet_size,
int  phase,
int  q_len 
)

Definition at line 236 of file connection_basic.cpp.

236  {
237  double delay=0; // will be calculated
238  do
239  { // rate limiting
240  if (m_was_shutdown) {
241  _dbg2("m_was_shutdown - so abort sleep");
242  return;
243  }
244 
245  {
248  }
249 
250  delay *= 0.50;
251  if (delay > 0) {
252  long int ms = (long int)(delay * 1000);
253  MTRACE("Sleeping in " << __FUNCTION__ << " for " << ms << " ms before packet_size="<<packet_size); // debug sleep
254  boost::this_thread::sleep(boost::posix_time::milliseconds( ms ) );
255  }
256  } while(delay > 0);
257 
258 // XXX LATER XXX
259  {
261  network_throttle_manager::get_global_throttle_out().handle_trafic_exact( packet_size ); // increase counter - global
262  }
263 
264 }
#define MTRACE(x)
Definition: misc_log_ex.h:77
#define _dbg2(x)
Definition: misc_log_ex.h:106
#define CRITICAL_REGION_LOCAL(x)
Definition: syncobj.h:228
static i_network_throttle & get_global_throttle_out()
ditto ; use lock ... use m_lock_get_global_throttle_out obviously
virtual void handle_trafic_exact(size_t packet_size)=0
virtual network_time_seconds get_sleep_time_after_tick(size_t packet_size)=0
Here is the call graph for this function:

◆ socket()

boost::asio::ip::tcp::socket& epee::net_utils::connection_basic::socket ( )
inline

Definition at line 131 of file connection_basic.hpp.

131 { return socket_.next_layer(); }
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > socket_
Socket for the connection.
Here is the caller graph for this function:

Member Data Documentation

◆ m_is_multithreaded

volatile bool epee::net_utils::connection_basic::m_is_multithreaded

Definition at line 113 of file connection_basic.hpp.

◆ m_send_que

std::list<std::string> epee::net_utils::connection_basic::m_send_que

Definition at line 112 of file connection_basic.hpp.

◆ m_send_que_lock

critical_section epee::net_utils::connection_basic::m_send_que_lock

Definition at line 111 of file connection_basic.hpp.

◆ m_ssl_support

ssl_support_t epee::net_utils::connection_basic::m_ssl_support

Definition at line 118 of file connection_basic.hpp.

◆ m_want_close_connection

volatile uint32_t epee::net_utils::connection_basic::m_want_close_connection

Definition at line 109 of file connection_basic.hpp.

◆ m_was_shutdown

std::atomic<bool> epee::net_utils::connection_basic::m_was_shutdown

Definition at line 110 of file connection_basic.hpp.

◆ mI

std::unique_ptr< connection_basic_pimpl > epee::net_utils::connection_basic::mI

Definition at line 106 of file connection_basic.hpp.

◆ socket_

boost::asio::ssl::stream<boost::asio::ip::tcp::socket> epee::net_utils::connection_basic::socket_

Socket for the connection.

Definition at line 117 of file connection_basic.hpp.

◆ strand_

boost::asio::io_service::strand epee::net_utils::connection_basic::strand_

Strand to ensure the connection's handlers are not called concurrently.

Definition at line 115 of file connection_basic.hpp.


The documentation for this class was generated from the following files: