mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 11:04:00 +01:00
3-hops tunnels for tunnel pool
This commit is contained in:
parent
b47d7aceaa
commit
26c5f6cd77
|
@ -436,6 +436,9 @@ namespace tunnel
|
||||||
if (ts > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
if (ts > it->second->GetCreationTime () + TUNNEL_EXPIRATION_TIMEOUT)
|
||||||
{
|
{
|
||||||
LogPrint ("Tunnel ", it->second->GetTunnelID (), " expired");
|
LogPrint ("Tunnel ", it->second->GetTunnelID (), " expired");
|
||||||
|
auto pool = it->second->GetTunnelPool ();
|
||||||
|
if (pool)
|
||||||
|
pool->TunnelExpired (it->second);
|
||||||
it = m_InboundTunnels.erase (it);
|
it = m_InboundTunnels.erase (it);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -496,7 +499,7 @@ namespace tunnel
|
||||||
void Tunnels::ManageTunnelPools ()
|
void Tunnels::ManageTunnelPools ()
|
||||||
{
|
{
|
||||||
for (auto& it: m_Pools)
|
for (auto& it: m_Pools)
|
||||||
it->ManageTunnels ();
|
it->CreateTunnels ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tunnels::PostTunnelData (I2NPMessage * msg)
|
void Tunnels::PostTunnelData (I2NPMessage * msg)
|
||||||
|
|
1
Tunnel.h
1
Tunnel.h
|
@ -158,7 +158,6 @@ namespace tunnel
|
||||||
const decltype(m_OutboundTunnels)& GetOutboundTunnels () const { return m_OutboundTunnels; };
|
const decltype(m_OutboundTunnels)& GetOutboundTunnels () const { return m_OutboundTunnels; };
|
||||||
const decltype(m_InboundTunnels)& GetInboundTunnels () const { return m_InboundTunnels; };
|
const decltype(m_InboundTunnels)& GetInboundTunnels () const { return m_InboundTunnels; };
|
||||||
const decltype(m_TransitTunnels)& GetTransitTunnels () const { return m_TransitTunnels; };
|
const decltype(m_TransitTunnels)& GetTransitTunnels () const { return m_TransitTunnels; };
|
||||||
const decltype(m_Pools)& GetTunnelPools () const { return m_Pools; };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Tunnels tunnels;
|
extern Tunnels tunnels;
|
||||||
|
|
|
@ -23,6 +23,13 @@ namespace tunnel
|
||||||
m_InboundTunnels.insert (createdTunnel);
|
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 *> TunnelPool::GetInboundTunnels (int num) const
|
||||||
{
|
{
|
||||||
std::vector<InboundTunnel *> v;
|
std::vector<InboundTunnel *> v;
|
||||||
|
@ -48,34 +55,16 @@ namespace tunnel
|
||||||
OutboundTunnel * outboundTunnel = tunnels.GetNextOutboundTunnel ();
|
OutboundTunnel * outboundTunnel = tunnels.GetNextOutboundTunnel ();
|
||||||
LogPrint ("Creating destination inbound tunnel...");
|
LogPrint ("Creating destination inbound tunnel...");
|
||||||
auto firstHop = i2p::data::netdb.GetRandomRouter (outboundTunnel ? outboundTunnel->GetEndpointRouter () : nullptr);
|
auto firstHop = i2p::data::netdb.GetRandomRouter (outboundTunnel ? outboundTunnel->GetEndpointRouter () : nullptr);
|
||||||
|
auto secondHop = i2p::data::netdb.GetRandomRouter (firstHop);
|
||||||
auto * tunnel = tunnels.CreateTunnel<InboundTunnel> (
|
auto * tunnel = tunnels.CreateTunnel<InboundTunnel> (
|
||||||
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
|
||||||
{
|
{
|
||||||
firstHop,
|
firstHop,
|
||||||
i2p::data::netdb.GetRandomRouter (firstHop)
|
secondHop,
|
||||||
|
i2p::data::netdb.GetRandomRouter (secondHop)
|
||||||
}),
|
}),
|
||||||
outboundTunnel);
|
outboundTunnel);
|
||||||
tunnel->SetTunnelPool (this);
|
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 ();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,8 @@ namespace tunnel
|
||||||
|
|
||||||
void CreateTunnels ();
|
void CreateTunnels ();
|
||||||
void TunnelCreated (InboundTunnel * createdTunnel);
|
void TunnelCreated (InboundTunnel * createdTunnel);
|
||||||
|
void TunnelExpired (InboundTunnel * expiredTunnel);
|
||||||
std::vector<InboundTunnel *> GetInboundTunnels (int num) const;
|
std::vector<InboundTunnel *> GetInboundTunnels (int num) const;
|
||||||
void ManageTunnels ();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue