@ -80,10 +80,9 @@ PRAGMA_WARNING_DISABLE_VS(4355)
connection<t_protocol_handler>::connection( boost::asio::io_service& io_service,
connection<t_protocol_handler>::connection( boost::asio::io_service& io_service,
boost::shared_ptr<shared_state> state,
boost::shared_ptr<shared_state> state,
t_connection_type connection_type,
t_connection_type connection_type,
epee::net_utils::ssl_support_t ssl_support,
ssl_support_t ssl_support
ssl_context_t &ssl_context
)
)
: connection(boost::asio::ip::tcp::socket{io_service}, std::move(state), connection_type, ssl_support, ssl_context )
: connection(boost::asio::ip::tcp::socket{io_service}, std::move(state), connection_type, ssl_support)
{
{
}
}
@ -91,11 +90,10 @@ PRAGMA_WARNING_DISABLE_VS(4355)
connection<t_protocol_handler>::connection( boost::asio::ip::tcp::socket&& sock,
connection<t_protocol_handler>::connection( boost::asio::ip::tcp::socket&& sock,
boost::shared_ptr<shared_state> state,
boost::shared_ptr<shared_state> state,
t_connection_type connection_type,
t_connection_type connection_type,
epee::net_utils::ssl_support_t ssl_support,
ssl_support_t ssl_support
ssl_context_t &ssl_context
)
)
:
:
connection_basic(std::move(sock), state, ssl_support, ssl_context ),
connection_basic(std::move(sock), state, ssl_support),
m_protocol_handler(this, check_and_get(state).config, context),
m_protocol_handler(this, check_and_get(state).config, context),
m_connection_type( connection_type ),
m_connection_type( connection_type ),
m_throttle_speed_in("speed_in", "throttle_speed_in"),
m_throttle_speed_in("speed_in", "throttle_speed_in"),
@ -176,9 +174,9 @@ PRAGMA_WARNING_DISABLE_VS(4355)
_dbg3("[sock " << socket_.native_handle() << "] new connection from " << print_connection_context_short(context) <<
_dbg3("[sock " << socket_.native_handle() << "] new connection from " << print_connection_context_short(context) <<
" to " << local_ep.address().to_string() << ':' << local_ep.port() <<
" to " << local_ep.address().to_string() << ':' << local_ep.port() <<
", total sockets objects " << get_stats ().sock_count);
", total sockets objects " << get_state ().sock_count);
if(static_cast<shared_state&>(get_stats()).pfilter && !static_cast<shared_state&>(get_stats ()).pfilter->is_remote_host_allowed(context.m_remote_address))
if(static_cast<shared_state&>(get_state()).pfilter && !static_cast<shared_state&>(get_state ()).pfilter->is_remote_host_allowed(context.m_remote_address))
{
{
_dbg2("[sock " << socket().native_handle() << "] host denied " << context.m_remote_address.host_str() << ", shutdowning connection");
_dbg2("[sock " << socket().native_handle() << "] host denied " << context.m_remote_address.host_str() << ", shutdowning connection");
close();
close();
@ -901,8 +899,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
m_threads_count(0),
m_threads_count(0),
m_thread_index(0),
m_thread_index(0),
m_connection_type( connection_type ),
m_connection_type( connection_type ),
new_connection_(),
new_connection_()
m_ssl_context({boost::asio::ssl::context(boost::asio::ssl::context::tlsv12), {}})
{
{
create_server_type_map();
create_server_type_map();
m_thread_name_prefix = "NET";
m_thread_name_prefix = "NET";
@ -918,8 +915,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
m_threads_count(0),
m_threads_count(0),
m_thread_index(0),
m_thread_index(0),
m_connection_type(connection_type),
m_connection_type(connection_type),
new_connection_(),
new_connection_()
m_ssl_context({boost::asio::ssl::context(boost::asio::ssl::context::sslv23), {}})
{
{
create_server_type_map();
create_server_type_map();
m_thread_name_prefix = "NET";
m_thread_name_prefix = "NET";
@ -941,14 +937,14 @@ PRAGMA_WARNING_DISABLE_VS(4355)
}
}
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
template<class t_protocol_handler>
template<class t_protocol_handler>
bool boosted_tcp_server<t_protocol_handler>::init_server(uint32_t port, const std::string address, epee::net_utils::ssl_support_t ssl_support, const std::pair<std::string, std::string> &private_key_and_certificate_path, const std::string &ca_file, const std::vector<std::vector<uint8_t>> &allowed_fingerprints, bool allow_any_cert )
bool boosted_tcp_server<t_protocol_handler>::init_server(uint32_t port, const std::string address, ssl_options_t ssl_options )
{
{
TRY_ENTRY();
TRY_ENTRY();
m_stop_signal_sent = false;
m_stop_signal_sent = false;
m_port = port;
m_port = port;
m_address = address;
m_address = address;
if (ssl_support != epee::net_utils::ssl_support_t::e_ssl_support_disabled )
if (ssl_options )
m_ssl_context = create_ssl_context(private_key_and_certificate_path, ca_file, allowed_fingerprints, allow_any_cert );
m_state->configure_ssl(std::move(ssl_options) );
// Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
// Open the acceptor with the option to reuse the address (i.e. SO_REUSEADDR).
boost::asio::ip::tcp::resolver resolver(io_service_);
boost::asio::ip::tcp::resolver resolver(io_service_);
boost::asio::ip::tcp::resolver::query query(address, boost::lexical_cast<std::string>(port), boost::asio::ip::tcp::resolver::query::canonical_name);
boost::asio::ip::tcp::resolver::query query(address, boost::lexical_cast<std::string>(port), boost::asio::ip::tcp::resolver::query::canonical_name);
@ -960,7 +956,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
boost::asio::ip::tcp::endpoint binded_endpoint = acceptor_.local_endpoint();
boost::asio::ip::tcp::endpoint binded_endpoint = acceptor_.local_endpoint();
m_port = binded_endpoint.port();
m_port = binded_endpoint.port();
MDEBUG("start accept");
MDEBUG("start accept");
new_connection_.reset(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, ssl_support, m_ssl_contex t));
new_connection_.reset(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, m_state-> ssl_options(). support));
acceptor_.async_accept(new_connection_->socket(),
acceptor_.async_accept(new_connection_->socket(),
boost::bind(&boosted_tcp_server<t_protocol_handler>::handle_accept, this,
boost::bind(&boosted_tcp_server<t_protocol_handler>::handle_accept, this,
boost::asio::placeholders::error));
boost::asio::placeholders::error));
@ -982,7 +978,7 @@ PRAGMA_WARNING_DISABLE_VS(4355)
PUSH_WARNINGS
PUSH_WARNINGS
DISABLE_GCC_WARNING(maybe-uninitialized)
DISABLE_GCC_WARNING(maybe-uninitialized)
template<class t_protocol_handler>
template<class t_protocol_handler>
bool boosted_tcp_server<t_protocol_handler>::init_server(const std::string port, const std::string& address, epee::net_utils::ssl_support_t ssl_support, const std::pair<std::string, std::string> &private_key_and_certificate_path, const std::string &ca_file, const std::vector<std::vector<uint8_t>> &allowed_fingerprints, bool allow_any_cert )
bool boosted_tcp_server<t_protocol_handler>::init_server(const std::string port, const std::string& address, ssl_options_t ssl_options )
{
{
uint32_t p = 0;
uint32_t p = 0;
@ -990,7 +986,7 @@ DISABLE_GCC_WARNING(maybe-uninitialized)
MERROR("Failed to convert port no = " << port);
MERROR("Failed to convert port no = " << port);
return false;
return false;
}
}
return this->init_server(p, address, ssl_support, private_key_and_certificate_path, ca_file, allowed_fingerprints, allow_any_cert );
return this->init_server(p, address, std::move(ssl_options) );
}
}
POP_WARNINGS
POP_WARNINGS
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
@ -1165,7 +1161,7 @@ POP_WARNINGS
new_connection_->setRpcStation(); // hopefully this is not needed actually
new_connection_->setRpcStation(); // hopefully this is not needed actually
}
}
connection_ptr conn(std::move(new_connection_));
connection_ptr conn(std::move(new_connection_));
new_connection_.reset(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, conn->get_ssl_support(), m_ssl_context ));
new_connection_.reset(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, conn->get_ssl_support()));
acceptor_.async_accept(new_connection_->socket(),
acceptor_.async_accept(new_connection_->socket(),
boost::bind(&boosted_tcp_server<t_protocol_handler>::handle_accept, this,
boost::bind(&boosted_tcp_server<t_protocol_handler>::handle_accept, this,
boost::asio::placeholders::error));
boost::asio::placeholders::error));
@ -1200,7 +1196,7 @@ POP_WARNINGS
assert(m_state != nullptr); // always set in constructor
assert(m_state != nullptr); // always set in constructor
_erro("Some problems at accept: " << e.message() << ", connections_count = " << m_state->sock_count);
_erro("Some problems at accept: " << e.message() << ", connections_count = " << m_state->sock_count);
misc_utils::sleep_no_w(100);
misc_utils::sleep_no_w(100);
new_connection_.reset(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, new_connection_->get_ssl_support(), m_ssl_context ));
new_connection_.reset(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, new_connection_->get_ssl_support()));
acceptor_.async_accept(new_connection_->socket(),
acceptor_.async_accept(new_connection_->socket(),
boost::bind(&boosted_tcp_server<t_protocol_handler>::handle_accept, this,
boost::bind(&boosted_tcp_server<t_protocol_handler>::handle_accept, this,
boost::asio::placeholders::error));
boost::asio::placeholders::error));
@ -1211,7 +1207,7 @@ POP_WARNINGS
{
{
if(std::addressof(get_io_service()) == std::addressof(GET_IO_SERVICE(sock)))
if(std::addressof(get_io_service()) == std::addressof(GET_IO_SERVICE(sock)))
{
{
connection_ptr conn(new connection<t_protocol_handler>(std::move(sock), m_state, m_connection_type, ssl_support, m_ssl_context ));
connection_ptr conn(new connection<t_protocol_handler>(std::move(sock), m_state, m_connection_type, ssl_support));
if(conn->start(false, 1 < m_threads_count, std::move(real_remote)))
if(conn->start(false, 1 < m_threads_count, std::move(real_remote)))
{
{
conn->get_context(out);
conn->get_context(out);
@ -1298,7 +1294,7 @@ POP_WARNINGS
_dbg3("Connected success to " << adr << ':' << port);
_dbg3("Connected success to " << adr << ':' << port);
const epee::net_utils:: ssl_support_t ssl_support = new_connection_l->get_ssl_support();
const ssl_support_t ssl_support = new_connection_l->get_ssl_support();
if (ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_enabled || ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_autodetect)
if (ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_enabled || ssl_support == epee::net_utils::ssl_support_t::e_ssl_support_autodetect)
{
{
// Handshake
// Handshake
@ -1329,7 +1325,7 @@ POP_WARNINGS
{
{
TRY_ENTRY();
TRY_ENTRY();
connection_ptr new_connection_l(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, ssl_support, m_ssl_context ) );
connection_ptr new_connection_l(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, ssl_support) );
connections_mutex.lock();
connections_mutex.lock();
connections_.insert(new_connection_l);
connections_.insert(new_connection_l);
MDEBUG("connections_ size now " << connections_.size());
MDEBUG("connections_ size now " << connections_.size());
@ -1393,7 +1389,7 @@ POP_WARNINGS
bool boosted_tcp_server<t_protocol_handler>::connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeout, const t_callback &cb, const std::string& bind_ip, epee::net_utils::ssl_support_t ssl_support)
bool boosted_tcp_server<t_protocol_handler>::connect_async(const std::string& adr, const std::string& port, uint32_t conn_timeout, const t_callback &cb, const std::string& bind_ip, epee::net_utils::ssl_support_t ssl_support)
{
{
TRY_ENTRY();
TRY_ENTRY();
connection_ptr new_connection_l(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, ssl_support, m_ssl_context ) );
connection_ptr new_connection_l(new connection<t_protocol_handler>(io_service_, m_state, m_connection_type, ssl_support) );
connections_mutex.lock();
connections_mutex.lock();
connections_.insert(new_connection_l);
connections_.insert(new_connection_l);
MDEBUG("connections_ size now " << connections_.size());
MDEBUG("connections_ size now " << connections_.size());