Browse Source

add NetDb::WaitForReady

pull/628/head
Jeff Becker 8 years ago
parent
commit
10ffdb2766
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
  1. 14
      NetDb.cpp
  2. 8
      NetDb.h

14
NetDb.cpp

@ -23,7 +23,7 @@ namespace data @@ -23,7 +23,7 @@ namespace data
{
NetDb netdb;
NetDb::NetDb (): m_IsRunning (false), m_Thread (nullptr), m_Reseeder (nullptr), m_Storage("netDb", "r", "routerInfo-", "dat"), m_HiddenMode(false)
NetDb::NetDb (): m_Ready(new std::promise<void>()), m_IsRunning (false), m_Thread (nullptr), m_Reseeder (nullptr), m_Storage("netDb", "r", "routerInfo-", "dat"), m_HiddenMode(false)
{
}
@ -38,13 +38,14 @@ namespace data @@ -38,13 +38,14 @@ namespace data
m_Storage.SetPlace(i2p::fs::GetDataDir());
m_Storage.Init(i2p::data::GetBase64SubstitutionTable(), 64);
InitProfilesStorage ();
m_Families.LoadCertificates ();
m_Families.LoadCertificates ();
Load ();
if (m_RouterInfos.size () < 25) // reseed if # of router less than 50
Reseed ();
m_IsRunning = true;
m_Thread = new std::thread (std::bind (&NetDb::Run, this));
m_Ready->set_value();
}
void NetDb::Stop ()
@ -68,7 +69,14 @@ namespace data @@ -68,7 +69,14 @@ namespace data
m_Requests.Stop ();
}
}
void NetDb::WaitForReady()
{
m_Ready->get_future().wait();
delete m_Ready;
m_Ready = nullptr;
}
void NetDb::Run ()
{
uint32_t lastSave = 0, lastPublish = 0, lastExploratory = 0, lastManageRequest = 0, lastDestinationCleanup = 0;

8
NetDb.h

@ -8,6 +8,7 @@ @@ -8,6 +8,7 @@
#include <string>
#include <thread>
#include <mutex>
#include <future>
#include "Base.h"
#include "Gzip.h"
@ -48,7 +49,9 @@ namespace data @@ -48,7 +49,9 @@ namespace data
void Start ();
void Stop ();
/** block until netdb is ready, call only once*/
void WaitForReady();
bool AddRouterInfo (const uint8_t * buf, int len);
bool AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len);
bool AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, std::shared_ptr<i2p::tunnel::InboundTunnel> from);
@ -109,7 +112,8 @@ namespace data @@ -109,7 +112,8 @@ namespace data
std::shared_ptr<const RouterInfo> GetRandomRouter (Filter filter) const;
private:
std::promise<void> * m_Ready;
mutable std::mutex m_LeaseSetsMutex;
std::map<IdentHash, std::shared_ptr<LeaseSet> > m_LeaseSets;
mutable std::mutex m_RouterInfosMutex;

Loading…
Cancel
Save