2013-11-13 12:59:21 +00:00
|
|
|
#ifndef NETDB_H__
|
|
|
|
#define NETDB_H__
|
|
|
|
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2013-11-19 01:37:38 +00:00
|
|
|
#include <thread>
|
2013-11-20 12:46:09 +00:00
|
|
|
#include "Queue.h"
|
|
|
|
#include "I2NPProtocol.h"
|
2013-11-13 12:59:21 +00:00
|
|
|
#include "RouterInfo.h"
|
|
|
|
#include "LeaseSet.h"
|
|
|
|
|
|
|
|
namespace i2p
|
|
|
|
{
|
|
|
|
namespace data
|
|
|
|
{
|
|
|
|
class NetDb
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
NetDb ();
|
|
|
|
~NetDb ();
|
2013-11-19 01:37:38 +00:00
|
|
|
|
|
|
|
void Start ();
|
|
|
|
void Stop ();
|
2013-11-13 12:59:21 +00:00
|
|
|
|
|
|
|
void AddRouterInfo (uint8_t * buf, int len);
|
|
|
|
void AddLeaseSet (uint8_t * buf, int len);
|
|
|
|
RouterInfo * FindRouter (const uint8_t * ident);
|
|
|
|
|
|
|
|
void RequestDestination (const uint8_t * destination, const uint8_t * router);
|
2013-11-19 01:37:38 +00:00
|
|
|
void HandleDatabaseSearchReply (const uint8_t * key, const uint8_t * router);
|
2013-11-13 12:59:21 +00:00
|
|
|
|
2013-11-19 01:37:38 +00:00
|
|
|
const RouterInfo * GetRandomNTCPRouter (bool floodfillOnly = false) const;
|
|
|
|
const RouterInfo * GetRandomRouter () const;
|
2013-11-20 12:46:09 +00:00
|
|
|
|
|
|
|
void PostDatabaseStoreMsg (I2NPMessage * msg);
|
2013-11-13 12:59:21 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void Load (const char * directory);
|
2013-11-20 12:46:09 +00:00
|
|
|
void SaveUpdated (const char * directory);
|
2013-11-19 01:37:38 +00:00
|
|
|
void Run (); // exploratory thread
|
|
|
|
void Explore ();
|
|
|
|
|
2013-11-13 12:59:21 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
std::map<std::string, LeaseSet *> m_LeaseSets;
|
|
|
|
std::map<std::string, RouterInfo *> m_RouterInfos;
|
2013-11-19 01:37:38 +00:00
|
|
|
|
|
|
|
bool m_IsRunning;
|
|
|
|
std::thread * m_Thread;
|
|
|
|
uint8_t m_Exploratory[32];
|
2013-11-20 12:46:09 +00:00
|
|
|
const RouterInfo * m_LastFloodfill;
|
|
|
|
i2p::util::Queue<I2NPMessage> m_Queue; // of I2NPDatabaseStoreMsg
|
2013-11-13 12:59:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern NetDb netdb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|