Browse Source

manage tunnel pools

pull/46/head
orignal 11 years ago
parent
commit
b47d7aceaa
  1. 13
      HTTPServer.cpp
  2. 16
      Tunnel.cpp
  3. 3
      Tunnel.h
  4. 4
      TunnelPool.cpp
  5. 4
      TunnelPool.h

13
HTTPServer.cpp

@ -145,20 +145,11 @@ namespace util
for (auto it: i2p::tunnel::tunnels.GetInboundTunnels ()) for (auto it: i2p::tunnel::tunnels.GetInboundTunnels ())
{ {
it.second->GetTunnelConfig ()->Print (s); it.second->GetTunnelConfig ()->Print (s);
if (it.second->GetTunnelPool ())
s << " " << "Pool";
s << " " << (int)it.second->GetNumReceivedBytes () << "<BR>"; s << " " << (int)it.second->GetNumReceivedBytes () << "<BR>";
} }
s << "<P>Tunnel pools</P>";
for (auto it: i2p::tunnel::tunnels.GetTunnelPools ())
{
for (auto it1: it->GetInboundTunnels ())
{
it1->GetTunnelConfig ()->Print (s);
s << " " << (int)it1->GetNumReceivedBytes () << "<BR>";
}
s << "<BR>";
}
s << "<P>Transit tunnels</P>"; s << "<P>Transit tunnels</P>";
for (auto it: i2p::tunnel::tunnels.GetTransitTunnels ()) for (auto it: i2p::tunnel::tunnels.GetTransitTunnels ())
{ {

16
Tunnel.cpp

@ -273,9 +273,17 @@ namespace tunnel
return tunnel;*/ return tunnel;*/
} }
void Tunnels::CreateTunnelPool (i2p::data::LocalDestination * localDestination) TunnelPool * Tunnels::CreateTunnelPool (i2p::data::LocalDestination * localDestination)
{ {
m_Pools.push_back (new TunnelPool (localDestination)); auto pool = new TunnelPool (localDestination);
m_Pools.push_back (pool);
return pool;
}
void Tunnels::DeleteTunnelPool (TunnelPool * pool)
{
m_Pools.remove (pool);
delete pool;
} }
void Tunnels::AddTransitTunnel (TransitTunnel * tunnel) void Tunnels::AddTransitTunnel (TransitTunnel * tunnel)
@ -441,7 +449,7 @@ namespace tunnel
return; return;
} }
if (m_InboundTunnels.size () < 10) if (m_InboundTunnels.size () < 15) // TODO: store exploratory tunnels explicitly
{ {
// trying to create one more inbound tunnel // trying to create one more inbound tunnel
if (m_OutboundTunnels.empty () || m_InboundTunnels.size () < 3) if (m_OutboundTunnels.empty () || m_InboundTunnels.size () < 3)
@ -513,10 +521,10 @@ namespace tunnel
void Tunnels::AddInboundTunnel (InboundTunnel * newTunnel) void Tunnels::AddInboundTunnel (InboundTunnel * newTunnel)
{ {
m_InboundTunnels[newTunnel->GetTunnelID ()] = newTunnel;
auto pool = newTunnel->GetTunnelPool (); auto pool = newTunnel->GetTunnelPool ();
if (!pool) if (!pool)
{ {
m_InboundTunnels[newTunnel->GetTunnelID ()] = newTunnel;
// build symmetric outbound tunnel // build symmetric outbound tunnel
CreateTunnel<OutboundTunnel> (newTunnel->GetTunnelConfig ()->Invert (), GetNextOutboundTunnel ()); CreateTunnel<OutboundTunnel> (newTunnel->GetTunnelConfig ()->Invert (), GetNextOutboundTunnel ());
} }

3
Tunnel.h

@ -120,7 +120,8 @@ namespace tunnel
void PostTunnelData (I2NPMessage * msg); void PostTunnelData (I2NPMessage * msg);
template<class TTunnel> template<class TTunnel>
TTunnel * CreateTunnel (TunnelConfig * config, OutboundTunnel * outboundTunnel = 0); TTunnel * CreateTunnel (TunnelConfig * config, OutboundTunnel * outboundTunnel = 0);
void CreateTunnelPool (i2p::data::LocalDestination * localDestination); TunnelPool * CreateTunnelPool (i2p::data::LocalDestination * localDestination);
void DeleteTunnelPool (TunnelPool * pool);
OutboundTunnel * CreateOneHopOutboundTestTunnel (InboundTunnel * replyTunnel); OutboundTunnel * CreateOneHopOutboundTestTunnel (InboundTunnel * replyTunnel);
InboundTunnel * CreateOneHopInboundTestTunnel (OutboundTunnel * outboundTunnel = 0); InboundTunnel * CreateOneHopInboundTestTunnel (OutboundTunnel * outboundTunnel = 0);

4
TunnelPool.cpp

@ -15,7 +15,7 @@ namespace tunnel
TunnelPool::~TunnelPool () TunnelPool::~TunnelPool ()
{ {
for (auto it: m_InboundTunnels) for (auto it: m_InboundTunnels)
delete it; it->SetTunnelPool (nullptr);
} }
void TunnelPool::TunnelCreated (InboundTunnel * createdTunnel) void TunnelPool::TunnelCreated (InboundTunnel * createdTunnel)
@ -55,7 +55,7 @@ namespace tunnel
i2p::data::netdb.GetRandomRouter (firstHop) i2p::data::netdb.GetRandomRouter (firstHop)
}), }),
outboundTunnel); outboundTunnel);
tunnel->SetTunnelPool (this); tunnel->SetTunnelPool (this);
} }
void TunnelPool::ManageTunnels () void TunnelPool::ManageTunnels ()

4
TunnelPool.h

@ -38,10 +38,6 @@ namespace tunnel
int m_NumTunnels; int m_NumTunnels;
std::set<InboundTunnel *, TunnelCreationTimeCmp> m_InboundTunnels; // recent tunnel appears first std::set<InboundTunnel *, TunnelCreationTimeCmp> m_InboundTunnels; // recent tunnel appears first
public:
// for HTTP only
const decltype(m_InboundTunnels)& GetInboundTunnels () const { return m_InboundTunnels; };
}; };
} }
} }

Loading…
Cancel
Save