Browse Source

[NetDb] check PersistProfiles on load

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

54
libi2pd/NetDb.cpp

@ -105,7 +105,7 @@ namespace data
case eI2NPDummyMsg: case eI2NPDummyMsg:
// plain RouterInfo from NTCP2 with flags for now // plain RouterInfo from NTCP2 with flags for now
HandleNTCP2RouterInfoMsg (msg); HandleNTCP2RouterInfoMsg (msg);
break; break;
default: // WTF? default: // WTF?
LogPrint (eLogError, "NetDb: unexpected message type ", (int) msg->GetTypeID ()); LogPrint (eLogError, "NetDb: unexpected message type ", (int) msg->GetTypeID ());
//i2p::HandleI2NPMessage (msg); //i2p::HandleI2NPMessage (msg);
@ -138,7 +138,7 @@ namespace data
lastDestinationCleanup = ts; lastDestinationCleanup = ts;
} }
if (ts - lastPublish >= NETDB_PUBLISH_INTERVAL) // update timestamp and publish if (ts - lastPublish >= NETDB_PUBLISH_INTERVAL) // update timestamp and publish
{ {
i2p::context.UpdateTimestamp (ts); i2p::context.UpdateTimestamp (ts);
if (!m_HiddenMode) Publish (); if (!m_HiddenMode) Publish ();
@ -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)
@ -170,17 +170,17 @@ 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)
{ {
bool updated; bool updated;
AddRouterInfo (buf, len, updated); AddRouterInfo (buf, len, updated);
return updated; return updated;
} }
std::shared_ptr<const RouterInfo> NetDb::AddRouterInfo (const uint8_t * buf, int len, bool& updated) std::shared_ptr<const RouterInfo> NetDb::AddRouterInfo (const uint8_t * buf, int len, bool& updated)
@ -196,7 +196,7 @@ namespace data
{ {
bool updated; bool updated;
AddRouterInfo (ident, buf, len, updated); AddRouterInfo (ident, buf, len, updated);
return updated; return updated;
} }
std::shared_ptr<const RouterInfo> NetDb::AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len, bool& updated) std::shared_ptr<const RouterInfo> NetDb::AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len, bool& updated)
@ -294,7 +294,7 @@ namespace data
// always new LS2 for now. TODO: implement update // always new LS2 for now. TODO: implement update
auto leaseSet = std::make_shared<LeaseSet2> (storeType, buf, len, false); // we don't need leases in netdb auto leaseSet = std::make_shared<LeaseSet2> (storeType, buf, len, false); // we don't need leases in netdb
m_LeaseSets[ident] = leaseSet; m_LeaseSets[ident] = leaseSet;
return true; return true;
} }
std::shared_ptr<RouterInfo> NetDb::FindRouter (const IdentHash& ident) const std::shared_ptr<RouterInfo> NetDb::FindRouter (const IdentHash& ident) const
@ -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 ();)
@ -651,22 +655,22 @@ namespace data
size_t payloadOffset = offset; size_t payloadOffset = offset;
bool updated = false; bool updated = false;
uint8_t storeType = buf[DATABASE_STORE_TYPE_OFFSET]; uint8_t storeType = buf[DATABASE_STORE_TYPE_OFFSET];
if (storeType) // LeaseSet or LeaseSet2 if (storeType) // LeaseSet or LeaseSet2
{ {
if (!m->from) // unsolicited LS must be received directly if (!m->from) // unsolicited LS must be received directly
{ {
if (storeType == NETDB_STORE_TYPE_LEASESET) // 1 if (storeType == NETDB_STORE_TYPE_LEASESET) // 1
{ {
LogPrint (eLogDebug, "NetDb: store request: LeaseSet for ", ident.ToBase32()); LogPrint (eLogDebug, "NetDb: store request: LeaseSet for ", ident.ToBase32());
updated = AddLeaseSet (ident, buf + offset, len - offset); updated = AddLeaseSet (ident, buf + offset, len - offset);
} }
else // all others are considered as LeaseSet2 else // all others are considered as LeaseSet2
{ {
LogPrint (eLogDebug, "NetDb: store request: LeaseSet2 of type ", storeType, " for ", ident.ToBase32()); LogPrint (eLogDebug, "NetDb: store request: LeaseSet2 of type ", storeType, " for ", ident.ToBase32());
updated = AddLeaseSet2 (ident, buf + offset, len - offset, storeType); updated = AddLeaseSet2 (ident, buf + offset, len - offset, storeType);
} }
} }
} }
else // RouterInfo else // RouterInfo
{ {
@ -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