diff --git a/Destination.cpp b/Destination.cpp index ef0ee5da..2ebf0fbb 100644 --- a/Destination.cpp +++ b/Destination.cpp @@ -283,7 +283,7 @@ namespace stream m_Service->post (boost::bind (&StreamingDestination::HandleDeliveryStatusMessage, this, msg)); } - void StreamingDestination::HandleI2NPMessage (const uint8_t * buf, size_t len) + void StreamingDestination::HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from) { I2NPHeader * header = (I2NPHeader *)buf; switch (header->typeID) @@ -293,10 +293,10 @@ namespace stream break; case eI2NPDatabaseStore: HandleDatabaseStoreMessage (buf + sizeof (I2NPHeader), be16toh (header->size)); - i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf))); // TODO: remove + i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf), from)); // TODO: remove break; default: - i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf))); + i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf), from)); } } diff --git a/Destination.h b/Destination.h index 62dc527c..77e7d54c 100644 --- a/Destination.h +++ b/Destination.h @@ -49,7 +49,7 @@ namespace stream // implements GarlicDestination const i2p::data::LeaseSet * GetLeaseSet (); - void HandleI2NPMessage (const uint8_t * buf, size_t len); + void HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from); // override GarlicDestination void ProcessGarlicMessage (I2NPMessage * msg); diff --git a/Garlic.cpp b/Garlic.cpp index df3587d0..ba4a7e19 100644 --- a/Garlic.cpp +++ b/Garlic.cpp @@ -382,12 +382,12 @@ namespace garlic { case eGarlicDeliveryTypeLocal: LogPrint ("Garlic type local"); - HandleI2NPMessage (buf, len); + HandleI2NPMessage (buf, len, from); break; case eGarlicDeliveryTypeDestination: LogPrint ("Garlic type destination"); buf += 32; // destination. check it later or for multiple destinations - HandleI2NPMessage (buf, len); + HandleI2NPMessage (buf, len, from); break; case eGarlicDeliveryTypeTunnel: { diff --git a/Garlic.h b/Garlic.h index cabb7d5d..fca6b8d7 100644 --- a/Garlic.h +++ b/Garlic.h @@ -99,7 +99,7 @@ namespace garlic virtual void SetLeaseSetUpdated (); virtual const i2p::data::LeaseSet * GetLeaseSet () = 0; // TODO - virtual void HandleI2NPMessage (const uint8_t * buf, size_t len) = 0; + virtual void HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from) = 0; protected: diff --git a/LeaseSet.cpp b/LeaseSet.cpp index 26211d13..467f3145 100644 --- a/LeaseSet.cpp +++ b/LeaseSet.cpp @@ -12,16 +12,14 @@ namespace i2p namespace data { - LeaseSet::LeaseSet (const uint8_t * buf, int len, bool unsolicited): - m_IsUnsolicited (unsolicited) + LeaseSet::LeaseSet (const uint8_t * buf, int len) { memcpy (m_Buffer, buf, len); m_BufferLen = len; ReadFromBuffer (); } - LeaseSet::LeaseSet (const i2p::tunnel::TunnelPool& pool): - m_IsUnsolicited (false) + LeaseSet::LeaseSet (const i2p::tunnel::TunnelPool& pool) { // header const i2p::data::LocalDestination& localDestination = pool.GetLocalDestination (); diff --git a/LeaseSet.h b/LeaseSet.h index f8976a69..e1286681 100644 --- a/LeaseSet.h +++ b/LeaseSet.h @@ -41,7 +41,7 @@ namespace data { public: - LeaseSet (const uint8_t * buf, int len, bool unsolicited = false); + LeaseSet (const uint8_t * buf, int len); LeaseSet (const LeaseSet& ) = default; LeaseSet (const i2p::tunnel::TunnelPool& pool); LeaseSet& operator=(const LeaseSet& ) = default; @@ -51,9 +51,6 @@ namespace data const uint8_t * GetBuffer () const { return m_Buffer; }; size_t GetBufferLen () const { return m_BufferLen; }; - bool IsUnsolicited () const { return m_IsUnsolicited; }; - void SetUnsolicited (bool unsolicited) { m_IsUnsolicited = unsolicited; }; - // implements RoutingDestination const IdentHash& GetIdentHash () const { return m_Identity.GetIdentHash (); }; const std::vector& GetLeases () const { return m_Leases; }; @@ -74,7 +71,6 @@ namespace data uint8_t m_EncryptionKey[256]; uint8_t m_Buffer[MAX_LS_BUFFER_SIZE]; size_t m_BufferLen; - bool m_IsUnsolicited; }; } } diff --git a/NetDb.cpp b/NetDb.cpp index 44624ef0..84dd68a5 100644 --- a/NetDb.cpp +++ b/NetDb.cpp @@ -195,19 +195,23 @@ namespace data } } - void NetDb::AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len) + void NetDb::AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, + i2p::tunnel::InboundTunnel * from) { - bool unsolicited = !DeleteRequestedDestination (ident); - auto it = m_LeaseSets.find(ident); - if (it != m_LeaseSets.end ()) - { - it->second->Update (buf, len); - LogPrint ("LeaseSet updated"); - } - else + DeleteRequestedDestination (ident); + if (!from) // unsolicited LS must be received directly { - LogPrint ("New LeaseSet added"); - m_LeaseSets[ident] = new LeaseSet (buf, len, unsolicited); + auto it = m_LeaseSets.find(ident); + if (it != m_LeaseSets.end ()) + { + it->second->Update (buf, len); + LogPrint ("LeaseSet updated"); + } + else + { + LogPrint ("New LeaseSet added"); + m_LeaseSets[ident] = new LeaseSet (buf, len); + } } } @@ -427,7 +431,7 @@ namespace data if (msg->type) { LogPrint ("LeaseSet"); - AddLeaseSet (msg->key, buf + offset, len - offset); + AddLeaseSet (msg->key, buf + offset, len - offset, m->from); } else { @@ -635,7 +639,7 @@ namespace data if (!replyMsg) { auto leaseSet = FindLeaseSet (buf); - if (leaseSet && leaseSet->IsUnsolicited ()) // we don't send back our LeaseSets + if (leaseSet) // we don't send back our LeaseSets { LogPrint ("Requested LeaseSet ", key, " found"); replyMsg = CreateDatabaseStoreMsg (leaseSet); @@ -885,8 +889,6 @@ namespace data LogPrint ("LeaseSet requested"); RequestDestination (ident, true, pool); } - else - leaseSet->SetUnsolicited (false); m_Subscriptions[ident] = pool; } @@ -920,7 +922,7 @@ namespace data { for (auto it = m_LeaseSets.begin (); it != m_LeaseSets.end ();) { - if (it->second->IsUnsolicited () && !it->second->HasNonExpiredLeases ()) // all leases expired + if (it->second->HasNonExpiredLeases ()) // all leases expired { LogPrint ("LeaseSet ", it->second->GetIdentHash ().ToBase64 (), " expired"); delete it->second; diff --git a/NetDb.h b/NetDb.h index 523f5c81..ab7a74e8 100644 --- a/NetDb.h +++ b/NetDb.h @@ -64,7 +64,7 @@ namespace data void Stop (); void AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len); - void AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len); + void AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, i2p::tunnel::InboundTunnel * from); RouterInfo * FindRouter (const IdentHash& ident) const; LeaseSet * FindLeaseSet (const IdentHash& destination) const; AddressBook& GetAddressBook () { return m_AddressBook; };// TODO: move AddressBook away from NetDb diff --git a/RouterContext.cpp b/RouterContext.cpp index be1aaaa4..2560e6d4 100644 --- a/RouterContext.cpp +++ b/RouterContext.cpp @@ -160,8 +160,8 @@ namespace i2p fk.write ((char *)&keys, sizeof (keys)); } - void RouterContext::HandleI2NPMessage (const uint8_t * buf, size_t len) + void RouterContext::HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from) { - i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf))); + i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf), from)); } } diff --git a/RouterContext.h b/RouterContext.h index ae3e3f10..777482b8 100644 --- a/RouterContext.h +++ b/RouterContext.h @@ -44,7 +44,7 @@ namespace i2p // implements GarlicDestination const i2p::data::LeaseSet * GetLeaseSet () { return nullptr; }; - void HandleI2NPMessage (const uint8_t * buf, size_t len); + void HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from); private: