Browse Source

store RIs as shared pointers

pull/113/head
orignal 10 years ago
parent
commit
96387aecbd
  1. 23
      NetDb.cpp
  2. 4
      NetDb.h

23
NetDb.cpp

@ -71,8 +71,6 @@ namespace data
Stop (); Stop ();
for (auto l:m_LeaseSets) for (auto l:m_LeaseSets)
delete l.second; delete l.second;
for (auto r:m_RouterInfos)
delete r.second;
for (auto r:m_RequestedDestinations) for (auto r:m_RequestedDestinations)
delete r.second; delete r.second;
} }
@ -181,7 +179,7 @@ namespace data
else else
{ {
LogPrint ("New RouterInfo added"); LogPrint ("New RouterInfo added");
RouterInfo * r = new RouterInfo (buf, len); auto r = std::make_shared<RouterInfo> (buf, len);
m_RouterInfos[r->GetIdentHash ()] = r; m_RouterInfos[r->GetIdentHash ()] = r;
if (r->IsFloodfill ()) if (r->IsFloodfill ())
{ {
@ -215,7 +213,7 @@ namespace data
{ {
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.get ();
else else
return nullptr; return nullptr;
} }
@ -271,8 +269,6 @@ namespace data
if (!CreateNetDb(p)) return; if (!CreateNetDb(p)) return;
} }
// make sure we cleanup netDb from previous attempts // make sure we cleanup netDb from previous attempts
for (auto r: m_RouterInfos)
delete r.second;
m_RouterInfos.clear (); m_RouterInfos.clear ();
m_Floodfills.clear (); m_Floodfills.clear ();
@ -291,7 +287,7 @@ namespace data
#else #else
const std::string& fullPath = it1->path(); const std::string& fullPath = it1->path();
#endif #endif
RouterInfo * r = new RouterInfo(fullPath); auto r = std::make_shared<RouterInfo>(fullPath);
if (!r->IsUnreachable () && (!r->UsesIntroducer () || ts < r->GetTimestamp () + 3600*1000LL)) // 1 hour if (!r->IsUnreachable () && (!r->UsesIntroducer () || ts < r->GetTimestamp () + 3600*1000LL)) // 1 hour
{ {
r->DeleteBuffer (); r->DeleteBuffer ();
@ -304,7 +300,6 @@ namespace data
{ {
if (boost::filesystem::exists (fullPath)) if (boost::filesystem::exists (fullPath))
boost::filesystem::remove (fullPath); boost::filesystem::remove (fullPath);
delete r;
} }
} }
} }
@ -341,7 +336,7 @@ namespace data
{ {
if (it.second->IsUpdated ()) if (it.second->IsUpdated ())
{ {
it.second->SaveToFile (GetFilePath(fullDirectory, it.second)); it.second->SaveToFile (GetFilePath(fullDirectory, it.second.get ()));
it.second->SetUpdated (false); it.second->SetUpdated (false);
it.second->DeleteBuffer (); it.second->DeleteBuffer ();
count++; count++;
@ -359,9 +354,9 @@ namespace data
if (it.second->IsUnreachable ()) if (it.second->IsUnreachable ())
{ {
if (boost::filesystem::exists (GetFilePath (fullDirectory, it.second))) if (boost::filesystem::exists (GetFilePath (fullDirectory, it.second.get ())))
{ {
boost::filesystem::remove (GetFilePath (fullDirectory, it.second)); boost::filesystem::remove (GetFilePath (fullDirectory, it.second.get ()));
deletedCount++; deletedCount++;
} }
} }
@ -824,8 +819,8 @@ namespace data
{ {
if (i >= ind) if (i >= ind)
{ {
if (!it.second->IsUnreachable () && filter (it.second)) if (!it.second->IsUnreachable () && filter (it.second.get ()))
return it.second; return it.second.get ();
} }
else else
i++; i++;
@ -857,7 +852,7 @@ namespace data
if (m < minMetric) if (m < minMetric)
{ {
minMetric = m; minMetric = m;
r = it; r = it.get ();
} }
} }
} }

4
NetDb.h

@ -109,9 +109,9 @@ namespace data
private: private:
std::map<IdentHash, LeaseSet *> m_LeaseSets; std::map<IdentHash, LeaseSet *> m_LeaseSets;
std::map<IdentHash, RouterInfo *> m_RouterInfos; std::map<IdentHash, std::shared_ptr<RouterInfo> > m_RouterInfos;
mutable std::mutex m_FloodfillsMutex; mutable std::mutex m_FloodfillsMutex;
std::vector<RouterInfo *> m_Floodfills; std::vector<std::shared_ptr<RouterInfo> > m_Floodfills;
std::mutex m_RequestedDestinationsMutex; std::mutex m_RequestedDestinationsMutex;
std::map<IdentHash, RequestedDestination *> m_RequestedDestinations; std::map<IdentHash, RequestedDestination *> m_RequestedDestinations;

Loading…
Cancel
Save