Browse Source

store floodfills separately

pull/48/head
orignal 11 years ago
parent
commit
fb9d351600
  1. 34
      NetDb.cpp
  2. 3
      NetDb.h

34
NetDb.cpp

@ -55,7 +55,7 @@ namespace data @@ -55,7 +55,7 @@ namespace data
NetDb::~NetDb ()
{
Stop ();
Stop ();
for (auto l:m_LeaseSets)
delete l.second;
for (auto r:m_RouterInfos)
@ -160,6 +160,8 @@ namespace data @@ -160,6 +160,8 @@ namespace data
{
LogPrint ("New RouterInfo added");
m_RouterInfos[r->GetIdentHash ()] = r;
if (r->IsFloodfill ())
m_Floodfills.push_back (r);
}
}
@ -237,6 +239,7 @@ namespace data @@ -237,6 +239,7 @@ namespace data
for (auto r: m_RouterInfos)
delete r.second;
m_RouterInfos.clear ();
m_Floodfills.clear ();
// load routers now
int numRouters = 0;
@ -253,11 +256,14 @@ namespace data @@ -253,11 +256,14 @@ namespace data
RouterInfo * r = new RouterInfo(it1->path().c_str());
#endif
m_RouterInfos[r->GetIdentHash ()] = r;
if (r->IsFloodfill ())
m_Floodfills.push_back (r);
numRouters++;
}
}
}
LogPrint (numRouters, " routers loaded");
LogPrint (m_Floodfills.size (), " floodfills loaded");
}
void NetDb::SaveUpdated (const char * directory)
@ -594,22 +600,6 @@ namespace data @@ -594,22 +600,6 @@ namespace data
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
{
@ -633,7 +623,7 @@ namespace data @@ -633,7 +623,7 @@ namespace data
// we couldn't find anything, try second pass
ind = 0;
}
return nullptr; // seem we have too few routers
return nullptr; // seems we have too few routers
}
void NetDb::PostI2NPMsg (I2NPMessage * msg)
@ -648,15 +638,15 @@ namespace data @@ -648,15 +638,15 @@ namespace data
XORMetric minMetric;
RoutingKey destKey = CreateRoutingKey (destination);
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)
{
minMetric = m;
r = it.second;
r = it;
}
}
}

3
NetDb.h

@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
#include <inttypes.h>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <thread>
#include <boost/filesystem.hpp>
@ -73,7 +74,6 @@ namespace data @@ -73,7 +74,6 @@ namespace data
void HandleDatabaseStoreMsg (uint8_t * buf, size_t len);
void HandleDatabaseSearchReplyMsg (I2NPMessage * msg);
const RouterInfo * GetRandomNTCPRouter (bool floodfillOnly = false) const;
const RouterInfo * GetRandomRouter (const RouterInfo * compatibleWith = nullptr, bool floodfillOnly = false) const;
void PostI2NPMsg (I2NPMessage * msg);
@ -98,6 +98,7 @@ namespace data @@ -98,6 +98,7 @@ namespace data
std::map<IdentHash, LeaseSet *> m_LeaseSets;
std::map<IdentHash, RouterInfo *> m_RouterInfos;
std::vector<RouterInfo *> m_Floodfills;
std::map<IdentHash, RequestedDestination *> m_RequestedDestinations;
std::set<IdentHash> m_Subscriptions;

Loading…
Cancel
Save