diff --git a/src/ripple/overlay/Peer.h b/src/ripple/overlay/Peer.h index 3dd7b2a2f..f60bac171 100644 --- a/src/ripple/overlay/Peer.h +++ b/src/ripple/overlay/Peer.h @@ -36,7 +36,7 @@ class Charge; class Peer { public: - typedef std::shared_ptr ptr; + using ptr = std::shared_ptr; /** Uniquely identifies a peer. This can be stored in tables to find the peer later. Callers @@ -45,6 +45,8 @@ public: */ using id_t = std::uint32_t; + virtual ~Peer() = default; + // // Network // diff --git a/src/ripple/overlay/impl/ConnectAttempt.cpp b/src/ripple/overlay/impl/ConnectAttempt.cpp index 41a16d2e2..845677aed 100644 --- a/src/ripple/overlay/impl/ConnectAttempt.cpp +++ b/src/ripple/overlay/impl/ConnectAttempt.cpp @@ -28,8 +28,8 @@ namespace ripple { ConnectAttempt::ConnectAttempt (boost::asio::io_service& io_service, endpoint_type const& remote_endpoint, Resource::Consumer usage, beast::asio::ssl_bundle::shared_context const& context, - std::uint32_t id, beast::Journal journal, - OverlayImpl& overlay) + std::uint32_t id, PeerFinder::Slot::ptr const& slot, + beast::Journal journal, OverlayImpl& overlay) : Child (overlay) , id_ (id) , sink_ (journal, OverlayImpl::makePrefix(id)) @@ -49,8 +49,7 @@ ConnectAttempt::ConnectAttempt (boost::asio::io_service& io_service, boost::asio::buffer(data, size))); } , response_, false) - , slot_(overlay_.peerFinder().new_outbound_slot( - beast::IPAddressConversion::from_asio(remote_endpoint))) + , slot_ (slot) { if (journal_.trace) journal_.trace << "Connect " << remote_endpoint; @@ -75,6 +74,7 @@ ConnectAttempt::stop() if (journal_.debug) journal_.debug << "Stop"; } + close(); } void @@ -191,14 +191,13 @@ void ConnectAttempt::onHandshake (error_code ec) { cancelTimer(); - if(! stream_.next_layer().is_open()) return; if(ec == boost::asio::error::operation_aborted) return; - - endpoint_type local_endpoint = - stream_.next_layer().local_endpoint(ec); + endpoint_type local_endpoint; + if (! ec) + local_endpoint = stream_.next_layer().local_endpoint(ec); if(ec) return fail("onHandshake", ec); if(journal_.trace) journal_.trace << diff --git a/src/ripple/overlay/impl/ConnectAttempt.h b/src/ripple/overlay/impl/ConnectAttempt.h index 475f65c17..4e39904c4 100644 --- a/src/ripple/overlay/impl/ConnectAttempt.h +++ b/src/ripple/overlay/impl/ConnectAttempt.h @@ -75,8 +75,8 @@ public: ConnectAttempt (boost::asio::io_service& io_service, endpoint_type const& remote_endpoint, Resource::Consumer usage, beast::asio::ssl_bundle::shared_context const& context, - std::uint32_t id, beast::Journal journal, - OverlayImpl& overlay); + std::uint32_t id, PeerFinder::Slot::ptr const& slot, + beast::Journal journal, OverlayImpl& overlay); ~ConnectAttempt(); diff --git a/src/ripple/overlay/impl/OverlayImpl.cpp b/src/ripple/overlay/impl/OverlayImpl.cpp index d751cb6cf..f94f84d0c 100644 --- a/src/ripple/overlay/impl/OverlayImpl.cpp +++ b/src/ripple/overlay/impl/OverlayImpl.cpp @@ -362,10 +362,18 @@ OverlayImpl::connect (beast::IP::Endpoint const& remote_endpoint) "Over resource limit: " << remote_endpoint; return; } + + auto const slot = peerFinder().new_outbound_slot(remote_endpoint); + if (slot == nullptr) + { + if (journal_.debug) journal_.debug << + "Connect: No slot for " << remote_endpoint; + return; + } auto const p = std::make_shared( io_service_, beast::IPAddressConversion::to_asio_endpoint(remote_endpoint), - usage, setup_.context, next_id_++, + usage, setup_.context, next_id_++, slot, deprecatedLogs().journal("Peer"), *this); std::lock_guard lock(mutex_); diff --git a/src/ripple/overlay/impl/PeerImp.cpp b/src/ripple/overlay/impl/PeerImp.cpp index 676985a7b..e30ca3b93 100644 --- a/src/ripple/overlay/impl/PeerImp.cpp +++ b/src/ripple/overlay/impl/PeerImp.cpp @@ -636,12 +636,12 @@ PeerImp::onReadMessage (error_code ec, std::size_t bytes_transferred) return fail("onReadMessage", ec); if (! stream_.next_layer().is_open()) return; + if(gracefulClose_) + return; if (bytes_consumed == 0) break; read_buffer_.consume (bytes_consumed); } - if(gracefulClose_) - return; // Timeout on writes only stream_.async_read_some (read_buffer_.prepare (Tuning::readBufferBytes), strand_.wrap (std::bind (&PeerImp::onReadMessage,