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;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user