mirror of https://github.com/PurpleI2P/i2pd.git
I2P: End-to-End encrypted and anonymous Internet
https://i2pd.website/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
107 lines
3.9 KiB
107 lines
3.9 KiB
11 years ago
|
#ifndef NETDB_H__
|
||
|
#define NETDB_H__
|
||
|
|
||
|
#include <inttypes.h>
|
||
11 years ago
|
#include <set>
|
||
11 years ago
|
#include <map>
|
||
10 years ago
|
#include <list>
|
||
11 years ago
|
#include <string>
|
||
11 years ago
|
#include <thread>
|
||
10 years ago
|
#include <mutex>
|
||
11 years ago
|
#include <boost/filesystem.hpp>
|
||
9 years ago
|
#include "util/Queue.h"
|
||
11 years ago
|
#include "I2NPProtocol.h"
|
||
11 years ago
|
#include "RouterInfo.h"
|
||
|
#include "LeaseSet.h"
|
||
9 years ago
|
#include "tunnel/Tunnel.h"
|
||
|
#include "tunnel/TunnelPool.h"
|
||
10 years ago
|
#include "Reseed.h"
|
||
10 years ago
|
#include "NetDbRequests.h"
|
||
11 years ago
|
|
||
|
namespace i2p
|
||
|
{
|
||
|
namespace data
|
||
10 years ago
|
{
|
||
|
|
||
|
class NetDb
|
||
|
{
|
||
|
public:
|
||
|
|
||
|
NetDb ();
|
||
|
~NetDb ();
|
||
|
|
||
|
void Start ();
|
||
|
void Stop ();
|
||
|
|
||
|
void AddRouterInfo (const uint8_t * buf, int len);
|
||
|
void AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len);
|
||
|
void AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, std::shared_ptr<i2p::tunnel::InboundTunnel> from);
|
||
|
std::shared_ptr<RouterInfo> FindRouter (const IdentHash& ident) const;
|
||
|
std::shared_ptr<LeaseSet> FindLeaseSet (const IdentHash& destination) const;
|
||
|
|
||
|
void RequestDestination (const IdentHash& destination, RequestedDestination::RequestComplete requestComplete = nullptr);
|
||
|
|
||
|
void HandleDatabaseStoreMsg (std::shared_ptr<const I2NPMessage> msg);
|
||
|
void HandleDatabaseSearchReplyMsg (std::shared_ptr<const I2NPMessage> msg);
|
||
|
void HandleDatabaseLookupMsg (std::shared_ptr<const I2NPMessage> msg);
|
||
|
|
||
|
std::shared_ptr<const RouterInfo> GetRandomRouter () const;
|
||
|
std::shared_ptr<const RouterInfo> GetRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const;
|
||
|
std::shared_ptr<const RouterInfo> GetHighBandwidthRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const;
|
||
|
std::shared_ptr<const RouterInfo> GetRandomPeerTestRouter () const;
|
||
|
std::shared_ptr<const RouterInfo> GetRandomIntroducer () const;
|
||
|
std::shared_ptr<const RouterInfo> GetClosestFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const;
|
||
|
std::vector<IdentHash> GetClosestFloodfills (const IdentHash& destination, size_t num,
|
||
|
std::set<IdentHash>& excluded) const;
|
||
|
std::shared_ptr<const RouterInfo> GetClosestNonFloodfill (const IdentHash& destination, const std::set<IdentHash>& excluded) const;
|
||
|
void SetUnreachable (const IdentHash& ident, bool unreachable);
|
||
|
|
||
|
void PostI2NPMsg (std::shared_ptr<const I2NPMessage> msg);
|
||
|
|
||
|
void Reseed ();
|
||
|
|
||
|
// for web interface
|
||
|
int GetNumRouters () const { return m_RouterInfos.size (); };
|
||
|
int GetNumFloodfills () const { return m_Floodfills.size (); };
|
||
|
int GetNumLeaseSets () const { return m_LeaseSets.size (); };
|
||
|
|
||
|
private:
|
||
|
|
||
|
bool CreateNetDb(boost::filesystem::path directory);
|
||
|
void Load ();
|
||
|
void SaveUpdated ();
|
||
|
void Run (); // exploratory thread
|
||
|
void Explore (int numDestinations);
|
||
|
void Publish ();
|
||
|
void ManageLeaseSets ();
|
||
|
void ManageRequests ();
|
||
|
|
||
|
template<typename Filter>
|
||
|
std::shared_ptr<const RouterInfo> GetRandomRouter (Filter filter) const;
|
||
|
|
||
|
private:
|
||
|
|
||
|
std::map<IdentHash, std::shared_ptr<LeaseSet> > m_LeaseSets;
|
||
|
mutable std::mutex m_RouterInfosMutex;
|
||
|
std::map<IdentHash, std::shared_ptr<RouterInfo> > m_RouterInfos;
|
||
|
mutable std::mutex m_FloodfillsMutex;
|
||
|
std::list<std::shared_ptr<RouterInfo> > m_Floodfills;
|
||
|
|
||
|
bool m_IsRunning;
|
||
|
std::thread * m_Thread;
|
||
|
i2p::util::Queue<std::shared_ptr<const I2NPMessage> > m_Queue; // of I2NPDatabaseStoreMsg
|
||
|
|
||
|
Reseeder * m_Reseeder;
|
||
|
|
||
|
friend class NetDbRequests;
|
||
|
NetDbRequests m_Requests;
|
||
|
|
||
|
static const char m_NetDbPath[];
|
||
|
};
|
||
|
|
||
|
extern NetDb netdb;
|
||
11 years ago
|
}
|
||
|
}
|
||
|
|
||
|
#endif
|