mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2024-11-16 00:12:43 +00:00
implement Update for LeaseSet2
This commit is contained in:
parent
bc3f02cb6b
commit
6643258618
@ -262,16 +262,23 @@ namespace data
|
||||
|
||||
void LeaseSet2::Update (const uint8_t * buf, size_t len, bool verifySignature)
|
||||
{
|
||||
// shouldn't be called for now. Must be called from NetDb::AddLeaseSet later
|
||||
SetBuffer (buf, len);
|
||||
// TODO:verify signature if requested
|
||||
if (storeType != NETDB_STORE_TYPE_ENCRYPTED_LEASESET2)
|
||||
ReadFromBuffer (buf, len, false, verifySignature);
|
||||
// TODO: implement encrypted
|
||||
}
|
||||
|
||||
void LeaseSet2::ReadFromBuffer (const uint8_t * buf, size_t len)
|
||||
void LeaseSet2::ReadFromBuffer (const uint8_t * buf, size_t len, bool readIdentity, bool verifySignature)
|
||||
{
|
||||
// standard LS2 header
|
||||
auto identity = std::make_shared<IdentityEx>(buf, len);
|
||||
SetIdentity (identity);
|
||||
std::shared_ptr<const IdentityEx> identity;
|
||||
if (readIdentity)
|
||||
{
|
||||
identity = std::make_shared<IdentityEx>(buf, len);
|
||||
SetIdentity (identity);
|
||||
}
|
||||
else
|
||||
identity = GetIdentity ();
|
||||
size_t offset = identity->GetFullLen ();
|
||||
if (offset + 8 >= len) return;
|
||||
uint32_t timestamp = bufbe32toh (buf + offset); offset += 4; // published timestamp (seconds)
|
||||
@ -315,10 +322,13 @@ namespace data
|
||||
}
|
||||
if (!s) return;
|
||||
offset += s;
|
||||
// verify signature
|
||||
bool verified = transientVerifier ? VerifySignature (transientVerifier, buf, len, offset) :
|
||||
VerifySignature (identity, buf, len, offset);
|
||||
SetIsValid (verified);
|
||||
if (verifySignature || transientVerifier)
|
||||
{
|
||||
// verify signature
|
||||
bool verified = transientVerifier ? VerifySignature (transientVerifier, buf, len, offset) :
|
||||
VerifySignature (identity, buf, len, offset);
|
||||
SetIsValid (verified);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename Verifier>
|
||||
|
@ -135,7 +135,7 @@ namespace data
|
||||
|
||||
private:
|
||||
|
||||
void ReadFromBuffer (const uint8_t * buf, size_t len);
|
||||
void ReadFromBuffer (const uint8_t * buf, size_t len, bool readIdentity = true, bool verifySignature = true);
|
||||
void ReadFromBufferEncrypted (const uint8_t * buf, size_t len);
|
||||
size_t ReadStandardLS2TypeSpecificPart (const uint8_t * buf, size_t len);
|
||||
size_t ReadMetaLS2TypeSpecificPart (const uint8_t * buf, size_t len);
|
||||
|
Loading…
Reference in New Issue
Block a user