This commit is contained in:
orignal 2014-02-12 22:02:39 -05:00
parent 411ac5b898
commit ce722e7a5e
2 changed files with 21 additions and 4 deletions

View File

@ -90,7 +90,7 @@ namespace data
void NetDb::Run ()
{
uint32_t lastTs = 0;
uint32_t lastSave = 0, lastPublish = 0;
m_IsRunning = true;
while (m_IsRunning)
{
@ -120,11 +120,16 @@ namespace data
Explore ();
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
if (ts - lastTs >= 60) // save routers every minute
if (ts - lastSave >= 60) // save routers every minute
{
if (lastTs)
if (lastSave)
SaveUpdated (m_NetDbPath);
lastTs = ts;
lastSave = ts;
}
if (ts - lastPublish >= 600) // publish every 10 minutes
{
Publish ();
lastPublish = ts;
}
}
catch (std::exception& ex)
@ -543,6 +548,17 @@ namespace data
}
}
void NetDb::Publish ()
{
std::set<IdentHash> excluded; // TODO: fill up later
auto floodfill = GetClosestFloodfill (i2p::context.GetRouterInfo ().GetIdentHash (), excluded);
if (floodfill)
{
LogPrint ("Publishing our RouterInfo to ", floodfill->GetIdentHashAbbreviation ());
transports.SendMessage (floodfill->GetIdentHash (), CreateDatabaseStoreMsg ());
}
}
RequestedDestination * NetDb::CreateRequestedDestination (const IdentHash& dest,
bool isLeaseSet, bool isExploratory)
{

View File

@ -82,6 +82,7 @@ namespace data
void SaveUpdated (const char * directory);
void Run (); // exploratory thread
void Explore ();
void Publish ();
const RouterInfo * GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const;
RequestedDestination * CreateRequestedDestination (const IdentHash& dest,