mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add FixedPeers connection policy to peerfinder
This commit is contained in:
@@ -50,16 +50,24 @@ public:
|
||||
*/
|
||||
virtual void setConfig (Config const& config) = 0;
|
||||
|
||||
/** Add a set of strings for peers that should always be connected.
|
||||
This is useful for maintaining a private cluster of peers.
|
||||
If a string is not parseable as a numeric IP address it will
|
||||
be passed to a DNS resolver to perform a lookup.
|
||||
*/
|
||||
virtual void addFixedPeers (
|
||||
std::vector <std::string> const& strings) = 0;
|
||||
|
||||
/** Add a set of strings as fallback IPEndpoint sources.
|
||||
@param name A label used for diagnostics.
|
||||
*/
|
||||
virtual void addStrings (std::string const& name,
|
||||
virtual void addFallbackStrings (std::string const& name,
|
||||
std::vector <std::string> const& strings) = 0;
|
||||
|
||||
/** Add a URL as a fallback location to obtain IPEndpoint sources.
|
||||
@param name A label used for diagnostics.
|
||||
*/
|
||||
virtual void addURL (std::string const& name,
|
||||
virtual void addFallbackURL (std::string const& name,
|
||||
std::string const& url) = 0;
|
||||
|
||||
/** Called when a new peer connection is established.
|
||||
|
||||
@@ -40,7 +40,10 @@ typedef boost::multi_index_container <
|
||||
PeerInfo, boost::multi_index::indexed_by <
|
||||
boost::multi_index::hashed_unique <
|
||||
BOOST_MULTI_INDEX_MEMBER(PeerFinder::PeerInfo,PeerID,id),
|
||||
PeerID::hasher>
|
||||
PeerID::hasher>,
|
||||
boost::multi_index::hashed_non_unique <
|
||||
BOOST_MULTI_INDEX_MEMBER(PeerFinder::PeerInfo,IPEndpoint,address),
|
||||
IPEndpoint::hasher>
|
||||
>
|
||||
> Peers;
|
||||
|
||||
@@ -80,6 +83,13 @@ public:
|
||||
Journal m_journal;
|
||||
Config m_config;
|
||||
|
||||
// The number of fixed peers that are currently connected
|
||||
int m_fixedPeersConnected;
|
||||
|
||||
// A list of peers that should always be connected
|
||||
typedef std::set <IPEndpoint> FixedPeers;
|
||||
FixedPeers m_fixedPeers;
|
||||
|
||||
// A list of dynamic sources to consult as a fallback
|
||||
std::vector <SharedPtr <Source> > m_sources;
|
||||
|
||||
@@ -104,6 +114,7 @@ public:
|
||||
, m_store (store)
|
||||
, m_checker (checker)
|
||||
, m_journal (journal)
|
||||
, m_fixedPeersConnected (0)
|
||||
, m_cache (journal)
|
||||
, m_legacyCache (store, journal)
|
||||
{
|
||||
@@ -165,18 +176,34 @@ public:
|
||||
//
|
||||
void makeOutgoingConnections ()
|
||||
{
|
||||
std::vector <IPEndpoint> list;
|
||||
|
||||
if (m_slots.outDesired > m_slots.outboundCount)
|
||||
{
|
||||
int const needed (std::min (
|
||||
m_slots.outDesired - m_slots.outboundCount,
|
||||
int (maxAddressesPerAttempt)));
|
||||
std::vector <IPEndpoint> list;
|
||||
m_legacyCache.get (needed, list);
|
||||
}
|
||||
|
||||
if (m_fixedPeersConnected < m_fixedPeers.size())
|
||||
{
|
||||
list.reserve (list.size() + m_fixedPeers.size() - m_fixedPeersConnected);
|
||||
|
||||
for (FixedPeers::const_iterator iter (m_fixedPeers.begin());
|
||||
iter != m_fixedPeers.end(); ++iter)
|
||||
{
|
||||
if (m_peers.get<1>().find (*iter) != m_peers.get<1>().end())
|
||||
{
|
||||
list.push_back (*iter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if RIPPLE_USE_PEERFINDER
|
||||
if (! list.empty())
|
||||
m_callback.connectPeerEndpoints (list);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -191,6 +218,23 @@ public:
|
||||
m_slots.update (m_config);
|
||||
}
|
||||
|
||||
void addFixedPeers (std::vector <std::string> const& strings)
|
||||
{
|
||||
for (std::vector <std::string>::const_iterator iter (strings.begin());
|
||||
iter != strings.end(); ++iter)
|
||||
{
|
||||
IPEndpoint ep (IPEndpoint::from_string (*iter));
|
||||
if (! ep.empty ())
|
||||
{
|
||||
m_fixedPeers.insert (ep);
|
||||
}
|
||||
else
|
||||
{
|
||||
// VFALCO TODO Attempt name resolution
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void addStaticSource (SharedPtr <Source> const& source)
|
||||
{
|
||||
fetch (source);
|
||||
|
||||
@@ -240,7 +240,19 @@ public:
|
||||
config)));
|
||||
}
|
||||
|
||||
void addStrings (std::string const& name,
|
||||
void addFixedPeers (
|
||||
std::vector <std::string> const& strings)
|
||||
{
|
||||
#if 1
|
||||
m_logic.addFixedPeers (strings);
|
||||
#else
|
||||
m_queue.dispatch (m_context.wrap (
|
||||
bind (&Logic::addFixedPeers, &m_logic,
|
||||
std::vector <std::string> (strings))));
|
||||
#endif
|
||||
}
|
||||
|
||||
void addFallbackStrings (std::string const& name,
|
||||
std::vector <std::string> const& strings)
|
||||
{
|
||||
m_queue.dispatch (
|
||||
@@ -250,8 +262,9 @@ public:
|
||||
SourceStrings::New (name, strings))));
|
||||
}
|
||||
|
||||
void addURL (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
|
||||
}
|
||||
|
||||
void onPeerConnected (PeerID const& id,
|
||||
|
||||
Reference in New Issue
Block a user