MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / SelectTrustedRouter

Method SelectTrustedRouter

libi2pd/TunnelPool.cpp:716–745  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

714 }
715
716 std::shared_ptr<const i2p::data::RouterInfo> TunnelPool::SelectTrustedRouter (bool inbound) const
717 {
718 size_t count = m_TrustedRouters.size ();
719 if (!count) return nullptr;
720 std::shared_ptr<const i2p::data::RouterInfo> r;
721 int ind = tunnels.GetRng ()() % count;
722 for (size_t i = 0; i < count; i++)
723 {
724 auto& ident = m_TrustedRouters[(ind + i) % count];
725 if (inbound)
726 {
727 if (i2p::transport::transports.IsConnected (ident))
728 {
729 r = i2p::data::netdb.FindRouter (ident);
730 break;
731 }
732 }
733 else
734 {
735 auto r1 = i2p::data::netdb.FindRouter (ident);
736 if (!r1) i2p::data::netdb.RequestDestination (ident, nullptr); // request one if not in NetDB
737 if (r1 && !r1->IsUnreachable () && r1->IsReachableFrom (i2p::context.GetRouterInfo ()))
738 {
739 r = r1;
740 break;
741 }
742 }
743 }
744 return r;
745 }
746
747 void TunnelPool::CreateInboundTunnel (uint64_t ts)
748 {

Callers

nothing calls this directly

Calls 5

FindRouterMethod · 0.80
IsReachableFromMethod · 0.80
IsConnectedMethod · 0.45
RequestDestinationMethod · 0.45
IsUnreachableMethod · 0.45

Tested by

no test coverage detected