|
|
|
@ -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; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|