mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Latency-aware fetch pack target selection
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -81,6 +81,10 @@ public:
|
||||
bool
|
||||
isHighLatency() const = 0;
|
||||
|
||||
virtual
|
||||
int
|
||||
getScore (bool) const = 0;
|
||||
|
||||
virtual
|
||||
RippleAddress const&
|
||||
getNodePublic() const = 0;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user