| 356 | } |
| 357 | |
| 358 | bool NetDb::AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len) |
| 359 | { |
| 360 | std::lock_guard<std::mutex> lock(m_LeaseSetsMutex); |
| 361 | bool updated = false; |
| 362 | auto it = m_LeaseSets.find(ident); |
| 363 | if (it != m_LeaseSets.end () && it->second->GetStoreType () == i2p::data::NETDB_STORE_TYPE_LEASESET) |
| 364 | { |
| 365 | // we update only is existing LeaseSet is not LeaseSet2 |
| 366 | uint64_t expires; |
| 367 | if(LeaseSetBufferValidate(buf, len, expires)) |
| 368 | { |
| 369 | if(it->second->GetExpirationTime() < expires) |
| 370 | { |
| 371 | it->second->Update (buf, len, nullptr, false); // signature is verified already |
| 372 | if (CheckLogLevel (eLogInfo)) |
| 373 | LogPrint (eLogInfo, "NetDb: LeaseSet updated: ", ident.ToBase32()); |
| 374 | updated = true; |
| 375 | } |
| 376 | else if (CheckLogLevel (eLogDebug)) |
| 377 | LogPrint(eLogDebug, "NetDb: LeaseSet is older: ", ident.ToBase32()); |
| 378 | } |
| 379 | else |
| 380 | LogPrint(eLogError, "NetDb: LeaseSet is invalid: ", ident.ToBase32()); |
| 381 | } |
| 382 | else |
| 383 | { |
| 384 | auto leaseSet = std::make_shared<LeaseSet> (buf, len, false); // we don't need leases in netdb |
| 385 | if (leaseSet->IsValid ()) |
| 386 | { |
| 387 | if (CheckLogLevel (eLogInfo)) |
| 388 | LogPrint (eLogInfo, "NetDb: LeaseSet added: ", ident.ToBase32()); |
| 389 | m_LeaseSets[ident] = leaseSet; |
| 390 | updated = true; |
| 391 | } |
| 392 | else |
| 393 | LogPrint (eLogError, "NetDb: New LeaseSet validation failed: ", ident.ToBase32()); |
| 394 | } |
| 395 | return updated; |
| 396 | } |
| 397 | |
| 398 | bool NetDb::AddLeaseSet2 (const IdentHash& ident, const uint8_t * buf, int len, uint8_t storeType) |
| 399 | { |
nothing calls this directly
no test coverage detected