Browse Source

don't select same peer too often

pull/2095/head
orignal 3 months ago
parent
commit
3720a5fce3
  1. 13
      libi2pd/Transports.cpp
  2. 5
      libi2pd/Transports.h

13
libi2pd/Transports.cpp

@ -977,6 +977,7 @@ namespace transport @@ -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 @@ -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 @@ -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 @@ -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;
}

5
libi2pd/Transports.h

@ -64,12 +64,13 @@ namespace transport @@ -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 @@ -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…
Cancel
Save