mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 04:04:16 +00:00
store floodfills separately
This commit is contained in:
parent
d32f345aee
commit
fb9d351600
34
NetDb.cpp
34
NetDb.cpp
@ -55,7 +55,7 @@ namespace data
|
|||||||
|
|
||||||
NetDb::~NetDb ()
|
NetDb::~NetDb ()
|
||||||
{
|
{
|
||||||
Stop ();
|
Stop ();
|
||||||
for (auto l:m_LeaseSets)
|
for (auto l:m_LeaseSets)
|
||||||
delete l.second;
|
delete l.second;
|
||||||
for (auto r:m_RouterInfos)
|
for (auto r:m_RouterInfos)
|
||||||
@ -160,6 +160,8 @@ namespace data
|
|||||||
{
|
{
|
||||||
LogPrint ("New RouterInfo added");
|
LogPrint ("New RouterInfo added");
|
||||||
m_RouterInfos[r->GetIdentHash ()] = r;
|
m_RouterInfos[r->GetIdentHash ()] = r;
|
||||||
|
if (r->IsFloodfill ())
|
||||||
|
m_Floodfills.push_back (r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,6 +239,7 @@ namespace data
|
|||||||
for (auto r: m_RouterInfos)
|
for (auto r: m_RouterInfos)
|
||||||
delete r.second;
|
delete r.second;
|
||||||
m_RouterInfos.clear ();
|
m_RouterInfos.clear ();
|
||||||
|
m_Floodfills.clear ();
|
||||||
|
|
||||||
// load routers now
|
// load routers now
|
||||||
int numRouters = 0;
|
int numRouters = 0;
|
||||||
@ -253,11 +256,14 @@ namespace data
|
|||||||
RouterInfo * r = new RouterInfo(it1->path().c_str());
|
RouterInfo * r = new RouterInfo(it1->path().c_str());
|
||||||
#endif
|
#endif
|
||||||
m_RouterInfos[r->GetIdentHash ()] = r;
|
m_RouterInfos[r->GetIdentHash ()] = r;
|
||||||
|
if (r->IsFloodfill ())
|
||||||
|
m_Floodfills.push_back (r);
|
||||||
numRouters++;
|
numRouters++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LogPrint (numRouters, " routers loaded");
|
LogPrint (numRouters, " routers loaded");
|
||||||
|
LogPrint (m_Floodfills.size (), " floodfills loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetDb::SaveUpdated (const char * directory)
|
void NetDb::SaveUpdated (const char * directory)
|
||||||
@ -594,22 +600,6 @@ namespace data
|
|||||||
delete dest;
|
delete dest;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const RouterInfo * NetDb::GetRandomNTCPRouter (bool floodfillOnly) const
|
|
||||||
{
|
|
||||||
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
|
|
||||||
uint32_t ind = rnd.GenerateWord32 (0, m_RouterInfos.size () - 1), i = 0;
|
|
||||||
RouterInfo * last = nullptr;
|
|
||||||
for (auto it: m_RouterInfos)
|
|
||||||
{
|
|
||||||
if (it.second->IsNTCP () && !it.second->IsUnreachable () &&
|
|
||||||
(!floodfillOnly || it.second->IsFloodfill ()))
|
|
||||||
last = it.second;
|
|
||||||
if (i >= ind) break;
|
|
||||||
else i++;
|
|
||||||
}
|
|
||||||
return last;
|
|
||||||
}
|
|
||||||
|
|
||||||
const RouterInfo * NetDb::GetRandomRouter (const RouterInfo * compatibleWith, bool floodfillOnly) const
|
const RouterInfo * NetDb::GetRandomRouter (const RouterInfo * compatibleWith, bool floodfillOnly) const
|
||||||
{
|
{
|
||||||
@ -633,7 +623,7 @@ namespace data
|
|||||||
// we couldn't find anything, try second pass
|
// we couldn't find anything, try second pass
|
||||||
ind = 0;
|
ind = 0;
|
||||||
}
|
}
|
||||||
return nullptr; // seem we have too few routers
|
return nullptr; // seems we have too few routers
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetDb::PostI2NPMsg (I2NPMessage * msg)
|
void NetDb::PostI2NPMsg (I2NPMessage * msg)
|
||||||
@ -648,15 +638,15 @@ namespace data
|
|||||||
XORMetric minMetric;
|
XORMetric minMetric;
|
||||||
RoutingKey destKey = CreateRoutingKey (destination);
|
RoutingKey destKey = CreateRoutingKey (destination);
|
||||||
minMetric.SetMax ();
|
minMetric.SetMax ();
|
||||||
for (auto it: m_RouterInfos)
|
for (auto it: m_Floodfills)
|
||||||
{
|
{
|
||||||
if (it.second->IsFloodfill () &&! it.second->IsUnreachable () && !excluded.count (it.first))
|
if (!it->IsUnreachable () && !excluded.count (it->GetIdentHash ()))
|
||||||
{
|
{
|
||||||
XORMetric m = destKey ^ it.second->GetRoutingKey ();
|
XORMetric m = destKey ^ it->GetRoutingKey ();
|
||||||
if (m < minMetric)
|
if (m < minMetric)
|
||||||
{
|
{
|
||||||
minMetric = m;
|
minMetric = m;
|
||||||
r = it.second;
|
r = it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
3
NetDb.h
3
NetDb.h
@ -4,6 +4,7 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
@ -73,7 +74,6 @@ namespace data
|
|||||||
void HandleDatabaseStoreMsg (uint8_t * buf, size_t len);
|
void HandleDatabaseStoreMsg (uint8_t * buf, size_t len);
|
||||||
void HandleDatabaseSearchReplyMsg (I2NPMessage * msg);
|
void HandleDatabaseSearchReplyMsg (I2NPMessage * msg);
|
||||||
|
|
||||||
const RouterInfo * GetRandomNTCPRouter (bool floodfillOnly = false) const;
|
|
||||||
const RouterInfo * GetRandomRouter (const RouterInfo * compatibleWith = nullptr, bool floodfillOnly = false) const;
|
const RouterInfo * GetRandomRouter (const RouterInfo * compatibleWith = nullptr, bool floodfillOnly = false) const;
|
||||||
|
|
||||||
void PostI2NPMsg (I2NPMessage * msg);
|
void PostI2NPMsg (I2NPMessage * msg);
|
||||||
@ -98,6 +98,7 @@ namespace data
|
|||||||
|
|
||||||
std::map<IdentHash, LeaseSet *> m_LeaseSets;
|
std::map<IdentHash, LeaseSet *> m_LeaseSets;
|
||||||
std::map<IdentHash, RouterInfo *> m_RouterInfos;
|
std::map<IdentHash, RouterInfo *> m_RouterInfos;
|
||||||
|
std::vector<RouterInfo *> m_Floodfills;
|
||||||
std::map<IdentHash, RequestedDestination *> m_RequestedDestinations;
|
std::map<IdentHash, RequestedDestination *> m_RequestedDestinations;
|
||||||
std::set<IdentHash> m_Subscriptions;
|
std::set<IdentHash> m_Subscriptions;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user