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
m_Service->post (boost::bind (&StreamingDestination::HandleDeliveryStatusMessage, this, msg)); 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; I2NPHeader * header = (I2NPHeader *)buf;
switch (header->typeID) switch (header->typeID)
@ -293,10 +293,10 @@ namespace stream
break; break;
case eI2NPDatabaseStore: case eI2NPDatabaseStore:
HandleDatabaseStoreMessage (buf + sizeof (I2NPHeader), be16toh (header->size)); 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; break;
default: default:
i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf))); i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf), from));
} }
} }

2
Destination.h

@ -49,7 +49,7 @@ namespace stream
// implements GarlicDestination // implements GarlicDestination
const i2p::data::LeaseSet * GetLeaseSet (); 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 // override GarlicDestination
void ProcessGarlicMessage (I2NPMessage * msg); void ProcessGarlicMessage (I2NPMessage * msg);

4
Garlic.cpp

@ -382,12 +382,12 @@ namespace garlic
{ {
case eGarlicDeliveryTypeLocal: case eGarlicDeliveryTypeLocal:
LogPrint ("Garlic type local"); LogPrint ("Garlic type local");
HandleI2NPMessage (buf, len); HandleI2NPMessage (buf, len, from);
break; break;
case eGarlicDeliveryTypeDestination: case eGarlicDeliveryTypeDestination:
LogPrint ("Garlic type destination"); LogPrint ("Garlic type destination");
buf += 32; // destination. check it later or for multiple destinations buf += 32; // destination. check it later or for multiple destinations
HandleI2NPMessage (buf, len); HandleI2NPMessage (buf, len, from);
break; break;
case eGarlicDeliveryTypeTunnel: case eGarlicDeliveryTypeTunnel:
{ {

2
Garlic.h

@ -99,7 +99,7 @@ namespace garlic
virtual void SetLeaseSetUpdated (); virtual void SetLeaseSetUpdated ();
virtual const i2p::data::LeaseSet * GetLeaseSet () = 0; // TODO 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: protected:

6
LeaseSet.cpp

@ -12,16 +12,14 @@ namespace i2p
namespace data namespace data
{ {
LeaseSet::LeaseSet (const uint8_t * buf, int len, bool unsolicited): LeaseSet::LeaseSet (const uint8_t * buf, int len)
m_IsUnsolicited (unsolicited)
{ {
memcpy (m_Buffer, buf, len); memcpy (m_Buffer, buf, len);
m_BufferLen = len; m_BufferLen = len;
ReadFromBuffer (); ReadFromBuffer ();
} }
LeaseSet::LeaseSet (const i2p::tunnel::TunnelPool& pool): LeaseSet::LeaseSet (const i2p::tunnel::TunnelPool& pool)
m_IsUnsolicited (false)
{ {
// header // header
const i2p::data::LocalDestination& localDestination = pool.GetLocalDestination (); const i2p::data::LocalDestination& localDestination = pool.GetLocalDestination ();

6
LeaseSet.h

@ -41,7 +41,7 @@ namespace data
{ {
public: public:
LeaseSet (const uint8_t * buf, int len, bool unsolicited = false); LeaseSet (const uint8_t * buf, int len);
LeaseSet (const LeaseSet& ) = default; LeaseSet (const LeaseSet& ) = default;
LeaseSet (const i2p::tunnel::TunnelPool& pool); LeaseSet (const i2p::tunnel::TunnelPool& pool);
LeaseSet& operator=(const LeaseSet& ) = default; LeaseSet& operator=(const LeaseSet& ) = default;
@ -51,9 +51,6 @@ namespace data
const uint8_t * GetBuffer () const { return m_Buffer; }; const uint8_t * GetBuffer () const { return m_Buffer; };
size_t GetBufferLen () const { return m_BufferLen; }; size_t GetBufferLen () const { return m_BufferLen; };
bool IsUnsolicited () const { return m_IsUnsolicited; };
void SetUnsolicited (bool unsolicited) { m_IsUnsolicited = unsolicited; };
// implements RoutingDestination // implements RoutingDestination
const IdentHash& GetIdentHash () const { return m_Identity.GetIdentHash (); }; const IdentHash& GetIdentHash () const { return m_Identity.GetIdentHash (); };
const std::vector<Lease>& GetLeases () const { return m_Leases; }; const std::vector<Lease>& GetLeases () const { return m_Leases; };
@ -74,7 +71,6 @@ namespace data
uint8_t m_EncryptionKey[256]; uint8_t m_EncryptionKey[256];
uint8_t m_Buffer[MAX_LS_BUFFER_SIZE]; uint8_t m_Buffer[MAX_LS_BUFFER_SIZE];
size_t m_BufferLen; size_t m_BufferLen;
bool m_IsUnsolicited;
}; };
} }
} }

34
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); DeleteRequestedDestination (ident);
auto it = m_LeaseSets.find(ident); if (!from) // unsolicited LS must be received directly
if (it != m_LeaseSets.end ())
{
it->second->Update (buf, len);
LogPrint ("LeaseSet updated");
}
else
{ {
LogPrint ("New LeaseSet added"); auto it = m_LeaseSets.find(ident);
m_LeaseSets[ident] = new LeaseSet (buf, len, unsolicited); 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) if (msg->type)
{ {
LogPrint ("LeaseSet"); LogPrint ("LeaseSet");
AddLeaseSet (msg->key, buf + offset, len - offset); AddLeaseSet (msg->key, buf + offset, len - offset, m->from);
} }
else else
{ {
@ -635,7 +639,7 @@ namespace data
if (!replyMsg) if (!replyMsg)
{ {
auto leaseSet = FindLeaseSet (buf); 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"); LogPrint ("Requested LeaseSet ", key, " found");
replyMsg = CreateDatabaseStoreMsg (leaseSet); replyMsg = CreateDatabaseStoreMsg (leaseSet);
@ -885,8 +889,6 @@ namespace data
LogPrint ("LeaseSet requested"); LogPrint ("LeaseSet requested");
RequestDestination (ident, true, pool); RequestDestination (ident, true, pool);
} }
else
leaseSet->SetUnsolicited (false);
m_Subscriptions[ident] = pool; m_Subscriptions[ident] = pool;
} }
@ -920,7 +922,7 @@ namespace data
{ {
for (auto it = m_LeaseSets.begin (); it != m_LeaseSets.end ();) 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"); LogPrint ("LeaseSet ", it->second->GetIdentHash ().ToBase64 (), " expired");
delete it->second; delete it->second;

2
NetDb.h

@ -64,7 +64,7 @@ namespace data
void Stop (); void Stop ();
void AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len); 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; RouterInfo * FindRouter (const IdentHash& ident) const;
LeaseSet * FindLeaseSet (const IdentHash& destination) const; LeaseSet * FindLeaseSet (const IdentHash& destination) const;
AddressBook& GetAddressBook () { return m_AddressBook; };// TODO: move AddressBook away from NetDb AddressBook& GetAddressBook () { return m_AddressBook; };// TODO: move AddressBook away from NetDb

4
RouterContext.cpp

@ -160,8 +160,8 @@ namespace i2p
fk.write ((char *)&keys, sizeof (keys)); 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
// implements GarlicDestination // implements GarlicDestination
const i2p::data::LeaseSet * GetLeaseSet () { return nullptr; }; 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: private:

Loading…
Cancel
Save