Skip to content

Commit

Permalink
separate requsted and unsolicited LeaseSets
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Oct 13, 2014
1 parent 96e8cab commit 3a4b6bd
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 36 deletions.
6 changes: 3 additions & 3 deletions Destination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion Destination.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Garlic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
{
Expand Down
2 changes: 1 addition & 1 deletion Garlic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
6 changes: 2 additions & 4 deletions LeaseSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down
6 changes: 1 addition & 5 deletions LeaseSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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; };
Expand All @@ -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;
};
}
}
Expand Down
34 changes: 18 additions & 16 deletions NetDb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -885,8 +889,6 @@ namespace data
LogPrint ("LeaseSet requested");
RequestDestination (ident, true, pool);
}
else
leaseSet->SetUnsolicited (false);
m_Subscriptions[ident] = pool;
}

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion NetDb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions RouterContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 1 addition & 1 deletion RouterContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down

0 comments on commit 3a4b6bd

Please sign in to comment.