Browse Source

implement Update for LeaseSet2

pull/1292/head
orignal 6 years ago
parent
commit
6643258618
  1. 28
      libi2pd/LeaseSet.cpp
  2. 2
      libi2pd/LeaseSet.h

28
libi2pd/LeaseSet.cpp

@ -262,16 +262,23 @@ namespace data @@ -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 @@ -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>

2
libi2pd/LeaseSet.h

@ -135,7 +135,7 @@ namespace data @@ -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…
Cancel
Save