mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
find new introducers to connect
This commit is contained in:
parent
7a19533380
commit
db93a7315f
|
@ -1168,12 +1168,13 @@ namespace data
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<const RouterInfo> NetDb::GetRandomIntroducer (bool v4) const
|
std::shared_ptr<const RouterInfo> NetDb::GetRandomIntroducer (bool v4, const std::set<IdentHash>& excluded) const
|
||||||
{
|
{
|
||||||
return GetRandomRouter (
|
return GetRandomRouter (
|
||||||
[v4](std::shared_ptr<const RouterInfo> router)->bool
|
[v4, &excluded](std::shared_ptr<const RouterInfo> router)->bool
|
||||||
{
|
{
|
||||||
return router->IsIntroducer (v4) && !router->IsHidden () && !router->IsFloodfill (); // floodfills don't send relay tag
|
return router->IsIntroducer (v4) && !excluded.count (router->GetIdentHash ()) &&
|
||||||
|
!router->IsHidden () && !router->IsFloodfill (); // floodfills don't send relay tag
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ namespace data
|
||||||
std::shared_ptr<const RouterInfo> GetHighBandwidthRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith, bool reverse) const;
|
std::shared_ptr<const RouterInfo> GetHighBandwidthRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith, bool reverse) const;
|
||||||
std::shared_ptr<const RouterInfo> GetRandomPeerTestRouter (bool v4, const std::set<IdentHash>& excluded) const;
|
std::shared_ptr<const RouterInfo> GetRandomPeerTestRouter (bool v4, const std::set<IdentHash>& excluded) const;
|
||||||
std::shared_ptr<const RouterInfo> GetRandomSSUV6Router () const; // TODO: change to v6 peer test later
|
std::shared_ptr<const RouterInfo> GetRandomSSUV6Router () const; // TODO: change to v6 peer test later
|
||||||
std::shared_ptr<const RouterInfo> GetRandomIntroducer (bool v4) const;
|
std::shared_ptr<const RouterInfo> GetRandomIntroducer (bool v4, const std::set<IdentHash>& excluded) const;
|
||||||
std::shared_ptr<const RouterInfo> GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded, bool closeThanUsOnly = false) const;
|
std::shared_ptr<const RouterInfo> GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded, bool closeThanUsOnly = false) const;
|
||||||
std::vector<IdentHash> GetClosestFloodfills (const IdentHash& destination, size_t num,
|
std::vector<IdentHash> GetClosestFloodfills (const IdentHash& destination, size_t num,
|
||||||
std::set<IdentHash>& excluded, bool closeThanUsOnly = false) const;
|
std::set<IdentHash>& excluded, bool closeThanUsOnly = false) const;
|
||||||
|
|
|
@ -778,6 +778,7 @@ namespace transport
|
||||||
i2p::context.RemoveIntroducer (it);
|
i2p::context.RemoveIntroducer (it);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::set<i2p::data::IdentHash> excluded;
|
||||||
if (numIntroducers < SSU_MAX_NUM_INTRODUCERS)
|
if (numIntroducers < SSU_MAX_NUM_INTRODUCERS)
|
||||||
{
|
{
|
||||||
// create new
|
// create new
|
||||||
|
@ -809,16 +810,16 @@ namespace transport
|
||||||
newList.push_back (ep);
|
newList.push_back (ep);
|
||||||
if (newList.size () >= SSU_MAX_NUM_INTRODUCERS) break;
|
if (newList.size () >= SSU_MAX_NUM_INTRODUCERS) break;
|
||||||
}
|
}
|
||||||
|
excluded.insert (it1->GetRemoteIdentity ()->GetIdentHash ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
introducers = newList;
|
introducers = newList;
|
||||||
if (introducers.size () < SSU_MAX_NUM_INTRODUCERS)
|
if (introducers.size () < SSU_MAX_NUM_INTRODUCERS)
|
||||||
{
|
{
|
||||||
std::set<std::shared_ptr<const i2p::data::RouterInfo> > requested;
|
|
||||||
for (auto i = introducers.size (); i < SSU_MAX_NUM_INTRODUCERS; i++)
|
for (auto i = introducers.size (); i < SSU_MAX_NUM_INTRODUCERS; i++)
|
||||||
{
|
{
|
||||||
auto introducer = i2p::data::netdb.GetRandomIntroducer (v4);
|
auto introducer = i2p::data::netdb.GetRandomIntroducer (v4, excluded);
|
||||||
if (introducer && !requested.count (introducer)) // not requested already
|
if (introducer)
|
||||||
{
|
{
|
||||||
auto address = v4 ? introducer->GetSSUAddress (true) : introducer->GetSSUV6Address ();
|
auto address = v4 ? introducer->GetSSUAddress (true) : introducer->GetSSUV6Address ();
|
||||||
if (address && !address->host.is_unspecified () && address->port)
|
if (address && !address->host.is_unspecified () && address->port)
|
||||||
|
@ -827,7 +828,7 @@ namespace transport
|
||||||
if (std::find (introducers.begin (), introducers.end (), ep) == introducers.end ()) // not connected yet
|
if (std::find (introducers.begin (), introducers.end (), ep) == introducers.end ()) // not connected yet
|
||||||
{
|
{
|
||||||
CreateDirectSession (introducer, ep, false);
|
CreateDirectSession (introducer, ep, false);
|
||||||
requested.insert (introducer);
|
excluded.insert (introducer->GetIdentHash ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue