Browse Source

delete delete routers from memory

pull/113/head
orignal 10 years ago
parent
commit
ed3aaefe96
  1. 34
      NetDb.cpp
  2. 1
      NetDb.h

34
NetDb.cpp

@ -168,23 +168,26 @@ namespace data
void NetDb::AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len) void NetDb::AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len)
{ {
DeleteRequestedDestination (ident); DeleteRequestedDestination (ident);
auto it = m_RouterInfos.find(ident); auto r = FindRouter (ident);
if (it != m_RouterInfos.end ()) if (r)
{ {
auto ts = it->second->GetTimestamp (); auto ts = r->GetTimestamp ();
it->second->Update (buf, len); r->Update (buf, len);
if (it->second->GetTimestamp () > ts) if (r->GetTimestamp () > ts)
LogPrint ("RouterInfo updated"); LogPrint ("RouterInfo updated");
} }
else else
{ {
LogPrint ("New RouterInfo added"); LogPrint ("New RouterInfo added");
auto r = std::make_shared<RouterInfo> (buf, len); auto newRouter = std::make_shared<RouterInfo> (buf, len);
m_RouterInfos[r->GetIdentHash ()] = r; {
if (r->IsFloodfill ()) std::unique_lock<std::mutex> l(m_RouterInfosMutex);
m_RouterInfos[r->GetIdentHash ()] = newRouter;
}
if (newRouter->IsFloodfill ())
{ {
std::unique_lock<std::mutex> l(m_FloodfillsMutex); std::unique_lock<std::mutex> l(m_FloodfillsMutex);
m_Floodfills.push_back (r); m_Floodfills.push_back (newRouter);
} }
} }
} }
@ -211,6 +214,7 @@ namespace data
std::shared_ptr<RouterInfo> NetDb::FindRouter (const IdentHash& ident) const std::shared_ptr<RouterInfo> NetDb::FindRouter (const IdentHash& ident) const
{ {
std::unique_lock<std::mutex> l(m_RouterInfosMutex);
auto it = m_RouterInfos.find (ident); auto it = m_RouterInfos.find (ident);
if (it != m_RouterInfos.end ()) if (it != m_RouterInfos.end ())
return it->second; return it->second;
@ -372,7 +376,18 @@ namespace data
if (count > 0) if (count > 0)
LogPrint (count," new/updated routers saved"); LogPrint (count," new/updated routers saved");
if (deletedCount > 0) if (deletedCount > 0)
{
LogPrint (deletedCount," routers deleted"); LogPrint (deletedCount," routers deleted");
// clean up RouterInfos table
std::unique_lock<std::mutex> l(m_RouterInfosMutex);
for (auto it = m_RouterInfos.begin (); it != m_RouterInfos.end ();)
{
if (it->second->IsUnreachable ())
it = m_RouterInfos.erase (it);
else
it++;
}
}
} }
void NetDb::RequestDestination (const IdentHash& destination, bool isLeaseSet, i2p::tunnel::TunnelPool * pool) void NetDb::RequestDestination (const IdentHash& destination, bool isLeaseSet, i2p::tunnel::TunnelPool * pool)
@ -822,6 +837,7 @@ namespace data
for (int j = 0; j < 2; j++) for (int j = 0; j < 2; j++)
{ {
uint32_t i = 0; uint32_t i = 0;
std::unique_lock<std::mutex> l(m_RouterInfosMutex);
for (auto it: m_RouterInfos) for (auto it: m_RouterInfos)
{ {
if (i >= ind) if (i >= ind)

1
NetDb.h

@ -109,6 +109,7 @@ namespace data
private: private:
std::map<IdentHash, LeaseSet *> m_LeaseSets; std::map<IdentHash, LeaseSet *> m_LeaseSets;
mutable std::mutex m_RouterInfosMutex;
std::map<IdentHash, std::shared_ptr<RouterInfo> > m_RouterInfos; std::map<IdentHash, std::shared_ptr<RouterInfo> > m_RouterInfos;
mutable std::mutex m_FloodfillsMutex; mutable std::mutex m_FloodfillsMutex;
std::list<std::shared_ptr<RouterInfo> > m_Floodfills; std::list<std::shared_ptr<RouterInfo> > m_Floodfills;

Loading…
Cancel
Save