select first hop from high bandwidth peer for client tunnels

This commit is contained in:
orignal 2023-02-03 15:59:56 -05:00
parent 544fcd147f
commit 21542e8150
5 changed files with 29 additions and 19 deletions

View file

@ -72,11 +72,15 @@ namespace transport
uint64_t creationTime, nextRouterInfoUpdateTime;
std::vector<std::shared_ptr<i2p::I2NPMessage> > delayedMessages;
std::vector<i2p::data::RouterInfo::SupportedTransports> priority;
bool isHighBandwidth;
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)
nextRouterInfoUpdateTime (ts + PEER_ROUTER_INFO_UPDATE_INTERVAL),
isHighBandwidth (false)
{
if (router)
isHighBandwidth = router->IsHighBandwidth ();
}
void Done ()
@ -84,6 +88,13 @@ namespace transport
for (auto& it: sessions)
it->Done ();
}
void SetRouter (std::shared_ptr<const i2p::data::RouterInfo> r)
{
router = r;
if (router)
isHighBandwidth = router->IsHighBandwidth ();
}
};
const uint64_t SESSION_CREATION_TIMEOUT = 15; // in seconds
@ -131,7 +142,7 @@ namespace transport
bool IsBandwidthExceeded () const;
bool IsTransitBandwidthExceeded () const;
size_t GetNumPeers () const { return m_Peers.size (); };
std::shared_ptr<const i2p::data::RouterInfo> GetRandomPeer () const;
std::shared_ptr<const i2p::data::RouterInfo> GetRandomPeer (bool isHighBandwidth) const;
/** get a trusted first hop for restricted routes */
std::shared_ptr<const i2p::data::RouterInfo> GetRestrictedPeer() const;