Browse Source

check log level before calculating base32 or base64 of ident

pull/2014/head
orignal 9 months ago
parent
commit
592d6ae4f4
  1. 12
      libi2pd/NetDb.cpp

12
libi2pd/NetDb.cpp

@ -262,9 +262,11 @@ namespace data
return nullptr; return nullptr;
} }
} }
if (CheckLogLevel (eLogInfo))
LogPrint (eLogInfo, "NetDb: RouterInfo updated: ", ident.ToBase64()); LogPrint (eLogInfo, "NetDb: RouterInfo updated: ", ident.ToBase64());
if (wasFloodfill != r->IsFloodfill ()) // if floodfill status updated if (wasFloodfill != r->IsFloodfill ()) // if floodfill status updated
{ {
if (CheckLogLevel (eLogDebug))
LogPrint (eLogDebug, "NetDb: RouterInfo floodfill status updated: ", ident.ToBase64()); LogPrint (eLogDebug, "NetDb: RouterInfo floodfill status updated: ", ident.ToBase64());
std::lock_guard<std::mutex> l(m_FloodfillsMutex); std::lock_guard<std::mutex> l(m_FloodfillsMutex);
if (wasFloodfill) if (wasFloodfill)
@ -280,6 +282,7 @@ namespace data
} }
else else
{ {
if (CheckLogLevel (eLogDebug))
LogPrint (eLogDebug, "NetDb: RouterInfo is older: ", ident.ToBase64()); LogPrint (eLogDebug, "NetDb: RouterInfo is older: ", ident.ToBase64());
updated = false; updated = false;
} }
@ -297,6 +300,7 @@ namespace data
} }
if (inserted) if (inserted)
{ {
if (CheckLogLevel (eLogInfo))
LogPrint (eLogInfo, "NetDb: RouterInfo added: ", ident.ToBase64()); LogPrint (eLogInfo, "NetDb: RouterInfo added: ", ident.ToBase64());
if (r->IsFloodfill () && r->IsEligibleFloodfill ()) if (r->IsFloodfill () && r->IsEligibleFloodfill ())
{ {
@ -338,10 +342,11 @@ namespace data
if(it->second->GetExpirationTime() < expires) if(it->second->GetExpirationTime() < expires)
{ {
it->second->Update (buf, len, false); // signature is verified already it->second->Update (buf, len, false); // signature is verified already
if (CheckLogLevel (eLogInfo))
LogPrint (eLogInfo, "NetDb: LeaseSet updated: ", ident.ToBase32()); LogPrint (eLogInfo, "NetDb: LeaseSet updated: ", ident.ToBase32());
updated = true; updated = true;
} }
else else if (CheckLogLevel (eLogDebug))
LogPrint(eLogDebug, "NetDb: LeaseSet is older: ", ident.ToBase32()); LogPrint(eLogDebug, "NetDb: LeaseSet is older: ", ident.ToBase32());
} }
else else
@ -352,6 +357,7 @@ namespace data
auto leaseSet = std::make_shared<LeaseSet> (buf, len, false); // we don't need leases in netdb auto leaseSet = std::make_shared<LeaseSet> (buf, len, false); // we don't need leases in netdb
if (leaseSet->IsValid ()) if (leaseSet->IsValid ())
{ {
if (CheckLogLevel (eLogInfo))
LogPrint (eLogInfo, "NetDb: LeaseSet added: ", ident.ToBase32()); LogPrint (eLogInfo, "NetDb: LeaseSet added: ", ident.ToBase32());
m_LeaseSets[ident] = leaseSet; m_LeaseSets[ident] = leaseSet;
updated = true; updated = true;
@ -376,6 +382,7 @@ namespace data
i2p::util::GetSecondsSinceEpoch () + NETDB_EXPIRATION_TIMEOUT_THRESHOLD > leaseSet->GetPublishedTimestamp ()) i2p::util::GetSecondsSinceEpoch () + NETDB_EXPIRATION_TIMEOUT_THRESHOLD > leaseSet->GetPublishedTimestamp ())
{ {
// TODO: implement actual update // TODO: implement actual update
if (CheckLogLevel (eLogInfo))
LogPrint (eLogInfo, "NetDb: LeaseSet2 updated: ", ident.ToBase32()); LogPrint (eLogInfo, "NetDb: LeaseSet2 updated: ", ident.ToBase32());
m_LeaseSets[ident] = leaseSet; m_LeaseSets[ident] = leaseSet;
return true; return true;
@ -863,11 +870,13 @@ namespace data
{ {
if (storeType == NETDB_STORE_TYPE_LEASESET) // 1 if (storeType == NETDB_STORE_TYPE_LEASESET) // 1
{ {
if (CheckLogLevel (eLogDebug))
LogPrint (eLogDebug, "NetDb: Store request: LeaseSet for ", ident.ToBase32()); LogPrint (eLogDebug, "NetDb: Store request: LeaseSet for ", ident.ToBase32());
updated = AddLeaseSet (ident, buf + offset, len - offset); updated = AddLeaseSet (ident, buf + offset, len - offset);
} }
else // all others are considered as LeaseSet2 else // all others are considered as LeaseSet2
{ {
if (CheckLogLevel (eLogDebug))
LogPrint (eLogDebug, "NetDb: Store request: LeaseSet2 of type ", int(storeType), " for ", ident.ToBase32()); LogPrint (eLogDebug, "NetDb: Store request: LeaseSet2 of type ", int(storeType), " for ", ident.ToBase32());
updated = AddLeaseSet2 (ident, buf + offset, len - offset, storeType); updated = AddLeaseSet2 (ident, buf + offset, len - offset, storeType);
} }
@ -875,6 +884,7 @@ namespace data
} }
else // RouterInfo else // RouterInfo
{ {
if (CheckLogLevel (eLogDebug))
LogPrint (eLogDebug, "NetDb: Store request: RouterInfo ", ident.ToBase64()); LogPrint (eLogDebug, "NetDb: Store request: RouterInfo ", ident.ToBase64());
size_t size = bufbe16toh (buf + offset); size_t size = bufbe16toh (buf + offset);
offset += 2; offset += 2;

Loading…
Cancel
Save