Latency-aware fetch pack target selection

This commit is contained in:
JoelKatz
2015-05-19 14:00:03 -07:00
committed by Nik Bougalis
parent 6f5d8bba2d
commit 172e967a73
4 changed files with 20 additions and 9 deletions

View File

@@ -596,16 +596,23 @@ public:
return;
}
// Select target Peer based on highest score.
// The score is randomized but biased in favor of Peers with low latency.
Peer::ptr target;
int count = 0;
Overlay::PeerSequence peerList = getApp().overlay ().getActivePeers ();
for (auto const& peer : peerList)
{
if (peer->hasRange (missingIndex, missingIndex + 1))
int maxScore = 0;
Overlay::PeerSequence peerList = getApp().overlay ().getActivePeers ();
for (auto const& peer : peerList)
{
if ((count++ == 0) || ((rand() % count) == 0))
target = peer;
if (peer->hasRange (missingIndex, missingIndex + 1))
{
int score = peer->getScore (true);
if (! target || (score > maxScore))
{
target = peer;
maxScore = score;
}
}
}
}

View File

@@ -81,6 +81,10 @@ public:
bool
isHighLatency() const = 0;
virtual
int
getScore (bool) const = 0;
virtual
RippleAddress const&
getNodePublic() const = 0;

View File

@@ -2171,7 +2171,7 @@ PeerImp::peerTXData (Job&, uint256 const& hash,
}
int
PeerImp::getScore (bool haveItem)
PeerImp::getScore (bool haveItem) const
{
// Random component of score, used to break ties and avoid
// overloading the "best" peer

View File

@@ -305,7 +305,7 @@ public:
// Called to determine our priority for querying
int
getScore (bool haveItem);
getScore (bool haveItem) const override;
bool
isHighLatency() const override;