diff --git a/NetDb.cpp b/NetDb.cpp index aa040758..f9da5263 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -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 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) { diff --git a/NetDb.h b/NetDb.h index 8f0e4125..68c136bc 100644 --- a/NetDb.h +++ b/NetDb.h @@ -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& excluded) const; RequestedDestination * CreateRequestedDestination (const IdentHash& dest,