mirror of https://github.com/PurpleI2P/i2pd.git
orignal
11 years ago
8 changed files with 229 additions and 47 deletions
@ -0,0 +1,74 @@
@@ -0,0 +1,74 @@
|
||||
#include <iostream> |
||||
#include <fstream> |
||||
#include <boost/regex.hpp> |
||||
#include "Reseed.h" |
||||
#include "Log.h" |
||||
#include "util.h" |
||||
|
||||
|
||||
namespace i2p |
||||
{ |
||||
namespace data |
||||
{ |
||||
//TODO: Implement v2 reseeding. Lightweight zip library is needed.
|
||||
//TODO: Implement SU3, utils.
|
||||
Reseeder::Reseeder() |
||||
{ |
||||
} |
||||
|
||||
Reseeder::~Reseeder() |
||||
{ |
||||
} |
||||
|
||||
bool Reseeder::reseedNow() |
||||
{ |
||||
try |
||||
{ |
||||
std::string reseedHost = httpReseedHostList[(rand() % httpReseedHostList.size())]; |
||||
LogPrint("Reseeding from ", reseedHost); |
||||
std::string content = i2p::util::http::httpRequest(reseedHost); |
||||
if (content == "") |
||||
{ |
||||
LogPrint("Reseed failed"); |
||||
return false; |
||||
} |
||||
boost::regex e("<\\s*A\\s+[^>]*href\\s*=\\s*\"([^\"]*)\"", boost::regex::normal | boost::regbase::icase); |
||||
boost::sregex_token_iterator i(content.begin(), content.end(), e, 1); |
||||
boost::sregex_token_iterator j; |
||||
//TODO: Ugly code, try to clean up.
|
||||
//TODO: Try to reduce N number of variables
|
||||
std::string name; |
||||
std::string routerInfo; |
||||
std::string tmpUrl; |
||||
std::string filename; |
||||
std::string ignoreFileSuffix = ".zip"; |
||||
while (i != j) |
||||
{ |
||||
name = *i++; |
||||
if (name.find(ignoreFileSuffix)!=std::string::npos) |
||||
continue; |
||||
LogPrint("Downloading ", name); |
||||
tmpUrl = reseedHost; |
||||
tmpUrl.append(name); |
||||
routerInfo = i2p::util::http::httpRequest(tmpUrl); |
||||
filename = "netDb/r"; |
||||
filename += name.at(11); // first char in id
|
||||
filename.append("/"); |
||||
filename.append(name.c_str()); |
||||
std::ofstream outfile (filename, std::ios::binary); |
||||
outfile << routerInfo; |
||||
outfile.close(); |
||||
} |
||||
return true; |
||||
} |
||||
catch (std::exception& ex) |
||||
{ |
||||
//TODO: error reporting
|
||||
return false; |
||||
} |
||||
return false; |
||||
} |
||||
|
||||
} |
||||
} |
||||
|
@ -0,0 +1,36 @@
@@ -0,0 +1,36 @@
|
||||
#ifndef RESEED_H |
||||
#define RESEED_H |
||||
|
||||
#include <string> |
||||
#include <vector> |
||||
|
||||
namespace i2p |
||||
{ |
||||
namespace data |
||||
{ |
||||
|
||||
class Reseeder |
||||
{ |
||||
public: |
||||
Reseeder(); |
||||
~Reseeder(); |
||||
bool reseedNow(); |
||||
private: |
||||
std::vector<std::string> httpReseedHostList = { |
||||
"http://193.150.121.66/netDb/", |
||||
"http://netdb.i2p2.no/", |
||||
"http://reseed.i2p-projekt.de/", |
||||
"http://cowpuncher.drollette.com/netdb/", |
||||
"http://i2p.mooo.com/netDb/", |
||||
"http://reseed.info/", |
||||
"http://reseed.pkol.de/", |
||||
"http://uk.reseed.i2p2.no/", |
||||
"http://i2p-netdb.innovatio.no/", |
||||
"http://ieb9oopo.mooo.com" |
||||
}; |
||||
}; |
||||
|
||||
} |
||||
} |
||||
|
||||
#endif |
Loading…
Reference in new issue