mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-01-22 21:37:17 +01:00
separate requsted and unsolicited LeaseSets
This commit is contained in:
parent
96e8cab8fb
commit
3a4b6bd7b0
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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:
|
||||
{
|
||||
|
|
2
Garlic.h
2
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:
|
||||
|
||||
|
|
|
@ -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 ();
|
||||
|
|
|
@ -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<Lease>& 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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
18
NetDb.cpp
18
NetDb.cpp
|
@ -195,9 +195,12 @@ 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)
|
||||
{
|
||||
DeleteRequestedDestination (ident);
|
||||
if (!from) // unsolicited LS must be received directly
|
||||
{
|
||||
bool unsolicited = !DeleteRequestedDestination (ident);
|
||||
auto it = m_LeaseSets.find(ident);
|
||||
if (it != m_LeaseSets.end ())
|
||||
{
|
||||
|
@ -207,7 +210,8 @@ namespace data
|
|||
else
|
||||
{
|
||||
LogPrint ("New LeaseSet added");
|
||||
m_LeaseSets[ident] = new LeaseSet (buf, len, unsolicited);
|
||||
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;
|
||||
|
|
2
NetDb.h
2
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
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
||||
|
|
Loading…
Reference in a new issue