diff --git a/src/ripple/peerfinder/Manager.h b/src/ripple/peerfinder/Manager.h index 09bf5deb1..f900e0fd7 100644 --- a/src/ripple/peerfinder/Manager.h +++ b/src/ripple/peerfinder/Manager.h @@ -24,6 +24,7 @@ #include #include #include +#include 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 const& eps) = 0; + //-------------------------------------------------------------------------- /** Called when an outbound connection attempt succeeds. diff --git a/src/ripple/peerfinder/impl/Logic.h b/src/ripple/peerfinder/impl/Logic.h index d14b96bc9..4c07d6fc8 100644 --- a/src/ripple/peerfinder/impl/Logic.h +++ b/src/ripple/peerfinder/impl/Logic.h @@ -924,6 +924,12 @@ public: } } + // Insert a set of redirect IP addresses into the Bootcache + template + 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 +template +void +Logic::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; +} + } } diff --git a/src/ripple/peerfinder/impl/Manager.cpp b/src/ripple/peerfinder/impl/Manager.cpp index 0fcbc755b..23c2a695e 100644 --- a/src/ripple/peerfinder/impl/Manager.cpp +++ b/src/ripple/peerfinder/impl/Manager.cpp @@ -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 const& addresses) + std::vector const& addresses) override { m_logic.addFixedPeer (name, addresses); } void addFallbackStrings (std::string const& name, - std::vector const& strings) + std::vector 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 (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 (slot)); m_logic.on_closed (impl); } + void + onRedirects (boost::asio::ip::tcp::endpoint const& remote_address, + std::vector const& eps) override + { + m_logic.onRedirects(eps.begin(), eps.end(), remote_address); + } + //-------------------------------------------------------------------------- bool diff --git a/src/ripple/peerfinder/impl/Tuning.h b/src/ripple/peerfinder/impl/Tuning.h index 3b73bcecc..47433a977 100644 --- a/src/ripple/peerfinder/impl/Tuning.h +++ b/src/ripple/peerfinder/impl/Tuning.h @@ -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 }; //------------------------------------------------------------------------------