i2pd/NetDb.h

68 lines
1.5 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);
2013-11-29 16:52:09 +04:00
RouterInfo * FindRouter (const IdentHash& ident) const;
2013-12-22 20:29:57 +04:00
LeaseSet * FindLeaseSet (const IdentHash& destination) const;
void RequestDestination (const char * b32, const uint8_t * router); // in base32
2013-11-13 16:59:21 +04:00
void RequestDestination (const uint8_t * destination, const uint8_t * router);
2013-12-22 20:29:57 +04:00
void RequestDestination (const IdentHash& destination);
void HandleDatabaseStoreMsg (uint8_t * buf, size_t len);
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:
2013-11-29 16:52:09 +04:00
std::map<IdentHash, LeaseSet *> m_LeaseSets;
std::map<IdentHash, 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