Browse Source

Reseed through I2PControl

pull/150/head
orignal 10 years ago
parent
commit
027c43c99c
  1. 10
      I2PControl.cpp
  2. 2
      I2PControl.h
  3. 36
      NetDb.cpp
  4. 5
      NetDb.h

10
I2PControl.cpp

@ -38,6 +38,7 @@ namespace client
// RouterManager // RouterManager
m_RouterManagerHandlers[I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN] = &I2PControlService::ShutdownHandler; m_RouterManagerHandlers[I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN] = &I2PControlService::ShutdownHandler;
m_RouterManagerHandlers[I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN_GRACEFUL] = &I2PControlService::ShutdownGracefulHandler; m_RouterManagerHandlers[I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN_GRACEFUL] = &I2PControlService::ShutdownGracefulHandler;
m_RouterManagerHandlers[I2P_CONTROL_ROUTER_MANAGER_RESEED] = &I2PControlService::ReseedHandler;
} }
I2PControlService::~I2PControlService () I2PControlService::~I2PControlService ()
@ -330,7 +331,14 @@ namespace client
}); });
} }
// network setting void I2PControlService::ReseedHandler (std::map<std::string, std::string>& results)
{
LogPrint (eLogInfo, "Reseed requested");
results[I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN] = "";
i2p::data::netdb.Reseed ();
}
// network setting
void I2PControlService::NetworkSettingHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results) void I2PControlService::NetworkSettingHandler (const std::map<std::string, std::string>& params, std::map<std::string, std::string>& results)
{ {
LogPrint (eLogDebug, "I2PControl NetworkSetting"); LogPrint (eLogDebug, "I2PControl NetworkSetting");

2
I2PControl.h

@ -51,6 +51,7 @@ namespace client
// RouterManager requests // RouterManager requests
const char I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN[] = "Shutdown"; const char I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN[] = "Shutdown";
const char I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN_GRACEFUL[] = "ShutdownGraceful"; const char I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN_GRACEFUL[] = "ShutdownGraceful";
const char I2P_CONTROL_ROUTER_MANAGER_RESEED[] = "Reseed";
class I2PControlService class I2PControlService
{ {
@ -101,6 +102,7 @@ namespace client
typedef void (I2PControlService::*RouterManagerRequestHandler)(std::map<std::string, std::string>& results); typedef void (I2PControlService::*RouterManagerRequestHandler)(std::map<std::string, std::string>& results);
void ShutdownHandler (std::map<std::string, std::string>& results); void ShutdownHandler (std::map<std::string, std::string>& results);
void ShutdownGracefulHandler (std::map<std::string, std::string>& results); void ShutdownGracefulHandler (std::map<std::string, std::string>& results);
void ReseedHandler (std::map<std::string, std::string>& results);
// NetworkSetting // NetworkSetting
typedef void (I2PControlService::*NetworkSettingRequestHandler)(const std::string& value, std::map<std::string, std::string>& results); typedef void (I2PControlService::*NetworkSettingRequestHandler)(const std::string& value, std::map<std::string, std::string>& results);

36
NetDb.cpp

@ -13,7 +13,6 @@
#include "RouterContext.h" #include "RouterContext.h"
#include "Garlic.h" #include "Garlic.h"
#include "NetDb.h" #include "NetDb.h"
#include "Reseed.h"
#include "util.h" #include "util.h"
using namespace i2p::transport; using namespace i2p::transport;
@ -72,13 +71,14 @@ namespace data
#endif #endif
NetDb netdb; NetDb netdb;
NetDb::NetDb (): m_IsRunning (false), m_Thread (nullptr) NetDb::NetDb (): m_IsRunning (false), m_Thread (nullptr), m_Reseeder (nullptr)
{ {
} }
NetDb::~NetDb () NetDb::~NetDb ()
{ {
Stop (); Stop ();
delete m_Reseeder;
} }
void NetDb::Start () void NetDb::Start ()
@ -86,26 +86,22 @@ namespace data
Load (m_NetDbPath); Load (m_NetDbPath);
if (m_RouterInfos.size () < 50) // reseed if # of router less than 50 if (m_RouterInfos.size () < 50) // reseed if # of router less than 50
{ {
Reseeder reseeder;
reseeder.LoadCertificates (); // we need certificates for SU3 verification
// try SU3 first // try SU3 first
int reseedRetries = 0; Reseed ();
while (m_RouterInfos.size () < 50 && reseedRetries < 10)
{
reseeder.ReseedNowSU3();
reseedRetries++;
}
// deprecated
if (m_Reseeder)
{
// if still not enough download .dat files // if still not enough download .dat files
reseedRetries = 0; int reseedRetries = 0;
while (m_RouterInfos.size () < 50 && reseedRetries < 10) while (m_RouterInfos.size () < 50 && reseedRetries < 10)
{ {
reseeder.reseedNow(); m_Reseeder->reseedNow();
reseedRetries++; reseedRetries++;
Load (m_NetDbPath); Load (m_NetDbPath);
} }
} }
}
m_IsRunning = true; m_IsRunning = true;
m_Thread = new std::thread (std::bind (&NetDb::Run, this)); m_Thread = new std::thread (std::bind (&NetDb::Run, this));
} }
@ -314,6 +310,20 @@ namespace data
return true; return true;
} }
void NetDb::Reseed ()
{
if (!m_Reseeder)
{
m_Reseeder = new Reseeder ();
m_Reseeder->LoadCertificates (); // we need certificates for SU3 verification
}
int reseedRetries = 0;
while (reseedRetries < 10 && !m_Reseeder->ReseedNowSU3 ())
reseedRetries++;
if (reseedRetries >= 10)
LogPrint (eLogWarning, "Failed to reseed after 10 attempts");
}
void NetDb::Load (const char * directory) void NetDb::Load (const char * directory)
{ {
boost::filesystem::path p (i2p::util::filesystem::GetDataDir()); boost::filesystem::path p (i2p::util::filesystem::GetDataDir());

5
NetDb.h

@ -15,6 +15,7 @@
#include "LeaseSet.h" #include "LeaseSet.h"
#include "Tunnel.h" #include "Tunnel.h"
#include "TunnelPool.h" #include "TunnelPool.h"
#include "Reseed.h"
namespace i2p namespace i2p
{ {
@ -83,6 +84,8 @@ namespace data
void PostI2NPMsg (I2NPMessage * msg); void PostI2NPMsg (I2NPMessage * msg);
void Reseed ();
// for web interface // for web interface
int GetNumRouters () const { return m_RouterInfos.size (); }; int GetNumRouters () const { return m_RouterInfos.size (); };
int GetNumFloodfills () const { return m_Floodfills.size (); }; int GetNumFloodfills () const { return m_Floodfills.size (); };
@ -119,6 +122,8 @@ namespace data
std::thread * m_Thread; std::thread * m_Thread;
i2p::util::Queue<I2NPMessage> m_Queue; // of I2NPDatabaseStoreMsg i2p::util::Queue<I2NPMessage> m_Queue; // of I2NPDatabaseStoreMsg
Reseeder * m_Reseeder;
static const char m_NetDbPath[]; static const char m_NetDbPath[];
}; };

Loading…
Cancel
Save