mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 22:45:52 +00:00
Fixes to Overlay:
* Make ~Peer virtual * Call close in ConnectAttempt::stop * Handle nullptr return in new_outbound_slot * Check gracefulClose_ in read loop
This commit is contained in:
@@ -36,7 +36,7 @@ class Charge;
|
||||
class Peer
|
||||
{
|
||||
public:
|
||||
typedef std::shared_ptr <Peer> ptr;
|
||||
using ptr = std::shared_ptr<Peer>;
|
||||
|
||||
/** 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
|
||||
//
|
||||
|
||||
@@ -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 <<
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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<ConnectAttempt>(
|
||||
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<decltype(mutex_)> lock(mutex_);
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user