Browse Source

[NetDb] check PersistProfiles on load

* tabulation fixes
pull/1285/merge
R4SAS 6 years ago
parent
commit
d8a4954bf1
  1. 34
      libi2pd/NetDb.cpp

34
libi2pd/NetDb.cpp

@ -148,7 +148,7 @@ namespace data
{ {
auto numRouters = m_RouterInfos.size (); auto numRouters = m_RouterInfos.size ();
if (!numRouters) if (!numRouters)
throw std::runtime_error("No known routers, reseed seems to be totally failed"); throw std::runtime_error("No known routers, reseed seems to be totally failed");
else // we have peers now else // we have peers now
m_FloodfillBootstrap = nullptr; m_FloodfillBootstrap = nullptr;
if (numRouters < 2500 || ts - lastExploratory >= 90) if (numRouters < 2500 || ts - lastExploratory >= 90)
@ -172,9 +172,9 @@ namespace data
void NetDb::SetHidden(bool hide) void NetDb::SetHidden(bool hide)
{ {
// TODO: remove reachable addresses from router info // TODO: remove reachable addresses from router info
m_HiddenMode = hide; m_HiddenMode = hide;
} }
bool NetDb::AddRouterInfo (const uint8_t * buf, int len) bool NetDb::AddRouterInfo (const uint8_t * buf, int len)
{ {
@ -319,6 +319,9 @@ namespace data
std::shared_ptr<RouterProfile> NetDb::FindRouterProfile (const IdentHash& ident) const std::shared_ptr<RouterProfile> NetDb::FindRouterProfile (const IdentHash& ident) const
{ {
if (!m_PersistProfiles)
return nullptr;
auto router = FindRouter (ident); auto router = FindRouter (ident);
return router ? router->GetProfile () : nullptr; return router ? router->GetProfile () : nullptr;
} }
@ -418,8 +421,9 @@ namespace data
void NetDb::VisitStoredRouterInfos(RouterInfoVisitor v) void NetDb::VisitStoredRouterInfos(RouterInfoVisitor v)
{ {
m_Storage.Iterate([v] (const std::string & filename) { m_Storage.Iterate([v] (const std::string & filename)
auto ri = std::make_shared<i2p::data::RouterInfo>(filename); {
auto ri = std::make_shared<i2p::data::RouterInfo>(filename);
v(ri); v(ri);
}); });
} }
@ -555,7 +559,7 @@ namespace data
++it; ++it;
} }
} }
// clean up expired floodfiils // clean up expired floodfills
{ {
std::unique_lock<std::mutex> l(m_FloodfillsMutex); std::unique_lock<std::mutex> l(m_FloodfillsMutex);
for (auto it = m_Floodfills.begin (); it != m_Floodfills.end ();) for (auto it = m_Floodfills.begin (); it != m_Floodfills.end ();)
@ -873,7 +877,7 @@ namespace data
} }
if (!replyMsg && (lookupType == DATABASE_LOOKUP_TYPE_LEASESET_LOOKUP || if (!replyMsg && (lookupType == DATABASE_LOOKUP_TYPE_LEASESET_LOOKUP ||
lookupType == DATABASE_LOOKUP_TYPE_NORMAL_LOOKUP)) lookupType == DATABASE_LOOKUP_TYPE_NORMAL_LOOKUP))
{ {
auto leaseSet = FindLeaseSet (ident); auto leaseSet = FindLeaseSet (ident);
if (!leaseSet) if (!leaseSet)
@ -1180,13 +1184,13 @@ namespace data
return res; return res;
} }
std::shared_ptr<const RouterInfo> NetDb::GetRandomRouterInFamily(const std::string & fam) const { std::shared_ptr<const RouterInfo> NetDb::GetRandomRouterInFamily(const std::string & fam) const {
return GetRandomRouter( return GetRandomRouter(
[fam](std::shared_ptr<const RouterInfo> router)->bool [fam](std::shared_ptr<const RouterInfo> router)->bool
{ {
return router->IsFamily(fam); return router->IsFamily(fam);
}); });
} }
std::shared_ptr<const RouterInfo> NetDb::GetClosestNonFloodfill (const IdentHash& destination, std::shared_ptr<const RouterInfo> NetDb::GetClosestNonFloodfill (const IdentHash& destination,
const std::set<IdentHash>& excluded) const const std::set<IdentHash>& excluded) const

Loading…
Cancel
Save