TunnelPool added

This commit is contained in:
orignal 2014-03-14 12:35:02 -04:00
parent 70df239d14
commit 7caa46b381
5 changed files with 72 additions and 3 deletions

View File

@ -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/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/UPnP.o
obj/UPnP.o obj/TunnelPool.o
INCFLAGS =
LDFLAGS = -Wl,-rpath,/usr/local/lib -lcryptopp -lboost_system -lboost_filesystem -lboost_regex -lboost_program_options -lpthread
LIBS =

View File

@ -14,7 +14,7 @@ namespace i2p
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)
{
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;
}
m_PendingTunnels.clear ();
@ -418,6 +421,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

View File

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

26
TunnelPool.cpp Normal file
View File

@ -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 Normal file
View File

@ -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