Browse Source

Added option to reseed from ZIP file

pull/792/head
Darknet Villain 8 years ago
parent
commit
21e23d5511
  1. 1
      Config.cpp
  2. 33
      NetDb.cpp
  3. 18
      Reseed.cpp
  4. 8
      Reseed.h

1
Config.cpp

@ -167,6 +167,7 @@ namespace config {
("reseed.verify", value<bool>()->default_value(false), "Verify .su3 signature") ("reseed.verify", value<bool>()->default_value(false), "Verify .su3 signature")
("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.urls", value<std::string>()->default_value( ("reseed.urls", value<std::string>()->default_value(
"https://reseed.i2p-projekt.de/," "https://reseed.i2p-projekt.de/,"
"https://i2p.mooo.com/netDb/," "https://i2p.mooo.com/netDb/,"

33
NetDb.cpp

@ -308,7 +308,6 @@ namespace data
m_Reseeder = new Reseeder (); m_Reseeder = new Reseeder ();
m_Reseeder->LoadCertificates (); // we need certificates for SU3 verification m_Reseeder->LoadCertificates (); // we need certificates for SU3 verification
} }
int reseedRetries = 0;
// try reseeding from floodfill first if specified // try reseeding from floodfill first if specified
std::string riPath; std::string riPath;
@ -329,11 +328,41 @@ namespace data
} }
} }
while (reseedRetries < 10 && !m_Reseeder->ReseedNowSU3 ())
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++; reseedRetries++;
if (reseedRetries >= 10) if (reseedRetries >= 10)
LogPrint (eLogWarning, "NetDb: failed to reseed after 10 attempts"); 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)
{ {

18
Reseed.cpp

@ -32,30 +32,18 @@ namespace data
{ {
} }
int Reseeder::ReseedNowSU3 () 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);
std::string filename; i2p::config::GetOption("reseed.file", filename);
if (filename.length() > 0) // reseed file is specified
{
if (filename.length() > 8 && filename.substr(0, 8) == "https://")
{
return ReseedFromSU3 (filename); // reseed from https URL
} else {
auto num = ProcessSU3File (filename.c_str ());
if (num > 0) return num; // success
LogPrint (eLogWarning, "Can't reseed from ", filename, " . Trying from hosts");
}
}
auto ind = rand () % httpsReseedHostList.size (); auto ind = rand () % httpsReseedHostList.size ();
std::string reseedUrl = httpsReseedHostList[ind] + "i2pseeds.su3"; std::string reseedUrl = httpsReseedHostList[ind] + "i2pseeds.su3";
return ReseedFromSU3 (reseedUrl); return ReseedFromSU3Url (reseedUrl);
} }
int Reseeder::ReseedFromSU3 (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);
std::string su3 = HttpsRequest (url); std::string su3 = HttpsRequest (url);

8
Reseed.h

@ -21,7 +21,10 @@ namespace data
Reseeder(); Reseeder();
~Reseeder(); ~Reseeder();
int ReseedNowSU3 (); int ReseedFromServers ();
int ReseedFromSU3Url (const std::string& url);
int ProcessSU3File (const char * filename);
int ProcessZIPFile (const char * filename);
void LoadCertificates (); void LoadCertificates ();
@ -29,9 +32,6 @@ namespace data
void LoadCertificate (const std::string& filename); void LoadCertificate (const std::string& filename);
int ReseedFromSU3 (const std::string& url);
int ProcessSU3File (const char * filename);
int ProcessZIPFile (const char * filename);
int ProcessSU3Stream (std::istream& s); int ProcessSU3Stream (std::istream& s);
int ProcessZIPStream (std::istream& s, uint64_t contentLength); int ProcessZIPStream (std::istream& s, uint64_t contentLength);

Loading…
Cancel
Save