i2pd/NetDb.h

64 lines
1.3 KiB
C
Raw Normal View History

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