mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Add PeerFinder onRedirects function
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include <ripple/sitefiles/Sitefiles.h>
|
||||
#include <beast/chrono/abstract_clock.h>
|
||||
#include <beast/module/core/files/File.h>
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
|
||||
namespace ripple {
|
||||
namespace PeerFinder {
|
||||
@@ -191,6 +192,12 @@ public:
|
||||
*/
|
||||
virtual void on_closed (Slot::ptr const& slot) = 0;
|
||||
|
||||
/** Called when we received redirect IPs from a busy peer. */
|
||||
virtual
|
||||
void
|
||||
onRedirects (boost::asio::ip::tcp::endpoint const& remote_address,
|
||||
std::vector<boost::asio::ip::tcp::endpoint> const& eps) = 0;
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/** Called when an outbound connection attempt succeeds.
|
||||
|
||||
@@ -924,6 +924,12 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// Insert a set of redirect IP addresses into the Bootcache
|
||||
template <class FwdIter>
|
||||
void
|
||||
onRedirects (FwdIter first, FwdIter last,
|
||||
boost::asio::ip::tcp::endpoint const& remote_address);
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
// Returns `true` if the address matches a fixed slot address
|
||||
@@ -1186,6 +1192,24 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template <class Checker>
|
||||
template <class FwdIter>
|
||||
void
|
||||
Logic<Checker>::onRedirects (FwdIter first, FwdIter last,
|
||||
boost::asio::ip::tcp::endpoint const& remote_address)
|
||||
{
|
||||
typename SharedState::Access state (m_state);
|
||||
std::size_t n = 0;
|
||||
for(;first != last && n < Tuning::maxRedirects; ++first, ++n)
|
||||
state->bootcache.insert(
|
||||
beast::IPAddressConversion::from_asio(*first));
|
||||
if (n > 0)
|
||||
if (m_journal.trace) m_journal.trace << beast::leftw (18) <<
|
||||
"Logic add " << n << " redirect IPs from " << remote_address;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,25 +93,26 @@ public:
|
||||
//
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
void setConfig (Config const& config)
|
||||
void setConfig (Config const& config) override
|
||||
{
|
||||
m_logic.config (config);
|
||||
}
|
||||
|
||||
void addFixedPeer (std::string const& name,
|
||||
std::vector <beast::IP::Endpoint> const& addresses)
|
||||
std::vector <beast::IP::Endpoint> const& addresses) override
|
||||
{
|
||||
m_logic.addFixedPeer (name, addresses);
|
||||
}
|
||||
|
||||
void
|
||||
addFallbackStrings (std::string const& name,
|
||||
std::vector <std::string> const& strings)
|
||||
std::vector <std::string> const& strings) override
|
||||
{
|
||||
m_logic.addStaticSource (SourceStrings::New (name, strings));
|
||||
}
|
||||
|
||||
void addFallbackURL (std::string const& name, std::string const& url)
|
||||
void addFallbackURL (std::string const& name,
|
||||
std::string const& url)
|
||||
{
|
||||
// VFALCO TODO This needs to be implemented
|
||||
}
|
||||
@@ -121,37 +122,45 @@ public:
|
||||
Slot::ptr
|
||||
new_inbound_slot (
|
||||
beast::IP::Endpoint const& local_endpoint,
|
||||
beast::IP::Endpoint const& remote_endpoint)
|
||||
beast::IP::Endpoint const& remote_endpoint) override
|
||||
{
|
||||
return m_logic.new_inbound_slot (local_endpoint, remote_endpoint);
|
||||
}
|
||||
|
||||
Slot::ptr
|
||||
new_outbound_slot (beast::IP::Endpoint const& remote_endpoint)
|
||||
new_outbound_slot (beast::IP::Endpoint const& remote_endpoint) override
|
||||
{
|
||||
return m_logic.new_outbound_slot (remote_endpoint);
|
||||
}
|
||||
|
||||
void
|
||||
on_endpoints (Slot::ptr const& slot, Endpoints const& endpoints)
|
||||
on_endpoints (Slot::ptr const& slot,
|
||||
Endpoints const& endpoints) override
|
||||
{
|
||||
SlotImp::ptr impl (std::dynamic_pointer_cast <SlotImp> (slot));
|
||||
m_logic.on_endpoints (impl, endpoints);
|
||||
}
|
||||
|
||||
void
|
||||
on_legacy_endpoints (IPAddresses const& addresses)
|
||||
on_legacy_endpoints (IPAddresses const& addresses) override
|
||||
{
|
||||
m_logic.on_legacy_endpoints (addresses);
|
||||
}
|
||||
|
||||
void
|
||||
on_closed (Slot::ptr const& slot)
|
||||
on_closed (Slot::ptr const& slot) override
|
||||
{
|
||||
SlotImp::ptr impl (std::dynamic_pointer_cast <SlotImp> (slot));
|
||||
m_logic.on_closed (impl);
|
||||
}
|
||||
|
||||
void
|
||||
onRedirects (boost::asio::ip::tcp::endpoint const& remote_address,
|
||||
std::vector<boost::asio::ip::tcp::endpoint> const& eps) override
|
||||
{
|
||||
m_logic.onRedirects(eps.begin(), eps.end(), remote_address);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
bool
|
||||
|
||||
@@ -58,6 +58,12 @@ enum
|
||||
|
||||
/** The default value of Config::maxPeers. */
|
||||
,defaultMaxPeers = 21
|
||||
|
||||
/** Max redirects we will accept from one connection.
|
||||
Redirects are limited for security purposes, to prevent
|
||||
the address caches from getting flooded.
|
||||
*/
|
||||
,maxRedirects = 30
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user