mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-17 21:26:04 +00:00
Merge branch 'openssl' of https://github.com/PurpleI2P/i2pd into openssl
This commit is contained in:
commit
34b7e8815a
49
NetDb.cpp
49
NetDb.cpp
@ -304,7 +304,7 @@ namespace data
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LogPrint(eLogWarning, "NetDb: Can't load RI from ", path, ", delete");
|
LogPrint(eLogWarning, "NetDb: RI from ", path, " is invalid. Delete");
|
||||||
i2p::fs::Remove(path);
|
i2p::fs::Remove(path);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -335,7 +335,8 @@ namespace data
|
|||||||
{
|
{
|
||||||
std::string ident = it.second->GetIdentHashBase64();
|
std::string ident = it.second->GetIdentHashBase64();
|
||||||
std::string path = m_Storage.Path(ident);
|
std::string path = m_Storage.Path(ident);
|
||||||
if (it.second->IsUpdated ()) {
|
if (it.second->IsUpdated ())
|
||||||
|
{
|
||||||
it.second->SaveToFile (path);
|
it.second->SaveToFile (path);
|
||||||
it.second->SetUpdated (false);
|
it.second->SetUpdated (false);
|
||||||
it.second->SetUnreachable (false);
|
it.second->SetUnreachable (false);
|
||||||
@ -344,16 +345,22 @@ namespace data
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// find & mark unreachable routers
|
// find & mark unreachable routers
|
||||||
if (it.second->UsesIntroducer () && ts > it.second->GetTimestamp () + 3600*1000LL) {
|
if (it.second->UsesIntroducer () && ts > it.second->GetTimestamp () + 3600*1000LL)
|
||||||
|
{
|
||||||
// RouterInfo expires after 1 hour if uses introducer
|
// RouterInfo expires after 1 hour if uses introducer
|
||||||
it.second->SetUnreachable (true);
|
it.second->SetUnreachable (true);
|
||||||
} else if (total > 75 && ts > (i2p::context.GetStartupTime () + 600)*1000LL) {
|
}
|
||||||
|
else if (total > 75 && ts > (i2p::context.GetStartupTime () + 600)*1000LL)
|
||||||
|
{
|
||||||
// routers don't expire if less than 25 or uptime is less than 10 minutes
|
// routers don't expire if less than 25 or uptime is less than 10 minutes
|
||||||
if (i2p::context.IsFloodfill ()) {
|
if (i2p::context.IsFloodfill ())
|
||||||
if (ts > it.second->GetTimestamp () + 3600*1000LL) { // 1 hour
|
{
|
||||||
|
if (ts > it.second->GetTimestamp () + 3600*1000LL)
|
||||||
|
{ // 1 hour
|
||||||
it.second->SetUnreachable (true);
|
it.second->SetUnreachable (true);
|
||||||
total--;
|
total--;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (total > 2500)
|
else if (total > 2500)
|
||||||
{
|
{
|
||||||
if (ts > it.second->GetTimestamp () + 12*3600*1000LL) // 12 hours
|
if (ts > it.second->GetTimestamp () + 12*3600*1000LL) // 12 hours
|
||||||
@ -370,36 +377,38 @@ namespace data
|
|||||||
total--;
|
total--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (total > 120) {
|
else if (total > 120)
|
||||||
if (ts > it.second->GetTimestamp () + 72*3600*1000LL) { // 72 hours
|
{
|
||||||
|
if (ts > it.second->GetTimestamp () + 72*3600*1000LL)
|
||||||
|
{
|
||||||
|
// 72 hours
|
||||||
it.second->SetUnreachable (true);
|
it.second->SetUnreachable (true);
|
||||||
total--;
|
total--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (it.second->IsUnreachable ()) {
|
if (it.second->IsUnreachable ())
|
||||||
|
{
|
||||||
total--;
|
total--;
|
||||||
// delete RI file
|
// delete RI file
|
||||||
m_Storage.Remove(ident);
|
m_Storage.Remove(ident);
|
||||||
deletedCount++;
|
deletedCount++;
|
||||||
// delete from floodfills list
|
|
||||||
if (it.second->IsFloodfill ()) {
|
|
||||||
std::unique_lock<std::mutex> l(m_FloodfillsMutex);
|
|
||||||
m_Floodfills.remove (it.second);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} // m_RouterInfos iteration
|
} // m_RouterInfos iteration
|
||||||
|
|
||||||
if (updatedCount > 0)
|
if (updatedCount > 0)
|
||||||
LogPrint (eLogInfo, "NetDb: saved ", updatedCount, " new/updated routers");
|
LogPrint (eLogInfo, "NetDb: saved ", updatedCount, " new/updated routers");
|
||||||
if (deletedCount > 0)
|
if (deletedCount > 0)
|
||||||
{
|
{
|
||||||
LogPrint (eLogInfo, "NetDb: deleting ", deletedCount, " unreachable routers");
|
LogPrint (eLogInfo, "NetDb: deleting ", deletedCount, " unreachable routers");
|
||||||
// clean up RouterInfos table
|
// clean up RouterInfos table
|
||||||
|
{
|
||||||
std::unique_lock<std::mutex> l(m_RouterInfosMutex);
|
std::unique_lock<std::mutex> l(m_RouterInfosMutex);
|
||||||
for (auto it = m_RouterInfos.begin (); it != m_RouterInfos.end ();)
|
for (auto it = m_RouterInfos.begin (); it != m_RouterInfos.end ();)
|
||||||
{
|
{
|
||||||
if (it->second->IsUnreachable ()) {
|
if (it->second->IsUnreachable ())
|
||||||
|
{
|
||||||
it->second->SaveProfile ();
|
it->second->SaveProfile ();
|
||||||
it = m_RouterInfos.erase (it);
|
it = m_RouterInfos.erase (it);
|
||||||
continue;
|
continue;
|
||||||
@ -407,6 +416,16 @@ namespace data
|
|||||||
it++;
|
it++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// clean up expired floodfiils
|
||||||
|
{
|
||||||
|
std::unique_lock<std::mutex> l(m_FloodfillsMutex);
|
||||||
|
for (auto it = m_Floodfills.begin (); it != m_Floodfills.end ();)
|
||||||
|
if ((*it)->IsUnreachable ())
|
||||||
|
it = m_Floodfills.erase (it);
|
||||||
|
else
|
||||||
|
it++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetDb::RequestDestination (const IdentHash& destination, RequestedDestination::RequestComplete requestComplete)
|
void NetDb::RequestDestination (const IdentHash& destination, RequestedDestination::RequestComplete requestComplete)
|
||||||
|
Loading…
Reference in New Issue
Block a user