|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
#include <iostream> |
|
|
|
|
#include <fstream> |
|
|
|
|
#include <sstream> |
|
|
|
|
#include <boost/regex.hpp> |
|
|
|
|
#include <boost/filesystem.hpp> |
|
|
|
|
#include <cryptopp/zinflate.h> |
|
|
|
@ -7,6 +7,7 @@
@@ -7,6 +7,7 @@
|
|
|
|
|
#include "Reseed.h" |
|
|
|
|
#include "Log.h" |
|
|
|
|
#include "Identity.h" |
|
|
|
|
#include "NetDb.h" |
|
|
|
|
#include "util.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -122,21 +123,52 @@ namespace data
@@ -122,21 +123,52 @@ namespace data
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int Reseeder::ReseedNowSU3 () |
|
|
|
|
{ |
|
|
|
|
std::string reseedHost = httpReseedHostList[(rand() % httpReseedHostList.size())]; |
|
|
|
|
return ReseedFromSU3 (reseedHost); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const char SU3_MAGIC_NUMBER[]="I2Psu3"; |
|
|
|
|
void ProcessSU3File (const char * filename) |
|
|
|
|
int Reseeder::ReseedFromSU3 (const std::string& host) |
|
|
|
|
{ |
|
|
|
|
static uint32_t headerSignature = htole32 (0x04034B50); |
|
|
|
|
std::string url = host + "i2pseeds.su3"; |
|
|
|
|
LogPrint (eLogInfo, "Dowloading SU3 from ", host); |
|
|
|
|
std::string su3 = i2p::util::http::httpRequest (url); |
|
|
|
|
if (su3.length () > 0) |
|
|
|
|
{ |
|
|
|
|
std::stringstream s(su3); |
|
|
|
|
return ProcessSU3Stream (s); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
LogPrint (eLogWarning, "SU3 download failed"); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int ProcessSU3File (const char * filename) |
|
|
|
|
{ |
|
|
|
|
std::ifstream s(filename, std::ifstream::binary); |
|
|
|
|
if (s.is_open ()) |
|
|
|
|
return ProcessSU3Stream (s); |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
LogPrint (eLogError, "Can't open file ", filename); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const char SU3_MAGIC_NUMBER[]="I2Psu3"; |
|
|
|
|
int ProcessSU3Stream (std::istream& s) |
|
|
|
|
{ |
|
|
|
|
static uint32_t headerSignature = htole32 (0x04034B50); |
|
|
|
|
|
|
|
|
|
char magicNumber[7]; |
|
|
|
|
s.read (magicNumber, 7); // magic number and zero byte 6
|
|
|
|
|
if (strcmp (magicNumber, SU3_MAGIC_NUMBER)) |
|
|
|
|
{ |
|
|
|
|
LogPrint (eLogError, "Unexpected SU3 magic number"); |
|
|
|
|
return; |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
s.seekg (1, std::ios::cur); // su3 file format version
|
|
|
|
|
SigningKeyType signatureType; |
|
|
|
@ -160,7 +192,7 @@ namespace data
@@ -160,7 +192,7 @@ namespace data
|
|
|
|
|
if (fileType != 0x00) // zip file
|
|
|
|
|
{ |
|
|
|
|
LogPrint (eLogError, "Can't handle file type ", (int)fileType); |
|
|
|
|
return; |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
s.seekg (1, std::ios::cur); // unused
|
|
|
|
|
uint8_t contentType; |
|
|
|
@ -168,7 +200,7 @@ namespace data
@@ -168,7 +200,7 @@ namespace data
|
|
|
|
|
if (contentType != 0x03) // reseed data
|
|
|
|
|
{ |
|
|
|
|
LogPrint (eLogError, "Unexpected content type ", (int)contentType); |
|
|
|
|
return; |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
s.seekg (12, std::ios::cur); // unused
|
|
|
|
|
|
|
|
|
@ -176,6 +208,7 @@ namespace data
@@ -176,6 +208,7 @@ namespace data
|
|
|
|
|
s.seekg (signerIDLength, std::ios::cur); // skip signer ID
|
|
|
|
|
|
|
|
|
|
// handle content
|
|
|
|
|
int numFiles = 0; |
|
|
|
|
size_t contentPos = s.tellg (); |
|
|
|
|
while (!s.eof ()) |
|
|
|
|
{ |
|
|
|
@ -206,11 +239,13 @@ namespace data
@@ -206,11 +239,13 @@ namespace data
|
|
|
|
|
CryptoPP::Inflator decompressor; |
|
|
|
|
decompressor.Put (compressed, compressedSize); |
|
|
|
|
delete[] compressed; |
|
|
|
|
if (decompressor.MaxRetrievable () <= uncompressedSize) |
|
|
|
|
size_t len = decompressor.MaxRetrievable (); |
|
|
|
|
if (len <= uncompressedSize) |
|
|
|
|
{ |
|
|
|
|
uint8_t * uncompressed = new uint8_t[uncompressedSize]; |
|
|
|
|
decompressor.Get (uncompressed, decompressor.MaxRetrievable ()); |
|
|
|
|
// TODO: save file
|
|
|
|
|
decompressor.Get (uncompressed, len); |
|
|
|
|
i2p::data::netdb.AddRouterInfo (uncompressed, len); |
|
|
|
|
numFiles++; |
|
|
|
|
delete[] uncompressed; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
@ -222,11 +257,8 @@ namespace data
@@ -222,11 +257,8 @@ namespace data
|
|
|
|
|
if (end - contentPos >= contentLength) |
|
|
|
|
break; // we are beyond contentLength
|
|
|
|
|
} |
|
|
|
|
return numFiles; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
LogPrint (eLogError, "Can't open file ", filename); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|