diff --git a/src/ripple_net/basics/RPCDoor.cpp b/src/ripple_net/basics/RPCDoor.cpp index 522936a2b7..6e756898ca 100644 --- a/src/ripple_net/basics/RPCDoor.cpp +++ b/src/ripple_net/basics/RPCDoor.cpp @@ -60,9 +60,10 @@ public: mAcceptor.set_option (boost::asio::ip::tcp::acceptor::reuse_address (true)); - mAcceptor.async_accept (new_connection->getRawSocket (), - boost::bind (&RPCDoorImp::handleConnect, this, new_connection, - boost::asio::placeholders::error)); + mAcceptor.async_accept (new_connection->getRawSocket (), + new_connection->getRemoteEndpoint (), + boost::bind (&RPCDoorImp::handleConnect, this, + new_connection, boost::asio::placeholders::error)); } //-------------------------------------------------------------------------- @@ -82,25 +83,19 @@ public: //-------------------------------------------------------------------------- - void handleConnect (RPCServerImp::pointer new_connection, boost::system::error_code const& error) + void handleConnect (RPCServerImp::pointer new_connection, + boost::system::error_code const& error) { bool delay = false; if (!error) { // Restrict callers by IP - // VFALCO NOTE Prevent exceptions from being thrown at all. - try + std::string client_ip ( + new_connection->getRemoteEndpoint ().address ().to_string ()); + + if (! isClientAllowed (client_ip)) { - if (! isClientAllowed (new_connection->getRemoteAddressText ())) - { - startListening (); - return; - } - } - catch (...) - { - // client may have disconnected startListening (); return; } diff --git a/src/ripple_net/basics/RPCServer.h b/src/ripple_net/basics/RPCServer.h index 6346fc6505..a03c769a83 100644 --- a/src/ripple_net/basics/RPCServer.h +++ b/src/ripple_net/basics/RPCServer.h @@ -55,15 +55,9 @@ public: */ virtual void connected () = 0; - // VFALCO TODO Remove this since it exposes boost + // VFALCO TODO Remove these since they expose boost virtual boost::asio::ip::tcp::socket& getRawSocket () = 0; - - /** Retrieve the remote address as a string. - - @return A std::string representing the remote address. - */ - // VFALCO TODO Replace the return type with a dedicated class. - virtual std::string getRemoteAddressText () = 0; + virtual boost::asio::ip::tcp::socket::endpoint_type& getRemoteEndpoint () = 0; }; #endif diff --git a/src/ripple_net/basics/impl/RPCServerImp.h b/src/ripple_net/basics/impl/RPCServerImp.h index dd31aba76b..eba12f32b4 100644 --- a/src/ripple_net/basics/impl/RPCServerImp.h +++ b/src/ripple_net/basics/impl/RPCServerImp.h @@ -219,8 +219,9 @@ public: { WriteLog (lsTRACE, RPCServer) << "handleRequest " << request; - return m_handler.processRequest (request, beast::IPAddressConversion::from_asio ( - mSocket.PlainSocket ().remote_endpoint().address())); + return m_handler.processRequest (request, + beast::IPAddressConversion::from_asio ( + m_remote_endpoint.address())); } //-------------------------------------------------------------------------- @@ -237,15 +238,9 @@ public: return mSocket.PlainSocket (); } - //-------------------------------------------------------------------------- - - std::string getRemoteAddressText () + boost::asio::ip::tcp::socket::endpoint_type& getRemoteEndpoint () { - std::string address; - - address = mSocket.PlainSocket ().remote_endpoint ().address ().to_string (); - - return address; + return m_remote_endpoint; } private: @@ -253,6 +248,7 @@ private: boost::asio::io_service::strand mStrand; AutoSocket mSocket; + AutoSocket::endpoint_type m_remote_endpoint; boost::asio::streambuf mLineBuffer; Blob mQueryVec; diff --git a/src/ripple_overlay/impl/PeerImp.h b/src/ripple_overlay/impl/PeerImp.h index f9a465536b..5709628516 100644 --- a/src/ripple_overlay/impl/PeerImp.h +++ b/src/ripple_overlay/impl/PeerImp.h @@ -168,6 +168,7 @@ public: /** New incoming peer from the specified socket */ PeerImp ( boost::shared_ptr const& socket, + IP::Endpoint remoteAddress, Peers& peers, Resource::Manager& resourceManager, PeerFinder::Manager& peerFinder, @@ -177,6 +178,7 @@ public: : m_shared_socket (socket) , m_journal (LogPartition::getJournal ()) , m_shortId (0) + , m_remoteAddress (remoteAddress) , m_resourceManager (resourceManager) , m_peerFinder (peerFinder) , m_peers (peers) @@ -202,6 +204,7 @@ public: from inside constructors. */ PeerImp ( + IP::Endpoint remoteAddress, boost::asio::io_service& io_service, Peers& peers, Resource::Manager& resourceManager, @@ -211,6 +214,7 @@ public: MultiSocket::Flag flags) : m_journal (LogPartition::getJournal ()) , m_shortId (0) + , m_remoteAddress (remoteAddress) , m_resourceManager (resourceManager) , m_peerFinder (peerFinder) , m_peers (peers) @@ -274,10 +278,8 @@ public: object and begins the process of connection establishment instead of requiring the caller to construct a Peer and call connect. */ - void connect (IP::Endpoint const& address) + void connect () { - m_remoteAddress = address; - m_journal.info << "Connecting to " << m_remoteAddress; boost::system::error_code err; @@ -295,7 +297,7 @@ public: } getNativeSocket ().async_connect ( - IPAddressConversion::to_asio_endpoint (address), + IPAddressConversion::to_asio_endpoint (m_remoteAddress), m_strand.wrap (boost::bind (&PeerImp::onConnect, shared_from_this (), boost::asio::placeholders::error))); } @@ -425,8 +427,6 @@ public: */ void accept () { - m_remoteAddress = m_socket->remote_endpoint(); - m_journal.info << "Accepted " << m_remoteAddress; m_socket->set_verify_mode (boost::asio::ssl::verify_none); @@ -776,8 +776,6 @@ private: return; } - m_remoteAddress = m_socket->remote_endpoint(); - if (m_inbound) m_usage = m_resourceManager.newInboundEndpoint (m_remoteAddress); else diff --git a/src/ripple_overlay/impl/Peers.cpp b/src/ripple_overlay/impl/Peers.cpp index e26c7243fb..c98c4fed22 100644 --- a/src/ripple_overlay/impl/Peers.cpp +++ b/src/ripple_overlay/impl/Peers.cpp @@ -206,7 +206,7 @@ public: flags = flags.with (MultiSocket::Flag::proxy); PeerImp::ptr const peer (boost::make_shared ( - socket, *this, m_resourceManager, *m_peerFinder, + socket, remote_endpoint, *this, m_resourceManager, *m_peerFinder, slot, m_ssl_context, flags)); { @@ -244,8 +244,8 @@ public: MultiSocket::Flag::client_role | MultiSocket::Flag::ssl); PeerImp::ptr const peer (boost::make_shared ( - m_io_service, *this, m_resourceManager, *m_peerFinder, - slot, m_ssl_context, flags)); + remote_endpoint, m_io_service, *this, m_resourceManager, + *m_peerFinder, slot, m_ssl_context, flags)); { std::lock_guard lock (m_mutex); @@ -258,7 +258,7 @@ public: // This has to happen while holding the lock, // otherwise the socket might not be canceled during a stop. - peer->connect (remote_endpoint); + peer->connect (); } } diff --git a/src/ripple_websocket/autosocket/AutoSocket.h b/src/ripple_websocket/autosocket/AutoSocket.h index 5c5e4956ef..70a96d3097 100644 --- a/src/ripple_websocket/autosocket/AutoSocket.h +++ b/src/ripple_websocket/autosocket/AutoSocket.h @@ -29,6 +29,7 @@ class AutoSocket { public: typedef boost::asio::ssl::stream ssl_socket; + typedef boost::asio::ip::tcp::socket::endpoint_type endpoint_type; typedef boost::shared_ptr socket_ptr; typedef ssl_socket::next_layer_type plain_socket; typedef ssl_socket::lowest_layer_type lowest_layer_type;