mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 13:27:17 +01:00
don't select same peer too often
This commit is contained in:
parent
0df895b6a7
commit
3720a5fce3
|
@ -977,6 +977,7 @@ namespace transport
|
|||
std::shared_ptr<const i2p::data::RouterInfo> Transports::GetRandomPeer (Filter filter) const
|
||||
{
|
||||
if (m_Peers.empty()) return nullptr;
|
||||
auto ts = i2p::util::GetSecondsSinceEpoch ();
|
||||
bool found = false;
|
||||
i2p::data::IdentHash ident;
|
||||
{
|
||||
|
@ -1017,9 +1018,11 @@ namespace transport
|
|||
it = it1;
|
||||
while (it != it2 && it != m_Peers.end ())
|
||||
{
|
||||
if (filter (it->second))
|
||||
if (ts > it->second->lastSelectionTime + PEER_SELECTION_MIN_INTERVAL &&
|
||||
filter (it->second))
|
||||
{
|
||||
ident = it->first;
|
||||
it->second->lastSelectionTime = ts;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
@ -1031,9 +1034,11 @@ namespace transport
|
|||
it = m_Peers.begin ();
|
||||
while (it != it1 && it != m_Peers.end ())
|
||||
{
|
||||
if (filter (it->second))
|
||||
if (ts > it->second->lastSelectionTime + PEER_SELECTION_MIN_INTERVAL &&
|
||||
filter (it->second))
|
||||
{
|
||||
ident = it->first;
|
||||
it->second->lastSelectionTime = ts;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
@ -1045,9 +1050,11 @@ namespace transport
|
|||
it = it2;
|
||||
while (it != m_Peers.end ())
|
||||
{
|
||||
if (filter (it->second))
|
||||
if (ts > it->second->lastSelectionTime + PEER_SELECTION_MIN_INTERVAL &&
|
||||
filter (it->second))
|
||||
{
|
||||
ident = it->first;
|
||||
it->second->lastSelectionTime = ts;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -64,12 +64,13 @@ namespace transport
|
|||
const int PEER_ROUTER_INFO_UPDATE_INTERVAL = 31*60; // in seconds
|
||||
const int PEER_ROUTER_INFO_UPDATE_INTERVAL_VARIANCE = 7*60; // in seconds
|
||||
const size_t PEER_ROUTER_INFO_OVERLOAD_QUEUE_SIZE = 25;
|
||||
const int PEER_SELECTION_MIN_INTERVAL = 20; // in seconds
|
||||
struct Peer
|
||||
{
|
||||
int numAttempts;
|
||||
std::shared_ptr<const i2p::data::RouterInfo> router;
|
||||
std::list<std::shared_ptr<TransportSession> > sessions;
|
||||
uint64_t creationTime, nextRouterInfoUpdateTime;
|
||||
uint64_t creationTime, nextRouterInfoUpdateTime, lastSelectionTime;
|
||||
std::vector<std::shared_ptr<i2p::I2NPMessage> > delayedMessages;
|
||||
std::vector<i2p::data::RouterInfo::SupportedTransports> priority;
|
||||
bool isHighBandwidth, isEligible;
|
||||
|
@ -77,7 +78,7 @@ namespace transport
|
|||
Peer (std::shared_ptr<const i2p::data::RouterInfo> r, uint64_t ts):
|
||||
numAttempts (0), router (r), creationTime (ts),
|
||||
nextRouterInfoUpdateTime (ts + PEER_ROUTER_INFO_UPDATE_INTERVAL),
|
||||
isHighBandwidth (false), isEligible (false)
|
||||
lastSelectionTime (0), isHighBandwidth (false), isEligible (false)
|
||||
{
|
||||
UpdateParams (router);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue