Fix case where slot==nullptr in Overlay:

This changes the Overlay to correctly handle the case when nullptr is
returned by PeerFinder new_inbound_slot on a detected self-connection.
This commit is contained in:
Vinnie Falco
2014-11-17 16:04:33 -08:00
committed by Nik Bougalis
parent a3204a4df7
commit 0e1dd92d9b

View File

@@ -161,10 +161,11 @@ OverlayImpl::onLegacyPeerHello (
beast::IPAddressConversion::from_asio(local_endpoint), beast::IPAddressConversion::from_asio(local_endpoint),
beast::IPAddressConversion::from_asio(remote_address)); beast::IPAddressConversion::from_asio(remote_address));
addpeer (std::make_shared<PeerImp>(std::move(ssl_bundle), if (slot != nullptr)
boost::asio::const_buffers_1(buffer), return addpeer (std::make_shared<PeerImp>(std::move(ssl_bundle),
beast::IPAddressConversion::from_asio(remote_address), boost::asio::const_buffers_1(buffer),
*this, m_resourceManager, *m_peerFinder, slot)); beast::IPAddressConversion::from_asio(remote_address),
*this, m_resourceManager, *m_peerFinder, slot));
} }
Handoff Handoff
@@ -192,23 +193,17 @@ OverlayImpl::onHandoff (std::unique_ptr <beast::asio::ssl_bundle>&& ssl_bundle,
beast::IPAddressConversion::from_asio(local_endpoint), beast::IPAddressConversion::from_asio(local_endpoint),
beast::IPAddressConversion::from_asio(remote_address)); beast::IPAddressConversion::from_asio(remote_address));
#if 0
if (slot == nullptr) if (slot == nullptr)
#else
// For now, always redirect.
if (true)
#endif
{ {
// Full, give them some addresses // self connect
handoff.response = makeRedirectResponse(slot, request); handoff.moved = false;
handoff.keep_alive = request.keep_alive();
return handoff; return handoff;
} }
addpeer (std::make_shared<PeerImp>(std::move(ssl_bundle), // For now, always redirect
std::move(request), beast::IPAddressConversion::from_asio(remote_address), // Full, give them some addresses
*this, m_resourceManager, *m_peerFinder, slot)); handoff.response = makeRedirectResponse(slot, request);
handoff.moved = true; handoff.keep_alive = request.keep_alive();
return handoff; return handoff;
} }