mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
add reseed from floodfill option
This commit is contained in:
parent
975dab6d1d
commit
6b5b9b3d62
|
@ -158,6 +158,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.floodfill", value<std::string>()->default_value(""), "Path to router info of floodfill to reseed from")
|
||||||
("reseed.file", value<std::string>()->default_value(""), "Path to .su3 file")
|
("reseed.file", value<std::string>()->default_value(""), "Path to .su3 file")
|
||||||
("reseed.urls", value<std::string>()->default_value(
|
("reseed.urls", value<std::string>()->default_value(
|
||||||
"https://reseed.i2p-projekt.de/,"
|
"https://reseed.i2p-projekt.de/,"
|
||||||
|
|
74
NetDb.cpp
74
NetDb.cpp
|
@ -14,6 +14,7 @@
|
||||||
#include "RouterContext.h"
|
#include "RouterContext.h"
|
||||||
#include "Garlic.h"
|
#include "Garlic.h"
|
||||||
#include "NetDb.h"
|
#include "NetDb.h"
|
||||||
|
#include "Config.h"
|
||||||
|
|
||||||
using namespace i2p::transport;
|
using namespace i2p::transport;
|
||||||
|
|
||||||
|
@ -23,7 +24,7 @@ namespace data
|
||||||
{
|
{
|
||||||
NetDb netdb;
|
NetDb netdb;
|
||||||
|
|
||||||
NetDb::NetDb (): m_IsRunning (false), m_Thread (nullptr), m_Reseeder (nullptr), m_Storage("netDb", "r", "routerInfo-", "dat"), m_HiddenMode(false)
|
NetDb::NetDb (): m_IsRunning (false), m_Thread (nullptr), m_Reseeder (nullptr), m_Storage("netDb", "r", "routerInfo-", "dat"), m_FloodfillBootstrap(nullptr), m_HiddenMode(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,6 +141,8 @@ namespace data
|
||||||
LogPrint(eLogError, "NetDb: no known routers, reseed seems to be totally failed");
|
LogPrint(eLogError, "NetDb: no known routers, reseed seems to be totally failed");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else // we have peers now
|
||||||
|
m_FloodfillBootstrap = nullptr;
|
||||||
if (numRouters < 2500 || ts - lastExploratory >= 90)
|
if (numRouters < 2500 || ts - lastExploratory >= 90)
|
||||||
{
|
{
|
||||||
numRouters = 800/numRouters;
|
numRouters = 800/numRouters;
|
||||||
|
@ -296,12 +299,61 @@ namespace data
|
||||||
m_Reseeder->LoadCertificates (); // we need certificates for SU3 verification
|
m_Reseeder->LoadCertificates (); // we need certificates for SU3 verification
|
||||||
}
|
}
|
||||||
int reseedRetries = 0;
|
int reseedRetries = 0;
|
||||||
|
|
||||||
|
// try reseeding from floodfill first if specified
|
||||||
|
std::string riPath;
|
||||||
|
if(i2p::config::GetOption("reseed.floodfill", riPath)) {
|
||||||
|
auto ri = std::make_shared<RouterInfo>(riPath);
|
||||||
|
if (ri->IsFloodfill()) {
|
||||||
|
const uint8_t * riData = ri->GetBuffer();
|
||||||
|
int riLen = ri->GetBufferLen();
|
||||||
|
if(!i2p::data::netdb.AddRouterInfo(riData, riLen)) {
|
||||||
|
// bad router info
|
||||||
|
LogPrint(eLogError, "NetDb: bad router info");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
m_FloodfillBootstrap = ri;
|
||||||
|
ReseedFromFloodfill(*ri);
|
||||||
|
// don't try reseed servers if trying to boostrap from floodfill
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while (reseedRetries < 10 && !m_Reseeder->ReseedNowSU3 ())
|
while (reseedRetries < 10 && !m_Reseeder->ReseedNowSU3 ())
|
||||||
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)
|
||||||
|
{
|
||||||
|
LogPrint(eLogInfo, "NetDB: reseeding from floodfill ", ri.GetIdentHashBase64());
|
||||||
|
std::vector<std::shared_ptr<i2p::I2NPMessage> > requests;
|
||||||
|
|
||||||
|
i2p::data::IdentHash ourIdent = i2p::context.GetIdentHash();
|
||||||
|
i2p::data::IdentHash ih = ri.GetIdentHash();
|
||||||
|
i2p::data::IdentHash randomIdent;
|
||||||
|
|
||||||
|
// make floodfill lookups
|
||||||
|
while(numFloodfills > 0) {
|
||||||
|
randomIdent.Randomize();
|
||||||
|
auto msg = i2p::CreateRouterInfoDatabaseLookupMsg(randomIdent, ourIdent, 0, false);
|
||||||
|
requests.push_back(msg);
|
||||||
|
numFloodfills --;
|
||||||
|
}
|
||||||
|
|
||||||
|
// make regular router lookups
|
||||||
|
while(numRouters > 0) {
|
||||||
|
randomIdent.Randomize();
|
||||||
|
auto msg = i2p::CreateRouterInfoDatabaseLookupMsg(randomIdent, ourIdent, 0, true);
|
||||||
|
requests.push_back(msg);
|
||||||
|
numRouters --;
|
||||||
|
}
|
||||||
|
|
||||||
|
// send them off
|
||||||
|
i2p::transport::transports.SendMessages(ih, requests);
|
||||||
|
}
|
||||||
|
|
||||||
bool NetDb::LoadRouterInfo (const std::string & path)
|
bool NetDb::LoadRouterInfo (const std::string & path)
|
||||||
{
|
{
|
||||||
auto r = std::make_shared<RouterInfo>(path);
|
auto r = std::make_shared<RouterInfo>(path);
|
||||||
|
@ -499,6 +551,21 @@ namespace data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NetDb::RequestDestinationFrom (const IdentHash& destination, const IdentHash & from, bool exploritory, RequestedDestination::RequestComplete requestComplete)
|
||||||
|
{
|
||||||
|
|
||||||
|
auto dest = m_Requests.CreateRequest (destination, exploritory, requestComplete); // non-exploratory
|
||||||
|
if (!dest)
|
||||||
|
{
|
||||||
|
LogPrint (eLogWarning, "NetDb: destination ", destination.ToBase64(), " is requested already");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LogPrint(eLogInfo, "NetDb: destination ", destination.ToBase64(), " being requested directly from ", from.ToBase64());
|
||||||
|
// direct
|
||||||
|
transports.SendMessage (from, dest->CreateRequestMessage (nullptr, nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void NetDb::HandleDatabaseStoreMsg (std::shared_ptr<const I2NPMessage> m)
|
void NetDb::HandleDatabaseStoreMsg (std::shared_ptr<const I2NPMessage> m)
|
||||||
{
|
{
|
||||||
const uint8_t * buf = m->GetPayload ();
|
const uint8_t * buf = m->GetPayload ();
|
||||||
|
@ -664,7 +731,7 @@ namespace data
|
||||||
// no more requests for detination possible. delete it
|
// no more requests for detination possible. delete it
|
||||||
m_Requests.RequestComplete (ident, nullptr);
|
m_Requests.RequestComplete (ident, nullptr);
|
||||||
}
|
}
|
||||||
else
|
else if(!m_FloodfillBootstrap)
|
||||||
LogPrint (eLogWarning, "NetDb: requested destination for ", key, " not found");
|
LogPrint (eLogWarning, "NetDb: requested destination for ", key, " not found");
|
||||||
|
|
||||||
// try responses
|
// try responses
|
||||||
|
@ -681,6 +748,9 @@ namespace data
|
||||||
{
|
{
|
||||||
// router with ident not found or too old (1 hour)
|
// router with ident not found or too old (1 hour)
|
||||||
LogPrint (eLogDebug, "NetDb: found new/outdated router. Requesting RouterInfo ...");
|
LogPrint (eLogDebug, "NetDb: found new/outdated router. Requesting RouterInfo ...");
|
||||||
|
if(m_FloodfillBootstrap)
|
||||||
|
RequestDestinationFrom(router, m_FloodfillBootstrap->GetIdentHash(), true);
|
||||||
|
else
|
||||||
RequestDestination (router);
|
RequestDestination (router);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
9
NetDb.h
9
NetDb.h
|
@ -60,6 +60,7 @@ namespace data
|
||||||
std::shared_ptr<RouterProfile> FindRouterProfile (const IdentHash& ident) const;
|
std::shared_ptr<RouterProfile> FindRouterProfile (const IdentHash& ident) const;
|
||||||
|
|
||||||
void RequestDestination (const IdentHash& destination, RequestedDestination::RequestComplete requestComplete = nullptr);
|
void RequestDestination (const IdentHash& destination, RequestedDestination::RequestComplete requestComplete = nullptr);
|
||||||
|
void RequestDestinationFrom (const IdentHash& destination, const IdentHash & from, bool exploritory, RequestedDestination::RequestComplete requestComplete = nullptr);
|
||||||
|
|
||||||
void HandleDatabaseStoreMsg (std::shared_ptr<const I2NPMessage> msg);
|
void HandleDatabaseStoreMsg (std::shared_ptr<const I2NPMessage> msg);
|
||||||
void HandleDatabaseSearchReplyMsg (std::shared_ptr<const I2NPMessage> msg);
|
void HandleDatabaseSearchReplyMsg (std::shared_ptr<const I2NPMessage> msg);
|
||||||
|
@ -98,6 +99,9 @@ namespace data
|
||||||
void VisitRouterInfos(RouterInfoVisitor v);
|
void VisitRouterInfos(RouterInfoVisitor v);
|
||||||
/** visit N random router that match using filter, then visit them with a visitor, return number of RouterInfos that were visited */
|
/** visit N random router that match using filter, then visit them with a visitor, return number of RouterInfos that were visited */
|
||||||
size_t VisitRandomRouterInfos(RouterInfoFilter f, RouterInfoVisitor v, size_t n);
|
size_t VisitRandomRouterInfos(RouterInfoFilter f, RouterInfoVisitor v, size_t n);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void Load ();
|
void Load ();
|
||||||
|
@ -110,6 +114,8 @@ namespace data
|
||||||
void ManageRequests ();
|
void ManageRequests ();
|
||||||
void ManageLookupResponses ();
|
void ManageLookupResponses ();
|
||||||
|
|
||||||
|
void ReseedFromFloodfill(const RouterInfo & ri, int numRouters=40, int numFloodfills=20);
|
||||||
|
|
||||||
template<typename Filter>
|
template<typename Filter>
|
||||||
std::shared_ptr<const RouterInfo> GetRandomRouter (Filter filter) const;
|
std::shared_ptr<const RouterInfo> GetRandomRouter (Filter filter) const;
|
||||||
|
|
||||||
|
@ -135,6 +141,9 @@ namespace data
|
||||||
friend class NetDbRequests;
|
friend class NetDbRequests;
|
||||||
NetDbRequests m_Requests;
|
NetDbRequests m_Requests;
|
||||||
|
|
||||||
|
/** router info we are bootstrapping from or nullptr if we are not currently doing that*/
|
||||||
|
std::shared_ptr<RouterInfo> m_FloodfillBootstrap;
|
||||||
|
|
||||||
std::map<IdentHash, std::pair<std::vector<IdentHash>, uint64_t> > m_LookupResponses; // ident->(closest FFs, timestamp)
|
std::map<IdentHash, std::pair<std::vector<IdentHash>, uint64_t> > m_LookupResponses; // ident->(closest FFs, timestamp)
|
||||||
|
|
||||||
/** true if in hidden mode */
|
/** true if in hidden mode */
|
||||||
|
|
|
@ -11,9 +11,14 @@ namespace data
|
||||||
std::shared_ptr<I2NPMessage> RequestedDestination::CreateRequestMessage (std::shared_ptr<const RouterInfo> router,
|
std::shared_ptr<I2NPMessage> RequestedDestination::CreateRequestMessage (std::shared_ptr<const RouterInfo> router,
|
||||||
std::shared_ptr<const i2p::tunnel::InboundTunnel> replyTunnel)
|
std::shared_ptr<const i2p::tunnel::InboundTunnel> replyTunnel)
|
||||||
{
|
{
|
||||||
auto msg = i2p::CreateRouterInfoDatabaseLookupMsg (m_Destination,
|
std::shared_ptr<I2NPMessage> msg;
|
||||||
|
if(replyTunnel)
|
||||||
|
msg = i2p::CreateRouterInfoDatabaseLookupMsg (m_Destination,
|
||||||
replyTunnel->GetNextIdentHash (), replyTunnel->GetNextTunnelID (), m_IsExploratory,
|
replyTunnel->GetNextIdentHash (), replyTunnel->GetNextTunnelID (), m_IsExploratory,
|
||||||
&m_ExcludedPeers);
|
&m_ExcludedPeers);
|
||||||
|
else
|
||||||
|
msg = i2p::CreateRouterInfoDatabaseLookupMsg(m_Destination, i2p::context.GetIdentHash(), 0, m_IsExploratory, &m_ExcludedPeers);
|
||||||
|
if(router)
|
||||||
m_ExcludedPeers.insert (router->GetIdentHash ());
|
m_ExcludedPeers.insert (router->GetIdentHash ());
|
||||||
m_CreationTime = i2p::util::GetSecondsSinceEpoch ();
|
m_CreationTime = i2p::util::GetSecondsSinceEpoch ();
|
||||||
return msg;
|
return msg;
|
||||||
|
|
6
Tag.h
6
Tag.h
|
@ -11,6 +11,7 @@
|
||||||
|
|
||||||
#include <boost/static_assert.hpp>
|
#include <boost/static_assert.hpp>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <openssl/rand.h>
|
||||||
#include "Base.h"
|
#include "Base.h"
|
||||||
|
|
||||||
namespace i2p {
|
namespace i2p {
|
||||||
|
@ -50,6 +51,11 @@ public:
|
||||||
memset(m_Buf, c, sz);
|
memset(m_Buf, c, sz);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Randomize()
|
||||||
|
{
|
||||||
|
RAND_bytes(m_Buf, sz);
|
||||||
|
}
|
||||||
|
|
||||||
std::string ToBase64 () const
|
std::string ToBase64 () const
|
||||||
{
|
{
|
||||||
char str[sz*2];
|
char str[sz*2];
|
||||||
|
|
Loading…
Reference in a new issue