Skip to content

Commit

Permalink
select tunnel from TunnelPool rather than from LeaseSet for DeliveryS…
Browse files Browse the repository at this point in the history
…tatus
  • Loading branch information
orignal committed Apr 5, 2015
1 parent 62593f6 commit 10577cd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions Destination.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ namespace client

// implements GarlicDestination
const i2p::data::LeaseSet * GetLeaseSet ();
std::shared_ptr<i2p::tunnel::TunnelPool> GetTunnelPool () const { return m_Pool; }
void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from);

// override GarlicDestination
Expand Down
11 changes: 5 additions & 6 deletions Garlic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,16 +297,15 @@ namespace garlic
size_t size = 0;
if (m_Owner)
{
auto leases = m_Owner->GetLeaseSet ()->GetNonExpiredLeases ();
if (!leases.empty ())
auto inboundTunnel = m_Owner->GetTunnelPool ()->GetNextInboundTunnel ();
if (inboundTunnel)
{
buf[size] = eGarlicDeliveryTypeTunnel << 5; // delivery instructions flag tunnel
size++;
uint32_t i = m_Rnd.GenerateWord32 (0, leases.size () - 1);
// hash and tunnelID sequence is reversed for Garlic
memcpy (buf + size, leases[i].tunnelGateway, 32); // To Hash
memcpy (buf + size, inboundTunnel->GetNextIdentHash (), 32); // To Hash
size += 32;
htobe32buf (buf + size, leases[i].tunnelID); // tunnelID
htobe32buf (buf + size, inboundTunnel->GetNextTunnelID ()); // tunnelID
size += 4;
// create msg
I2NPMessage * msg = CreateDeliveryStatusMsg (msgID);
Expand All @@ -333,7 +332,7 @@ namespace garlic
size += 3;
}
else
LogPrint ("All tunnels of local LeaseSet expired");
LogPrint (eLogError, "No inbound tunnels in the pool for DeliveryStatus");
}
else
LogPrint ("Missing local LeaseSet");
Expand Down
3 changes: 2 additions & 1 deletion Garlic.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ namespace garlic
i2p::crypto::CBCEncryption m_Encryption;
CryptoPP::AutoSeededRandomPool m_Rnd;
};

class GarlicDestination: public i2p::data::LocalDestination
{
public:
Expand All @@ -133,6 +133,7 @@ namespace garlic
virtual void SetLeaseSetUpdated ();

virtual const i2p::data::LeaseSet * GetLeaseSet () = 0; // TODO
virtual std::shared_ptr<i2p::tunnel::TunnelPool> GetTunnelPool () const = 0;
virtual void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from) = 0;

protected:
Expand Down
5 changes: 5 additions & 0 deletions RouterContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ namespace i2p
fk.write ((char *)&keys, sizeof (keys));
}

std::shared_ptr<i2p::tunnel::TunnelPool> RouterContext::GetTunnelPool () const
{
return i2p::tunnel::tunnels.GetExploratoryPool ();
}

void RouterContext::HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from)
{
i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf), from));
Expand Down
1 change: 1 addition & 0 deletions RouterContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ namespace i2p

// implements GarlicDestination
const i2p::data::LeaseSet * GetLeaseSet () { return nullptr; };
std::shared_ptr<i2p::tunnel::TunnelPool> GetTunnelPool () const;
void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from);

private:
Expand Down

0 comments on commit 10577cd

Please sign in to comment.