mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-03-21 16:49:10 +01:00
LocalLeaseSet2 added
This commit is contained in:
parent
5398b651f7
commit
9504e69598
3 changed files with 49 additions and 4 deletions
|
@ -280,7 +280,7 @@ namespace i2p
|
||||||
auto m = NewI2NPShortMessage ();
|
auto m = NewI2NPShortMessage ();
|
||||||
uint8_t * payload = m->GetPayload ();
|
uint8_t * payload = m->GetPayload ();
|
||||||
memcpy (payload + DATABASE_STORE_KEY_OFFSET, leaseSet->GetIdentHash (), 32);
|
memcpy (payload + DATABASE_STORE_KEY_OFFSET, leaseSet->GetIdentHash (), 32);
|
||||||
payload[DATABASE_STORE_TYPE_OFFSET] = 1; // LeaseSet
|
payload[DATABASE_STORE_TYPE_OFFSET] = leaseSet->GetStoreType (); // LeaseSet or LeaseSet2
|
||||||
htobe32buf (payload + DATABASE_STORE_REPLY_TOKEN_OFFSET, replyToken);
|
htobe32buf (payload + DATABASE_STORE_REPLY_TOKEN_OFFSET, replyToken);
|
||||||
size_t size = DATABASE_STORE_HEADER_SIZE;
|
size_t size = DATABASE_STORE_HEADER_SIZE;
|
||||||
if (replyToken && replyTunnel)
|
if (replyToken && replyTunnel)
|
||||||
|
|
|
@ -478,11 +478,19 @@ namespace data
|
||||||
|
|
||||||
LocalLeaseSet::LocalLeaseSet (std::shared_ptr<const IdentityEx> identity, const uint8_t * buf, size_t len):
|
LocalLeaseSet::LocalLeaseSet (std::shared_ptr<const IdentityEx> identity, const uint8_t * buf, size_t len):
|
||||||
m_ExpirationTime (0), m_Identity (identity)
|
m_ExpirationTime (0), m_Identity (identity)
|
||||||
|
{
|
||||||
|
if (buf)
|
||||||
{
|
{
|
||||||
m_BufferLen = len;
|
m_BufferLen = len;
|
||||||
m_Buffer = new uint8_t[m_BufferLen];
|
m_Buffer = new uint8_t[m_BufferLen];
|
||||||
memcpy (m_Buffer, buf, len);
|
memcpy (m_Buffer, buf, len);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_Buffer = nullptr;
|
||||||
|
m_BufferLen = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool LocalLeaseSet::IsExpired () const
|
bool LocalLeaseSet::IsExpired () const
|
||||||
{
|
{
|
||||||
|
@ -490,6 +498,14 @@ namespace data
|
||||||
return ts > m_ExpirationTime;
|
return ts > m_ExpirationTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LocalLeaseSet::SetBuffer (const uint8_t * buf, size_t len)
|
||||||
|
{
|
||||||
|
if (m_Buffer) delete[] m_Buffer;
|
||||||
|
m_Buffer = new uint8_t[len];
|
||||||
|
m_BufferLen = len;
|
||||||
|
memcpy (m_Buffer, buf, len);
|
||||||
|
}
|
||||||
|
|
||||||
bool LeaseSetBufferValidate(const uint8_t * ptr, size_t sz, uint64_t & expires)
|
bool LeaseSetBufferValidate(const uint8_t * ptr, size_t sz, uint64_t & expires)
|
||||||
{
|
{
|
||||||
IdentityEx ident(ptr, sz);
|
IdentityEx ident(ptr, sz);
|
||||||
|
@ -523,5 +539,13 @@ namespace data
|
||||||
}
|
}
|
||||||
return ident.Verify(ptr, leases - ptr, leases);
|
return ident.Verify(ptr, leases - ptr, leases);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LocalLeaseSet2::LocalLeaseSet2 (uint8_t storeType, std::shared_ptr<const IdentityEx> identity,
|
||||||
|
uint16_t keyType, uint16_t keyLen, const uint8_t * encryptionPublicKey,
|
||||||
|
std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels):
|
||||||
|
LocalLeaseSet (identity, nullptr, 0), m_StoreType (storeType)
|
||||||
|
{
|
||||||
|
// TODO:
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,6 +168,12 @@ namespace data
|
||||||
bool operator== (const LeaseSet& other) const
|
bool operator== (const LeaseSet& other) const
|
||||||
{ return m_BufferLen == other.GetBufferLen () && !memcmp (other.GetBuffer (), other.GetBuffer (), m_BufferLen); };
|
{ return m_BufferLen == other.GetBufferLen () && !memcmp (other.GetBuffer (), other.GetBuffer (), m_BufferLen); };
|
||||||
|
|
||||||
|
virtual uint8_t GetStoreType () const { return NETDB_STORE_TYPE_LEASESET; };
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// called from LocalLeaseSet2
|
||||||
|
void SetBuffer (const uint8_t * buf, size_t len);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -176,6 +182,21 @@ namespace data
|
||||||
uint8_t * m_Buffer, * m_Leases;
|
uint8_t * m_Buffer, * m_Leases;
|
||||||
size_t m_BufferLen;
|
size_t m_BufferLen;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class LocalLeaseSet2: public LocalLeaseSet
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
LocalLeaseSet2 (uint8_t storeType, std::shared_ptr<const IdentityEx> identity,
|
||||||
|
uint16_t keyType, uint16_t keyLen, const uint8_t * encryptionPublicKey,
|
||||||
|
std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels);
|
||||||
|
|
||||||
|
uint8_t GetStoreType () const { return m_StoreType; };
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
uint8_t m_StoreType;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue