mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-11 17:37:53 +00:00
Reseed through I2PControl
This commit is contained in:
parent
f5b937667a
commit
027c43c99c
@ -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");
|
||||||
|
@ -51,7 +51,8 @@ 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
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -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);
|
||||||
|
44
NetDb.cpp
44
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,24 +86,20 @@ 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++;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if still not enough download .dat files
|
// deprecated
|
||||||
reseedRetries = 0;
|
if (m_Reseeder)
|
||||||
while (m_RouterInfos.size () < 50 && reseedRetries < 10)
|
|
||||||
{
|
{
|
||||||
reseeder.reseedNow();
|
// if still not enough download .dat files
|
||||||
reseedRetries++;
|
int reseedRetries = 0;
|
||||||
Load (m_NetDbPath);
|
while (m_RouterInfos.size () < 50 && reseedRetries < 10)
|
||||||
|
{
|
||||||
|
m_Reseeder->reseedNow();
|
||||||
|
reseedRetries++;
|
||||||
|
Load (m_NetDbPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_IsRunning = true;
|
m_IsRunning = true;
|
||||||
@ -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
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…
Reference in New Issue
Block a user