Browse Source

separate requsted and unsolicited LeaseSets

pull/102/head
orignal 10 years ago
parent
commit
3a4b6bd7b0
  1. 6
      Destination.cpp
  2. 2
      Destination.h
  3. 4
      Garlic.cpp
  4. 2
      Garlic.h
  5. 6
      LeaseSet.cpp
  6. 6
      LeaseSet.h
  7. 34
      NetDb.cpp
  8. 2
      NetDb.h
  9. 4
      RouterContext.cpp
  10. 2
      RouterContext.h

6
Destination.cpp

@ -283,7 +283,7 @@ namespace stream @@ -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 @@ -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));
}
}

2
Destination.h

@ -49,7 +49,7 @@ namespace stream @@ -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);

4
Garlic.cpp

@ -382,12 +382,12 @@ namespace garlic @@ -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

@ -99,7 +99,7 @@ namespace garlic @@ -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:

6
LeaseSet.cpp

@ -12,16 +12,14 @@ namespace i2p @@ -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 ();

6
LeaseSet.h

@ -41,7 +41,7 @@ namespace data @@ -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 @@ -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 @@ -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;
};
}
}

34
NetDb.cpp

@ -195,19 +195,23 @@ namespace data @@ -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 @@ -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 @@ -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 @@ -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 @@ -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

@ -64,7 +64,7 @@ namespace data @@ -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

4
RouterContext.cpp

@ -160,8 +160,8 @@ namespace i2p @@ -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));
}
}

2
RouterContext.h

@ -44,7 +44,7 @@ namespace i2p @@ -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…
Cancel
Save