|
|
@ -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) |
|
|
@ -595,23 +601,7 @@ namespace data |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const RouterInfo * NetDb::GetRandomNTCPRouter (bool floodfillOnly) const |
|
|
|
const RouterInfo * NetDb::GetRandomRouter (const RouterInfo * compatibleWith, uint8_t caps) 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 |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); |
|
|
|
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); |
|
|
|
uint32_t ind = rnd.GenerateWord32 (0, m_RouterInfos.size () - 1); |
|
|
|
uint32_t ind = rnd.GenerateWord32 (0, m_RouterInfos.size () - 1); |
|
|
@ -624,7 +614,7 @@ namespace data |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!it.second->IsUnreachable () && |
|
|
|
if (!it.second->IsUnreachable () && |
|
|
|
(!compatibleWith || it.second->IsCompatible (*compatibleWith)) && |
|
|
|
(!compatibleWith || it.second->IsCompatible (*compatibleWith)) && |
|
|
|
(!floodfillOnly || it.second->IsFloodfill ())) |
|
|
|
(!caps || (it.second->GetCaps () & caps) == caps)) |
|
|
|
return it.second; |
|
|
|
return it.second; |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|