Browse Source

publish

pull/46/head
orignal 11 years ago
parent
commit
ce722e7a5e
  1. 24
      NetDb.cpp
  2. 1
      NetDb.h

24
NetDb.cpp

@ -90,7 +90,7 @@ namespace data @@ -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 @@ -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 @@ -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)
{

1
NetDb.h

@ -82,6 +82,7 @@ namespace data @@ -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,

Loading…
Cancel
Save