mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-10 17:41:06 +00:00
Merge pull request #793 from l-n-s/reseed_from_zip
Added reseed.threshold + refactor
This commit is contained in:
commit
19e5b8cc50
@ -165,6 +165,7 @@ namespace config {
|
|||||||
options_description reseed("Reseed options");
|
options_description reseed("Reseed options");
|
||||||
reseed.add_options()
|
reseed.add_options()
|
||||||
("reseed.verify", value<bool>()->default_value(false), "Verify .su3 signature")
|
("reseed.verify", value<bool>()->default_value(false), "Verify .su3 signature")
|
||||||
|
("reseed.threshold", value<uint16_t>()->default_value(25), "Minimum number of known routers before requesting reseed")
|
||||||
("reseed.floodfill", value<std::string>()->default_value(""), "Path to router info of floodfill to reseed from")
|
("reseed.floodfill", value<std::string>()->default_value(""), "Path to router info of floodfill to reseed from")
|
||||||
("reseed.file", value<std::string>()->default_value(""), "Path to local .su3 file or HTTPS URL to reseed from")
|
("reseed.file", value<std::string>()->default_value(""), "Path to local .su3 file or HTTPS URL to reseed from")
|
||||||
("reseed.zipfile", value<std::string>()->default_value(""), "Path to local .zip file to reseed from")
|
("reseed.zipfile", value<std::string>()->default_value(""), "Path to local .zip file to reseed from")
|
||||||
|
39
NetDb.cpp
39
NetDb.cpp
@ -41,7 +41,9 @@ namespace data
|
|||||||
InitProfilesStorage ();
|
InitProfilesStorage ();
|
||||||
m_Families.LoadCertificates ();
|
m_Families.LoadCertificates ();
|
||||||
Load ();
|
Load ();
|
||||||
if (m_RouterInfos.size () < 25) // reseed if # of router less than 50
|
|
||||||
|
uint16_t threshold; i2p::config::GetOption("reseed.threshold", threshold);
|
||||||
|
if (m_RouterInfos.size () < threshold) // reseed if # of router less than threshold
|
||||||
Reseed ();
|
Reseed ();
|
||||||
|
|
||||||
m_IsRunning = true;
|
m_IsRunning = true;
|
||||||
@ -328,40 +330,7 @@ namespace data
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_Reseeder->Bootstrap ();
|
||||||
std::string su3FileName; i2p::config::GetOption("reseed.file", su3FileName);
|
|
||||||
std::string zipFileName; i2p::config::GetOption("reseed.zipfile", zipFileName);
|
|
||||||
|
|
||||||
if (su3FileName.length() > 0) // bootstrap from SU3 file or URL
|
|
||||||
{
|
|
||||||
int num;
|
|
||||||
if (su3FileName.length() > 8 && su3FileName.substr(0, 8) == "https://")
|
|
||||||
{
|
|
||||||
num = m_Reseeder->ReseedFromSU3Url (su3FileName); // from https URL
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
num = m_Reseeder->ProcessSU3File (su3FileName.c_str ());
|
|
||||||
}
|
|
||||||
if (num == 0)
|
|
||||||
LogPrint (eLogWarning, "NetDb: failed to reseed from ", su3FileName);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (zipFileName.length() > 0) // bootstrap from ZIP file
|
|
||||||
{
|
|
||||||
int num = m_Reseeder->ProcessZIPFile (zipFileName.c_str ());
|
|
||||||
if (num == 0)
|
|
||||||
LogPrint (eLogWarning, "NetDb: failed to reseed from ", zipFileName);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else // bootstrap from reseed servers
|
|
||||||
{
|
|
||||||
int reseedRetries = 0;
|
|
||||||
while (reseedRetries < 10 && !m_Reseeder->ReseedFromServers ())
|
|
||||||
reseedRetries++;
|
|
||||||
if (reseedRetries >= 10)
|
|
||||||
LogPrint (eLogWarning, "NetDb: failed to reseed after 10 attempts");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetDb::ReseedFromFloodfill(const RouterInfo & ri, int numRouters, int numFloodfills)
|
void NetDb::ReseedFromFloodfill(const RouterInfo & ri, int numRouters, int numFloodfills)
|
||||||
|
62
Reseed.cpp
62
Reseed.cpp
@ -32,17 +32,73 @@ namespace data
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @brief tries to bootstrap into I2P network (from local files and servers, with respect of options)
|
||||||
|
*/
|
||||||
|
void Reseeder::Bootstrap ()
|
||||||
|
{
|
||||||
|
std::string su3FileName; i2p::config::GetOption("reseed.file", su3FileName);
|
||||||
|
std::string zipFileName; i2p::config::GetOption("reseed.zipfile", zipFileName);
|
||||||
|
|
||||||
|
if (su3FileName.length() > 0) // bootstrap from SU3 file or URL
|
||||||
|
{
|
||||||
|
int num;
|
||||||
|
if (su3FileName.length() > 8 && su3FileName.substr(0, 8) == "https://")
|
||||||
|
{
|
||||||
|
num = ReseedFromSU3Url (su3FileName); // from https URL
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
num = ProcessSU3File (su3FileName.c_str ());
|
||||||
|
}
|
||||||
|
if (num == 0)
|
||||||
|
LogPrint (eLogWarning, "Reseed: failed to reseed from ", su3FileName);
|
||||||
|
}
|
||||||
|
else if (zipFileName.length() > 0) // bootstrap from ZIP file
|
||||||
|
{
|
||||||
|
int num = ProcessZIPFile (zipFileName.c_str ());
|
||||||
|
if (num == 0)
|
||||||
|
LogPrint (eLogWarning, "Reseed: failed to reseed from ", zipFileName);
|
||||||
|
}
|
||||||
|
else // bootstrap from reseed servers
|
||||||
|
{
|
||||||
|
int num = ReseedFromServers ();
|
||||||
|
if (num == 0)
|
||||||
|
LogPrint (eLogWarning, "Reseed: failed to reseed from servers");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief bootstrap from random server, retry 10 times
|
||||||
|
* @return number of entries added to netDb
|
||||||
|
*/
|
||||||
int Reseeder::ReseedFromServers ()
|
int Reseeder::ReseedFromServers ()
|
||||||
{
|
{
|
||||||
std::string reseedURLs; i2p::config::GetOption("reseed.urls", reseedURLs);
|
std::string reseedURLs; i2p::config::GetOption("reseed.urls", reseedURLs);
|
||||||
std::vector<std::string> httpsReseedHostList;
|
std::vector<std::string> httpsReseedHostList;
|
||||||
boost::split(httpsReseedHostList, reseedURLs, boost::is_any_of(","), boost::token_compress_on);
|
boost::split(httpsReseedHostList, reseedURLs, boost::is_any_of(","), boost::token_compress_on);
|
||||||
|
|
||||||
auto ind = rand () % httpsReseedHostList.size ();
|
if (reseedURLs.length () == 0)
|
||||||
std::string reseedUrl = httpsReseedHostList[ind] + "i2pseeds.su3";
|
{
|
||||||
return ReseedFromSU3Url (reseedUrl);
|
LogPrint (eLogWarning, "Reseed: No reseed servers specified");
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int reseedRetries = 0;
|
||||||
|
while (reseedRetries < 10)
|
||||||
|
{
|
||||||
|
auto ind = rand () % httpsReseedHostList.size ();
|
||||||
|
std::string reseedUrl = httpsReseedHostList[ind] + "i2pseeds.su3";
|
||||||
|
auto num = ReseedFromSU3Url (reseedUrl);
|
||||||
|
if (num > 0) return num; // success
|
||||||
|
reseedRetries++;
|
||||||
|
}
|
||||||
|
LogPrint (eLogWarning, "Reseed: failed to reseed from servers after 10 attempts");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief bootstrap from HTTPS URL with SU3 file
|
||||||
|
* @param url
|
||||||
|
* @return number of entries added to netDb
|
||||||
|
*/
|
||||||
int Reseeder::ReseedFromSU3Url (const std::string& url)
|
int Reseeder::ReseedFromSU3Url (const std::string& url)
|
||||||
{
|
{
|
||||||
LogPrint (eLogInfo, "Reseed: Downloading SU3 from ", url);
|
LogPrint (eLogInfo, "Reseed: Downloading SU3 from ", url);
|
||||||
|
1
Reseed.h
1
Reseed.h
@ -21,6 +21,7 @@ namespace data
|
|||||||
|
|
||||||
Reseeder();
|
Reseeder();
|
||||||
~Reseeder();
|
~Reseeder();
|
||||||
|
void Bootstrap ();
|
||||||
int ReseedFromServers ();
|
int ReseedFromServers ();
|
||||||
int ReseedFromSU3Url (const std::string& url);
|
int ReseedFromSU3Url (const std::string& url);
|
||||||
int ProcessSU3File (const char * filename);
|
int ProcessSU3File (const char * filename);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user