Browse Source

TunnelPool added

pull/46/head
orignal 11 years ago
parent
commit
7caa46b381
  1. 2
      Makefile
  2. 8
      Tunnel.cpp
  3. 6
      Tunnel.h
  4. 26
      TunnelPool.cpp
  5. 33
      TunnelPool.h

2
Makefile

@ -5,7 +5,7 @@ OBJECTS = obj/i2p.o obj/base64.o obj/NTCPSession.o obj/RouterInfo.o obj/Transpor
obj/RouterContext.o obj/NetDb.o obj/LeaseSet.o obj/Tunnel.o obj/TunnelEndpoint.o \ obj/RouterContext.o obj/NetDb.o obj/LeaseSet.o obj/Tunnel.o obj/TunnelEndpoint.o \
obj/TunnelGateway.o obj/TransitTunnel.o obj/I2NPProtocol.o obj/Log.o obj/Garlic.o \ obj/TunnelGateway.o obj/TransitTunnel.o obj/I2NPProtocol.o obj/Log.o obj/Garlic.o \
obj/HTTPServer.o obj/Streaming.o obj/Identity.o obj/SSU.o obj/util.o obj/Reseed.o \ obj/HTTPServer.o obj/Streaming.o obj/Identity.o obj/SSU.o obj/util.o obj/Reseed.o \
obj/UPnP.o obj/UPnP.o obj/TunnelPool.o
INCFLAGS = INCFLAGS =
LDFLAGS = -Wl,-rpath,/usr/local/lib -lcryptopp -lboost_system -lboost_filesystem -lboost_regex -lboost_program_options -lpthread LDFLAGS = -Wl,-rpath,/usr/local/lib -lcryptopp -lboost_system -lboost_filesystem -lboost_regex -lboost_program_options -lpthread
LIBS = LIBS =

8
Tunnel.cpp

@ -14,7 +14,7 @@ namespace i2p
namespace tunnel namespace tunnel
{ {
Tunnel::Tunnel (TunnelConfig * config): m_Config (config), m_IsEstablished (false) Tunnel::Tunnel (TunnelConfig * config): m_Config (config), m_Pool (nullptr), m_IsEstablished (false)
{ {
} }
@ -343,6 +343,9 @@ namespace tunnel
for (auto& it : m_PendingTunnels) for (auto& it : m_PendingTunnels)
{ {
LogPrint ("Pending tunnel build request ", it.first, " has not been responded. Deleted"); LogPrint ("Pending tunnel build request ", it.first, " has not been responded. Deleted");
auto pool = it.second->GetTunnelPool ();
if (pool)
pool->TunnelCreationFailed (it.second);
delete it.second; delete it.second;
} }
m_PendingTunnels.clear (); m_PendingTunnels.clear ();
@ -418,6 +421,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

6
Tunnel.h

@ -11,6 +11,7 @@
#include <cryptopp/aes.h> #include <cryptopp/aes.h>
#include "Queue.h" #include "Queue.h"
#include "TunnelConfig.h" #include "TunnelConfig.h"
#include "TunnelPool.h"
#include "TransitTunnel.h" #include "TransitTunnel.h"
#include "TunnelEndpoint.h" #include "TunnelEndpoint.h"
#include "TunnelGateway.h" #include "TunnelGateway.h"
@ -36,7 +37,9 @@ namespace tunnel
TunnelConfig * GetTunnelConfig () const { return m_Config; } TunnelConfig * GetTunnelConfig () const { return m_Config; }
bool IsEstablished () const { return m_IsEstablished; }; bool IsEstablished () const { return m_IsEstablished; };
TunnelPool * GetTunnelPool () const { return m_Pool; };
void SetTunnelPool (TunnelPool * pool) { m_Pool = pool; };
bool HandleTunnelBuildResponse (uint8_t * msg, size_t len); bool HandleTunnelBuildResponse (uint8_t * msg, size_t len);
// implements TunnelBase // implements TunnelBase
@ -53,6 +56,7 @@ namespace tunnel
private: private:
TunnelConfig * m_Config; TunnelConfig * m_Config;
TunnelPool * m_Pool; // pool, tunnel belongs to, or null
bool m_IsEstablished; bool m_IsEstablished;
CryptoPP::ECB_Mode<CryptoPP::AES>::Decryption m_ECBDecryption; CryptoPP::ECB_Mode<CryptoPP::AES>::Decryption m_ECBDecryption;

26
TunnelPool.cpp

@ -0,0 +1,26 @@
#include "Tunnel.h"
#include "TunnelPool.h"
namespace i2p
{
namespace tunnel
{
TunnelPool::TunnelPool ()
{
}
TunnelPool::~TunnelPool ()
{
for (auto it: m_InboundTunnels)
it->SetTunnelPool (nullptr);
}
void TunnelPool::TunnelCreationFailed (Tunnel * failedTunnel)
{
}
void TunnelPool::TunnelExpired (InboundTunnel * expiredTunnel)
{
}
}
}

33
TunnelPool.h

@ -0,0 +1,33 @@
#ifndef TUNNEL_POOL__
#define TUNNEL_POOL__
#include <list>
#include "LeaseSet.h"
namespace i2p
{
namespace tunnel
{
class Tunnel;
class InboundTunnel;
class OutboundTunnel;
class TunnelPool // per local destination
{
public:
TunnelPool ();
~TunnelPool ();
void TunnelCreationFailed (Tunnel * failedTunnel);
void TunnelExpired (InboundTunnel * expiredTunnel);
private:
std::list<InboundTunnel *> m_InboundTunnels;
};
}
}
#endif
Loading…
Cancel
Save