From 9504e695985decd018e9bd296d4a4031d16fcd42 Mon Sep 17 00:00:00 2001 From: orignal Date: Wed, 9 Jan 2019 14:51:47 -0500 Subject: [PATCH] LocalLeaseSet2 added --- libi2pd/I2NPProtocol.cpp | 2 +- libi2pd/LeaseSet.cpp | 30 +++++++++++++++++++++++++++--- libi2pd/LeaseSet.h | 21 +++++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/libi2pd/I2NPProtocol.cpp b/libi2pd/I2NPProtocol.cpp index c98c7a88..2fc1df3b 100644 --- a/libi2pd/I2NPProtocol.cpp +++ b/libi2pd/I2NPProtocol.cpp @@ -280,7 +280,7 @@ namespace i2p auto m = NewI2NPShortMessage (); uint8_t * payload = m->GetPayload (); 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); size_t size = DATABASE_STORE_HEADER_SIZE; if (replyToken && replyTunnel) diff --git a/libi2pd/LeaseSet.cpp b/libi2pd/LeaseSet.cpp index 41483469..280ee7d3 100644 --- a/libi2pd/LeaseSet.cpp +++ b/libi2pd/LeaseSet.cpp @@ -479,9 +479,17 @@ namespace data LocalLeaseSet::LocalLeaseSet (std::shared_ptr identity, const uint8_t * buf, size_t len): m_ExpirationTime (0), m_Identity (identity) { - m_BufferLen = len; - m_Buffer = new uint8_t[m_BufferLen]; - memcpy (m_Buffer, buf, len); + if (buf) + { + m_BufferLen = len; + m_Buffer = new uint8_t[m_BufferLen]; + memcpy (m_Buffer, buf, len); + } + else + { + m_Buffer = nullptr; + m_BufferLen = 0; + } } bool LocalLeaseSet::IsExpired () const @@ -490,6 +498,14 @@ namespace data 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) { IdentityEx ident(ptr, sz); @@ -523,5 +539,13 @@ namespace data } return ident.Verify(ptr, leases - ptr, leases); } + + LocalLeaseSet2::LocalLeaseSet2 (uint8_t storeType, std::shared_ptr identity, + uint16_t keyType, uint16_t keyLen, const uint8_t * encryptionPublicKey, + std::vector > tunnels): + LocalLeaseSet (identity, nullptr, 0), m_StoreType (storeType) + { + // TODO: + } } } diff --git a/libi2pd/LeaseSet.h b/libi2pd/LeaseSet.h index c1b1df9a..01c1f248 100644 --- a/libi2pd/LeaseSet.h +++ b/libi2pd/LeaseSet.h @@ -168,6 +168,12 @@ namespace data bool operator== (const LeaseSet& other) const { 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: @@ -176,6 +182,21 @@ namespace data uint8_t * m_Buffer, * m_Leases; size_t m_BufferLen; }; + + class LocalLeaseSet2: public LocalLeaseSet + { + public: + + LocalLeaseSet2 (uint8_t storeType, std::shared_ptr identity, + uint16_t keyType, uint16_t keyLen, const uint8_t * encryptionPublicKey, + std::vector > tunnels); + + uint8_t GetStoreType () const { return m_StoreType; }; + + private: + + uint8_t m_StoreType; + }; } }