|
|
@ -13,7 +13,6 @@ |
|
|
|
#include "RouterContext.h" |
|
|
|
#include "RouterContext.h" |
|
|
|
#include "Garlic.h" |
|
|
|
#include "Garlic.h" |
|
|
|
#include "NetDb.h" |
|
|
|
#include "NetDb.h" |
|
|
|
#include "Reseed.h" |
|
|
|
|
|
|
|
#include "util.h" |
|
|
|
#include "util.h" |
|
|
|
|
|
|
|
|
|
|
|
using namespace i2p::transport; |
|
|
|
using namespace i2p::transport; |
|
|
@ -72,13 +71,14 @@ namespace data |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
NetDb netdb; |
|
|
|
NetDb netdb; |
|
|
|
|
|
|
|
|
|
|
|
NetDb::NetDb (): m_IsRunning (false), m_Thread (nullptr) |
|
|
|
NetDb::NetDb (): m_IsRunning (false), m_Thread (nullptr), m_Reseeder (nullptr) |
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
NetDb::~NetDb () |
|
|
|
NetDb::~NetDb () |
|
|
|
{ |
|
|
|
{ |
|
|
|
Stop (); |
|
|
|
Stop (); |
|
|
|
|
|
|
|
delete m_Reseeder; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void NetDb::Start () |
|
|
|
void NetDb::Start () |
|
|
@ -86,26 +86,22 @@ namespace data |
|
|
|
Load (m_NetDbPath); |
|
|
|
Load (m_NetDbPath); |
|
|
|
if (m_RouterInfos.size () < 50) // reseed if # of router less than 50
|
|
|
|
if (m_RouterInfos.size () < 50) // reseed if # of router less than 50
|
|
|
|
{ |
|
|
|
{ |
|
|
|
Reseeder reseeder; |
|
|
|
|
|
|
|
reseeder.LoadCertificates (); // we need certificates for SU3 verification
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// try SU3 first
|
|
|
|
// try SU3 first
|
|
|
|
int reseedRetries = 0; |
|
|
|
Reseed (); |
|
|
|
while (m_RouterInfos.size () < 50 && reseedRetries < 10) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
reseeder.ReseedNowSU3(); |
|
|
|
|
|
|
|
reseedRetries++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// deprecated
|
|
|
|
|
|
|
|
if (m_Reseeder) |
|
|
|
|
|
|
|
{ |
|
|
|
// if still not enough download .dat files
|
|
|
|
// if still not enough download .dat files
|
|
|
|
reseedRetries = 0; |
|
|
|
int reseedRetries = 0; |
|
|
|
while (m_RouterInfos.size () < 50 && reseedRetries < 10) |
|
|
|
while (m_RouterInfos.size () < 50 && reseedRetries < 10) |
|
|
|
{ |
|
|
|
{ |
|
|
|
reseeder.reseedNow(); |
|
|
|
m_Reseeder->reseedNow(); |
|
|
|
reseedRetries++; |
|
|
|
reseedRetries++; |
|
|
|
Load (m_NetDbPath); |
|
|
|
Load (m_NetDbPath); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
m_IsRunning = true; |
|
|
|
m_IsRunning = true; |
|
|
|
m_Thread = new std::thread (std::bind (&NetDb::Run, this)); |
|
|
|
m_Thread = new std::thread (std::bind (&NetDb::Run, this)); |
|
|
|
} |
|
|
|
} |
|
|
@ -314,6 +310,20 @@ namespace data |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void NetDb::Reseed () |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!m_Reseeder) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
m_Reseeder = new Reseeder (); |
|
|
|
|
|
|
|
m_Reseeder->LoadCertificates (); // we need certificates for SU3 verification
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
int reseedRetries = 0; |
|
|
|
|
|
|
|
while (reseedRetries < 10 && !m_Reseeder->ReseedNowSU3 ()) |
|
|
|
|
|
|
|
reseedRetries++; |
|
|
|
|
|
|
|
if (reseedRetries >= 10) |
|
|
|
|
|
|
|
LogPrint (eLogWarning, "Failed to reseed after 10 attempts"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void NetDb::Load (const char * directory) |
|
|
|
void NetDb::Load (const char * directory) |
|
|
|
{ |
|
|
|
{ |
|
|
|
boost::filesystem::path p (i2p::util::filesystem::GetDataDir()); |
|
|
|
boost::filesystem::path p (i2p::util::filesystem::GetDataDir()); |
|
|
|