diff --git a/src/ripple/app/main/Application.cpp b/src/ripple/app/main/Application.cpp index b834234cc..d837b7f93 100644 --- a/src/ripple/app/main/Application.cpp +++ b/src/ripple/app/main/Application.cpp @@ -742,9 +742,8 @@ public: if (!getConfig ().WEBSOCKET_IP.empty () && getConfig ().WEBSOCKET_PORT) { m_wsPrivateDoor.reset (WSDoor::New (*m_resourceManager, - getOPs(), getConfig ().WEBSOCKET_IP, - getConfig ().WEBSOCKET_PORT, false, false, - m_wsSSLContext->get ())); + getOPs(), getConfig ().WEBSOCKET_IP, getConfig ().WEBSOCKET_PORT, + false, m_wsSSLContext->get ())); if (m_wsPrivateDoor == nullptr) { @@ -762,9 +761,8 @@ public: if (!getConfig ().WEBSOCKET_PUBLIC_IP.empty () && getConfig ().WEBSOCKET_PUBLIC_PORT) { m_wsPublicDoor.reset (WSDoor::New (*m_resourceManager, - getOPs(), getConfig ().WEBSOCKET_PUBLIC_IP, - getConfig ().WEBSOCKET_PUBLIC_PORT, true, false, - m_wsSSLContext->get ())); + getOPs(), getConfig ().WEBSOCKET_PUBLIC_IP, getConfig ().WEBSOCKET_PUBLIC_PORT, + true, m_wsSSLContext->get ())); if (m_wsPublicDoor == nullptr) { diff --git a/src/ripple/app/websocket/WSDoor.cpp b/src/ripple/app/websocket/WSDoor.cpp index a0241f587..dfd7528a0 100644 --- a/src/ripple/app/websocket/WSDoor.cpp +++ b/src/ripple/app/websocket/WSDoor.cpp @@ -45,15 +45,14 @@ class WSDoorImp { public: WSDoorImp (Resource::Manager& resourceManager, - InfoSub::Source& source, std::string const& strIp, - int iPort, bool bPublic, bool bProxy, boost::asio::ssl::context& ssl_context) + InfoSub::Source& source, std::string const& strIp, int iPort, + bool bPublic, boost::asio::ssl::context& ssl_context) : WSDoor (source) , Thread ("websocket") , m_resourceManager (resourceManager) , m_source (source) , m_ssl_context (ssl_context) , mPublic (bPublic) - , mProxy (bProxy) , mIp (strIp) , mPort (iPort) { @@ -72,14 +71,14 @@ private: boost::format ("Websocket: %s: Listening: %s %d ") % (mPublic ? "Public" : "Private") % mIp % mPort); - websocketpp::server_multitls::handler::ptr handler ( - new WSServerHandler ( - m_resourceManager, m_source, m_ssl_context, mPublic, mProxy)); + websocketpp::server_autotls::handler::ptr handler ( + new WSServerHandler ( + m_resourceManager, m_source, m_ssl_context, mPublic)); { ScopedLockType lock (m_endpointLock); - m_endpoint = std::make_shared (handler); + m_endpoint = std::make_shared (handler); } // Call the main-event-loop of the websocket server. @@ -120,7 +119,7 @@ private: void onStop () { - std::shared_ptr endpoint; + std::shared_ptr endpoint; { ScopedLockType lock (m_endpointLock); @@ -146,9 +145,8 @@ private: boost::asio::ssl::context& m_ssl_context; LockType m_endpointLock; - std::shared_ptr m_endpoint; + std::shared_ptr m_endpoint; bool mPublic; - bool mProxy; std::string mIp; int mPort; }; @@ -162,16 +160,16 @@ WSDoor::WSDoor (Stoppable& parent) //------------------------------------------------------------------------------ -WSDoor* WSDoor::New (Resource::Manager& resourceManager, - InfoSub::Source& source, std::string const& strIp, - int iPort, bool bPublic, bool bProxy, boost::asio::ssl::context& ssl_context) +WSDoor* WSDoor::New (Resource::Manager& resourceManager, InfoSub::Source& source, + std::string const& strIp, int iPort, bool bPublic, + boost::asio::ssl::context& ssl_context) { std::unique_ptr door; try { door = std::make_unique (resourceManager, - source, strIp, iPort, bPublic, bProxy, ssl_context); + source, strIp, iPort, bPublic, ssl_context); } catch (...) { diff --git a/src/ripple/app/websocket/WSDoor.h b/src/ripple/app/websocket/WSDoor.h index 9e61b59f5..64339817c 100644 --- a/src/ripple/app/websocket/WSDoor.h +++ b/src/ripple/app/websocket/WSDoor.h @@ -29,11 +29,11 @@ protected: explicit WSDoor (Stoppable& parent); public: - virtual ~WSDoor () { } + virtual ~WSDoor() = default; static WSDoor* New (Resource::Manager& resourceManager, - InfoSub::Source& source, std::string const& strIp, - int iPort, bool bPublic, bool bProxy, boost::asio::ssl::context& ssl_context); + InfoSub::Source& source, std::string const& strIp, int iPort, + bool bPublic, boost::asio::ssl::context& ssl_context); }; } // ripple diff --git a/src/ripple/app/websocket/WSServerHandler.h b/src/ripple/app/websocket/WSServerHandler.h index e3cc349a4..75becc5cb 100644 --- a/src/ripple/app/websocket/WSServerHandler.h +++ b/src/ripple/app/websocket/WSServerHandler.h @@ -77,16 +77,14 @@ protected: typedef hash_map MapType; MapType mMap; bool const mPublic; - bool const mProxy; public: WSServerHandler (Resource::Manager& resourceManager, - InfoSub::Source& source, boost::asio::ssl::context& ssl_context, bool bPublic, bool bProxy) + InfoSub::Source& source, boost::asio::ssl::context& ssl_context, bool bPublic) : m_resourceManager (resourceManager) , m_source (source) , m_ssl_context (ssl_context) , mPublic (bPublic) - , mProxy (bProxy) { } @@ -409,10 +407,6 @@ public: { return m_ssl_context; } - bool get_proxy () - { - return mProxy; - } // Respond to http requests. bool http (connection_ptr cpClient) diff --git a/src/websocket/src/sockets/multitls.hpp b/src/websocket/src/sockets/multitls.hpp deleted file mode 100644 index f94393221..000000000 --- a/src/websocket/src/sockets/multitls.hpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (c) 2011, Peter Thorson. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the WebSocket++ Project nor the - * names of its contributors may be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL PETER THORSON BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - */ - -#ifndef WEBSOCKETPP_SOCKET_MULTITLS_HPP -#define WEBSOCKETPP_SOCKET_MULTITLS_HPP - -// VFALCO NOTE This is a prohibited dependency direction! -#include -#include - -namespace websocketpp { -namespace socket { - -template -class multitls { -public: - typedef multitls type; - typedef ripple::MultiSocket multitls_socket; - typedef boost::asio::ip::tcp::socket native_socket_t; - typedef boost::shared_ptr multitls_socket_ptr; - - // should be private friended - boost::asio::io_service& get_io_service() { - return m_io_service; - } - - static void handle_shutdown(multitls_socket_ptr, const boost::system::error_code&) { - } - - void set_secure_only() { - m_secure_only = true; - } - - void set_plain_only() { - m_plain_only = true; - } - - // should be private friended? - multitls_socket::handshake_type get_handshake_type() { - if (static_cast< endpoint_type* >(this)->is_server()) { - return boost::asio::ssl::stream_base::server; - } else { - return boost::asio::ssl::stream_base::client; - } - } - - class handler_interface { - public: - virtual ~handler_interface() {} - - virtual void on_tcp_init() {}; - virtual boost::asio::ssl::context& get_ssl_context () = 0; - virtual bool get_proxy() = 0; - }; - - // Connection specific details - template - class connection { - public: - - multitls_socket& get_socket() { - return *m_socket_ptr; - } - - native_socket_t& get_native_socket() { - return m_socket_ptr->next_layer (); - } - - bool is_secure() { - return m_socket_ptr->ssl_handle() != NULL; - } - protected: - connection(multitls& e) - : m_endpoint(e) - , m_connection(static_cast< connection_type& >(*this)) {} - - void init() { - boost::asio::ssl::context& ssl_context ( - m_connection.get_handler()->get_ssl_context()); - - int flags = multitls_socket::Flag::server_role | - (m_endpoint.m_secure_only ? multitls_socket::Flag::ssl_required : 0) | - (m_endpoint.m_plain_only ? 0 : multitls_socket::Flag::ssl); - if (m_connection.get_handler()->get_proxy ()) - flags |= multitls_socket::Flag::proxy; - - m_socket_ptr = multitls_socket_ptr (multitls_socket::New ( - m_endpoint.get_io_service(), ssl_context, flags ) ); - } - - void async_init(boost::function callback) - { - m_connection.get_handler()->on_tcp_init(); - - // wait for TLS handshake - // TODO: configurable value - m_connection.register_timeout(5000, - fail::status::TIMEOUT_TLS, - "Timeout on TLS handshake"); - - m_socket_ptr->async_handshake( - m_endpoint.get_handshake_type(), - boost::bind( - &connection::handle_init, - this, - callback, - boost::asio::placeholders::error - ) - ); - } - - void handle_init(socket_init_callback callback,const boost::system::error_code& error) { - m_connection.cancel_timeout(); - callback(error); - } - - // note, this function for some reason shouldn't/doesn't need to be - // called for plain HTTP connections. not sure why. - bool shutdown() { - boost::system::error_code ignored_ec; - - m_socket_ptr->async_shutdown( // Don't block on connection shutdown DJS - boost::bind( - &multitls::handle_shutdown, - m_socket_ptr, - boost::asio::placeholders::error - ) - ); - - if (ignored_ec) { - return false; - } else { - return true; - } - } - private: - boost::shared_ptr m_context_ptr; - multitls_socket_ptr m_socket_ptr; - multitls& m_endpoint; - connection_type& m_connection; - }; -protected: - multitls (boost::asio::io_service& m) : m_io_service(m), m_secure_only(false), m_plain_only(false) {} -private: - boost::asio::io_service& m_io_service; - bool m_secure_only; - bool m_plain_only; -}; - -} // namespace socket -} // namespace websocketpp - -#endif // WEBSOCKETPP_SOCKET_MULTITLS_HPP diff --git a/src/websocket/src/websocketpp.hpp b/src/websocket/src/websocketpp.hpp index 6456402c3..c6692a9ba 100644 --- a/src/websocket/src/websocketpp.hpp +++ b/src/websocket/src/websocketpp.hpp @@ -41,13 +41,9 @@ namespace websocketpp { typedef websocketpp::endpoint server_tls; #endif - #ifdef WEBSOCKETPP_SOCKET_MULTITLS_HPP - typedef websocketpp::endpoint server_multitls; - #endif #ifdef WEBSOCKETPP_SOCKET_AUTOTLS_HPP typedef websocketpp::endpoint server_multitls; + websocketpp::socket::autotls> server_autotls; #endif #endif