From ec92344fb4e6ccfcec6883dc4e988277a2df6507 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 18 Oct 2014 17:40:21 -0700 Subject: [PATCH] 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. --- Builds/VisualStudio2013/RippleD.vcxproj | 2 +- Builds/VisualStudio2013/RippleD.vcxproj.filters | 2 +- src/ripple/app/websocket/WSServerHandler.h | 12 ++++++------ src/ripple/resource/api/Manager.h | 1 - src/ripple/unity/websocket.h | 2 +- src/ripple/websocket/autosocket/AutoSocket.h | 15 +++++++++++++++ src/websocket/src/endpoint.hpp | 4 ++-- src/websocket/src/roles/server.hpp | 4 ++-- src/websocket/src/sockets/autotls.hpp | 17 +++++++++++++---- src/websocket/src/websocketpp.hpp | 4 ++++ 10 files changed, 45 insertions(+), 18 deletions(-) diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj index 9a37031a1..e2d4ebe8a 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj +++ b/Builds/VisualStudio2013/RippleD.vcxproj @@ -4210,7 +4210,7 @@ - + diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters index 04a6f3d63..d03ad90c8 100644 --- a/Builds/VisualStudio2013/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters @@ -5667,7 +5667,7 @@ websocket\src - + websocket\src\sockets diff --git a/src/ripple/app/websocket/WSServerHandler.h b/src/ripple/app/websocket/WSServerHandler.h index 56e72fc50..55952890b 100644 --- a/src/ripple/app/websocket/WSServerHandler.h +++ b/src/ripple/app/websocket/WSServerHandler.h @@ -204,7 +204,7 @@ public: assert (result.second); (void) result.second; WriteLog (lsDEBUG, WSServerHandlerLog) << - "Ws:: on_open(" << cpClient->get_socket ().remote_endpoint ().to_string () << ")"; + "Ws:: on_open(" << cpClient->get_socket ().remote_endpoint() << ")"; } catch (...) { @@ -226,7 +226,7 @@ public: try { WriteLog (lsDEBUG, WSServerHandlerLog) << - "Ws:: on_pong(" << cpClient->get_socket ().remote_endpoint ().to_string () << ")"; + "Ws:: on_pong(" << cpClient->get_socket ().remote_endpoint() << ")"; } catch (...) { @@ -258,7 +258,7 @@ public: { WriteLog (lsDEBUG, WSServerHandlerLog) << "Ws:: " << reason << "(" << - cpClient->get_socket ().remote_endpoint ().to_string () << ") not found"; + cpClient->get_socket ().remote_endpoint() << ") not found"; } catch (...) { @@ -274,7 +274,7 @@ public: { WriteLog (lsDEBUG, WSServerHandlerLog) << "Ws:: " << reason << "(" << - cpClient->get_socket ().remote_endpoint ().to_string () << ") found"; + cpClient->get_socket ().remote_endpoint () << ") found"; } catch (...) { @@ -306,7 +306,7 @@ public: try { WriteLog (lsDEBUG, WSServerHandlerLog) << - "Ws:: Rejected(" << to_string (cpClient->get_socket ().remote_endpoint ()) << + "Ws:: Rejected(" << cpClient->get_socket().remote_endpoint() << ") '" << mpMessage->get_payload () << "'"; } catch (...) @@ -366,7 +366,7 @@ public: try { WriteLog (lsDEBUG, WSServerHandlerLog) << - "Ws:: Receiving(" << to_string (cpClient->get_socket ().remote_endpoint ()) << + "Ws:: Receiving(" << cpClient->get_socket ().remote_endpoint () << ") '" << mpMessage->get_payload () << "'"; } catch (...) diff --git a/src/ripple/resource/api/Manager.h b/src/ripple/resource/api/Manager.h index b30f84e08..3587dccb3 100644 --- a/src/ripple/resource/api/Manager.h +++ b/src/ripple/resource/api/Manager.h @@ -22,7 +22,6 @@ #include #include - #include #include #include diff --git a/src/ripple/unity/websocket.h b/src/ripple/unity/websocket.h index 7424facd0..3d4de77af 100644 --- a/src/ripple/unity/websocket.h +++ b/src/ripple/unity/websocket.h @@ -33,7 +33,7 @@ #include #include -#include +#include #include #include diff --git a/src/ripple/websocket/autosocket/AutoSocket.h b/src/ripple/websocket/autosocket/AutoSocket.h index eee970947..75fa330d1 100644 --- a/src/ripple/websocket/autosocket/AutoSocket.h +++ b/src/ripple/websocket/autosocket/AutoSocket.h @@ -21,6 +21,7 @@ #define RIPPLE_WEBSOCKET_AUTOSOCKET_H_INCLUDED #include +#include #include #include #include @@ -85,6 +86,20 @@ public: 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 () { return mSocket->lowest_layer (); diff --git a/src/websocket/src/endpoint.hpp b/src/websocket/src/endpoint.hpp index c457ef5d7..862243c1c 100644 --- a/src/websocket/src/endpoint.hpp +++ b/src/websocket/src/endpoint.hpp @@ -29,7 +29,7 @@ #define WEBSOCKETPP_ENDPOINT_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 @@ -74,7 +74,7 @@ protected: */ template < template class role, - template class socket = socket::multitls, + template class socket = socket::autotls, template class logger = log::logger> class endpoint : public endpoint_base, diff --git a/src/websocket/src/roles/server.hpp b/src/websocket/src/roles/server.hpp index 35c8c04d6..01b4d9ffe 100644 --- a/src/websocket/src/roles/server.hpp +++ b/src/websocket/src/roles/server.hpp @@ -607,7 +607,7 @@ void server::connection::handle_read_request( m_version = -1; shared_const_buffer buffer(reply); - async_write( + boost::asio::async_write( m_connection.get_socket(), shared_const_buffer(reply), boost::bind( @@ -866,7 +866,7 @@ void server::connection::write_response() { m_endpoint.m_alog->at(log::alevel::DEBUG_HANDSHAKE) << raw << log::endl; - async_write( + boost::asio::async_write( m_connection.get_socket(), //boost::asio::buffer(raw), buffer, diff --git a/src/websocket/src/sockets/autotls.hpp b/src/websocket/src/sockets/autotls.hpp index 803e7e65b..602804097 100644 --- a/src/websocket/src/sockets/autotls.hpp +++ b/src/websocket/src/sockets/autotls.hpp @@ -28,6 +28,9 @@ #ifndef WEBSOCKETPP_SOCKET_AUTOTLS_HPP #define WEBSOCKETPP_SOCKET_AUTOTLS_HPP +#include +#include + // Note that AutoSocket.h must be included before this file namespace websocketpp { @@ -89,6 +92,12 @@ public: bool is_secure() { return m_socket_ptr->isSecure(); } + + typename AutoSocket::lowest_layer_type& + get_native_socket() { + return m_socket_ptr->lowest_layer(); + } + protected: connection(autotls& e) : m_endpoint(e) @@ -115,11 +124,11 @@ public: m_socket_ptr->async_handshake( m_endpoint.get_handshake_type(), - boost::bind( + std::bind( &connection::handle_init, this, callback, - boost::asio::placeholders::error + beast::asio::placeholders::error ) ); } @@ -135,10 +144,10 @@ public: boost::system::error_code ignored_ec; m_socket_ptr->async_shutdown( // Don't block on connection shutdown DJS - boost::bind( + std::bind( &autotls::handle_shutdown, m_socket_ptr, - boost::asio::placeholders::error + beast::asio::placeholders::error ) ); diff --git a/src/websocket/src/websocketpp.hpp b/src/websocket/src/websocketpp.hpp index 8ae9e804a..6456402c3 100644 --- a/src/websocket/src/websocketpp.hpp +++ b/src/websocket/src/websocketpp.hpp @@ -45,6 +45,10 @@ namespace websocketpp { typedef websocketpp::endpoint server_multitls; #endif + #ifdef WEBSOCKETPP_SOCKET_AUTOTLS_HPP + typedef websocketpp::endpoint server_multitls; + #endif #endif