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

View File

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

View File

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

View File

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