Use autotls instead of multitls in websocket:

The MultiSocket class implements a socket that handshakes in multiple
protocols including SSL and PROXY. Unfortunately the way it type-erases the
handlers and buffers is incompatible with boost::asio coroutines. To pave the
way for coroutines this is part of a larger set of changes that roll back the
usage of MultiSocket to older code, and some custom implementations that use
templates. The custom implementations are more simple since they use
coroutines. Removing MultiSocket will make many other classes and source files
unused, a big win for trimming down the codebase size.
This commit is contained in:
Vinnie Falco
2014-10-18 17:40:21 -07:00
parent 44c68d6174
commit ec92344fb4
10 changed files with 45 additions and 18 deletions

View File

@@ -4210,7 +4210,7 @@
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\websocket\src\shared_const_buffer.hpp"> <ClInclude Include="..\..\src\websocket\src\shared_const_buffer.hpp">
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\websocket\src\sockets\multitls.hpp"> <ClInclude Include="..\..\src\websocket\src\sockets\autotls.hpp">
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\websocket\src\sockets\socket_base.hpp"> <ClInclude Include="..\..\src\websocket\src\sockets\socket_base.hpp">
</ClInclude> </ClInclude>

View File

@@ -5667,7 +5667,7 @@
<ClInclude Include="..\..\src\websocket\src\shared_const_buffer.hpp"> <ClInclude Include="..\..\src\websocket\src\shared_const_buffer.hpp">
<Filter>websocket\src</Filter> <Filter>websocket\src</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\websocket\src\sockets\multitls.hpp"> <ClInclude Include="..\..\src\websocket\src\sockets\autotls.hpp">
<Filter>websocket\src\sockets</Filter> <Filter>websocket\src\sockets</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\websocket\src\sockets\socket_base.hpp"> <ClInclude Include="..\..\src\websocket\src\sockets\socket_base.hpp">

View File

@@ -204,7 +204,7 @@ public:
assert (result.second); assert (result.second);
(void) result.second; (void) result.second;
WriteLog (lsDEBUG, WSServerHandlerLog) << WriteLog (lsDEBUG, WSServerHandlerLog) <<
"Ws:: on_open(" << cpClient->get_socket ().remote_endpoint ().to_string () << ")"; "Ws:: on_open(" << cpClient->get_socket ().remote_endpoint() << ")";
} }
catch (...) catch (...)
{ {
@@ -226,7 +226,7 @@ public:
try try
{ {
WriteLog (lsDEBUG, WSServerHandlerLog) << WriteLog (lsDEBUG, WSServerHandlerLog) <<
"Ws:: on_pong(" << cpClient->get_socket ().remote_endpoint ().to_string () << ")"; "Ws:: on_pong(" << cpClient->get_socket ().remote_endpoint() << ")";
} }
catch (...) catch (...)
{ {
@@ -258,7 +258,7 @@ public:
{ {
WriteLog (lsDEBUG, WSServerHandlerLog) << WriteLog (lsDEBUG, WSServerHandlerLog) <<
"Ws:: " << reason << "(" << "Ws:: " << reason << "(" <<
cpClient->get_socket ().remote_endpoint ().to_string () << ") not found"; cpClient->get_socket ().remote_endpoint() << ") not found";
} }
catch (...) catch (...)
{ {
@@ -274,7 +274,7 @@ public:
{ {
WriteLog (lsDEBUG, WSServerHandlerLog) << WriteLog (lsDEBUG, WSServerHandlerLog) <<
"Ws:: " << reason << "(" << "Ws:: " << reason << "(" <<
cpClient->get_socket ().remote_endpoint ().to_string () << ") found"; cpClient->get_socket ().remote_endpoint () << ") found";
} }
catch (...) catch (...)
{ {
@@ -306,7 +306,7 @@ public:
try try
{ {
WriteLog (lsDEBUG, WSServerHandlerLog) << WriteLog (lsDEBUG, WSServerHandlerLog) <<
"Ws:: Rejected(" << to_string (cpClient->get_socket ().remote_endpoint ()) << "Ws:: Rejected(" << cpClient->get_socket().remote_endpoint() <<
") '" << mpMessage->get_payload () << "'"; ") '" << mpMessage->get_payload () << "'";
} }
catch (...) catch (...)
@@ -366,7 +366,7 @@ public:
try try
{ {
WriteLog (lsDEBUG, WSServerHandlerLog) << WriteLog (lsDEBUG, WSServerHandlerLog) <<
"Ws:: Receiving(" << to_string (cpClient->get_socket ().remote_endpoint ()) << "Ws:: Receiving(" << cpClient->get_socket ().remote_endpoint () <<
") '" << mpMessage->get_payload () << "'"; ") '" << mpMessage->get_payload () << "'";
} }
catch (...) catch (...)

View File

@@ -22,7 +22,6 @@
#include <ripple/resource/api/Consumer.h> #include <ripple/resource/api/Consumer.h>
#include <ripple/resource/api/Gossip.h> #include <ripple/resource/api/Gossip.h>
#include <beast/insight/Collector.h> #include <beast/insight/Collector.h>
#include <beast/net/IPEndpoint.h> #include <beast/net/IPEndpoint.h>
#include <beast/utility/Journal.h> #include <beast/utility/Journal.h>

View File

@@ -33,7 +33,7 @@
#include <websocket/src/common.hpp> #include <websocket/src/common.hpp>
#include <websocket/src/sockets/socket_base.hpp> #include <websocket/src/sockets/socket_base.hpp>
#include <websocket/src/sockets/multitls.hpp> #include <websocket/src/sockets/autotls.hpp>
#include <websocket/src/websocketpp.hpp> #include <websocket/src/websocketpp.hpp>
#include <websocket/src/logger/logger.hpp> #include <websocket/src/logger/logger.hpp>

View File

@@ -21,6 +21,7 @@
#define RIPPLE_WEBSOCKET_AUTOSOCKET_H_INCLUDED #define RIPPLE_WEBSOCKET_AUTOSOCKET_H_INCLUDED
#include <ripple/basics/Log.h> #include <ripple/basics/Log.h>
#include <beast/asio/IPAddressConversion.h>
#include <beast/asio/bind_handler.h> #include <beast/asio/bind_handler.h>
#include <beast/asio/placeholders.h> #include <beast/asio/placeholders.h>
#include <boost/asio.hpp> #include <boost/asio.hpp>
@@ -85,6 +86,20 @@ public:
mBuffer.clear (); mBuffer.clear ();
} }
beast::IP::Endpoint
local_endpoint()
{
return beast::IP::from_asio(
lowest_layer().local_endpoint());
}
beast::IP::Endpoint
remote_endpoint()
{
return beast::IP::from_asio(
lowest_layer().remote_endpoint());
}
lowest_layer_type& lowest_layer () lowest_layer_type& lowest_layer ()
{ {
return mSocket->lowest_layer (); return mSocket->lowest_layer ();

View File

@@ -29,7 +29,7 @@
#define WEBSOCKETPP_ENDPOINT_HPP #define WEBSOCKETPP_ENDPOINT_HPP
#include "connection.hpp" #include "connection.hpp"
#include "sockets/multitls.hpp" // should this be here? #include "sockets/autotls.hpp" // should this be here?
#include "logger/logger.hpp" #include "logger/logger.hpp"
#include <boost/asio.hpp> #include <boost/asio.hpp>
@@ -74,7 +74,7 @@ protected:
*/ */
template < template <
template <class> class role, template <class> class role,
template <class> class socket = socket::multitls, template <class> class socket = socket::autotls,
template <class> class logger = log::logger> template <class> class logger = log::logger>
class endpoint class endpoint
: public endpoint_base, : public endpoint_base,

View File

@@ -607,7 +607,7 @@ void server<endpoint>::connection<connection_type>::handle_read_request(
m_version = -1; m_version = -1;
shared_const_buffer buffer(reply); shared_const_buffer buffer(reply);
async_write( boost::asio::async_write(
m_connection.get_socket(), m_connection.get_socket(),
shared_const_buffer(reply), shared_const_buffer(reply),
boost::bind( boost::bind(
@@ -866,7 +866,7 @@ void server<endpoint>::connection<connection_type>::write_response() {
m_endpoint.m_alog->at(log::alevel::DEBUG_HANDSHAKE) << raw << log::endl; m_endpoint.m_alog->at(log::alevel::DEBUG_HANDSHAKE) << raw << log::endl;
async_write( boost::asio::async_write(
m_connection.get_socket(), m_connection.get_socket(),
//boost::asio::buffer(raw), //boost::asio::buffer(raw),
buffer, buffer,

View File

@@ -28,6 +28,9 @@
#ifndef WEBSOCKETPP_SOCKET_AUTOTLS_HPP #ifndef WEBSOCKETPP_SOCKET_AUTOTLS_HPP
#define WEBSOCKETPP_SOCKET_AUTOTLS_HPP #define WEBSOCKETPP_SOCKET_AUTOTLS_HPP
#include <beast/asio/placeholders.h>
#include <functional>
// Note that AutoSocket.h must be included before this file // Note that AutoSocket.h must be included before this file
namespace websocketpp { namespace websocketpp {
@@ -89,6 +92,12 @@ public:
bool is_secure() { bool is_secure() {
return m_socket_ptr->isSecure(); return m_socket_ptr->isSecure();
} }
typename AutoSocket::lowest_layer_type&
get_native_socket() {
return m_socket_ptr->lowest_layer();
}
protected: protected:
connection(autotls<endpoint_type>& e) connection(autotls<endpoint_type>& e)
: m_endpoint(e) : m_endpoint(e)
@@ -115,11 +124,11 @@ public:
m_socket_ptr->async_handshake( m_socket_ptr->async_handshake(
m_endpoint.get_handshake_type(), m_endpoint.get_handshake_type(),
boost::bind( std::bind(
&connection<connection_type>::handle_init, &connection<connection_type>::handle_init,
this, this,
callback, callback,
boost::asio::placeholders::error beast::asio::placeholders::error
) )
); );
} }
@@ -135,10 +144,10 @@ public:
boost::system::error_code ignored_ec; boost::system::error_code ignored_ec;
m_socket_ptr->async_shutdown( // Don't block on connection shutdown DJS m_socket_ptr->async_shutdown( // Don't block on connection shutdown DJS
boost::bind( std::bind(
&autotls<endpoint_type>::handle_shutdown, &autotls<endpoint_type>::handle_shutdown,
m_socket_ptr, m_socket_ptr,
boost::asio::placeholders::error beast::asio::placeholders::error
) )
); );

View File

@@ -45,6 +45,10 @@ namespace websocketpp {
typedef websocketpp::endpoint<websocketpp::role::server, typedef websocketpp::endpoint<websocketpp::role::server,
websocketpp::socket::multitls> server_multitls; websocketpp::socket::multitls> server_multitls;
#endif #endif
#ifdef WEBSOCKETPP_SOCKET_AUTOTLS_HPP
typedef websocketpp::endpoint<websocketpp::role::server,
websocketpp::socket::autotls> server_multitls;
#endif
#endif #endif