mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-21 03:26:01 +00:00
Send a smarter list of peers.
This commit is contained in:
@@ -106,6 +106,14 @@ public:
|
|||||||
{
|
{
|
||||||
return mIpPort.second;
|
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);
|
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")
|
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);
|
getApp().getPeers ().savePeer (strIP, iPort, UniqueNodeList::vsTold);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ public:
|
|||||||
|
|
||||||
virtual bool isOutbound () const = 0;
|
virtual bool isOutbound () const = 0;
|
||||||
|
|
||||||
|
virtual bool getConnectString(std::string&) const = 0;
|
||||||
|
|
||||||
virtual uint256 const& getClosedLedgerHash () const = 0;
|
virtual uint256 const& getClosedLedgerHash () const = 0;
|
||||||
|
|
||||||
virtual bool hasLedger (uint256 const& hash, uint32 seq) const = 0;
|
virtual bool hasLedger (uint256 const& hash, uint32 seq) const = 0;
|
||||||
|
|||||||
@@ -147,11 +147,26 @@ void Peers::start ()
|
|||||||
|
|
||||||
bool Peers::getTopNAddrs (int n, std::vector<std::string>& addrs)
|
bool Peers::getTopNAddrs (int n, std::vector<std::string>& addrs)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// Try current connections first
|
||||||
|
std::vector<Peer::pointer> peers = getPeerVector();
|
||||||
|
BOOST_FOREACH(Peer::ref peer, peers)
|
||||||
|
{
|
||||||
|
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)
|
// XXX Filter out other local addresses (like ipv6)
|
||||||
Database* db = getApp().getWalletDB ()->getDB ();
|
Database* db = getApp().getWalletDB ()->getDB ();
|
||||||
ScopedLock sl (getApp().getWalletDB ()->getDBLock ());
|
ScopedLock sl (getApp().getWalletDB ()->getDBLock ());
|
||||||
|
|
||||||
SQL_FOREACH (db, str (boost::format ("SELECT IpPort FROM PeerIps LIMIT %d") % n) )
|
SQL_FOREACH (db, str (boost::format ("SELECT IpPort FROM PeerIps LIMIT %d") % n))
|
||||||
{
|
{
|
||||||
std::string str;
|
std::string str;
|
||||||
|
|
||||||
@@ -159,6 +174,9 @@ bool Peers::getTopNAddrs (int n, std::vector<std::string>& addrs)
|
|||||||
|
|
||||||
addrs.push_back (str);
|
addrs.push_back (str);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME: Should uniqify addrs
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user