Browse Source

3-hops tunnels for tunnel pool

pull/46/head
orignal 11 years ago
parent
commit
26c5f6cd77
  1. 5
      Tunnel.cpp
  2. 1
      Tunnel.h
  3. 31
      TunnelPool.cpp
  4. 2
      TunnelPool.h

5
Tunnel.cpp

@ -436,6 +436,9 @@ namespace tunnel @@ -436,6 +436,9 @@ namespace tunnel
if (ts > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
{
LogPrint ("Tunnel ", it->second->GetTunnelID (), " expired");
auto pool = it->second->GetTunnelPool ();
if (pool)
pool->TunnelExpired (it->second);
it = m_InboundTunnels.erase (it);
}
else
@ -496,7 +499,7 @@ namespace tunnel @@ -496,7 +499,7 @@ namespace tunnel
void Tunnels::ManageTunnelPools ()
{
for (auto& it: m_Pools)
it->ManageTunnels ();
it->CreateTunnels ();
}
void Tunnels::PostTunnelData (I2NPMessage * msg)

1
Tunnel.h

@ -158,7 +158,6 @@ namespace tunnel @@ -158,7 +158,6 @@ namespace tunnel
const decltype(m_OutboundTunnels)& GetOutboundTunnels () const { return m_OutboundTunnels; };
const decltype(m_InboundTunnels)& GetInboundTunnels () const { return m_InboundTunnels; };
const decltype(m_TransitTunnels)& GetTransitTunnels () const { return m_TransitTunnels; };
const decltype(m_Pools)& GetTunnelPools () const { return m_Pools; };
};
extern Tunnels tunnels;

31
TunnelPool.cpp

@ -23,6 +23,13 @@ namespace tunnel @@ -23,6 +23,13 @@ namespace tunnel
m_InboundTunnels.insert (createdTunnel);
}
void TunnelPool::TunnelExpired (InboundTunnel * expiredTunnel)
{
m_InboundTunnels.erase (expiredTunnel);
if (m_Owner)
m_Owner->UpdateLeaseSet ();
}
std::vector<InboundTunnel *> TunnelPool::GetInboundTunnels (int num) const
{
std::vector<InboundTunnel *> v;
@ -48,34 +55,16 @@ namespace tunnel @@ -48,34 +55,16 @@ namespace tunnel
OutboundTunnel * outboundTunnel = tunnels.GetNextOutboundTunnel ();
LogPrint ("Creating destination inbound tunnel...");
auto firstHop = i2p::data::netdb.GetRandomRouter (outboundTunnel ? outboundTunnel->GetEndpointRouter () : nullptr);
auto secondHop = i2p::data::netdb.GetRandomRouter (firstHop);
auto * tunnel = tunnels.CreateTunnel<InboundTunnel> (
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
{
firstHop,
i2p::data::netdb.GetRandomRouter (firstHop)
secondHop,
i2p::data::netdb.GetRandomRouter (secondHop)
}),
outboundTunnel);
tunnel->SetTunnelPool (this);
}
void TunnelPool::ManageTunnels ()
{
uint64_t ts = i2p::util::GetSecondsSinceEpoch ();
bool isLeaseSetUpdated = false;
for (auto it = m_InboundTunnels.begin (); it != m_InboundTunnels.end ();)
{
if (ts > (*it)->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
{
LogPrint ("Destination tunnel ", (*it)->GetTunnelID (), " expired");
m_InboundTunnels.erase (it++);
isLeaseSetUpdated = true;
}
else
++it;
}
CreateTunnels ();
if (isLeaseSetUpdated && m_Owner)
m_Owner->UpdateLeaseSet ();
}
}
}

2
TunnelPool.h

@ -25,8 +25,8 @@ namespace tunnel @@ -25,8 +25,8 @@ namespace tunnel
void CreateTunnels ();
void TunnelCreated (InboundTunnel * createdTunnel);
void TunnelExpired (InboundTunnel * expiredTunnel);
std::vector<InboundTunnel *> GetInboundTunnels (int num) const;
void ManageTunnels ();
private:

Loading…
Cancel
Save