From a0c4e685c58056babc7cfbcf8f723d7673de6be5 Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Tue, 22 Oct 2013 12:32:48 -0700 Subject: [PATCH] Add local_endpoint and remote_endpoint to MultiSocket --- src/ripple_net/basics/MultiSocket.h | 2 + src/ripple_net/basics/impl/MultiSocketType.h | 103 ++++++++++++------- 2 files changed, 70 insertions(+), 35 deletions(-) diff --git a/src/ripple_net/basics/MultiSocket.h b/src/ripple_net/basics/MultiSocket.h index 3ce79f7abb..efa1270f93 100644 --- a/src/ripple_net/basics/MultiSocket.h +++ b/src/ripple_net/basics/MultiSocket.h @@ -104,6 +104,8 @@ public: // Note that this returns the original flags virtual Flag getFlags () = 0; + virtual IPAddress local_endpoint() = 0; + virtual IPAddress remote_endpoint() = 0; virtual ProxyInfo getProxyInfo () = 0; virtual SSL* native_handle () = 0; diff --git a/src/ripple_net/basics/impl/MultiSocketType.h b/src/ripple_net/basics/impl/MultiSocketType.h index c223fac4d5..af28dd1fe6 100644 --- a/src/ripple_net/basics/impl/MultiSocketType.h +++ b/src/ripple_net/basics/impl/MultiSocketType.h @@ -27,6 +27,32 @@ template class MultiSocketType : public MultiSocket { +private: + // Tells us what to do next + // + enum State + { + stateNone, // Uninitialized, unloved. + stateHandshake, // We need a call to handshake() to proceed + stateExpectPROXY, // We expect to see a proxy handshake + stateDetectSSL, // We should detect SSL + stateHandshakeFinal, // Final call to underlying stream handshake() + stateReady // Stream is set and ready to go + }; + + Flag m_flags; + State m_state; + boost::asio::ssl::context& m_ssl_context; + int m_verify_mode; + ScopedPointer m_stream; + ScopedPointer m_ssl_stream; // the ssl portion of our stream if it exists + bool m_needsShutdown; + StreamSocket m_next_layer; + ProxyInfo m_proxyInfo; + bool m_proxyInfoSet; + SSL* m_native_ssl_handle; + Flag m_origFlags; + protected: typedef boost::system::error_code error_code; @@ -44,6 +70,7 @@ public: , m_stream (nullptr) , m_needsShutdown (false) , m_next_layer (arg) + , m_proxyInfoSet (false) , m_native_ssl_handle (nullptr) , m_origFlags (cleaned_flags (flags)) { @@ -53,18 +80,6 @@ public: } protected: - // Tells us what to do next - // - enum State - { - stateNone, // Uninitialized, unloved. - stateHandshake, // We need a call to handshake() to proceed - stateExpectPROXY, // We expect to see a proxy handshake - stateDetectSSL, // We should detect SSL - stateHandshakeFinal, // Final call to underlying stream handshake() - stateReady // Stream is set and ready to go - }; - //-------------------------------------------------------------------------- // // MultiSocket @@ -75,6 +90,36 @@ protected: return m_origFlags; } + IPAddress local_endpoint() + { + return IPAddressConversion::from_asio ( + m_next_layer.local_endpoint()); + } + + IPAddress remote_endpoint() + { + if (m_proxyInfoSet) + { + if (m_proxyInfo.protocol == "TCP4") + { + return IPAddress ( + IPAddress::V4 ( + m_proxyInfo.destAddress.value [0], + m_proxyInfo.destAddress.value [1], + m_proxyInfo.destAddress.value [2], + m_proxyInfo.destAddress.value [4]) + , m_proxyInfo.destPort); + } + + // VFALCO TODO IPv6 support + bassertfalse; + return IPAddress(); + } + + return IPAddressConversion::from_asio ( + m_next_layer.remote_endpoint()); + } + ProxyInfo getProxyInfo () { return m_proxyInfo; @@ -689,6 +734,7 @@ protected: if (op.getLogic ().success ()) { m_proxyInfo = op.getLogic ().getInfo (); + m_proxyInfoSet = true; // Strip off the PROXY flag. m_flags = m_flags.without (Flag::proxy); @@ -775,6 +821,15 @@ protected: struct AsyncOp : ComposedAsyncOperation { typedef SharedHandlerAllocator Allocator; + + SharedHandlerPtr m_handler; + MultiSocketType & m_owner; + Stream& m_stream; + handshake_type const m_type; + boost::asio::basic_streambuf m_buffer; + HandshakeDetectorType m_proxy; + HandshakeDetectorType m_ssl; + bool m_running; AsyncOp (MultiSocketType & owner, Stream& stream, handshake_type type, ConstBuffers const& buffers, @@ -865,6 +920,7 @@ protected: if (m_proxy.getLogic ().success ()) { m_owner.m_proxyInfo = m_proxy.getLogic ().getInfo (); + m_owner.m_proxyInfoSet = true; // Strip off the PROXY flag. m_owner.m_flags = m_owner.m_flags.without (Flag::proxy); @@ -933,30 +989,7 @@ protected: { return m_running || m_handler->is_continuation (); } - - private: - SharedHandlerPtr m_handler; - MultiSocketType & m_owner; - Stream& m_stream; - handshake_type const m_type; - boost::asio::basic_streambuf m_buffer; - HandshakeDetectorType m_proxy; - HandshakeDetectorType m_ssl; - bool m_running; }; - -private: - Flag m_flags; - State m_state; - boost::asio::ssl::context& m_ssl_context; - int m_verify_mode; - ScopedPointer m_stream; - ScopedPointer m_ssl_stream; // the ssl portion of our stream if it exists - bool m_needsShutdown; - StreamSocket m_next_layer; - ProxyInfo m_proxyInfo; - SSL* m_native_ssl_handle; - Flag m_origFlags; }; #endif