mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-20 19:15:54 +00:00
Send a smarter list of peers.
This commit is contained in:
@@ -106,6 +106,14 @@ public:
|
||||
{
|
||||
return mIpPort.second;
|
||||
}
|
||||
bool getConnectString(std::string& connect) const
|
||||
{
|
||||
if (!mHello.has_ipv4port() || mIpPortConnect.first.empty())
|
||||
return false;
|
||||
connect = boost::str(boost::format("%s:%d") % mIpPortConnect.first % mHello.ipv4port());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void setIpPort (const std::string & strIP, int iPort);
|
||||
|
||||
@@ -1533,7 +1541,7 @@ void PeerImp::recvPeers (protocol::TMPeers& packet)
|
||||
|
||||
if (strIP != "0.0.0.0" && strIP != "127.0.0.1")
|
||||
{
|
||||
//WriteLog (lsINFO, Peer) << "Peer: Learning: " << addressToString(this) << ": " << i << ": " << strIP << " " << iPort;
|
||||
WriteLog (lsDEBUG, Peer) << "Peer: Learning: " << addressToString(this) << ": " << i << ": " << strIP << " " << iPort;
|
||||
|
||||
getApp().getPeers ().savePeer (strIP, iPort, UniqueNodeList::vsTold);
|
||||
}
|
||||
|
||||
@@ -73,6 +73,8 @@ public:
|
||||
|
||||
virtual bool isOutbound () const = 0;
|
||||
|
||||
virtual bool getConnectString(std::string&) const = 0;
|
||||
|
||||
virtual uint256 const& getClosedLedgerHash () const = 0;
|
||||
|
||||
virtual bool hasLedger (uint256 const& hash, uint32 seq) const = 0;
|
||||
|
||||
@@ -147,19 +147,37 @@ void Peers::start ()
|
||||
|
||||
bool Peers::getTopNAddrs (int n, std::vector<std::string>& addrs)
|
||||
{
|
||||
// XXX Filter out other local addresses (like ipv6)
|
||||
Database* db = getApp().getWalletDB ()->getDB ();
|
||||
ScopedLock sl (getApp().getWalletDB ()->getDBLock ());
|
||||
|
||||
SQL_FOREACH (db, str (boost::format ("SELECT IpPort FROM PeerIps LIMIT %d") % n) )
|
||||
// Try current connections first
|
||||
std::vector<Peer::pointer> peers = getPeerVector();
|
||||
BOOST_FOREACH(Peer::ref peer, peers)
|
||||
{
|
||||
std::string str;
|
||||
|
||||
db->getStr (0, str);
|
||||
|
||||
addrs.push_back (str);
|
||||
if (peer->isConnected())
|
||||
{
|
||||
std::string connectString;
|
||||
if (peer->getConnectString(connectString))
|
||||
addrs.push_back(connectString);
|
||||
}
|
||||
}
|
||||
|
||||
if (addrs.size() < n)
|
||||
{
|
||||
// XXX Filter out other local addresses (like ipv6)
|
||||
Database* db = getApp().getWalletDB ()->getDB ();
|
||||
ScopedLock sl (getApp().getWalletDB ()->getDBLock ());
|
||||
|
||||
SQL_FOREACH (db, str (boost::format ("SELECT IpPort FROM PeerIps LIMIT %d") % n))
|
||||
{
|
||||
std::string str;
|
||||
|
||||
db->getStr (0, str);
|
||||
|
||||
addrs.push_back (str);
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Should uniqify addrs
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user