|
|
|
@ -250,16 +250,14 @@ namespace data
@@ -250,16 +250,14 @@ namespace data
|
|
|
|
|
return r; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool NetDb::AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, |
|
|
|
|
std::shared_ptr<i2p::tunnel::InboundTunnel> from) |
|
|
|
|
bool NetDb::AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len) |
|
|
|
|
{ |
|
|
|
|
std::unique_lock<std::mutex> lock(m_LeaseSetsMutex); |
|
|
|
|
bool updated = false; |
|
|
|
|
if (!from) // unsolicited LS must be received directly
|
|
|
|
|
{ |
|
|
|
|
auto it = m_LeaseSets.find(ident); |
|
|
|
|
if (it != m_LeaseSets.end ()) |
|
|
|
|
if (it != m_LeaseSets.end () && it->second->GetStoreType () == i2p::data::NETDB_STORE_TYPE_LEASESET) |
|
|
|
|
{ |
|
|
|
|
// we update only is existing LeaseSet is not LeaseSet2
|
|
|
|
|
uint64_t expires; |
|
|
|
|
if(LeaseSetBufferValidate(buf, len, expires)) |
|
|
|
|
{ |
|
|
|
@ -287,22 +285,17 @@ namespace data
@@ -287,22 +285,17 @@ namespace data
|
|
|
|
|
else |
|
|
|
|
LogPrint (eLogError, "NetDb: new LeaseSet validation failed: ", ident.ToBase32()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return updated; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool NetDb::AddLeaseSet2 (const IdentHash& ident, const uint8_t * buf, int len, uint8_t storeType) |
|
|
|
|
{ |
|
|
|
|
std::unique_lock<std::mutex> lock(m_LeaseSetsMutex); |
|
|
|
|
auto it = m_LeaseSets.find(ident); |
|
|
|
|
if (it == m_LeaseSets.end ()) |
|
|
|
|
{ |
|
|
|
|
// always new LS2 for now. TODO: implement update
|
|
|
|
|
auto leaseSet = std::make_shared<LeaseSet2> (storeType, buf, len, false); // we don't need leases in netdb
|
|
|
|
|
m_LeaseSets[ident] = leaseSet; |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
std::shared_ptr<RouterInfo> NetDb::FindRouter (const IdentHash& ident) const |
|
|
|
|
{ |
|
|
|
@ -660,11 +653,13 @@ namespace data
@@ -660,11 +653,13 @@ namespace data
|
|
|
|
|
bool updated = false; |
|
|
|
|
uint8_t storeType = buf[DATABASE_STORE_TYPE_OFFSET]; |
|
|
|
|
if (storeType) // LeaseSet or LeaseSet2
|
|
|
|
|
{ |
|
|
|
|
if (!m->from) // unsolicited LS must be received directly
|
|
|
|
|
{ |
|
|
|
|
if (storeType == NETDB_STORE_TYPE_LEASESET) // 1
|
|
|
|
|
{ |
|
|
|
|
LogPrint (eLogDebug, "NetDb: store request: LeaseSet for ", ident.ToBase32()); |
|
|
|
|
updated = AddLeaseSet (ident, buf + offset, len - offset, m->from); |
|
|
|
|
updated = AddLeaseSet (ident, buf + offset, len - offset); |
|
|
|
|
} |
|
|
|
|
else // all others are considered as LeaseSet2
|
|
|
|
|
{ |
|
|
|
@ -672,6 +667,7 @@ namespace data
@@ -672,6 +667,7 @@ namespace data
|
|
|
|
|
updated = AddLeaseSet2 (ident, buf + offset, len - offset, storeType); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else // RouterInfo
|
|
|
|
|
{ |
|
|
|
|
LogPrint (eLogDebug, "NetDb: store request: RouterInfo"); |
|
|
|
|