Browse Source

find actual router for peer

pull/1645/head
orignal 4 years ago
parent
commit
1d5d06f731
  1. 13
      libi2pd/Transports.cpp
  2. 6
      libi2pd/TunnelPool.cpp

13
libi2pd/Transports.cpp

@ -772,10 +772,15 @@ namespace transport
std::shared_ptr<const i2p::data::RouterInfo> Transports::GetRandomPeer () const std::shared_ptr<const i2p::data::RouterInfo> Transports::GetRandomPeer () const
{ {
if (m_Peers.empty ()) return nullptr; if (m_Peers.empty ()) return nullptr;
std::unique_lock<std::mutex> l(m_PeersMutex); i2p::data::IdentHash ident;
auto it = m_Peers.begin (); {
std::advance (it, rand () % m_Peers.size ()); std::unique_lock<std::mutex> l(m_PeersMutex);
return it != m_Peers.end () ? it->second.router : nullptr; auto it = m_Peers.begin ();
std::advance (it, rand () % m_Peers.size ());
if (it == m_Peers.end () || it->second.router) return nullptr; // not connected
ident = it->first;
}
return i2p::data::netdb.FindRouter (ident);
} }
void Transports::RestrictRoutesToFamilies(std::set<std::string> families) void Transports::RestrictRoutesToFamilies(std::set<std::string> families)
{ {

6
libi2pd/TunnelPool.cpp

@ -406,6 +406,7 @@ namespace tunnel
bool StandardSelectPeers(Path & peers, int numHops, bool inbound, SelectHopFunc nextHop) bool StandardSelectPeers(Path & peers, int numHops, bool inbound, SelectHopFunc nextHop)
{ {
int start = 0;
auto prevHop = i2p::context.GetSharedRouterInfo (); auto prevHop = i2p::context.GetSharedRouterInfo ();
if(i2p::transport::transports.RoutesRestricted()) if(i2p::transport::transports.RoutesRestricted())
{ {
@ -414,6 +415,7 @@ namespace tunnel
if(!hop) return false; if(!hop) return false;
peers.push_back(hop->GetRouterIdentity()); peers.push_back(hop->GetRouterIdentity());
prevHop = hop; prevHop = hop;
start++;
} }
else if (i2p::transport::transports.GetNumPeers () > 25) else if (i2p::transport::transports.GetNumPeers () > 25)
{ {
@ -423,11 +425,11 @@ namespace tunnel
{ {
prevHop = r; prevHop = r;
peers.push_back (r->GetRouterIdentity ()); peers.push_back (r->GetRouterIdentity ());
numHops--; start++;
} }
} }
for(int i = 0; i < numHops; i++ ) for(int i = start; i < numHops; i++ )
{ {
auto hop = nextHop (prevHop, inbound); auto hop = nextHop (prevHop, inbound);
if (!hop && !i) // if no suitable peer found for first hop, try already connected if (!hop && !i) // if no suitable peer found for first hop, try already connected

Loading…
Cancel
Save